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 return
72 df={}
73 for i in resp.getQueryPayload():
74 if not isinstance(i, Node):
75 continue
76 df[i.getName()] = i.getData()
77 con.Event(NS_REGISTER, REGISTER_DATA_RECEIVED, (agent, df, False, ''))
78
79 -def register(disp, host, info, cb, args=None):
80 """
81 Perform registration on remote server with provided info
82
83 If registration fails you can get additional info from the dispatcher's
84 owner attributes lastErrNode, lastErr and lastErrCode.
85 """
86 iq=Iq('set', NS_REGISTER, to=host)
87 if not isinstance(info, dict):
88 info=info.asDict()
89 for i in info.keys():
90 iq.setTag('query').setTagData(i, info[i])
91 disp.SendAndCallForResponse(iq, cb, args)
92
94 """
95 Unregisters with host (permanently removes account). Returns true on success
96 """
97 iq = Iq('set', NS_REGISTER, to=host, payload=[Node('remove')])
98 _on_default_response(disp, iq, cb)
99
101 """
102 Changes password on specified or current (if not specified) server. Returns
103 true on success.
104 """
105 if not host:
106 host = disp._owner.Server
107 iq = Iq('set', NS_REGISTER, to=host, payload=[Node('username',
108 payload=[disp._owner.Server]), Node('password', payload=[newpassword])])
109 _on_default_response(disp, iq, cb)
110
111
112
113
114
115 PL_TYPE_JID = 'jid'
116 PL_TYPE_GROUP = 'group'
117 PL_TYPE_SUBC = 'subscription'
118 PL_ACT_ALLOW = 'allow'
119 PL_ACT_DENY = 'deny'
120
121 PRIVACY_LISTS_RECEIVED = 'PRIVACY LISTS RECEIVED'
122 PRIVACY_LIST_RECEIVED = 'PRIVACY LIST RECEIVED'
123 PRIVACY_LISTS_ACTIVE_DEFAULT = 'PRIVACY LISTS ACTIVE DEFAULT'
124
142 disp.SendAndCallForResponse(iq, _on_response)
143
157 disp.SendAndCallForResponse(iq, _on_response)
158
169 iq = Iq('get', NS_PRIVACY, payload=[Node('list', {'name': listname})])
170 disp.SendAndCallForResponse(iq, _on_response)
171
173 """
174 Switch privacy list 'listname' to specified type. By default the type is
175 'active'. Returns true on success.
176 """
177 if listname:
178 attrs={'name':listname}
179 else:
180 attrs={}
181 iq = Iq('set', NS_PRIVACY, payload=[Node(typ, attrs)])
182 _on_default_response(disp, iq, cb)
183
185 """
186 Set the default privacy list as 'listname'. Returns true on success
187 """
188 return setActivePrivacyList(disp, listname, 'default')
189
191 """
192 Set the ruleset
193
194 'list' should be the simpleXML node formatted according to RFC 3921
195 (XMPP-IM) I.e. Node('list',{'name':listname},payload=[...]).
196
197 Returns true on success.
198 """
199 iq = Iq('set', NS_PRIVACY, xmlns = '')
200 list_query = iq.getTag('query').setTag('list', {'name': listname})
201 for item in tags:
202 if 'type' in item and 'value' in item:
203 item_tag = list_query.setTag('item', {'action': item['action'],
204 'order': item['order'], 'type': item['type'],
205 'value': item['value']})
206 else:
207 item_tag = list_query.setTag('item', {'action': item['action'],
208 'order': item['order']})
209 if 'child' in item:
210 for child_tag in item['child']:
211 item_tag.setTag(child_tag)
212 _on_default_response(disp, iq, None)
213
215 ''' Deletes privacy list 'listname'. Returns true on success. '''
216 iq = Iq('set', NS_PRIVACY, payload=[Node('list', {'name':listname})])
217 _on_default_response(disp, iq, cb)
218