source: ralphm-patches/roster_server.patch @ 49:537d1413b661

Last change on this file since 49:537d1413b661 was 49:537d1413b661, checked in by Ralph Meijer <ralphm@…>, 10 years ago

Save work after moving stuff to keep from wokkel.xmppim to wokkel.im.

File size: 1.8 KB
RevLine 
[49]1diff -r 3c5fb05162e1 wokkel/im.py
2--- a/wokkel/im.py      Wed May 25 09:39:42 2011 +0200
3+++ b/wokkel/im.py      Wed May 25 09:40:28 2011 +0200
4@@ -14,7 +14,7 @@
[34]5 
[49]6 from twisted.internet import defer
7 from twisted.words.protocols.jabber.jid import JID, internJID
8-from twisted.words.protocols.jabber import error
[34]9+from twisted.words.protocols.jabber import error, xmlstream
10 from twisted.words.xish import domish
11 
[49]12 from wokkel.compat import IQ
13@@ -25,6 +25,7 @@
[34]14 NS_ROSTER = 'jabber:iq:roster'
15 
[49]16 XPATH_ROSTER_SET = "/iq[@type='set']/query[@xmlns='%s']" % NS_ROSTER
17+XPATH_ROSTER_GET = "/iq[@type='get']/query[@xmlns='%s']" % NS_ROSTER
[36]18 
[34]19 
20 
[49]21@@ -579,3 +580,43 @@
22         @param entity: The entity for which the roster item has been removed.
[34]23         @type entity: L{JID}
24         """
[49]25+
[34]26+
27+
28+class RosterServerProtocol(XMPPHandler):
29+    """
30+    XMPP subprotocol handler for the roster, server side.
31+    """
32+
33+    def connectionInitialized(self):
[37]34+        self.xmlstream.addObserver(XPATH_ROSTER_GET, self._onRosterGet)
35+        self.xmlstream.addObserver(XPATH_ROSTER_SET, self._onRosterSet)
[34]36+
37+
[36]38+    def _toRosterReply(self, roster, iq):
[34]39+        response = xmlstream.toResponse(iq, 'result')
40+        response.addElement((NS_ROSTER, 'query'))
41+
[36]42+        for item in roster:
43+            response.query.addChild(item.toElement())
[34]44+
45+        return response
46+
47+
48+    def _onRosterGet(self, iq):
49+        iq.handled = True
50+
[49]51+        d = self.getRoster(internJID(iq["from"]))
[34]52+        d.addCallback(self._toRosterReply, iq)
53+        d.addErrback(lambda _: error.ErrorStanza('internal-error').toResponse(iq))
54+        d.addBoth(self.send)
55+
56+
57+    def _onRosterSet(self, iq):
58+        iq.handled = True
59+        response = error.StanzaError('bad-request').toResponse(iq)
60+        self.send(response)
61+
62+
63+    def getRoster(self, entity):
64+        raise NotImplemented
Note: See TracBrowser for help on using the repository browser.