From 8569dfec15368986773e67d8c1598c0e02b39084 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 11 May 2023 19:56:16 +0200 Subject: Refactor with new setupConn() --- xmpp.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'xmpp.go') diff --git a/xmpp.go b/xmpp.go index 9e09700..d7c8790 100644 --- a/xmpp.go +++ b/xmpp.go @@ -16,18 +16,8 @@ const ( ) func (l *Limox) xmpp(jid string, pwd string) { - log.Printf("JID: '%s' PWD: '%s'\n", jid, pwd) - domain := domainpart(jid) - log.Printf("Domain: '%s'\n", domain) - - roots, err := x509.SystemCertPool() - if err != nil { - l.XmppEvents <- err - return - } - - conn, err := tls.Dial("tcp", domain+":"+"5223", &tls.Config{RootCAs: roots}) + conn, err := setupConn(jid) if err != nil { l.XmppEvents <- err return @@ -71,6 +61,17 @@ func (l *Limox) xmpp(jid string, pwd string) { l.XmppEvents <- XmppDisconnect } +func setupConn(jid string) (*tls.Conn, error) { + domain := domainpart(jid) + + roots, err := x509.SystemCertPool() + if err != nil { + return nil, err + } + + return tls.Dial("tcp", domain+":"+"5223", &tls.Config{RootCAs: roots}) +} + func rxRoutine(conn *tls.Conn, tokens chan xml.Token, terminator chan bool) { quit := false dec := xml.NewDecoder(conn) -- cgit v1.2.3-70-g09d2