source: ralphm-patches/roster_server.patch @ 50:b69ca8f7174e

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

Cleanup JIDs a bit more and adjust affected patches.

File size: 1.8 KB
RevLine 
[50]1diff -r 05330d69e16c wokkel/im.py
2--- a/wokkel/im.py      Wed May 25 20:20:50 2011 +0200
3+++ b/wokkel/im.py      Wed May 25 20:22:14 2011 +0200
4@@ -12,7 +12,7 @@
[34]5 
[49]6 from twisted.internet import defer
[50]7 from twisted.words.protocols.jabber import jid
[49]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
[50]13@@ -23,6 +23,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 
[50]21@@ -550,3 +551,43 @@
[49]22         @param entity: The entity for which the roster item has been removed.
[50]23         @type entity: L{jid.JID}
[34]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.