changeset 23203:313b87adb730

A patch from Peter O'Gorman at The Written Word, Inc. to fix various portability issues. These changes seemed reasonable, even though I wasn't able to test or verify them all in particular. Hopefully we don't break anything on another OS. Refs #3798 committer: Richard Laager <rlaager@wiktel.com>
author Peter O'Gorman <pogma@thewrittenword.com>
date Tue, 27 May 2008 01:11:46 +0000
parents 5197256f66b5
children 1e87376e77f2
files COPYRIGHT configure.ac libpurple/dnsquery.c libpurple/dnssrv.c libpurple/internal.h libpurple/nat-pmp.c libpurple/network.c libpurple/protocols/zephyr/Makefile.am libpurple/protocols/zephyr/zephyr.c libpurple/proxy.c
diffstat 10 files changed, 60 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Mon May 26 17:10:55 2008 +0000
+++ b/COPYRIGHT	Tue May 27 01:11:46 2008 +0000
@@ -278,6 +278,7 @@
 Novell
 Padraig O'Briain
 Christopher O'Brien (siege)
+Peter O'Gorman
 Jon Oberheide
 Yusuke Odate
 Ruediger Oertel
@@ -449,6 +450,7 @@
 Matt Wilson
 Dan Winship
 Scott Wolchok
+The Written Word, Inc.
 Kevin Wu Won
 Pui Lam Wong
 Justin Wood
--- a/configure.ac	Mon May 26 17:10:55 2008 +0000
+++ b/configure.ac	Tue May 27 01:11:46 2008 +0000
@@ -108,13 +108,14 @@
 
 dnl Checks for programs.
 AC_PROG_CC
+AM_PROG_CC_C_O
 AC_DISABLE_STATIC
-AM_PROG_LIBTOOL
+AC_PROG_LIBTOOL
 LIBTOOL="$LIBTOOL --silent"
 AC_PROG_INSTALL
 AC_PROG_INTLTOOL
 PKG_PROG_PKG_CONFIG
-
+AC_FUNC_ALLOCA
 GETTEXT_PACKAGE=pidgin
 AC_SUBST(GETTEXT_PACKAGE)
 
@@ -210,7 +211,7 @@
 		[Define to 1 if you have the getaddrinfo function.])],
 	[AC_CHECK_LIB(socket, getaddrinfo,
 		[AC_DEFINE([HAVE_GETADDRINFO]) LIBS="-lsocket -lsnl $LIBS"], , , -lnsl)])
-
+AC_CHECK_FUNCS(inet_ntop)
 dnl Check for socklen_t (in Unix98)
 AC_MSG_CHECKING(for socklen_t)
 AC_TRY_COMPILE([
@@ -234,6 +235,12 @@
 	])
 ])
 
+dnl Some systems do not have sa_len field for struct sockaddr.
+AC_CHECK_MEMBER([struct sockaddr.sa_len],
+	[AC_DEFINE([HAVE_STRUCT_SOCKADDR_SA_LEN],[1],
+	[Define if struct sockaddr has an sa_len member])],[:],
+	[#include <sys/socket.h>])
+
 dnl to prevent the g_stat()/g_unlink() crash,
 dnl (09:50:07) Robot101: LSchiere2: it's easy. +LC_SYS_LARGEFILE somewhere in configure.ac
 AC_SYS_LARGEFILE
--- a/libpurple/dnsquery.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/dnsquery.c	Tue May 27 01:11:46 2008 +0000
@@ -32,6 +32,9 @@
 #include "prefs.h"
 #include "util.h"
 
+#if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
+#define PURPLE_DNSQUERY_USE_FORK
+#endif
 /**************************************************************************
  * DNS query API
  **************************************************************************/
@@ -47,16 +50,16 @@
 	gpointer data;
 	guint timeout;
 
-#if defined(__unix__) || defined(__APPLE__)
+#if defined(PURPLE_DNSQUERY_USE_FORK)
 	PurpleDnsQueryResolverProcess *resolver;
-#elif defined _WIN32 /* end __unix__ || __APPLE__ */
+#elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK  */
 	GThread *resolver;
 	GSList *hosts;
 	gchar *error_message;
 #endif
 };
 
-#if defined(__unix__) || defined(__APPLE__)
+#if defined(PURPLE_DNSQUERY_USE_FORK)
 
 #define MAX_DNS_CHILDREN 4
 
@@ -131,7 +134,7 @@
 	return FALSE;
 }
 
-#if defined(__unix__) || defined(__APPLE__)
+#if defined(PURPLE_DNSQUERY_USE_FORK)
 
 /*
  * Unix!
@@ -649,7 +652,7 @@
 	return query_data;
 }
 
-#elif defined _WIN32 /* end __unix__ || __APPLE__ */
+#elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK  */
 
 /*
  * Windows!
@@ -821,7 +824,7 @@
 	return query_data;
 }
 
-#else /* not __unix__ or __APPLE__ or _WIN32 */
+#else /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
 
 /*
  * We weren't able to do anything fancier above, so use the
@@ -897,7 +900,7 @@
 	return query_data;
 }
 
-#endif /* not __unix__ or __APPLE__ or _WIN32 */
+#endif /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
 
 void
 purple_dnsquery_destroy(PurpleDnsQueryData *query_data)
@@ -907,7 +910,7 @@
 	if (ops && ops->destroy)
 		ops->destroy(query_data);
 
-#if defined(__unix__) || defined(__APPLE__)
+#if defined(PURPLE_DNSQUERY_USE_FORK)
 	queued_requests = g_slist_remove(queued_requests, query_data);
 
 	if (query_data->resolver != NULL)
