Make a complet ask with message stanza
This commit is contained in:
parent
77752651e1
commit
0a737a4f01
|
|
@ -1,6 +1,8 @@
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kingpenguin.tk/chteufleur/HTTPAuthentificationOverXMPP.git/xmpp"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -61,6 +63,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
case answer = <- chanAnswer:
|
case answer = <- chanAnswer:
|
||||||
case <- time.After(time.Duration(TimeoutSec) * time.Second):
|
case <- time.After(time.Duration(TimeoutSec) * time.Second):
|
||||||
answer = false
|
answer = false
|
||||||
|
delete(xmpp.WaitMessageAnswers, transaction)
|
||||||
}
|
}
|
||||||
if answer {
|
if answer {
|
||||||
ret = RETURN_VALUE_OK
|
ret = RETURN_VALUE_OK
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,4 @@ xmpp_server_address=192.168.1.2
|
||||||
xmpp_server_port=5347
|
xmpp_server_port=5347
|
||||||
xmpp_hostname=xmppsteam.kingpenguin.tk
|
xmpp_hostname=xmppsteam.kingpenguin.tk
|
||||||
xmpp_secret=xmpp4steam_password
|
xmpp_secret=xmpp4steam_password
|
||||||
xmpp_debug=true
|
xmpp_debug=false
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,10 @@ func (client *Client) askViaMessage() {
|
||||||
|
|
||||||
m.Thread = xmpp.SessionID()
|
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.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)
|
log.Printf("%sSenp message %v", LogInfo, m)
|
||||||
comp.Out <- m
|
comp.Out <- m
|
||||||
|
|
||||||
waitMessageAnswers[m.Thread] = client
|
WaitMessageAnswers[client.Transaction] = client
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
xmpp/xmpp.go
18
xmpp/xmpp.go
|
|
@ -25,13 +25,14 @@ var (
|
||||||
|
|
||||||
ChanAction = make(chan string)
|
ChanAction = make(chan string)
|
||||||
|
|
||||||
waitMessageAnswers = make(map[string]*Client)
|
WaitMessageAnswers = make(map[string]*Client)
|
||||||
waitIQAnswers = make(map[string]*Client)
|
waitIQAnswers = make(map[string]*Client)
|
||||||
|
|
||||||
Debug = true
|
Debug = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
log.Printf("%sRunning", LogInfo)
|
log.Printf("%sRunning", LogInfo)
|
||||||
// Create stream and configure it as a component connection.
|
// Create stream and configure it as a component connection.
|
||||||
|
|
@ -50,12 +51,15 @@ func mainXMPP() {
|
||||||
case *xmpp.Presence:
|
case *xmpp.Presence:
|
||||||
|
|
||||||
case *xmpp.Message:
|
case *xmpp.Message:
|
||||||
client := waitMessageAnswers[v.Thread]
|
client := WaitMessageAnswers[v.Confir.ID]
|
||||||
if client != nil {
|
if client != nil {
|
||||||
// TODO chek the answer
|
if v.Error != nil {
|
||||||
client.ChanReply <- true
|
client.ChanReply <- false
|
||||||
}
|
} else {
|
||||||
delete(waitMessageAnswers, v.Thread)
|
client.ChanReply <- true
|
||||||
|
}
|
||||||
|
delete(WaitMessageAnswers, v.Confir.ID)
|
||||||
|
}
|
||||||
|
|
||||||
case *xmpp.Iq:
|
case *xmpp.Iq:
|
||||||
switch v.PayloadName().Space {
|
switch v.PayloadName().Space {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue