From 561fac842c091c1a9d37405afbd6973afe10569d Mon Sep 17 00:00:00 2001 From: James Canete Date: Thu, 3 Jul 2008 04:32:28 +0000 Subject: [PATCH] Add linux/unix version of SRV lookup. Add some extra debugging when SRV lookup fails. --- SConstruct | 2 ++ src/conn.c | 2 ++ src/sock.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 7e773e9..f1bdb45 100644 --- a/SConstruct +++ b/SConstruct @@ -102,6 +102,8 @@ exenv.Append(LIBS=["strophe", "expat"]) exenv.Append(LIBPATH=["."]) if exenv["PLATFORM"] == "win32": exenv.Append(LIBS=["ws2_32", "winmm"]) +if exenv["PLATFORM"] != "win32": + exenv.Append(LIBS=["resolv"]) for e in path("examples", Examples): example = exenv.Program(e) Default(example) diff --git a/src/conn.c b/src/conn.c index 3e0605c..e52cbe7 100644 --- a/src/conn.c +++ b/src/conn.c @@ -361,8 +361,10 @@ int xmpp_connect_client(xmpp_conn_t * const conn, if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport)) { + xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed."); if (altdomain) { + xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport); strcpy(connectdomain, altdomain); connectport = altport; } diff --git a/src/sock.c b/src/sock.c index a528e9e..f137ad3 100644 --- a/src/sock.c +++ b/src/sock.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #endif #include "sock.h" @@ -858,7 +860,48 @@ int sock_srv_lookup(const char *service, const char *proto, const char *domain, } -#else +#else + if (!set) + { + char buf[65535]; + int len; + + if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0) + { + int offset; + int i; + struct dnsquery_header header; + struct dnsquery_question question; + struct dnsquery_resourcerecord rr; + + offset = 0; + netbuf_get_dnsquery_header(buf, 65536, &offset, &header); + + for (i = 0; i < header.qdcount; i++) + { + netbuf_get_dnsquery_question(buf, 65536, &offset, &question); + } + + for (i = 0; i < header.ancount; i++) + { + netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); + + if (rr.type == 33) + { + struct dnsquery_srvrdata *srvrdata = &(rr.rdata); + + snprintf(resulttarget, resulttargetlength, srvrdata->target); + *resultport = srvrdata->port; + set = 1; + } + } + + for (i = 0; i < header.ancount; i++) + { + netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); + } + } + } #endif if (!set)