summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmpp/iq.go30
-rw-r--r--xmpp/routing.go6
2 files changed, 22 insertions, 14 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
- }
-}
diff --git a/xmpp/routing.go b/xmpp/routing.go
index df45451..4058dfb 100644
--- a/xmpp/routing.go
+++ b/xmpp/routing.go
@@ -12,7 +12,7 @@ func route(s *xml.StartElement, d *xml.Decoder, c chan<- any) {
case xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `success`}:
parse(saslSuccess{}, s, d, c)
case xml.Name{`jabber:client`, `iq`}:
- parse(iq{}, s, d, c)
+ parse(iqRx{}, s, d, c)
case xml.Name{`jabber:client`, `message`}:
parse(message{}, s, d, c)
default:
@@ -35,8 +35,8 @@ func handle(s *session, element any) {
handleStreamFeatures(s, t)
case saslSuccess:
handleSaslSuccess(s)
- case iq:
- handleIq(s, t)
+ case iqRx:
+ t.handle(s)
case message:
handleMessage(s, t)
default: