package xmpp import ( "encoding/xml" "fmt" "math/rand" "log" ) 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() s.sendRosterGet() 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{ 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 := bindSet{} 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!") } } type rosterGet struct { XMLName xml.Name `xml:"jabber:client iq"` Type string `xml:"type,attr,omitempty"` Id string `xml:"id,attr,omitempty"` Query string `xml:"jabber:iq:roster query"` } func (s *session) sendRosterGet() { req := rosterGet{} req.Id = fmt.Sprintf("%016x", rand.Uint64()) req.Type = "get" err := s.tx.Encode(req) if err != nil { log.Println("Could not encode ressource binding!") } }