Changeset 68:14b59e18ecb6 in ralphm-patches
- Timestamp:
- Oct 21, 2012, 6:04:01 AM (10 years ago)
- Branch:
- default
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
c2s_server_factory.patch
r66 r68 1 1 # HG changeset patch 2 # Parent 23dbe722e4482b8286153d29bf87902b464f919f2 # Parent f164cc75b8337933cc6dd9c7f43424f3dbd74dee 3 3 Add factory for accepting client connections. 4 4 … … 24 24 --- a/wokkel/client.py 25 25 +++ b/wokkel/client.py 26 @@ -21, 6 +21,7@@26 @@ -21,7 +21,9 @@ 27 27 from twisted.words.xish import domish 28 28 … … 30 30 +from wokkel.compat import XmlStreamServerFactory 31 31 from wokkel.iwokkel import IUserSession 32 +from wokkel.subprotocols import ServerStreamManager 32 33 from wokkel.subprotocols import StreamManager 33 34 34 @@ -401,3 +402,61 @@ 35 NS_CLIENT = 'jabber:client' 36 @@ -442,3 +444,41 @@ 35 37 self.portal = self.portals[self.xmlstream.thisEntity] 36 38 except KeyError: … … 41 43 +class XMPPC2SServerFactory(XmlStreamServerFactory): 42 44 + 43 + def __init__(self, portal): 44 + self.portal = portal 45 + 45 + def __init__(self, portals): 46 46 + def authenticatorFactory(): 47 + return XMPPClientListenAuthenticator(portal )47 + return XMPPClientListenAuthenticator(portals) 48 48 + 49 49 + XmlStreamServerFactory.__init__(self, authenticatorFactory) 50 50 + self.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, 51 51 + self.onConnectionMade) 52 + self.addBootstrap(xmlstream.STREAM_AUTHD_EVENT,53 + self.onAuthenticated)54 +55 + self.serial = 056 52 + 57 53 + 58 54 + def onConnectionMade(self, xs): 59 55 + """ 60 + Called when a client-to-server connection was made. 61 + 62 + This enables traffic debugging on incoming streams. 63 + """ 64 + xs.serial = self.serial 65 + self.serial += 1 66 + 67 + log.msg("Client connection %d made" % xs.serial) 68 + 69 + def logDataIn(buf): 70 + log.msg("RECV (%d): %r" % (xs.serial, buf)) 71 + 72 + def logDataOut(buf): 73 + log.msg("SEND (%d): %r" % (xs.serial, buf)) 74 + 56 + Called when a connection is made. 57 + 58 + This creates a stream manager, calls L{setupHandlers} to attach 59 + subprotocol handlers and then signals the stream manager that 60 + the connection was made. 61 + """ 62 + sm = ServerStreamManager() 63 + sm.logTraffic = self.logTraffic 64 + 65 + for handler in self.setupHandlers(): 66 + handler.setHandlerParent(sm) 67 + 68 + sm.makeConnection(xs) 69 + 70 + 71 + def setupHandlers(self): 72 + """ 73 + Set up XMPP subprotocol handlers. 74 + """ 75 + return [ 76 + generic.StanzaForwarder() 77 + ] 78 diff --git a/wokkel/generic.py b/wokkel/generic.py 79 --- a/wokkel/generic.py 80 +++ b/wokkel/generic.py 81 @@ -615,3 +615,55 @@ 82 83 self._initializers = self.getInitializers() 84 self._initializeStream() 85 + 86 + 87 + 88 +class StanzaForwarder(XMPPHandler): 89 + """ 90 + XMPP protocol for passing incoming stanzas to the stream avatar. 91 + 92 + This handler adds an observer for all XML Stanzas to forward to the C{send} 93 + method on the cred avatar set on the XML Stream, unless it has been handled 94 + by other observers. 95 + 96 + Stream errors are logged. 97 + """ 98 + 99 + def connectionMade(self): 100 + """ 101 + Called when a connection is made. 102 + """ 103 + self.xmlstream.addObserver(xmlstream.STREAM_ERROR_EVENT, self.onError) 104 + 105 + 106 + def connectionInitialized(self): 107 + """ 108 + Called when the stream has been initialized. 109 + """ 110 + self.xmlstream.addObserver( 111 + '/*[@xmlns="%s"]' % self.xmlstream.namespace, 112 + self.onStanza, priority=-1) 113 + 114 + 115 + def onStanza(self, element): 116 + """ 117 + Called when a stanza element was received. 118 + 119 + Unless a stanza has already been handled, or the name of the element is 120 + not one of C{'iq'}, C{'message'}, C{'presence'}, the stanza is passed 121 + on to the avatar's C{send} method. 122 + """ 123 + if element.handled: 124 + return 125 + 126 + if element.name not in ('iq', 'message', 'presence'): 127 + return 128 + 129 + self.xmlstream.avatar.send(element) 130 + 131 + 132 + def onError(reason): 133 + """ 134 + Log a stream error. 135 + """ 136 + log.err(reason, "Stream error") 137 diff --git a/wokkel/subprotocols.py b/wokkel/subprotocols.py 138 --- a/wokkel/subprotocols.py 139 +++ b/wokkel/subprotocols.py 140 @@ -142,10 +142,13 @@ 141 @type timeout: C{int} 142 143 @ivar _reactor: A provider of L{IReactorTime} to track timeouts. 144 + 145 + @cvar __streamCount: Global stream count for distinguishing streams. 146 """ 147 148 timeout = None 149 _reactor = None 150 + __streamCount = 0 151 152 logTraffic = False 153 154 @@ -195,20 +198,24 @@ 155 and call each handler's C{makeConnection} method with the L{XmlStream} 156 instance. 157 """ 158 - def logDataIn(buf): 159 - log.msg("RECV: %r" % buf) 160 + xs.serial = self.__streamCount 161 + BaseStreamManager.__streamCount += 1 162 163 - def logDataOut(buf): 164 - log.msg("SEND: %r" % buf) 165 166 if self.logTraffic: 167 - xs.rawDataInFn = logDataIn 168 - xs.rawDataOutFn = logDataOut 169 + def logData(direction, data): 170 + log.msg(format="%(direction)s (%(streamID)s): %(data)r", 171 + direction=direction, streamID=xs.serial, data=data) 172 + 173 + log.msg(format="Connection %(streamID) made", streamID=xs.serial) 174 + xs.rawDataInFn = lambda data: logData("RECV", data) 175 + xs.rawDataOutFn = lambda data: logData("SEND", data) 176 177 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, 178 self.connectionInitialized) 179 xs.addObserver(xmlstream.STREAM_END_EVENT, 180 self.connectionLost) 181 + 182 self.xmlstream = xs 183 184 for e in list(self): 185 @@ -222,6 +229,9 @@ 186 Send out cached stanzas and call each handler's 187 C{connectionInitialized} method. 188 """ 75 189 + if self.logTraffic: 76 + xs.rawDataInFn = logDataIn 77 + xs.rawDataOutFn = logDataOut 78 + 79 + xs.addObserver(xmlstream.STREAM_END_EVENT, self.onConnectionLost, 80 + 0, xs) 81 + xs.addObserver(xmlstream.STREAM_ERROR_EVENT, self.onError) 82 + 83 + 84 + def onAuthenticated(self, xs): 85 + log.msg("Client connection %d authenticated" % xs.serial) 86 + 87 + xs.addObserver('/*', xs.avatar.send) 88 + 89 + 90 + def onConnectionLost(self, xs, reason): 91 + log.msg("Client connection %d disconnected" % xs.serial) 92 + 93 + 94 + def onError(self, reason): 95 + log.err(reason, "Stream Error") 190 + log.msg(format="Connection %(streamID) initialized", 191 + streamID=xs.serial) 192 193 xs.addObserver('/iq[@type="result"]', self._onIQResponse) 194 xs.addObserver('/iq[@type="error"]', self._onIQResponse) 195 @@ -247,6 +257,10 @@ 196 L{XmlStream} anymore and notifies each handler that the connection 197 was lost by calling its C{connectionLost} method. 198 """ 199 + if self.logTraffic: 200 + log.msg(format="Connection %(streamID) lost", 201 + streamID=self.xmlstream.serial) 202 + 203 self.xmlstream = None 204 self._initialized = False 205 -
roster_server.patch
r62 r68 144 144 + 145 145 + 146 + def getRoster(self, entity):146 + def getRoster(self, request): 147 147 + raise NotImplementedError() -
series
r67 r68 1 server-stream-manager.patch 1 2 roster_server.patch #+c2s 2 router_unknown.patch #+c2s3 3 4 4 listening-authenticator-stream-features.patch #+c2s -
session_manager.patch
r66 r68 1 1 # HG changeset patch 2 # Parent 4962500d52ed0bd4a71047c93818303accea55fd2 # Parent 53e7ea0d847e61f209fe37359380c8c58e0ece72 3 3 4 4 diff --git a/wokkel/client.py b/wokkel/client.py 5 5 --- a/wokkel/client.py 6 6 +++ b/wokkel/client.py 7 @@ -12,1 8 +12,21@@7 @@ -12,19 +12,23 @@ 8 8 9 9 import base64 … … 26 26 from wokkel.compat import XmlStreamServerFactory 27 27 from wokkel.iwokkel import IUserSession 28 -from wokkel.subprotocols import StreamManager 29 +from wokkel.subprotocols import StreamManager, XMPPHandler 28 from wokkel.subprotocols import ServerStreamManager 29 from wokkel.subprotocols import StreamManager 30 +from wokkel.subprotocols import XMPPHandler 30 31 31 32 NS_CLIENT = 'jabber:client' 32 33 33 @@ - 501,3 +504,161 @@34 35 def onError(self, reason):36 log.err(reason, "Stream Error")34 @@ -479,3 +483,161 @@ 35 return [ 36 generic.StanzaForwarder() 37 ] 37 38 + 38 39 +
Note: See TracChangeset
for help on using the changeset viewer.