Make a different map for iq stanza + handle iq response without containing HTTP Auth namespace

This commit is contained in:
Chteufleur 2016-07-10 08:16:36 +02:00
parent 7ecfbfe63b
commit 6de5cee2ca
3 changed files with 18 additions and 10 deletions

View File

@ -15,11 +15,11 @@ import (
)
const (
Version = "v0.1.0"
Version = "v0.1.1"
configurationFilePath = "httpAuth.cfg"
default_xmpp_server_address = "127.0.0.1"
default_xmpp_server_port = "5347"
default_xmpp_server_port = "5347"
)
var (
@ -35,12 +35,12 @@ func init() {
// HTTP config
httpTimeout, err := strconv.Atoi(mapConfig["http_timeoute_sec"])
if err == nil {
log.Println("Define HTTP timeout to "+strconv.Itoa(httpTimeout)+" second")
log.Println("Define HTTP timeout to " + strconv.Itoa(httpTimeout) + " second")
http.TimeoutSec = httpTimeout
}
httpPort, err := strconv.Atoi(mapConfig["http_port"])
if err == nil {
log.Println("Define HTTP port to "+strconv.Itoa(httpPort))
log.Println("Define HTTP port to " + strconv.Itoa(httpPort))
http.HttpPortBind = httpPort
}

View File

@ -32,7 +32,7 @@ func (client *Client) askViaIQ() {
m := xmpp.Iq{Type: xmpp.IQTypeGet, To: client.JID, From: jid.Domain, Id: stanzaIDstr}
confirm := &xmpp.Confirm{Id: client.Transaction, Method: client.Method, URL: client.Domain}
m.PayloadEncode(confirm)
WaitMessageAnswers[stanzaIDstr] = client
WaitIqMessages[stanzaIDstr] = client
comp.Out <- m
}

View File

@ -28,6 +28,7 @@ var (
ChanAction = make(chan string)
WaitMessageAnswers = make(map[string]*Client)
WaitIqMessages = make(map[string]*Client)
Debug = true
)
@ -76,14 +77,21 @@ func mainXMPP() {
case xmpp.NSHTTPAuth:
confirm := &xmpp.Confirm{}
v.PayloadDecode(confirm)
client := WaitMessageAnswers[v.Id]
delete(WaitMessageAnswers, v.Id)
client := WaitIqMessages[v.Id]
delete(WaitIqMessages, v.Id)
processConfirm(v, client)
default:
reply := v.Response(xmpp.IQTypeError)
reply.PayloadEncode(xmpp.NewError("cancel", xmpp.FeatureNotImplemented, ""))
comp.Out <- reply
// Handle reply iq that doesn't contain HTTP-Auth namespace
client := WaitIqMessages[v.Id]
delete(WaitIqMessages, v.Id)
processConfirm(v, client)
if client == nil {
reply := v.Response(xmpp.IQTypeError)
reply.PayloadEncode(xmpp.NewError("cancel", xmpp.FeatureNotImplemented, ""))
comp.Out <- reply
}
}
default: