annotate wokkel/mam.py @ 4:66a7586e49f8

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