annotate sat_pubsub/remote_roster.py @ 280:798cb8962c0b

MAM (XEP-0313) support: first draft
author souliane <souliane@mailoo.org>
date Fri, 09 Jan 2015 10:57:10 +0100
parents d55620ceafed
children 002c59dbc23f
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
255
d55620ceafed copyright update
Goffi <goffi@goffi.org>
parents: 253
diff changeset
6 Copyright (c) 2012, 2013 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
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
64 from twisted.words.xish import domish
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
65
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
66 NS_ROSTER = 'jabber:iq:roster'
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
67
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
68 class RosterClient(xmppim.RosterClientProtocol):
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
69 """Similar to classic RosterClient, but we can get any jid managed by the host server"""
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
70 #FIXME: need to manage updates, and database sync
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
71 #TODO: cache
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
72
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def getRoster(self, to_jid):
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
74 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
75 Retrieve contact list.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
76
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
77 @return: Roster as a mapping from L{JID} to L{RosterItem}.
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @rtype: L{twisted.internet.defer.Deferred}
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
79 """
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
80
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def processRoster(result):
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
82 roster = {}
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
83 for element in domish.generateElementsQNamed(result.query.children,
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
84 'item', NS_ROSTER):
253
06494c9b25f2 update to fix broken RemoteRoster after Wokkel 0.7.1 changes
Goffi <goffi@goffi.org>
parents: 242
diff changeset
85 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
86 roster[item.entity] = item
242
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
87
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return roster
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
89
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
90 iq = IQ(self.xmlstream, 'get')
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
91 iq.addElement((NS_ROSTER, 'query'))
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
92 iq["to"] = to_jid.userhost()
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
93 d = iq.send()
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
94 d.addCallback(processRoster)
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
95 return d
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
96
a6170637690d remote roster partial support
Goffi <goffi@goffi.org>
parents:
diff changeset
97