Use google/uuid for message IDs.

It is used for go-xmpp in the sasl2 branch anyway.
sasl2
Martin Dosch 2 months ago
parent 3e57ec3603
commit a44554218d
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -8,6 +8,7 @@ require (
github.com/ProtonMail/gopenpgp/v2 v2.7.5
github.com/beevik/etree v1.3.0
github.com/gabriel-vasile/mimetype v1.4.3
github.com/google/uuid v1.6.0
github.com/pborman/getopt/v2 v2.1.0
github.com/xmppo/go-xmpp v0.1.5
salsa.debian.org/mdosch/xmppsrv v0.2.6
@ -17,7 +18,6 @@ require (
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect

@ -14,6 +14,8 @@ import (
"os"
"regexp"
"strings"
"github.com/google/uuid" // BSD-3-Clause
)
func validUTF8(s string) string {
@ -64,12 +66,7 @@ func getRpad(messageLength int) string {
}
func getID() string {
id := make([]byte, defaultIDBytes)
_, err := rand.Read(id)
if err != nil {
log.Fatal(err)
}
return fmt.Sprintf("%x-%x-%x", id[0:4], id[4:8], id[8:])
return uuid.NewString()
}
func getShortID() string {

@ -64,9 +64,6 @@ var DefaultConfig = &tls.Config{}
// DebugWriter is the writer used to write debugging output to.
var DebugWriter io.Writer = os.Stderr
// Cookie is a unique XMPP session identifier
type Cookie uint64
// Client holds XMPP connection options
type Client struct {
conn net.Conn // connection to server
@ -876,13 +873,13 @@ func (c *Client) init(o *Options) error {
if !bind2 {
// Generate a unique cookie
cookie := uuid.New()
cookie := uuid.NewString()
// Send IQ message asking to bind to the local user name.
if o.Resource == "" {
fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'></bind></iq>\n", cookie, nsBind)
fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%s'><bind xmlns='%s'></bind></iq>\n", cookie, nsBind)
} else {
fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'><resource>%s</resource></bind></iq>\n", cookie, nsBind, o.Resource)
fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%s'><bind xmlns='%s'><resource>%s</resource></bind></iq>\n", cookie, nsBind, o.Resource)
}
_, val, err = c.next()
if err != nil {
@ -908,8 +905,8 @@ func (c *Client) init(o *Options) error {
}
if o.Session {
// if server support session, open it
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)
cookie := uuid.NewString() // generate new id value for session
fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%s'><session xmlns='%s'/></iq>\n", xmlEscape(domain), cookie, nsSession)
}
// We're connected and can now receive and send messages.

Loading…
Cancel
Save