summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-02 12:04:10 +0200
committerxengineering <me@xengineering.eu>2023-07-03 20:54:35 +0200
commitbde6e0c5095c1fd73058dc8dab408fd5f27aee7c (patch)
treec003e3f70c2715ca7f9bcf44cfda736392d92c9e
parent6a623ed4ec649f0fcfa775405ad5584bc1cd6762 (diff)
downloadlimox-bde6e0c5095c1fd73058dc8dab408fd5f27aee7c.tar
limox-bde6e0c5095c1fd73058dc8dab408fd5f27aee7c.tar.zst
limox-bde6e0c5095c1fd73058dc8dab408fd5f27aee7c.zip
Switch to EncodeElement() for resource binding
-rw-r--r--xmpp/jid.go48
1 files changed, 17 insertions, 31 deletions
diff --git a/xmpp/jid.go b/xmpp/jid.go
index fd0d7ae..332073b 100644
--- a/xmpp/jid.go
+++ b/xmpp/jid.go
@@ -56,47 +56,33 @@ func hasBind(e []xml.Token) bool {
return false
}
+type bindRequest struct {
+ Bind struct {
+ Xmlns string `xml:"xmlns,attr"`
+ Resource struct {
+ Content string `xml:",chardata"`
+ } `xml:"resource"`
+ } `xml:"bind"`
+}
+
func (s *session) sendBind() {
+
s.resourceReq = fmt.Sprintf("%016x", rand.Uint64())
- iqStart := xml.StartElement{
+ start := xml.StartElement{
xml.Name{"jabber:client", "iq"},
[]xml.Attr{
xml.Attr{xml.Name{"", "id"}, s.resourceReq},
xml.Attr{xml.Name{"", "type"}, "set"},
},
}
- iqEnd := iqStart.End()
-
- bindStart := xml.StartElement{
- xml.Name{"urn:ietf:params:xml:ns:xmpp-bind", "bind"},
- []xml.Attr{},
- }
- bindEnd := bindStart.End()
- resourceStart := xml.StartElement{
- xml.Name{"", "resource"},
- []xml.Attr{},
- }
- resourceEnd := resourceStart.End()
-
- name := xml.CharData("limox-" + fmt.Sprintf("%08x", rand.Uint32()))
-
- tokens := [...]xml.Token{
- iqStart,
- bindStart,
- resourceStart,
- name,
- resourceEnd,
- bindEnd,
- iqEnd,
- }
+ inner := bindRequest{}
+ inner.Bind.Xmlns = "urn:ietf:params:xml:ns:xmpp-bind"
+ inner.Bind.Resource.Content = "limox-" + fmt.Sprintf("%08x", rand.Uint32())
- for _, v := range tokens {
- err := s.ed.encodeToken(v)
- if err != nil {
- log.Println("Could not encode ressource binding!")
- return
- }
+ err := s.ed.tx.EncodeElement(inner, start)
+ if err != nil {
+ log.Println("Could not encode ressource binding!")
}
}