From 5151d4520308f59c71764423c3853a35cf23e279 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Sat, 9 Jun 2007 13:40:22 +0000 Subject: [PATCH] * [pupnp-devel] NetBSD & Mac OS X packages and patches. Rene Hexel's patch to compile in NetBSD and Mac OS X. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@205 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 4 ++++ THANKS | 1 + threadutil/src/ThreadPool.c | 21 ++++++++++++++------- upnp/inc/upnp.h | 3 ++- upnp/inc/upnpdebug.h | 12 ++++++++---- upnp/src/api/upnpapi.c | 20 ++++++++++---------- upnp/src/api/upnpdebug.c | 2 +- upnp/src/genlib/net/sock.c | 17 +++++++++++++++++ upnp/src/genlib/net/uri/uri.c | 29 ++++++++++++++++++++++++++++- upnp/src/inc/upnpapi.h | 1 - upnp/src/urlconfig/urlconfig.c | 1 + 11 files changed, 86 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59b5e3d..90e04a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ Version 1.6.0 ******************************************************************************* +2007-06-09 Marcelo Jimenez + * [pupnp-devel] NetBSD & Mac OS X packages and patches. + Rene Hexel's patch to compile in NetBSD and Mac OS X. + 2007-05-26 Marcelo Jimenez * Updated the macro files acx_pthread.m4, ax_cflags_gcc_option.m4, ax_cflags_warn_all.m4, m4/ax_cflags_warn_all_ansi.m4, diff --git a/THANKS b/THANKS index 316458e..9d6b03c 100644 --- a/THANKS +++ b/THANKS @@ -29,6 +29,7 @@ exempt of errors. - Oskar Liljeblad - Michael (Oxy) - Paul Vixie +- Rene Hexel - Siva Chandran - Timothy Redaelli - Titus Winters diff --git a/threadutil/src/ThreadPool.c b/threadutil/src/ThreadPool.c index 3a78b72..a0dd99b 100644 --- a/threadutil/src/ThreadPool.c +++ b/threadutil/src/ThreadPool.c @@ -354,18 +354,25 @@ tp->stats.totalJobsLQ++; tp->stats.totalTimeLQ += diff; break; default: * Parameters: * *****************************************************************************/ - static void SetSeed() { - struct timeb t; +static void SetSeed() { + struct timeb t; - ftime( &t ); + ftime( &t ); #if defined(WIN32) - srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id().p ); + srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id().p ); #elif defined(__FreeBSD__) - srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id() ); + srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id() ); +#elif defined(__linux__) + srand( ( unsigned int )t.millitm + ithread_get_current_thread_id() ); #else - srand( ( unsigned int )t.millitm + ithread_get_current_thread_id() ); + { + volatile union { volatile pthread_t tid; volatile unsigned i; } idu; + + idu.tid = ithread_get_current_thread_id(); + srand( ( unsigned int )t.millitm + idu.i ); + } #endif - } +} /**************************************************************************** * Function: WorkerThread diff --git a/upnp/inc/upnp.h b/upnp/inc/upnp.h index e59d2f4..2dd2427 100644 --- a/upnp/inc/upnp.h +++ b/upnp/inc/upnp.h @@ -47,7 +47,8 @@ #include -#ifdef __FreeBSD__ +#include +#if (defined(BSD) && BSD >= 199306) #include #endif #include "ixml.h" diff --git a/upnp/inc/upnpdebug.h b/upnp/inc/upnpdebug.h index 97c9534..9cbe868 100644 --- a/upnp/inc/upnpdebug.h +++ b/upnp/inc/upnpdebug.h @@ -246,11 +246,15 @@ static UPNP_INLINE int DebugAtThisLevel( * Returns: void ***************************************************************************/ #ifdef DEBUG -void UpnpPrintf (Upnp_LogLevel DLevel, Dbg_Module Module, - const char* DbgFileName, int DbgLineNo, - const char* FmtStr, - ...) +void UpnpPrintf( + Upnp_LogLevel DLevel, + Dbg_Module Module, + const char* DbgFileName, + int DbgLineNo, + const char* FmtStr, + ...) #if (__GNUC__ >= 3) + /* This enables printf like format checking by the compiler */ __attribute__((format (__printf__, 5, 6))) #endif ; diff --git a/upnp/src/api/upnpapi.c b/upnp/src/api/upnpapi.c index ecc72fb..04a23f9 100644 --- a/upnp/src/api/upnpapi.c +++ b/upnp/src/api/upnpapi.c @@ -73,6 +73,8 @@ #include "urlconfig.h" #endif // INTERNAL_WEB_SERVER +virtualDirList *pVirtualDirList; + // Mutex to synchronize the subscription handling at the client side CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; ) @@ -3287,17 +3289,15 @@ UpnpDownloadXmlDoc( const char *url, } else { #ifdef DEBUG xml_buf = ixmlPrintNode( ( IXML_Node * ) * xmlDoc ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Printing the Parsed xml document \n %s\n", - xml_buf ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "****************** END OF Parsed XML Doc *****************\n" ); - ixmlFreeDOMString( xml_buf ); - UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, - "Exiting UpnpDownloadXmlDoc\n" ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Printing the Parsed xml document \n %s\n", xml_buf ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "****************** END OF Parsed XML Doc *****************\n" ); + ixmlFreeDOMString( xml_buf ); + UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, + "Exiting UpnpDownloadXmlDoc\n" ); #endif - - return UPNP_E_SUCCESS; + return UPNP_E_SUCCESS; } } diff --git a/upnp/src/api/upnpdebug.c b/upnp/src/api/upnpdebug.c index 6748fa7..25f01d6 100644 --- a/upnp/src/api/upnpdebug.c +++ b/upnp/src/api/upnpdebug.c @@ -173,7 +173,7 @@ int DebugAtThisLevel( IN Upnp_LogLevel DLevel, IN Dbg_Module Module) { - int ret = g_log_level >= DLevel; + int ret = DLevel <= g_log_level; ret &= DEBUG_ALL || (Module == SSDP && DEBUG_SSDP ) || diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index c18e9eb..1af6ee8 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -231,6 +231,15 @@ sock_read_write( IN SOCKINFO * info, } } +#ifdef SO_NOSIGPIPE + { + int old; + int set = 1; + socklen_t olen = sizeof(old); + getsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, &olen); + setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set)); +#endif + if( bRead ) { // read data numBytes = recv( sockfd, buffer, bufsize,MSG_NOSIGNAL); @@ -243,6 +252,9 @@ sock_read_write( IN SOCKINFO * info, send( sockfd, buffer + bytes_sent, byte_left, MSG_DONTROUTE|MSG_NOSIGNAL); if( num_written == -1 ) { +#ifdef SO_NOSIGPIPE + setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen); +#endif return num_written; } @@ -253,6 +265,11 @@ sock_read_write( IN SOCKINFO * info, numBytes = bytes_sent; } +#ifdef SO_NOSIGPIPE + setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen); + } +#endif + if( numBytes < 0 ) { return UPNP_E_SOCKET_ERROR; } diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index ca3cdc1..b661cc9 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -640,11 +640,38 @@ parse_hostport( const char *in, if ( h == NULL ) { errCode = 1; } -#else +#elif defined(__linux__) errCode = gethostbyname_r( temp_host_name, &h_buf, temp_hostbyname_buff, BUFFER_SIZE, &h, &errcode ); +#else +{ + struct addrinfo hints, *res, *res0; + + h = NULL; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_INET; + hints.ai_socktype = SOCK_STREAM; + errCode = getaddrinfo(temp_host_name, "http", &hints, &res0); + + if (!errCode) { + for (res = res0; res; res = res->ai_next) { + if (res->ai_family == PF_INET && + res->ai_addr->sa_family == AF_INET) + { + h = &h_buf; + h->h_addrtype = res->ai_addr->sa_family; + h->h_length = 4; + h->h_addr = (void *) temp_hostbyname_buff; + *(struct in_addr *)h->h_addr = + ((struct sockaddr_in *)res->ai_addr)->sin_addr; + break; + } + } + freeaddrinfo(res0); + } +} #endif if( errCode == 0 ) { diff --git a/upnp/src/inc/upnpapi.h b/upnp/src/inc/upnpapi.h index c32a39f..5f6a58c 100644 --- a/upnp/src/inc/upnpapi.h +++ b/upnp/src/inc/upnpapi.h @@ -176,7 +176,6 @@ void UpnpThreadDistribution(struct UpnpNonblockParam * Param); void AutoAdvertise(void *input); int getlocalhostname(char *out); -virtualDirList *pVirtualDirList; extern WebServerState bWebServerState; #endif diff --git a/upnp/src/urlconfig/urlconfig.c b/upnp/src/urlconfig/urlconfig.c index 7da2fa3..c2877d2 100644 --- a/upnp/src/urlconfig/urlconfig.c +++ b/upnp/src/urlconfig/urlconfig.c @@ -32,6 +32,7 @@ #include "config.h" #include #ifndef WIN32 + #include #include #include #include