source: ralphm-patches/router_unknown.patch @ 57:0d8b6cf41728

Last change on this file since 57:0d8b6cf41728 was 57:0d8b6cf41728, checked in by Ralph Meijer <ralphm@…>, 10 years ago

Wokkel 0.7.0 release, clean up various patches.

File size: 1.5 KB
RevLine 
[54]1# HG changeset patch
[57]2# Parent 3d3065a425fa27c45c1f25aae8910f282f3049a4
[54]3Send back an error if there is no known route to the stanza's destination.
4
5This is most useful in situations where there is no server-to-server
6component that acts as the default route (indexed by `None`).
7
[57]8diff -r 3d3065a425fa wokkel/component.py
9--- a/wokkel/component.py       Wed Mar 28 13:34:30 2012 +0200
10+++ b/wokkel/component.py       Wed Mar 28 13:36:55 2012 +0200
11@@ -332,12 +332,24 @@
[54]12         """
13         destination = JID(stanza['to'])
14 
15-        log.msg("Routing to %s: %r" % (destination.full(), stanza.toXml()))
16 
17         if destination.host in self.routes:
18+            log.msg("Routing to %s: %r" % (destination.full(),
19+                                           stanza.toXml()))
20             self.routes[destination.host].send(stanza)
21+        elif None in self.routes:
22+            log.msg("Routing to %s (default route): %r" % (destination.full(),
23+                                                           stanza.toXml()))
24+            self.routes[None].send(stanza)
25         else:
26-            self.routes[None].send(stanza)
27+            log.msg("No route to %s: %r" % (destination.full(),
28+                                            stanza.toXml()))
29+            if stanza.getAttribute('type') not in ('result', 'error'):
30+                # No route, send back error
31+                exc = error.StanzaError('remote-server-timeout', type='wait')
32+                exc.code = '504'
33+                response = exc.toResponse(stanza)
34+                self.route(response)
35 
36 
37 
Note: See TracBrowser for help on using the repository browser.