X-Git-Url: https://code.delx.au/pymsnt/blobdiff_plain/de2c51b7bf725efa348074d3324e23fd4afd8e5e..ab3667805a3bb1f43d9a3dcbfe74d3d15b0ea0fa:/src/main.py diff --git a/src/main.py b/src/main.py index b98680e..eb90dd4 100644 --- a/src/main.py +++ b/src/main.py @@ -7,23 +7,26 @@ sys.setdefaultencoding("utf-8") sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout) # Find the best reactor +selectWarning = "Unable to install any good reactors (kqueue, epoll, poll).\nWe fell back to using select. You may have scalability problems.\nThis reactor will not support more than 1024 connections at a time." try: from twisted.internet import epollreactor as bestreactor -except ImportError: +except: try: from twisted.internet import kqreactor as bestreactor - except ImportError: + except: try: from twisted.internet import pollreactor as bestreactor - except ImportError: + except: try: - from twisted.internet import default as bestreactor - print "Unable to install any good reactors (kqueue, epoll, poll)." - print "We fell back to using select. You may have scalability problems." - print "This reactor will not support more than 1024 connections at a time." - except ImportError: - print "Unable to find a reactor.\nExiting..." - sys.exit(1) + from twisted.internet import selectreactor as bestreactor + print selectWarning + except: + try: + from twisted.internet import default as bestreactor + print selectWarning + except: + print "Unable to find a reactor. Please make sure you have Twisted properly installed.\nExiting..." + sys.exit(1) bestreactor.install() @@ -38,7 +41,7 @@ for o, v in opts: if o in ("-c", "--config"): configFile = v elif o in ("-b", "--background"): - config.daemonise = True + config.background = True elif o in ("-d", "--debug"): config.debugLevel = "2" elif o in ("-D", "--Debug"): @@ -93,6 +96,7 @@ from tlib.xmlw import Element, jid, component from debug import LogEvent, INFO, WARN, ERROR import debug +import svninfo import utils import xdb import avatar @@ -111,11 +115,15 @@ import housekeep class PyTransport(component.Service): def __init__(self): LogEvent(INFO) + try: + LogEvent(INFO, msg="SVN r" + str(svninfo.getSVNVersion())) + except: + pass # Discovery, as well as some builtin features self.discovery = disco.ServerDiscovery(self) - self.discovery.addIdentity("gateway", legacy.id, legacy.name, config.jid) - self.discovery.addIdentity("conference", "text", legacy.name + " Chatrooms", config.jid) + self.discovery.addIdentity("gateway", legacy.id, config.discoName, config.jid) + self.discovery.addIdentity("conference", "text", config.discoName + " Chatrooms", config.jid) self.discovery.addFeature(disco.XCONFERENCE, None, config.jid) # So that clients know you can create groupchat rooms on the server self.discovery.addFeature("jabber:iq:conference", None, config.jid) # We don't actually support this, but Psi has a bug where it looks for this instead of the above self.discovery.addIdentity("client", "pc", "MSN Messenger", "USER") @@ -149,8 +157,8 @@ class PyTransport(component.Service): # Message IDs self.messageID = 0 - self.loopCall = task.LoopingCall(self.loopCall) - self.loopCall.start(60.0) + self.loopTask = task.LoopingCall(self.loopFunc) + self.loopTask.start(60.0) def removeMe(self): LogEvent(INFO) @@ -173,7 +181,7 @@ class PyTransport(component.Service): def reserveID(self, ID): self.reservedIDs.append(ID) - def loopCall(self): + def loopFunc(self): numsessions = len(self.sessions) #if config.debugOn and numsessions > 0: @@ -239,10 +247,11 @@ class PyTransport(component.Service): mtype = el.getAttribute("type") s = self.sessions.get(froj.userhost(), None) if mtype == "error" and s: + LogEvent(INFO, s.jabberID, "Removing session because of message type=error") s.removeMe() elif s: s.onMessage(el) - else: + elif mtype != "error": to = el.getAttribute("to") ulang = utils.getLang(el) body = None @@ -251,6 +260,7 @@ class PyTransport(component.Service): body = child.__str__() LogEvent(INFO, "", "Sending error response to a message outside of session.") jabw.sendErrorMessage(self, fro, to, "auth", "not-authorized", lang.get(ulang).notLoggedIn, body) + jabw.sendPresence(self, fro, to, ptype="unavailable") def onPresence(self, el): fro = el.getAttribute("from") @@ -262,8 +272,12 @@ class PyTransport(component.Service): LogEvent(WARN, "", "Failed stringprep.") return + ptype = el.getAttribute("type") s = self.sessions.get(froj.userhost()) - if s: + if ptype == "error" and s: + LogEvent(INFO, s.jabberID, "Removing session because of message type=error") + s.removeMe() + elif s: s.onPresence(el) else: ulang = utils.getLang(el) @@ -285,25 +299,24 @@ class PyTransport(component.Service): elif el.getAttribute("type") != "error": LogEvent(INFO, "", "Sending unavailable presence to non-logged in user.") - pres = Element((None, "presence")) - pres.attributes["from"] = to - pres.attributes["to"] = fro - pres.attributes["type"] = "unavailable" - self.send(pres) + jabw.sendPresence(self, fro, to, ptype="unavailable") return elif ptype and (ptype.startswith("subscribe") or ptype.startswith("unsubscribe")): # They haven't logged in, and are trying to change subscription to a user + # No, lets not log them in. Lets send an error :) + jabw.sendPresence(self, fro, to, ptype="error") + # Lets log them in and then do it - LogEvent(INFO, "", "Attempting to create a session to do subscription stuff.") - s = session.makeSession(self, froj.userhost(), ulang) - if s: - self.sessions[froj.userhost()] = s - LogEvent(INFO, "", "New session created.") - # Tell the session there's a new resource - s.handleResourcePresence(froj.userhost(), froj.resource, toj.userhost(), toj.resource, 0, None, None, None) - # Send this subscription - s.onPresence(el) + #LogEvent(INFO, "", "Attempting to create a session to do subscription stuff.") + #s = session.makeSession(self, froj.userhost(), ulang) + #if s: + # self.sessions[froj.userhost()] = s + # LogEvent(INFO, "", "New session created.") + # # Tell the session there's a new resource + # s.handleResourcePresence(froj.userhost(), froj.resource, toj.userhost(), toj.resource, 0, None, None, None) + # # Send this subscription + # s.onPresence(el) class App: