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.Domain = getChanString(http.ChanRequest)
|
||||||
client.Transaction = getChanString(http.ChanRequest)
|
client.Transaction = getChanString(http.ChanRequest)
|
||||||
|
|
||||||
|
if client.Transaction == "" {
|
||||||
|
// Random transaction ID generation
|
||||||
|
client.Transaction = xmpp.SessionID()
|
||||||
|
}
|
||||||
|
|
||||||
chanResult := <-http.ChanRequest
|
chanResult := <-http.ChanRequest
|
||||||
if v, ok := chanResult.(chan bool); ok {
|
if v, ok := chanResult.(chan bool); ok {
|
||||||
client.ChanReply = v
|
client.ChanReply = v
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,15 @@ package xmpp
|
||||||
import (
|
import (
|
||||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||||
|
|
||||||
|
"crypto/rand"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||||
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
JID string
|
JID string
|
||||||
Method string
|
Method string
|
||||||
|
|
@ -49,3 +54,14 @@ func (client *Client) askViaMessage() {
|
||||||
WaitMessageAnswers[client.Transaction] = client
|
WaitMessageAnswers[client.Transaction] = client
|
||||||
comp.Out <- m
|
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