diff --git a/http/http.go b/http/http.go index d40572e..251d990 100644 --- a/http/http.go +++ b/http/http.go @@ -1,6 +1,8 @@ package http import ( + "git.kingpenguin.tk/chteufleur/HTTPAuthentificationOverXMPP.git/xmpp" + "fmt" "log" "net/http" @@ -61,6 +63,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) { case answer = <- chanAnswer: case <- time.After(time.Duration(TimeoutSec) * time.Second): answer = false + delete(xmpp.WaitMessageAnswers, transaction) } if answer { ret = RETURN_VALUE_OK diff --git a/httpAuth.cfg b/httpAuth.cfg index 72ffb10..fc21647 100644 --- a/httpAuth.cfg +++ b/httpAuth.cfg @@ -3,4 +3,4 @@ xmpp_server_address=192.168.1.2 xmpp_server_port=5347 xmpp_hostname=xmppsteam.kingpenguin.tk xmpp_secret=xmpp4steam_password -xmpp_debug=true +xmpp_debug=false diff --git a/xmpp/client.go b/xmpp/client.go index ab22ac7..61bd1a8 100644 --- a/xmpp/client.go +++ b/xmpp/client.go @@ -30,9 +30,10 @@ func (client *Client) askViaMessage() { m.Thread = xmpp.SessionID() m.Body = "Auth request for "+client.Domain+".\nTransaction identifier is: "+client.Transaction+"\nReply to this message to confirm the request." + m.Confir = &xmpp.Confirm{ID: client.Transaction, Method: client.Method, URL: client.Domain} log.Printf("%sSenp message %v", LogInfo, m) comp.Out <- m - waitMessageAnswers[m.Thread] = client + WaitMessageAnswers[client.Transaction] = client } diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 80c60fd..d0f3c80 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -25,13 +25,14 @@ var ( ChanAction = make(chan string) - waitMessageAnswers = make(map[string]*Client) + WaitMessageAnswers = make(map[string]*Client) waitIQAnswers = make(map[string]*Client) Debug = true ) + func Run() { log.Printf("%sRunning", LogInfo) // Create stream and configure it as a component connection. @@ -50,12 +51,15 @@ func mainXMPP() { case *xmpp.Presence: case *xmpp.Message: - client := waitMessageAnswers[v.Thread] - if client != nil { - // TODO chek the answer - client.ChanReply <- true - } - delete(waitMessageAnswers, v.Thread) + client := WaitMessageAnswers[v.Confir.ID] + if client != nil { + if v.Error != nil { + client.ChanReply <- false + } else { + client.ChanReply <- true + } + delete(WaitMessageAnswers, v.Confir.ID) + } case *xmpp.Iq: switch v.PayloadName().Space {