def register(disp, host, info, cb, args=None): """ Perform registration on remote server with provided info If registration fails you can get additional info from the dispatcher's owner attributes lastErrNode, lastErr and lastErrCode. """ iq=Iq('set', NS_REGISTER, to=host) if not isinstance(info, dict): info=info.asDict() for i in info.keys(): iq.setTag('query').setTagData(i, info[i]) disp.SendAndCallForResponse(iq, cb, args)
def setItem(self, jid, name=None, groups=[]): """ Rename contact 'jid' and sets the groups list that it now belongs to """ iq = Iq('set', NS_ROSTER) query = iq.getTag('query') attrs = {'jid': jid} if name: attrs['name'] = name item = query.setTag('item', attrs) for group in groups: item.addChild(node=Node('group', payload=[group])) self._owner.send(iq)
def setItemMulti(self, items): """ Rename multiple contacts and sets their group lists """ iq = Iq('set', NS_ROSTER) query = iq.getTag('query') for i in items: attrs = {'jid': i['jid']} if i['name']: attrs['name'] = i['name'] item = query.setTag('item', attrs) for group in i['groups']: item.addChild(node=Node('group', payload=[group])) self._owner.send(iq)
def getRegInfo(disp, host, info={}, sync=True): """ Get registration form from remote host. Info dict can be prefilled :param disp: plugged dispatcher instance :param info: dict, like {'username':'******'}. See JEP-0077 for details. """ iq=Iq('get', NS_REGISTER, to=host) for i in info.keys(): iq.setTagData(i, info[i]) if sync: disp.SendAndCallForResponse(iq, lambda resp: _ReceivedRegInfo(disp.Dispatcher, resp, host)) else: disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host })
def Request(self, force=0): """ Request roster from server if it were not yet requested (or if the 'force' argument is set) """ if self._set is None: self._set = 0 elif not force: return iq = Iq('get', NS_ROSTER) if self.version is not None: iq.setTagAttr('query', 'ver', self.version) id_ = self._owner.getAnID() iq.setID(id_) self._owner.send(iq) log.info('Roster requested from server') return id_
def setPrivacyList(disp, listname, tags): """ Set the ruleset 'list' should be the simpleXML node formatted according to RFC 3921 (XMPP-IM) I.e. Node('list',{'name':listname},payload=[...]). Returns true on success. """ iq = Iq('set', NS_PRIVACY, xmlns = '') list_query = iq.getTag('query').setTag('list', {'name': listname}) for item in tags: if 'type' in item and 'value' in item: item_tag = list_query.setTag('item', {'action': item['action'], 'order': item['order'], 'type': item['type'], 'value': item['value']}) else: item_tag = list_query.setTag('item', {'action': item['action'], 'order': item['order']}) if 'child' in item: for child_tag in item['child']: item_tag.setTag(child_tag) _on_default_response(disp, iq, None)