Add UUID4 func and use it instead of hard-coded <iq/> ids.
This commit is contained in:
parent
909d0f5fac
commit
20c380ebc6
|
|
@ -52,7 +52,7 @@ func main() {
|
|||
|
||||
// Get disco#info for home server.
|
||||
info := &DiscoInfo{}
|
||||
iq := xmpp.Iq{Id: "abc", Type: "get", To: x.JID.Domain}
|
||||
iq := xmpp.Iq{Id: xmpp.UUID4(), Type: "get", To: x.JID.Domain}
|
||||
iq.PayloadEncode(info)
|
||||
reply, _ := x.SendRecv(&iq)
|
||||
reply.PayloadDecode(info)
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ type saslAuth struct {
|
|||
|
||||
func bindResource(stream *Stream, jid JID) (JID, error) {
|
||||
|
||||
req := Iq{Id: "foo", Type: "set"}
|
||||
req := Iq{Id: UUID4(), Type: "set"}
|
||||
if jid.Resource == "" {
|
||||
req.PayloadEncode(bindIq{})
|
||||
} else {
|
||||
|
|
@ -245,5 +245,3 @@ type saslFailure struct {
|
|||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
|
||||
Reason xml.Name `xml:",any"`
|
||||
}
|
||||
|
||||
// BUG(matt): Don't use "foo" as the <iq/> id during resource binding.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package xmpp
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Generate a UUID4.
|
||||
func UUID4() string {
|
||||
uuid := make([]byte, 16)
|
||||
if _, err := rand.Read(uuid); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
uuid[6] = (uuid[6] & 0x0F) | 0x40
|
||||
uuid[8] = (uuid[8] &^ 0x40) | 0x80
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue