Make full implementation Iq stanza
This commit is contained in:
parent
0a737a4f01
commit
950dfc43dc
|
|
@ -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=false
|
xmpp_debug=true
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
"git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp"
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
|
@ -18,11 +19,22 @@ type Client struct {
|
||||||
|
|
||||||
func (client *Client) QueryClient() {
|
func (client *Client) QueryClient() {
|
||||||
log.Printf("%sQuery JID %s", LogInfo, client.JID)
|
log.Printf("%sQuery JID %s", LogInfo, client.JID)
|
||||||
client.askViaMessage()
|
clientJID, _ := xmpp.ParseJID(client.JID)
|
||||||
|
if clientJID.Resource == "" {
|
||||||
|
client.askViaMessage()
|
||||||
|
} else {
|
||||||
|
client.askViaIQ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) askViaIQ() {
|
func (client *Client) askViaIQ() {
|
||||||
|
stanzaID++
|
||||||
|
stanzaIDstr := strconv.Itoa(stanzaID)
|
||||||
|
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
|
||||||
|
comp.Out <- m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) askViaMessage() {
|
func (client *Client) askViaMessage() {
|
||||||
|
|
@ -30,10 +42,9 @@ 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}
|
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
|
|
||||||
|
|
||||||
WaitMessageAnswers[client.Transaction] = client
|
WaitMessageAnswers[client.Transaction] = client
|
||||||
|
comp.Out <- m
|
||||||
}
|
}
|
||||||
|
|
|
||||||
51
xmpp/xmpp.go
51
xmpp/xmpp.go
|
|
@ -19,6 +19,8 @@ var (
|
||||||
|
|
||||||
SoftVersion = ""
|
SoftVersion = ""
|
||||||
|
|
||||||
|
stanzaID = 0
|
||||||
|
|
||||||
jid xmpp.JID
|
jid xmpp.JID
|
||||||
stream = new(xmpp.Stream)
|
stream = new(xmpp.Stream)
|
||||||
comp = new(xmpp.XMPP)
|
comp = new(xmpp.XMPP)
|
||||||
|
|
@ -26,7 +28,6 @@ var (
|
||||||
ChanAction = make(chan string)
|
ChanAction = make(chan string)
|
||||||
|
|
||||||
WaitMessageAnswers = make(map[string]*Client)
|
WaitMessageAnswers = make(map[string]*Client)
|
||||||
waitIQAnswers = make(map[string]*Client)
|
|
||||||
|
|
||||||
Debug = true
|
Debug = true
|
||||||
)
|
)
|
||||||
|
|
@ -51,14 +52,11 @@ func mainXMPP() {
|
||||||
case *xmpp.Presence:
|
case *xmpp.Presence:
|
||||||
|
|
||||||
case *xmpp.Message:
|
case *xmpp.Message:
|
||||||
client := WaitMessageAnswers[v.Confir.ID]
|
confirm := v.Confir
|
||||||
if client != nil {
|
if confirm != nil {
|
||||||
if v.Error != nil {
|
client := WaitMessageAnswers[confirm.Id]
|
||||||
client.ChanReply <- false
|
delete(WaitMessageAnswers, confirm.Id)
|
||||||
} else {
|
processConfirm(v, client)
|
||||||
client.ChanReply <- true
|
|
||||||
}
|
|
||||||
delete(WaitMessageAnswers, v.Confir.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case *xmpp.Iq:
|
case *xmpp.Iq:
|
||||||
|
|
@ -77,6 +75,13 @@ func mainXMPP() {
|
||||||
reply.PayloadEncode(&xmpp.SoftwareVersion{Name: "HTTP authentification component", Version: SoftVersion})
|
reply.PayloadEncode(&xmpp.SoftwareVersion{Name: "HTTP authentification component", Version: SoftVersion})
|
||||||
comp.Out <- reply
|
comp.Out <- reply
|
||||||
|
|
||||||
|
case xmpp.NSHTTPAuth:
|
||||||
|
confirm := &xmpp.Confirm{}
|
||||||
|
v.PayloadDecode(confirm)
|
||||||
|
client := WaitMessageAnswers[v.Id]
|
||||||
|
delete(WaitMessageAnswers, v.Id)
|
||||||
|
processConfirm(v, client)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reply := v.Response(xmpp.IQTypeError)
|
reply := v.Response(xmpp.IQTypeError)
|
||||||
reply.PayloadEncode(xmpp.NewError("cancel", xmpp.FeatureNotImplemented, ""))
|
reply.PayloadEncode(xmpp.NewError("cancel", xmpp.FeatureNotImplemented, ""))
|
||||||
|
|
@ -89,6 +94,21 @@ func mainXMPP() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processConfirm(x interface{}, client *Client) {
|
||||||
|
mes, mesOK := x.(*xmpp.Message)
|
||||||
|
iq, iqOK := x.(*xmpp.Iq)
|
||||||
|
|
||||||
|
if client != nil {
|
||||||
|
if mesOK && mes.Error != nil {
|
||||||
|
client.ChanReply <- false
|
||||||
|
} else if iqOK && iq.Error != nil {
|
||||||
|
client.ChanReply <- false
|
||||||
|
} else {
|
||||||
|
client.ChanReply <- true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func must(v interface{}, err error) interface{} {
|
func must(v interface{}, err error) interface{} {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(LogError, err)
|
log.Fatal(LogError, err)
|
||||||
|
|
@ -96,19 +116,6 @@ func must(v interface{}, err error) interface{} {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func SendMessage(to, subject, message string) {
|
|
||||||
m := xmpp.Message{From: jid.Domain, To: to, Body: message, Type: "chat"}
|
|
||||||
|
|
||||||
if subject != "" {
|
|
||||||
m.Subject = subject
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("%sSenp message %v", LogInfo, m)
|
|
||||||
comp.Out <- m
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func execDiscoCommand(iq *xmpp.Iq) {
|
func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
log.Printf("%sDiscovery item iq received", LogInfo)
|
log.Printf("%sDiscovery item iq received", LogInfo)
|
||||||
reply := iq.Response(xmpp.IQTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue