def __onStanzaPresence(self, stanza): from_jid = getAttr(stanza, 'from').encode('utf8') user = jidAttr(from_jid, 'muc_user') presenceType = getAttr(stanza, 'type') if not presenceType: presenceType = 'available' self.eventUserOffline(user) if presenceType == 'unavailable' else self.eventUserOnline(user)
def __onStanzaPresence(self, stanza): from_jid = getAttr(stanza, 'from').encode('utf8') user = jidAttr(from_jid, 'muc_user') presenceType = getAttr(stanza, 'type') if not presenceType: presenceType = 'available' self.eventUserOffline( user) if presenceType == 'unavailable' else self.eventUserOnline( user)
def __onStanzaMessage(self, stanza): from_jid = getAttr(stanza, 'from').encode('utf-8') user = jidAttr(from_jid, 'muc_user') messageType = getAttr(stanza, 'type') if messageType == 'error': return body = getChild(stanza, 'body') if not body: return self.eventMessage(user, body['data'].encode('utf-8'))
def __onStateOnline(self, stanza): stanzaName = stanza['name'] stanzaFrom = getAttr(stanza, 'from') or u'' stanzaId = getAttr(stanza, 'id') or u'' bare_jid = jidAttr(stanzaFrom, 'bare') entity = self.entities.get(bare_jid) if entity: entity.onStanza(stanza) try: match = re.match(XMPPConnection.Connection.STANZA_ID_TEMPLATE, stanzaId) if match: self.tasks[int(match.group(1))].digest(stanza, int(match.group(2))) except: LOG_CURRENT_EXCEPTION() if stanzaName == 'stream:error': child = getChild(stanza, 'system-shutdown') if child: LOG_ERROR('XMPP: Stream error: %s' % stanza) self.__onServerDisconnected() return
def __onStateAuthenticating(self, stanza): stanzaName = stanza['name'] stanzaID = getAttr(stanza, 'id') stanzaType = getAttr(stanza, 'type') if stanzaName == 'challenge': self.__onStanzaAuthChallenge(stanza) elif stanzaName == 'success': self.connection.parser.newParser() self.connection.sendStanza(XMPPStanzas.STREAM_START % self.connection.host[0]) elif stanzaName == 'stream:features': self.connection.sendStanza(XMPPStanzas.BIND_RESOURCE % XMPPConnection.Connection.RESOURCE) elif stanzaName == 'iq': if stanzaType == 'result': if stanzaID == 'bind_2': self.connection.sendStanza(XMPPStanzas.SESSION) elif stanzaID == 'sess_1': self.__updateState(Client.STATE_ONLINE) self.eventConnected() self.connection.sendStanza(XMPPStanzas.presence()) else: LOG_ERROR('Unhandled stanza name:', stanzaName, stanza)
def __onStateOnline(self, stanza): stanzaName = stanza['name'] if not getAttr(stanza, 'from'): stanzaFrom = u'' if not getAttr(stanza, 'id'): stanzaId = u'' bare_jid = jidAttr(stanzaFrom, 'bare') entity = self.entities.get(bare_jid) if entity: entity.onStanza(stanza) try: match = re.match( XMPPConnection.Connection.STANZA_ID_TEMPLATE, stanzaId) if match: self.tasks[int(match.group(1))].digest( stanza, int(match.group(2))) except: LOG_CURRENT_EXCEPTION() child = stanzaName == 'stream:error' and getChild( stanza, 'system-shutdown') child and LOG_ERROR('XMPP: Stream error: %s' % stanza) self.__onServerDisconnected() return