Mercurial > libervia-backend
annotate src/tmp/wokkel/mam.py @ 1283:7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 09 Jan 2015 10:50:11 +0100 |
parents | |
children | ed2c718bfe03 |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 from zope.interface import Interface, implements |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 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
|
16 from twisted.words.xish import domish |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 from twisted.words.protocols.jabber import jid |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 from wokkel import disco, rsm, data_form |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 NS_MAM = 'urn:xmpp:mam:0' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 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
|
28 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 # TODO: add the tests! |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 class MAMError(Exception): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 MAM error. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 """ |
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 Unsupported(MAMError): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 def __init__(self, feature, text=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 self.feature = feature |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 MAMError.__init__(self, 'feature-not-implemented', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 'unsupported', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 feature, |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 text) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 def __str__(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 message = MAMError.__str__(self) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 message += ', feature %r' % self.feature |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 return message |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 |
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 class MAMQueryRequest(): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 A Message Archive Management <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 @ivar form: Data Form specifing the filters. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 @itype form: L{data_form.Form} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 @ivar rsm: RSM request instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 @itype rsm: L{rsm.RSMRequest} |
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 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
|
63 @itype form: C{unicode} |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 form = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 rsm = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 node = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 def __init__(self, form=None, rsm=None, node=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 self.form = form |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 self.rsm = rsm |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 self.node = node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 """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
|
78 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 @param element: MAM <query/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 @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
|
81 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 @return: MAMQueryRequest instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 @rtype: L{MAMQueryRequest} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 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
|
86 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
|
87 form = data_form.findForm(element, NS_MAM) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 rsm_request = rsm.RSMRequest.parse(element) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 except rsm.RSMNotFoundError: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 rsm_request = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 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
|
93 return MAMQueryRequest(form, rsm_request, node) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 def toElement(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 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
|
98 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 @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
|
100 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 mam_elt = domish.Element((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 if self.node is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 mam_elt['node'] = self.node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 if self.form is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 mam_elt.addChild(self.form.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 if self.rsm is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 mam_elt.addChild(self.rsm.toElement()) |
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 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 """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
|
113 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 @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
|
116 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 @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
|
119 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 assert(parent.name == 'iq') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 return mam_elt |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 class MAMPrefs(): |
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 A Message Archive Management <prefs/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 @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
|
131 @type : C{unicode} |
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 @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
|
134 @type always: C{list} |
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 @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
|
137 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 default = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 always = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 never = None |
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 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
|
145 if default: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 assert(default in ('always', 'never', 'roster')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 self.default = default |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 if always: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 assert(isinstance(always, list)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 self.always = always |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 else: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 self.always = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 if never: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 assert(isinstance(never, list)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 self.never = never |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 else: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 self.never = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 """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
|
162 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 @param element: MAM <prefs/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 @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
|
165 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 @return: MAMPrefs instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 @rtype: L{MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 prefs = {} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 prefs[attr] = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 pref = domish.generateElementsNamed(element.elements(), attr).next() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 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
|
178 prefs[attr].append(jid.JID(jid_s)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 except StopIteration: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 pass |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 return MAMPrefs(default, **prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 def toElement(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 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
|
186 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 @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
|
188 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 mam_elt = domish.Element((NS_MAM, 'prefs')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 if self.default: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 mam_elt['default'] = self.default |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 attr_elt = mam_elt.addElement(attr) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 jids = getattr(self, attr) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 for jid in jids: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 attr_elt.addElement('jid', content=jid.full()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 """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
|
201 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 @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
|
204 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 @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
|
207 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 assert(parent.name == 'iq') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 return mam_elt |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 class MAMClient(XMPPHandler): |
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 MAM client. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 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
|
219 """ |
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 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
|
222 """Query a user, MUC or pubsub archive. |
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 @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
|
225 @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
|
226 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 @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
|
228 @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
|
229 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 @param rsm: RSM request instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 @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
|
234 @type node: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 @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
|
238 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 @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
|
240 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 MAMQueryRequest(form, rsm, node).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 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
|
247 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 def queryFields(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 """Ask the server about additional supported fields. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 @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
|
252 @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
|
253 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 @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
|
256 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 @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
|
258 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 # 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
|
261 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 MAMQueryRequest().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 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
|
266 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 def queryPrefs(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 """Retrieve the current user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 @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
|
271 @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
|
272 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 @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
|
275 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 @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
|
277 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 # 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
|
280 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 MAMPrefs().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 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
|
285 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 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
|
287 """Set new user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 @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
|
290 @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
|
291 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 @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
|
293 @type : C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 @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
|
296 @type always: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 @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
|
299 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 @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
|
303 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 @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
|
305 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 # 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
|
308 assert(default is not None) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 MAMPrefs(default, always, never).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 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
|
314 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 class IMAMResource(Interface): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 def onArchiveRequest(self, mam, rsm, requestor): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 @param mam: The MAM <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 @type mam: L{MAMQueryReques<wokkel.mam.MAMQueryRequest>} |
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 @param rsm: The RSM request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 @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
|
329 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 @return: The RSM answer. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 def onPrefsGetRequest(self, requestor): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 @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
|
339 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 @return: The current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 def onPrefsSetRequest(self, prefs, requestor): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 @param prefs: The new settings to set. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 @type prefs: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 @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
|
352 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 @return: The new current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 |
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 class MAMService(XMPPHandler, IQHandlerMixin): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 Protocol implementation for a MAM service. |
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 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
|
363 """ |
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 implements(disco.IDisco) |
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 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 ARCHIVE_REQUEST: '_onArchiveRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 PREFS_GET_REQUEST: '_onPrefsGetRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 PREFS_SET_REQUEST: '_onPrefsSetRequest' |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 _legacyFilters = {'start': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 'var': 'start', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 'label': 'Starting time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 'desc': 'Starting time a the result period.', |
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 'end': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 'var': 'end', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 'label': 'Ending time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 'desc': 'Ending time of 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 'with': {'fieldType': 'jid-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 'var': 'with', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 'label': 'Entity', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 'desc': 'Entity against which to match message.', |
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 } |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 extra_filters = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 def __init__(self, resource): |
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 @param resource: instance implementing IMAMResource |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
395 @type resource: L{object} |
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 self.resource = 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 def connectionInitialized(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
400 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
401 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
|
402 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
403 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
|
404 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 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
|
408 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
|
409 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 def addFilter(self, field): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 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
|
413 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 @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
|
415 wokkel.data_form.Field. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 @type field: C{dict} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 self.extra_filters.append(field) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 def _onFieldsRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 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
|
423 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 query = response.addElement((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 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
|
429 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 def _onArchiveRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 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
|
435 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 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
|
437 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
|
438 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 mam_ = MAMQueryRequest.parse(iq.query) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 rsm_ = rsm.RSMRequest.parse(iq.query) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 except rsm.RSMNotFoundError: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 rsm_ = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
448 rsm_response = self.resource.onArchiveRequest(mam_, rsm_, requestor) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
449 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
450 msg = domish.Element((None, 'message')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 fin = msg.addElement('fin', NS_MAM) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 if iq.hasAttribute('queryid'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
453 fin['queryid'] = iq.query['queryid'] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 if rsm_response is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 fin.addChild(rsm_response.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
456 self.xmlstream.send(msg) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
457 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
458 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
459 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
460 def _onPrefsGetRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
461 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
462 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
|
463 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
464 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
465 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
466 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
467 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
469 prefs = self.resource.onPrefsGetRequest(requestor) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
470 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
471 response.addChild(prefs.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
472 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
473 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
474 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
475 def _onPrefsSetRequest(self, iq): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
476 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
477 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
|
478 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 This immediately replies with a result response. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
480 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
482 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
483 prefs = MAMPrefs.parse(iq.prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
484 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
485 prefs = self.resource.onPrefsSetRequest(prefs, requestor) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
487 response.addChild(prefs.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
488 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
489 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
490 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
491 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
492 return [disco.DiscoFeature(NS_MAM)] |
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 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
495 return [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
496 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
497 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
498 def datetime2utc(datetime): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
499 """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
|
500 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
501 @param datetime: Offset-aware timestamp to convert. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
502 @type datetime: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
503 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
504 @return: The datetime converted to UTC. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
505 @rtype: C{unicode} |
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 stampFormat = '%Y-%m-%dT%H:%M:%SZ' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
508 return datetime.astimezone(tzutc()).strftime(stampFormat) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
509 |
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 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
|
512 """Prepare a Data Form for MAM. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
513 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
514 @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
|
515 @type formType: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
516 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
517 @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
|
518 @type start: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
519 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
520 @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
|
521 @type end: L{datetime<datetime.datetime>} |
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 @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
|
524 @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
|
525 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 @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
|
527 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
|
528 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
|
529 @type: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
530 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
531 @return: XEP-0004 Data Form object. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 @rtype: L{Form<wokkel.data_form.Form>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
533 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
534 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
|
535 filters = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
536 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
537 if formType == 'form': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
538 filters.extend(MAMService._legacyFilters.values()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
539 elif formType == 'submit': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
540 if start: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 filters.append({'var': 'start', 'value': datetime2utc(start)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 if end: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 filters.append({'var': 'end', 'value': datetime2utc(end)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 if with_jid: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
545 # 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
|
546 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
|
547 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 if extra is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 filters.extend(extra) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 for field in filters: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
552 form.addField(data_form.Field(**field)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
553 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
554 return form |