def commandInfoQuery(self, con, iq_obj): """ Send disco#info result for query for command (JEP-0050, example 6.). Return True if the result was sent, False if not """ try: jid = helpers.get_full_jid_from_iq(iq_obj) except helpers.InvalidFormat: log.warning('Invalid JID: %s, ignoring it' % iq_obj.getFrom()) return node = iq_obj.getTagAttr('query', 'node') if node not in self.__commands: return False cmd = self.__commands[node] if cmd.isVisibleFor(self.isSameJID(jid)): iq = iq_obj.buildReply('result') q = iq.getTag('query') q.addChild('identity', attrs={ 'type': 'command-node', 'category': 'automation', 'name': cmd.commandname }) q.addChild('feature', attrs={'var': nbxmpp.NS_COMMANDS}) for feature in cmd.commandfeatures: q.addChild('feature', attrs={'var': feature}) self.connection.send(iq) return True return False
def commandInfoQuery(self, con, iq_obj): """ Send disco#info result for query for command (JEP-0050, example 6.). Return True if the result was sent, False if not """ try: jid = helpers.get_full_jid_from_iq(iq_obj) except helpers.InvalidFormat: log.warning('Invalid JID: %s, ignoring it' % iq_obj.getFrom()) return node = iq_obj.getTagAttr('query', 'node') if node not in self.__commands: return False cmd = self.__commands[node] if cmd.isVisibleFor(self.isSameJID(jid)): iq = iq_obj.buildReply('result') q = iq.getTag('query') q.addChild('identity', attrs = {'type': 'command-node', 'category': 'automation', 'name': cmd.commandname}) q.addChild('feature', attrs = {'var': nbxmpp.NS_COMMANDS}) for feature in cmd.commandfeatures: q.addChild('feature', attrs = {'var': feature}) self.connection.send(iq) return True return False
def _nec_raw_message(self, obj): if not HAS_GOOCANVAS: return if obj.stanza.getTag('sxe', namespace=NS_SXE): account = obj.conn.name try: fjid = helpers.get_full_jid_from_iq(obj.stanza) except helpers.InvalidFormat: obj.conn.dispatch('ERROR', (_('Invalid Jabber ID'), _('A message from a non-valid JID arrived, it has been ' 'ignored.'))) jid = gajim.get_jid_without_resource(fjid) ctrl = (gajim.interface.msg_win_mgr.get_control(fjid, account) or gajim.interface.msg_win_mgr.get_control(jid, account)) if not ctrl: return sxe = obj.stanza.getTag('sxe') if not sxe: return sid = sxe.getAttr('session') if (jid, sid) not in obj.conn._sessions: pass # newjingle = JingleSession(con=self, weinitiate=False, jid=jid, sid=sid) # self.addJingle(newjingle) # we already have such session in dispatcher... session = obj.conn.get_jingle_session(fjid, sid) cn = session.contents[('initiator', 'xhtml')] error = obj.stanza.getTag('error') if error: action = 'iq-error' else: action = 'edit' cn.on_stanza(obj.stanza, sxe, error, action) # def __editCB(self, stanza, content, error, action): #new_tags = sxe.getTags('new') #remove_tags = sxe.getTags('remove') #if new_tags is not None: ## Process new elements #for tag in new_tags: #if tag.getAttr('type') == 'element': #ctrl.whiteboard.recieve_element(tag) #elif tag.getAttr('type') == 'attr': #ctrl.whiteboard.recieve_attr(tag) #ctrl.whiteboard.apply_new() #if remove_tags is not None: ## Delete rids #for tag in remove_tags: #target = tag.getAttr('target') #ctrl.whiteboard.image.del_rid(target) # Stop propagating this event, it's handled return True
def generate(self): msg_type = self.base_event.stanza.attrs.get("type", None) if msg_type == u"chat": self.stanza = self.base_event.stanza self.conn = self.base_event.conn self.from_jid = helpers.get_full_jid_from_iq(self.stanza) self.from_jid_without_resource = gajim.get_jid_without_resource(self.from_jid) self.account = self.conn.name self.from_nickname = gajim.get_contact_name_from_jid(self.account, self.from_jid_without_resource) self.msg_text = "".join(self.stanza.kids[0].data) return True return False
def _JingleCB(self, con, stanza): """ The jingle stanza dispatcher Route jingle stanza to proper JingleSession object, or create one if it is a new session. TODO: Also check if the stanza isn't an error stanza, if so route it adequatelly. """ # get data try: jid = helpers.get_full_jid_from_iq(stanza) except helpers.InvalidFormat: logger.warning('Invalid JID: %s, ignoring it', stanza.getFrom()) return id_ = stanza.getID() if (jid, id_) in self.__iq_responses.keys(): self.__iq_responses[(jid, id_)].on_stanza(stanza) del self.__iq_responses[(jid, id_)] raise nbxmpp.NodeProcessed jingle = stanza.getTag('jingle') # a jingle element is not necessary in iq-result stanza # don't check for that if jingle: sid = jingle.getAttr('sid') else: sid = None for sesn in self._sessions.values(): if id_ in sesn.iq_ids: sesn.on_stanza(stanza) return # do we need to create a new jingle object if sid not in self._sessions: #TODO: tie-breaking and other things... newjingle = JingleSession(con=self, weinitiate=False, jid=jid, iq_id=id_, sid=sid) self._sessions[sid] = newjingle # we already have such session in dispatcher... self._sessions[sid].collect_iq_id(id_) self._sessions[sid].on_stanza(stanza) # Delete invalid/unneeded sessions if sid in self._sessions and \ self._sessions[sid].state == JingleStates.ENDED: self.delete_jingle_session(sid) raise nbxmpp.NodeProcessed
def _bytestreamErrorCB(self, con, iq_obj): id_ = unicode(iq_obj.getAttr('id')) frm = helpers.get_full_jid_from_iq(iq_obj) query = iq_obj.getTag('query') gajim.proxy65_manager.error_cb(frm, query) jid = helpers.get_jid_from_iq(iq_obj) id_ = id_[3:] file_props = FilesProp.getFilePropBySid(id_) if not file_props: return file_props.error = -4 from common.connection_handlers_events import FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=jid, file_props=file_props, error_msg='')) raise nbxmpp.NodeProcessed
def _bytestreamErrorCB(self, con, iq_obj): id_ = iq_obj.getAttr('id') frm = helpers.get_full_jid_from_iq(iq_obj) query = iq_obj.getTag('query') gajim.proxy65_manager.error_cb(frm, query) jid = helpers.get_jid_from_iq(iq_obj) id_ = id_[3:] file_props = FilesProp.getFilePropBySid(id_) if not file_props: return file_props.error = -4 from common.connection_handlers_events import FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=jid, file_props=file_props, error_msg='')) raise nbxmpp.NodeProcessed
def generate(self): msg_type = self.base_event.stanza.attrs.get('type', None) if msg_type == u'chat': self.stanza = self.base_event.stanza self.conn = self.base_event.conn self.from_jid = helpers.get_full_jid_from_iq(self.stanza) self.from_jid_without_resource = gajim.get_jid_without_resource( self.from_jid) self.account = self.conn.name self.from_nickname = gajim.get_contact_name_from_jid( self.account, self.from_jid_without_resource) self.msg_text = ''.join(self.stanza.kids[0].data) return True return False
def commandListQuery(self, con, iq_obj): iq = iq_obj.buildReply('result') jid = helpers.get_full_jid_from_iq(iq_obj) q = iq.getTag('query') # buildReply don't copy the node attribute. Re-add it q.setAttr('node', nbxmpp.NS_COMMANDS) for node, cmd in self.__commands.items(): if cmd.isVisibleFor(self.isSameJID(jid)): q.addChild('item', { # TODO: find the jid 'jid': self.getOurBareJID() + '/' + self.server_resource, 'node': node, 'name': cmd.commandname}) self.connection.send(iq)
def commandItemsQuery(self, con, iq_obj): """ Send disco#items result for query for command. Return True if the result was sent, False if not. """ jid = helpers.get_full_jid_from_iq(iq_obj) node = iq_obj.getTagAttr('query', 'node') if node not in self.__commands: return False cmd = self.__commands[node] if cmd.isVisibleFor(self.isSameJID(jid)): iq = iq_obj.buildReply('result') self.connection.send(iq) return True return False
def _JingleCB(self, con, stanza): """ The jingle stanza dispatcher Route jingle stanza to proper JingleSession object, or create one if it is a new session. TODO: Also check if the stanza isn't an error stanza, if so route it adequatelly. """ # get data try: jid = helpers.get_full_jid_from_iq(stanza) except helpers.InvalidFormat: logger.warn('Invalid JID: %s, ignoring it' % stanza.getFrom()) return id_ = stanza.getID() if (jid, id_) in self.__iq_responses.keys(): self.__iq_responses[(jid, id_)].on_stanza(stanza) del self.__iq_responses[(jid, id_)] raise nbxmpp.NodeProcessed jingle = stanza.getTag('jingle') # a jingle element is not necessary in iq-result stanza # don't check for that if jingle: sid = jingle.getAttr('sid') else: sid = None for sesn in self._sessions.values(): if id_ in sesn.iq_ids: sesn.on_stanza(stanza) return # do we need to create a new jingle object if sid not in self._sessions: #TODO: tie-breaking and other things... newjingle = JingleSession(con=self, weinitiate=False, jid=jid, iq_id=id_, sid=sid) self._sessions[sid] = newjingle # we already have such session in dispatcher... self._sessions[sid].collect_iq_id(id_) self._sessions[sid].on_stanza(stanza) # Delete invalid/unneeded sessions if sid in self._sessions and \ self._sessions[sid].state == JingleStates.ended: self.delete_jingle_session(sid) raise nbxmpp.NodeProcessed
def commandListQuery(self, con, iq_obj): iq = iq_obj.buildReply('result') jid = helpers.get_full_jid_from_iq(iq_obj) q = iq.getTag('query') # buildReply don't copy the node attribute. Re-add it q.setAttr('node', nbxmpp.NS_COMMANDS) for node, cmd in self.__commands.items(): if cmd.isVisibleFor(self.isSameJID(jid)): q.addChild( 'item', { # TODO: find the jid 'jid': self.getOurBareJID() + '/' + self.server_resource, 'node': node, 'name': cmd.commandname }) self.connection.send(iq)
def _nec_raw_message(self, obj): if not HAS_GOOCANVAS: return if obj.stanza.getTag('sxe', namespace=NS_SXE): account = obj.conn.name try: fjid = helpers.get_full_jid_from_iq(obj.stanza) except helpers.InvalidFormat: obj.conn.dispatch( 'ERROR', (_('Invalid Jabber ID'), _('A message from a non-valid JID arrived, it has been ' 'ignored.'))) jid = gajim.get_jid_without_resource(fjid) ctrl = (gajim.interface.msg_win_mgr.get_control(fjid, account) or gajim.interface.msg_win_mgr.get_control(jid, account)) if not ctrl: return sxe = obj.stanza.getTag('sxe') if not sxe: return sid = sxe.getAttr('session') if (jid, sid) not in obj.conn._sessions: pass # newjingle = JingleSession(con=self, weinitiate=False, jid=jid, sid=sid) # self.addJingle(newjingle) # we already have such session in dispatcher... session = obj.conn.get_jingle_session(fjid, sid) cn = session.contents[('initiator', 'xhtml')] error = obj.stanza.getTag('error') if error: action = 'iq-error' else: action = 'edit' cn.on_stanza(obj.stanza, sxe, error, action) # def __editCB(self, stanza, content, error, action): #new_tags = sxe.getTags('new') #remove_tags = sxe.getTags('remove') #if new_tags is not None: ## Process new elements #for tag in new_tags: #if tag.getAttr('type') == 'element': #ctrl.whiteboard.recieve_element(tag) #elif tag.getAttr('type') == 'attr': #ctrl.whiteboard.recieve_attr(tag) #ctrl.whiteboard.apply_new() #if remove_tags is not None: ## Delete rids #for tag in remove_tags: #target = tag.getAttr('target') #ctrl.whiteboard.image.del_rid(target) # Stop propagating this event, it's handled return True
def _ft_get_from(self, iq_obj): return helpers.get_full_jid_from_iq(iq_obj)
def _CommandExecuteCB(self, con, iq_obj): jid = helpers.get_full_jid_from_iq(iq_obj) cmd = iq_obj.getTag('command') if cmd is None: return node = cmd.getAttr('node') if node is None: return sessionid = cmd.getAttr('sessionid') if sessionid is None: # we start a new command session... only if we are visible for the jid # and command exist if node not in self.__commands.keys(): self.connection.send( nbxmpp.Error(iq_obj, nbxmpp.NS_STANZAS + ' item-not-found')) raise nbxmpp.NodeProcessed newcmd = self.__commands[node] if not newcmd.isVisibleFor(self.isSameJID(jid)): return # generate new sessionid sessionid = self.connection.getAnID() # create new instance and run it obj = newcmd(conn=self, jid=jid, sessionid=sessionid) rc = obj.execute(iq_obj) if rc: self.__sessions[(jid, sessionid, node)] = obj raise nbxmpp.NodeProcessed else: # the command is already running, check for it magictuple = (jid, sessionid, node) if magictuple not in self.__sessions: # we don't have this session... ha! return action = cmd.getAttr('action') obj = self.__sessions[magictuple] try: if action == 'cancel': rc = obj.cancel(iq_obj) elif action == 'prev': rc = obj.prev(iq_obj) elif action == 'next': rc = obj.next(iq_obj) elif action == 'execute' or action is None: rc = obj.execute(iq_obj) elif action == 'complete': rc = obj.complete(iq_obj) else: # action is wrong. stop the session, send error raise AttributeError except AttributeError: # the command probably doesn't handle invoked action... # stop the session, return error del self.__sessions[magictuple] return # delete the session if rc is False if not rc: del self.__sessions[magictuple] raise nbxmpp.NodeProcessed
def _CommandExecuteCB(self, con, iq_obj): jid = helpers.get_full_jid_from_iq(iq_obj) cmd = iq_obj.getTag('command') if cmd is None: return node = cmd.getAttr('node') if node is None: return sessionid = cmd.getAttr('sessionid') if sessionid is None: # we start a new command session... only if we are visible for the jid # and command exist if node not in self.__commands.keys(): self.connection.send( nbxmpp.Error(iq_obj, nbxmpp.NS_STANZAS + ' item-not-found')) raise nbxmpp.NodeProcessed newcmd = self.__commands[node] if not newcmd.isVisibleFor(self.isSameJID(jid)): return # generate new sessionid sessionid = self.connection.getAnID() # create new instance and run it obj = newcmd(conn = self, jid = jid, sessionid = sessionid) rc = obj.execute(iq_obj) if rc: self.__sessions[(jid, sessionid, node)] = obj raise nbxmpp.NodeProcessed else: # the command is already running, check for it magictuple = (jid, sessionid, node) if magictuple not in self.__sessions: # we don't have this session... ha! return action = cmd.getAttr('action') obj = self.__sessions[magictuple] try: if action == 'cancel': rc = obj.cancel(iq_obj) elif action == 'prev': rc = obj.prev(iq_obj) elif action == 'next': rc = obj.next(iq_obj) elif action == 'execute' or action is None: rc = obj.execute(iq_obj) elif action == 'complete': rc = obj.complete(iq_obj) else: # action is wrong. stop the session, send error raise AttributeError except AttributeError: # the command probably doesn't handle invoked action... # stop the session, return error del self.__sessions[magictuple] return # delete the session if rc is False if not rc: del self.__sessions[magictuple] raise nbxmpp.NodeProcessed