Changeset 654
- Timestamp:
- 05/09/08 15:09:39 (7 months ago)
- Files:
-
- oss/headstock/headstock/api/contact.py (modified) (1 diff)
- oss/headstock/headstock/api/discovery.py (modified) (6 diffs)
- oss/headstock/headstock/api/im.py (modified) (4 diffs)
- oss/headstock/headstock/api/pubsub.py (modified) (3 diffs)
- oss/headstock/headstock/example/simplechat (added)
- oss/headstock/headstock/example/simplechat/simplechat.py (added)
- oss/headstock/headstock/protocol/core/stream.py (modified) (10 diffs)
- oss/headstock/headstock/protocol/extension/discovery.py (modified) (5 diffs)
- oss/headstock/headstock/protocol/extension/pubsub.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
oss/headstock/headstock/api/contact.py
r652 r654 94 94 @staticmethod 95 95 def from_element(e): 96 print e.xml()97 96 r = Roster(JID.parse(e.xml_parent.get_attribute_value('from')), 98 97 JID.parse(e.xml_parent.get_attribute_value('to'))) oss/headstock/headstock/api/discovery.py
r652 r654 13 13 from bridge.common import XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS, \ 14 14 XMPP_OOB_NS, XMPP_SI_NS, XMPP_SI_FILE_TRANSFER_NS, XMPP_BYTESTREAMS_NS,\ 15 XMPP_DATA_FORM_NS, XMPP_CLIENT_NS, XMPP_STREAM_NS 15 XMPP_DATA_FORM_NS, XMPP_CLIENT_NS, XMPP_STREAM_NS, XMPP_PUBSUB_NS 16 16 17 __all__ = ['FeaturesDiscovery', 'ItemsDiscovery'] 17 __all__ = ['FeaturesDiscovery', 'ItemsDiscovery', 18 'SubscriptionsDiscovery'] 18 19 19 20 class Identity(object): … … 43 44 return '<Item %s at %s>' % (str(self.jid), hex(id(self))) 44 45 46 class Subscription(object): 47 def __init__(self, node, jid, state): 48 self.node = node 49 self.jid = jid 50 self.state = state 51 52 def __repr__(self): 53 return '<Subscription %s [%s:%s] at %s>' % (str(self.jid), self.node, 54 self.state, hex(id(self))) 55 45 56 class FeaturesDiscovery(Entity): 46 57 def __init__(self, from_jid, to_jid, node_name=None, type=u'get', stanza_id=None): … … 51 62 self.features = [] 52 63 self.items = [] 64 65 def has_feature(self, feature): 66 for f in self.features: 67 if f.var == feature: 68 return True 69 70 return False 53 71 54 72 @staticmethod … … 78 96 if i.xml_ns in [XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS]: 79 97 if i.xml_name == 'identity': 80 ident = Identity(i.get_attribute ('name'),81 i.get_attribute ('category'),82 i.get_attribute ('type'))98 ident = Identity(i.get_attribute_value('name'), 99 i.get_attribute_value('category'), 100 i.get_attribute_value('type')) 83 101 disco.identities.append(ident) 84 102 elif i.xml_name == 'feature': 85 feat = Feature(i.get_attribute ('var'))103 feat = Feature(i.get_attribute_value('var')) 86 104 disco.features.append(feat) 87 105 elif i.xml_name == 'item': 88 jid = JID.parse(unicode(i.get_attribute ('jid')))89 item = Item(jid, i.get_attribute ('action'),90 i.get_attribute ('name'),91 i.get_attribute ('node'))106 jid = JID.parse(unicode(i.get_attribute_value('jid'))) 107 item = Item(jid, i.get_attribute_value('action'), 108 i.get_attribute_value('name'), 109 i.get_attribute_value('node')) 92 110 disco.items.append(item) 93 111 elif i.xml_ns == XMPP_DATA_FORM_NS: … … 127 145 for i in c.xml_children: 128 146 if i.xml_name == 'item' and i.xml_ns in [XMPP_DISCO_ITEMS_NS]: 129 jid = JID.parse(unicode(i.get_attribute ('jid')))130 item = Item(jid, i.get_attribute ('action'),131 i.get_attribute ('name'),132 i.get_attribute ('node'))147 jid = JID.parse(unicode(i.get_attribute_value('jid'))) 148 item = Item(jid, i.get_attribute_value('action'), 149 i.get_attribute_value('name'), 150 i.get_attribute_value('node')) 133 151 disco.items.append(item) 134 152 elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': … … 136 154 137 155 return disco 156 157 class SubscriptionsDiscovery(Entity): 158 def __init__(self, from_jid, to_jid, type=u'get', stanza_id=None): 159 Entity.__init__(self, from_jid, to_jid, type, stanza_id) 160 self.subscriptions = [] 161 162 @staticmethod 163 def to_element(e): 164 iq = Entity.to_element(e) 165 query = E(u'query', namespace=XMPP_PUBSUB_NS, parent=iq) 166 E('subscriptions', namespace=XMPP_PUBSUB_NS, parent=query) 167 168 return iq 169 170 @staticmethod 171 def from_element(e): 172 disco = SubscriptionsDiscovery(JID.parse(e.get_attribute_value('from')), 173 JID.parse(e.get_attribute_value('to')), 174 type=e.get_attribute_value('type'), 175 stanza_id=e.get_attribute_value('id')) 176 177 for c in e.xml_children: 178 if not isinstance(c, E): 179 continue 180 181 if c.xml_ns == XMPP_PUBSUB_NS: 182 if c.xml_name == 'subscriptions': 183 for i in c.xml_children: 184 if i.xml_name == 'subscription' and i.xml_ns == XMPP_DISCO_ITEMS_NS: 185 jid = JID.parse(unicode(i.get_attribute_value('jid'))) 186 item = Subscription(i.get_attribute_value('node'), 187 jid, i.get_attribute_value('subscription')) 188 disco.subscriptions.append(item) 189 elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': 190 disco.error = Error.from_element(c) 191 192 return disco oss/headstock/headstock/api/im.py
r641 r654 24 24 return '<Body at %s>' % (hex(id(self)),) 25 25 26 def __str__(self): 27 return str(self.plain_body) 28 26 29 class Subject(object): 27 30 def __init__(self, content, lang=None): … … 40 43 41 44 class Event(object): 42 def __init__(self, offline=False, composing=False, 43 delivered=False, displayed=False): 44 self.offline = offline 45 self.composing = composing 46 self.delivered = delivered 47 self.displayed = displayed 48 49 def __repr__(self): 50 return '<Event at %s>' % (hex(id(self)),) 45 offline = u"offline" 46 composing = u"composing" 47 delivered = u"delivered" 48 displayed = u"displayed" 51 49 52 50 class Message(Entity): … … 80 78 81 79 if child.xml_ns == XMPP_EVENT_NS: 82 message.event = Event(child.has_child('offline', XMPP_EVENT_NS), 83 child.has_child('composing', XMPP_EVENT_NS), 84 child.has_child('delivered', XMPP_EVENT_NS), 85 child.has_child('displayed', XMPP_EVENT_NS)) 80 if child.has_child('offline', XMPP_EVENT_NS): 81 message.event = Event.offline 82 if child.has_child('composing', XMPP_EVENT_NS): 83 message.event = Event.composing 84 if child.has_child('delivered', XMPP_EVENT_NS): 85 message.event = Event.delivered 86 if child.has_child('displayed', XMPP_EVENT_NS): 87 message.event = Event.displayed 88 86 89 elif child.xml_ns == XMPP_CLIENT_NS: 87 90 if child.xml_name == 'body': … … 139 142 namespace=XMPP_CLIENT_NS, parent=e) 140 143 144 x = E(u'x', namespace=XMPP_EVENT_NS, parent=e) 141 145 if m.event: 142 x = E(u'x', namespace=XMPP_EVENT_NS, parent=e) 143 if m.event.offline: 144 E(u'offline', namespace=XMPP_EVENT_NS, parent=x) 145 elif m.event.composing: 146 E(u'composing', namespace=XMPP_EVENT_NS, parent=x) 147 elif m.event.delivered: 148 E(u'delivered', namespace=XMPP_EVENT_NS, parent=x) 149 elif m.event.displayed: 150 E(u'displayed', namespace=XMPP_EVENT_NS, parent=x) 146 E(m.event, namespace=XMPP_EVENT_NS, parent=x) 151 147 152 148 for f in m.foreign: oss/headstock/headstock/api/pubsub.py
r652 r654 11 11 from bridge import Attribute as A 12 12 from bridge.common import XMPP_CLIENT_NS, XMPP_STREAM_NS, \ 13 XMPP_PUBSUB_NS, XMPP_PUBSUB_OWNER_NS, XMPP_PUBSUB_NODE_CONFIG_NS 13 XMPP_PUBSUB_NS, XMPP_PUBSUB_OWNER_NS, XMPP_PUBSUB_NODE_CONFIG_NS,\ 14 XMPP_PUBSUB_EVENT_NS 14 15 15 16 class Configure(object): … … 30 31 31 32 class Item(object): 32 def __init__(self, id=None, payload=None ):33 def __init__(self, id=None, payload=None, eventType=None): 33 34 self.id = id 34 35 self.payload = payload 36 self.event = eventType 35 37 36 38 def __repr__(self): … … 228 230 229 231 230 class Items(object): 231 def __init__(self, max_items=None, node=None, subid=None): 232 self.max_items = max_items 233 self.node = node 234 self.subid = subid 232 class Message(Entity): 233 def __init__(self, from_jid, to_jid): 234 Entity.__init__(self, from_jid, to_jid) 235 self.node_name = None 235 236 self.items = [] 236 237 def __repr__(self): 238 return '<Items "%s" on (%s) at %s>' % (self.subid or '', self.node, hex(id(self)),) 239 237 238 @staticmethod 239 def from_element(e): 240 msg = Message(JID.parse(e.get_attribute_value('from')), 241 JID.parse(e.get_attribute_value('to'))) 242 243 for c in e.xml_children: 244 if c.xml_ns == XMPP_PUBSUB_EVENT_NS: # x or event 245 for i in c.xml_children: 246 if i.xml_ns == XMPP_PUBSUB_EVENT_NS: # items 247 msg.node_name = i.get_attribute_value('node') 248 for t in i.xml_children: # item 249 payload = None 250 if t.xml_children: 251 payload = t.xml_children[0] 252 msg.items.append(Item(id=t.get_attribute_value('id'), 253 payload=payload, eventType=t.xml_name)) 254 255 return msg oss/headstock/headstock/protocol/core/stream.py
r652 r654 115 115 Inboxes = {"inbox" : "bridge.Element instance", 116 116 "control" : "Shutdown the client stream", 117 "forward": "bridge.Element instance to be sent out to the client",} 117 "forward": "bridge.Element instance to be sent out to the client", 118 "proceedtls": "", 119 "tlssuccess": "", 120 "tlsfailure": ""} 118 121 119 122 Outboxes = {"outbox" : "Any string data to be passed to the client", … … 122 125 "log" : "String to be logged", 123 126 "error" : "bridge.Element instance", 127 "starttls": "", 128 "jid" : "", 124 129 "bound" : "indicates the client has been successfully bound to an XMPP server", 125 130 "terminated": "Indicates the stream has been terminated by the peer", … … 129 134 "%s.message" % XMPP_CLIENT_NS: "Handles 'message' element in the %s namespace" %XMPP_CLIENT_NS} 130 135 131 def __init__(self, jid=None, password_lookup=None ):136 def __init__(self, jid=None, password_lookup=None, use_tls=False): 132 137 """ 133 138 A client stream is the interface between a remote XMPP service … … 143 148 self.jid = jid 144 149 self.password_lookup = password_lookup 150 self.use_tls = use_tls 145 151 146 152 self.status = DISCONNECTED … … 177 183 178 184 def _send_stream_header(self, omit_decl=False): 179 attributes = {u'to': self.jid.domain, u'version': u'1.0', 180 u'id': generate_unique()} 185 attributes = {u'to': self.jid.domain, u'version': u'1.0'} 181 186 stream = E(u'stream', attributes=attributes, 182 187 prefix=XMPP_STREAM_PREFIX, namespace=XMPP_STREAM_NS) … … 191 196 self.status = CONNECTED 192 197 mechanisms = e.get_child('mechanisms', ns=XMPP_SASL_NS) 193 if mechanisms: 198 support_tls = e.get_child('starttls', ns=XMPP_TLS_NS) 199 if support_tls and self.use_tls: 200 tls = E(u'starttls', namespace=XMPP_TLS_NS) 201 self.propagate(element=tls) 202 elif mechanisms: 194 203 self._handle_mechanisms(mechanisms) 195 204 205 def _handle_tls(self): 206 self._reset_stream_header(omit_decl=True) 207 208 def _proceed_tls(self, e): 209 self.log(e) 210 self.send('', 'starttls') 211 196 212 def _handle_challenge(self, e): 197 213 self.log(e) … … 270 286 def _handle_jid(self, e): 271 287 self.log(e) 272 #self.jid = JID.parse(e.xml_text)288 self.jid = JID.parse(e.xml_text) 273 289 274 290 self.status = ACTIVE 291 292 self.send(self.jid, 'jid') 275 293 276 294 # Sends the initial presence information to the server 277 295 self.propagate(element=Stanza(u'presence').to_element()) 278 296 279 297 # Asks immediatly for the client's roster list 280 298 iq = Iq.create_get_iq(from_jid=unicode(self.jid), stanza_id=generate_unique()) … … 296 314 self.send(producerFinished(), "signal") 297 315 break 316 317 if self.dataReady('tlssuccess'): 318 self.recv('tlssuccess') 319 yield 1 320 self._handle_tls() 321 yield 1 298 322 299 323 if self.dataReady("forward"): … … 316 340 if (e.xml_ns == XMPP_STREAM_NS) and (e.xml_name == 'features'): 317 341 self._handle_features(e) 342 elif (e.xml_ns == XMPP_TLS_NS) and (e.xml_name == 'proceed'): 343 self._proceed_tls(e) 344 yield 1 318 345 elif (e.xml_ns == XMPP_SASL_NS) and (e.xml_name == 'challenge'): 319 346 self._handle_challenge(e) … … 346 373 # unhandled element. 347 374 self.send(e, "unhandled") 375 e = None 348 376 349 377 if not self.anyReady(): oss/headstock/headstock/protocol/extension/discovery.py
r652 r654 2 2 # -*- coding: utf-8 -*- 3 3 4 from headstock.api.discovery import FeaturesDiscovery, ItemsDiscovery 4 from headstock.api.discovery import FeaturesDiscovery, ItemsDiscovery,\ 5 SubscriptionsDiscovery 5 6 from bridge import Element as E 6 7 from bridge import Attribute as A … … 11 12 12 13 13 __all__ = ['FeaturesDiscoveryDispatcher', 'ItemsDiscoveryDispatcher'] 14 __all__ = ['FeaturesDiscoveryDispatcher', 'ItemsDiscoveryDispatcher', 15 'SubscriptionsDiscoveryDispatcher', 'DiscoveryDispatcher'] 14 16 15 17 class FeaturesDiscoveryDispatcher(component): … … 25 27 "unknown" : "Unknown element that could not be dispatched properly", 26 28 "xmpp.get" : "Activity requests", 29 "xmpp.set" : "Activity requests", 27 30 "xmpp.result" : "Activity responses", 28 31 "xmpp.error" : "Activity response error", … … 78 81 "unknown" : "Unknown element that could not be dispatched properly", 79 82 "xmpp.get" : "Activity requests", 83 "xmpp.set" : "Activity requests", 80 84 "xmpp.result" : "Activity responses", 81 85 "xmpp.error" : "Activity response error", … … 118 122 119 123 yield 1 124 125 class SubscriptionsDiscoveryDispatcher(component): 126 127 Inboxes = {"inbox" : "bridge.Element instance", 128 "control" : "Shutdown the client stream", 129 "forward" : "headstock.api.contact.Message instance to be sent back to the client. Transforms the instance to a bridge.Element instance and puts it into the 'outbox'", 130 } 131 132 Outboxes = {"outbox" : "bridge.Element instance", 133 "signal" : "Shutdown signal", 134 "log" : "log", 135 "unknown" : "Unknown element that could not be dispatched properly", 136 "xmpp.get" : "Activity requests", 137 "xmpp.set" : "Activity requests", 138 "xmpp.result" : "Activity responses", 139 "xmpp.error" : "Activity response error", 140 } 141 142 def __init__(self): 143 super(SubscriptionsDiscoveryDispatcher, self).__init__() 144 145 def main(self): 146 while 1: 147 if self.dataReady("control"): 148 mes = self.recv("control") 149 150 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 151 self.send(producerFinished(), "signal") 152 break 153 154 if self.dataReady("forward"): 155 m = self.recv("forward") 156 self.send(SubscriptionsDiscovery.to_element(m), "outbox") 157 158 if self.dataReady("inbox"): 159 handled = False 160 e = self.recv("inbox") 161 e = e.xml_parent.xml_parent 162 print e.xml() 163 self.send(('INCOMING', e), "log") 164 165 msg_type = e.get_attribute_value(u'type') or u'get' 166 key = 'xmpp.%s' % unicode(msg_type) 167 168 if key in self.outboxes: 169 self.send(SubscriptionsDiscovery.from_element(e), key) 170 handled = True 171 172 if not handled: 173 self.send(e, "unknown") 174 175 if not self.anyReady(): 176 self.pause() 177 178 yield 1 179 180 class DiscoveryDispatcher(component): 181 Inboxes = {"inbox" : "bridge.Element instance", 182 "control" : "Shutdown the client stream", 183 "features.inbox": "", 184 "subscription.inbox": "", 185 "items.inbox": "", 186 "features.forward": "", 187 "subscription.forward": "", 188 "items.forward": "", 189 "in.features.get" : "Activity requests", 190 "in.features.set" : "Activity requests", 191 "in.features.result" : "Activity responses", 192 "in.features.error" : "Activity response error", 193 "in.items.get" : "Activity requests", 194 "in.items.set" : "Activity requests", 195 "in.items.result" : "Activity responses", 196 "in.items.error" : "Activity response error", 197 "in.subscription.get" : "Activity requests", 198 "in.subscription.set" : "Activity requests", 199 "in.subscription.result" : "Activity responses", 200 "in.subscription.error" : "Activity response error",} 201 202 Outboxes = {"outbox" : "bridge.Element instance", 203 "signal" : "Shutdown signal", 204 "log" : "log", 205 "unknown" : "Unknown element that could not be dispatched properly", 206 "features.outbox": "", 207 "subscription.outbox": "", 208 "items.outbox": "", 209 "out.features.get" : "Activity requests", 210 "out.features.set" : "Activity requests", 211 "out.features.result" : "Activity responses", 212 "out.features.error" : "Activity response error", 213 "out.items.get" : "Activity requests", 214 "out.items.set" : "Activity requests", 215 "out.items.result" : "Activity responses", 216 "out.items.error" : "Activity response error", 217 "out.subscription.get" : "Activity requests", 218 "out.subscription.set" : "Activity requests", 219 "out.subscription.result" : "Activity responses", 220 "out.subscription.error" : "Activity response error", 221 } 222 223 def __init__(self): 224 super(DiscoveryDispatcher, self).__init__() 225 226 def initComponents(self): 227 subdisp = SubscriptionsDiscoveryDispatcher() 228 self.link((self, 'subscription.inbox'), (subdisp, 'inbox'), passthrough=1) 229 self.link((self, 'subscription.forward'), (subdisp, 'forward'), passthrough=1) 230 self.link((self, 'in.subscription.get'), (subdisp, 'forward'), passthrough=1) 231 self.link((self, 'in.subscription.set'), (subdisp, 'forward'), passthrough=1) 232 self.link((self, 'in.subscription.result'), (subdisp, 'forward'), passthrough=1) 233 self.link((self, 'in.subscription.error'), (subdisp, 'forward'), passthrough=1) 234 self.link((subdisp, 'outbox'), (self, 'subscription.outbox'), passthrough=2) 235 self.link((subdisp, 'xmpp.get'), (self, 'out.subscription.get'), passthrough=2) 236 self.link((subdisp, 'xmpp.set'), (self, 'out.subscription.set'), passthrough=2) 237 self.link((subdisp, 'xmpp.result'), (self, 'out.subscription.result'), passthrough=2) 238 self.link((subdisp, 'xmpp.error'), (self, 'out.subscription.error'), passthrough=2) 239 self.link((subdisp, 'unknown'), (self, 'unknown'), passthrough=2) 240 self.link((subdisp, 'log'), (self, 'log'), passthrough=2) 241 self.addChildren(subdisp) 242 subdisp.activate() 243 244 featdisp = FeaturesDiscoveryDispatcher() 245 self.link((self, 'features.inbox'), (featdisp, 'inbox'), passthrough=1) 246 self.link((self, 'features.forward'), (featdisp, 'forward'), passthrough=1) 247 self.link((self, 'in.features.get'), (featdisp, 'forward'), passthrough=1) 248 self.link((self, 'in.features.set'), (featdisp, 'forward'), passthrough=1) 249 self.link((self, 'in.features.result'), (featdisp, 'forward'), passthrough=1) 250 self.link((self, 'in.features.error'), (featdisp, 'forward'), passthrough=1) 251 self.link((featdisp, 'outbox'), (self, 'outbox'), passthrough=2) 252 self.link((featdisp, 'xmpp.get'), (self, 'out.features.get'), passthrough=2) 253 self.link((featdisp, 'xmpp.set'), (self, 'out.features.set'), passthrough=2) 254 self.link((featdisp, 'xmpp.result'), (self, 'out.features.result'), passthrough=2) 255 self.link((featdisp, 'xmpp.error'), (self, 'out.features.error'), passthrough=2) 256 self.link((featdisp, 'unknown'), (self, 'unknown'), passthrough=2) 257 self.link((featdisp, 'log'), (self, 'log'), passthrough=2) 258 self.addChildren(featdisp) 259 featdisp.activate() 260 261 itemsdisp = ItemsDiscoveryDispatcher() 262 self.link((self, 'items.inbox'), (itemsdisp, 'inbox'), passthrough=1) 263 self.link((self, 'items.forward'), (itemsdisp, 'forward'), passthrough=1) 264 self.link((self, 'in.items.get'), (itemsdisp, 'forward'), passthrough=1) 265 self.link((self, 'in.items.set'), (itemsdisp, 'forward'), passthrough=1) 266 self.link((self, 'in.items.result'), (itemsdisp, 'forward'), passthrough=1) 267 self.link((self, 'in.items.error'), (itemsdisp, 'forward'), passthrough=1) 268 self.link((itemsdisp, 'outbox'), (self, 'outbox'), passthrough=2) 269 self.link((itemsdisp, 'xmpp.get'), (self, 'out.items.get'), passthrough=2) 270 self.link((itemsdisp, 'xmpp.set'), (self, 'out.items.set'), passthrough=2) 271 self.link((itemsdisp, 'xmpp.result'), (self, 'out.items.result'), passthrough=2) 272 self.link((itemsdisp, 'xmpp.error'), (self, 'out.items.error'), passthrough=2) 273 self.link((itemsdisp, 'unknown'), (self, 'unknown'), passthrough=2) 274 self.link((itemsdisp, 'log'), (self, 'log'), passthrough=2) 275 self.addChildren(itemsdisp) 276 itemsdisp.activate() 277 278 return 1 279 280 def main(self): 281 yield self.initComponents() 282 283 while 1: 284 if self.dataReady("control"): 285 mes = self.recv("control") 286 287 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 288 self.send(producerFinished(), "signal") 289 break 290 291 if not self.anyReady(): 292 self.pause() 293 294 yield 1 295 296 yield 1 oss/headstock/headstock/protocol/extension/pubsub.py
r652 r654 3 3 from Axon.Component import component 4 4 from Axon.Ipc import shutdownMicroprocess, producerFinished 5 from Kamaelia.Chassis.Graphline import Graphline 5 6 6 7 from bridge.common import XMPP_PUBSUB_NS, XMPP_DISCO_INFO_NS, \ 7 8 XMPP_DISCO_ITEMS_NS, XMPP_PUBSUB_OWNER_NS, XMPP_PUBSUB_EVENT_NS 8 from headstock.api.pubsub import Node 9 from headstock.api.pubsub import Node, Message 9 10 10 11 __all__ = ['SubscriptionDispatcher', 'NodeCreationDispatcher', 11 12 'NodeDeletionDispatcher', 'UnsubscriptionDispatcher', 12 'ItemPublicationDispatcher', 'ItemDeletionDispatcher'] 13 'ItemPublicationDispatcher', 'ItemDeletionDispatcher', 14 'MessageEventDispatcher', 'PubSubDispatcher'] 13 15 14 16 class SubscriptionDispatcher(component): … … 359 361 360 362 yield 1 363 364 class MessageEventDispatcher(component): 365 366 Inboxes = {"inbox" : "bridge.Element instance", 367 "control" : "",} 368 369 Outboxes = {"outbox" : "bridge.Element instance", 370 "signal" : "Shutdown signal", 371 "log" : "log", 372 "unknown" : "Unknown element that could not be dispatched properly", 373 "xmpp.message" : "Activity requests", 374 } 375 376 def __init__(self): 377 super(MessageEventDispatcher, self).__init__() 378 379 def main(self): 380 yield 1 381 382 while 1: 383 if self.dataReady("control"): 384 mes = self.recv("control") 385 386 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 387 self.send(producerFinished(), "signal") 388 break 389 390 if self.dataReady("inbox"): 391 handled = False 392 a = self.recv("inbox") 393 e = a.xml_parent 394 self.send(('INCOMING', e), "log") 395 self.send(Message.from_element(e), "xmpp.message") 396 397 if not self.anyReady(): 398 self.pause() 399 400 yield 1 401 402 yield 1 403 404 class PubSubDispatcher(component): 405 Inboxes = {"inbox" : "bridge.Element instance", 406 "control" : "Shutdown the client stream", 407 "create.inbox" : "", 408 "create.forward" : "", 409 "delete.inbox" : "", 410 "delete.forward" : "", 411 "subscribe.inbox" : "", 412 "subscribe.forward" : "", 413 "unsubscribe.inbox" : "", 414 "unsubscribe.forward" : "", 415 "publish.inbox" : "", 416 "publish.forward" : "", 417 "retract.inbox" : "", 418 "retract.forward" : "", 419 "message.inbox" : "", 420 "in.create.get" : "Publish items requests", 421 "in.create.set" : "Publish items responses", 422 "in.create.result" : "Publish items responses", 423 "in.delete.error" : "Publish items response error", 424 "in.delete.get" : "Publish items requests", 425 "in.delete.set" : "Publish items responses", 426 "in.delete.result" : "Publish items responses", 427 "in.create.error" : "Publish items response error", 428 "in.subscribe.get" : "Publish items requests", 429 "in.subscribe.set" : "Publish items responses", 430 "in.subscribe.result" : "Publish items responses", 431 "in.subscribe.error" : "Publish items response error", 432 "in.unsubscribe.get" : "Publish items requests", 433 "in.unsubscribe.set" : "Publish items responses", 434 "in.unsubscribe.result" : "Publish items responses", 435 "in.unsubscribe.error" : "Publish items response error", 436 "in.publish.get" : "Publish items requests", 437 "in.publish.set" : "Publish items responses", 438 "in.publish.result" : "Publish items responses", 439 "in.publish.error" : "Publish items response error", 440 "in.retract.get" : "Retract item requests", 441 "in.retract.set" : "Retract item responses", 442 "in.retract.result" : "Retract item responses", 443 "in.retract.error" : "Retract item response error"} 444 445 Outboxes = {"outbox" : "bridge.Element instance", 446 "signal" : "Shutdown signal", 447 "unknown" : "Unknown element that could not be dispatched properly", 448 "log" : "log", 449 "create.outbox" : "", 450 "delete.outbox" : "", 451 "subscribe.outbox" : "", 452 "unsubscribe.outbox" : "", 453 "publish.outbox" : "", 454 "retract.outbox" : "", 455 "message.outbox" : "", 456 "out.create.get" : "Publish items requests", 457 "out.create.set" : "Publish items responses", 458 "out.create.result" : "Publish items responses", 459 "out.delete.error" : "Publish items response error", 460 "out.delete.get" : "Publish items requests", 461 "out.delete.set" : "Publish items responses", 462 "out.delete.result" : "Publish items responses", 463 "out.create.error" : "Publish items response error", 464 "out.subscribe.get" : "Publish items requests", 465 "out.subscribe.set" : "Publish items responses", 466 "out.subscribe.result" : "Publish items responses", 467 "out.subscribe.error" : "Publish items response error", 468 "out.unsubscribe.get" : "Publish items requests", 469 "out.unsubscribe.set" : "Publish items responses", 470 "out.unsubscribe.result" : "Publish items responses", 471 "out.unsubscribe.error" : "Publish items response error", 472 "out.publish.get" : "Publish items requests", 473 "out.publish.set" : "Publish items responses", 474 "out.publish.result" : "Publish items responses", 475 "out.publish.error" : "Publish items response error", 476 "out.retract.get" : "Retract item requests", 477 "out.retract.set" : "Retract item responses", 478 "out.retract.result" : "Retract item responses", 479 "out.retract.error" : "Retract item response error", 480 "out.message" : "Retract item requests",} 481 482 def __init__(self): 483 super(PubSubDispatcher, self).__init__() 484 485 def initComponents(self): 486 subdisp = SubscriptionDispatcher() 487 self.link((self, 'subscribe.inbox'), (subdisp, 'inbox'), passthrough=1) 488 self.link((self, 'subscribe.forward'), (subdisp, 'forward'), passthrough=1) 489 self.link((self, 'in.subscribe.get'), (subdisp, 'forward'), passthrough=1) 490 self.link((self, 'in.subscribe.set'), (subdisp, 'forward'), passthrough=1) 491 self.link((self, 'in.subscribe.result'), (subdisp, 'forward'), passthrough=1) 492 self.link((self, 'in.subscribe.error'), (subdisp, 'forward'), passthrough=1) 493 self.link((subdisp, 'outbox'), (self, 'subscribe.outbox'), passthrough=2) 494 self.link((subdisp, 'xmpp.get'), (self, 'out.subscribe.get'), passthrough=2) 495 self.link((subdisp, 'xmpp.set'), (self, 'out.subscribe.set'), passthrough=2) 496 self.link((subdisp, 'xmpp.result'), (self, 'out.subscribe.result'), passthrough=2) 497 self.link((subdisp, 'xmpp.error'), (self, 'out.subscribe.error'), passthrough=2) 498 self.link((subdisp, 'unknown'), (self, 'unknown'), passthrough=2) 499 self.link((subdisp, 'log'), (self, 'log'), passthrough=2) 500 self.addChildren(subdisp) 501 subdisp.activate() 502 503 unsubdisp = UnsubscriptionDispatcher() 504 self.link((self, 'unsubscribe.inbox'), (unsubdisp, 'inbox'), passthrough=1) 505 self.link((self, 'unsubscribe.forward'), (unsubdisp, 'forward'), passthrough=1) 506 self.link((self, 'in.unsubscribe.get'), (unsubdisp, 'forward'), passthrough=1) 507 self.link((self, 'in.unsubscribe.set'), (unsubdisp, 'forward'), passthrough=1) 508 self.link((self, 'in.unsubscribe.result'), (unsubdisp, 'forward'), passthrough=1) 509 self.link((self, 'in.unsubscribe.error'), (unsubdisp, 'forward'), passthrough=1) 510 self.link((unsubdisp, 'outbox'), (self, 'unsubscribe.outbox'), passthrough=2) 511 self.link((unsubdisp, 'xmpp.get'), (self, 'out.unsubscribe.get'), passthrough=2) 512 self.link((unsubdisp, 'xmpp.set'), (self, 'out.unsubscribe.set'), passthrough=2) 513 self.link((unsubdisp, 'xmpp.result'), (self, 'out.unsubscribe.result'), passthrough=2) 514 self.link((unsubdisp, 'xmpp.error'), (self, 'out.unsubscribe.error'), passthrough=2) 515 self.link((unsubdisp, 'unknown'), (self, 'unknown'), passthrough=2) 516 self.link((unsubdisp, 'log'), (self, 'log'), passthrough=2) 517 self.addChildren(unsubdisp) 518 unsubdisp.activate() 519 520 nodecreatedisp = NodeCreationDispatcher() 521 self.link((self, 'create.inbox'), (nodecreatedisp, 'inbox'), passthrough=1) 522 self.link((self, 'create.forward'), (nodecreatedisp, 'forward'), passthrough=1) 523 self.link((self, 'in.create.get'), (nodecreatedisp, 'forward'), passthrough=1) 524 self.link((self, 'in.create.set'), (nodecreatedisp, 'forward'), passthrough=1) 525 self.link((self, 'in.create.result'), (nodecreatedisp, 'forward'), passthrough=1) 526 self.link((self, 'in.create.error'), (nodecreatedisp, 'forward'), passthrough=1) 527 self.link((nodecreatedisp, 'outbox'), (self, 'create.outbox'), passthrough=2) 528 self.link((nodecreatedisp, 'xmpp.get'), (self, 'out.create.get'), passthrough=2) 529 self.link((nodecreatedisp, 'xmpp.set'), (self, 'out.create.set'), passthrough=2) 530 self.link((nodecreatedisp, 'xmpp.result'), (self, 'out.create.result'), passthrough=2) 531 self.link((nodecreatedisp, 'xmpp.error'), (self, 'out.create.error'), passthrough=2) 532 self.link((nodecreatedisp, 'unknown'), (self, 'unknown'), passthrough=2) 533 self.link((nodecreatedisp, 'log'), (self, 'log'), passthrough=2) 534 self.addChildren(nodecreatedisp) 535 nodecreatedisp.activate() 536 537 nodedeletedisp = NodeDeletionDispatcher() 538 self.link((self, 'delete.inbox'), (nodedeletedisp, 'inbox'), passthrough=1) 539 self.link((self, 'delete.forward'), (nodedeletedisp, 'forward'), passthrough=1) 540 self.link((self, 'in.delete.get'), (nodedeletedisp, 'forward'), passthrough=1) 541 self.link((self, 'in.delete.set'), (nodedeletedisp, 'forward'), passthrough=1) 542 self.link((self, 'in.delete.result'), (nodedeletedisp, 'forward'), passthrough=1) 543 self.link((self, 'in.delete.error'), (nodedeletedisp, 'forward'), passthrough=1) 544 self.link((nodedeletedisp, 'outbox'), (self, 'delete.outbox'), passthrough=2) 545 self.link((nodedeletedisp, 'xmpp.get'), (self, 'out.delete.get'), passthrough=2) 546 self.link((nodedeletedisp, 'xmpp.set'), (self, 'out.delete.set'), passthrough=2) 547 self.link((nodedeletedisp, 'xmpp.result'), (self, 'out.delete.result'), passthrough=2) 548 self.link((nodedeletedisp, 'xmpp.error'), (self, 'out.delete.error'), passthrough=2) 549 self.link((nodedeletedisp, 'unknown'), (self, 'unknown'), passthrough=2) 550 self.link((nodedeletedisp, 'log'), (self, 'log'), passthrough=2) 551 self.addChildren(nodedeletedisp) 552 nodedeletedisp.activate() 553 554 itempublishdisp = ItemPublicationDispatcher() 555 self.link((self, 'publish.inbox'), (itempublishdisp, 'inbox'), passthrough=1) 556 self.link((self, 'publish.forward'), (itempublishdisp, 'forward'), passthrough=1) 557 self.link((self, 'in.publish.get'), (itempublishdisp, 'forward'), passthrough=1) 558 self.link((self, 'in.publish.set'), (itempublishdisp, 'forward'), passthrough=1) 559 self.link((self, 'in.publish.result'), (itempublishdisp, 'forward'), passthrough=1) 560 self.link((self, 'in.publish.error'), (itempublishdisp, 'forward'), passthrough=1) 561 self.link((itempublishdisp, 'outbox'), (self, 'publish.outbox'), passthrough=2) 562 self.link((itempublishdisp, 'xmpp.get'), (self, 'out.publish.get'), passthrough=2) 563 self.link((itempublishdisp, 'xmpp.set'), (self, 'out.publish.set'), passthrough=2) 564 self.link((itempublishdisp, 'xmpp.result'), (self, 'out.publish.result'), passthrough=2) 565 self.link((itempublishdisp, 'xmpp.error'), (self, 'out.publish.error'), passthrough=2) 566 self.link((itempublishdisp, 'unknown'), (self, 'unknown'), passthrough=2) 567 self.link((itempublishdisp, 'log'), (self, 'log'), passthrough=2) 568 self.addChildren(itempublishdisp) 569 itempublishdisp.activate() 570 571 itemretractdisp = ItemDeletionDispatcher() 572 self.link((self, 'retract.inbox'), (itemretractdisp, 'inbox'), passthrough=1) 573 self.link((self, 'retract.forward'), (itemretractdisp, 'forward'), passthrough=1) 574 self.link((self, 'in.retract.get'), (itemretractdisp, 'forward'), passthrough=1) 575 self.link((self, 'in.retract.set'), (itemretractdisp, 'forward'), passthrough=1) 576 self.link((self, 'in.retract.result'), (itemretractdisp, 'forward'), passthrough=1) 577 self.link((self, 'in.retract.error'), (itemretractdisp, 'forward'), passthrough=1) 578 self.link((itemretractdisp, 'outbox'), (self, 'retract.outbox'), passthrough=2) 579 self.link((itemretractdisp, 'xmpp.get'), (self, 'out.retract.get'), passthrough=2) 580 self.link((itemretractdisp, 'xmpp.set'), (self, 'out.retract.set'), passthrough=2) 581 self.link((itemretractdisp, 'xmpp.result'), (self, 'out.retract.result'), passthrough=2) 582