@@ -918,7 +921,7 @@
 		 * they just don't listen.
 		 */
 		purple_dnsquery_resolver_destroy(query_data->resolver);
-#elif defined _WIN32 /* end __unix__ || __APPLE__ */
+#elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
 	if (query_data->resolver != NULL)
 	{
 		/*
@@ -987,7 +990,7 @@
 void
 purple_dnsquery_uninit(void)
 {
-#if defined(__unix__) || defined(__APPLE__)
+#if defined(PURPLE_DNSQUERY_USE_FORK)
 	while (free_dns_children != NULL)
 	{
 		purple_dnsquery_resolver_destroy(free_dns_children->data);
--- a/libpurple/dnssrv.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/dnssrv.c	Tue May 27 01:11:46 2008 +0000
@@ -25,8 +25,8 @@
 #include "util.h"
 
 #ifndef _WIN32
+#include <arpa/nameser.h>
 #include <resolv.h>
-#include <arpa/nameser.h>
 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
 #include <arpa/nameser_compat.h>
 #endif
--- a/libpurple/internal.h	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/internal.h	Tue May 27 01:11:46 2008 +0000
@@ -102,7 +102,7 @@
 #include <gmodule.h>
 
 #ifdef PURPLE_PLUGINS
-# ifndef _WIN32
+# ifdef HAVE_DLFCN_H 
 #  include <dlfcn.h>
 # endif
 #endif
--- a/libpurple/nat-pmp.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/nat-pmp.c	Tue May 27 01:11:46 2008 +0000
@@ -125,7 +125,16 @@
 		if (bitmask & (1 << i)) 
 		{
 			addrs[i] = sa;
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
 			sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
+#else
+			if (sa->sa_family == AF_INET)
+				sa = (struct sockaddr*)(sizeof(struct sockaddr_in) + (char *)sa);
+#ifdef AF_INET6
+			else if (sa->sa_family == AF_INET6)
+				sa = (struct sockaddr*)(sizeof(struct sockaddr_in6) + (char *)sa);
+#endif
+#endif
 		} 
 		else
 		{
@@ -146,7 +155,12 @@
     if ((sin->sin_addr.s_addr == INADDR_ANY) &&
 		mask &&
 		(ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) == 0L ||
-		 mask->sa_len == 0))
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+		 mask->sa_len == 0
+#else
+		0
+#endif
+		))
 		return 1;
     else
 		return 0;
--- a/libpurple/network.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/network.c	Tue May 27 01:11:46 2008 +0000
@@ -27,9 +27,9 @@
 #include "internal.h"
 
 #ifndef _WIN32
+#include <arpa/nameser.h>
 #include <resolv.h>
 #include <netinet/in.h>
-#include <arpa/nameser.h>
 #include <net/if.h>
 #include <sys/ioctl.h>
 #else
--- a/libpurple/protocols/zephyr/Makefile.am	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/protocols/zephyr/Makefile.am	Tue May 27 01:11:46 2008 +0000
@@ -104,7 +104,7 @@
 	-I$(top_srcdir)/libpurple \
 	-I$(top_builddir)/libpurple \
 	-I$(top_srcdir)/libpurple/protocols \
-	-DCONFDIR=\"$(confdir)\" \
+	-DCONFDIR=\"$(sysconfdir)\" \
 	$(GLIB_CFLAGS) \
 	$(KRB4_CFLAGS) \
 	$(DEBUG_CFLAGS)
--- a/libpurple/protocols/zephyr/zephyr.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Tue May 27 01:11:46 2008 +0000
@@ -892,11 +892,16 @@
 			gconv1 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
 														 zt2->name, gc->account);
 			gcc = purple_conversation_get_chat_data(gconv1);
-
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN 16
+#endif
 			if (!purple_conv_chat_find_user(gcc, sendertmp)) {
 				gchar ipaddr[INET_ADDRSTRLEN];
+#ifdef HAVE_INET_NTOP
 				inet_ntop(AF_INET, &notice.z_sender_addr.s_addr, ipaddr, sizeof(ipaddr));
-
+#else
+				memcpy(ipaddr,inet_ntoa(notice.z_sender_addr),sizeof(ipaddr));
+#endif
 				purple_conv_chat_add_user(gcc, sendertmp, ipaddr, PURPLE_CBFLAGS_NONE, TRUE);
 			}
 			g_free(sendertmp);
--- a/libpurple/proxy.c	Mon May 26 17:10:55 2008 +0000
+++ b/libpurple/proxy.c	Tue May 27 01:11:46 2008 +0000
@@ -1726,6 +1726,10 @@
  * resolved, and each time a connection attempt fails (assuming there
  * is another IP address to try).
  */
+#ifndef INET6_ADDRSTRLEN
+#define INET6_ADDRSTRLEN 46
+#endif
+
 static void try_connect(PurpleProxyConnectData *connect_data)
 {
 	size_t addrlen;
@@ -1736,9 +1740,13 @@
 	connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
 	addr = connect_data->hosts->data;
 	connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
-
+#ifdef HAVE_INET_NTOP
 	inet_ntop(addr->sa_family, &((struct sockaddr_in *)addr)->sin_addr,
 			ipaddr, sizeof(ipaddr));
+#else
+	memcpy(ipaddr,inet_ntoa(((struct sockaddr_in *)addr)->sin_addr),
+			sizeof(ipaddr));
+#endif
 	purple_debug_info("proxy", "Attempting connection to %s\n", ipaddr);
 
 	switch (purple_proxy_info_get_type(connect_data->gpi)) {