Mercurial > libervia-backend
annotate src/tmp/wokkel/mam.py @ 1386:1f3513cfb246
quick_frontend, primivitus: remove QuickChat.getUserNick + primivitus ChatText gets the user nick directly from parent Chat instance
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 23 Mar 2015 15:38:32 +0100 |
parents | d9939b476526 |
children | e5393b12dd0f |
rev | line source |
---|---|
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 # -*- test-case-name: wokkel.test.test_mam -*- |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 # Copyright (c) Adrien Cossa. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # See LICENSE for details. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 XMPP Message Archive Management protocol. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 This protocol is specified in |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 from dateutil.tz import tzutc |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
14 |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 from zope.interface import Interface, implements |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
16 |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 from twisted.words.protocols.jabber.xmlstream import IQ, toResponse |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 from twisted.words.xish import domish |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 from twisted.words.protocols.jabber import jid |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
20 from twisted.python import log |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
21 |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
23 from wokkel import disco, data_form, delay |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
24 |
1285
ed2c718bfe03
tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents:
1283
diff
changeset
|
25 import rsm |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 NS_MAM = 'urn:xmpp:mam:0' |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
28 NS_FORWARD = 'urn:xmpp:forward:0' |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 FIELDS_REQUEST = "/iq[@type='get']/query[@xmlns='%s']" % NS_MAM |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 ARCHIVE_REQUEST = "/iq[@type='set']/query[@xmlns='%s']" % NS_MAM |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 PREFS_GET_REQUEST = "/iq[@type='get']/prefs[@xmlns='%s']" % NS_MAM |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 PREFS_SET_REQUEST = "/iq[@type='set']/prefs[@xmlns='%s']" % NS_MAM |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 # TODO: add the tests! |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 class MAMError(Exception): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 MAM error. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 class Unsupported(MAMError): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 def __init__(self, feature, text=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 self.feature = feature |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 MAMError.__init__(self, 'feature-not-implemented', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 'unsupported', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 feature, |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 text) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 def __str__(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 message = MAMError.__str__(self) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 message += ', feature %r' % self.feature |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 return message |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 class MAMQueryRequest(): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 A Message Archive Management <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 @ivar form: Data Form specifing the filters. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 @itype form: L{data_form.Form} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 @ivar rsm: RSM request instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 @itype rsm: L{rsm.RSMRequest} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 @ivar node: pubsub node id if querying a pubsub node, else None. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 @itype form: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 form = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 rsm = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 node = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 def __init__(self, form=None, rsm=None, node=None): |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
77 if form is not None: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
78 assert(form.formType == 'submit') |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 self.form = form |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 self.rsm = rsm |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 self.node = node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 """Parse the DOM representation of a MAM <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 @param element: MAM <query/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 @type element: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 @return: MAMQueryRequest instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 @rtype: L{MAMQueryRequest} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 if element.uri != NS_MAM or element.name != 'query': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 raise MAMError('Element provided is not a MAM <query/> request') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 form = data_form.findForm(element, NS_MAM) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 rsm_request = rsm.RSMRequest.parse(element) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 except rsm.RSMNotFoundError: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 rsm_request = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 node = element['node'] if element.hasAttribute('node') else None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 return MAMQueryRequest(form, rsm_request, node) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 def toElement(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 Return the DOM representation of this RSM <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 @rtype: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 mam_elt = domish.Element((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 if self.node is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 mam_elt['node'] = self.node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 if self.form is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 mam_elt.addChild(self.form.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 if self.rsm is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 mam_elt.addChild(self.rsm.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
116 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 """Embed the DOM representation of this MAM request in the given element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 @type parent: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 @rtype: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 assert(parent.name == 'iq') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 class MAMPrefs(): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 A Message Archive Management <prefs/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 @param default: A value in ('always', 'never', 'roster'). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 @type : C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 @param always (list): A list of JID instances. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 @type always: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 @param never (list): A list of JID instances. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 default = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 always = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 never = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 def __init__(self, default=None, always=None, never=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 if default: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 assert(default in ('always', 'never', 'roster')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 self.default = default |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 if always: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 assert(isinstance(always, list)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 self.always = always |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 else: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 self.always = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 if never: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 assert(isinstance(never, list)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 self.never = never |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 else: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 self.never = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 """Parse the DOM representation of a MAM <prefs/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 @param element: MAM <prefs/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 @type element: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 @return: MAMPrefs instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 @rtype: L{MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 if element.uri != NS_MAM or element.name != 'prefs': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 raise MAMError('Element provided is not a MAM <prefs/> request') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 default = element['default'] if element.hasAttribute('default') else None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 prefs = {} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 prefs[attr] = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 pref = domish.generateElementsNamed(element.elements(), attr).next() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 for jid_s in domish.generateElementsNamed(pref.elements(), 'jid'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 prefs[attr].append(jid.JID(jid_s)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 except StopIteration: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 pass |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 return MAMPrefs(default, **prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 def toElement(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 Return the DOM representation of this RSM <prefs/>request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 @rtype: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 mam_elt = domish.Element((NS_MAM, 'prefs')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 if self.default: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 mam_elt['default'] = self.default |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 attr_elt = mam_elt.addElement(attr) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 jids = getattr(self, attr) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 for jid in jids: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 attr_elt.addElement('jid', content=jid.full()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 """Embed the DOM representation of this MAM request in the given element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 @type parent: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 @rtype: L{Element<twisted.words.xish.domish.Element>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 assert(parent.name == 'iq') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 class MAMClient(XMPPHandler): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 MAM client. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 This handler implements the protocol for sending out MAM requests. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 def queryArchive(self, service=None, form=None, rsm=None, node=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 """Query a user, MUC or pubsub archive. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 @param service: Entity offering the MAM service (None for user archives). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 @param form: Data Form to filter the request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 @type form: L{Form<wokkel.data_form.Form>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 @param rsm: RSM request instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 @param node: Pubsub node to query, or None if inappropriate. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 @type node: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 @return: A deferred that fires upon receiving a response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 MAMQueryRequest(form, rsm, node).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 return iq.send(to=service.full() if service else None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 def queryFields(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 """Ask the server about additional supported fields. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 @param service: Entity offering the MAM service (None for user archives). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 @return: A deferred that fires upon receiving a response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 # http://xmpp.org/extensions/xep-0313.html#query-form |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 MAMQueryRequest().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
272 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 return iq.send(to=service.full() if service else None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 def queryPrefs(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 """Retrieve the current user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 @param service: Entity offering the MAM service (None for user archives). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 @return: A deferred that fires upon receiving a response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 # http://xmpp.org/extensions/xep-0313.html#prefs |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 MAMPrefs().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 return iq.send(to=service.full() if service else None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 def setPrefs(self, service=None, default='roster', always=None, never=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 """Set new user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 @param service: Entity offering the MAM service (None for user archives). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 @param default: A value in ('always', 'never', 'roster'). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 @type : C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 @param always (list): A list of JID instances. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 @type always: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 @param never (list): A list of JID instances. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 @return: A deferred that fires upon receiving a response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 # http://xmpp.org/extensions/xep-0313.html#prefs |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 assert(default is not None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 MAMPrefs(default, always, never).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 return iq.send(to=service.full() if service else None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 class IMAMResource(Interface): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
326 def onArchiveRequest(self, mam, requestor): |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 @param mam: The MAM <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 @type mam: L{MAMQueryReques<wokkel.mam.MAMQueryRequest>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 @return: The RSM answer. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 def onPrefsGetRequest(self, requestor): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 @return: The current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 def onPrefsSetRequest(self, prefs, requestor): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 @param prefs: The new settings to set. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 @type prefs: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 @return: The new current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 class MAMService(XMPPHandler, IQHandlerMixin): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 Protocol implementation for a MAM service. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 This handler waits for XMPP Ping requests and sends a response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 implements(disco.IDisco) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 ARCHIVE_REQUEST: '_onArchiveRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 PREFS_GET_REQUEST: '_onPrefsGetRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 PREFS_SET_REQUEST: '_onPrefsSetRequest' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 } |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 _legacyFilters = {'start': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 'var': 'start', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 'label': 'Starting time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 'desc': 'Starting time a the result period.', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 }, |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 'end': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 'var': 'end', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 'label': 'Ending time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 'desc': 'Ending time of the result period.', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 }, |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 'with': {'fieldType': 'jid-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 'var': 'with', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 'label': 'Entity', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 'desc': 'Entity against which to match message.', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 }, |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
393 } |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
394 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
395 extra_filters = {} |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
396 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 def __init__(self, resource): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
398 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
399 @param resource: instance implementing IMAMResource |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
400 @type resource: L{object} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
401 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
402 self.resource = resource |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
403 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
404 def connectionInitialized(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 Called when the XML stream has been initialized. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
408 This sets up an observer for incoming ping requests. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 self.xmlstream.addObserver(PREFS_GET_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
413 self.xmlstream.addObserver(PREFS_SET_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 def addFilter(self, field): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 Add a new filter for querying MAM archive. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 @param field: dictionary specifying the attributes to build a |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 wokkel.data_form.Field. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 @type field: C{dict} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 """ |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
423 self.extra_filters[field.var] = field |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 def _onFieldsRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 Called when a fields request has been received. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
429 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 query = response.addElement((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 query.addChild(buildForm('form', extra=self.extra_filters).toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
435 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
437 def _onArchiveRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
438 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 Called when a message archive request has been received. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 This immediately replies with a result response, followed by the |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 list of archived message and the finally the <fin/> message. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 mam_ = MAMQueryRequest.parse(iq.query) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
448 requestor = jid.JID(iq['from']) |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
449 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
450 # remove unsupported filters |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
451 unsupported_fields = [] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
452 if mam_.form: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
453 for key, field in mam_.form.fields.iteritems(): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
454 if key not in self._legacyFilters and key not in self.extra_filters: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
455 log.msg('Ignored unsupported MAM filter: %s' % field) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
456 unsupported_fields.append(key) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
457 for key in unsupported_fields: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
458 del mam_.form.fields[key] |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
459 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
460 def forward_message(id_, elt, date): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
461 msg = domish.Element((None, 'message')) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
462 msg['to'] = iq['from'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
463 result = msg.addElement('result', NS_MAM) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
464 if iq.hasAttribute('queryid'): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
465 result['queryid'] = iq.query['queryid'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
466 result['id'] = id_ |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
467 forward = result.addElement('forwarded', NS_FORWARD) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
468 forward.addChild(delay.Delay(date).toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
469 forward.addChild(elt) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
470 self.xmlstream.send(msg) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
471 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
472 def cb(result): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
473 msg_data, rsm_elt = result |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
474 for data in msg_data: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
475 forward_message(*data) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
476 msg = domish.Element((None, 'message')) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
477 msg['to'] = iq['from'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
478 fin = msg.addElement('fin', NS_MAM) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
479 if iq.hasAttribute('queryid'): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
480 fin['queryid'] = iq.query['queryid'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
481 if rsm_elt is not None: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
482 fin.addChild(rsm_elt) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
483 self.xmlstream.send(msg) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
484 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
485 self.resource.onArchiveRequest(mam_, requestor).addCallback(cb) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
487 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
488 def _onPrefsGetRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
489 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
490 Called when a prefs get request has been received. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
491 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
492 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
493 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
494 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
495 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
496 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
497 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
498 def cb(prefs): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
499 response.addChild(prefs.toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
500 self.xmlstream.send(response) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
501 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
502 self.resource.onPrefsGetRequest(requestor).addCallback(cb) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
503 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
504 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
505 def _onPrefsSetRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
506 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
507 Called when a prefs get request has been received. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
508 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
509 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
510 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
512 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
513 prefs = MAMPrefs.parse(iq.prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
514 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
515 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
516 def cb(prefs): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
517 response.addChild(prefs.toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
518 self.xmlstream.send(response) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
519 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
520 self.resource.onPrefsSetRequest(prefs, requestor).addCallback(cb) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
521 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
522 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
523 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
524 return [disco.DiscoFeature(NS_MAM)] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
525 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
527 return [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
529 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
530 def datetime2utc(datetime): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
531 """Convert a datetime to a XEP-0082 compliant UTC datetime. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
533 @param datetime: Offset-aware timestamp to convert. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
534 @type datetime: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
535 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
536 @return: The datetime converted to UTC. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
537 @rtype: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
538 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
539 stampFormat = '%Y-%m-%dT%H:%M:%SZ' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
540 return datetime.astimezone(tzutc()).strftime(stampFormat) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 def buildForm(formType='submit', start=None, end=None, with_jid=None, extra=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 """Prepare a Data Form for MAM. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
545 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
546 @param formType: The type of the Data Form ('submit' or 'form'). |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
547 @type formType: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 @param start: Offset-aware timestamp to filter out older messages. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 @type start: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
552 @param end: Offset-aware timestamp to filter out later messages. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
553 @type end: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
554 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
555 @param with_jid: JID against which to match messages. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
556 @type with_jid: L{JID<twisted.words.protocols.jabber.jid.JID>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
557 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
558 @param extra: list of extra fields that are not defined by the |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 specification. Each element of the list must be a dictionary |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
560 specifying the attributes to build a wokkel.data_form.Field. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
561 @type: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
562 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
563 @return: XEP-0004 Data Form object. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
564 @rtype: L{Form<wokkel.data_form.Form>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
565 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 form = data_form.Form(formType, formNamespace=NS_MAM) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
567 filters = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
568 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
569 if formType == 'form': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
570 filters.extend(MAMService._legacyFilters.values()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
571 elif formType == 'submit': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
572 if start: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
573 filters.append({'var': 'start', 'value': datetime2utc(start)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
574 if end: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
575 filters.append({'var': 'end', 'value': datetime2utc(end)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
576 if with_jid: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
577 # must specify the field type to overwrite default value in Field.__init__ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
578 filters.append({'fieldType': 'jid-single', 'var': 'with', 'value': with_jid.full()}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
579 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
580 if extra is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
581 filters.extend(extra) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
582 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 for field in filters: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 form.addField(data_form.Field(**field)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
586 return form |