1
0
Fork 0

Add client session establishment.

This commit is contained in:
Matt Goodall 2012-07-13 11:23:49 +01:00
parent ba349b1058
commit 17d143cb2c
1 changed files with 31 additions and 0 deletions

View File

@ -66,6 +66,14 @@ func NewClientXMPP(stream *Stream, jid JID, password string, config *ClientConfi
jid = boundJID jid = boundJID
} }
// Session.
if f.Session != nil {
log.Println("Establishing session.")
if err := establishSession(stream, jid.Domain); err != nil {
return nil, err
}
}
break break
} }
@ -208,6 +216,24 @@ type bindIq struct {
JID string `xml:"jid,omitempty"` JID string `xml:"jid,omitempty"`
} }
func establishSession(stream *Stream, domain string) error {
req := Iq{Id: UUID4(), Type: "set", To: domain}
req.PayloadEncode(&session{})
if err := stream.Send(req); err != nil {
return err
}
resp := Iq{}
if err := stream.Decode(&resp, nil); err != nil {
return err
} else if resp.Error != nil {
return resp.Error
}
return nil
}
func stringSliceContains(l []string, m string) bool { func stringSliceContains(l []string, m string) bool {
for _, i := range l { for _, i := range l {
if i == m { if i == m {
@ -222,6 +248,11 @@ type features struct {
StartTLS *tlsStartTLS `xml:"starttls"` StartTLS *tlsStartTLS `xml:"starttls"`
Mechanisms *mechanisms `xml:"mechanisms"` Mechanisms *mechanisms `xml:"mechanisms"`
Bind *bind `xml:"bind"` Bind *bind `xml:"bind"`
Session *session `xml:"session"`
}
type session struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-session session"`
} }
type bind struct { type bind struct {