How to use the nbxmpp.Iq function in nbxmpp

To help you get started, we’ve selected a few nbxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajim / gajim / gajim / common / modules / bytestream.py View on Github external
def _connect_error(self, sid, error, error_type, msg=None):
        """
        Called when there is an error establishing BS connection, or when
        connection is rejected
        """
        if not app.account_is_available(self._account):
            return
        file_props = FilesProp.getFileProp(self._account, sid)
        if file_props is None:
            log.error('can not send iq error on failed transfer')
            return
        if file_props.type_ == 's':
            to = file_props.receiver
        else:
            to = file_props.sender
        iq = nbxmpp.Iq(to=to, typ='error')
        iq.setAttr('id', file_props.request_id)
        err = iq.setTag('error')
        err.setAttr('type', error_type)
        err.setTag(error, namespace=Namespace.STANZAS)
        self._con.connection.send(iq)
        if msg:
            self.disconnect_transfer(file_props)
            file_props.error = -3
            app.nec.push_incoming_event(
                NetworkEvent('file-request-error',
                             conn=self._con,
                             jid=app.get_jid_without_resource(to),
                             file_props=file_props,
                             error_msg=msg))
github gajim / gajim / gajim / common / modules / vcard_temp.py View on Github external
if isinstance(callback, RequestAvatar):
            if callback == RequestAvatar.SELF:
                if not self.supported:
                    return
                callback = self._on_own_avatar_received
            elif callback == RequestAvatar.ROOM:
                callback = self._on_room_avatar_received
            elif callback == RequestAvatar.USER:
                callback = self._on_avatar_received

        if room:
            room_jid = app.get_room_from_fjid(jid)
            if room_jid not in self.room_jids:
                self.room_jids.append(room_jid)

        iq = nbxmpp.Iq(typ='get')
        if jid:
            iq.setTo(jid)
        iq.setQuery('vCard').setNamespace(Namespace.VCARD)

        own_jid = self._con.get_own_jid().getStripped()
        self._log.info('Request: %s, expected sha: %s', jid or own_jid, sha)

        self._con.connection.SendAndCallForResponse(
            iq, self._parse_vcard, {'callback': callback, 'expected_sha': sha})
github gajim / gajim / gajim / common / modules / delimiter.py View on Github external
def set_roster_delimiter(self):
        self._log.info('Set delimiter')
        iq = nbxmpp.Iq('set', Namespace.PRIVATE)
        roster = iq.getQuery().addChild('roster', namespace='roster:delimiter')
        roster.setData('::')

        self._con.connection.SendAndCallForResponse(
            iq, self._set_delimiter_response)
github gajim / gajim / gajim / common / connection.py View on Github external
self.USE_GPG = True
                                self.gpg = gpg.GnuPG()
                            app.nec.push_incoming_event(
                                AccountCreatedEvent(None, conn=self,
                                account_info=self.new_account_info))
                            self.new_account_info = None
                            self.new_account_form = None
                            if self.connection:
                                self.connection.UnregisterDisconnectHandler(
                                        self._on_new_account)
                            self.disconnect(on_purpose=True)
                        # it's the second time we get the form, we have info user
                        # typed, so send them
                        if is_form:
                            #TODO: Check if form has changed
                            iq = nbxmpp.Iq('set', nbxmpp.NS_REGISTER,
                                to=self._hostname)
                            iq.setTag('query').addChild(node=self.new_account_form)
                            self.connection.SendAndCallForResponse(iq,
                                    _on_register_result)
                        else:
                            if list(self.new_account_form.keys()).sort() != \
                            list(conf.keys()).sort():
                                # requested config has changed since first connection
                                reason = _('Server %s provided a different '
                                    'registration form') % data[0]
                                app.nec.push_incoming_event(AccountNotCreatedEvent(
                                    None, conn=self, reason=reason))
                                return
                            nbxmpp.features_nb.register(self.connection,
                                    self._hostname, self.new_account_form,
                                    _on_register_result)
github gajim / gajim / gajim / common / modules / entity_time.py View on Github external
def request_entity_time(self, jid, resource):
        if not app.account_is_available(self._account):
            return

        if resource:
            jid += '/' + resource
        iq = nbxmpp.Iq(to=jid, typ='get')
        iq.addChild('time', namespace=Namespace.TIME_REVISED)

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

        self._con.connection.SendAndCallForResponse(iq, self._result_received)
github gajim / gajim / gajim / common / pubsub.py View on Github external
def send_pb_retract(self, jid, node, id_):
        """
        Delete item from a node
        """
        if not self.connection or self.connected < 2:
            return
        query = nbxmpp.Iq('set', to=jid)
        r = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
        r = r.addChild('retract', {'node': node, 'notify': '1'})
        r = r.addChild('item', {'id': id_})

        self.connection.send(query)
github gajim / gajim / gajim / common / pubsub.py View on Github external
def send_pb_subscribe(self, jid, node, cb, *args, **kwargs):
        if not self.connection or self.connected < 2:
            return
        our_jid = app.get_jid_from_account(self.name)
        query = nbxmpp.Iq('set', to=jid)
        pb = query.addChild('pubsub', namespace=nbxmpp.NS_PUBSUB)
        pb.addChild('subscribe', {'node': node, 'jid': our_jid})

        id_ = self.connection.send(query)

        self.__callbacks[id_] = (cb, args, kwargs)
github gajim / gajim / gajim / common / modules / metacontacts.py View on Github external
def store_metacontacts(self, tags_list):
        if not app.account_is_available(self._account):
            return
        iq = nbxmpp.Iq('set', Namespace.PRIVATE)
        meta = iq.getQuery().addChild('storage',
                                      namespace='storage:metacontacts')
        for tag in tags_list:
            for data in tags_list[tag]:
                jid = data['jid']
                dict_ = {'jid': jid, 'tag': tag}
                if 'order' in data:
                    dict_['order'] = data['order']
                meta.addChild(name='meta', attrs=dict_)
        self._log.info('Store: %s', tags_list)
        self._con.connection.SendAndCallForResponse(
            iq, self._store_response_received)
github gajim / gajim / gajim / common / modules / vcard_temp.py View on Github external
def send_vcard(self, vcard, sha):
        if not app.account_is_available(self._account):
            return

        iq = nbxmpp.Iq(typ='set')
        iq2 = iq.setTag(Namespace.VCARD + ' vCard')
        for i in vcard:
            if i == 'jid':
                continue
            if isinstance(vcard[i], dict):
                iq3 = iq2.addChild(i)
                for j in vcard[i]:
                    iq3.addChild(j).setData(vcard[i][j])
            elif isinstance(vcard[i], list):
                for j in vcard[i]:
                    iq3 = iq2.addChild(i)
                    for k in j:
                        iq3.addChild(k).setData(j[k])
            else:
                iq2.addChild(i).setData(vcard[i])
github gajim / gajim / gajim / common / modules / pubsub.py View on Github external
def send_pb_publish(self, jid, node, item,
                        id_=None, options=None, cb=None, **kwargs):
        if not app.account_is_available(self._account):
            return

        if cb is None:
            cb = self._default_callback

        query = nbxmpp.Iq('set', to=jid)
        pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB)
        publish = pubsub.addChild('publish', {'node': node})
        attrs = {}
        if id_:
            attrs = {'id': id_}
        publish.addChild('item', attrs, [item])
        if options:
            publish = pubsub.addChild('publish-options')
            publish.addChild(node=options)

        self._con.connection.SendAndCallForResponse(query, cb, kwargs)