|
|
|
@ -23,7 +23,6 @@ import (
|
|
|
|
|
"crypto/tls"
|
|
|
|
|
"crypto/x509"
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"encoding/xml"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
@ -68,14 +67,6 @@ var DebugWriter io.Writer = os.Stderr
|
|
|
|
|
// Cookie is a unique XMPP session identifier
|
|
|
|
|
type Cookie uint64
|
|
|
|
|
|
|
|
|
|
func getCookie() Cookie {
|
|
|
|
|
var buf [8]byte
|
|
|
|
|
if _, err := rand.Reader.Read(buf[:]); err != nil {
|
|
|
|
|
panic("Failed to read random bytes: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
return Cookie(binary.LittleEndian.Uint64(buf[:]))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Client holds XMPP connection options
|
|
|
|
|
type Client struct {
|
|
|
|
|
conn net.Conn // connection to server
|
|
|
|
@ -584,7 +575,7 @@ func (c *Client) init(o *Options) error {
|
|
|
|
|
if o.Resource != "" {
|
|
|
|
|
resource = o.Resource
|
|
|
|
|
} else {
|
|
|
|
|
resource = fmt.Sprint(getCookie())
|
|
|
|
|
resource = uuid.NewString()
|
|
|
|
|
}
|
|
|
|
|
bind2Data = fmt.Sprintf("<bind xmlns='%s'><tag>%s</tag></bind>",
|
|
|
|
|
nsBind2, resource)
|
|
|
|
@ -885,7 +876,7 @@ func (c *Client) init(o *Options) error {
|
|
|
|
|
|
|
|
|
|
if !bind2 {
|
|
|
|
|
// Generate a unique cookie
|
|
|
|
|
cookie := getCookie()
|
|
|
|
|
cookie := uuid.New()
|
|
|
|
|
|
|
|
|
|
// Send IQ message asking to bind to the local user name.
|
|
|
|
|
if o.Resource == "" {
|
|
|
|
@ -917,7 +908,7 @@ func (c *Client) init(o *Options) error {
|
|
|
|
|
}
|
|
|
|
|
if o.Session {
|
|
|
|
|
// if server support session, open it
|
|
|
|
|
cookie := getCookie() // generate new id value for session
|
|
|
|
|
cookie := uuid.New() // generate new id value for session
|
|
|
|
|
fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>\n", xmlEscape(domain), cookie, nsSession)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|