summaryrefslogtreecommitdiff
path: root/xmpp/iq.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-06 21:21:33 +0200
committerxengineering <me@xengineering.eu>2023-07-06 21:21:33 +0200
commit553537a2c9f08450614648d7184b6bbf212d5ed5 (patch)
treebd804d8a9b5fa66bdcb115f522b0348feae809f1 /xmpp/iq.go
parent4cc9ea5cd439a1f5306f38838774b46d2b145d9a (diff)
downloadlimox-553537a2c9f08450614648d7184b6bbf212d5ed5.tar
limox-553537a2c9f08450614648d7184b6bbf212d5ed5.tar.zst
limox-553537a2c9f08450614648d7184b6bbf212d5ed5.zip
Use different IQ struct for RX and TX
It is quite tricky to write structs with correct XML struct tags which are suitable for RX and TX because in RX structs all possible fields have to be addressed and in TX some have to be hidden depending on the use case.
Diffstat (limited to 'xmpp/iq.go')
-rw-r--r--xmpp/iq.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/xmpp/iq.go b/xmpp/iq.go
index 2fe7c94..3d0e5a2 100644
--- a/xmpp/iq.go
+++ b/xmpp/iq.go
@@ -7,12 +7,28 @@ import (
"log"
)
-type iq struct {
+type iqRx struct {
+ XMLName xml.Name `xml:"jabber:client iq"`
+ Type string `xml:"type,attr"`
+ Id string `xml:"id,attr"`
+ Bind struct{
+ Jid string `xml:"jid"`
+ } `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
+}
+
+func (i iqRx) handle(s *session) {
+ if i.Bind.Jid != "" {
+ s.jid = i.Bind.Jid
+ s.sendPresence()
+ return
+ }
+}
+
+type bindSet struct {
XMLName xml.Name `xml:"jabber:client iq"`
Type string `xml:"type,attr,omitempty"`
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"`
}
@@ -20,7 +36,7 @@ type iq struct {
func (s *session) sendBind() {
s.resourceReq = fmt.Sprintf("%016x", rand.Uint64())
- req := iq{}
+ req := bindSet{}
req.Id = s.resourceReq
req.Type = "set"
req.Bind.Resource = "limox-" + fmt.Sprintf("%08x", rand.Uint32())
@@ -30,11 +46,3 @@ func (s *session) sendBind() {
log.Println("Could not encode ressource binding!")
}
}
-
-func handleIq(s *session, i iq) {
- if i.Bind.Jid != "" {
- s.jid = i.Bind.Jid
- s.sendPresence()
- return
- }
-}