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 ( const (
Version = "v0.1.0" Version = "v0.1.1"
configurationFilePath = "httpAuth.cfg" configurationFilePath = "httpAuth.cfg"
default_xmpp_server_address = "127.0.0.1" default_xmpp_server_address = "127.0.0.1"
default_xmpp_server_port = "5347" default_xmpp_server_port = "5347"
) )
var ( var (
@ -35,12 +35,12 @@ func init() {
// HTTP config // HTTP config
httpTimeout, err := strconv.Atoi(mapConfig["http_timeoute_sec"]) httpTimeout, err := strconv.Atoi(mapConfig["http_timeoute_sec"])
if err == nil { 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 http.TimeoutSec = httpTimeout
} }
httpPort, err := strconv.Atoi(mapConfig["http_port"]) httpPort, err := strconv.Atoi(mapConfig["http_port"])
if err == nil { if err == nil {
log.Println("Define HTTP port to "+strconv.Itoa(httpPort)) log.Println("Define HTTP port to " + strconv.Itoa(httpPort))
http.HttpPortBind = 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} 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} confirm := &xmpp.Confirm{Id: client.Transaction, Method: client.Method, URL: client.Domain}
m.PayloadEncode(confirm) m.PayloadEncode(confirm)
WaitMessageAnswers[stanzaIDstr] = client WaitIqMessages[stanzaIDstr] = client
comp.Out <- m comp.Out <- m
} }

View File

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