|
|
|
@ -7,6 +7,7 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/xmppo/go-xmpp" // BSD-3-Clause
|
|
|
|
@ -14,27 +15,31 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func connect(options xmpp.Options, directTLS bool) (*xmpp.Client, error) {
|
|
|
|
|
proxy := os.Getenv("HTTP_PROXY")
|
|
|
|
|
// Look up SRV records if server is not specified manually.
|
|
|
|
|
if options.Host == "" {
|
|
|
|
|
server := options.User[strings.Index(options.User, "@")+1:]
|
|
|
|
|
// Look up xmpp-client SRV records.
|
|
|
|
|
srvMixed, err := xmppsrv.LookupClient(server)
|
|
|
|
|
if len(srvMixed) > 0 && err == nil {
|
|
|
|
|
for _, adr := range srvMixed {
|
|
|
|
|
if !directTLS && adr.Type != "xmpps-client" {
|
|
|
|
|
// Use StartTLS
|
|
|
|
|
options.NoTLS = true
|
|
|
|
|
options.StartTLS = true
|
|
|
|
|
} else if adr.Type == "xmpps-client" {
|
|
|
|
|
// Use direct TLS
|
|
|
|
|
options.NoTLS = false
|
|
|
|
|
options.StartTLS = false
|
|
|
|
|
}
|
|
|
|
|
options.Host = net.JoinHostPort(adr.Target, fmt.Sprint(adr.Port))
|
|
|
|
|
// Connect to server
|
|
|
|
|
client, err := options.NewClient()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return client, nil
|
|
|
|
|
// Don't do SRV look ups if proxy is set.
|
|
|
|
|
if proxy == "" {
|
|
|
|
|
// Look up xmpp-client SRV records.
|
|
|
|
|
srvMixed, err := xmppsrv.LookupClient(server)
|
|
|
|
|
if len(srvMixed) > 0 && err == nil {
|
|
|
|
|
for _, adr := range srvMixed {
|
|
|
|
|
if !directTLS && adr.Type != "xmpps-client" {
|
|
|
|
|
// Use StartTLS
|
|
|
|
|
options.NoTLS = true
|
|
|
|
|
options.StartTLS = true
|
|
|
|
|
} else if adr.Type == "xmpps-client" {
|
|
|
|
|
// Use direct TLS
|
|
|
|
|
options.NoTLS = false
|
|
|
|
|
options.StartTLS = false
|
|
|
|
|
}
|
|
|
|
|
options.Host = net.JoinHostPort(adr.Target, fmt.Sprint(adr.Port))
|
|
|
|
|
// Connect to server
|
|
|
|
|
client, err := options.NewClient()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return client, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|