diff options
author | xengineering <me@xengineering.eu> | 2023-07-05 22:34:13 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-07-05 22:34:13 +0200 |
commit | 4cc9ea5cd439a1f5306f38838774b46d2b145d9a (patch) | |
tree | f1baf8010d7be8ee298e605d6308c345d4d17606 | |
parent | 57845892dbfc6db0648b18e418a6b15218d8526c (diff) | |
download | limox-4cc9ea5cd439a1f5306f38838774b46d2b145d9a.tar limox-4cc9ea5cd439a1f5306f38838774b46d2b145d9a.tar.zst limox-4cc9ea5cd439a1f5306f38838774b46d2b145d9a.zip |
Migrate bind sending to new generic iq struct
This makes the code way less complex.
-rw-r--r-- | xmpp/iq.go | 28 |
1 files changed, 6 insertions, 22 deletions
@@ -13,35 +13,19 @@ type iq struct { Id string `xml:"id,attr,omitempty"` Bind struct{ Jid string `xml:"jid,omitempty"` + Resource string `xml:"resource,omitempty"` } `xml:"urn:ietf:params:xml:ns:xmpp-bind bind,omitempty"` } -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()) - start := xml.StartElement{ - xml.Name{"jabber:client", "iq"}, - []xml.Attr{ - xml.Attr{xml.Name{"", "id"}, s.resourceReq}, - xml.Attr{xml.Name{"", "type"}, "set"}, - }, - } - - inner := bindRequest{} - inner.Bind.Xmlns = "urn:ietf:params:xml:ns:xmpp-bind" - inner.Bind.Resource.Content = "limox-" + fmt.Sprintf("%08x", rand.Uint32()) + req := iq{} + req.Id = s.resourceReq + req.Type = "set" + req.Bind.Resource = "limox-" + fmt.Sprintf("%08x", rand.Uint32()) - err := s.tx.EncodeElement(inner, start) + err := s.tx.Encode(req) if err != nil { log.Println("Could not encode ressource binding!") } |