diff options
author | xengineering <me@xengineering.eu> | 2023-05-11 19:56:16 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-11 19:56:16 +0200 |
commit | 8569dfec15368986773e67d8c1598c0e02b39084 (patch) | |
tree | 81b79e55a4d0aea5489608bc0a95416d57dc2a40 /xmpp.go | |
parent | 6ec791ba0fffb2a0c8e0e603f4f5f0cc2b6f5e18 (diff) | |
download | limox-8569dfec15368986773e67d8c1598c0e02b39084.tar limox-8569dfec15368986773e67d8c1598c0e02b39084.tar.zst limox-8569dfec15368986773e67d8c1598c0e02b39084.zip |
Refactor with new setupConn()
Diffstat (limited to 'xmpp.go')
-rw-r--r-- | xmpp.go | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -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) |