diff options
author | xengineering <me@xengineering.eu> | 2023-06-30 13:07:12 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-30 13:07:12 +0200 |
commit | 8b608265772ba5df13d24071117c694bdfd1212a (patch) | |
tree | d78bbd26a438e645c807f6a917b4101d20fe18b1 | |
parent | 372575cd38a939d1c8f412c8cea653c86bc725df (diff) | |
download | limox-8b608265772ba5df13d24071117c694bdfd1212a.tar limox-8b608265772ba5df13d24071117c694bdfd1212a.tar.zst limox-8b608265772ba5df13d24071117c694bdfd1212a.zip |
Add session pointer to routing infrastructure
It is nearly useless to route a XML element to an appropriate handler
function if the latter has no idea how to send responses to the server
or the GUI. Passing a pointer to the session solves this issue.
-rw-r--r-- | xmpp/router.go | 6 | ||||
-rw-r--r-- | xmpp/router_test.go | 7 | ||||
-rw-r--r-- | xmpp/stream_pair.go | 4 |
3 files changed, 9 insertions, 8 deletions
diff --git a/xmpp/router.go b/xmpp/router.go index 879579d..bd619b4 100644 --- a/xmpp/router.go +++ b/xmpp/router.go @@ -12,7 +12,7 @@ import ( // entry of the routingTable. type routingTable []struct { name xml.Name - handler func([]xml.Token) + handler func(*session, []xml.Token) } // getRoutingTable returns the routing table used in @@ -29,7 +29,7 @@ func getRoutingTable() routingTable { // route determines the correct handler function for the given XML element by a // given routingTable. In addition it executes the determined handler function. // If no handler function is found an error message is send via the log module. -func route(e []xml.Token, t routingTable) { +func route(s *session, e []xml.Token, t routingTable) { var name xml.Name // TODO a stronger definition of an XML element (as here @@ -50,7 +50,7 @@ func route(e []xml.Token, t routingTable) { for _, r := range t { if name == r.name { - r.handler(e) + r.handler(s, e) return } } diff --git a/xmpp/router_test.go b/xmpp/router_test.go index ea13712..41484c5 100644 --- a/xmpp/router_test.go +++ b/xmpp/router_test.go @@ -23,9 +23,10 @@ type routerTest struct { // validated. func TestRouter(t *testing.T) { var testpoint int + var s session - factory := func(tp *int, i int) func([]xml.Token) { - return func([]xml.Token) { + factory := func(tp *int, i int) func(*session, []xml.Token) { + return func(*session, []xml.Token) { *tp = i } } @@ -60,7 +61,7 @@ func TestRouter(t *testing.T) { tokens = append(tokens, xml.CopyToken(token)) } - route(tokens, testRouting) + route(&s, tokens, testRouting) if testpoint != v.value { t.Fatalf("XML element was not routed correctly!\n") diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go index 8f70318..8ec06a6 100644 --- a/xmpp/stream_pair.go +++ b/xmpp/stream_pair.go @@ -28,7 +28,7 @@ func runStreamPair(s *session) { } if buf.isComplete() { element := buf.reset() - route(element, getRoutingTable()) + route(s, element, getRoutingTable()) } } } @@ -91,7 +91,7 @@ func closeStream(s *session) { } } -func streamFeaturesHandler(e []xml.Token) { +func streamFeaturesHandler(s *session, e []xml.Token) { sasl := hasSaslPlain(e) if sasl { log.Println("Stream is compatible with SASL PLAIN mechanism") |