summaryrefslogtreecommitdiff
path: root/xmpp/iq.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/iq.go')
-rw-r--r--xmpp/iq.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/xmpp/iq.go b/xmpp/iq.go
new file mode 100644
index 0000000..1c12c8c
--- /dev/null
+++ b/xmpp/iq.go
@@ -0,0 +1,51 @@
+package xmpp
+
+import (
+ "encoding/xml"
+ "fmt"
+ "math/rand"
+ "log"
+)
+
+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())
+
+ err := s.tx.EncodeElement(inner, start)
+ if err != nil {
+ log.Println("Could not encode ressource binding!")
+ }
+}
+
+type iqResponse struct {
+ Jid string `xml:"urn:ietf:params:xml:ns:xmpp-bind bind>jid"`
+}
+
+func handleIqResponse(s *session, i iqResponse) {
+ if i.Jid != "" {
+ s.jid = i.Jid
+ s.sendPresence()
+ return
+ }
+}