annotate sat_pubsub/privilege.py @ 285:a87c155d0fd5

replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
author Goffi <goffi@goffi.org>
date Tue, 31 Mar 2015 17:31:56 +0200
parents sat_pubsub/remote_roster.py@002c59dbc23f
children 2f87fa282dfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
2 #-*- coding: utf-8 -*-
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
3 #
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Copyright (c) 2003-2011 Ralph Meijer
283
002c59dbc23f 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 255
diff changeset
6 Copyright (c) 2012, 2013, 2014, 2015 Jérôme Poisson
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
7
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
8
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
9 This program is free software: you can redistribute it and/or modify
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
10 it under the terms of the GNU Affero General Public License as published by
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
12 (at your option) any later version.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
13
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
17 GNU Affero General Public License for more details.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
18
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
19 You should have received a copy of the GNU Affero General Public License
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
21 --
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
22
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
23 This program is based on Idavoll (http://idavoll.ik.nu/),
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
24 originaly written by Ralph Meijer (http://ralphm.net/blog/)
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
25 It is sublicensed under AGPL v3 (or any later version) as allowed by the original
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
26 license.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
27
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
28 --
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
29
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
30 Here is a copy of the original license:
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
31
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
32 Copyright (c) 2003-2011 Ralph Meijer
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
33
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
34 Permission is hereby granted, free of charge, to any person obtaining
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
35 a copy of this software and associated documentation files (the
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "Software"), to deal in the Software without restriction, including
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
37 without limitation the rights to use, copy, modify, merge, publish,
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
38 distribute, sublicense, and/or sell copies of the Software, and to
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
39 permit persons to whom the Software is furnished to do so, subject to
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
40 the following conditions:
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
41
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
42 The above copyright notice and this permission notice shall be
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
43 included in all copies or substantial portions of the Software.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
44
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
45 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
46 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
48 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
49 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
52
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
53 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
54
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
55 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
56 Remote roster client.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
57
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
58 This module access roster throught a hacked version of
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
59 remote roster management http://jkaluza.fedorapeople.org/remote-roster.html
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
61
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
62 from wokkel import xmppim
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
63 from wokkel.compat import IQ
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
64 from wokkel.subprotocols import XMPPHandler
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
65 from twisted.python import log
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
66 from twisted.python import failure
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
67
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
68 PRIV_ENT_NS = 'urn:xmpp:privilege:1'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
69 PRIV_ENT_ADV_XPATH = '/message/privilege[@xmlns="{}"]'.format(PRIV_ENT_NS)
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
70 ROSTER_NS = 'jabber:iq:roster'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
71 PERM_ROSTER = 'roster'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
72 PERM_MESSAGE = 'message'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
73 PERM_PRESENCE = 'presence'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
74 ALLOWED_ROSTER = ('none', 'get', 'set', 'both')
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
75 ALLOWED_MESSAGE = ('none', 'outgoing')
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
76 ALLOWED_PRESENCE = ('none', 'managed_entity', 'roster')
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
77 TO_CHECK = {PERM_ROSTER:ALLOWED_ROSTER, PERM_MESSAGE:ALLOWED_MESSAGE, PERM_PRESENCE:ALLOWED_PRESENCE}
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
78
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
79
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
80 class InvalidStanza(Exception):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
81 pass
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
82
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
83 class NotAllowedError(Exception):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
84 pass
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
85
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
86 class PrivilegesHandler(XMPPHandler):
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
87 #FIXME: need to manage updates, and database sync
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
88 #TODO: cache
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
89
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
90 def __init__(self):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
91 super(PrivilegesHandler, self).__init__()
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
92 self._permissions = {PERM_ROSTER: 'none',
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
93 PERM_MESSAGE: 'none',
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
94 PERM_PRESENCE: 'none'}
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
95
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
96 @property
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
97 def permissions(self):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
98 return self._permissions
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
99
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
100 def connectionInitialized(self):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
101 self.xmlstream.addObserver(PRIV_ENT_ADV_XPATH, self.onAdvertise)
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
102
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
103 def onAdvertise(self, message):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
104 """Managage the <message/> advertising privileges
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
105
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
106 self._permissions will be updated according to advertised privileged
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
107 """
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
108 privilege_elt = message.elements(PRIV_ENT_NS, 'privilege').next()
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
109 for perm_elt in privilege_elt.elements(PRIV_ENT_NS):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
110 try:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
111 if perm_elt.name != 'perm':
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
112 raise InvalidStanza(u'unexpected element {}'.format(perm_elt.name))
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
113 perm_access = perm_elt['access']
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
114 perm_type = perm_elt['type']
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
115 try:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
116 if perm_type not in TO_CHECK[perm_access]:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
117 raise InvalidStanza(u'bad type [{}] for permission {}'.format(perm_type, perm_access))
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
118 except KeyError:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
119 raise InvalidStanza(u'bad permission [{}]'.format(perm_access))
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
120 except InvalidStanza as e:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
121 log.msg("Invalid stanza received ({}), setting permission to none".format(e))
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
122 for perm in self._permissions:
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
123 self._permissions[perm] = 'none'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
124 break
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
125
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
126 self._permissions[perm_access] = perm_type or 'none'
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
127
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
128 log.msg('Privileges updated: roster={roster}, message={message}, presence={presence}'.format(**self._permissions))
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
129
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
130
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def getRoster(self, to_jid):
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
132 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
133 Retrieve contact list.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
134
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
135 @return: Roster as a mapping from L{JID} to L{RosterItem}.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
136 @rtype: L{twisted.internet.defer.Deferred}
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
137 """
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
138 if self._permissions[PERM_ROSTER] not in ('get', 'both'):
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
139 log.msg("WARNING: permission not allowed to get roster")
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
140 raise failure.Failure(NotAllowedError('roster get is not allowed'))
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
141
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
142 def processRoster(result):
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
143 roster = {}
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
144 for element in result.elements(ROSTER_NS, 'item'):
253
06494c9b25f2 update to fix broken RemoteRoster after Wokkel 0.7.1 changes
Goffi <goffi@goffi.org>
parents: 242
diff changeset
145 item = xmppim.RosterItem.fromElement(element)
06494c9b25f2 update to fix broken RemoteRoster after Wokkel 0.7.1 changes
Goffi <goffi@goffi.org>
parents: 242
diff changeset
146 roster[item.entity] = item
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
147
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return roster
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
149
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
150 iq = IQ(self.xmlstream, 'get')
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
151 iq.addElement((ROSTER_NS, 'query'))
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
152 iq["to"] = to_jid.userhost()
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
153 d = iq.send()
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
154 d.addCallback(processRoster)
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
155 return d
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
156
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
157