diff options
author | xengineering <me@xengineering.eu> | 2023-06-26 18:37:16 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-27 15:04:33 +0200 |
commit | 8715603ce1a713d1c8841382bb965cb55948fedd (patch) | |
tree | c3af42979a443168d85dd194b063308417ad0f42 /xmpp/routing.go | |
parent | a8a6c31d862ec1d491fc76ed21c46d7e0b35b7f2 (diff) | |
download | limox-8715603ce1a713d1c8841382bb965cb55948fedd.tar limox-8715603ce1a713d1c8841382bb965cb55948fedd.tar.zst limox-8715603ce1a713d1c8841382bb965cb55948fedd.zip |
xmpp: Remove unused code
This is part of the refactoring. Details of the old implementation
should be looked up by older commits.
Diffstat (limited to 'xmpp/routing.go')
-rw-r--r-- | xmpp/routing.go | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go deleted file mode 100644 index 9199874..0000000 --- a/xmpp/routing.go +++ /dev/null @@ -1,104 +0,0 @@ -package xmpp - -import ( - "encoding/xml" - "errors" - "log" -) - -type tokenRouter struct { - start xml.StartElement - end xml.EndElement - buffer []xml.Token - level uint16 // XML nesting level - enc *encoder -} - -func newTokenRouter() tokenRouter { - return tokenRouter{ - buffer: make([]xml.Token, 0), - level: 0, - } -} - -func (r *tokenRouter) route(t xml.Token, c *Conn) error { - r.buffer = append(r.buffer, t) - - switch unwrapped := t.(type) { - case xml.StartElement: - r.level += 1 - if r.level == 1 { - r.start = unwrapped - r.buffer = r.buffer[:0] - // call start handler - } - case xml.EndElement: - if r.level == 0 { - log.Println("Ignoring XML end element on nesting level zero") - return nil - } - r.level -= 1 - switch r.level { - case 0: - return errors.New("Stream was closed by server") - case 1: - err := routeElement(r.buffer, c) - if err != nil { - return err - } - r.buffer = r.buffer[:0] - } - case xml.ProcInst: - log.Println("Ignoring xml.ProcInst element") - r.buffer = r.buffer[:len(r.buffer)-1] - case xml.Directive: - log.Println("Ignoring xml.Directive element") - r.buffer = r.buffer[:len(r.buffer)-1] - case xml.Comment: - log.Println("Ignoring xml.Comment element") - r.buffer = r.buffer[:len(r.buffer)-1] - } - - return nil -} - -func routeElement(b []xml.Token, c *Conn) error { - tab := elementRoutingTable{ - {xml.Name{"http://etherx.jabber.org/streams", "features"}, streamFeatures}, - {xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "success"}, onSaslSuccess}, - {xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "failure"}, onSaslFailure}, - } - - switch unwrapped := b[0].(type) { - case xml.StartElement: - for _, v := range(tab) { - if unwrapped.Name == v.name { - err := v.handler(b, c) - if err != nil { - return err - } - return nil - } - } - log.Printf("Ignoring XML element '%s' from namespace '%s'", - unwrapped.Name.Local, unwrapped.Name.Space) - default: - log.Println("Ignoring XML element which has no StartElement as first token") - } - - return nil -} - -type elementRoutingTable []struct { - name xml.Name - handler func(b []xml.Token, c *Conn) error -} - -func streamFeatures(b []xml.Token, c *Conn) error { - err := sendSaslAuth(b, c) - if err != nil { - return err - } - - return nil -} |