Add the possibility to connect as a client

This commit is contained in:
Chteufleur 2016-07-23 12:03:21 +02:00
parent 20dc1ee9e8
commit c88ec7a32d
4 changed files with 38 additions and 22 deletions

View File

@ -1,10 +1,15 @@
# XMPP informations
# XMPP informations (component)
xmpp_server_address=192.168.1.2
xmpp_server_port=5347
xmpp_hostname=xmppsteam.kingpenguin.tk
xmpp_secret=xmpp4steam_password
xmpp_debug=true
# XMPP informations (client)
#xmpp_hostname=toto@jabber.fr
#xmpp_secret=totoPwd
#xmpp_debug=true
# HTTP informations
http_port=9090
https_port=9093

12
main.go
View File

@ -17,9 +17,6 @@ import (
const (
Version = "v0.3.1"
configurationFilePath = "httpAuth.cfg"
default_xmpp_server_address = "127.0.0.1"
default_xmpp_server_port = "5347"
)
var (
@ -55,15 +52,14 @@ func init() {
// XMPP config
xmpp_server_address := mapConfig["xmpp_server_address"]
if xmpp_server_address == "" {
xmpp_server_address = default_xmpp_server_address
if xmpp_server_address != "" {
xmpp.Addr = xmpp_server_address
}
xmpp_server_port := mapConfig["xmpp_server_port"]
if xmpp_server_port == "" {
xmpp_server_port = default_xmpp_server_port
if xmpp_server_port != "" {
xmpp.Port = xmpp_server_port
}
xmpp.Addr = xmpp_server_address + ":" + xmpp_server_port
xmpp.JidStr = mapConfig["xmpp_hostname"]
xmpp.Secret = mapConfig["xmpp_secret"]
xmpp.Debug = mapConfig["xmpp_debug"] == "true"

View File

@ -31,13 +31,6 @@ type Confirmation struct {
ChanReply chan string
}
/*
type Transport interface {
Run()
Out(chan interface{})
}
*/
func (confirmation *Confirmation) SendConfirmation() {
log.Printf("%sQuery JID %s", LogInfo, confirmation.JID)
isAutoGeneratedTranctionID := false

View File

@ -8,13 +8,14 @@ import (
)
const (
LogInfo = "\t[XMPP COMPONENT INFO]\t"
LogError = "\t[XMPP COMPONENT ERROR]\t"
LogDebug = "\t[XMPP COMPONENT DEBUG]\t"
LogInfo = "\t[XMPP INFO]\t"
LogError = "\t[XMPP ERROR]\t"
LogDebug = "\t[XMPP DEBUG]\t"
)
var (
Addr = "127.0.0.1:5347"
Addr = "127.0.0.1"
Port = "5347"
JidStr = ""
Secret = ""
@ -35,11 +36,32 @@ var (
)
func Run() {
var addr string
var isComponent bool
log.Printf("%sRunning", LogInfo)
// Create stream and configure it as a component connection.
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
stream = must(xmpp.NewStream(Addr, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
comp = must(xmpp.NewComponentXMPP(stream, jid, Secret)).(*xmpp.XMPP)
isComponent = jid.Node == ""
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()
log.Printf("%sReach main method's end", LogInfo)