Пример #1
0
    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)
Пример #2
0
    def request_archive_on_muc_join(self, jid):
        _task = yield

        threshold = app.settings.get_group_chat_setting(
            self._account, jid, 'sync_threshold')
        self._log.info('Threshold for %s: %s', jid, threshold)

        if threshold == SyncThreshold.NO_SYNC:
            return

        mam_id, start_date = self._get_muc_query_params(jid, threshold)

        result = yield self._execute_query(jid, mam_id, start_date)
        if is_error(result):
            if result.condition != 'item-not-found':
                self._log.warning(result)
                return

            app.storage.archive.reset_archive_infos(result.jid)
            _, start_date = self._get_muc_query_params(jid, threshold)
            result = yield self._execute_query(result.jid, None, start_date)
            if is_error(result):
                self._log.warning(result)
                return

        if result.rsm.last is not None:
            # <last> is not provided if the requested page was empty
            # so this means we did not get anything hence we only need
            # to update the archive info if <last> is present
            app.storage.archive.set_archive_infos(
                result.jid,
                last_mam_id=result.rsm.last,
                last_muc_timestamp=time.time())
Пример #3
0
    def get_roster_delimiter(self):
        _task = yield

        delimiter = yield self.request_delimiter()
        if is_error(delimiter) or delimiter is None:
            result = yield self.set_delimiter(self.delimiter)
            if is_error(result):
                self._con.connect_machine()
                return

            delimiter = self.delimiter

        self.delimiter = delimiter
        self.available = True
        self._con.connect_machine()
Пример #4
0
    def publish(self,
                node,
                item,
                id_=None,
                options=None,
                jid=None,
                force_node_options=False):

        _task = yield

        request = _make_publish_request(node, item, id_, options, jid)
        response = yield request

        if response.isError():
            error = PubSubStanzaError(response)
            if (not force_node_options
                    or error.app_condition != 'precondition-not-met'):
                raise error

            result = yield self.reconfigure_node(node, options, jid)
            if is_error(result):
                raise result

            response = yield request
            if response.isError():
                raise PubSubStanzaError(response)

        jid = response.getFrom()
        item_id = _get_published_item_id(response, node, id_)
        yield PubSubPublishResult(jid, node, item_id)
Пример #5
0
    def send_ping(self, contact: ContactsT) -> Generator:
        _task = yield

        if not app.account_is_available(self._account):
            return

        jid = contact.get_full_jid()

        self._log.info('Send ping to %s', jid)

        app.nec.push_incoming_event(
            NetworkEvent('ping-sent', account=self._account, contact=contact))

        ping_time = time.time()

        response = yield self.ping(jid, timeout=10)
        if is_error(response):
            app.nec.push_incoming_event(
                NetworkEvent('ping-error',
                             account=self._account,
                             contact=contact,
                             error=str(response)))
            return

        diff = round(time.time() - ping_time, 2)
        self._log.info('Received pong from %s after %s seconds', response.jid,
                       diff)

        app.nec.push_incoming_event(
            NetworkEvent('ping-reply',
                         account=self._account,
                         contact=contact,
                         seconds=diff))
Пример #6
0
    def _log_if_fatal(self, error):
        if is_error(error):
            if error.is_fatal:
                self._logger.log(error.log_level, error)

        elif isinstance(error, Exception):
            self._logger.exception('Fatal Exception')
Пример #7
0
    def reconfigure_node(self, node, options, jid=None):
        _task = yield

        result = yield self.get_node_configuration(node, jid)
        if is_error(result):
            raise result

        _apply_options(result.form, options)
        result = yield self.set_node_configuration(node, result.form, jid)
        yield result
Пример #8
0
    def _request_vcard(self, jid):
        _task = yield

        con = app.connections[self.account]
        vcard = yield con.get_module('VCardTemp').request_vcard(jid=jid)

        if is_error(vcard):
            return

        self.clear_values()
        self._set_values(vcard.data, str(jid))
        self._load_avatar(vcard)
Пример #9
0
    def request_archive_on_signin(self):
        _task = yield

        own_jid = self._con.get_own_jid().bare

        if own_jid in self._mam_query_ids:
            self._log.warning('request already running for %s', own_jid)
            return

        mam_id, start_date = self._get_query_params()

        result = yield self._execute_query(own_jid, mam_id, start_date)
        if is_error(result):
            if result.condition != 'item-not-found':
                self._log.warning(result)
                return

            app.storage.archive.reset_archive_infos(result.jid)
            _, start_date = self._get_query_params()
            result = yield self._execute_query(result.jid, None, start_date)
            if is_error(result):
                self._log.warning(result)
                return

        if result.rsm.last is not None:
            # <last> is not provided if the requested page was empty
            # so this means we did not get anything hence we only need
            # to update the archive info if <last> is present
            app.storage.archive.set_archive_infos(
                result.jid,
                last_mam_id=result.rsm.last,
                last_muc_timestamp=time.time())

        if start_date is not None:
            # Record the earliest timestamp we request from
            # the account archive. For the account archive we only
            # set start_date at the very first request.
            app.storage.archive.set_archive_infos(
                result.jid, oldest_mam_timestamp=start_date.timestamp())
Пример #10
0
    def _process_search_result(self, result, parameters=False):
        if self._search_stopped:
            raise CancelledError()

        if is_error(result):
            self._global_search_listbox.remove_progress()
            self._show_error_page(to_user_string(result))
            raise result

        if parameters:
            return

        for item in result.items:
            self._global_search_listbox.add(ResultRow(item))
Пример #11
0
    def request_catalog(self, jid):
        _task = yield

        catalog = yield self._nbxmpp('SecurityLabels').request_catalog(jid)

        if is_error(catalog):
            self._log.info(catalog)
            return

        self._catalogs[jid] = catalog

        self._log.info('Received catalog: %s', jid)

        app.nec.push_incoming_event(
            NetworkEvent('sec-catalog-received',
                         account=self._account,
                         jid=jid,
                         catalog=catalog))
Пример #12
0
def finalize(task, result):
    if is_error(result):
        raise result
    if isinstance(result, Node):
        return task.set_result(result)
    return result
Пример #13
0
def raise_if_error(result):
    if is_error(result):
        raise result
Пример #14
0
def is_fatal_error(error):
    if is_error(error):
        return error.is_fatal
    return isinstance(error, Exception)