Changeset 79:0752a1cca356 in ralphm-patches for c2s_server_factory.patch


Ignore:
Timestamp:
Jun 22, 2016, 4:43:00 PM (4 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Split out stanza module and response tracking patches, fix other patches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c2s_server_factory.patch

    r72 r79  
    11# HG changeset patch
    22# Parent 49294b2cf829414b42141731b5130d91474c0443
     3# Parent  97fdb86984fc983e78234f8c3d746da061b21f1b
    34Add factory for accepting client connections.
    45
     
    106107--- a/wokkel/generic.py
    107108+++ b/wokkel/generic.py
    108 @@ -628,3 +628,65 @@
     109@@ -480,3 +480,64 @@
    109110     standard full stop.
    110111     """
     
    135136+        Called when the stream has been initialized.
    136137+        """
    137 +        self.xmlstream.addObserver('/*[@xmlns="%s"]' %
    138 +                                       self.xmlstream.namespace,
    139 +                                   stripNamespace, priority=1)
    140138+        self.xmlstream.addObserver('/*', self.onStanza, priority=-1)
    141139+
     
    157155+
    158156+        if (element.name not in ('iq', 'message', 'presence') or
    159 +            element.uri is not None):
     157+            element.uri != self.xmlstream.namespace):
    160158+            return
    161159+
    162 +        if not element.getAttribute('to'):
     160+        stanza = Stanza.fromElement(element)
     161+
     162+        if not stanza.recipient:
    163163+            exc = error.StanzaError('service-unavailable')
    164 +            self.send(exc.toResponse(element))
     164+            self.send(exc.toResponse(stanza.element))
    165165+        else:
    166 +            self.xmlstream.avatar.send(element)
     166+            self.xmlstream.avatar.send(stanza.element)
    167167+
    168168+
     
    316316--- a/wokkel/test/test_generic.py
    317317+++ b/wokkel/test/test_generic.py
    318 @@ -681,3 +681,105 @@
     318@@ -728,3 +728,91 @@
    319319         name = u"example.com."
    320320         result = generic.prepareIDNName(name)
     
    351351+        self.protocol.connectionInitialized()
    352352+
    353 +        element = domish.Element((None, u'message'))
     353+        element = domish.Element((u'jabber:client', u'message'))
    354354+        element[u'to'] = u'other@example.org'
    355355+        self.stub.send(element)
     
    365365+        self.protocol.connectionInitialized()
    366366+
    367 +        element = domish.Element((None, u'message'))
     367+        element = domish.Element((u'jabber:client', u'message'))
    368368+        self.stub.send(element)
    369369+
    370370+        self.assertEqual(0, len(self.avatar.sent))
    371371+        self.assertEqual(1, len(self.stub.output))
    372 +
    373 +
    374 +    def test_onStanzaClientNamespace(self):
    375 +        """
    376 +        Stanzas with an explicit namespace are delivered.
    377 +        """
    378 +        self.protocol.connectionInitialized()
    379 +
    380 +        element = domish.Element(('jabber:client', u'message'))
    381 +        element[u'to'] = u'other@example.org'
    382 +        self.stub.send(element)
    383 +
    384 +        self.assertEqual(1, len(self.avatar.sent))
    385 +        self.assertEqual(0, len(self.stub.output))
    386372+
    387373+
Note: See TracChangeset for help on using the changeset viewer.