def handleLastOnline(self, node, jid=None): firstChild = node.getChild(0) ProtocolTreeNode.require(firstChild, 'query') seconds = firstChild.getAttributeValue('seconds') status = None status = firstChild.data if seconds is not None and jid is not None: self.connection.event.lastSeenUpdated.emit(int(seconds), jid)
def handleGroupInfo(self,node,jid): groupNode = node.getChild(0) ProtocolTreeNode.require(groupNode,"group") gid = groupNode.getAttributeValue("id") owner = groupNode.getAttributeValue("owner") subject = groupNode.getAttributeValue("subject") subjectT = groupNode.getAttributeValue("s_t") subjectOwner = groupNode.getAttributeValue("s_o") creation = groupNode.getAttributeValue("creation") self.eventHandler.onGroupInfo(jid,owner,subject,subjectOwner,int(subjectT),int(creation))
def handleLastOnline(self,node,jid=None): firstChild = node.getChild(0); ProtocolTreeNode.require(firstChild,"query"); seconds = firstChild.getAttributeValue("seconds"); status = None status = firstChild.data try: if seconds is not None and jid is not None: self.eventHandler.onLastSeen(jid,int(seconds),status); except: self._d("Ignored exception in handleLastOnline "+ sys.exc_info()[1])
def handleLastOnline(self, node, jid=None): firstChild = node.getChild(0) ProtocolTreeNode.require(firstChild, "query") seconds = firstChild.getAttributeValue("seconds") status = None status = firstChild.data try: if seconds is not None and jid is not None: self.eventHandler.onLastSeen(jid, int(seconds), status) except: print "Ignored exception in handleLastOnline " + sys.exc_info()[1]
def readSuccess(self): node = self.inn.nextTree(); self._d("Login Status: %s"%(node.tag)); if ProtocolTreeNode.tagEquals(node,"failure"): self.loginFailed.emit() raise Exception("Login Failure"); ProtocolTreeNode.require(node,"success"); expiration = node.getAttributeValue("expiration"); if expiration is not None: self._d("Expires: "+str(expiration)); self.connection.expire_date = expiration; kind = node.getAttributeValue("kind"); self._d("Account type: %s"%(kind)) if kind == "paid": self.connection.account_kind = 1; elif kind == "free": self.connection.account_kind = 0; else: self.connection.account_kind = -1; status = node.getAttributeValue("status"); self._d("Account status: %s"%(status)); if status == "expired": self.loginFailed.emit() raise Exception("Account expired on "+str(self.connection.expire_date)); if status == "active": if expiration is None: #raise Exception ("active account with no expiration"); '''@@TODO expiration changed to creation''' else: self.connection.account_kind = 1; self.inn.inn.buf = []; self.loginSuccess.emit()
def readSuccess(self): node = self.inn.nextTree() Utilities.debug("Login Status: " + node.tag) if ProtocolTreeNode.tagEquals(node, "failure"): self.loginFailed.emit() raise Exception("Login Failure") ProtocolTreeNode.require(node, "success") expiration = node.getAttributeValue("expiration") if expiration is not None: Utilities.debug("Expires: " + str(expiration)) self.connection.expire_date = expiration kind = node.getAttributeValue("kind") Utilities.debug("Account type: " + kind) if kind == "paid": self.connection.account_kind = 1 elif kind == "free": self.connection.account_kind = 0 else: self.connection.account_kind = -1 status = node.getAttributeValue("status") Utilities.debug("Account status: " + status) if status == "expired": self.loginFailed.emit() raise Exception("Account expired on " + str(self.connection.expire_date)) if status == "active": if expiration is None: #raise Exception ("active account with no expiration"); '''@@TODO expiration changed to creation''' else: self.connection.account_kind = 1 self.inn.inn.buf = [] self.loginSuccess.emit()
def readSuccess(self): node = self.inn.nextTree() Utilities.debug("Login Status: " + node.tag) if ProtocolTreeNode.tagEquals(node, "failure"): self.loginFailed.emit() raise Exception("Login Failure") ProtocolTreeNode.require(node, "success") expiration = node.getAttributeValue("expiration") if expiration is not None: Utilities.debug("Expires: " + str(expiration)) self.connection.expire_date = expiration kind = node.getAttributeValue("kind") Utilities.debug("Account type: " + kind) if kind == "paid": self.connection.account_kind = 1 elif kind == "free": self.connection.account_kind = 0 else: self.connection.account_kind = -1 status = node.getAttributeValue("status") Utilities.debug("Account status: " + status) if status == "expired": self.loginFailed.emit() raise Exception("Account expired on " + str(self.connection.expire_date)) if status == "active": if expiration is None: # raise Exception ("active account with no expiration"); """@@TODO expiration changed to creation""" else: self.connection.account_kind = 1 self.inn.inn.buf = [] self.loginSuccess.emit()
def readSuccess(self): node = self.inn.nextTree() if ProtocolTreeNode.tagEquals(node, 'failure'): self.connection.event.loginFailed.emit() raise LoginException('Login Failure') ProtocolTreeNode.require(node, 'success') expiration = node.getAttributeValue('expiration') if expiration is not None: self.connection.expire_date = expiration kind = node.getAttributeValue('kind') if kind == 'paid': self.connection.account_kind = 1 elif kind == 'free': self.connection.account_kind = 0 else: self.connection.account_kind = -1 status = node.getAttributeValue('status') if status == 'expired': self.connection.event.loginFailed.emit() raise LoginException('Account expired on ' + str(self.connection.expire_date)) if status == 'active': if expiration is None: pass else: self.connection.account_kind = 1 self.inn.inn.buf = [] self.connection.event.loginSuccess.emit()
def run(self): flag = True; self._d("Read thread started"); while flag == True: self._d("waiting"); ready = select.select([self.inn.rawIn], [], []) if ready[0]: try: node = self.inn.nextTree(); except ConnectionClosedException: self._d("Socket closed, got 0 bytes") if self.eventHandler.connMonitor.isOnline(): self.eventHandler.connMonitor.connected.emit() return except: self._d("Unhandled error: %s .restarting connection " % sys.exc_info()[1]) if self.eventHandler.connMonitor.isOnline(): self.eventHandler.connMonitor.connected.emit() else: self._d("Not online, aborting restart") return self.lastTreeRead = int(time.time())*1000; if node is not None: if ProtocolTreeNode.tagEquals(node,"iq"): iqType = node.getAttributeValue("type") idx = node.getAttributeValue("id") jid = node.getAttributeValue("from"); if iqType is None: raise Exception("iq doesn't have type") if iqType == "result": if self.requests.has_key(idx): self.requests[idx](node,jid) del self.requests[idx] elif idx.startswith(self.connection.user): accountNode = node.getChild(0) ProtocolTreeNode.require(accountNode,"account") kind = accountNode.getAttributeValue("kind") if kind == "paid": self.connection.account_kind = 1 elif kind == "free": self.connection.account_kind = 0 else: self.connection.account_kind = -1 expiration = accountNode.getAttributeValue("expiration") if expiration is None: raise Exception("no expiration") try: self.connection.expire_date = long(expiration) except ValueError: raise IOError("invalid expire date %s"%(expiration)) self.eventHandler.onAccountChanged(self.connection.account_kind,self.connection.expire_date) elif iqType == "error": if self.requests.has_key(idx): self.requests[idx](node) del self.requests[idx] elif iqType == "get": childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode,"ping"): self.eventHandler.onPing(idx) elif ProtocolTreeNode.tagEquals(childNode,"query") and jid is not None and "http://jabber.org/protocol/disco#info" == childNode.getAttributeValue("xmlns"): pin = childNode.getAttributeValue("pin"); timeoutString = childNode.getAttributeValue("timeout"); try: timeoutSeconds = int(timeoutString) if timoutString is not None else None except ValueError: raise Exception("relay-iq exception parsing timeout %s "%(timeoutString)) if pin is not None: self.eventHandler.onRelayRequest(pin,timeoutSeconds,idx) elif iqType == "set": childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode,"query"): xmlns = childNode.getAttributeValue("xmlns") if xmlns == "jabber:iq:roster": itemNodes = childNode.getAllChildren("item"); ask = "" for itemNode in itemNodes: jid = itemNode.getAttributeValue("jid") subscription = itemNode.getAttributeValue("subscription") ask = itemNode.getAttributeValue("ask") else: raise Exception("Unkown iq type %s"%(iqType)) elif ProtocolTreeNode.tagEquals(node,"presence"): xmlns = node.getAttributeValue("xmlns") jid = node.getAttributeValue("from") if (xmlns is None or xmlns == "urn:xmpp") and jid is not None: presenceType = node.getAttributeValue("type") if presenceType == "unavailable": self.eventHandler.presence_unavailable_received(jid); elif presenceType is None or presenceType == "available": self.eventHandler.presence_available_received(jid); elif xmlns == "w" and jid is not None: add = node.getAttributeValue("add"); remove = node.getAttributeValue("remove") status = node.getAttributeValue("status") if add is not None: self._d("GROUP EVENT ADD") elif remove is not None: self._d("GROUP EVENT REMOVE") elif status == "dirty": categories = self.parseCategories(node); self.eventHandler.onDirty(categories); elif ProtocolTreeNode.tagEquals(node,"message"): self.parseMessage(node) '''
def run(self): while True: if self.connection.disconnectRequested: self.connection.conn.close() break ready = select.select([self.inn.rawIn], [], []) if ready[0]: try: node = self.inn.nextTree() except Exception, e: self.connection.event.reconnecting.emit() self.connection.login() return self.lastTreeRead = int(time.time()) * 1000 if node is not None: # print node.toString() if ProtocolTreeNode.tagEquals(node, 'iq'): iqType = node.getAttributeValue('type') idx = node.getAttributeValue('id') jid = node.getAttributeValue('from') if iqType is None: raise Exception("iq doesn't have type") if iqType == 'result': if self.requests.has_key(idx): self.requests[idx](node, jid) del self.requests[idx] elif jid == 'g.us': children = node.getAllChildren() if len(children) > 0: # List of groups received if ProtocolTreeNode.tagEquals(children[0], 'group'): self.connection.event.groupsReceived(map(lambda c: { 'subject': c.getAttributeValue('subject'), 'owner': c.getAttributeValue('owner'), 'id': c.getAttributeValue('id') }, children)) elif idx.startswith(self.connection.user): accountNode = node.getChild(0) ProtocolTreeNode.require(accountNode, 'account') kind = accountNode.getAttributeValue('kind') if kind == 'paid': self.connection.account_kind = 1 elif kind == 'free': self.connection.account_kind = 0 else: self.connection.account_kind = -1 expiration = accountNode.getAttributeValue('expiration') if expiration is None: raise Exception('no expiration') try: self.connection.expire_date = long(expiration) except ValueError: raise IOError('invalid expire date %s'% expiration) self.connection.event.onAccountChanged(self.connection.account_kind, self.connection.expire_date) elif iqType == 'error': if self.requests.has_key(idx): self.requests[idx](node) del self.requests[idx] elif iqType == 'get': childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, 'ping'): self.connection.event.onPing(idx) elif ProtocolTreeNode.tagEquals(childNode, 'query') and jid is not None \ and 'http://jabber.org/protocol/disco#info' \ == childNode.getAttributeValue('xmlns'): pin = childNode.getAttributeValue('pin') timeoutString = childNode.getAttributeValue('timeout') try: timeoutSeconds = (int(timeoutString) if timoutString is not None else None) except ValueError: raise Exception('relay-iq exception parsing timeout %s ' % timeoutString) if pin is not None: self.connection.event.onRelayRequest(pin, timeoutSeconds, idx) elif iqType == 'set': childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, 'query'): xmlns = childNode.getAttributeValue('xmlns') if xmlns == 'jabber:iq:roster': itemNodes = childNode.getAllChildren('item') ask = '' for itemNode in itemNodes: jid = itemNode.getAttributeValue('jid') subscription = itemNode.getAttributeValue('subscription') ask = itemNode.getAttributeValue('ask') else: raise Exception('Unkown iq type %s' % iqType) elif ProtocolTreeNode.tagEquals(node, 'presence'): xmlns = node.getAttributeValue('xmlns') jid = node.getAttributeValue('from') if (xmlns is None or xmlns == 'urn:xmpp') and jid is not None: presenceType = node.getAttributeValue('type') if presenceType == 'unavailable': self.connection.event.presence_unavailable_received(jid) elif presenceType is None or presenceType \ == 'available': self.connection.event.presence_available_received(jid) elif xmlns == 'w' and jid is not None: add = node.getAttributeValue('add') remove = node.getAttributeValue('remove') status = node.getAttributeValue('status') if add is not None: self.connection.event.groupAdd(jid.split('-')[-1], add) elif remove is not None: self.connection.event.groupRemove(jid.split('-')[-1], remove) elif status == 'dirty': categories = self.parseCategories(node) self.connection.event.onDirty(categories) elif ProtocolTreeNode.tagEquals(node, 'message'): self.parseMessage(node)
def run(self): flag = True Utilities.debug("Read thread started") while flag == True: Utilities.debug("waiting") ready = select.select([self.inn.rawIn], [], []) if ready[0]: try: node = self.inn.nextTree() except ConnectionClosedException: print "Socket closed, got 0 bytes" if self.eventHandler.connMonitor.isOnline(): self.eventHandler.connMonitor.connected.emit() return except: print "Unhandled error: %s .restarting connection " % sys.exc_info( )[1] if self.eventHandler.connMonitor.isOnline(): self.eventHandler.connMonitor.connected.emit() else: print "Not online, aborting restart" return self.lastTreeRead = int(time.time()) * 1000 if node is not None: if ProtocolTreeNode.tagEquals(node, "iq"): iqType = node.getAttributeValue("type") idx = node.getAttributeValue("id") jid = node.getAttributeValue("from") if iqType is None: raise Exception("iq doesn't have type") if iqType == "result": if self.requests.has_key(idx): self.requests[idx](node, jid) del self.requests[idx] elif idx.startswith(self.connection.user): accountNode = node.getChild(0) ProtocolTreeNode.require( accountNode, "account") kind = accountNode.getAttributeValue("kind") if kind == "paid": self.connection.account_kind = 1 elif kind == "free": self.connection.account_kind = 0 else: self.connection.account_kind = -1 expiration = accountNode.getAttributeValue( "expiration") if expiration is None: raise Exception("no expiration") try: self.connection.expire_date = long( expiration) except ValueError: raise IOError("invalid expire date %s" % (expiration)) self.eventHandler.onAccountChanged( self.connection.account_kind, self.connection.expire_date) elif iqType == "error": if self.requests.has_key(idx): self.requests[idx](node) del self.requests[idx] elif iqType == "get": childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, "ping"): self.eventHandler.onPing(idx) elif ProtocolTreeNode.tagEquals( childNode, "query" ) and jid is not None and "http://jabber.org/protocol/disco#info" == childNode.getAttributeValue( "xmlns"): pin = childNode.getAttributeValue("pin") timeoutString = childNode.getAttributeValue( "timeout") try: timeoutSeconds = int( timeoutString ) if timoutString is not None else None except ValueError: raise Exception( "relay-iq exception parsing timeout %s " % (timeoutString)) if pin is not None: self.eventHandler.onRelayRequest( pin, timeoutSeconds, idx) elif iqType == "set": childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, "query"): xmlns = childNode.getAttributeValue("xmlns") if xmlns == "jabber:iq:roster": itemNodes = childNode.getAllChildren( "item") ask = "" for itemNode in itemNodes: jid = itemNode.getAttributeValue("jid") subscription = itemNode.getAttributeValue( "subscription") ask = itemNode.getAttributeValue("ask") else: raise Exception("Unkown iq type %s" % (iqType)) elif ProtocolTreeNode.tagEquals(node, "presence"): xmlns = node.getAttributeValue("xmlns") jid = node.getAttributeValue("from") if (xmlns is None or xmlns == "urn:xmpp") and jid is not None: presenceType = node.getAttributeValue("type") if presenceType == "unavailable": self.eventHandler.presence_unavailable_received( jid) elif presenceType is None or presenceType == "available": self.eventHandler.presence_available_received( jid) elif xmlns == "w" and jid is not None: add = node.getAttributeValue("add") remove = node.getAttributeValue("remove") status = node.getAttributeValue("status") if add is not None: print "GROUP EVENT ADD" elif remove is not None: print "GROUP EVENT REMOVE" elif status == "dirty": categories = self.parseCategories(node) self.eventHandler.onDirty(categories) elif ProtocolTreeNode.tagEquals(node, "message"): self.parseMessage(node) '''
def run(self): while True: if self.connection.disconnectRequested: self.connection.conn.close() break ready = select.select([self.inn.rawIn], [], []) if ready[0]: try: node = self.inn.nextTree() except Exception, e: self.connection.event.reconnecting.emit() self.connection.login() return self.lastTreeRead = int(time.time()) * 1000 if node is not None: # print node.toString() if ProtocolTreeNode.tagEquals(node, 'iq'): iqType = node.getAttributeValue('type') idx = node.getAttributeValue('id') jid = node.getAttributeValue('from') if iqType is None: raise Exception("iq doesn't have type") if iqType == 'result': if self.requests.has_key(idx): self.requests[idx](node, jid) del self.requests[idx] elif jid == 'g.us': children = node.getAllChildren() if len(children) > 0: # List of groups received if ProtocolTreeNode.tagEquals( children[0], 'group'): self.connection.event.groupsReceived( map( lambda c: { 'subject': c.getAttributeValue( 'subject'), 'owner': c.getAttributeValue('owner' ), 'id': c.getAttributeValue('id') }, children)) elif idx.startswith(self.connection.user): accountNode = node.getChild(0) ProtocolTreeNode.require( accountNode, 'account') kind = accountNode.getAttributeValue('kind') if kind == 'paid': self.connection.account_kind = 1 elif kind == 'free': self.connection.account_kind = 0 else: self.connection.account_kind = -1 expiration = accountNode.getAttributeValue( 'expiration') if expiration is None: raise Exception('no expiration') try: self.connection.expire_date = long( expiration) except ValueError: raise IOError('invalid expire date %s' % expiration) self.connection.event.onAccountChanged( self.connection.account_kind, self.connection.expire_date) elif iqType == 'error': if self.requests.has_key(idx): self.requests[idx](node) del self.requests[idx] elif iqType == 'get': childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, 'ping'): self.connection.event.onPing(idx) elif ProtocolTreeNode.tagEquals(childNode, 'query') and jid is not None \ and 'http://jabber.org/protocol/disco#info' \ == childNode.getAttributeValue('xmlns'): pin = childNode.getAttributeValue('pin') timeoutString = childNode.getAttributeValue( 'timeout') try: timeoutSeconds = (int(timeoutString) if timoutString is not None else None) except ValueError: raise Exception( 'relay-iq exception parsing timeout %s ' % timeoutString) if pin is not None: self.connection.event.onRelayRequest( pin, timeoutSeconds, idx) elif iqType == 'set': childNode = node.getChild(0) if ProtocolTreeNode.tagEquals(childNode, 'query'): xmlns = childNode.getAttributeValue('xmlns') if xmlns == 'jabber:iq:roster': itemNodes = childNode.getAllChildren( 'item') ask = '' for itemNode in itemNodes: jid = itemNode.getAttributeValue('jid') subscription = itemNode.getAttributeValue( 'subscription') ask = itemNode.getAttributeValue('ask') else: raise Exception('Unkown iq type %s' % iqType) elif ProtocolTreeNode.tagEquals(node, 'presence'): xmlns = node.getAttributeValue('xmlns') jid = node.getAttributeValue('from') if (xmlns is None or xmlns == 'urn:xmpp') and jid is not None: presenceType = node.getAttributeValue('type') if presenceType == 'unavailable': self.connection.event.presence_unavailable_received( jid) elif presenceType is None or presenceType \ == 'available': self.connection.event.presence_available_received( jid) elif xmlns == 'w' and jid is not None: add = node.getAttributeValue('add') remove = node.getAttributeValue('remove') status = node.getAttributeValue('status') if add is not None: self.connection.event.groupAdd( jid.split('-')[-1], add) elif remove is not None: self.connection.event.groupRemove( jid.split('-')[-1], remove) elif status == 'dirty': categories = self.parseCategories(node) self.connection.event.onDirty(categories) elif ProtocolTreeNode.tagEquals(node, 'message'): self.parseMessage(node)