Auto generation for transaction ID if not provided in HTTP request

This commit is contained in:
Chteufleur 2016-07-16 09:44:54 +02:00
parent 2e3d328fdd
commit 36bbb829b5
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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)
}