1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18  """ 
 19  Different stuff that wasn't worth separating it into modules 
 20  (Registration, Privacy Lists, ...) 
 21  """ 
 22   
 23  from protocol import NS_REGISTER, NS_PRIVACY, NS_DATA, Iq, isResultNode, Node 
 24   
 26      def _on_response(resp): 
 27          if isResultNode(resp): 
 28              if cb: 
 29                  cb(True) 
 30          elif cb: 
 31              cb(False) 
  32      disp.SendAndCallForResponse(iq, _on_response) 
 33   
 34   
 35   
 36   
 37   
 38  REGISTER_DATA_RECEIVED = 'REGISTER DATA RECEIVED' 
 39   
 56   
 58      Iq('get', NS_REGISTER, to=agent) 
 59      if not isResultNode(resp): 
 60          error_msg = resp.getErrorMsg() 
 61          con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, '')) 
 62          return 
 63      tag=resp.getTag('query', namespace=NS_REGISTER) 
 64      if not tag: 
 65          error_msg = resp.getErrorMsg() 
 66          con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, None, False, error_msg, '')) 
 67          return 
 68      df=tag.getTag('x', namespace=NS_DATA) 
 69      if df: 
 70          con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, True, '', 
 71              tag)) 
 72          return 
 73      df={} 
 74      for i in resp.getQueryPayload(): 
 75          if not isinstance(i, Node): 
 76              continue 
 77          df[i.getName()] = i.getData() 
 78      con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, False, '', '')) 
  79   
 80 -def register(disp, host, info, cb, args=None): 
  81      """ 
 82      Perform registration on remote server with provided info 
 83   
 84      If registration fails you can get additional info from the dispatcher's 
 85      owner   attributes lastErrNode, lastErr and lastErrCode. 
 86      """ 
 87      iq=Iq('set', NS_REGISTER, to=host) 
 88      if not isinstance(info, dict): 
 89          info=info.asDict() 
 90      for i in info.keys(): 
 91          iq.setTag('query').setTagData(i, info[i]) 
 92      disp.SendAndCallForResponse(iq, cb, args) 
  93   
 95      """ 
 96      Unregisters with host (permanently removes account). Returns true on success 
 97      """ 
 98      iq = Iq('set', NS_REGISTER, to=host, payload=[Node('remove')]) 
 99      _on_default_response(disp, iq, cb) 
 100   
102      """ 
103      Changes password on specified or current (if not specified) server. Returns 
104      true on success. 
105      """ 
106      if not host: 
107          host = disp._owner.Server 
108      iq = Iq('set', NS_REGISTER, to=host, payload=[Node('username', 
109                      payload=[disp._owner.Server]), Node('password', payload=[newpassword])]) 
110      _on_default_response(disp, iq, cb) 
 111   
112   
113   
114   
115   
116  PL_TYPE_JID = 'jid' 
117  PL_TYPE_GROUP = 'group' 
118  PL_TYPE_SUBC = 'subscription' 
119  PL_ACT_ALLOW = 'allow' 
120  PL_ACT_DENY = 'deny' 
121   
122  PRIVACY_LISTS_RECEIVED = 'PRIVACY LISTS RECEIVED' 
123  PRIVACY_LIST_RECEIVED = 'PRIVACY LIST RECEIVED' 
124  PRIVACY_LISTS_ACTIVE_DEFAULT = 'PRIVACY LISTS ACTIVE DEFAULT' 
125   
143      disp.SendAndCallForResponse(iq, _on_response) 
144   
158      disp.SendAndCallForResponse(iq, _on_response) 
159   
170      iq = Iq('get', NS_PRIVACY, payload=[Node('list', {'name': listname})]) 
171      disp.SendAndCallForResponse(iq, _on_response) 
172   
174      """ 
175      Switch privacy list 'listname' to specified type. By default the type is 
176      'active'. Returns true on success. 
177      """ 
178      if listname: 
179          attrs={'name':listname} 
180      else: 
181          attrs={} 
182      iq = Iq('set', NS_PRIVACY, payload=[Node(typ, attrs)]) 
183      _on_default_response(disp, iq, cb) 
 184   
186      """ 
187      Set the default privacy list as 'listname'. Returns true on success 
188      """ 
189      return setActivePrivacyList(disp, listname, 'default') 
 190   
192      """ 
193      Set the ruleset 
194   
195      'list' should be the simpleXML node formatted according to RFC 3921 
196      (XMPP-IM) I.e. Node('list',{'name':listname},payload=[...]). 
197   
198      Returns true on success. 
199      """ 
200      iq = Iq('set', NS_PRIVACY, xmlns = '') 
201      list_query = iq.getTag('query').setTag('list', {'name': listname}) 
202      for item in tags: 
203          if 'type' in item and 'value' in item: 
204              item_tag = list_query.setTag('item', {'action': item['action'], 
205                      'order': item['order'], 'type': item['type'], 
206                      'value': item['value']}) 
207          else: 
208              item_tag = list_query.setTag('item', {'action': item['action'], 
209                      'order': item['order']}) 
210          if 'child' in item: 
211              for child_tag in item['child']: 
212                  item_tag.setTag(child_tag) 
213      _on_default_response(disp, iq, None) 
 214   
216      ''' Deletes privacy list 'listname'. Returns true on success. ''' 
217      iq = Iq('set', NS_PRIVACY, payload=[Node('list', {'name':listname})]) 
218      _on_default_response(disp, iq, cb) 
 219