Mercurial > sat_tmp
annotate wokkel/mam.py @ 40:03224edb88af
tmp (wokkel/pubsub): subscriptions improvments:
- added "none" state to Subscription, it is needed to remove existing subscription
- implemented subscriptionsGet and subscriptionsSet
- replaced "nodeOrEmpty" by "node" for affiliationsGet, affiliationsSet and subscriptionsGet as node is mandatory for these commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 20 Aug 2017 10:29:26 +0200 |
parents | c0f71fd5ed6b |
children |
rev | line source |
---|---|
8 | 1 # -*- coding: utf-8 -*- |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- test-case-name: wokkel.test.test_mam -*- |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 # |
6 | 4 # SàT Wokkel extension for Message Archive Management (XEP-0313) |
20 | 5 # Copyright (C) 2015 Jérôme Poisson (goffi@goffi.org) |
6 | 6 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org) |
7 | |
8 # This program is free software: you can redistribute it and/or modify | |
9 # it under the terms of the GNU Affero General Public License as published by | |
10 # the Free Software Foundation, either version 3 of the License, or | |
11 # (at your option) any later version. | |
12 | |
13 # This program is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 # GNU Affero General Public License for more details. | |
17 | |
18 # You should have received a copy of the GNU Affero General Public License | |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 XMPP Message Archive Management protocol. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 This protocol is specified in |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
28 from dateutil import tz |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
29 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
30 from zope.interface import implements |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
31 from zope.interface import Interface |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
32 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
33 from twisted.words.protocols.jabber import xmlstream |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 from twisted.words.xish import domish |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 from twisted.words.protocols.jabber import jid |
29
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
36 from twisted.words.protocols.jabber import error |
20 | 37 from twisted.internet import defer |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
38 from twisted.python import log |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
39 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
40 from wokkel import subprotocols |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
41 from wokkel import disco |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
42 from wokkel import data_form |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
43 from wokkel import delay |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
44 |
2
4369549244e8
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1
diff
changeset
|
45 import rsm |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 |
20 | 47 NS_MAM = 'urn:xmpp:mam:1' |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
48 NS_FORWARD = 'urn:xmpp:forward:0' |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 FIELDS_REQUEST = "/iq[@type='get']/query[@xmlns='%s']" % NS_MAM |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 ARCHIVE_REQUEST = "/iq[@type='set']/query[@xmlns='%s']" % NS_MAM |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 PREFS_GET_REQUEST = "/iq[@type='get']/prefs[@xmlns='%s']" % NS_MAM |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 PREFS_SET_REQUEST = "/iq[@type='set']/prefs[@xmlns='%s']" % NS_MAM |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 # TODO: add the tests! |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 |
29
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
57 |
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
58 class MAMError(error.StanzaError): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 MAM error. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 """ |
29
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
62 def __init__(self, text=None): |
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
63 error.StanzaError.__init__(self, 'bad-request', text=text) |
17ab4fbce513
tmp (wokkel.mam): MAMErrow now inherit from StanzaError so it can be handler properly by services
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
64 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 class Unsupported(MAMError): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 def __init__(self, feature, text=None): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 self.feature = feature |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 MAMError.__init__(self, 'feature-not-implemented', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 'unsupported', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 feature, |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 text) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 def __str__(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 message = MAMError.__str__(self) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 message += ', feature %r' % self.feature |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 return message |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
80 class MAMRequest(object): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 A Message Archive Management <query/> request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 @ivar form: Data Form specifing the filters. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 @itype form: L{data_form.Form} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 @ivar rsm: RSM request instance. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 @itype rsm: L{rsm.RSMRequest} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 @ivar node: pubsub node id if querying a pubsub node, else None. |
33
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
91 @itype node: C{unicode} |
20 | 92 |
93 @ivar query_id: id to use to track the query | |
33
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
94 @itype query_id: C{unicode} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 """ |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
96 # FIXME: should be based on generic.Stanza |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
98 def __init__(self, form=None, rsm_=None, node=None, query_id=None, sender=None, recipient=None): |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
99 if form is not None: |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
100 assert form.formType == 'submit' |
20 | 101 assert form.formNamespace == NS_MAM |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 self.form = form |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
103 self.rsm = rsm_ |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 self.node = node |
20 | 105 self.query_id = query_id |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
106 self.sender = sender |
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
107 self.recipient = recipient |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 @classmethod |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
110 def fromElement(cls, iq): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 """Parse the DOM representation of a MAM <query/> request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
113 @param iq: <iq/> element containing a MAM <query/>. |
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
114 @type iq: L{Element<twisted.words.xish.domish.Element>} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
116 @return: MAMRequest instance. |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
117 @rtype: L{MAMRequest} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 """ |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
119 sender = jid.JID(iq.getAttribute('from')) |
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
120 recipient = jid.JID(iq.getAttribute('to')) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 try: |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
122 query = iq.elements(NS_MAM, 'query').next() |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
123 except StopIteration: |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
124 raise MAMError("Can't find MAM <query/> in element") |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
125 form = data_form.findForm(query, NS_MAM) |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
126 try: |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
127 rsm_request = rsm.RSMRequest.fromElement(query) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 except rsm.RSMNotFoundError: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 rsm_request = None |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
130 node = query.getAttribute('node') |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
131 query_id = query.getAttribute('queryid') |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
132 return MAMRequest(form, rsm_request, node, query_id, sender, recipient) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 def toElement(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 Return the DOM representation of this RSM <query/> request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 @rtype: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 mam_elt = domish.Element((NS_MAM, 'query')) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 if self.node is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 mam_elt['node'] = self.node |
20 | 143 if self.query_id is not None: |
144 mam_elt['queryid'] = self.query_id | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 if self.form is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 mam_elt.addChild(self.form.toElement()) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 if self.rsm is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 mam_elt.addChild(self.rsm.toElement()) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 return mam_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 def render(self, parent): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 """Embed the DOM representation of this MAM request in the given element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 @param parent: parent IQ element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 @type parent: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 @return: MAM request element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 @rtype: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 """ |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
161 assert parent.name == 'iq' |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 mam_elt = self.toElement() |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 parent.addChild(mam_elt) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 return mam_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
167 class MAMPrefs(object): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 A Message Archive Management <prefs/> request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 @param default: A value in ('always', 'never', 'roster'). |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
172 @type : C{unicode} or C{None} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 @param always (list): A list of JID instances. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 @type always: C{list} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 @param never (list): A list of JID instances. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 @type never: C{list} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 |
33
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
181 def __init__(self, default=None, always=None, never=None): |
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
182 if default is not None: |
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
183 # default must be defined in response, but can be empty in request (see http://xmpp.org/extensions/xep-0313.html#config) |
c0f71fd5ed6b
tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents:
30
diff
changeset
|
184 assert default in ('always', 'never', 'roster') |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
185 self.default = default |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
186 if always is not None: |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
187 assert isinstance(always, list) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 else: |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
189 always = [] |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
190 self.always = always |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
191 if never is not None: |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
192 assert isinstance(never, list) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 else: |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
194 never = [] |
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
195 self.never = never |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 @classmethod |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
198 def fromElement(cls, prefs_elt): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 """Parse the DOM representation of a MAM <prefs/> request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 |
20 | 201 @param prefs_elt: MAM <prefs/> request element. |
202 @type prefs_elt: L{Element<twisted.words.xish.domish.Element>} | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 @return: MAMPrefs instance. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 @rtype: L{MAMPrefs} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 """ |
20 | 207 if prefs_elt.uri != NS_MAM or prefs_elt.name != 'prefs': |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 raise MAMError('Element provided is not a MAM <prefs/> request') |
20 | 209 try: |
210 default = prefs_elt['default'] | |
211 except KeyError: | |
212 # FIXME: return proper error here | |
213 raise MAMError('Element provided is not a valid MAM <prefs/> request') | |
214 | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 prefs = {} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 for attr in ('always', 'never'): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 prefs[attr] = [] |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 try: |
20 | 219 pref = prefs_elt.elements(NS_MAM, attr).next() |
220 except StopIteration: | |
221 # FIXME: return proper error here | |
222 raise MAMError('Element provided is not a valid MAM <prefs/> request') | |
223 else: | |
224 for jid_s in pref.elements(NS_MAM, 'jid'): | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 prefs[attr].append(jid.JID(jid_s)) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 return MAMPrefs(default, **prefs) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 def toElement(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 Return the DOM representation of this RSM <prefs/>request. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 @rtype: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 mam_elt = domish.Element((NS_MAM, 'prefs')) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 if self.default: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 mam_elt['default'] = self.default |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 for attr in ('always', 'never'): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 attr_elt = mam_elt.addElement(attr) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 jids = getattr(self, attr) |
4
66a7586e49f8
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
240 for jid_ in jids: |
66a7586e49f8
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
241 attr_elt.addElement('jid', content=jid_.full()) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 return mam_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 def render(self, parent): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 """Embed the DOM representation of this MAM request in the given element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 @param parent: parent IQ element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 @type parent: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 @return: MAM request element. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 @rtype: L{Element<twisted.words.xish.domish.Element>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 """ |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
253 assert parent.name == 'iq' |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 mam_elt = self.toElement() |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 parent.addChild(mam_elt) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 return mam_elt |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
259 class MAMClient(subprotocols.XMPPHandler): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 MAM client. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 This handler implements the protocol for sending out MAM requests. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
266 def queryArchive(self, mam_query, service=None, sender=None): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 """Query a user, MUC or pubsub archive. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
269 @param mam_query: query to use |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
270 @type form: L{MAMRequest} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
272 @param service: Entity offering the MAM service (None for user server). |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
273 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 @param sender: Optional sender address. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 @return: A deferred that fires upon receiving a response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 """ |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
281 iq = xmlstream.IQ(self.xmlstream, 'set') |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
282 mam_query.render(iq) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 if sender is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 iq['from'] = unicode(sender) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 return iq.send(to=service.full() if service else None) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 def queryFields(self, service=None, sender=None): |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
288 """Ask the server about supported fields. |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 @param service: Entity offering the MAM service (None for user archives). |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 @param sender: Optional sender address. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 |
20 | 296 @return: data Form with the fields, or None if not found |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 # http://xmpp.org/extensions/xep-0313.html#query-form |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
300 iq = xmlstream.IQ(self.xmlstream, 'get') |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
301 MAMRequest().render(iq) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 if sender is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 iq['from'] = unicode(sender) |
20 | 304 d = iq.send(to=service.full() if service else None) |
305 d.addCallback(lambda iq_result: iq_result.elements(NS_MAM, 'query').next()) | |
306 d.addCallback(data_form.findForm, NS_MAM) | |
307 return d | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 def queryPrefs(self, service=None, sender=None): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 """Retrieve the current user preferences. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 @param service: Entity offering the MAM service (None for user archives). |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 @param sender: Optional sender address. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 @return: A deferred that fires upon receiving a response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 # http://xmpp.org/extensions/xep-0313.html#prefs |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
322 iq = xmlstream.IQ(self.xmlstream, 'get') |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 MAMPrefs().render(iq) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 if sender is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 iq['from'] = unicode(sender) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 return iq.send(to=service.full() if service else None) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 def setPrefs(self, service=None, default='roster', always=None, never=None, sender=None): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 """Set new user preferences. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 @param service: Entity offering the MAM service (None for user archives). |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 @param default: A value in ('always', 'never', 'roster'). |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 @type : C{unicode} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 @param always (list): A list of JID instances. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 @type always: C{list} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 @param never (list): A list of JID instances. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 @type never: C{list} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 @param sender: Optional sender address. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 @return: A deferred that fires upon receiving a response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 # http://xmpp.org/extensions/xep-0313.html#prefs |
7
1e21b4e94566
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
350 assert default is not None |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
351 iq = xmlstream.IQ(self.xmlstream, 'set') |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 MAMPrefs(default, always, never).render(iq) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 if sender is not None: |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 iq['from'] = unicode(sender) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 return iq.send(to=service.full() if service else None) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 class IMAMResource(Interface): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
360 def onArchiveRequest(self, mam): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 @param mam: The MAM <query/> request. |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
364 @type mam: L{MAMQueryReques<wokkel.mam.MAMRequest>} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 @return: The RSM answer. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 def onPrefsGetRequest(self, requestor): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 @param requestor: JID of the requestor. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 @return: The current settings. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 @rtype: L{wokkel.mam.MAMPrefs} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 def onPrefsSetRequest(self, prefs, requestor): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 @param prefs: The new settings to set. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 @type prefs: L{wokkel.mam.MAMPrefs} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 @param requestor: JID of the requestor. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 @return: The new current settings. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 @rtype: L{wokkel.mam.MAMPrefs} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
393 class IMAMService(Interface): |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
394 """ |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
395 Interface for XMPP MAM service. |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
396 """ |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
398 def addFilter(self, field): |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
399 """ |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
400 Add a new filter for querying MAM archive. |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
401 |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
402 @param field: data form field of the filter |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
403 @type field: L{Form<wokkel.data_form.Field>} |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
404 """ |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
405 |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
406 |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
407 class MAMService(subprotocols.XMPPHandler, subprotocols.IQHandlerMixin): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
408 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 Protocol implementation for a MAM service. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 This handler waits for XMPP Ping requests and sends a response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 """ |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
413 implements(IMAMService, disco.IDisco) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
415 _request_class = MAMRequest |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 ARCHIVE_REQUEST: '_onArchiveRequest', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 PREFS_GET_REQUEST: '_onPrefsGetRequest', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 PREFS_SET_REQUEST: '_onPrefsSetRequest' |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 } |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
423 _legacyFilters = {'start': {'fieldType': 'text-single', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 'var': 'start', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 'label': 'Starting time', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 'desc': 'Starting time a the result period.', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 }, |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 'end': {'fieldType': 'text-single', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
429 'var': 'end', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 'label': 'Ending time', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 'desc': 'Ending time of the result period.', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 }, |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 'with': {'fieldType': 'jid-single', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 'var': 'with', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
435 'label': 'Entity', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 'desc': 'Entity against which to match message.', |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
437 }, |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
438 } |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 def __init__(self, resource): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 @param resource: instance implementing IMAMResource |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 @type resource: L{object} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 self.resource = resource |
20 | 446 self.extra_fields = {} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
448 def connectionInitialized(self): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
449 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
450 Called when the XML stream has been initialized. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 This sets up an observer for incoming ping requests. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
453 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
456 self.xmlstream.addObserver(PREFS_GET_REQUEST, self.handleRequest) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
457 self.xmlstream.addObserver(PREFS_SET_REQUEST, self.handleRequest) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
458 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
459 def addFilter(self, field): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
460 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
461 Add a new filter for querying MAM archive. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
462 |
20 | 463 @param field: data form field of the filter |
464 @type field: L{Form<wokkel.data_form.Field>} | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
465 """ |
20 | 466 self.extra_fields[field.var] = field |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
467 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 def _onFieldsRequest(self, iq): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
469 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
470 Called when a fields request has been received. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
471 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
472 This immediately replies with a result response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
473 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
474 iq.handled = True |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
475 query = domish.Element((NS_MAM, 'query')) |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
476 query.addChild(buildForm(extra_fields=self.extra_fields).toElement(), formType='form') |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
477 return query |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
478 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 def _onArchiveRequest(self, iq): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
480 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 Called when a message archive request has been received. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
482 |
20 | 483 This replies with the list of archived message and the <iq> result |
484 @return: A tuple with list of message data (id, element, data) and RSM element | |
485 @rtype: C{tuple} | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 """ |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
487 iq.handled = True |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
488 mam_ = self._request_class.fromElement(iq) |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
489 |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
490 # remove unsupported filters |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
491 unsupported_fields = [] |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
492 if mam_.form: |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
493 for key, field in mam_.form.fields.iteritems(): |
20 | 494 if key not in self._legacyFilters and key not in self.extra_fields: |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
495 log.msg('Ignored unsupported MAM filter: %s' % field) |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
496 unsupported_fields.append(key) |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
497 for key in unsupported_fields: |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
498 del mam_.form.fields[key] |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
499 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
500 def forwardMessage(id_, elt, date): |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
501 msg = domish.Element((None, 'message')) |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
502 msg['to'] = iq['from'] |
20 | 503 result = msg.addElement((NS_MAM, 'result')) |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
504 if mam_.query_id is not None: |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
505 result['queryid'] = mam_.query_id |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
506 result['id'] = id_ |
20 | 507 forward = result.addElement((NS_FORWARD, 'forwarded')) |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
508 forward.addChild(delay.Delay(date).toElement()) |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
509 forward.addChild(elt) |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
510 self.xmlstream.send(msg) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
512 def cb(result): |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
513 msg_data, rsm_elt = result |
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
514 for data in msg_data: |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
515 forwardMessage(*data) |
20 | 516 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
517 fin_elt = domish.Element((NS_MAM, 'fin')) |
20 | 518 |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
519 if rsm_elt is not None: |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
520 fin_elt.addChild(rsm_elt) |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
521 return fin_elt |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
522 |
30
73465c020455
tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
523 d = defer.maybeDeferred(self.resource.onArchiveRequest, mam_) |
20 | 524 d.addCallback(cb) |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
525 return d |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
527 def _onPrefsGetRequest(self, iq): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
529 Called when a prefs get request has been received. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
530 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
531 This immediately replies with a result response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 """ |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
533 iq.handled = True |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
534 requestor = jid.JID(iq['from']) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
535 |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
536 def cb(prefs): |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
537 return prefs.toElement() |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
538 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
539 d = self.resource.onPrefsGetRequest(requestor).addCallback(cb) |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
540 return d |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 def _onPrefsSetRequest(self, iq): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 Called when a prefs get request has been received. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
545 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
546 This immediately replies with a result response. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
547 """ |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
548 iq.handled = True |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
550 prefs = MAMPrefs.fromElement(iq.prefs) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 requestor = jid.JID(iq['from']) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
552 |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
553 def cb(prefs): |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
554 return prefs.toElement() |
3
7eb4d15650dc
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
2
diff
changeset
|
555 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
556 d = self.resource.onPrefsSetRequest(prefs, requestor).addCallback(cb) |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
557 return d |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
558 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
4
66a7586e49f8
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
560 if nodeIdentifier: |
66a7586e49f8
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
561 return [] |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
562 return [disco.DiscoFeature(NS_MAM)] |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
563 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
564 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
565 return [] |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
567 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
568 def datetime2utc(datetime_obj): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
569 """Convert a datetime to a XEP-0082 compliant UTC datetime. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
570 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
571 @param datetime_obj: Offset-aware timestamp to convert. |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
572 @type datetime_obj: L{datetime<datetime.datetime>} |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
573 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
574 @return: The datetime converted to UTC. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
575 @rtype: C{unicode} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
576 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
577 stampFormat = '%Y-%m-%dT%H:%M:%SZ' |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
578 return datetime_obj.astimezone(tz.tzutc()).strftime(stampFormat) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
579 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
580 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
581 def buildForm(start=None, end=None, with_jid=None, extra_fields=None, formType='submit'): |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
582 """Prepare a Data Form for MAM. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 @param start: Offset-aware timestamp to filter out older messages. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 @type start: L{datetime<datetime.datetime>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
586 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
587 @param end: Offset-aware timestamp to filter out later messages. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
588 @type end: L{datetime<datetime.datetime>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
589 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
590 @param with_jid: JID against which to match messages. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 @type with_jid: L{JID<twisted.words.protocols.jabber.jid.JID>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
592 |
20 | 593 @param extra_fields: list of extra data form fields that are not defined by the |
594 specification. | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
595 @type: C{list} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
596 |
24
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
597 @param formType: The type of the Data Form ('submit' or 'form'). |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
598 @type formType: C{unicode} |
0640d72d6841
tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
599 |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
600 @return: XEP-0004 Data Form object. |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
601 @rtype: L{Form<wokkel.data_form.Form>} |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
602 """ |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
603 form = data_form.Form(formType, formNamespace=NS_MAM) |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
604 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
605 if formType == 'form': |
20 | 606 for kwargs in MAMService._legacyFilters.values(): |
607 form.addField(data_form.Field(**kwargs)) | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
608 elif formType == 'submit': |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
609 if start: |
20 | 610 form.addField(data_form.Field(var='start', value=datetime2utc(start))) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
611 if end: |
20 | 612 form.addField(data_form.Field(var='end', value=datetime2utc(end))) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
613 if with_jid: |
20 | 614 form.addField(data_form.Field(fieldType='jid-single', var='with', value=with_jid.full())) |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
615 |
20 | 616 if extra_fields is not None: |
617 for field in extra_fields: | |
618 form.addField(field) | |
1
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
619 |
9d35f88168a1
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
620 return form |