diff options
author | xengineering <me@xengineering.eu> | 2023-06-30 14:08:04 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-30 15:30:27 +0200 |
commit | dd1cb9c23392d4d43198d60879fecf61fe4503b7 (patch) | |
tree | 089f4054ba1b4575e347c0c49b5d6d9408be2b76 | |
parent | 2f1fd4d1ce2c0c2e46fcfa1ffedfd84f0d36484e (diff) | |
download | limox-dd1cb9c23392d4d43198d60879fecf61fe4503b7.tar limox-dd1cb9c23392d4d43198d60879fecf61fe4503b7.tar.zst limox-dd1cb9c23392d4d43198d60879fecf61fe4503b7.zip |
Implement detection of resource binding offer
This allows to trigger resource binding if the stream supports it.
-rw-r--r-- | xmpp/jid.go | 19 | ||||
-rw-r--r-- | xmpp/stream_pair.go | 5 |
2 files changed, 24 insertions, 0 deletions
diff --git a/xmpp/jid.go b/xmpp/jid.go index 90c1509..d7107d4 100644 --- a/xmpp/jid.go +++ b/xmpp/jid.go @@ -1,5 +1,9 @@ package xmpp +import ( + "encoding/xml" +) + // domainpart extracts the domain name from a JID / XMPP address. See // https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details. func domainpart(jid string) string { @@ -33,3 +37,18 @@ 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 +} diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go index 693972e..9be880f 100644 --- a/xmpp/stream_pair.go +++ b/xmpp/stream_pair.go @@ -98,5 +98,10 @@ func streamFeaturesHandler(s *session, e []xml.Token) { return } + if hasBind(e) { + log.Println("Stream supports ressource binding") + return + } + log.Println("Stream has no implemented features!") } |