From 724700be0d16e4217c9b518af9c141e04e55f541 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Sun, 25 May 2008 00:49:43 +0000 Subject: [PATCH] Ported Peter Hartley's patch to compile with mingw. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@391 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 3 + configure.ac | 46 +++++++- upnp/inc/upnp.h | 10 ++ upnp/src/genlib/miniserver/miniserver.c | 17 +-- upnp/src/genlib/net/sock.c | 16 +-- upnp/src/genlib/net/uri/uri.c | 79 +++++++------- upnp/src/inc/inet_pton.h | 137 ++++++++++++------------ upnp/src/inc/unixutil.h | 13 ++- upnp/src/inet_pton.c | 121 ++++----------------- 9 files changed, 196 insertions(+), 246 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5633a25..9ab5ab9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ Version 1.8.0 ******************************************************************************* +2008-05-24 Marcelo Jimenez + * Ported Peter Hartley's patch to compile with mingw. + 2008-05-24 Marcelo Jimenez * Added some debug capability to ixml. diff --git a/configure.ac b/configure.ac index 9986ab4..e0a8856 100644 --- a/configure.ac +++ b/configure.ac @@ -341,9 +341,26 @@ AC_DEFINE([_FILE_OFFSET_BITS], [64], [File Offset size]) # -# Checks for header files +# Are we targetting Win32? +# +AC_MSG_CHECKING([for Win32]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#ifdef WIN32 + #error Yup +#endif +],[])], [ac_cv_win32="no"], [ac_cv_win32="yes"]) +if test "$ac_cv_win32" = "yes"; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi + + +# +# Checks for header files (which aren't needed on Win32) # AC_HEADER_STDC +if test "$ac_cv_win32" = "no"; then # libupnp code doesn't use autoconf variables yet, # so just abort if a header file is not found. AC_CHECK_HEADERS( @@ -365,13 +382,38 @@ AC_CHECK_HEADERS( ], [], [AC_MSG_ERROR([required header file missing])]) +fi # # Checks for typedefs, structures, and compiler characteristics # AC_C_CONST -TYPE_SOCKLEN_T + +# The test for socklen_t was getting it wrong when it exists but is in ws2tcpip.h, +# so we use a new test. +#TYPE_SOCKLEN_T + +AC_CHECK_HEADERS([sys/types.h sys/socket.h ws2tcpip.h]) +AC_MSG_CHECKING(for socklen_t) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#ifdef HAVE_SYS_TYPES_H + #include +#endif +#ifdef HAVE_SYS_SOCKET_H + #include +#endif +#ifdef HAVE_WS2TCPIP_H + #include +#endif +],[ socklen_t t = 0; return t; ]) +],[ac_cv_socklen_t="yes"],[ac_cv_socklen_t="no"]) +if test "$ac_cv_socklen_t" = "yes"; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no, using int]) + AC_DEFINE(socklen_t, int, [Type for storing the length of struct sockaddr]) +fi # diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index 9c21133..96c9da5 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -100,6 +100,16 @@ #define PRId64 "I64d" #define PRIzu "zu" #endif /* UPNP_USE_BCBPP */ + + + #ifdef __GNUC__ + #define UPNP_INLINE inline + /* Note with PRIzu that in the case of Mingw32, it's the MS C + * runtime printf which ends up getting called, not the glibc + * printf, so it genuinely doesn't have "zu" + */ + #define PRIzu "lu" + #endif #else #define EXPORT_SPEC #define UPNP_INLINE inline diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c index ae7dedc..e2ff407 100644 --- a/upnp/src/genlib/miniserver/miniserver.c +++ b/upnp/src/genlib/miniserver/miniserver.c @@ -47,7 +47,7 @@ #include "ssdplib.h" #include "statcodes.h" #include "ThreadPool.h" -#include "unixutil.h" +#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */ #include "upnpapi.h" #include "util.h" @@ -60,21 +60,6 @@ #include -#ifdef WIN32 - #include - - typedef int socklen_t; - #define EAFNOSUPPORT 97 -#else - #include - #include - #include - #include - #include - #include -#endif - - #define APPLICATION_LISTENING_PORT 49152 struct mserv_request_t { diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index 5cd882d..90bd514 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -41,7 +41,7 @@ #include "sock.h" -#include "unixutil.h" +#include "unixutil.h" /* for socklen_t, EAFNOSUPPORT */ #include "upnp.h" @@ -51,20 +51,8 @@ #include -#ifdef WIN32 - #include -#else - #include - #include - #include - #include - #include - #include -#endif - - #ifndef MSG_NOSIGNAL - #define MSG_NOSIGNAL 0 + #define MSG_NOSIGNAL 0 #endif /************************************************************************ diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index 311f907..9cec794 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -1,44 +1,48 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + + +/******************************************************************************* + * Purpose: This file contains functions for uri, url parsing utility. + ******************************************************************************/ -/************************************************************************ -* Purpose: This file contains functions for uri, url parsing utility. -************************************************************************/ #ifdef __FreeBSD__ -#include -#if __FreeBSD_version < 601103 -#include -#endif + #include + #if __FreeBSD_version < 601103 + #include + #endif #endif + + #include "config.h" #include "uri.h" #include "upnpapi.h" @@ -1044,3 +1048,4 @@ parse_uri_and_unescape( char *in, remove_escaped_chars( (char *)out->fragment.buff, &out->fragment.size ); return HTTP_SUCCESS; } + diff --git a/upnp/src/inc/inet_pton.h b/upnp/src/inc/inet_pton.h index ba91c34..f828e8e 100644 --- a/upnp/src/inc/inet_pton.h +++ b/upnp/src/inc/inet_pton.h @@ -1,103 +1,100 @@ -#ifdef WIN32 + + #ifndef INET_PTON #define INET_PTON -#include + +#ifdef WIN32 + + +#include "unixutil.h" + #include #include #include -typedef int socklen_t; -#define EAFNOSUPPORT 97 -/* - * WARNING: Don't even consider trying to compile this on a system where + +/*! + * \file + * + * \author: Paul Vixie, 1996. + * + * \brief Network support routines missing in WIN32. + * + * \warning Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) 4 is fine; all the world's not a VAX. + * */ -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. +/*! + * \brief format an IPv4 address + * + * \return `dst' (as a const) + * + * \note + * \li (1) uses no statics + * \li (2) takes a u_char* not an in_addr as input + * */ -extern const char * inet_ntop4(const u_char src, char *dst, socklen_t size); +extern const char *inet_ntop4(const u_char src, char *dst, socklen_t size); -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. + +/*! + * \brief convert IPv6 binary address into presentation (printable) format */ - #ifdef INET_IPV6 - -extern const char * inet_ntop6(src, dst, size); - +extern const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); #endif /* INET_IPV6 */ -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. + +/*! + * \brief like inet_aton() but without all the hexadecimal and shorthand. + * + * \return 1 if `src' is a valid dotted quad, else 0. + * + * \note does not touch `dst' unless it's returning 1. */ extern inet_pton4(const char *src,u_char *dst); -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. + +/*! + * \brief convert presentation level address to network order binary form. + * + * \return 1 if `src' is a valid [RFC1884 2.2] address, else 0. + * + * \note + * \li (1) does not touch `dst' unless it's returning 1. + * \li (2) :: in a full address is silently ignored. */ - #ifdef INET_IPV6 - -extern int inet_pton6(src, dst); - +extern int inet_pton6(const char *src, u_char *dst); #endif /* INET_IPV6 */ - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: +/*! + * \brief convert a network format address to presentation format. + * + * \return * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. */ extern const char *inet_ntop(int af,const void *src,char *dst,socklen_t size); -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. +/*! + * \brief convert from presentation format (which usually means ASCII printable) + * to network format (which is usually some kind of binary format). + * + * \return + * \li 1 if the address was valid for the specified address family + * \li 0 if the address wasn't valid (`dst' is untouched in this case) + * \li -1 if some other error occurred (`dst' is untouched in this case, too) */ extern int inet_pton(int af,const char *src,void *dst); -#endif -#endif + +#endif /* WIN32 */ + + +#endif /* INET_PTON */ + diff --git a/upnp/src/inc/unixutil.h b/upnp/src/inc/unixutil.h index acd956b..c7f3f70 100644 --- a/upnp/src/inc/unixutil.h +++ b/upnp/src/inc/unixutil.h @@ -1,4 +1,4 @@ -/************************************************************************** +/******************************************************************************* * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. @@ -27,7 +27,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ******************************************************************************/ /* Unix-specific network utilities */ @@ -37,14 +37,17 @@ #define GENLIB_NET_UNIXUTIL_H -#include - - #ifdef WIN32 + #include typedef int socklen_t; #define EAFNOSUPPORT 97 #else + #include + #include #include + #include + #include + #include #endif diff --git a/upnp/src/inet_pton.c b/upnp/src/inet_pton.c index 489391c..6bd6273 100644 --- a/upnp/src/inet_pton.c +++ b/upnp/src/inet_pton.c @@ -1,4 +1,3 @@ -#ifdef WIN32 /* * Copyright (c) 1996-1999 by Internet Software Consortium. * @@ -16,39 +15,15 @@ * SOFTWARE. */ -/*#include -#include -#include -#include -#include -#include */ -#include - -#include -#include -#include -typedef int socklen_t; -#define EAFNOSUPPORT 97 -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) 4 is fine; all the world's not a VAX. - */ +/* This file is WIN32 only */ +#ifdef WIN32 -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const u_char *src, char *dst, socklen_t size) +#include "inet_pton.h" + + +static const char *inet_ntop4(const u_char *src, char *dst, socklen_t size) { char tmp[sizeof ("255.255.255.255") + 1] = "\0"; int octet; @@ -82,20 +57,8 @@ inet_ntop4(const u_char *src, char *dst, socklen_t size) } -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ - #ifdef INET_IPV6 - -static const char * -inet_ntop6(src, dst, size) - const u_char *src; - char *dst; - socklen_t size; +static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough @@ -182,18 +145,7 @@ inet_ntop6(src, dst, size) #endif /* INET_IPV6 */ -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src,u_char *dst) +static int inet_pton4(const char *src,u_char *dst) { int saw_digit, octets, ch; u_char tmp[4], *tp; @@ -225,29 +177,12 @@ inet_pton4(const char *src,u_char *dst) if (octets < 4) return (0); memcpy(dst, tmp, 4); - return (1); + return 1; } -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ #ifdef INET_IPV6 - -static int -inet_pton6(src, dst) - const char *src; - u_char *dst; +static int inet_pton6(const char *src, u_char *dst) { static const char xdigits[] = "0123456789abcdef"; u_char tmp[16], *tp, *endp, *colonp; @@ -330,20 +265,10 @@ inet_pton6(src, dst) memcpy(dst, tmp, 16); return (1); } - #endif /* INET_IPV6 */ - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -extern const char *inet_ntop(int af,const void *src,char *dst,socklen_t size) +const char *inet_ntop(int af,const void *src,char *dst,socklen_t size) { switch (af) { case AF_INET: @@ -353,24 +278,13 @@ extern const char *inet_ntop(int af,const void *src,char *dst,socklen_t size) return (inet_ntop6(src, dst, size)); #endif default: - //__set_errno (EAFNOSUPPORT); - return (NULL); + /*__set_errno(EAFNOSUPPORT);*/ + return NULL; } /* NOTREACHED */ } -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ int inet_pton(int af,const char *src,void *dst) { switch (af) { @@ -381,9 +295,12 @@ int inet_pton(int af,const char *src,void *dst) return (inet_pton6(src, dst)); #endif default: - //__set_errno (EAFNOSUPPORT); - return (-1); + /*__set_errno(EAFNOSUPPORT);*/ + return -1; } /* NOTREACHED */ } -#endif \ No newline at end of file + + +#endif /* WIN32 */ +