Changeset 41:2a1d87409c11 in ralphm-patches


Ignore:
Timestamp:
Feb 25, 2010, 9:50:42 AM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Minor cleanups, have handlers return boolean that sets presence.handled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • xmpp_client_service.patch

    r40 r41  
    11diff -r 62f841ed2a99 doc/examples/client_service.tac
    22--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    3 +++ b/doc/examples/client_service.tac   Mon Feb 22 18:20:52 2010 +0100
     3+++ b/doc/examples/client_service.tac   Thu Feb 25 09:47:52 2010 +0100
    44@@ -0,0 +1,74 @@
    55+from twisted.application import service, strports
     
    7979diff -r 62f841ed2a99 wokkel/client.py
    8080--- a/wokkel/client.py  Sat Feb 13 18:57:26 2010 +0100
    81 +++ b/wokkel/client.py  Mon Feb 22 18:20:52 2010 +0100
     81+++ b/wokkel/client.py  Thu Feb 25 09:47:52 2010 +0100
    8282@@ -10,13 +10,27 @@
    8383 that should probably eventually move there.
     
    472472diff -r 62f841ed2a99 wokkel/component.py
    473473--- a/wokkel/component.py       Sat Feb 13 18:57:26 2010 +0100
    474 +++ b/wokkel/component.py       Mon Feb 22 18:20:52 2010 +0100
    475 @@ -313,12 +313,24 @@
     474+++ b/wokkel/component.py       Thu Feb 25 09:47:52 2010 +0100
     475@@ -313,12 +313,25 @@
    476476         """
    477477         destination = JID(stanza['to'])
     
    484484+                                           stanza.toXml()))
    485485             self.routes[destination.host].send(stanza)
    486 +        elif None in self.routers:
     486+        elif None in self.routes:
    487487+            log.msg("Routing to %s (default route): %r" % (destination.full(),
    488488+                                                           stanza.toXml()))
     
    494494+            if stanza.getAttribute('type') not in ('result', 'error'):
    495495+                # No route, send back error
    496 +                exc = error.StanzaError('remote-server-timeout')
     496+                exc = error.StanzaError('remote-server-timeout', type='wait')
     497+                exc.code = '504'
    497498+                response = exc.toResponse(stanza)
    498499+                self.route(response)
     
    502503diff -r 62f841ed2a99 wokkel/xmppim.py
    503504--- a/wokkel/xmppim.py  Sat Feb 13 18:57:26 2010 +0100
    504 +++ b/wokkel/xmppim.py  Mon Feb 22 18:20:52 2010 +0100
     505+++ b/wokkel/xmppim.py  Thu Feb 25 09:47:52 2010 +0100
    505506@@ -12,8 +12,11 @@
    506507 All of it should eventually move to Twisted.
     
    674675 
    675676         presenceType = stanza.stanzaType or 'available'
    676 @@ -405,7 +411,12 @@
     677@@ -405,14 +411,19 @@
    677678         except KeyError:
    678679             return
     
    688689         try:
    689690             handler = getattr(self, '%sReceived' % presenceType)
     691         except AttributeError:
     692             return
     693         else:
     694-            handler(presence)
     695+            element.handled = handler(presence)
     696 
     697 
     698     def errorReceived(self, presence):
    690699@@ -478,7 +489,7 @@
    691700 
     
    778787         d.addErrback(lambda _: error.ErrorStanza('internal-error').toResponse(iq))
    779788         d.addBoth(self.send)
    780 @@ -808,3 +819,416 @@
     789@@ -808,3 +819,433 @@
    781790         """
    782791         Called when a message stanza was received.
     
    824833+            # Bare JID at local domain, ignore it
    825834+            return
    826 +        elif recipient.user in self.sessionManager.sessions:
    827 +            # Full JID with connected resource, deliver the stanza
     835+
     836+        userSessions = self.sessionManager.sessions.get(recipient.user,
     837+                                                        {})
     838+        if recipient.resource in userSessions:
    828839+            self.sessionManager.deliverStanza(iq, recipient)
    829840+        else:
     
    967978+
    968979+
     980+    def _onPresenceOutbound(self, element):
     981+        log.msg("Got outbound presence: %r" % element.toXml())
     982+        presence = self.parsePresence(element)
     983+
     984+        presenceType = presence.stanzaType or 'available'
     985+        method = '%sReceivedOutbound' % presenceType
     986+        print method
     987+
     988+        try:
     989+            handler = getattr(self, method)
     990+        except AttributeError:
     991+            return
     992+        else:
     993+            element.handled = handler(presence)
     994+
     995+
    969996+    def _broadcastToOtherResources(self, presence):
    970997+        """
     
    10571084+        self.sessionManager.sessions[user][resource].presence = presence
    10581085+
    1059 +
    1060 +    #def _on_availableDirected(self, presence):
    1061 +    #    pass
    1062 +
    1063 +
    1064 +    def _on_availableInbound(self, presence):
     1086+        return True
     1087+
     1088+
     1089+    def _on_availableDirected(self, presence):
     1090+        self.send(presence.element)
     1091+        return True
     1092+
     1093+
     1094+    def availableReceivedOutbound(self, presence):
     1095+        if presence.recipient:
     1096+            return self._on_availableDirected(presence)
     1097+        else:
     1098+            return self._on_availableBroadcast(presence)
     1099+
     1100+
     1101+    def availableReceived(self, presence):
    10651102+        fromJID = presence.sender
    10661103+        toJID = presence.recipient
    1067 +        if (toJID.user in self.roster and
    1068 +            toJID.user in self.presences):
     1104+
     1105+        if toJID.user not in self.roster:
     1106+            return False
     1107+
     1108+        if toJID.user in self.presences:
    10691109+            for resource in self.presences[toJID.user]:
    10701110+                resourceJID = JID(tuple=(toJID.user, toJID.host, resource))
     
    10751115+            pass
    10761116+
     1117+        return True
     1118+
    10771119+
    10781120+    def _on_unavailableBroadcast(self, presence):
     
    10971139+                # TODO: save last unavailable presence
    10981140+
    1099 +
    1100 +#    def _on_unavailableDirected(self, presence):
    1101 +#        pass
    1102 +
    1103 +
    1104 +#    def _on_unavailableInbound(self, presence):
    1105 +#        pass
    1106 +
    1107 +
    1108 +    def _onPresenceOutbound(self, element):
    1109 +        log.msg("Got outbound presence: %r" % element.toXml())
    1110 +        presence = self.parsePresence(element)
    1111 +
    1112 +        presenceType = presence.stanzaType or 'available'
    1113 +        method = '%sReceivedOutbound' % presenceType
    1114 +        print method
    1115 +
    1116 +        try:
    1117 +            handler = getattr(self, method)
    1118 +        except AttributeError:
    1119 +            return
    1120 +        else:
    1121 +            element.handled = True
    1122 +            handler(presence)
    1123 +
    1124 +
    1125 +    def availableReceived(self, presence):
    1126 +        self._on_availableInbound(presence)
    1127 +
    1128 +
    1129 +    def availableReceivedOutbound(self, presence):
    1130 +        if presence.recipient:
    1131 +            pass # self._on_availableDirected(presence)
    1132 +        else:
    1133 +            self._on_availableBroadcast(presence)
    1134 +
    1135 +
    1136 +#    def unavailableReceived(self, presence):
    1137 +#        self._on_unavailableInbound(presence)
     1141+        return True
     1142+
     1143+
     1144+    def _on_unavailableDirected(self, presence):
     1145+        self.send(presence.element)
     1146+        return True
    11381147+
    11391148+
    11401149+    def unavailableReceivedOutbound(self, presence):
    11411150+        if presence.recipient:
    1142 +            pass # self._on_unavailableDirected(presence)
    1143 +        else:
    1144 +            self._on_unavailableBroadcast(presence)
     1151+            return self._on_unavailableDirected(presence)
     1152+        else:
     1153+            return self._on_unavailableBroadcast(presence)
     1154+
     1155+#    def unavailableReceived(self, presence):
    11451156+
    11461157+
     
    11481159+        log.msg("%r subscribed %s to its presence" % (presence.sender,
    11491160+                                                      presence.recipient))
    1150 +        #self.send(presence.element)
     1161+        self.send(presence.element)
     1162+        return True
     1163+
     1164+
     1165+    def subscribedReceived(self, presence):
     1166+        log.msg("%r subscribed %s to its presence" % (presence.sender,
     1167+                                                      presence.recipient))
    11511168+
    11521169+
     
    11541171+        log.msg("%r unsubscribed %s from its presence" % (presence.sender,
    11551172+                                                          presence.recipient))
    1156 +        #self.send(presence.element)
    1157 +
    1158 +
    1159 +    def subscribeReceived(self, presence):
    1160 +        log.msg("%r requests subscription to %s" % (presence.sender,
    1161 +                                                    presence.recipient))
     1173+        self.send(presence.element)
     1174+        return True
     1175+
     1176+
     1177+    def unsubscribedReceived(self, presence):
     1178+        log.msg("%r unsubscribed %s from its presence" % (presence.sender,
     1179+                                                          presence.recipient))
    11621180+
    11631181+
     
    11661184+                                                    presence.recipient))
    11671185+        self.send(presence.element)
    1168 +
    1169 +
    1170 +    def unsubscribeReceived(self, presence):
    1171 +        log.msg("%r requests unsubscription from %s" % (presence.sender,
    1172 +                                                        presence.recipient))
     1186+        return True
     1187+
     1188+
     1189+    def subscribeReceived(self, presence):
     1190+        log.msg("%r requests subscription to %s" % (presence.sender,
     1191+                                                    presence.recipient))
     1192+
    11731193+
    11741194+    def unsubscribeReceivedOutbound(self, presence):
     
    11761196+                                                        presence.recipient))
    11771197+        self.send(presence.element)
     1198+        return True
     1199+
     1200+
     1201+    def unsubscribeReceived(self, presence):
     1202+        log.msg("%r requests unsubscription from %s" % (presence.sender,
     1203+                                                        presence.recipient))
    11781204+
    11791205+
Note: See TracChangeset for help on using the changeset viewer.