diff options
author | xengineering <me@xengineering.eu> | 2023-07-04 22:04:05 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-07-04 22:04:05 +0200 |
commit | a23ba089a4e715e68b8c8d4179290692215784a2 (patch) | |
tree | f7c13f78ff728b9e0e59045f1709907c29c55e37 | |
parent | ed6b4e818f4090c0c707fab49093bc4c3cc3ac20 (diff) | |
download | limox-a23ba089a4e715e68b8c8d4179290692215784a2.tar limox-a23ba089a4e715e68b8c8d4179290692215784a2.tar.zst limox-a23ba089a4e715e68b8c8d4179290692215784a2.zip |
Re-implement resource binding and presence
This was removed for refactoring.
-rw-r--r-- | xmpp/jid.go | 27 | ||||
-rw-r--r-- | xmpp/routing.go | 8 | ||||
-rw-r--r-- | xmpp/sasl.go | 6 | ||||
-rw-r--r-- | xmpp/streams.go | 8 |
4 files changed, 34 insertions, 15 deletions
diff --git a/xmpp/jid.go b/xmpp/jid.go index 83772fd..c732027 100644 --- a/xmpp/jid.go +++ b/xmpp/jid.go @@ -41,21 +41,6 @@ func username(jid string) string { return "" } -func hasBind(e []xml.Token) bool { - bind := xml.Name{`urn:ietf:params:xml:ns:xmpp-bind`, `bind`} - - for _, v := range e { - switch s := v.(type) { - case xml.StartElement: - if s.Name == bind { - return true - } - } - } - - return false -} - type bindRequest struct { Bind struct { Xmlns string `xml:"xmlns,attr"` @@ -86,3 +71,15 @@ func (s *session) sendBind() { log.Println("Could not encode ressource binding!") } } + +type iqResponse struct { + Jid string `xml:"urn:ietf:params:xml:ns:xmpp-bind bind>jid"` +} + +func handleIqResponse(s *session, i iqResponse) { + if i.Jid != "" { + s.jid = i.Jid + s.sendPresence() + return + } +} diff --git a/xmpp/routing.go b/xmpp/routing.go index a9dd8b6..5cd2040 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -9,6 +9,10 @@ func route(s *xml.StartElement, d *xml.Decoder, c chan<- any) { switch (*s).Name { case xml.Name{`http://etherx.jabber.org/streams`, `features`}: parse(streamFeatures{}, s, d, c) + case xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `success`}: + parse(saslSuccess{}, s, d, c) + case xml.Name{`jabber:client`, `iq`}: + parse(iqResponse{}, s, d, c) default: d.Skip() } @@ -27,6 +31,10 @@ func handle(s *session, element any) { switch t := element.(type) { case streamFeatures: handleStreamFeatures(s, t) + case saslSuccess: + handleSaslSuccess(s) + case iqResponse: + handleIqResponse(s, t) default: log.Printf("Unknown parsed element: %v", t) } diff --git a/xmpp/sasl.go b/xmpp/sasl.go index a20ae56..5fac934 100644 --- a/xmpp/sasl.go +++ b/xmpp/sasl.go @@ -10,6 +10,12 @@ type saslRequest struct { Payload []byte `xml:",chardata"` } +type saslSuccess struct {} + +func handleSaslSuccess(s *session) { + openStream(s.tx, s.jid) +} + func (s *session) sasl() { start := xml.StartElement{ xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"}, diff --git a/xmpp/streams.go b/xmpp/streams.go index b9cd4cd..18a5e6a 100644 --- a/xmpp/streams.go +++ b/xmpp/streams.go @@ -7,9 +7,12 @@ import ( type streamFeatures struct { SaslMechanisms []string `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms>mechanism"` + Bind *bool `xml:"urn:ietf:params:xml:ns:xmpp-bind bind,omitempty"` } func handleStreamFeatures(s *session, f streamFeatures) { + log.Print(f) + if len(f.SaslMechanisms) > 0 { for _, v := range f.SaslMechanisms { if v == "PLAIN" { @@ -20,6 +23,11 @@ func handleStreamFeatures(s *session, f streamFeatures) { log.Println("No compatible SASL mechanism found!") return } + + if f.Bind != nil { + s.sendBind() + return + } } func openStream(e *xml.Encoder, jid string) { |