def command_info_query(self, stanza): """ Send disco#info result for query for command (XEP-0050, example 6.). Return True if the result was sent, False if not """ try: jid = helpers.get_full_jid_from_iq(stanza) except helpers.InvalidFormat: log.warning('Invalid JID: %s, ignoring it' % stanza.getFrom()) return node = stanza.getTagAttr('query', 'node') if node not in self._commands: return False cmd = self._commands[node] if cmd.isVisibleFor(self.is_same_jid(jid)): iq = stanza.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._con.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 XMPP Address'), _('A message from a non-valid XMPP address ' 'arrived. It has been ignored.'))) jid = app.get_jid_without_resource(fjid) ctrl = (app.interface.msg_win_mgr.get_control(fjid, account) or app.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.get_module('Jingle')._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_module('Jingle').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 get_jid_resource(self, check_fake_jid=False): if check_fake_jid and hasattr(self, 'id_') and \ self.id_ in self.conn.groupchat_jids: self.fjid = self.conn.groupchat_jids[self.id_] del self.conn.groupchat_jids[self.id_] else: self.fjid = helpers.get_full_jid_from_iq(self.stanza) if self.fjid is None: self.jid = None else: self.jid, self.resource = app.get_room_and_nick_from_fjid(self.fjid)
def _on_jingle_iq(self, _con, stanza, _properties): """ 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 adequately. """ # 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(self._con, 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_ = iq_obj.getAttr('id') frm = helpers.get_full_jid_from_iq(iq_obj) query = iq_obj.getTag('query') app.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 gajim.common.connection_handlers_events import FileRequestErrorEvent app.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self._con, jid=jid, file_props=file_props, error_msg='')) 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 command_list_query(self, stanza): iq = stanza.buildReply('result') jid = helpers.get_full_jid_from_iq(stanza) query = iq.getTag('query') # buildReply don't copy the node attribute. Re-add it query.setAttr('node', Namespace.COMMANDS) for node, cmd in self._commands.items(): if cmd.is_visible_for(self.is_same_jid(jid)): query.addChild('item', { # TODO: find the jid 'jid': str(self._con.get_own_jid()), 'node': node, 'name': cmd.commandname}) self._con.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 command_items_query(self, stanza): """ 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(stanza) node = stanza.getTagAttr('query', 'node') if node not in self._commands: return False cmd = self._commands[node] if cmd.isVisibleFor(self.is_same_jid(jid)): iq = stanza.buildReply('result') self._con.connection.send(iq) return True return False
def _on_bytestream_error(self, _con, iq_obj): id_ = iq_obj.getAttr('id') frm = helpers.get_full_jid_from_iq(iq_obj) query = iq_obj.getTag('query') app.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 app.nec.push_incoming_event( NetworkEvent('file-request-error', conn=self._con, jid=app.get_jid_without_resource(jid), file_props=file_props, error_msg='')) raise nbxmpp.NodeProcessed
def _execute_command_received(self, con, stanza): jid = helpers.get_full_jid_from_iq(stanza) cmd = stanza.getTag('command') if cmd is None: log.error('Malformed stanza (no command node) %s', stanza) raise nbxmpp.NodeProcessed node = cmd.getAttr('node') if node is None: log.error('Malformed stanza (no node attr) %s', stanza) raise nbxmpp.NodeProcessed 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._con.connection.send( nbxmpp.Error(stanza, nbxmpp.NS_STANZAS + ' item-not-found')) log.warning('Comand %s does not exist: %s', node, jid) raise nbxmpp.NodeProcessed newcmd = self._commands[node] if not newcmd.isVisibleFor(self.is_same_jid(jid)): log.warning('Command not visible for jid: %s', jid) raise nbxmpp.NodeProcessed # generate new sessionid sessionid = self._con.connection.getAnID() # create new instance and run it obj = newcmd(conn=self, jid=jid, sessionid=sessionid) rc = obj.execute(stanza) if rc: self._sessions[(jid, sessionid, node)] = obj log.info('Comand %s executed: %s', node, jid) 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! log.warning('Invalid session %s', magictuple) raise nbxmpp.NodeProcessed action = cmd.getAttr('action') obj = self._sessions[magictuple] try: if action == 'cancel': rc = obj.cancel(stanza) elif action == 'prev': rc = obj.prev(stanza) elif action == 'next': rc = obj.next(stanza) elif action == 'execute' or action is None: rc = obj.execute(stanza) elif action == 'complete': rc = obj.complete(stanza) 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] log.warning('Wrong action %s %s', node, jid) raise nbxmpp.NodeProcessed # delete the session if rc is False if not rc: del self._sessions[magictuple] raise nbxmpp.NodeProcessed
def _PubkeyResultCB(self, con, iq_obj): log.info('PubkeyResultCB') jid_from = helpers.get_full_jid_from_iq(iq_obj) jingle_xtls.handle_new_cert(con, iq_obj, jid_from)
def _PubkeyGetCB(self, con, iq_obj): log.info('PubkeyGetCB') jid_from = helpers.get_full_jid_from_iq(iq_obj) sid = iq_obj.getAttr('id') jingle_xtls.send_cert(con, jid_from, sid) 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
def _on_pubkey_request(self, con, stanza, _properties): jid_from = helpers.get_full_jid_from_iq(stanza) self._log.info('Pubkey request from %s', jid_from) sid = stanza.getAttr('id') jingle_xtls.send_cert(con, jid_from, sid) raise nbxmpp.NodeProcessed
def _ft_get_from(self, iq_obj): if self._account == 'Local': return iq_obj.getFrom() return helpers.get_full_jid_from_iq(iq_obj)
def _pubkey_result_received(self, con, stanza, _properties): jid_from = helpers.get_full_jid_from_iq(stanza) self._log.info('Pubkey result from %s', jid_from) jingle_xtls.handle_new_cert(con, stanza, jid_from)
def _ft_get_from(self, iq_obj): return helpers.get_full_jid_from_iq(iq_obj)