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

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

File size: 1.8 KB
  • wokkel/im.py

    diff -r 3c5fb05162e1 wokkel/im.py
    a b  
    1414
    1515from twisted.internet import defer
    1616from twisted.words.protocols.jabber.jid import JID, internJID
    17 from twisted.words.protocols.jabber import error
     17from twisted.words.protocols.jabber import error, xmlstream
    1818from twisted.words.xish import domish
    1919
    2020from wokkel.compat import IQ
     
    2525NS_ROSTER = 'jabber:iq:roster'
    2626
    2727XPATH_ROSTER_SET = "/iq[@type='set']/query[@xmlns='%s']" % NS_ROSTER
     28XPATH_ROSTER_GET = "/iq[@type='get']/query[@xmlns='%s']" % NS_ROSTER
    2829
    2930
    3031
     
    579580        @param entity: The entity for which the roster item has been removed.
    580581        @type entity: L{JID}
    581582        """
     583
     584
     585
     586class RosterServerProtocol(XMPPHandler):
     587    """
     588    XMPP subprotocol handler for the roster, server side.
     589    """
     590
     591    def connectionInitialized(self):
     592        self.xmlstream.addObserver(XPATH_ROSTER_GET, self._onRosterGet)
     593        self.xmlstream.addObserver(XPATH_ROSTER_SET, self._onRosterSet)
     594
     595
     596    def _toRosterReply(self, roster, iq):
     597        response = xmlstream.toResponse(iq, 'result')
     598        response.addElement((NS_ROSTER, 'query'))
     599
     600        for item in roster:
     601            response.query.addChild(item.toElement())
     602
     603        return response
     604
     605
     606    def _onRosterGet(self, iq):
     607        iq.handled = True
     608
     609        d = self.getRoster(internJID(iq["from"]))
     610        d.addCallback(self._toRosterReply, iq)
     611        d.addErrback(lambda _: error.ErrorStanza('internal-error').toResponse(iq))
     612        d.addBoth(self.send)
     613
     614
     615    def _onRosterSet(self, iq):
     616        iq.handled = True
     617        response = error.StanzaError('bad-request').toResponse(iq)
     618        self.send(response)
     619
     620
     621    def getRoster(self, entity):
     622        raise NotImplemented
Note: See TracBrowser for help on using the repository browser.