def messageReceived(self, source, resource, dest, destr, mtype, body, noerror, xhtml, autoResponse=0): if dest == config.jid: if body.lower().startswith("end"): LogEvent(INFO, self.jabberID, "Received 'end' request") self.removeMe() return if not self.ready: self.sendNotReadyError(source, resource, dest, body) return LogEvent(INFO, self.jabberID, "Message") self.legacycon.sendMessage(dest, resource, body, noerror, xhtml, autoResponse=autoResponse)
def __init__(self, pytrans, jabberID, username, password, ulang): """ Initialises the session object and connects to the legacy network """ jabw.JabberConnection.__init__(self, pytrans, jabberID) LogEvent(INFO, jabberID) self.pytrans = pytrans self.alive = True self.ready = False # Only ready when we're logged into the legacy service self.jabberID = jabberID # the JabberID of the Session's user self.username = username # the legacy network ID of the Session's user self.password = password self.nickname = "" self.avatar = None self.lang = ulang self.show = None self.status = None self.resourceList = {} self.groupchats = [] self.legacycon = legacy.LegacyConnection(self.username, self.password, self) self.contactList = contact.ContactList(self) self.contactList.legacyList = self.legacycon.legacyList if config.sessionGreeting: self.sendMessage(to=self.jabberID, fro=config.jid, body=config.sessionGreeting) self.updateNickname("") self.doVCardUpdate() LogEvent(INFO, self.jabberID, "Created!")
def updateRegistration(self, incoming): # Grab the username, password ID = incoming.getAttribute("id") fro = incoming.getAttribute("from") LogEvent(INFO) source = internJID(fro).userhost() ulang = utils.getLang(incoming) username = None password = None for queryFind in incoming.elements(): if (queryFind.name == "query"): for child in queryFind.elements(): try: if (child.name == "username"): username = child.__str__() elif (child.name == "password"): password = child.__str__() elif (child.name == "remove"): # The user wants to unregister the transport! Gasp! LogEvent(INFO, "", "Unregistering.") try: self.removeRegInfo(source) self.successReply(incoming) except: self.xdbErrorReply(incoming) return LogEvent(INFO, "", "Unregistered!") return except AttributeError, TypeError: continue # Ignore any errors, we'll check everything below
def messageReceived(self, source, resource, dest, destr, mtype, body, noerror): if dest == config.jid: if body.lower().startswith("end"): LogEvent(INFO, self.jabberID, "Received 'end' request.") self.removeMe() return if not self.ready: self.sendNotReadyError(source, resource, dest, body) return # Sends the message to the legacy translator groupchat = self.findGroupchat(dest) if groupchat: # It's for a groupchat if destr and len(destr) > 0 and not noerror: self.sendErrorMessage(to=(source + "/" + resource), fro=dest, etype="cancel", condition="not-allowed", explanation=lang.get( self.lang).groupchatPrivateError, body=body) else: LogEvent(INFO, self.jabberID, "Groupchat.") groupchat.sendMessage(body, noerror) else: LogEvent(INFO, self.jabberID, "Message.") self.legacycon.sendMessage(dest, resource, body, noerror)
def updateAvatar(self, contact, iconData=None, md5Hash=None, numHash=None): if config.disableAvatars: return from glue import icq2jid if md5Hash: LogEvent(INFO, self.session.jabberID, "%s [M]%s" % (contact.lower(), binascii.hexlify(md5Hash))) elif numHash: LogEvent(INFO, self.session.jabberID, "%s [N]%d" % (contact.lower(), numHash)) c = self.session.contactList.findContact(icq2jid(contact)) if not c: #debug.log("Update setting default avatar for %s" %(contact)) jabContact = self.session.contactList.createContact( icq2jid(contact), "both") c = jabContact if iconData and (md5Hash or numHash): LogEvent(INFO, self.session.jabberID, "Update setting custom avatar for %s" % (contact)) try: # Debugging, keeps original icon pre-convert try: f = open( os.path.abspath(config.spooldir) + X + config.jid + X + "avatarsdebug" + X + contact + ".icondata", 'w') f.write(iconData) f.close() except: # This isn't important pass avatarData = avatar.AvatarCache().setAvatar( imgmanip.convertToPNG(iconData)) c.updateAvatar(avatarData, push=True) if not md5Hash: m = md5.new() m.update(iconData) md5Hash = m.digest() if not numHash: numHash = oscar.getIconSum(iconData) self.updateIconHashes(contact.lower(), avatarData.getImageHash(), binascii.hexlify(md5Hash), numHash) except: LogEvent( INFO, self.session.jabberID, "Whoa there, this image doesn't want to work. Lets leave it where it was..." ) else: if not c.avatar: LogEvent(INFO, self.session.jabberID, "Update setting default avatar for %s" % (contact)) if config.disableDefaultAvatar: c.updateAvatar(None, push=True) else: if contact[0].isdigit(): c.updateAvatar(glue.defaultICQAvatar, push=True) else: c.updateAvatar(glue.defaultAIMAvatar, push=True)
def readGroup(self, memberlist, parent=None): for member in memberlist: if isinstance(member, oscar.SSIGroup): LogEvent(INFO, self.session.jabberID, "Found group %s" % (member.name)) self.ssigroups.append(member) self.readGroup(member.users, parent=member) elif isinstance(member, oscar.SSIBuddy): if member.nick: unick, uenc = oscar.guess_encoding(member.nick, config.encoding) else: unick = None if parent: LogEvent( INFO, self.session.jabberID, "Found user %r (%r) from group %r" % (member.name, unick, parent.name)) else: LogEvent( INFO, self.session.jabberID, "Found user %r (%r) from master group" % (member.name, unick)) self.oscarcon.legacyList.updateSSIContact(member.name, nick=unick) if member.name[0].isdigit() and (not member.nick or member.name == member.nick): # Hrm, lets get that nick self.getnicknames.append(member.name) else: LogEvent(INFO, self.session.jabberID, "Found unknown SSI entity: %r" % member)
def iqAvatarReceived(el): if not self.alive: return LogEvent(INFO, self.jabberID) qtype = el.getAttribute("type") if qtype == "error": LogEvent( INFO, self.jabberID, "That didn't work, let's try an IQ-storage-based avatar") d = self.sendStorageAvatarRequest(to=self.jabberID, fro=config.jid) d.addCallback(storageAvatarReceived) d.addErrback(errback) query = None for e in el.elements(): if e.name == "query" and e.uri == globals.IQAVATAR: query = e break if not query: return for e in query.elements(): if e.name == "data" and self.avatarPri < 3: imageData = avatar.parseIQPhotoEl(e) if not imageData: errback(Exception("Invalid image data") ) # Possibly it wasn't in a supported format? self.avatar = self.pytrans.avatarCache.setAvatar(imageData) self.legacycon.updateAvatar(self.avatar) self.avatarPri = 3
def prepxhtml(s): # We need to convert the horrible mess that is AIM's # type of html into well-formed xhtml. Yikes! try: s=s.encode("utf-8","replace") LogEvent(INFO, msg="Got %r" % s) s = re.sub(">+",">",s) s = re.sub("<+","<",s) # Fix dangling ampersands s = re.sub("&([^; =&<>\"'\n]*[ =&<>\"'\n])",r"&\1",s) all_regex = re.compile('</?[^>]*>'); try: s=all_regex.sub(lower_element, s); except: LogEvent(INFO, msg="Unable to do lowercase stuff") font_regex = re.compile('<font [^>]*>',re.X); try: s=font_regex.sub(font_to_span, s); except: LogEvent(INFO, msg="Unable to do font-to-span stuff") s = re.sub("</?(html|HTML)[^>]*>","",s) #s = re.sub("<font [^>]*color=[\"']([^\"']*)[\"'][^>]*>(.*?)</font>",r"<span style='color: \1'>\2</span>",s) #s = re.sub("<FONT [^>]*color=[\"']([^\"']*)[\"'][^>]*>(.*?)</FONT>",r"<span style='color: \1'>\2</span>",s) # Get rid of tags not supported by xhtml #s = re.sub("</?(font|FONT)[^>]*>","",s) s = re.sub("<(/?)font",r"<\1span",s) s = re.sub("<(body|BODY) ?","<body xmlns='http://www.w3.org/1999/xhtml' ",s); #s = re.sub("</BODY>","</body>",s); #s = re.sub("<BR/?>","<br/>",s); #s = re.sub("<P ?([^>]*)>",r"<p \1>",s); #s = re.sub("</P>",r"</p>",s); #s = re.sub("<A ?([^>]*)>",r"<a \1>",s); #s = re.sub("</A>",r"</a>",s); #s = re.sub("<B ?([^>]*)>",r"<b \1>",s); #s = re.sub("</B>",r"</b>",s); #s = re.sub("<I ?([^>]*)>",r"<i \1>",s); #s = re.sub("</I>",r"</i>",s); #s = re.sub("<STRONG ?([^>]*)>",r"<strong \1>",s); #s = re.sub("</STRONG>",r"</strong>",s); # Attempt to reparse so we can make well-formed XML ms = microdom.parseString(s, beExtremelyLenient=True) ret = ms.toxml() # Remove the xml header ret = re.sub('<\?xml.*\?>', '', ret) # Make sure our root tag is properly namespaced ret = "<html xmlns=\""+globals.XHTML+"\">%s</html>"%ret; LogEvent(INFO, msg="Made %r" % ret) return ret.encode("utf-8","replace") except: LogEvent(INFO, msg="Failed") return None
def sendDiscoItemsResponse(self, to, ID, ulang, jid): """ Send a service discovery disco#items stanza to the given 'to'. 'jid' is the JID that was queried. """ LogEvent(INFO) iq = Element((None, "iq")) iq.attributes["type"] = "result" iq.attributes["from"] = jid iq.attributes["to"] = to if ID: iq.attributes["id"] = ID query = iq.addElement("query") query.attributes["xmlns"] = globals.DISCO_ITEMS searchjid = jid if jid.find('@') > 0: searchjid = "USER" for node in self.nodes.get(searchjid, []): handler, name, rootnode = self.nodes[jid][node] if rootnode: LogEvent(INFO, msg="Found node %r" % (node)) name = lang.get(name, ulang) item = query.addElement("item") item.attributes["jid"] = jid item.attributes["node"] = node item.attributes["name"] = name if searchjid == "USER": # Add any user specific items for hndl in self.userItemHandlers: hndl(jid, query) self.pytrans.send(iq)
def handleResourcePresence(self, source, resource, to, tor, priority, ptype, show, status, url): if ptype and ptype != "unavailable": return # Ignore presence errors, probes, etc if to.find('@') > 0: return # Ignore presence packets sent to users existing = self.resourceList.has_key(resource) if ptype == "unavailable": if existing: LogEvent(INFO, self.jabberID, "Resource gone offline") self.resourceOffline(resource) else: return # I don't know the resource, and they're leaving, so it's all good else: if not existing: LogEvent(INFO, self.jabberID, "Resource came online") self.contactList.resendLists("%s/%s" % (source, resource)) LogEvent(INFO, self.jabberID, "Setting status") self.resourceList[resource] = SessionResource( show, status, priority, url) highestActive = self.highestResource() if highestActive: # If we're the highest active resource, we should update the legacy service LogEvent(INFO, self.jabberID, "Updating status on legacy service") r = self.resourceList[highestActive] self.setStatus(r.show, r.status, r.url) else: LogEvent(INFO, self.jabberID, "Last resource died. Calling removeMe in 0 seconds") #reactor.callLater(0, self.removeMe) self.removeMe()
def incomingIq(self, el): itype = el.getAttribute("type") fro = el.getAttribute("from") froj = internJID(fro) to = el.getAttribute("to") ID = el.getAttribute("id") ulang = utils.getLang(el) LogEvent(INFO, msg="Looking for handler") node = None for child in el.elements(): xmlns = child.uri node = child.getAttribute("node") handled = False if child.name == "query" and xmlns == globals.DISCO_INFO: if node and self.commands.has_key(node) and itype == "get": self.sendCommandInfoResponse(to=fro, ID=ID, node=node, ulang=ulang) handled = True elif child.name == "query" and xmlns == globals.DISCO_ITEMS: if node and self.commands.has_key(node) and itype == "get": self.sendCommandItemsResponse(to=fro, ID=ID, node=node, ulang=ulang) handled = True elif child.name == "command" and xmlns == globals.COMMANDS: if node and self.commands.has_key(node) and (itype == "set" or itype == "error"): self.commands[node](el) handled = True if not handled: LogEvent(WARN, msg="Unknown Ad-Hoc command received") self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=xmlns, etype="cancel", condition="feature-not-implemented")
def componentConnected(self, xmlstream): LogEvent(INFO) self.xmlstream = xmlstream self.xmlstream.addObserver("/iq", self.iq.onIq) self.xmlstream.addObserver("/presence", self.onPresence) self.xmlstream.addObserver("/message", self.onMessage) self.xmlstream.addObserver("/bind", self.onBind) self.xmlstream.addObserver("/route", self.onRouteMessage) self.xmlstream.addObserver( "/error[@xmlns='http://etherx.jabber.org/streams']", self.streamError) if config.useXCP and config.compjid: pres = Element((None, "presence")) pres.attributes["to"] = "presence@-internal" pres.attributes["from"] = config.compjid x = pres.addElement("x") x.attributes["xmlns"] = globals.COMPPRESENCE x.attributes["xmlns:config"] = globals.CONFIG x.attributes["config:version"] = "1" x.attributes["protocol-version"] = "1.0" x.attributes["config-ns"] = legacy.url + "/component" self.send(pres) if config.useComponentBinding: LogEvent(INFO, msg="Component binding to %r" % config.jid) bind = Element((None, "bind")) bind.attributes["name"] = config.jid self.send(bind) if config.useRouteWrap: self.routewrap = 1 self.sendInvitations()
def renderHTTP(self, ctx): request = inevow.IRequest(ctx) username = request.getUser() password = request.getPassword() if not username or not password: return self._loginFailed(None, ctx) LogEvent(INFO, msg=repr(username)) jabberPort = 5222 port_sep = username.find("%") if port_sep != -1: jabberPort = int(username[port_sep + 1:]) username = username[0:port_sep] if username: try: j = internJID(username) except InvalidFormat: return self._loginFailed(None, ctx) jabberHost = j.host else: jabberHost = config.mainServer LogEvent(INFO, msg="Port = %r" % jabberPort) p = portal.Portal(XMPPRealm()) p.registerChecker(XMPPChecker(jabberHost, jabberPort, tryonce=1)) creds = credentials.UsernamePassword(username, password) return p.login(creds, None, IXMPPAvatar).addCallback( self._loginSucceeded, ctx).addErrback(self._loginFailed, ctx)
def sendErrorMessage(self, to, fro, etype, explanation, condition=None, body=None): if self.last_el.has_key(to) and self.last_el[to].attributes.has_key( "from"): LogEvent(INFO, self.jabberID, "Using pre-existing element") sendErrorMessage(self.pytrans, to=to, fro=self.last_el[to].attributes["to"], etype=etype, condition=condition, explanation=explanation, body=body, el=self.last_el[to]) del self.last_el[to] else: LogEvent(INFO, self.jabberID, "**NOT** Using pre-existing element") sendErrorMessage(self.pytrans, to=to, fro=fro, etype=etype, condition=condition, explanation=explanation, body=body)
def resourceOffline(self, resource): from glue import aim2jid LogEvent(INFO, self.session.jabberID) try: show = None status = None ptype = "unavailable" for c in self.legacyList.ssicontacts.keys(): LogEvent(INFO, self.session.jabberID, "Sending offline %r" % c) jid = aim2jid(c) self.session.sendPresence(to=self.session.jabberID + "/" + resource, fro=jid, ptype=ptype, show=show, status=status) self.session.sendPresence(to=self.session.jabberID + "/" + resource, fro=config.jid, ptype=ptype, show=show, status=status) except AttributeError: return
def updateSSIContact(self, contact, presence="unavailable", show=None, status=None, nick=None, ipaddr=None, lanipaddr=None, lanipport=None, aimprotocol=None, url=None): from glue import aim2jid LogEvent(INFO, self.session.jabberID) self.ssicontacts[contact.lower()] = { 'presence': presence, 'show': show, 'status': status, 'url': url, 'ipaddr': ipaddr, 'lanipaddr': lanipaddr, 'lanipport': lanipport, 'aimprotocol': aimprotocol } c = self.session.contactList.findContact(aim2jid(contact)) if not c: LogEvent(INFO, self.session.jabberID, "Update setting default avatar for %s" % (contact)) c = self.session.contactList.createContact(aim2jid(contact), "both") if not config.disableAvatars: if contact[0].isdigit(): c.updateAvatar(glue.defaultICQAvatar, push=False) else: c.updateAvatar(glue.defaultAIMAvatar, push=False) if not self.xdbcontacts.has_key(contact.lower()): self.xdbcontacts[contact.lower()] = {} if nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick) else: self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", contact) self.session.pytrans.xdb.setListEntry( "roster", self.session.jabberID, contact.lower(), payload=self.xdbcontacts[contact.lower()]) else: if nick and self.xdbcontacts[contact.lower()].get('nickname', '') != nick: self.xdbcontacts[contact.lower()]['nickname'] = nick c.updateNickname(nick, push=True) self.session.sendRosterImport(aim2jid(contact), "subscribe", "both", nick)
def initDone(self): if not hasattr(self, "session") or not self.session: LogEvent(INFO, msg="No session!") return self.requestSelfInfo().addCallback(self.gotSelfInfo) #self.requestSelfInfo() # experimenting with no callback self.requestSSI().addCallback(self.gotBuddyList) LogEvent(INFO, self.session.jabberID)
def sendAwayPresence(self, msg, user): from glue import aim2jid buddyjid = aim2jid(user.name) c = self.session.contactList.findContact(buddyjid) if not c: return ptype = None show = "away" status = oscar.dehtml(msg[1]) # Removes any HTML tags url = user.url if status != None: charset = "iso-8859-1" m = None if msg[0]: m = re.search('charset="(.+)"', msg[0]) if m != None: charset = m.group(1) if charset == 'unicode-2-0': charset = 'utf-16be' elif charset == 'utf-8': pass elif charset == "us-ascii": charset = "iso-8859-1" else: LogEvent( INFO, self.session.jabberID, "Unknown charset (%s) of buddy's away message" % msg[0]) charset = "iso-8859-1" status = msg[0] + ": " + status status = status.decode(charset, 'replace') LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % (charset, msg[0], status)) if status == "Away" or status == "I am currently away from the computer." or status == "I am away from my computer right now.": status = "" if user.idleTime: if user.idleTime > 60 * 24: idle_time = "Idle %d days" % (user.idleTime / (60 * 24)) elif user.idleTime > 60: idle_time = "Idle %d hours" % (user.idleTime / (60)) else: idle_time = "Idle %d minutes" % (user.idleTime) if status: status = "%s - %s" % (idle_time, status) else: status = idle_time c.updatePresence(show=show, status=status, ptype=ptype) self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status, url=url)
def setItem(self, jid, node, itemid, el): """ Writes an item to disk according to its jid, node, and itemid. Returns nothing. """ LogEvent(INFO) prev_umask = os.umask(SPOOL_UMASK) try: f = open(self.dir(jid, node) + itemid + ".xml", 'wb') f.write(el.toXml()) f.close() except IOError, e: LogEvent(WARN, msg="IOError writing to node %r - %r" % (jid, node))
def removeRegInfo(self, jabberID): LogEvent(INFO) try: # If the session is active then send offline presences session = self.pytrans.sessions[jabberID] session.removeMe() except KeyError: pass self.pytrans.xdb.remove(jabberID) LogEvent(INFO, "", "done")
def inviteUser(self, userHandle): """ Used to invite a contact to the groupchat. Can be called immediately after instantiation. """ userHandle = str(userHandle) if self.ready: LogEvent(INFO, self.ident, "immediate") msn.SwitchboardClient.inviteUser(self, userHandle) else: LogEvent(INFO, self.ident, "pending") self.funcBuffer.append( lambda: msn.SwitchboardClient.inviteUser(self, userHandle))
def presenceReceived(self, source, resource, to, tor, priority, ptype, show, status, url=None): # Checks resources and priorities so that the highest priority resource always appears as the # legacy services status. If there are no more resources then the session is deleted # Additionally checks if the presence is to a groupchat room groupchat = self.findGroupchat(to) if groupchat: # It's for a groupchat if ptype == "unavailable": # Kill the groupchat LogEvent(INFO, self.jabberID, "Killing groupchat") groupchat.removeMe() else: if source == self.jabberID: if ptype == "error": groupchat.removeMe() else: groupchat.userJoined(tor) else: LogEvent(INFO, self.jabberID, "User not allowed") self.sendPresence(to=(source + "/" + resource), fro=to, ptype="error") elif legacy.isGroupJID( to ) and to != config.confjid and to != config.jid and not ptype: # Its to a groupchat JID, and the presence type is available if not self.ready: self.sendNotReadyError(source, resource, to, to) return # It's a new groupchat gcID = to[:to.find('@')] # Grab the room name LogEvent(INFO, self.jabberID, "Creating groupchat") groupchat = legacy.LegacyGroupchat( self, resource, gcID) # Creates an empty groupchat groupchat.userJoined(tor) elif ptype == 'probe': LogEvent(INFO, self.jabberID, "Responding to presence probe") if to == config.jid: self.legacycon.sendShowStatus(source) else: self.contactList.getContact(to).sendPresence(source) else: self.handleResourcePresence(source, resource, to, tor, priority, ptype, show, status, url)
def addContact(self, userHandle): LogEvent(INFO, self.session.jabberID) def cb(arg=None): self.updatePresence(userHandle, "subscribed") try: for g in self.bos.ssigroups: for u in g.users: aimHandle = self.aim2uhandle(u.name) if aimHandle == userHandle: if not u.authorizationRequestSent and not u.authorized: self.bos.sendAuthorizationRequest( userHandle, "Please authorize me!") u.authorizationRequestSent = True return else: cb() return savethisgroup = None groupName = "PyAIM-t Buddies" for g in self.bos.ssigroups: if g.name == groupName: LogEvent(INFO, self.session.jabberID, "Located group %s" % (g.name)) savethisgroup = g if savethisgroup is None: LogEvent(INFO, self.session.jabberID, "Adding new group") newGroupID = self.generateGroupID() newGroup = oscar.SSIGroup(groupName, newGroupID, 0) self.bos.startModifySSI() self.bos.addItemSSI(newGroup) self.bos.endModifySSI() savethisgroup = newGroup self.bos.ssigroups.append(newGroup) group = self.findGroupByName(groupName) newUserID = self.generateBuddyID(group.groupID) newUser = oscar.SSIBuddy(userHandle, group.groupID, newUserID) savethisgroup.addUser(newUserID, newUser) LogEvent(INFO, self.session.jabberID, "Adding item to SSI") self.bos.startModifySSI() self.bos.addItemSSI(newUser) self.bos.modifyItemSSI(savethisgroup) self.bos.endModifySSI() self.legacyList.updateSSIContact(userHandle) self.updatePresence(userHandle, "subscribe") except AttributeError: self.alertUser(lang.get("sessionnotactive", config.jid))
def main(): app = App() if config.webport: try: from nevow import appserver import web site = appserver.NevowSite(web.WebInterface(pytrans=app.transportSvc)) reactor.listenTCP(config.webport, site) LogEvent(INFO, msg="Web interface activated") except: LogEvent(WARN, msg="Unable to start web interface. Either Nevow is not installed or you need a more recent version of Twisted. (>= 2.0.0.0)") reactor.run()
def onMessage(self, el): """ Handles incoming message packets """ if not self.checkFrom(el): return LogEvent(INFO, self.jabberID) fro = el.getAttribute("from") to = el.getAttribute("to") try: froj = internJID(fro) toj = internJID(to) except Exception, e: LogEvent(WARN, self.jabberID) return
def getItem(self, jid, node, itemid): """ Loads the item from a node from disk and returns an element """ try: filename = self.dir(jid, node) + itemid + ".xml" if os.path.isfile(filename): LogEvent(INFO, msg="Getting item %r - %r" % (node, itemid)) document = utils.parseFile(filename) return document else: LogEvent(INFO, msg="Avatar not found %r" % (key)) except IOError, e: LogEvent(INFO, msg="IOError reading item %r - %r" % (node, itemid))
def __init__(self): LogEvent(INFO) LogEvent(INFO, msg="Reactor: " + str(reactor)) # Discovery, as well as some builtin features self.discovery = disco.ServerDiscovery(self) 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") self.discovery.addIdentity("conference", "text", "MSN Groupchat", "ROOM") self.xdb = xdb.XDB(config.jid, legacy.mangle) self.avatarCache = avatar.AvatarCache() self.registermanager = register.RegisterManager(self) self.gatewayTranslator = misciq.GatewayTranslator(self) self.versionTeller = misciq.VersionTeller(self) self.pingService = misciq.PingService(self) self.adHocCommands = misciq.AdHocCommands(self) self.vCardFactory = misciq.VCardFactory(self) self.iqAvatarFactor = misciq.IqAvatarFactory(self) self.connectUsers = misciq.ConnectUsers(self) if config.ftJabberPort: self.ftSOCKS5Receive = ft.Proxy65(int(config.ftJabberPort)) self.ftSOCKS5Send = misciq.Socks5FileTransfer(self) if config.ftOOBPort: self.ftOOBReceive = ft.FileTransferOOBReceive(int( config.ftOOBPort)) self.ftOOBSend = misciq.FileTransferOOBSend(self) self.statistics = misciq.Statistics(self) self.startTime = int(time.time()) self.xmlstream = None self.sessions = {} # Groupchat ID handling self.lastID = 0 self.reservedIDs = [] # Message IDs self.messageID = 0 self.loopTask = task.LoopingCall(self.loopFunc) self.loopTask.start(60.0)
def receivedIconUploadRequest(self, iconhash): if config.disableAvatars: return LogEvent(INFO, self.session.jabberID, "%s" % binascii.hexlify(iconhash)) if hasattr(self.oscarcon, "myavatar"): LogEvent( INFO, self.session.jabberID, "I have an icon, sending it on, %d" % len(self.oscarcon.myavatar)) self.uploadBuddyIconToServer( self.oscarcon.myavatar, len(self.oscarcon.myavatar)).addCallback( self.uploadedBuddyIconToServer)
def serverDiscoInfoReceived(el): if not self.alive: return LogEvent(INFO, self.jabberID) fro = el.getAttribute("from") for e in el.elements(): if e.name == "query" and e.uri == globals.DISCO_INFO: for item in e.elements(): if item.name == "feature": var = item.getAttribute("var") self.capabilities.append(var) LogEvent( INFO, self.jabberID, "Capabilities of %r:\n\t%s" % (fro, "\n\t".join(self.capabilities)))
def makeSession(pytrans, jabberID, ulang, rosterID): """ Tries to create a session object for the corresponding JabberID. Retrieves information from XDB to create the session. If it fails, then the user is most likely not registered with the transport """ LogEvent(INFO, jabberID) if pytrans.sessions.has_key(jabberID): LogEvent(INFO, jabberID, "Removing existing session") pytrans.sessions[jabberID].removeMe() result = pytrans.xdb.getRegistration(jabberID) if result: username, password = result return Session(pytrans, jabberID, username, password, ulang, rosterID) else: return None