Backport of most of upnp.h with documentation.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@475 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-07-27 03:06:21 +00:00
parent 7963e97469
commit ceca478180
11 changed files with 3051 additions and 3762 deletions

View File

@ -21,7 +21,8 @@ upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = \
inc/upnp.h \
inc/upnpdebug.h \
inc/UpnpGlobal.h
inc/UpnpGlobal.h \
inc/UpnpInet.h
nodist_upnpinclude_HEADERS = inc/upnpconfig.h
if ENABLE_TOOLS
@ -47,7 +48,6 @@ libupnp_la_SOURCES = \
src/inc/gena_device.h \
src/inc/global.h \
src/inc/gmtdate.h \
src/inc/http_client.h \
src/inc/httpparser.h \
src/inc/httpreadwrite.h \
src/inc/md5.h \
@ -111,7 +111,9 @@ libupnp_la_SOURCES += \
src/gena/gena_callback2.c
# api
libupnp_la_SOURCES += src/api/upnpapi.c
libupnp_la_SOURCES += \
src/api/upnpapi.c
if ENABLE_TOOLS
libupnp_la_SOURCES += src/api/upnptools.c
endif

23
upnp/inc/UpnpInet.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef UPNPINET_H
#define UPNPINET_H
/*!
* \file
*
* \brief Provides a platform independent way to include TCP/IP types and functions.
*/
#ifdef WIN32
#include <winsock2.h>
#include <Ws2tcpip.h>
#else
#include <netinet/in.h>
#endif
#endif /* UPNPINET_H */

File diff suppressed because it is too large Load Diff

View File

@ -1736,25 +1736,7 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
#ifdef INCLUDE_CLIENT_APIS
/**************************************************************************
* Function: UpnpUnSubscribe
*
* Parameters:
* IN UpnpClient_Handle Hnd: The handle of the control point.
* IN Upnp_SID SubsId: The ID returned when the control point
* subscribed to the service.
*
* Description:
* This function removes the subscription of a control point from a
* service previously subscribed to using UpnpSubscribe or
* UpnpSubscribeAsync. This is a synchronous call.
*
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId )
int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int RetVal;
@ -1861,33 +1843,12 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
return UPNP_E_SUCCESS;
} /****************** End of UpnpUnSubscribeAsync *********************/
}
#endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS
/**************************************************************************
* Function: UpnpRenewSubscription
*
* Parameters:
* IN UpnpClient_Handle Hnd: The handle of the control point that
* is renewing the subscription.
* INOUT int *TimeOut: Pointer to a variable containing the
* requested subscription time. Upon return,
* it contains the actual renewal time.
* IN Upnp_SID SubsId: The ID for the subscription to renew.
*
* Description:
* This function renews a subscription that is about to
* expire. This function is synchronous.
*
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpRenewSubscription( IN UpnpClient_Handle Hnd,
INOUT int *TimeOut,
IN Upnp_SID SubsId )
int UpnpRenewSubscription(UpnpClient_Handle Hnd, int *TimeOut, const Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int RetVal;
@ -2158,40 +2119,14 @@ UpnpNotifyExt( IN UpnpDevice_Handle Hnd,
#ifdef INCLUDE_DEVICE_APIS
/**************************************************************************
* Function: UpnpAcceptSubscription
*
* Parameters:
* IN UpnpDevice_Handle Hnd: The handle of the device.
* IN const char *DevID: The device ID of the subdevice of the
* service generating the event.
* IN const char *ServID: The unique service identifier of the
* service generating the event.
* IN const char **VarName: Pointer to an array of event variables.
* IN const char **NewVal: Pointer to an array of values for
* the event variables.
* IN int cVariables: The number of event variables in VarName.
* IN Upnp_SID SubsId: The subscription ID of the newly
* registered control point.
*
* Description:
* This function accepts a subscription request and sends
* out the current state of the eventable variables for a service.
* The device application should call this function when it receives a
* UPNP_EVENT_SUBSCRIPTION_REQUEST callback. This function is sychronous
* and generates no callbacks.
*
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpAcceptSubscription( IN UpnpDevice_Handle Hnd,
IN const char *DevID_const,
IN const char *ServName_const,
IN const char **VarName_const,
IN const char **NewVal_const,
int UpnpAcceptSubscription(
UpnpDevice_Handle Hnd,
const char *DevID_const,
const char *ServName_const,
const char **VarName_const,
const char **NewVal_const,
int cVariables,
IN Upnp_SID SubsId )
const Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int retVal;

View File

@ -1,52 +1,65 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
*
******************************************************************************/
/*
* \file
*
* \brief Contains functions for scanner and parser for http messages.
*/
/************************************************************************
* Purpose: This file contains functions for scanner and parser for http
* messages.
************************************************************************/
#define _GNU_SOURCE // For strcasestr() in string.h
#include "config.h"
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include "strintmap.h"
#include "httpparser.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpdebug.h"
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
/* entity positions */
// entity positions
#define NUM_HTTP_METHODS 9
static str_int_entry Http_Method_Table[NUM_HTTP_METHODS] = {
@ -122,8 +135,8 @@ str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES] = {
* Note :
************************************************************************/
static UPNP_INLINE void
scanner_init( OUT scanner_t * scanner,
IN membuffer * bufptr )
scanner_init( OUT scanner_t *scanner,
IN membuffer *bufptr )
{
scanner->cursor = 0;
scanner->msg = bufptr;
@ -395,12 +408,12 @@ scanner_get_str( IN scanner_t * scanner )
*
* Note :
************************************************************************/
#ifndef WIN32
#warning The only use of the function 'scanner_pushback()' in the code is commented out.
#warning 'scanner_pushback()' is a candidate for removal.
#ifdef WIN32
#pragma message ("The only use of the function 'scanner_pushback()' in the code is commented out.")
#pragma message ("'scanner_pushback()' is a candidate for removal.")
#else
#pragma message ("The only use of the function 'scanner_pushback()' in the code is commented out.")
#pragma message ("'scanner_pushback()' is a candidate for removal.")
#warning The only use of the function 'scanner_pushback()' in the code is commented out.
#warning 'scanner_pushback()' is a candidate for removal.
#endif
static UPNP_INLINE void
scanner_pushback( INOUT scanner_t * scanner,
@ -970,12 +983,12 @@ read_until_crlf( INOUT scanner_t * scanner,
* PARSE_FAILURE
* PARSE_INCOMPLETE
************************************************************************/
#ifndef WIN32
#warning There are currently no uses of the function 'skip_to_end_of_header()' in the code.
#warning 'skip_to_end_of_header()' is a candidate for removal.
#ifdef WIN32
#pragma message("There are currently no uses of the function 'skip_to_end_of_header()' in the code.")
#pragma message("'skip_to_end_of_header()' is a candidate for removal.")
#else
#pragma message("There are currently no uses of the function 'skip_to_end_of_header()' in the code.")
#pragma message("'skip_to_end_of_header()' is a candidate for removal.")
#warning There are currently no uses of the function 'skip_to_end_of_header()' in the code.
#warning 'skip_to_end_of_header()' is a candidate for removal.
#endif
static UPNP_INLINE int
skip_to_end_of_header( INOUT scanner_t * scanner )
@ -2496,26 +2509,15 @@ method_to_str( IN http_method_t method )
return index == -1 ? NULL : Http_Method_Table[index].name;
}
/************************************************************************
* Function: print_http_headers
*
* Parameters:
* http_message_t* hmsg ; HTTP Message object
*
* Description:
*
* Returns:
* void
************************************************************************/
#ifdef DEBUG
void
print_http_headers( http_message_t * hmsg )
void print_http_headers(http_message_t *hmsg)
{
ListNode *node;
// NNS: dlist_node *node;
/* NNS: dlist_node *node; */
http_header_t *header;
// print start line
/* print start line */
if( hmsg->is_request ) {
printf( "method = %d, version = %d.%d, url = %.*s\n",
hmsg->method, hmsg->major_version, hmsg->minor_version,
@ -2526,18 +2528,18 @@ print_http_headers( http_message_t * hmsg )
(int)hmsg->status_msg.length, hmsg->status_msg.buf);
}
// print headers
/* print headers */
node = ListHead( &hmsg->headers );
// NNS: node = dlist_first_node( &hmsg->headers );
/* NNS: node = dlist_first_node( &hmsg->headers ); */
while( node != NULL ) {
header = ( http_header_t * ) node->item;
// NNS: header = (http_header_t *)node->data;
/* NNS: header = (http_header_t *)node->data; */
printf( "hdr name: %.*s, value: %.*s\n",
(int)header->name.length, header->name.buf,
(int)header->value.length, header->value.buf );
node = ListNext( &hmsg->headers, node );
// NNS: node = dlist_next( &hmsg->headers, node );
/* NNS: node = dlist_next( &hmsg->headers, node ); */
}
}
#endif

View File

@ -1,221 +1,184 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
*
******************************************************************************/
/*!
* \file
*
* \brief Contains functions for uri, url parsing utility.
*/
/************************************************************************
* Purpose: This file contains functions for uri, url parsing utility.
************************************************************************/
#ifdef __FreeBSD__
#include <osreldate.h>
#if __FreeBSD_version < 601103
#include <lwres/netdb.h>
#endif
#include <osreldate.h>
#if __FreeBSD_version < 601103
#include <lwres/netdb.h>
#endif
#endif
#include "config.h"
#include "uri.h"
#ifdef WIN32
#include "inet_pton.h"
#endif
#include "upnpdebug.h"
/************************************************************************
* Function : is_reserved
*
* Parameters :
* char in ; char to be matched for RESERVED characters
*
* Description : Returns a 1 if a char is a RESERVED char as defined in
* http://www.ietf.org/rfc/rfc2396.txt RFC explaining URIs)
*
* Return : int ;
*
* Note :
************************************************************************/
int
is_reserved( char in )
/*!
* \brief Returns a 1 if a char is a RESERVED char as defined in
* http://www.ietf.org/rfc/rfc2396.txt RFC explaining URIs).
*
* \return 1 if char is a RESERVED char.
*/
static int is_reserved(
/*! [in] Char to be matched for RESERVED characters. */
char in)
{
if( strchr( RESERVED, in ) )
if (strchr(RESERVED, in)) {
return 1;
else
} else {
return 0;
}
}
/************************************************************************
* Function : is_mark
*
* Parameters :
* char in ; character to be matched for MARKED characters
*
* Description : Returns a 1 if a char is a MARK char as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
*
* Return : int ;
*
* Note :
************************************************************************/
int
is_mark( char in )
/*!
* \brief Returns a 1 if a char is a MARK char as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
*
* \return 1 if char is a MARKED char.
*/
int is_mark(
/*! [in] Char to be matched for MARKED characters. */
char in)
{
if( strchr( MARK, in ) )
if (strchr(MARK, in)) {
return 1;
else
} else {
return 0;
}
}
/************************************************************************
* Function : is_unreserved
*
* Parameters :
* char in ; character to be matched for UNRESERVED characters
*
* Description : Returns a 1 if a char is an unreserved char as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
*
* Return : int ;
*
* Note :
************************************************************************/
int
is_unreserved( char in )
/*!
* \brief Returns a 1 if a char is an UNRESERVED char as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
*
* \return 1 if char is a UNRESERVED char.
*/
int is_unreserved(
/*! [in] Char to be matched for UNRESERVED characters. */
char in)
{
if( isalnum( in ) || ( is_mark( in ) ) )
if (isalnum(in) || is_mark(in)) {
return 1;
else
} else {
return 0;
}
}
/************************************************************************
* Function : is_escaped
*
* Parameters :
* char * in ; character to be matched for ESCAPED characters
*
* Description : Returns a 1 if a char[3] sequence is escaped as defined
* in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
* size of array is NOT checked (MUST be checked by caller)
*
* Return : int ;
*
* Note :
************************************************************************/
int
is_escaped( const char *in )
/*!
* \brief Returns a 1 if a char[3] sequence is ESCAPED as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
*
* Size of array is NOT checked (MUST be checked by caller).
*
* \return 1 if char is a ESCAPED char.
*/
int is_escaped(
/*! [in] Char sequence to be matched for ESCAPED characters. */
const char *in)
{
if( ( in[0] == '%' ) && ( isxdigit( in[1] ) ) && isxdigit( in[2] ) ) {
if (in[0] == '%' && isxdigit(in[1]) && isxdigit(in[2])) {
return 1;
} else
} else {
return 0;
}
}
/************************************************************************
* Function : replace_escaped
*
* Parameters :
* char * in ; string of characters
* int index ; index at which to start checking the characters
* int *max ;
*
* Description : Replaces an escaped sequence with its unescaped version
* as in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
* Size of array is NOT checked (MUST be checked by caller)
*
* Return : int ;
*
* Note : This function modifies the string. If the sequence is an
* escaped sequence it is replaced, the other characters in the
* string are shifted over, and NULL characters are placed at the
* end of the string.
************************************************************************/
int
replace_escaped( char *in,
int index,
size_t *max )
int replace_escaped(char *in, int index, size_t *max)
{
int tempInt = 0;
char tempChar = 0;
int i = 0;
int j = 0;
if( ( in[index] == '%' ) && ( isxdigit( in[index + 1] ) )
&& isxdigit( in[index + 2] ) ) {
//Note the "%2x", makes sure that we convert a maximum of two
//characters.
if( sscanf( &in[index + 1], "%2x", &tempInt ) != 1 )
if (in[index] == '%' && isxdigit(in[index + 1]) && isxdigit(in[index + 2])) {
/* Note the "%2x", makes sure that we convert a maximum of two
* characters. */
if (sscanf(&in[index + 1], "%2x", &tempInt) != 1) {
return 0;
}
tempChar = ( char )tempInt;
for( i = index + 3, j = index; j < ( *max ); i++, j++ ) {
for (i = index + 3, j = index; j < *max; i++, j++) {
in[j] = tempChar;
if( i < ( *max ) )
if (i < *max) {
tempChar = in[i];
else
} else {
tempChar = 0;
}
( *max ) -= 2;
}
*max -= 2;
return 1;
} else
} else {
return 0;
}
}
/************************************************************************
* Function : parse_uric
*
* Parameters :
* char *in ; string of characters
* int max ; maximum limit
* token *out ; token object where the string of characters is
* copied
*
* Description : Parses a string of uric characters starting at in[0]
* as defined in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining
* URIs)
*
* Return : int ;
*
* Note :
************************************************************************/
int
parse_uric( const char *in,
/*!
* \brief Parses a string of uric characters starting at in[0] as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
*
* \return
*/
static int parse_uric(
/*! [in] String of characters. */
const char *in,
/*! [in] Maximum limit. */
int max,
token * out )
/*! [out] Token object where the string of characters is copied. */
token *out)
{
int i = 0;
while( ( i < max )
&& ( ( is_unreserved( in[i] ) ) || ( is_reserved( in[i] ) )
|| ( ( i + 2 < max ) && ( is_escaped( &in[i] ) ) ) ) ) {
while (i < max &&
(is_unreserved(in[i]) ||
is_reserved(in[i]) ||
((i + 2 < max) && is_escaped(&in[i])))) {
i++;
}
@ -247,55 +210,27 @@ copy_sockaddr_in( const struct sockaddr_in *in,
out->sin_addr.s_addr = in->sin_addr.s_addr;
}
/************************************************************************
* Function : copy_token
*
* Parameters :
* const token *in ; source token
* const char * in_base ;
* token * out ; destination token
* char * out_base ;
*
* Description : Tokens are generally pointers into other strings
* this copies the offset and size from a token (in) relative to
* one string (in_base) into a token (out) relative to another
* string (out_base)
*
* Return : void ;
*
* Note :
************************************************************************/
static void
copy_token( const token * in,
/*!
* \brief Tokens are generally pointers into other strings. This copies the
* offset and size from a token (in) relative to one string (in_base) into
* a token (out) relative to another string (out_base).
*/
static void copy_token(
/*! [in] Source token. */
const token *in,
/*! [in] . */
const char *in_base,
token * out,
char *out_base )
/*! [out] Destination token. */
token *out,
/*! [in] . */
char *out_base)
{
out->size = in->size;
out->buff = out_base + ( in->buff - in_base );
out->buff = out_base + (in->buff - in_base);
}
/************************************************************************
* Function : copy_URL_list
*
* Parameters :
* URL_list *in ; Source URL list
* URL_list *out ; Destination URL list
*
* Description : Copies one URL_list into another. This includes
* dynamically allocating the out->URLs field (the full string),
* and the structures used to hold the parsedURLs. This memory MUST
* be freed by the caller through: free_URL_list(&out)
*
* Return : int ;
* HTTP_SUCCESS - On Success
* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory
*
* Note :
************************************************************************/
int
copy_URL_list( URL_list * in,
URL_list * out )
int copy_URL_list(URL_list *in, URL_list *out)
{
int len = strlen( in->URLs ) + 1;
int i = 0;
@ -332,68 +267,34 @@ copy_URL_list( URL_list * in,
&out->parsedURLs[i].hostport.IPv4address );
}
out->size = in->size;
return HTTP_SUCCESS;
return HTTP_SUCCESS;
}
/************************************************************************
* Function : free_URL_list
*
* Parameters :
* URL_list * list ; URL List object
*
* Description : Frees the memory associated with a URL_list. Frees the
* dynamically allocated members of of list. Does NOT free the
* pointer to the list itself ( i.e. does NOT free(list))
*
* Return : void ;
*
* Note :
************************************************************************/
void
free_URL_list( URL_list * list )
void free_URL_list(URL_list *list)
{
if( list->URLs )
free( list->URLs );
if( list->parsedURLs )
free( list->parsedURLs );
if (list->URLs) {
free(list->URLs);
}
if (list->parsedURLs) {
free(list->parsedURLs);
}
list->size = 0;
}
/************************************************************************
* Function : print_uri
*
* Parameters :
* uri_type *in ; URI object
*
* Description : Function useful in debugging for printing a parsed uri.
*
* Return : void ;
*
* Note :
************************************************************************/
#ifdef DEBUG
void print_uri( uri_type *in )
{
print_token( &in->scheme );
print_token( &in->hostport.text );
print_token( &in->pathquery );
print_token( &in->fragment );
}
#endif
/************************************************************************
* Function : print_token
*
* Parameters :
* token * in ; token
*
* Description : Function useful in debugging for printing a token.
*
* Return : void ;
*
* Note :
************************************************************************/
#ifdef DEBUG
void print_uri(uri_type *in)
{
print_token(&in->scheme);
print_token(&in->hostport.text);
print_token(&in->pathquery);
print_token(&in->fragment);
}
#endif /* DEBUG */
#ifdef DEBUG
void print_token(token * in)
{
@ -405,149 +306,64 @@ void print_token(token * in)
putchar( '\'' );
putchar( '\n' );
}
#endif
#endif /* DEBUG */
/************************************************************************
* Function : token_string_casecmp
*
* Parameters :
* token * in1 ; Token object whose buffer is to be compared
* char * in2 ; string of characters to compare with
*
* Description : Compares buffer in the token object with the buffer
* in in2
*
* Return : int ;
* < 0 string1 less than string2
* 0 string1 identical to string2
* > 0 string1 greater than string2
*
* Note :
************************************************************************/
int token_string_casecmp(
token * in1,
char *in2 )
int token_string_casecmp(token *in1, char *in2)
{
int in2_length = strlen( in2 );
int in2_length = strlen(in2);
if( in1->size != in2_length )
if (in1->size != in2_length) {
return 1;
else
return strncasecmp( in1->buff, in2, in1->size );
} else {
return strncasecmp(in1->buff, in2, in1->size);
}
}
/************************************************************************
* Function : token_string_cmp
*
* Parameters :
* token * in1 ; Token object whose buffer is to be compared
* char * in2 ; string of characters to compare with
*
* Description : Compares a null terminated string to a token (exact)
*
* Return : int ;
* < 0 string1 less than string2
* 0 string1 identical to string2
* > 0 string1 greater than string2
*
* Note :
************************************************************************/
int
token_string_cmp( token * in1,
char *in2 )
{
int in2_length = strlen( in2 );
if( in1->size != in2_length )
int token_string_cmp(token * in1, char *in2)
{
int in2_length = strlen(in2);
if (in1->size != in2_length) {
return 1;
else
return strncmp( in1->buff, in2, in1->size );
} else {
return strncmp(in1->buff, in2, in1->size);
}
}
/************************************************************************
* Function : token_cmp
*
* Parameters :
* token *in1 ; First token object whose buffer is to be compared
* token *in2 ; Second token object used for the comparison
*
* Description : Compares two tokens
*
* Return : int ;
* < 0 string1 less than string2
* 0 string1 identical to string2
* > 0 string1 greater than string2
*
* Note :
************************************************************************/
int
token_cmp( token * in1,
token * in2 )
int token_cmp(token *in1, token *in2)
{
if( in1->size != in2->size )
if (in1->size != in2->size) {
return 1;
else
return memcmp( in1->buff, in2->buff, in1->size );
} else {
return memcmp(in1->buff, in2->buff, in1->size);
}
}
/************************************************************************
* Function : parse_port
*
* Parameters :
* int max ; sets a maximum limit
* char * port ; port to be parsed.
* unsigned short * out ; out parameter where the port is parsed
* and converted into network format
*
* Description : parses a port (i.e. '4000') and converts it into a
* network ordered unsigned short int.
*
* Return : int ;
*
* Note :
************************************************************************/
int
parse_port( int max,
const char *port,
unsigned short *out )
{
int parse_port(int max, const char *port, unsigned short *out)
{
const char *finger = port;
const char *max_ptr = finger + max;
unsigned short temp = 0;
while( ( finger < max_ptr ) && ( isdigit( *finger ) ) ) {
while((finger < max_ptr) && (isdigit(*finger))) {
temp = temp * 10;
temp += ( *finger ) - '0';
temp += *finger - '0';
finger++;
}
*out = htons( temp );
*out = htons(temp);
return finger - port;
}
/************************************************************************
* Function : parse_hostport
*
* Parameters :
* char *in ; string of characters representing host and port
* int max ; sets a maximum limit
* hostport_type *out ; out parameter where the host and port
* are represented as an internet address
*
* Description : Parses a string representing a host and port
* (e.g. "127.127.0.1:80" or "localhost") and fills out a
* hostport_type struct with internet address and a token
* representing the full host and port. uses gethostbyname.
*
* Return : int ;
*
* Note :
************************************************************************/
int
parse_hostport( const char *in,
int parse_hostport(
const char *in,
int max,
hostport_type * out )
hostport_type *out)
{
#define BUFFER_SIZE 8192
@ -564,8 +380,7 @@ parse_hostport( const char *in,
char *temp_host_name = NULL;
int last_dot = -1;
out->text.size = 0;
out->text.buff = NULL;
memset( out, 0, sizeof(hostport_type) );
out->IPv4address.sin_port = htons( 80 ); //default port is 80
memset( &out->IPv4address.sin_zero, 0, 8 );
@ -710,28 +525,23 @@ parse_hostport( const char *in,
}
/************************************************************************
* Function : parse_scheme
*
* Parameters :
* char * in ; string of characters representing a scheme
* int max ; maximum number of characters
* token * out ; output parameter whose buffer is filled in with
* the scheme
*
* Description : parses a uri scheme starting at in[0] as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
* (e.g. "http:" -> scheme= "http").
* Note, string MUST include ':' within the max charcters
*
* Return : int ;
*
* Note :
************************************************************************/
int
parse_scheme( const char *in,
/*!
* \brief parses a uri scheme starting at in[0] as defined in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
*
* (e.g. "http:" -> scheme= "http").
*
* \note String MUST include ':' within the max charcters.
*
* \return
*/
static int parse_scheme(
/*! [in] String of characters representing a scheme. */
const char *in,
/*! [in] Maximum number of characters. */
int max,
token * out )
/*! [out] Output parameter whose buffer is filled in with the scheme. */
token *out)
{
int i = 0;
@ -760,26 +570,8 @@ parse_scheme( const char *in,
}
/************************************************************************
* Function : remove_escaped_chars
*
* Parameters :
* INOUT char *in ; string of characters to be modified
* INOUT int *size ; size limit for the number of characters
*
* Description : removes http escaped characters such as: "%20" and
* replaces them with their character representation. i.e.
* "hello%20foo" -> "hello foo". The input IS MODIFIED in place.
* (shortened). Extra characters are replaced with NULL.
*
* Return : int ;
* UPNP_E_SUCCESS
*
* Note :
************************************************************************/
int
remove_escaped_chars( INOUT char *in,
INOUT size_t *size )
int remove_escaped_chars(INOUT char *in, INOUT size_t *size )
{
int i = 0;
@ -789,37 +581,8 @@ remove_escaped_chars( INOUT char *in,
return UPNP_E_SUCCESS;
}
/************************************************************************
* Function : remove_dots
*
* Parameters :
* char *in ; string of characters from which "dots" have to be
* removed
* int size ; size limit for the number of characters
*
* Description : Removes ".", and ".." from a path. If a ".." can not
* be resolved (i.e. the .. would go past the root of the path) an
* error is returned. The input IS modified in place.)
*
* Return : int ;
* UPNP_E_SUCCESS - On Success
* UPNP_E_OUTOF_MEMORY - On failure to allocate memory
* UPNP_E_INVALID_URL - Failure to resolve URL
*
* Note :
* Examples
* char path[30]="/../hello";
* remove_dots(path, strlen(path)) -> UPNP_E_INVALID_URL
* char path[30]="/./hello";
* remove_dots(path, strlen(path)) -> UPNP_E_SUCCESS,
* in = "/hello"
* char path[30]="/./hello/foo/../goodbye" ->
* UPNP_E_SUCCESS, in = "/hello/goodbye"
************************************************************************/
int
remove_dots( char *in,
int size )
int remove_dots(char *in, size_t size)
{
char *copyTo = in;
char *copyFrom = in;
@ -884,30 +647,8 @@ remove_dots( char *in,
return UPNP_E_SUCCESS;
}
/************************************************************************
* Function : resolve_rel_url
*
* Parameters :
* char * base_url ; Base URL
* char * rel_url ; Relative URL
*
* Description : resolves a relative url with a base url returning a NEW
* (dynamically allocated with malloc) full url. If the base_url is
* NULL, then a copy of the rel_url is passed back if the rel_url
* is absolute then a copy of the rel_url is passed back if neither
* the base nor the rel_url are Absolute then NULL is returned.
* otherwise it tries and resolves the relative url with the base
* as described in: http://www.ietf.org/rfc/rfc2396.txt (RFCs
* explaining URIs)
* : resolution of '..' is NOT implemented, but '.' is resolved
*
* Return : char * ;
*
* Note :
************************************************************************/
char *
resolve_rel_url( char *base_url,
char *rel_url )
char *resolve_rel_url(char *base_url, char *rel_url)
{
uri_type base;
uri_type rel;
@ -994,8 +735,8 @@ resolve_rel_url( char *base_url,
if( remove_dots( out_finger,
strlen( out_finger ) ) !=
UPNP_E_SUCCESS ) {
free( out );
//free(rel_url);
free(out);
/* free(rel_url); */
return NULL;
}
}
@ -1003,46 +744,23 @@ resolve_rel_url( char *base_url,
}
}
} else {
free( out );
//free(rel_url);
free(out);
/* free(rel_url); */
return NULL;
}
}
} else {
free( out );
//free(rel_url);
free(out);
/* free(rel_url); */
return NULL;
}
//free(rel_url);
/* free(rel_url); */
return out;
}
/************************************************************************
* Function : parse_uri
*
* Parameters :
* char * in ; character string containing uri information to be
* parsed
* int max ; maximum limit on the number of characters
* uri_type * out ; out parameter which will have the parsed uri
* information
*
* Description : parses a uri as defined in http://www.ietf.org/rfc/
* rfc2396.txt (RFC explaining URIs)
* Handles absolute, relative, and opaque uris. Parses into the
* following pieces: scheme, hostport, pathquery, fragment (path and
* query are treated as one token)
* Caller should check for the pieces they require.
*
* Return : int ;
*
* Note :
************************************************************************/
int
parse_uri( const char *in,
int max,
uri_type * out )
int parse_uri(const char *in, int max, uri_type *out)
{
int begin_path = 0;
int begin_hostport = 0;
@ -1069,10 +787,7 @@ parse_uri( const char *in,
return begin_path;
} else {
out->hostport.IPv4address.sin_port = 0;
out->hostport.IPv4address.sin_addr.s_addr = 0;
out->hostport.text.size = 0;
out->hostport.text.buff = 0;
memset( &out->hostport, 0, sizeof(out->hostport) );
begin_path = begin_hostport;
}
@ -1095,33 +810,22 @@ parse_uri( const char *in,
return HTTP_SUCCESS;
}
/************************************************************************
* Function : parse_uri_and_unescape
*
* Parameters :
* char * in ;
* int max ;
* uri_type * out ;
*
* Description : Same as parse_uri, except that all strings are
* unescaped (%XX replaced by chars)
*
* Return : int ;
*
* Note: This modifies 'pathquery' and 'fragment' parts of the input
************************************************************************/
int
parse_uri_and_unescape( char *in,
int max,
uri_type *out )
{
int ret;
if( ( ret = parse_uri( in, max, out ) ) != HTTP_SUCCESS )
int parse_uri_and_unescape(char *in, int max, uri_type *out)
{
int ret = parse_uri(in, max, out);
if (ret != HTTP_SUCCESS) {
return ret;
if( out->pathquery.size > 0 )
remove_escaped_chars( (char *)out->pathquery.buff, &out->pathquery.size );
if( out->fragment.size > 0 )
remove_escaped_chars( (char *)out->fragment.buff, &out->fragment.size );
}
if (out->pathquery.size > 0) {
remove_escaped_chars((char *)out->pathquery.buff, &out->pathquery.size);
}
if (out->fragment.size > 0) {
remove_escaped_chars((char *)out->fragment.buff, &out->fragment.size);
}
return HTTP_SUCCESS;
}

View File

@ -1,314 +0,0 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
//
///////////////////////////////////////////////////////////////////////////
#ifndef _http_client_h_
#define _http_client_h_
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
#include "genlib/closesocket/upnpclosesocket.h"
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
//#include <malloc.h>
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include "tools/config.h"
#include "upnp.h"
//#include "upnp_debug.h"
#define HTTP_DATE_LENGTH 37 // length for HTTP DATE:
//"DATE: Sun, 01 Jul 2000 08:15:23 GMT<cr><lf>"
#define SEPARATORS "()<>@,;:\\\"/[]?={} \t"
#define MARK "-_.!~*'()"
#define RESERVED ";/?:@&=+$,"
#define HTTP_SUCCESS 1
#define HTTP_E_BAD_URL UPNP_E_INVALID_URL
#define HTTP_E_READ_SOCKET UPNP_E_SOCKET_READ
#define HTTP_E_BIND_SOCKET UPNP_E_SOCKET_BIND
#define HTTP_E_WRITE_SOCKET UPNP_E_SOCKET_WRITE
#define HTTP_E_CONNECT_SOCKET UPNP_E_SOCKET_CONNECT
#define HTTP_E_SOCKET UPNP_E_OUTOF_SOCKET
#define HTTP_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
#define HTTP_E_BAD_REQUEST UPNP_E_BAD_REQUEST
#define HTTP_E_BAD_IP_ADDRESS UPNP_E_INVALID_URL
#define FALSE 0
#define TAB 9
#define CR 13
#define LF 10
#define RESPONSE_TIMEOUT 30
#define SOCKET_BUFFER_SIZE 5000
enum hostType { HOSTNAME, IPv4address };
enum pathType { ABS_PATH, REL_PATH, OPAQUE_PART };
enum uriType { ABSOLUTE, RELATIVE };
//Buffer used to store data read from
//a socket during an http transfer
//in function read_bytes.
typedef struct SOCKET_BUFFER{
char buff[SOCKET_BUFFER_SIZE];
int size;
struct SOCKET_BUFFER *next;
} socket_buffer;
//Buffer used in parsing
//http messages, urls, etc.
//generally this simply
//holds a pointer into a larger array
typedef struct TOKEN {
char * buff;
size_t size;
} token;
//Represents a host port:
//e.g. :"127.127.0.1:80"
//text is a token pointing to
//the full string representation
typedef struct HOSTPORT {
token text; //full host port
struct sockaddr_in IPv4address; //Network Byte Order
} hostport_type;
//Represents a URI
//used in parse_uri and elsewhere
typedef struct URI{
enum uriType type;
token scheme;
enum pathType path_type;
token pathquery;
token fragment;
hostport_type hostport;
} uri_type;
//Represents a list of URLs as in
//the "callback" header of SUBSCRIBE
//message in GENA
//char * URLs holds dynamic memory
typedef struct URL_LIST {
int size;
char * URLs; //all the urls, delimited by <>
uri_type *parsedURLs;
} URL_list;
typedef struct HTTP_HEADER {
token header;
token value;
struct HTTP_HEADER * next;
} http_header;
typedef struct HTTP_STATUS_LINE{
token http_version;
token status_code;
token reason_phrase;
} http_status;
typedef struct HTTP_REQUEST_LINE {
token http_version;
uri_type request_uri;
token method;
} http_request;
//Represents a parsed HTTP_MESSAGE
//head_list is dynamically allocated
typedef struct HTTP_MESSAGE {
http_status status;
http_request request;
http_header * header_list;
token content;
} http_message;
EXTERN_C int transferHTTP( char * request, char * toSend,
int toSendSize, char **out, char * Url);
EXTERN_C int transferHTTPRaw( char * toSend, int toSendSize,
char **out, char *URL);
//helper function
EXTERN_C int transferHTTPparsedURL( char * request,
char * toSend, int toSendSize,
char **out, uri_type *URL);
//assumes that char * out has enough space ( 38 characters)
//outputs the current time in the following null terminated string:
// "DATE: Sun, Jul 06 2000 08:53:01 GMT\r\n"
EXTERN_C void currentTmToHttpDate(char *out);
//returns dynamic memory or NULL on error
EXTERN_C char * resolve_rel_url( char * base_url, char * rel_url);
EXTERN_C int parse_uri( char * in, int max, uri_type * out);
EXTERN_C int token_cmp( token *in1, token *in2);
EXTERN_C int token_string_casecmp( token * in1, char * in2);
EXTERN_C int token_string_cmp( token * in1, char * in2);
EXTERN_C int parse_http_response( char * in, http_message * out,
int max_len);
EXTERN_C int parse_http_request( char * in, http_message *out,
int max_len);
EXTERN_C int search_for_header( http_message * in,
char * header, token *out_value);
EXTERN_C int parse_hostport( char* in, int max, hostport_type *out );
EXTERN_C size_t write_bytes(int fd, char * bytes, size_t n,
int timeout);
EXTERN_C void free_http_message(http_message * message);
EXTERN_C int copy_URL_list( URL_list *in, URL_list *out);
EXTERN_C void free_URL_list(URL_list * list);
EXTERN_C int parse_port(int max, char * port, unsigned short int * out);
EXTERN_C int parse_http_line( char * in, int max_size);
EXTERN_C int parse_not_LWS( char *in, token *out, int max_size);
EXTERN_C int parse_LWS( char * in, int max_size);
EXTERN_C int parse_token( char * in, token * out, int max_size);
EXTERN_C ssize_t readLine(int fd, char *out, int max, int *timeout);
EXTERN_C int remove_dots(char * in, int size);
#ifdef DEBUG
EXTERN_C void print_http_request(
http_message *message,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_http_request(
http_message *message,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#ifdef DEBUG
EXTERN_C void print_http_response(
http_message *message,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_http_response(
http_message *message,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#ifdef DEBUG
EXTERN_C void print_token(
token *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_token(
token *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#ifdef DEBUG
EXTERN_C void print_status_line(
http_status *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_status_line(
http_status *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#ifdef DEBUG
EXTERN_C void print_request_line(
http_request *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_request_line(
http_request *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#ifdef DEBUG
EXTERN_C void print_uri(
uri_type *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo);
#else
static inline void print_uri(
uri_type *in,
Upnp_LogLevel DLevel,
Dbg_Module Module,
char *DbgFileName,
int DbgLineNo) {}
#endif
#endif

View File

@ -48,6 +48,7 @@ extern "C" {
#include "uri.h"
#include "ixml.h"
#include "upnp.h"
#include "upnpdebug.h"
#include <stdio.h>
@ -131,139 +132,100 @@ subscription *GetSubscriptionSID(
service_info *service);
//returns a pointer to the subscription with the SID, NULL if not found
/*!
* \brief Gets pointer to the first subscription node in the service table.
*
* \return Pointer to the first subscription node.
*/
subscription *GetFirstSubscription(
/*! [in] Service object providing the list of subscriptions. */
service_info *service);
subscription * CheckSubscriptionSID(Upnp_SID sid,service_info * service);
//returns a pointer to the first subscription
subscription * GetFirstSubscription(service_info *service);
/*!
* \brief Get current and valid subscription from the service table.
*
* \return Pointer to the next subscription node.
*/
subscription *GetNextSubscription(
/*! [in] Service object providing the list of subscriptions. */
service_info *service,
/*! [in] Current subscription object. */
subscription *current);
/************************************************************************
* Function : GetNextSubscription
*
* Parameters :
* service_info * service ; service object providing the list of
* subscriptions
* subscription *current ; current subscription object
*
* Description : Get current and valid subscription from the service
* table.
*
* Return : subscription * - Pointer to the next subscription node;
*
* Note :
************************************************************************/
subscription * GetNextSubscription(service_info * service, subscription *current);
/************************************************************************
* Function : freeSubscription
*
* Parameters :
* subscription * sub ; subscription to be freed
*
* Description : Free's the memory allocated for storing the URL of
* the subscription.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeSubscription(subscription * sub);
/*!
* \brief Free's the memory allocated for storing the URL of the subscription.
*/
void freeSubscription(
/*! [in] Subscription object to be freed. */
subscription *sub);
/************************************************************************
* Function : freeSubscriptionList
*
* Parameters :
* subscription * head ; head of the subscription list
*
* Description : Free's memory allocated for all the subscriptions
* in the service table.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeSubscriptionList(subscription * head);
/************************************************************************
* Function : FindServiceId
*
* Parameters :
* service_table *table ; service table
* const char * serviceId ;string representing the service id
* to be found among those in the table
* const char * UDN ; string representing the UDN
* to be found among those in the table
*
* Description : Traverses through the service table and returns a
* pointer to the service node that matches a known service id
* and a known UDN
*
* Return : service_info * - pointer to the matching service_info node;
*
* Note :
************************************************************************/
service_info *FindServiceId( service_table * table,
const char * serviceId, const char * UDN);
/*!
* \brief Free's memory allocated for all the subscriptions in the service table.
*/
void freeSubscriptionList(
/*! [in] Head of the subscription list. */
subscription * head);
/************************************************************************
* Function : FindServiceEventURLPath
*
* Parameters :
* service_table *table ; service table
* char * eventURLPath ; event URL path used to find a service
* from the table
*
* Description : Traverses the service table and finds the node whose
* event URL Path matches a know value
*
* Return : service_info * - pointer to the service list node from the
* service table whose event URL matches a known event URL;
*
* Note :
************************************************************************/
service_info * FindServiceEventURLPath( service_table *table,
char * eventURLPath
);
/************************************************************************
* Function : FindServiceControlURLPath
*
* Parameters :
* service_table * table ; service table
* char * controlURLPath ; control URL path used to find a service
* from the table
*
* Description : Traverses the service table and finds the node whose
* control URL Path matches a know value
*
* Return : service_info * - pointer to the service list node from the
* service table whose control URL Path matches a known value;
*
* Note :
************************************************************************/
service_info * FindServiceControlURLPath( service_table *table,
const char * controlURLPath);
/*!
* \brief Traverses through the service table and returns a pointer to the
* service node that matches a known service id and a known UDN.
*
* \return Pointer to the matching service_info node.
*/
service_info *FindServiceId(
/*! [in] Service table. */
service_table *table,
/*! [in] String representing the service id to be found among those
* in the table. */
const char *serviceId,
/*! [in] String representing the UDN to be found among those in the
* table. */
const char *UDN);
/************************************************************************
* Function : printService
*
* Parameters :
* service_info *service ;Service whose information is to be printed
* Upnp_LogLevel level ; Debug level specified to the print function
* Dbg_Module module ; Debug module specified to the print function
*
* Description : For debugging purposes prints information from the
* service passed into the function.
*
* Return : void ;
*
* Note :
************************************************************************/
/*!
* \brief Traverses the service table and finds the node whose event URL Path
* matches a know value.
*
* \return Pointer to the service list node from the service table whose event
* URL matches a known event URL.
*/
service_info *FindServiceEventURLPath(
/*! [in] Service table. */
service_table *table,
/*! [in] Event URL path used to find a service from the table. */
char *eventURLPath);
/*!
* \brief Traverses the service table and finds the node whose control URL Path
* matches a know value.
*
* \return Pointer to the service list node from the service table whose control
* URL Path matches a known value.
*/
service_info * FindServiceControlURLPath(
/*! [in] Service table. */
service_table *table,
/*! [in] Control URL path used to find a service from the table. */
const char *controlURLPath);
/*!
* \brief For debugging purposes prints information from the service passed
* into the function.
*/
#ifdef DEBUG
void printService(
/*! [in] Service whose information is to be printed. */
service_info *service,
/*! [in] Debug level specified to the print function. */
Upnp_LogLevel level,
/*! [in] Debug module specified to the print function. */
Dbg_Module module);
#else
static UPNP_INLINE void printService(
@ -272,25 +234,18 @@ static UPNP_INLINE void printService(
Dbg_Module module) {}
#endif
/************************************************************************
* Function : printServiceList
*
* Parameters :
* service_info *service ; Service whose information is to be printed
* Upnp_LogLevel level ; Debug level specified to the print function
* Dbg_Module module ; Debug module specified to the print function
*
* Description : For debugging purposes prints information of each
* service from the service table passed into the function.
*
* Return : void ;
*
* Note :
************************************************************************/
/*!
* \brief For debugging purposes prints information of each service from the
* service table passed into the function.
*/
#ifdef DEBUG
void printServiceList(
/*! [in] Service whose information is to be printed. */
service_info *service,
/*! [in] Debug level specified to the print function. */
Upnp_LogLevel level,
/*! [in] Debug module specified to the print function. */
Dbg_Module module);
#else
static UPNP_INLINE void printServiceList(
@ -299,26 +254,18 @@ static UPNP_INLINE void printServiceList(
Dbg_Module module) {}
#endif
/************************************************************************
* Function : printServiceTable
*
* Parameters :
* service_table * table ; Service table to be printed
* Upnp_LogLevel level ; Debug level specified to the print function
* Dbg_Module module ; Debug module specified to the print function
*
* Description : For debugging purposes prints the URL base of the table
* and information of each service from the service table passed into
* the function.
*
* Return : void ;
*
* Note :
************************************************************************/
/*!
* \brief For debugging purposes prints the URL base of the table and information
* of each service from the service table passed into the function.
*/
#ifdef DEBUG
void printServiceTable(
/*! [in] Service table to be printed. */
service_table *table,
/*! [in] Debug level specified to the print function. */
Upnp_LogLevel level,
/*! [in] Debug module specified to the print function. */
Dbg_Module module);
#else
static UPNP_INLINE void printServiceTable(
@ -327,149 +274,105 @@ static UPNP_INLINE void printServiceTable(
Dbg_Module module) {}
#endif
/************************************************************************
* Function : freeService
*
* Parameters :
* service_info *in ; service information that is to be freed
*
* Description : Free's memory allocated for the various components
* of the service entry in the service table.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeService(service_info * in);
/************************************************************************
* Function : freeServiceList
*
* Parameters :
* service_info * head ; Head of the service list to be freed
*
* Description : Free's memory allocated for the various components
* of each service entry in the service table.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeServiceList(service_info * head);
/*!
* \brief Free's memory allocated for the various components of the service
* entry in the service table.
*/
void freeService(
/*! [in] Service information that is to be freed. */
service_info *in);
/************************************************************************
* Function : freeServiceTable
*
* Parameters :
* service_table * table ; Service table whose memory needs to be
* freed
*
* Description : Free's dynamic memory in table.
* (does not free table, only memory within the structure)
*
* Return : void ;
*
* Note :
************************************************************************/
void freeServiceTable(service_table * table);
/*!
* \brief Free's memory allocated for the various components of each service
* entry in the service table.
*/
void freeServiceList(
/*! [in] Head of the service list to be freed. */
service_info *head);
/************************************************************************
* Function : removeServiceTable
*
* Parameters :
* IXML_Node *node ; XML node information
* service_table *in ; service table from which services will be
* removed
*
* Description : This function assumes that services for a particular
* root device are placed linearly in the service table, and in the
* order in which they are found in the description document
* all services for this root device are removed from the list
*
* Return : int ;
*
* Note :
************************************************************************/
int removeServiceTable(IXML_Node *node,
/*!
* \brief Free's dynamic memory in table (does not free table, only memory
* within the structure).
*/
void freeServiceTable(
/*! [in] Service table whose internal memory needs to be freed. */
service_table *table);
/*!
* \brief This function assumes that services for a particular root device are
* placed linearly in the service table, and in the order in which they are
* found in the description document all services for this root device are
* removed from the list.
*
* \return An integer.
*/
int removeServiceTable(
/*! [in] XML node information. */
IXML_Node *node,
/*! [in] Service table from which services will be removed. */
service_table *in);
/************************************************************************
* Function : addServiceTable
*
* Parameters :
* IXML_Node *node ; XML node information
* service_table *in ; service table that will be initialized with
* services
* const char *DefaultURLBase ; Default base URL on which the URL
* will be returned to the service list.
*
* Description : Add Service to the table.
*
* Return : int ;
*
* Note :
************************************************************************/
int addServiceTable(IXML_Node *node, service_table *in, const char *DefaultURLBase);
/*!
* \brief Add Service to the table.
*/
int addServiceTable(
/*! [in] XML node information. */
IXML_Node *node,
/*! [in] Service table that will be initialized with services. */
service_table *in,
/*! [in] Default base URL on which the URL will be returned to the
* service list. */
const char *DefaultURLBase);
/************************************************************************
* Function : getServiceTable
*
* Parameters :
* IXML_Node *node ; XML node information
* service_table *out ; output parameter which will contain the
* service list and URL
* const char *DefaultURLBase ; Default base URL on which the URL
* will be returned.
*
* Description : Retrieve service from the table
*
* Return : int ;
*
* Note :
************************************************************************/
int getServiceTable(IXML_Node *node, service_table * out, const char * DefaultURLBase);
/*!
* \brief Retrieve service from the table.
*
* \return An integer
*/
int getServiceTable(
/*! [in] XML node information. */
IXML_Node *node,
/*! [in] Output parameter which will contain the service list and URL. */
service_table *out,
/*! [in] Default base URL on which the URL will be returned. */
const char *DefaultURLBase);
/* Misc helper functions */
/************************************************************************
* Function : getElementValue
*
* Parameters :
* IXML_Node *node ; Input node which provides the list of child
* nodes
*
* Description : Returns the clone of the element value
*
* Return : DOMString ;
*
* Note : value must be freed with DOMString_free
************************************************************************/
DOMString getElementValue(IXML_Node *node);
/*!
* \brief Returns the clone of the element value.
*
* \note Value must be freed with DOMString_free.
*
* \return DOMString
*/
DOMString getElementValue(
/*! [in] Input node which provides the list of child nodes. */
IXML_Node *node);
/************************************************************************
* Function : getSubElement
*
* Parameters :
* const char *element_name ; sub element name to be searched for
* IXML_Node *node ; Input node which provides the list of child
* nodes
* IXML_Node **out ; Ouput node to which the matched child node is
* returned.
*
* Description : Traverses through a list of XML nodes to find the
* node with the known element name.
*
* Return : int ;
* 1 - On Success
* 0 - On Failure
*
* Note :
************************************************************************/
int getSubElement(const char *element_name, IXML_Node *node,
/*!
* \brief Traverses through a list of XML nodes to find the node with the
* known element name.
*
* \return
* \li 1 - On Success
* \li 0 - On Failure
*/
int getSubElement(
/*! [in] Sub element name to be searched for. */
const char *element_name,
/*! [in] Input node which provides the list of child nodes. */
IXML_Node *node,
/*! [out] Ouput node to which the matched child node is returned. */
IXML_Node **out);
@ -479,5 +382,5 @@ int getSubElement(const char *element_name, IXML_Node *node,
}
#endif
#endif /* _SERVICE_TABLE */
#endif /* SERVICE_TABLE */

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +1,62 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
*
**************************************************************************/
#include "config.h"
#ifdef INCLUDE_DEVICE_APIS
#if EXCLUDE_SSDP == 0
#include "httpparser.h"
#include "httpreadwrite.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "ThreadPool.h"
#include "unixutil.h"
#include "upnpapi.h"
#include "UpnpInet.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "ssdplib.h"
#include "upnpapi.h"
#include "ThreadPool.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "statcodes.h"
#include "unixutil.h"
#ifdef WIN32
#include <ws2tcpip.h>
#include <winsock2.h>
#endif /* WIN32 */
#define MSGTYPE_SHUTDOWN 0
#define MSGTYPE_ADVERTISEMENT 1
#define MSGTYPE_REPLY 2
/************************************************************************
* Function : advertiseAndReplyThread
*
@ -88,7 +90,7 @@ advertiseAndReplyThread( IN void *data )
* Function : ssdp_handle_device_request
*
* Parameters:
* IN http_message_t* hmsg: SSDP search request from the control point
* IN http_message_t *hmsg: SSDP search request from the control point
* IN struct sockaddr_in* dest_addr: The address info of control point
*
* Description:
@ -101,7 +103,7 @@ advertiseAndReplyThread( IN void *data )
***************************************************************************/
#ifdef INCLUDE_DEVICE_APIS
void
ssdp_handle_device_request( IN http_message_t * hmsg,
ssdp_handle_device_request( IN http_message_t *hmsg,
IN struct sockaddr_in *dest_addr )
{
#define MX_FUDGE_FACTOR 10
@ -397,7 +399,7 @@ DeviceAdvertisement( IN char *DevType,
int ret_code;
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
"In function SendDeviceAdvertisemenrt\n" );
"In function DeviceAdvertisement\n" );
DestAddr.sin_family = AF_INET;
DestAddr.sin_addr.s_addr = inet_addr( SSDP_IP );
@ -550,7 +552,7 @@ DeviceReply( IN struct sockaddr_in *DestAddr,
IN int RootDev,
IN char *Udn,
IN char *Location,
IN int Duration )
IN int Duration)
{
char *szReq[3],
Mil_Nt[LINE_SIZE],
@ -624,7 +626,7 @@ int
ServiceAdvertisement( IN char *Udn,
IN char *ServType,
IN char *Location,
IN int Duration )
IN int Duration)
{
char Mil_Usn[LINE_SIZE];
char *szReq[1];
@ -713,7 +715,7 @@ int
ServiceShutdown( IN char *Udn,
IN char *ServType,
IN char *Location,
IN int Duration )
IN int Duration)
{
char Mil_Usn[LINE_SIZE];
char *szReq[1];
@ -762,7 +764,7 @@ DeviceShutdown( IN char *DevType,
IN char *Udn,
IN char *_Server,
IN char *Location,
IN int Duration )
IN int Duration)
{
struct sockaddr_in DestAddr;
char *msgs[3];

View File

@ -1,51 +1,60 @@
///////////////////////////////////////////////////////////////////////////
//
// 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.
*
**************************************************************************/
#include "config.h"
#include <assert.h>
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include "membuffer.h"
#include "unixutil.h"
#include "upnp.h"
#include "upnpdebug.h"
#include "UpnpInet.h"
#include "uri.h"
#include "urlconfig.h"
#include "util.h"
#include "webserver.h"
#include "uri.h"
#include "membuffer.h"
#include "urlconfig.h"
#include "unixutil.h"
#include <assert.h>
#include <stdio.h>
#ifdef WIN32
#else
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#endif
/************************************************************************
* Function : addrToString