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@…>, 9 years ago

Cleanup JIDs a bit more and adjust affected patches.

File size: 1.8 KB
  • wokkel/im.py

    diff -r 05330d69e16c wokkel/im.py
    a b  
    1212
    1313from twisted.internet import defer
    1414from twisted.words.protocols.jabber import jid
    15 from twisted.words.protocols.jabber import error
     15from twisted.words.protocols.jabber import error, xmlstream
    1616from twisted.words.xish import domish
    1717
    1818from wokkel.compat import IQ
     
    2323NS_ROSTER = 'jabber:iq:roster'
    2424
    2525XPATH_ROSTER_SET = "/iq[@type='set']/query[@xmlns='%s']" % NS_ROSTER
     26XPATH_ROSTER_GET = "/iq[@type='get']/query[@xmlns='%s']" % NS_ROSTER
    2627
    2728
    2829
     
    550551        @param entity: The entity for which the roster item has been removed.
    551552        @type entity: L{jid.JID}
    552553        """
     554
     555
     556
     557class RosterServerProtocol(XMPPHandler):
     558    """
     559    XMPP subprotocol handler for the roster, server side.
     560    """
     561
     562    def connectionInitialized(self):
     563        self.xmlstream.addObserver(XPATH_ROSTER_GET, self._onRosterGet)
     564        self.xmlstream.addObserver(XPATH_ROSTER_SET, self._onRosterSet)
     565
     566
     567    def _toRosterReply(self, roster, iq):
     568        response = xmlstream.toResponse(iq, 'result')
     569        response.addElement((NS_ROSTER, 'query'))
     570
     571        for item in roster:
     572            response.query.addChild(item.toElement())
     573
     574        return response
     575
     576
     577    def _onRosterGet(self, iq):
     578        iq.handled = True
     579
     580        d = self.getRoster(internJID(iq["from"]))
     581        d.addCallback(self._toRosterReply, iq)
     582        d.addErrback(lambda _: error.ErrorStanza('internal-error').toResponse(iq))
     583        d.addBoth(self.send)
     584
     585
     586    def _onRosterSet(self, iq):
     587        iq.handled = True
     588        response = error.StanzaError('bad-request').toResponse(iq)
     589        self.send(response)
     590
     591
     592    def getRoster(self, entity):
     593        raise NotImplemented
Note: See TracBrowser for help on using the repository browser.