Auto generation for transaction ID if not provided in HTTP request
This commit is contained in:
parent
2e3d328fdd
commit
36bbb829b5
5
main.go
5
main.go
|
|
@ -76,6 +76,11 @@ func request() {
|
|||
client.Domain = getChanString(http.ChanRequest)
|
||||
client.Transaction = getChanString(http.ChanRequest)
|
||||
|
||||
if client.Transaction == "" {
|
||||
// Random transaction ID generation
|
||||
client.Transaction = xmpp.SessionID()
|
||||
}
|
||||
|
||||
chanResult := <-http.ChanRequest
|
||||
if v, ok := chanResult.(chan bool); ok {
|
||||
client.ChanReply = v
|
||||
|
|
|
|||
|
|
@ -3,10 +3,15 @@ package xmpp
|
|||
import (
|
||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||
|
||||
"crypto/rand"
|
||||
"log"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
JID string
|
||||
Method string
|
||||
|
|
@ -49,3 +54,14 @@ func (client *Client) askViaMessage() {
|
|||
WaitMessageAnswers[client.Transaction] = client
|
||||
comp.Out <- m
|
||||
}
|
||||
|
||||
func SessionID() string {
|
||||
var bytes = make([]byte, 8)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for k, v := range bytes {
|
||||
bytes[k] = dictionary[v%byte(len(dictionary))]
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue