From 67b51187b9423c3c9be25f3b9db57a2fd24f9e5d Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Mon, 6 Aug 2007 02:07:41 +0000 Subject: [PATCH] =?UTF-8?q?Merge=20of=20Mac=20OS=20X=20patch=20from=20St?= =?UTF-8?q?=C3=A9phane=20Corth=C3=A9sy=20(davelopper),=20SF=20Bug=20Tracke?= =?UTF-8?q?r=20[=201686420=20]=20Modifications=20for=20MacOSX.=20Some=20of?= =?UTF-8?q?=20the=20proposed=20changes=20were=20already=20done=20by=20Rene?= =?UTF-8?q?=20Hexel's=20patch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@213 119443c7-1b9e-41f8-b6fc-b9c35fce742c --- ChangeLog | 5 ++ THANKS | 1 + threadutil/src/LinkedList.c | 2 +- threadutil/src/ThreadPool.c | 21 ++--- threadutil/src/iasnprintf.c | 2 +- upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c | 2 +- upnp/src/api/upnptools.c | 123 +++++++++++++------------- upnp/src/genlib/net/uri/uri.c | 87 +++++++++--------- upnp/test/test_init.c | 2 +- 9 files changed, 130 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index aaf1a45..a5e9c00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ Version 1.6.0 ******************************************************************************* +2007-08-05 Marcelo Jimenez + * Merge of Mac OS X patch from Stéphane Corthésy (davelopper), + SF Bug Tracker [ 1686420 ] Modifications for MacOSX. + Some of the proposed changes were already done by Rene Hexel's patch. + 2007-06-10 Marcelo Jimenez * More fixes to Mac OS X and NetBSD from Rene Hexel: [pupnp-devel] NetBSD & Mac OS X packages and patches diff --git a/THANKS b/THANKS index 9d6b03c..9e2aa02 100644 --- a/THANKS +++ b/THANKS @@ -31,6 +31,7 @@ exempt of errors. - Paul Vixie - Rene Hexel - Siva Chandran +- Stéphane Corthésy - Timothy Redaelli - Titus Winters diff --git a/threadutil/src/LinkedList.c b/threadutil/src/LinkedList.c index 6847687..675c4f1 100644 --- a/threadutil/src/LinkedList.c +++ b/threadutil/src/LinkedList.c @@ -31,7 +31,7 @@ #include "LinkedList.h" #include -#if (defined(BSD) && BSD >= 199306) +#if (defined(BSD) && BSD >= 199306) || defined(__OSX__) #include #else #include diff --git a/threadutil/src/ThreadPool.c b/threadutil/src/ThreadPool.c index 95b3bff..0c6f58e 100644 --- a/threadutil/src/ThreadPool.c +++ b/threadutil/src/ThreadPool.c @@ -90,22 +90,23 @@ FreeThreadPoolJob( ThreadPool * tp, static int SetPolicyType( PolicyType in ) { - #ifdef __CYGWIN__ - /* TODO not currently working... */ - return 0; - #else - #ifdef WIN32 +#ifdef __CYGWIN__ + /* TODO not currently working... */ + return 0; +#elif defined(__OSX__) + setpriority(PRIO_PROCESS, 0, 0); + return 0; +#elif defined(WIN32) return sched_setscheduler( 0, in); - #elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 +#elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 struct sched_param current; sched_getparam( 0, ¤t ); current.sched_priority = DEFAULT_SCHED_PARAM; return sched_setscheduler( 0, in, ¤t ); - #else +#else return 0; - #endif - #endif +#endif } /**************************************************************************** @@ -364,7 +365,7 @@ static void SetSeed() { ftime( &t ); #if defined(WIN32) srand( ( unsigned int )t.millitm + (unsigned int)ithread_get_current_thread_id().p ); -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__OSX__) 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() ); diff --git a/threadutil/src/iasnprintf.c b/threadutil/src/iasnprintf.c index 88ac9cc..ff5470f 100644 --- a/threadutil/src/iasnprintf.c +++ b/threadutil/src/iasnprintf.c @@ -32,7 +32,7 @@ #include #include #include -#if (defined(BSD) && BSD >= 199306) +#if (defined(BSD) && BSD >= 199306) || defined(__OSX__) #include #else #include diff --git a/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c b/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c index d84e079..038cc4a 100644 --- a/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c +++ b/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c @@ -1362,7 +1362,7 @@ TvCtrlPointStart( print_string printFunctionPtr, ithread_mutex_init( &DeviceListMutex, 0 ); - SampleUtil_Print( "Intializing UPnP with ipaddress=%s port=%d", + SampleUtil_Print( "Initializing UPnP with ipaddress=%s port=%d", ip_address, port ); rc = UpnpInit( ip_address, port ); if( UPNP_E_SUCCESS != rc ) { diff --git a/upnp/src/api/upnptools.c b/upnp/src/api/upnptools.c index 9a74da3..74ccf24 100644 --- a/upnp/src/api/upnptools.c +++ b/upnp/src/api/upnptools.c @@ -36,7 +36,7 @@ #include "uri.h" #define HEADER_LENGTH 2000 -//Structure to maintain a error code and string associated with the +// Structure to maintain a error code and string associated with the // error code struct ErrorString { int rc; /* error code */ @@ -44,7 +44,7 @@ struct ErrorString { }; -//Intializing the array of error structures. +// Initializing the array of error structures. struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"}, {UPNP_E_INVALID_HANDLE, "UPNP_E_INVALID_HANDLE"}, {UPNP_E_INVALID_PARAM, "UPNP_E_INVALID_PARAM"}, @@ -81,13 +81,13 @@ struct ErrorString ErrorMessages[] = { {UPNP_E_SUCCESS, "UPNP_E_SUCCESS"}, }; /************************************************************************ -* Function : UpnpGetErrorMessage -* -* Parameters: +* Function : UpnpGetErrorMessage +* +* Parameters: * IN int rc: error code -* -* Description: -* This functions returns the error string mapped to the error code +* +* Description: +* This functions returns the error string mapped to the error code * Returns: const char * * return either the right string or "Unknown Error" ***************************************************************************/ @@ -108,14 +108,14 @@ UpnpGetErrorMessage( IN int rc ) } /************************************************************************ -* Function : UpnpResolveURL -* -* Parameters: +* Function : UpnpResolveURL +* +* Parameters: * IN char * BaseURL: Base URL string * IN char * RelURL: relative URL string * OUT char * AbsURL: Absolute URL string -* Description: -* This functions concatinates the base URL and relative URL to generate +* Description: +* This functions concatinates the base URL and relative URL to generate * the absolute URL * Returns: int * return either UPNP_E_SUCCESS or appropriate error @@ -151,19 +151,19 @@ UpnpResolveURL( IN const char *BaseURL, } /************************************************************************ -* Function : addToAction -* -* Parameters: -* IN int response: flag to tell if the ActionDoc is for response -* or request +* Function : addToAction +* +* Parameters: +* IN int response: flag to tell if the ActionDoc is for response +* or request * INOUT IXML_Document **ActionDoc: request or response document * IN char *ActionName: Name of the action request or response * IN char *ServType: Service type * IN char * ArgName: Name of the argument * IN char * ArgValue: Value of the argument * -* Description: -* This function adds the argument in the action request or response. +* Description: +* This function adds the argument in the action request or response. * This function creates the action request or response if it is a first * argument else it will add the argument in the document * @@ -230,22 +230,22 @@ addToAction( IN int response, } /************************************************************************ -* Function : makeAction -* -* Parameters: -* IN int response: flag to tell if the ActionDoc is for response -* or request +* Function : makeAction +* +* Parameters: +* IN int response: flag to tell if the ActionDoc is for response +* or request * IN char * ActionName: Name of the action request or response * IN char * ServType: Service type * IN int NumArg :Number of arguments in the action request or response * IN char * Arg : pointer to the first argument * IN va_list ArgList: Argument list * -* Description: +* Description: * This function creates the action request or response from the argument * list. * Returns: IXML_Document * -* returns action request or response document if successful +* returns action request or response document if successful * else returns NULL ***************************************************************************/ static IXML_Document * @@ -326,9 +326,9 @@ makeAction( IN int response, } /************************************************************************ -* Function : UpnpMakeAction -* -* Parameters: +* Function : UpnpMakeAction +* +* Parameters: * IN char * ActionName: Name of the action request or response * IN char * ServType: Service type * IN int NumArg :Number of arguments in the action request or response @@ -336,7 +336,7 @@ makeAction( IN int response, * IN ... : variable argument list * IN va_list ArgList: Argument list * -* Description: +* Description: * This function creates the action request from the argument * list. Its a wrapper function that calls makeAction function to create * the action request. @@ -363,9 +363,9 @@ UpnpMakeAction( const char *ActionName, } /************************************************************************ -* Function : UpnpMakeActionResponse -* -* Parameters: +* Function : UpnpMakeActionResponse +* +* Parameters: * IN char * ActionName: Name of the action request or response * IN char * ServType: Service type * IN int NumArg :Number of arguments in the action request or response @@ -373,13 +373,13 @@ UpnpMakeAction( const char *ActionName, * IN ... : variable argument list * IN va_list ArgList: Argument list * -* Description: +* Description: * This function creates the action response from the argument * list. Its a wrapper function that calls makeAction function to create * the action response. * * Returns: IXML_Document * -* returns action response document if successful +* returns action response document if successful * else returns NULL ***************************************************************************/ IXML_Document * @@ -400,22 +400,22 @@ UpnpMakeActionResponse( const char *ActionName, } /************************************************************************ -* Function : UpnpAddToActionResponse -* +* Function : UpnpAddToActionResponse +* * Parameters: -* INOUT IXML_Document **ActionResponse: action response document +* INOUT IXML_Document **ActionResponse: action response document * IN char * ActionName: Name of the action request or response * IN char * ServType: Service type * IN int ArgName :Name of argument to be added in the action response * IN char * ArgValue : value of the argument * -* Description: -* This function adds the argument in the action response. Its a wrapper -* function that calls addToAction function to add the argument in the +* Description: +* This function adds the argument in the action response. Its a wrapper +* function that calls addToAction function to add the argument in the * action response. * * Returns: int -* returns UPNP_E_SUCCESS if successful +* returns UPNP_E_SUCCESS if successful * else returns appropriate error ***************************************************************************/ int @@ -430,22 +430,22 @@ UpnpAddToActionResponse( INOUT IXML_Document ** ActionResponse, } /************************************************************************ -* Function : UpnpAddToAction -* +* Function : UpnpAddToAction +* * Parameters: -* INOUT IXML_Document **ActionDoc: action request document +* INOUT IXML_Document **ActionDoc: action request document * IN char * ActionName: Name of the action request or response * IN char * ServType: Service type * IN int ArgName :Name of argument to be added in the action response * IN char * ArgValue : value of the argument * -* Description: -* This function adds the argument in the action request. Its a wrapper -* function that calls addToAction function to add the argument in the +* Description: +* This function adds the argument in the action request. Its a wrapper +* function that calls addToAction function to add the argument in the * action request. * * Returns: int -* returns UPNP_E_SUCCESS if successful +* returns UPNP_E_SUCCESS if successful * else returns appropriate error ***************************************************************************/ int @@ -461,15 +461,15 @@ UpnpAddToAction( IXML_Document ** ActionDoc, } /************************************************************************ -* Function : UpnpAddToPropertySet -* -* Parameters: +* Function : UpnpAddToPropertySet +* +* Parameters: * INOUT IXML_Document **PropSet: propertyset document * IN char *ArgName: Name of the argument * IN char *ArgValue: value of the argument * -* Description: -* This function adds the argument in the propertyset node +* Description: +* This function adds the argument in the propertyset node * * Returns: int * returns UPNP_E_SUCCESS if successful else returns appropriate error @@ -516,14 +516,14 @@ UpnpAddToPropertySet( INOUT IXML_Document ** PropSet, } /************************************************************************ -* Function : UpnpCreatePropertySet -* -* Parameters: +* Function : UpnpCreatePropertySet +* +* Parameters: * IN int NumArg: Number of argument that will go in the propertyset node * IN char * Args: argument strings * -* Description: -* This function creates a propertyset node and put all the input +* Description: +* This function creates a propertyset node and put all the input * parameters in the node as elements * * Returns: IXML_Document * @@ -581,4 +581,5 @@ UpnpCreatePropertySet( IN int NumArg, return PropSet; } -#endif +#endif // EXCLUDE_DOM == 0 + diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index b661cc9..0dee1ce 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -555,7 +555,7 @@ parse_hostport( const char *in, int begin_port; int hostport_size = 0; int host_size = 0; -#ifndef WIN32 +#if !defined(WIN32) && !defined(__OSX__) char temp_hostbyname_buff[BUFFER_SIZE]; struct hostent h_buf; #endif @@ -626,54 +626,61 @@ parse_hostport( const char *in, // TODO: Use autoconf to discover this rather than the // platform-specific stuff below #if defined(WIN32) || defined(__CYGWIN__) - h=gethostbyname(temp_host_name); + h = gethostbyname(temp_host_name); #elif defined(SPARC_SOLARIS) - errCode = gethostbyname_r( temp_host_name, - &h, - temp_hostbyname_buff, - BUFFER_SIZE, &errcode ); + errCode = gethostbyname_r( + temp_host_name, + &h, + temp_hostbyname_buff, + BUFFER_SIZE, &errcode ); #elif defined(__FreeBSD__) && __FreeBSD_version < 601103 - h = lwres_gethostbyname_r( temp_host_name, - &h_buf, - temp_hostbyname_buff, - BUFFER_SIZE, &errcode ); + h = lwres_gethostbyname_r( + temp_host_name, + &h_buf, + temp_hostbyname_buff, + BUFFER_SIZE, &errcode ); if ( h == NULL ) { - errCode = 1; + errCode = 1; + } +#elif defined(__OSX__) + h = gethostbyname(temp_host_name); + if ( h == NULL ) { + errCode = 1; } #elif defined(__linux__) - errCode = gethostbyname_r( temp_host_name, - &h_buf, - temp_hostbyname_buff, - BUFFER_SIZE, &h, &errcode ); + errCode = gethostbyname_r( + temp_host_name, + &h_buf, + temp_hostbyname_buff, + BUFFER_SIZE, &h, &errcode ); #else -{ - struct addrinfo hints, *res, *res0; + { + 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); + 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); - } -} + 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 ) { if( h ) { if( ( h->h_addrtype == AF_INET ) && ( h->h_length == 4 ) ) { diff --git a/upnp/test/test_init.c b/upnp/test/test_init.c index 98f1360..9a13214 100644 --- a/upnp/test/test_init.c +++ b/upnp/test/test_init.c @@ -105,7 +105,7 @@ main (int argc, char* argv[]) * Test library initialisation */ printf ("\n"); - printf ("Intializing UPnP ... \n"); + printf ("Initializing UPnP ... \n"); rc = UpnpInit (NULL, 0); if ( UPNP_E_SUCCESS == rc ) { const char* ip_address = UpnpGetServerIpAddress();