def _muc_info_response(self, conn, stanza, callback): if not nbxmpp.isResultNode(stanza): error = stanza.getError() if error == 'item-not-found': # Groupchat does not exist log.info('MUC does not exist: %s', stanza.getFrom()) callback() else: log.info('MUC disco error: %s', error) app.nec.push_incoming_event( InformationEvent( None, dialog_name='unable-join-groupchat', args=error)) return log.info('MUC info received: %s', stanza.getFrom()) muc_caps_cache.append(stanza) callback()
def _parse_iq(stanza): if not nbxmpp.isResultNode(stanza): log.error('Error on MAM query: %s', stanza.getError()) raise InvalidMamIQ fin = stanza.getTag('fin') if fin is None: log.error('Malformed MAM query result received: %s', stanza) raise InvalidMamIQ set_ = fin.getTag('set', namespace=nbxmpp.NS_RSM) if set_ is None: log.error( 'Malformed MAM query result received (no "set" Node): %s', stanza) raise InvalidMamIQ return fin, set_
def _config_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) return room_jid = stanza.getFrom().getStripped() payload = stanza.getQueryPayload() for form in payload: if form.getNamespace() == nbxmpp.NS_DATA: dataform = dataforms.ExtendForm(node=form) log.info('Config form received for %s', room_jid) app.nec.push_incoming_event( MucOwnerReceivedEvent(None, conn=self._con, form_node=form, dataform=dataform, jid=room_jid)) break
def _result_received(self, stanza): client_info, os_info = None, None if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) else: try: client_info, os_info = self._extract_info(stanza) except Exception: log.exception('Error') log.error(stanza) log.info('Received: %s %s %s', stanza.getFrom(), client_info, os_info) app.nec.push_incoming_event( VersionResultReceivedEvent(None, conn=self._con, jid=stanza.getFrom(), client_info=client_info, os_info=os_info))
def _disco_response(self, conn, stanza, success_cb, error_cb): if not nbxmpp.isResultNode(stanza): if error_cb is not None: error_cb()(stanza.getFrom(), stanza.getError()) else: log.info('Error: %s', stanza.getError()) return from_ = stanza.getFrom() node = stanza.getQuerynode() if stanza.getQueryNS() == nbxmpp.NS_DISCO_INFO: identities, features, data, node = self.parse_info_response(stanza) success_cb()(from_, identities, features, data, node) elif stanza.getQueryNS() == nbxmpp.NS_DISCO_ITEMS: items = self.parse_items_response(stanza) success_cb()(from_, node, items) else: log.warning('Wrong query namespace: %s', stanza)
def _register_agent_response(self, _con, stanza, agent, success_cb, error_cb): if not nbxmpp.isResultNode(stanza): error = stanza.getErrorMsg() self._log.info('Error: %s', error) if error_cb() is not None: form = is_form = None if stanza.getErrorType() == 'modify': form, is_form = self._get_register_form(stanza) error_cb()(error, form, is_form) return self._con.get_module('Presence').subscribe(agent, auto_auth=True) self.agent_registrations[agent]['roster_push'] = True if self.agent_registrations[agent]['sub_received']: self._con.get_module('Presence').subscribed(agent) if success_cb() is not None: success_cb()()
def _on_last_activity(self, stanza): if 'server_info' not in app.interface.instances[self.account]: # Window got closed in the meantime return if not nbxmpp.isResultNode(stanza): log.warning('Received malformed result: %s', stanza) return if stanza.getQueryNS() != nbxmpp.NS_LAST: log.warning('Wrong namespace on result: %s', stanza) return try: seconds = int(stanza.getQuery().getAttr('seconds')) except (ValueError, TypeError, AttributeError): log.exception('Received malformed last activity result') else: delta = timedelta(seconds=seconds) hours = 0 if seconds >= 3600: hours = delta.seconds // 3600 self.uptime = _('%s days, %s hours') % (delta.days, hours) self.update(self.get_infos, self.info_listbox)
def _command_list_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) app.nec.push_incoming_event( AdHocCommandError(None, conn=self._con, error=stanza.getError())) return items = stanza.getQueryPayload() commandlist = [] if items: commandlist = [(t.getAttr('node'), t.getAttr('name')) for t in items] log.info('Received: %s', commandlist) app.nec.push_incoming_event( AdHocCommandListReceived(None, conn=self._con, commandlist=commandlist))
def _roster_received(self, stanza): if not nbxmpp.isResultNode(stanza): self._log.warning('Unable to retrive roster: %s', stanza.getError()) else: self._log.info('Received Roster') received_from_server = False if stanza.getTag('query') is not None: # clear Roster self._data = {} version = self._parse_roster(stanza) self._log.info('New version: %s', version) app.logger.replace_roster(self._account, version, self._data) received_from_server = True app.nec.push_incoming_event(NetworkEvent( 'roster-received', conn=self._con, roster=self._data.copy(), received_from_server=received_from_server)) self._con.connect_machine()
def _received_pb_configuration(self, _con, stanza, node): if not nbxmpp.isResultNode(stanza): self._log.warning('Error: %s', stanza.getError()) return pubsub = stanza.getTag('pubsub', namespace=nbxmpp.NS_PUBSUB_OWNER) if pubsub is None: self._log.warning( 'Malformed PubSub configure ' 'stanza (no pubsub node): %s', stanza) return configure = pubsub.getTag('configure') if configure is None: self._log.warning( 'Malformed PubSub configure ' 'stanza (no configure node): %s', stanza) return if configure.getAttr('node') != node: self._log.warning( 'Malformed PubSub configure ' 'stanza (wrong node): %s', stanza) return form = configure.getTag('x', namespace=nbxmpp.NS_DATA) if form is None: self._log.warning( 'Malformed PubSub configure ' 'stanza (no form): %s', stanza) return app.nec.push_incoming_event( PubSubConfigReceivedEvent(None, conn=self._con, node=node, form=dataforms.extend_form(node=form)))
def _result_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) return log.info('Received annotations from %s', self._server) self.annotations = {} query = stanza.getTag('query') storage_node = query.getTag('storage') if storage_node is None: return notes = storage_node.getTags('note') if notes is None: return for note in notes: try: jid = helpers.parse_jid(note.getAttr('jid')) except helpers.InvalidFormat: log.warning('Invalid JID: %s, ignoring it', note.getAttr('jid')) continue self.annotations[jid] = note.getData()
def _on_unsubscribe_result(self, _nbxmpp_client, stanza): if not nbxmpp.isResultNode(stanza): self._log.info('Error: %s', stanza.getError()) return agent = stanza.getFrom().bare jid_list = [] for jid in app.contacts.get_jid_list(self._account): if jid.endswith('@' + agent): jid_list.append(jid) self._log.info( 'Removing contact %s due to' ' unregistered transport %s', jid, agent) self._con.get_module('Presence').unsubscribe(jid) # Transport contacts can't have 2 resources if jid in app.to_be_removed[self._account]: # This way we'll really remove it app.to_be_removed[self._account].remove(jid) app.nec.push_incoming_event( NetworkEvent('agent-removed', conn=self._con, agent=agent, jid_list=jid_list))
def _catalog_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError()) return query = stanza.getTag('catalog', namespace=nbxmpp.NS_SECLABEL_CATALOG) to = query.getAttr('to') items = query.getTags('item') labels = {} label_list = [] default = None for item in items: label = item.getAttr('selector') labels[label] = item.getTag('securitylabel') label_list.append(label) if item.getAttr('default') == 'true': default = label catalog = (labels, label_list, default) self._catalogs[to] = catalog app.nec.push_incoming_event(SecLabelCatalog( None, account=self._account, jid=to, catalog=catalog))
def _store_result_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.warning('Storing rosternotes failed: %s', stanza.getError()) return log.info('Storing rosternotes successful')
def _store_response_received(self, stanza): if not nbxmpp.isResultNode(stanza): self._log.info('Store error: %s', stanza.getError())
def _pubsub_store_result(self, conn, stanza): if not nbxmpp.isResultNode(stanza): log.error('Error: %s', stanza.getError()) return
def _default_result_handler(self, _con, stanza): if not nbxmpp.isResultNode(stanza): self._log.warning('Operation failed: %s', stanza.getError())
def _default_response(self, conn, stanza, **kwargs): if not nbxmpp.isResultNode(stanza): log.info('Error: %s', stanza.getError())
def _cancel_result_received(self, stanza): if not nbxmpp.isResultNode(stanza): log.warning('Error: %s', stanza.getError()) else: log.info('Cancel successful')
def _private_store_result(self, stanza): if not nbxmpp.isResultNode(stanza): log.error('Error: %s', stanza.getError()) return
def _set_delimiter_response(self, stanza): if not nbxmpp.isResultNode(stanza): self._log.info('Store error: %s', stanza.getError())
def _default_callback(self, conn, stanza, *args, **kwargs): if not nbxmpp.isResultNode(stanza): log.warning('Error: %s', stanza.getError())