Blob Blame History Raw
diff -NaurEbBH gloox-1.0.orig/src/dns.cpp gloox-1.0/src/dns.cpp
--- gloox-1.0.orig/src/dns.cpp	2009-04-05 12:55:54.000000000 +0400
+++ gloox-1.0/src/dns.cpp	2009-04-07 13:08:48.000000000 +0400
@@ -40,6 +40,8 @@
 # include <unistd.h>
 #endif
 
+#include <errno.h>
+
 #ifdef _WIN32
 # include <winsock.h>
 #elif defined( _WIN32_WCE )
@@ -77,8 +79,151 @@
 
 namespace gloox
 {
-
 #if defined( HAVE_RES_QUERYDOMAIN ) && defined( HAVE_DN_SKIPNAME ) && defined( HAVE_RES_QUERY )
+
+#define      EMSGSIZE        40
+#define __set_errno(e) (errno = (e))
+/*
+ THIS IS TEMPORRARY UGLY HACK!
+
+Function ns_name_ntop marked as PRIVATE in recent versions of glibc
+ (See Changelog.13 2002-02-01  Jakub Jelinek  <jakub@redhat.com> in it).
+
+So, untill author do not fix gloox implementation I just copy this function (and reffered specail and printable plus digits variable)
+ from glibc 2.8-8 (resolv/ns_name.c) source and add prefix in name _TMP_
+*/
+
+static const char	digits[] = "0123456789";
+
+/*
+ * special(ch)
+ *	Thinking in noninternationalized USASCII (per the DNS spec),
+ *	is this characted special ("in need of quoting") ?
+ * return:
+ *	boolean.
+ */
+static int
+special(int ch) {
+	switch (ch) {
+	case 0x22: /* '"' */
+	case 0x2E: /* '.' */
+	case 0x3B: /* ';' */
+	case 0x5C: /* '\\' */
+	/* Special modifiers in zone files. */
+	case 0x40: /* '@' */
+	case 0x24: /* '$' */
+		return (1);
+	default:
+		return (0);
+	}
+}
+
+/*
+ * printable(ch)
+ *	Thinking in noninternationalized USASCII (per the DNS spec),
+ *	is this character visible and not a space when printed ?
+ * return:
+ *	boolean.
+ */
+static int
+printable(int ch) {
+	return (ch > 0x20 && ch < 0x7f);
+}
+
+int
+_TMP_ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
+	const u_char *cp;
+	char *dn, *eom;
+	u_char c;
+	u_int n;
+
+	cp = src;
+	dn = dst;
+	eom = dst + dstsiz;
+
+	while ((n = *cp++) != 0) {
+		if ((n & NS_CMPRSFLGS) != 0 && n != 0x41) {
+			/* Some kind of compression pointer. */
+			__set_errno (EMSGSIZE);
+			return (-1);
+		}
+		if (dn != dst) {
+			if (dn >= eom) {
+				__set_errno (EMSGSIZE);
+				return (-1);
+			}
+			*dn++ = '.';
+		}
+
+		if (n == 0x41) {
+			n = *cp++ / 8;
+			if (dn + n * 2 + 4 >= eom) {
+				__set_errno (EMSGSIZE);
+				return (-1);
+			}
+			*dn++ = '\\';
+			*dn++ = '[';
+			*dn++ = 'x';
+
+			while (n-- > 0) {
+				c = *cp++;
+				unsigned u = c >> 4;
+				*dn++ = u > 9 ? 'a' + u - 10 : '0' + u;
+				u = c & 0xf;
+				*dn++ = u > 9 ? 'a' + u - 10 : '0' + u;
+			}
+
+			*dn++ = ']';
+			continue;
+		}
+
+		if (dn + n >= eom) {
+			__set_errno (EMSGSIZE);
+			return (-1);
+		}
+		for ((void)NULL; n > 0; n--) {
+			c = *cp++;
+			if (special(c)) {
+				if (dn + 1 >= eom) {
+					__set_errno (EMSGSIZE);
+					return (-1);
+				}
+				*dn++ = '\\';
+				*dn++ = (char)c;
+			} else if (!printable(c)) {
+				if (dn + 3 >= eom) {
+					__set_errno (EMSGSIZE);
+					return (-1);
+				}
+				*dn++ = '\\';
+				*dn++ = digits[c / 100];
+				*dn++ = digits[(c % 100) / 10];
+				*dn++ = digits[c % 10];
+			} else {
+				if (dn >= eom) {
+					__set_errno (EMSGSIZE);
+					return (-1);
+				}
+				*dn++ = (char)c;
+			}
+		}
+	}
+	if (dn == dst) {
+		if (dn >= eom) {
+			__set_errno (EMSGSIZE);
+			return (-1);
+		}
+		*dn++ = '.';
+	}
+	if (dn >= eom) {
+		__set_errno (EMSGSIZE);
+		return (-1);
+	}
+	*dn++ = '\0';
+	return (dn - dst);
+}
+
+
   DNS::HostMap DNS::resolve( const std::string& service, const std::string& proto,
                              const std::string& domain, const LogSink& logInstance )
   {
@@ -141,7 +286,7 @@
     {
       name srvname;
 
-      if( ns_name_ntop( srv[cnt] + SRV_SERVER, (char*)srvname, NS_MAXDNAME ) < 0 )
+      if( _TMP_ns_name_ntop( srv[cnt] + SRV_SERVER, (char*)srvname, NS_MAXDNAME ) < 0 )
       {
         //FIXME do we need to handle this? How? Can it actually happen at all?
 //         printf( "handle this error!\n" );