summaryrefslogtreecommitdiff
path: root/xmpp/iq.go
blob: 2fe7c9496b4a7ffcffd556e658d14eb96d7c1b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package xmpp

import (
	"encoding/xml"
	"fmt"
	"math/rand"
	"log"
)

type iq 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"`
}

func (s *session) sendBind() {
	s.resourceReq = fmt.Sprintf("%016x", rand.Uint64())

	req := iq{}
	req.Id = s.resourceReq
	req.Type = "set"
	req.Bind.Resource = "limox-" + fmt.Sprintf("%08x", rand.Uint32())

	err := s.tx.Encode(req)
	if err != nil {
		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
	}
}