Fix issue with SRV lookup for xmpps-client.

This commit is contained in:
Martin Dosch 2021-01-21 11:31:16 +01:00
parent 6c3fe6246a
commit e4e33cdf75

View File

@ -288,28 +288,28 @@ func main() {
server = *flagServer
}
// Lookup SRV record for xmpps-client if direct TLS is requested and the server is not
// specified.
if *flagTLS {
if _, addrs, err := net.LookupSRV("xmpps-client", "tcp", server); err == nil {
// Determine server part if no server is specified.
if server == "" {
server = strings.Split(user, "@")[1]
if len(addrs) > 0 {
// Default to first record
server = fmt.Sprintf("%s:%d", addrs[0].Target, addrs[0].Port)
defP := addrs[0].Priority
for _, adr := range addrs {
if adr.Priority < defP {
server = fmt.Sprintf("%s:%d", adr.Target, adr.Port)
defP = adr.Priority
// Lookup SRV record for xmpps-client if direct TLS is requested
if *flagTLS {
if _, addrs, err := net.LookupSRV("xmpps-client", "tcp", server); err == nil {
if len(addrs) > 0 {
// Default to first record
server = fmt.Sprintf("%s:%d", addrs[0].Target, addrs[0].Port)
defP := addrs[0].Priority
for _, adr := range addrs {
if adr.Priority < defP {
server = fmt.Sprintf("%s:%d", adr.Target, adr.Port)
defP = adr.Priority
}
}
}
}
}
}
// Use the JIDs server part if no server is specified.
if server == "" {
server = strings.Split(user, "@")[1]
}
// Overwrite password if specified via command line flag.