Add the possibility to connect as a client
This commit is contained in:
parent
20dc1ee9e8
commit
c88ec7a32d
|
|
@ -1,10 +1,15 @@
|
||||||
# XMPP informations
|
# XMPP informations (component)
|
||||||
xmpp_server_address=192.168.1.2
|
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=true
|
||||||
|
|
||||||
|
# XMPP informations (client)
|
||||||
|
#xmpp_hostname=toto@jabber.fr
|
||||||
|
#xmpp_secret=totoPwd
|
||||||
|
#xmpp_debug=true
|
||||||
|
|
||||||
# HTTP informations
|
# HTTP informations
|
||||||
http_port=9090
|
http_port=9090
|
||||||
https_port=9093
|
https_port=9093
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -17,9 +17,6 @@ import (
|
||||||
const (
|
const (
|
||||||
Version = "v0.3.1"
|
Version = "v0.3.1"
|
||||||
configurationFilePath = "httpAuth.cfg"
|
configurationFilePath = "httpAuth.cfg"
|
||||||
|
|
||||||
default_xmpp_server_address = "127.0.0.1"
|
|
||||||
default_xmpp_server_port = "5347"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -55,15 +52,14 @@ func init() {
|
||||||
|
|
||||||
// XMPP config
|
// XMPP config
|
||||||
xmpp_server_address := mapConfig["xmpp_server_address"]
|
xmpp_server_address := mapConfig["xmpp_server_address"]
|
||||||
if xmpp_server_address == "" {
|
if xmpp_server_address != "" {
|
||||||
xmpp_server_address = default_xmpp_server_address
|
xmpp.Addr = xmpp_server_address
|
||||||
}
|
}
|
||||||
xmpp_server_port := mapConfig["xmpp_server_port"]
|
xmpp_server_port := mapConfig["xmpp_server_port"]
|
||||||
if xmpp_server_port == "" {
|
if xmpp_server_port != "" {
|
||||||
xmpp_server_port = default_xmpp_server_port
|
xmpp.Port = xmpp_server_port
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp.Addr = xmpp_server_address + ":" + xmpp_server_port
|
|
||||||
xmpp.JidStr = mapConfig["xmpp_hostname"]
|
xmpp.JidStr = mapConfig["xmpp_hostname"]
|
||||||
xmpp.Secret = mapConfig["xmpp_secret"]
|
xmpp.Secret = mapConfig["xmpp_secret"]
|
||||||
xmpp.Debug = mapConfig["xmpp_debug"] == "true"
|
xmpp.Debug = mapConfig["xmpp_debug"] == "true"
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@ type Confirmation struct {
|
||||||
ChanReply chan string
|
ChanReply chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
type Transport interface {
|
|
||||||
Run()
|
|
||||||
Out(chan interface{})
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (confirmation *Confirmation) SendConfirmation() {
|
func (confirmation *Confirmation) SendConfirmation() {
|
||||||
log.Printf("%sQuery JID %s", LogInfo, confirmation.JID)
|
log.Printf("%sQuery JID %s", LogInfo, confirmation.JID)
|
||||||
isAutoGeneratedTranctionID := false
|
isAutoGeneratedTranctionID := false
|
||||||
|
|
|
||||||
34
xmpp/xmpp.go
34
xmpp/xmpp.go
|
|
@ -8,13 +8,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LogInfo = "\t[XMPP COMPONENT INFO]\t"
|
LogInfo = "\t[XMPP INFO]\t"
|
||||||
LogError = "\t[XMPP COMPONENT ERROR]\t"
|
LogError = "\t[XMPP ERROR]\t"
|
||||||
LogDebug = "\t[XMPP COMPONENT DEBUG]\t"
|
LogDebug = "\t[XMPP DEBUG]\t"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Addr = "127.0.0.1:5347"
|
Addr = "127.0.0.1"
|
||||||
|
Port = "5347"
|
||||||
JidStr = ""
|
JidStr = ""
|
||||||
Secret = ""
|
Secret = ""
|
||||||
|
|
||||||
|
|
@ -35,11 +36,32 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
var addr string
|
||||||
|
var isComponent bool
|
||||||
|
|
||||||
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.
|
||||||
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
||||||
stream = must(xmpp.NewStream(Addr, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
isComponent = jid.Node == ""
|
||||||
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
|
|
||||||
|
if isComponent {
|
||||||
|
// component
|
||||||
|
addr = Addr + ":" + Port
|
||||||
|
} else {
|
||||||
|
// client
|
||||||
|
addrs := must(xmpp.HomeServerAddrs(jid)).([]string)
|
||||||
|
addr = addrs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%sConnecting to %s", LogInfo, addr)
|
||||||
|
stream = must(xmpp.NewStream(addr, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
||||||
|
|
||||||
|
if isComponent {
|
||||||
|
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
|
||||||
|
} else {
|
||||||
|
comp = must(xmpp.NewClientXMPP(stream, jid, Secret, &xmpp.ClientConfig{InsecureSkipVerify: false})).(*xmpp.XMPP)
|
||||||
|
comp.Out <- xmpp.Presence{}
|
||||||
|
}
|
||||||
|
|
||||||
mainXMPP()
|
mainXMPP()
|
||||||
log.Printf("%sReach main method's end", LogInfo)
|
log.Printf("%sReach main method's end", LogInfo)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue