def request_info(self, jid, request_vcard=True, allow_redirect=False): _task = yield redirected = False disco_info = yield self.disco_info(jid) if is_error(disco_info): error_response = disco_info if not allow_redirect: raise error_response if error_response.condition != 'gone': raise error_response try: jid = parse_xmpp_uri(error_response.condition_data)[0] except Exception: raise error_response redirected = True disco_info = yield self.disco_info(jid) raise_if_error(disco_info) if not request_vcard or not disco_info.supports(Namespace.VCARD): yield MucInfoResult(info=disco_info, redirected=redirected) vcard = yield self.request_vcard(jid) if is_error(vcard): yield MucInfoResult(info=disco_info, redirected=redirected) yield MucInfoResult(info=disco_info, vcard=vcard, redirected=redirected)
def set_access_model(self, node, model): task = yield if model not in ('open', 'presence'): raise ValueError('Invalid access model') result = yield self.get_node_configuration(node) raise_if_error(result) try: access_model = result.form['pubsub#access_model'].value except Exception: yield task.set_error('warning', condition='access-model-not-supported') if access_model == model: jid = self._client.get_bound_jid().new_as_bare() yield CommonResult(jid=jid) result.form['pubsub#access_model'].value = model result = yield self.set_node_configuration(node, result.form) yield finalize(task, result)
def _execute_query(self, jid, mam_id, start_date): _task = yield if jid in self._catch_up_finished: self._catch_up_finished.remove(jid) queryid = self._get_query_id(jid) result = yield self.make_query(jid, queryid, after=mam_id, start=start_date) self._remove_query_id(result.jid) raise_if_error(result) while not result.complete: app.storage.archive.set_archive_infos(result.jid, last_mam_id=result.rsm.last) queryid = self._get_query_id(result.jid) result = yield self.make_query(result.jid, queryid, after=result.rsm.last, start=start_date) self._remove_query_id(result.jid) raise_if_error(result) self._catch_up_finished.append(result.jid) self._log.info('Request finished: %s, last mam id: %s', result.jid, result.rsm.last) yield result
def get_access_model(self, node): _task = yield result = yield self.get_node_configuration(node) raise_if_error(result) yield result.form['pubsub#access_model'].value
def request_avatar_data(self, id_, jid=None): task = yield item = yield self.request_item(Namespace.AVATAR_DATA, id_=id_, jid=jid) raise_if_error(item) if item is None: yield task.set_result(None) yield _get_avatar_data(item, id_)
def update_blocking_list(self, block, unblock): _task = yield if block: result = yield self.block(block) raise_if_error(result) if unblock: result = yield self.unblock(unblock) raise_if_error(result) yield True
def get_blocking_list(self): _task = yield blocking_list = yield self._nbxmpp('Blocking').request_blocking_list() raise_if_error(blocking_list) self.blocked = list(blocking_list) app.nec.push_incoming_event(NetworkEvent('blocking', conn=self._con, changed=self.blocked)) yield blocking_list
def request_bundle(self, jid, device_id): task = yield items = yield self.request_items( f'{Namespace.OMEMO_TEMP_BUNDLE}:{device_id}', max_items=1, jid=jid) raise_if_error(items) if not items: yield task.set_result(None) yield _parse_bundle(items[0])
def request_vcard(self, jid=None): task = yield items = yield self.request_items(Namespace.VCARD4_PUBSUB, jid=jid, max_items=1) raise_if_error(items) if not items: yield task.set_result(None) yield _get_vcard(items[0])
def request_devicelist(self, jid=None): task = yield items = yield self.request_items(Namespace.OMEMO_TEMP_DL, max_items=1, jid=jid) raise_if_error(items) if not items: yield task.set_result(None) yield _parse_devicelist(items[0])
def set_access_model(self, public): task = yield access_model = 'open' if public else 'presence' result = yield self._client.get_module('PubSub').set_access_model( Namespace.AVATAR_DATA, access_model) raise_if_error(result) result = yield self._client.get_module('PubSub').set_access_model( Namespace.AVATAR_METADATA, access_model) yield finalize(task, result)
def request_bookmarks(self): _task = yield items = yield self.request_items(Namespace.BOOKMARKS, max_items=1) raise_if_error(items) if not items: yield [] bookmarks = parse_bookmarks(items[0], self._log) for bookmark in bookmarks: self._log.info(bookmark) yield bookmarks
def set_avatar(self, avatar, public=False): task = yield access_model = 'open' if public else 'presence' if avatar is None: result = yield self._publish_avatar_metadata(None, access_model) raise_if_error(result) result = yield self.delete(Namespace.AVATAR_DATA) yield finalize(task, result) result = yield self._publish_avatar(avatar, access_model) yield finalize(task, result)
def request_secret_key(self): task = yield items = yield self.request_items(Namespace.OPENPGP_SK, max_items=1) raise_if_error(items) if not items: yield task.set_result(None) try: secret_key = _parse_secret_key(items[0]) except ValueError as error: raise MalformedStanzaError(str(error), items) yield secret_key
def request_public_key(self, jid, fingerprint): task = yield items = yield self.request_items( f'{Namespace.OPENPGP_PK}:{fingerprint}', max_items=1, jid=jid) raise_if_error(items) if not items: yield task.set_result(None) try: key = _parse_public_key(jid, items[0]) except ValueError as error: raise MalformedStanzaError(str(error), items) yield key
def request_keylist(self, jid=None): task = yield items = yield self.request_items(Namespace.OPENPGP_PK, max_items=1, jid=jid) raise_if_error(items) if not items: yield task.set_result(None) try: keylist = _parse_keylist(jid, items[0]) except ValueError as error: raise MalformedStanzaError(str(error), items) self._log.info('Received keylist: %s', keylist) yield keylist
def request_bookmarks(self): _task = yield items = yield self.request_items(Namespace.BOOKMARKS_1) raise_if_error(items) bookmarks = [] for item in items: try: bookmark_item = parse_bookmark(item) except MalformedStanzaError as error: self._log.warning(error) self._log.warning(error.stanza) continue bookmarks.append(bookmark_item) for bookmark in bookmarks: self._log.info(bookmark) yield bookmarks
def request_avatar_metadata(self, jid=None): task = yield items = yield self.request_items(Namespace.AVATAR_METADATA, max_items=1, jid=jid) raise_if_error(items) if not items: yield task.set_result(None) item = items[0] metadata = item.getTag('metadata', namespace=Namespace.AVATAR_METADATA) if metadata is None: raise MalformedStanzaError('metadata node missing', item) if not metadata.getChildren(): yield task.set_result(None) yield AvatarMetaData.from_node(metadata, item.getAttr('id'))
def _publish_avatar(self, avatar, access_model): task = yield options = { 'pubsub#persist_items': 'true', 'pubsub#access_model': access_model, } for info, data in avatar.pubsub_avatar_info(): item = _make_avatar_data_node(data) result = yield self.publish(Namespace.AVATAR_DATA, item, id_=info.id, options=options, force_node_options=True) raise_if_error(result) result = yield self._publish_avatar_metadata(avatar.metadata, access_model) yield finalize(task, result)