Removes C++ style comments.

This commit is contained in:
Marcelo Roberto Jimenez 2010-11-16 03:14:12 -02:00
parent 7c524df1d9
commit 5d6bcabd45
48 changed files with 1895 additions and 2087 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net> * Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -33,32 +33,27 @@
#ifndef UPNP_DEBUG_H #ifndef UPNP_DEBUG_H
#define UPNP_DEBUG_H #define UPNP_DEBUG_H
/*! /*!
* \file * \file
*/ */
#include "ThreadPool.h" #include "ThreadPool.h"
#include "upnpconfig.h" #include "upnpconfig.h"
#include "UpnpGlobal.h" /* for UPNP_INLINE */ #include "UpnpGlobal.h" /* for UPNP_INLINE */
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*! \name Other debugging features
/** \name Other debugging features
* *
* The UPnP SDK contains other features to aid in debugging. * The UPnP SDK contains other features to aid in debugging.
*/ */
/*@{*/ /*@{*/
/** \name Upnp_LogLevel /*! \name Upnp_LogLevel
* The user has the option to select 4 different types of debugging levels, * The user has the option to select 4 different types of debugging levels,
* see \c UpnpSetLogLevel. * see \c UpnpSetLogLevel.
* The critical level will show only those messages * The critical level will show only those messages
@ -85,7 +80,6 @@ typedef enum Upnp_Module {
HTTP HTTP
} Dbg_Module; } Dbg_Module;
/*@{*/ /*@{*/
typedef enum Upnp_LogLevel_e { typedef enum Upnp_LogLevel_e {
UPNP_CRITICAL, UPNP_CRITICAL,
@ -95,14 +89,11 @@ typedef enum Upnp_LogLevel_e {
} Upnp_LogLevel; } Upnp_LogLevel;
/*@}*/ /*@}*/
/*!
/**
* Default log level : see \c Upnp_LogLevel * Default log level : see \c Upnp_LogLevel
*/ */
#define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
/*! /*!
* \brief Initialize the log files. * \brief Initialize the log files.
* *
@ -117,7 +108,6 @@ static UPNP_INLINE int UpnpInitLog(void)
} }
#endif #endif
/*! /*!
* \brief Set the log level (see \c Upnp_LogLevel). * \brief Set the log level (see \c Upnp_LogLevel).
*/ */
@ -126,10 +116,13 @@ void UpnpSetLogLevel(
/*! [in] Log level. */ /*! [in] Log level. */
Upnp_LogLevel log_level); Upnp_LogLevel log_level);
#else #else
static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level) {} static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level)
{
return;
log_level = log_level;
}
#endif #endif
/*! /*!
* \brief Closes the log files. * \brief Closes the log files.
*/ */
@ -139,7 +132,6 @@ void UpnpCloseLog(void);
static UPNP_INLINE void UpnpCloseLog(void) {} static UPNP_INLINE void UpnpCloseLog(void) {}
#endif #endif
/*! /*!
* \brief Set the name for error and information files, respectively. * \brief Set the name for error and information files, respectively.
*/ */
@ -152,10 +144,14 @@ void UpnpSetLogFileNames(
#else #else
static UPNP_INLINE void UpnpSetLogFileNames( static UPNP_INLINE void UpnpSetLogFileNames(
const char *ErrFileName, const char *ErrFileName,
const char *InfoFileName) {} const char *InfoFileName)
{
return;
ErrFileName = ErrFileName;
InfoFileName = InfoFileName;
}
#endif #endif
/*! /*!
* \brief Check if the module is turned on for debug and returns the file * \brief Check if the module is turned on for debug and returns the file
* descriptor corresponding to the debug level * descriptor corresponding to the debug level
@ -174,6 +170,8 @@ FILE *UpnpGetDebugFile(
static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module) static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
{ {
return NULL; return NULL;
level = level;
module = module;
} }
#endif #endif
@ -196,6 +194,8 @@ static UPNP_INLINE int DebugAtThisLevel(
Dbg_Module Module) Dbg_Module Module)
{ {
return 0; return 0;
DLevel = DLevel;
Module = Module;
} }
#endif #endif
@ -234,6 +234,12 @@ static UPNP_INLINE void UpnpPrintf(
const char* FmtStr, const char* FmtStr,
...) ...)
{ {
return;
DLevel = DLevel;
Module = Module;
DbgFileName = DbgFileName;
DbgLineNo = DbgLineNo;
FmtStr = FmtStr;
} }
#endif /* DEBUG */ #endif /* DEBUG */
@ -254,7 +260,13 @@ void UpnpDisplayFileAndLine(
static UPNP_INLINE void UpnpDisplayFileAndLine( static UPNP_INLINE void UpnpDisplayFileAndLine(
FILE *fd, FILE *fd,
const char *DbgFileName, const char *DbgFileName,
int DbgLineNo) {} int DbgLineNo)
{
return;
fd = fd;
DbgFileName = DbgFileName;
DbgLineNo = DbgLineNo;
}
#endif #endif
@ -276,7 +288,14 @@ static UPNP_INLINE void UpnpDisplayBanner(
FILE *fd, FILE *fd,
const char **lines, const char **lines,
size_t size, size_t size,
int starlength) {} int starlength)
{
return;
fd = fd;
lines = lines;
size = size;
starlength = starlength;
}
#endif #endif
@ -300,10 +319,14 @@ static UPNP_INLINE void PrintThreadPoolStats(
int DbgLineNo, int DbgLineNo,
const char *msg) const char *msg)
{ {
return;
tp = tp;
DbgFileName = DbgFileName;
DbgLineNo = DbgLineNo;
msg = msg;
} }
#endif #endif
/*@}*/ /*@}*/
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -191,7 +191,7 @@ int SampleUtil_FindAndParseService (
********************************************************************************/ ********************************************************************************/
typedef void (*print_string)(const char *string); typedef void (*print_string)(const char *string);
//global print function used by sample util /*global print function used by sample util */
extern print_string gPrintFun; extern print_string gPrintFun;
/******************************************************************************** /********************************************************************************
@ -212,7 +212,7 @@ typedef void (*state_update)(
const char *UDN, const char *UDN,
eventType type); eventType type);
//global state update function used by smaple util /*global state update function used by smaple util */
extern state_update gStateUpdateFun; extern state_update gStateUpdateFun;
/******************************************************************************** /********************************************************************************

View File

@ -52,10 +52,10 @@ enum cmdloop_tvcmds {
Data structure for parsing commands from the command line Data structure for parsing commands from the command line
*/ */
struct cmdloop_commands { struct cmdloop_commands {
char *str; // the string char *str; /* the string */
int cmdnum; // the command int cmdnum; /* the command */
int numargs; // the number of arguments int numargs; /* the number of arguments */
char *args; // the args char *args; /* the args */
} cmdloop_commands; } cmdloop_commands;
/* /*
@ -417,7 +417,7 @@ device_main( int argc, char **argv )
SampleUtil_Initialize( linux_print ); SampleUtil_Initialize( linux_print );
// Parse options /* Parse options */
for( i = 1; i < argc; i++ ) { for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-ip" ) == 0 ) { if( strcmp( argv[i], "-ip" ) == 0 ) {
ip_address = argv[++i]; ip_address = argv[++i];

View File

@ -125,7 +125,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
} }
} }
//Notify New Device Added /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, node->device.UDN, DEVICE_REMOVED ); SampleUtil_StateUpdate( NULL, NULL, node->device.UDN, DEVICE_REMOVED );
free( node ); free( node );
node = NULL; node = NULL;
@ -374,7 +374,7 @@ TvCtrlPointSendAction( int service,
param_val[param] ) != UPNP_E_SUCCESS ) { param_val[param] ) != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print
( "ERROR: TvCtrlPointSendAction: Trying to add action param" ); ( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
//return -1; // TBD - BAD! leaves mutex locked /*return -1; // TBD - BAD! leaves mutex locked */
} }
} }
} }
@ -716,7 +716,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
if( strcmp( deviceType, TvDeviceType ) == 0 ) { if( strcmp( deviceType, TvDeviceType ) == 0 ) {
SampleUtil_Print( "Found Tv device" ); SampleUtil_Print( "Found Tv device" );
// Check if this device is already in the list /* Check if this device is already in the list */
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
if( strcmp( tmpdevnode->device.UDN, UDN ) == 0 ) { if( strcmp( tmpdevnode->device.UDN, UDN ) == 0 ) {
@ -727,8 +727,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
} }
if( found ) { if( found ) {
// The device is already there, so just update /* The device is already there, so just update */
// the advertisement timeout field /* the advertisement timeout field */
tmpdevnode->device.AdvrTimeOut = expires; tmpdevnode->device.AdvrTimeOut = expires;
} else { } else {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
@ -794,7 +794,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
deviceNode->next = NULL; deviceNode->next = NULL;
// Insert the new device node in the list /* Insert the new device node in the list */
if( ( tmpdevnode = GlobalDeviceList ) ) { if( ( tmpdevnode = GlobalDeviceList ) ) {
while( tmpdevnode ) { while( tmpdevnode ) {
@ -809,7 +809,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
GlobalDeviceList = deviceNode; GlobalDeviceList = deviceNode;
} }
//Notify New Device Added /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN, SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN,
DEVICE_ADDED ); DEVICE_ADDED );
} }
@ -1219,7 +1219,7 @@ TvCtrlPointVerifyTimeouts( int incr )
while( curdevnode ) { while( curdevnode ) {
curdevnode->device.AdvrTimeOut -= incr; curdevnode->device.AdvrTimeOut -= incr;
//SampleUtil_Print("Advertisement Timeout: %d\n", curdevnode->device.AdvrTimeOut); /*SampleUtil_Print("Advertisement Timeout: %d\n", curdevnode->device.AdvrTimeOut); */
if( curdevnode->device.AdvrTimeOut <= 0 ) { if( curdevnode->device.AdvrTimeOut <= 0 ) {
/* /*
@ -1275,7 +1275,7 @@ TvCtrlPointVerifyTimeouts( int incr )
static int TvCtrlPointTimerLoopRun = 1; static int TvCtrlPointTimerLoopRun = 1;
void *TvCtrlPointTimerLoop(void *args) void *TvCtrlPointTimerLoop(void *args)
{ {
int incr = 30; // how often to verify the timeouts, in seconds int incr = 30; /* how often to verify the timeouts, in seconds */
while (TvCtrlPointTimerLoopRun) { while (TvCtrlPointTimerLoopRun) {
isleep( incr ); isleep( incr );

View File

@ -168,4 +168,5 @@ int TvCtrlPointProcessCommand(char *cmdline);
}; };
#endif #endif
#endif //UPNP_TV_CTRLPT_H #endif /*UPNP_TV_CTRLPT_H */

View File

@ -92,31 +92,31 @@ UpnpDevice_Handle device_handle = -1;
*/ */
ithread_mutex_t TVDevMutex; ithread_mutex_t TVDevMutex;
//Color constants /*Color constants */
#define MAX_COLOR 10 #define MAX_COLOR 10
#define MIN_COLOR 1 #define MIN_COLOR 1
//Brightness constants /*Brightness constants */
#define MAX_BRIGHTNESS 10 #define MAX_BRIGHTNESS 10
#define MIN_BRIGHTNESS 1 #define MIN_BRIGHTNESS 1
//Power constants /*Power constants */
#define POWER_ON 1 #define POWER_ON 1
#define POWER_OFF 0 #define POWER_OFF 0
//Tint constants /*Tint constants */
#define MAX_TINT 10 #define MAX_TINT 10
#define MIN_TINT 1 #define MIN_TINT 1
//Volume constants /*Volume constants */
#define MAX_VOLUME 10 #define MAX_VOLUME 10
#define MIN_VOLUME 1 #define MIN_VOLUME 1
//Contrast constants /*Contrast constants */
#define MAX_CONTRAST 10 #define MAX_CONTRAST 10
#define MIN_CONTRAST 1 #define MIN_CONTRAST 1
//Channel constants /*Channel constants */
#define MAX_CHANNEL 100 #define MAX_CHANNEL 100
#define MIN_CHANNEL 1 #define MIN_CHANNEL 1
@ -287,7 +287,7 @@ TvDeviceStateTableInit( IN char *DescDocURL )
*ctrlurl_pict = NULL; *ctrlurl_pict = NULL;
char *udn = NULL; char *udn = NULL;
//Download description document /*Download description document */
if( UpnpDownloadXmlDoc( DescDocURL, &DescDoc ) != UPNP_E_SUCCESS ) { if( UpnpDownloadXmlDoc( DescDocURL, &DescDoc ) != UPNP_E_SUCCESS ) {
SampleUtil_Print( "TvDeviceStateTableInit -- Error Parsing %s\n", SampleUtil_Print( "TvDeviceStateTableInit -- Error Parsing %s\n",
DescDocURL ); DescDocURL );
@ -312,7 +312,7 @@ TvDeviceStateTableInit( IN char *DescDocURL )
goto error_handler; goto error_handler;
} }
//set control service table /*set control service table */
SetServiceTable( TV_SERVICE_CONTROL, udn, servid_ctrl, SetServiceTable( TV_SERVICE_CONTROL, udn, servid_ctrl,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
&tv_service_table[TV_SERVICE_CONTROL] ); &tv_service_table[TV_SERVICE_CONTROL] );
@ -331,14 +331,14 @@ TvDeviceStateTableInit( IN char *DescDocURL )
ret = UPNP_E_INVALID_DESC; ret = UPNP_E_INVALID_DESC;
goto error_handler; goto error_handler;
} }
//set picture service table /*set picture service table */
SetServiceTable( TV_SERVICE_PICTURE, udn, servid_pict, SetServiceTable( TV_SERVICE_PICTURE, udn, servid_pict,
TvServiceType[TV_SERVICE_PICTURE], TvServiceType[TV_SERVICE_PICTURE],
&tv_service_table[TV_SERVICE_PICTURE] ); &tv_service_table[TV_SERVICE_PICTURE] );
error_handler: error_handler:
//clean up /*clean up */
if( udn ) if( udn )
free( udn ); free( udn );
if( servid_ctrl ) if( servid_ctrl )
@ -380,7 +380,7 @@ int TvDeviceHandleSubscriptionRequest(IN struct Upnp_Subscription_Request *sr_ev
const char *l_udn = NULL; const char *l_udn = NULL;
const char *l_sid = NULL; const char *l_sid = NULL;
// lock state mutex /* lock state mutex */
ithread_mutex_lock(&TVDevMutex); ithread_mutex_lock(&TVDevMutex);
l_serviceId = sr_event->ServiceId; l_serviceId = sr_event->ServiceId;
@ -394,22 +394,22 @@ int TvDeviceHandleSubscriptionRequest(IN struct Upnp_Subscription_Request *sr_ev
PropSet = NULL; PropSet = NULL;
for (j = 0; j< tv_service_table[i].VariableCount; ++j) { for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
// add each variable to the property set /* add each variable to the property set */
// for initial state dump /* for initial state dump */
UpnpAddToPropertySet( UpnpAddToPropertySet(
&PropSet, &PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state /* dump initial state */
UpnpAcceptSubscriptionExt( UpnpAcceptSubscriptionExt(
device_handle, device_handle,
l_udn, l_udn,
l_serviceId, l_serviceId,
PropSet, PropSet,
l_sid); l_sid);
// free document /* free document */
Document_free(PropSet); Document_free(PropSet);
#endif #endif
UpnpAcceptSubscription( UpnpAcceptSubscription(
@ -454,14 +454,14 @@ int TvDeviceHandleGetVarRequest(INOUT struct Upnp_State_Var_Request *cgv_event)
ithread_mutex_lock(&TVDevMutex); ithread_mutex_lock(&TVDevMutex);
for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) { for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) {
// check udn and service id /* check udn and service id */
const char *devUDN = const char *devUDN =
cgv_event->DevUDN; cgv_event->DevUDN;
const char *serviceID = const char *serviceID =
cgv_event->ServiceID; cgv_event->ServiceID;
if (strcmp(devUDN, tv_service_table[i].UDN) == 0 && if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
strcmp(serviceID, tv_service_table[i].ServiceId) == 0) { strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name /* check variable name */
for (j = 0; j < tv_service_table[i].VariableCount; j++) { for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName = const char *stateVarName =
cgv_event->StateVarName; cgv_event->StateVarName;
@ -561,7 +561,7 @@ int TvDeviceHandleActionRequest(INOUT struct Upnp_Action_Request *ca_event)
if (retCode == UPNP_E_SUCCESS) { if (retCode == UPNP_E_SUCCESS) {
ca_event->ErrCode = UPNP_E_SUCCESS; ca_event->ErrCode = UPNP_E_SUCCESS;
} else { } else {
// copy the error string /* copy the error string */
strcpy(ca_event->ErrStr, errorString); strcpy(ca_event->ErrStr, errorString);
switch (retCode) { switch (retCode) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
@ -601,7 +601,7 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
IN unsigned int variable, IN unsigned int variable,
IN char *value ) IN char *value )
{ {
//IXML_Document *PropSet= NULL; /*IXML_Document *PropSet= NULL; */
if( ( service >= TV_SERVICE_SERVCOUNT ) if( ( service >= TV_SERVICE_SERVCOUNT )
|| ( variable >= tv_service_table[service].VariableCount ) || ( variable >= tv_service_table[service].VariableCount )
@ -613,8 +613,8 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
strcpy( tv_service_table[service].VariableStrVal[variable], value ); strcpy( tv_service_table[service].VariableStrVal[variable], value );
/* #if 0
//Using utility api /*Using utility api */
PropSet= UpnpCreatePropertySet(1,tv_service_table[service]. PropSet= UpnpCreatePropertySet(1,tv_service_table[service].
VariableName[variable], VariableName[variable],
tv_service_table[service]. tv_service_table[service].
@ -623,9 +623,9 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
UpnpNotifyExt(device_handle, tv_service_table[service].UDN, UpnpNotifyExt(device_handle, tv_service_table[service].UDN,
tv_service_table[service].ServiceId,PropSet); tv_service_table[service].ServiceId,PropSet);
//Free created property set /*Free created property set */
Document_free(PropSet); Document_free(PropSet);
*/ #endif
UpnpNotify( device_handle, UpnpNotify( device_handle,
tv_service_table[service].UDN, tv_service_table[service].UDN,
@ -694,7 +694,7 @@ TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **error
( *errorString ) = NULL; ( *errorString ) = NULL;
if( TvDeviceSetPower( POWER_ON ) ) { if( TvDeviceSetPower( POWER_ON ) ) {
//create a response /*create a response */
if( UpnpAddToActionResponse( out, "PowerOn", if( UpnpAddToActionResponse( out, "PowerOn",
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
@ -731,7 +731,7 @@ TvDevicePowerOff( IN IXML_Document * in,
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
if( TvDeviceSetPower( POWER_OFF ) ) { if( TvDeviceSetPower( POWER_OFF ) ) {
//create a response /*create a response */
if( UpnpAddToActionResponse( out, "PowerOff", if( UpnpAddToActionResponse( out, "PowerOff",
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],

View File

@ -61,74 +61,74 @@ extern "C" {
#endif #endif
//Color constants /*Color constants */
#define MAX_COLOR 10 #define MAX_COLOR 10
#define MIN_COLOR 1 #define MIN_COLOR 1
//Brightness constants /*Brightness constants */
#define MAX_BRIGHTNESS 10 #define MAX_BRIGHTNESS 10
#define MIN_BRIGHTNESS 1 #define MIN_BRIGHTNESS 1
//Power constants /*Power constants */
#define POWER_ON 1 #define POWER_ON 1
#define POWER_OFF 0 #define POWER_OFF 0
//Tint constants /*Tint constants */
#define MAX_TINT 10 #define MAX_TINT 10
#define MIN_TINT 1 #define MIN_TINT 1
//Volume constants /*Volume constants */
#define MAX_VOLUME 10 #define MAX_VOLUME 10
#define MIN_VOLUME 1 #define MIN_VOLUME 1
//Contrast constants /*Contrast constants */
#define MAX_CONTRAST 10 #define MAX_CONTRAST 10
#define MIN_CONTRAST 1 #define MIN_CONTRAST 1
//Channel constants /*Channel constants */
#define MAX_CHANNEL 100 #define MAX_CHANNEL 100
#define MIN_CHANNEL 1 #define MIN_CHANNEL 1
//Number of services. /*Number of services. */
#define TV_SERVICE_SERVCOUNT 2 #define TV_SERVICE_SERVCOUNT 2
//Index of control service /*Index of control service */
#define TV_SERVICE_CONTROL 0 #define TV_SERVICE_CONTROL 0
//Index of picture service /*Index of picture service */
#define TV_SERVICE_PICTURE 1 #define TV_SERVICE_PICTURE 1
//Number of control variables /*Number of control variables */
#define TV_CONTROL_VARCOUNT 3 #define TV_CONTROL_VARCOUNT 3
//Index of power variable /*Index of power variable */
#define TV_CONTROL_POWER 0 #define TV_CONTROL_POWER 0
//Index of channel variable /*Index of channel variable */
#define TV_CONTROL_CHANNEL 1 #define TV_CONTROL_CHANNEL 1
//Index of volume variable /*Index of volume variable */
#define TV_CONTROL_VOLUME 2 #define TV_CONTROL_VOLUME 2
//Number of picture variables /*Number of picture variables */
#define TV_PICTURE_VARCOUNT 4 #define TV_PICTURE_VARCOUNT 4
//Index of color variable /*Index of color variable */
#define TV_PICTURE_COLOR 0 #define TV_PICTURE_COLOR 0
//Index of tint variable /*Index of tint variable */
#define TV_PICTURE_TINT 1 #define TV_PICTURE_TINT 1
//Index of contrast variable /*Index of contrast variable */
#define TV_PICTURE_CONTRAST 2 #define TV_PICTURE_CONTRAST 2
//Index of brightness variable /*Index of brightness variable */
#define TV_PICTURE_BRIGHTNESS 3 #define TV_PICTURE_BRIGHTNESS 3
//Max value length /*Max value length */
#define TV_MAX_VAL_LEN 5 #define TV_MAX_VAL_LEN 5
//Max actions /*Max actions */
#define TV_MAXACTIONS 12 #define TV_MAXACTIONS 12
/* This should be the maximum VARCOUNT from above */ /* This should be the maximum VARCOUNT from above */
@ -177,10 +177,10 @@ struct TvService {
unsigned int VariableCount; unsigned int VariableCount;
}; };
//Array of service structures /*Array of service structures */
extern struct TvService tv_service_table[]; extern struct TvService tv_service_table[];
//Device handle returned from sdk /*Device handle returned from sdk */
extern UpnpDevice_Handle device_handle; extern UpnpDevice_Handle device_handle;
@ -310,7 +310,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType, void*, void*);
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*); int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
//Control Service Actions /*Control Service Actions */
/****************************************************************************** /******************************************************************************
* TvDevicePowerOn * TvDevicePowerOn
@ -436,7 +436,7 @@ int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT ch
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
//Picture Service Actions /*Picture Service Actions */
/****************************************************************************** /******************************************************************************
* TvDeviceSetColor * TvDeviceSetColor

View File

@ -51,10 +51,10 @@ enum cmdloop_tvcmds {
Data structure for parsing commands from the command line Data structure for parsing commands from the command line
*/ */
struct cmdloop_commands { struct cmdloop_commands {
char *str; // the string char *str; /* the string */
int cmdnum; // the command int cmdnum; /* the command */
int numargs; // the number of arguments int numargs; /* the number of arguments */
char *args; // the args char *args; /* the args */
} cmdloop_commands; } cmdloop_commands;
/* /*

View File

@ -125,7 +125,7 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
} }
} }
//Notify New Device Added /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, node->device.UDN, DEVICE_REMOVED ); SampleUtil_StateUpdate( NULL, NULL, node->device.UDN, DEVICE_REMOVED );
free( node ); free( node );
node = NULL; node = NULL;
@ -374,7 +374,7 @@ TvCtrlPointSendAction( int service,
param_val[param] ) != UPNP_E_SUCCESS ) { param_val[param] ) != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print
( "ERROR: TvCtrlPointSendAction: Trying to add action param" ); ( "ERROR: TvCtrlPointSendAction: Trying to add action param" );
//return -1; // TBD - BAD! leaves mutex locked /*return -1; // TBD - BAD! leaves mutex locked */
} }
} }
} }
@ -716,7 +716,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
if( strcmp( deviceType, TvDeviceType ) == 0 ) { if( strcmp( deviceType, TvDeviceType ) == 0 ) {
SampleUtil_Print( "Found Tv device" ); SampleUtil_Print( "Found Tv device" );
// Check if this device is already in the list /* Check if this device is already in the list */
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while( tmpdevnode ) {
if( strcmp( tmpdevnode->device.UDN, UDN ) == 0 ) { if( strcmp( tmpdevnode->device.UDN, UDN ) == 0 ) {
@ -727,8 +727,8 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
} }
if( found ) { if( found ) {
// The device is already there, so just update /* The device is already there, so just update */
// the advertisement timeout field /* the advertisement timeout field */
tmpdevnode->device.AdvrTimeOut = expires; tmpdevnode->device.AdvrTimeOut = expires;
} else { } else {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) {
@ -794,7 +794,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
deviceNode->next = NULL; deviceNode->next = NULL;
// Insert the new device node in the list /* Insert the new device node in the list */
if( ( tmpdevnode = GlobalDeviceList ) ) { if( ( tmpdevnode = GlobalDeviceList ) ) {
while( tmpdevnode ) { while( tmpdevnode ) {
@ -809,7 +809,7 @@ TvCtrlPointAddDevice( IXML_Document *DescDoc,
GlobalDeviceList = deviceNode; GlobalDeviceList = deviceNode;
} }
//Notify New Device Added /*Notify New Device Added */
SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN, SampleUtil_StateUpdate( NULL, NULL, deviceNode->device.UDN,
DEVICE_ADDED ); DEVICE_ADDED );
} }
@ -1219,7 +1219,7 @@ TvCtrlPointVerifyTimeouts( int incr )
while( curdevnode ) { while( curdevnode ) {
curdevnode->device.AdvrTimeOut -= incr; curdevnode->device.AdvrTimeOut -= incr;
//SampleUtil_Print("Advertisement Timeout: %d\n", curdevnode->device.AdvrTimeOut); /*SampleUtil_Print("Advertisement Timeout: %d\n", curdevnode->device.AdvrTimeOut); */
if( curdevnode->device.AdvrTimeOut <= 0 ) { if( curdevnode->device.AdvrTimeOut <= 0 ) {
/* /*
@ -1275,7 +1275,7 @@ TvCtrlPointVerifyTimeouts( int incr )
static int TvCtrlPointTimerLoopRun = 1; static int TvCtrlPointTimerLoopRun = 1;
void *TvCtrlPointTimerLoop(void *args) void *TvCtrlPointTimerLoop(void *args)
{ {
int incr = 30; // how often to verify the timeouts, in seconds int incr = 30; /* how often to verify the timeouts, in seconds */
while (TvCtrlPointTimerLoopRun) { while (TvCtrlPointTimerLoopRun) {
isleep( incr ); isleep( incr );

View File

@ -79,7 +79,7 @@ TvDeviceCommandLoop( void *args )
SampleUtil_Print( "\n>> " ); SampleUtil_Print( "\n>> " );
// Get a command line /* Get a command line */
fgets( cmdline, 100, stdin ); fgets( cmdline, 100, stdin );
sscanf( cmdline, "%s", cmd ); sscanf( cmdline, "%s", cmd );
@ -141,7 +141,7 @@ int main( IN int argc, IN char **argv )
SampleUtil_Initialize( linux_print ); SampleUtil_Initialize( linux_print );
// Parse options /* Parse options */
for( i = 1; i < argc; i++ ) { for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-ip" ) == 0 ) { if( strcmp( argv[i], "-ip" ) == 0 ) {
ip_address = argv[++i]; ip_address = argv[++i];

View File

@ -94,31 +94,31 @@ UpnpDevice_Handle device_handle = -1;
*/ */
ithread_mutex_t TVDevMutex; ithread_mutex_t TVDevMutex;
//Color constants /*Color constants */
#define MAX_COLOR 10 #define MAX_COLOR 10
#define MIN_COLOR 1 #define MIN_COLOR 1
//Brightness constants /*Brightness constants */
#define MAX_BRIGHTNESS 10 #define MAX_BRIGHTNESS 10
#define MIN_BRIGHTNESS 1 #define MIN_BRIGHTNESS 1
//Power constants /*Power constants */
#define POWER_ON 1 #define POWER_ON 1
#define POWER_OFF 0 #define POWER_OFF 0
//Tint constants /*Tint constants */
#define MAX_TINT 10 #define MAX_TINT 10
#define MIN_TINT 1 #define MIN_TINT 1
//Volume constants /*Volume constants */
#define MAX_VOLUME 10 #define MAX_VOLUME 10
#define MIN_VOLUME 1 #define MIN_VOLUME 1
//Contrast constants /*Contrast constants */
#define MAX_CONTRAST 10 #define MAX_CONTRAST 10
#define MIN_CONTRAST 1 #define MIN_CONTRAST 1
//Channel constants /*Channel constants */
#define MAX_CHANNEL 100 #define MAX_CHANNEL 100
#define MIN_CHANNEL 1 #define MIN_CHANNEL 1
@ -289,7 +289,7 @@ TvDeviceStateTableInit( IN char *DescDocURL )
*ctrlurl_pict = NULL; *ctrlurl_pict = NULL;
char *udn = NULL; char *udn = NULL;
//Download description document /*Download description document */
if( UpnpDownloadXmlDoc( DescDocURL, &DescDoc ) != UPNP_E_SUCCESS ) { if( UpnpDownloadXmlDoc( DescDocURL, &DescDoc ) != UPNP_E_SUCCESS ) {
SampleUtil_Print( "TvDeviceStateTableInit -- Error Parsing %s\n", SampleUtil_Print( "TvDeviceStateTableInit -- Error Parsing %s\n",
DescDocURL ); DescDocURL );
@ -314,7 +314,7 @@ TvDeviceStateTableInit( IN char *DescDocURL )
goto error_handler; goto error_handler;
} }
//set control service table /*set control service table */
SetServiceTable( TV_SERVICE_CONTROL, udn, servid_ctrl, SetServiceTable( TV_SERVICE_CONTROL, udn, servid_ctrl,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
&tv_service_table[TV_SERVICE_CONTROL] ); &tv_service_table[TV_SERVICE_CONTROL] );
@ -333,14 +333,14 @@ TvDeviceStateTableInit( IN char *DescDocURL )
ret = UPNP_E_INVALID_DESC; ret = UPNP_E_INVALID_DESC;
goto error_handler; goto error_handler;
} }
//set picture service table /*set picture service table */
SetServiceTable( TV_SERVICE_PICTURE, udn, servid_pict, SetServiceTable( TV_SERVICE_PICTURE, udn, servid_pict,
TvServiceType[TV_SERVICE_PICTURE], TvServiceType[TV_SERVICE_PICTURE],
&tv_service_table[TV_SERVICE_PICTURE] ); &tv_service_table[TV_SERVICE_PICTURE] );
error_handler: error_handler:
//clean up /*clean up */
if( udn ) if( udn )
free( udn ); free( udn );
if( servid_ctrl ) if( servid_ctrl )
@ -382,7 +382,7 @@ int TvDeviceHandleSubscriptionRequest(IN struct Upnp_Subscription_Request *sr_ev
const char *l_udn = NULL; const char *l_udn = NULL;
const char *l_sid = NULL; const char *l_sid = NULL;
// lock state mutex /* lock state mutex */
ithread_mutex_lock(&TVDevMutex); ithread_mutex_lock(&TVDevMutex);
l_serviceId = sr_event->ServiceId; l_serviceId = sr_event->ServiceId;
@ -396,22 +396,22 @@ int TvDeviceHandleSubscriptionRequest(IN struct Upnp_Subscription_Request *sr_ev
PropSet = NULL; PropSet = NULL;
for (j = 0; j< tv_service_table[i].VariableCount; ++j) { for (j = 0; j< tv_service_table[i].VariableCount; ++j) {
// add each variable to the property set /* add each variable to the property set */
// for initial state dump /* for initial state dump */
UpnpAddToPropertySet( UpnpAddToPropertySet(
&PropSet, &PropSet,
tv_service_table[i].VariableName[j], tv_service_table[i].VariableName[j],
tv_service_table[i].VariableStrVal[j]); tv_service_table[i].VariableStrVal[j]);
} }
// dump initial state /* dump initial state */
UpnpAcceptSubscriptionExt( UpnpAcceptSubscriptionExt(
device_handle, device_handle,
l_udn, l_udn,
l_serviceId, l_serviceId,
PropSet, PropSet,
l_sid); l_sid);
// free document /* free document */
Document_free(PropSet); Document_free(PropSet);
#endif #endif
UpnpAcceptSubscription( UpnpAcceptSubscription(
@ -456,14 +456,14 @@ int TvDeviceHandleGetVarRequest(INOUT struct Upnp_State_Var_Request *cgv_event)
ithread_mutex_lock(&TVDevMutex); ithread_mutex_lock(&TVDevMutex);
for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) { for (i = 0; i < TV_SERVICE_SERVCOUNT; i++) {
// check udn and service id /* check udn and service id */
const char *devUDN = const char *devUDN =
cgv_event->DevUDN; cgv_event->DevUDN;
const char *serviceID = const char *serviceID =
cgv_event->ServiceID; cgv_event->ServiceID;
if (strcmp(devUDN, tv_service_table[i].UDN) == 0 && if (strcmp(devUDN, tv_service_table[i].UDN) == 0 &&
strcmp(serviceID, tv_service_table[i].ServiceId) == 0) { strcmp(serviceID, tv_service_table[i].ServiceId) == 0) {
// check variable name /* check variable name */
for (j = 0; j < tv_service_table[i].VariableCount; j++) { for (j = 0; j < tv_service_table[i].VariableCount; j++) {
const char *stateVarName = const char *stateVarName =
cgv_event->StateVarName; cgv_event->StateVarName;
@ -563,7 +563,7 @@ int TvDeviceHandleActionRequest(INOUT struct Upnp_Action_Request *ca_event)
if (retCode == UPNP_E_SUCCESS) { if (retCode == UPNP_E_SUCCESS) {
ca_event->ErrCode = UPNP_E_SUCCESS; ca_event->ErrCode = UPNP_E_SUCCESS;
} else { } else {
// copy the error string /* copy the error string */
strcpy(ca_event->ErrStr, errorString); strcpy(ca_event->ErrStr, errorString);
switch (retCode) { switch (retCode) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
@ -603,7 +603,7 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
IN unsigned int variable, IN unsigned int variable,
IN char *value ) IN char *value )
{ {
//IXML_Document *PropSet= NULL; /*IXML_Document *PropSet= NULL; */
if( ( service >= TV_SERVICE_SERVCOUNT ) if( ( service >= TV_SERVICE_SERVCOUNT )
|| ( variable >= tv_service_table[service].VariableCount ) || ( variable >= tv_service_table[service].VariableCount )
@ -615,8 +615,8 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
strcpy( tv_service_table[service].VariableStrVal[variable], value ); strcpy( tv_service_table[service].VariableStrVal[variable], value );
/* #if 0
//Using utility api /*Using utility api */
PropSet= UpnpCreatePropertySet(1,tv_service_table[service]. PropSet= UpnpCreatePropertySet(1,tv_service_table[service].
VariableName[variable], VariableName[variable],
tv_service_table[service]. tv_service_table[service].
@ -625,9 +625,9 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
UpnpNotifyExt(device_handle, tv_service_table[service].UDN, UpnpNotifyExt(device_handle, tv_service_table[service].UDN,
tv_service_table[service].ServiceId,PropSet); tv_service_table[service].ServiceId,PropSet);
//Free created property set /*Free created property set */
Document_free(PropSet); Document_free(PropSet);
*/ #endif
UpnpNotify( device_handle, UpnpNotify( device_handle,
tv_service_table[service].UDN, tv_service_table[service].UDN,
@ -696,7 +696,7 @@ TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **error
( *errorString ) = NULL; ( *errorString ) = NULL;
if( TvDeviceSetPower( POWER_ON ) ) { if( TvDeviceSetPower( POWER_ON ) ) {
//create a response /*create a response */
if( UpnpAddToActionResponse( out, "PowerOn", if( UpnpAddToActionResponse( out, "PowerOn",
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
@ -733,7 +733,7 @@ TvDevicePowerOff( IN IXML_Document * in,
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
if( TvDeviceSetPower( POWER_OFF ) ) { if( TvDeviceSetPower( POWER_OFF ) ) {
//create a response /*create a response */
if( UpnpAddToActionResponse( out, "PowerOff", if( UpnpAddToActionResponse( out, "PowerOff",
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],

View File

@ -61,74 +61,74 @@ extern "C" {
#endif #endif
//Color constants /*Color constants */
#define MAX_COLOR 10 #define MAX_COLOR 10
#define MIN_COLOR 1 #define MIN_COLOR 1
//Brightness constants /*Brightness constants */
#define MAX_BRIGHTNESS 10 #define MAX_BRIGHTNESS 10
#define MIN_BRIGHTNESS 1 #define MIN_BRIGHTNESS 1
//Power constants /*Power constants */
#define POWER_ON 1 #define POWER_ON 1
#define POWER_OFF 0 #define POWER_OFF 0
//Tint constants /*Tint constants */
#define MAX_TINT 10 #define MAX_TINT 10
#define MIN_TINT 1 #define MIN_TINT 1
//Volume constants /*Volume constants */
#define MAX_VOLUME 10 #define MAX_VOLUME 10
#define MIN_VOLUME 1 #define MIN_VOLUME 1
//Contrast constants /*Contrast constants */
#define MAX_CONTRAST 10 #define MAX_CONTRAST 10
#define MIN_CONTRAST 1 #define MIN_CONTRAST 1
//Channel constants /*Channel constants */
#define MAX_CHANNEL 100 #define MAX_CHANNEL 100
#define MIN_CHANNEL 1 #define MIN_CHANNEL 1
//Number of services. /*Number of services. */
#define TV_SERVICE_SERVCOUNT 2 #define TV_SERVICE_SERVCOUNT 2
//Index of control service /*Index of control service */
#define TV_SERVICE_CONTROL 0 #define TV_SERVICE_CONTROL 0
//Index of picture service /*Index of picture service */
#define TV_SERVICE_PICTURE 1 #define TV_SERVICE_PICTURE 1
//Number of control variables /*Number of control variables */
#define TV_CONTROL_VARCOUNT 3 #define TV_CONTROL_VARCOUNT 3
//Index of power variable /*Index of power variable */
#define TV_CONTROL_POWER 0 #define TV_CONTROL_POWER 0
//Index of channel variable /*Index of channel variable */
#define TV_CONTROL_CHANNEL 1 #define TV_CONTROL_CHANNEL 1
//Index of volume variable /*Index of volume variable */
#define TV_CONTROL_VOLUME 2 #define TV_CONTROL_VOLUME 2
//Number of picture variables /*Number of picture variables */
#define TV_PICTURE_VARCOUNT 4 #define TV_PICTURE_VARCOUNT 4
//Index of color variable /*Index of color variable */
#define TV_PICTURE_COLOR 0 #define TV_PICTURE_COLOR 0
//Index of tint variable /*Index of tint variable */
#define TV_PICTURE_TINT 1 #define TV_PICTURE_TINT 1
//Index of contrast variable /*Index of contrast variable */
#define TV_PICTURE_CONTRAST 2 #define TV_PICTURE_CONTRAST 2
//Index of brightness variable /*Index of brightness variable */
#define TV_PICTURE_BRIGHTNESS 3 #define TV_PICTURE_BRIGHTNESS 3
//Max value length /*Max value length */
#define TV_MAX_VAL_LEN 5 #define TV_MAX_VAL_LEN 5
//Max actions /*Max actions */
#define TV_MAXACTIONS 12 #define TV_MAXACTIONS 12
/* This should be the maximum VARCOUNT from above */ /* This should be the maximum VARCOUNT from above */
@ -177,10 +177,10 @@ struct TvService {
unsigned int VariableCount; unsigned int VariableCount;
}; };
//Array of service structures /*Array of service structures */
extern struct TvService tv_service_table[]; extern struct TvService tv_service_table[];
//Device handle returned from sdk /*Device handle returned from sdk */
extern UpnpDevice_Handle device_handle; extern UpnpDevice_Handle device_handle;
@ -310,7 +310,7 @@ int TvDeviceCallbackEventHandler(Upnp_EventType, void*, void*);
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*); int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
//Control Service Actions /*Control Service Actions */
/****************************************************************************** /******************************************************************************
* TvDevicePowerOn * TvDevicePowerOn
@ -436,7 +436,7 @@ int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT ch
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
//Picture Service Actions /*Picture Service Actions */
/****************************************************************************** /******************************************************************************
* TvDeviceSetColor * TvDeviceSetColor

View File

@ -66,7 +66,7 @@ struct SUpnpString
UpnpString *UpnpString_new() UpnpString *UpnpString_new()
{ {
// All bytes are zero, and so is the length of the string. /* All bytes are zero, and so is the length of the string. */
struct SUpnpString *p = calloc(1, sizeof (struct SUpnpString)); struct SUpnpString *p = calloc(1, sizeof (struct SUpnpString));
if (p == NULL) { if (p == NULL) {
goto error_handler1; goto error_handler1;
@ -75,7 +75,7 @@ UpnpString *UpnpString_new()
p->m_length = 0; p->m_length = 0;
#endif #endif
// This byte is zero, calloc does initialize it. /* This byte is zero, calloc does initialize it. */
p->m_string = calloc(1, 1); p->m_string = calloc(1, 1);
if (p->m_string == NULL) { if (p->m_string == NULL) {
goto error_handler2; goto error_handler2;
@ -83,7 +83,7 @@ UpnpString *UpnpString_new()
return (UpnpString *)p; return (UpnpString *)p;
//free(p->m_string); /*free(p->m_string); */
error_handler2: error_handler2:
free(p); free(p);
error_handler1: error_handler1:
@ -120,7 +120,7 @@ UpnpString *UpnpString_dup(const UpnpString *p)
return (UpnpString *)q; return (UpnpString *)q;
//free(q->m_string); /*free(q->m_string); */
error_handler2: error_handler2:
free(q); free(q);
error_handler1: error_handler1:

View File

@ -925,7 +925,7 @@ int UpnpRegisterRootDevice2(
} }
HandleTable[*Hnd] = HInfo; HandleTable[*Hnd] = HInfo;
// prevent accidental removal of a non-existent alias /* prevent accidental removal of a non-existent alias */
HInfo->aliasInstalled = 0; HInfo->aliasInstalled = 0;
retVal = GetDescDocumentAndURL( retVal = GetDescDocumentAndURL(
@ -1189,7 +1189,7 @@ int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
HandleUnlock(); HandleUnlock();
return UPNP_E_INVALID_HANDLE; return UPNP_E_INVALID_HANDLE;
} }
//info = (struct Handle_Info *) HandleTable[Hnd]; /*info = (struct Handle_Info *) HandleTable[Hnd]; */
ixmlNodeList_free( HInfo->DeviceList ); ixmlNodeList_free( HInfo->DeviceList );
ixmlNodeList_free( HInfo->ServiceList ); ixmlNodeList_free( HInfo->ServiceList );
ixmlDocument_free( HInfo->DescDocument ); ixmlDocument_free( HInfo->DescDocument );
@ -1202,7 +1202,7 @@ int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
if( HInfo->aliasInstalled ) { if( HInfo->aliasInstalled ) {
web_server_set_alias( NULL, NULL, 0, 0 ); web_server_set_alias( NULL, NULL, 0, 0 );
} }
#endif // INTERNAL_WEB_SERVER #endif /* INTERNAL_WEB_SERVER */
if( HInfo->DeviceAf == AF_INET ) { if( HInfo->DeviceAf == AF_INET ) {
UpnpSdkDeviceRegisteredV4 = 0; UpnpSdkDeviceRegisteredV4 = 0;
@ -2973,9 +2973,9 @@ int UpnpDownloadXmlDoc(const char *url, IXML_Document **xmlDoc)
int UpnpGetIfInfo(const char *IfName) int UpnpGetIfInfo(const char *IfName)
{ {
#ifdef WIN32 #ifdef WIN32
// ---------------------------------------------------- /* ---------------------------------------------------- */
// WIN32 implementation will use the IpHlpAPI library. /* WIN32 implementation will use the IpHlpAPI library. */
// ---------------------------------------------------- /* ---------------------------------------------------- */
PIP_ADAPTER_ADDRESSES adapts = NULL; PIP_ADAPTER_ADDRESSES adapts = NULL;
PIP_ADAPTER_ADDRESSES adapts_item; PIP_ADAPTER_ADDRESSES adapts_item;
PIP_ADAPTER_UNICAST_ADDRESS uni_addr; PIP_ADAPTER_UNICAST_ADDRESS uni_addr;
@ -2987,7 +2987,7 @@ int UpnpGetIfInfo(const char *IfName)
int ifname_found = 0; int ifname_found = 0;
int valid_addr_found = 0; int valid_addr_found = 0;
// Get Adapters addresses required size. /* Get Adapters addresses required size. */
ret = GetAdaptersAddresses(AF_UNSPEC, ret = GetAdaptersAddresses(AF_UNSPEC,
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_DNS_SERVER, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_DNS_SERVER,
NULL, adapts, &adapts_sz ); NULL, adapts, &adapts_sz );
@ -2997,13 +2997,13 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INIT; return UPNP_E_INIT;
} }
// Allocate enough memory. /* Allocate enough memory. */
adapts = (PIP_ADAPTER_ADDRESSES)malloc( adapts_sz ); adapts = (PIP_ADAPTER_ADDRESSES)malloc( adapts_sz );
if( adapts == NULL ) { if( adapts == NULL ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// Do the call that will actually return the info. /* Do the call that will actually return the info. */
ret = GetAdaptersAddresses( AF_UNSPEC, ret = GetAdaptersAddresses( AF_UNSPEC,
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_DNS_SERVER, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_DNS_SERVER,
NULL, adapts, &adapts_sz ); NULL, adapts, &adapts_sz );
@ -3014,7 +3014,7 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INIT; return UPNP_E_INIT;
} }
// Copy interface name, if it was provided. /* Copy interface name, if it was provided. */
if( IfName != NULL ) { if( IfName != NULL ) {
if( strlen(IfName) > sizeof(gIF_NAME) ) if( strlen(IfName) > sizeof(gIF_NAME) )
return UPNP_E_INVALID_INTERFACE; return UPNP_E_INVALID_INTERFACE;
@ -3031,17 +3031,17 @@ int UpnpGetIfInfo(const char *IfName)
} }
if( ifname_found == 0 ) { if( ifname_found == 0 ) {
// We have found a valid interface name. Keep it. /* We have found a valid interface name. Keep it. */
strncpy( gIF_NAME, adapts_item->FriendlyName, sizeof(gIF_NAME) ); strncpy( gIF_NAME, adapts_item->FriendlyName, sizeof(gIF_NAME) );
ifname_found = 1; ifname_found = 1;
} else { } else {
if( strncmp( gIF_NAME, adapts_item->FriendlyName, sizeof(gIF_NAME) ) != 0 ) { if( strncmp( gIF_NAME, adapts_item->FriendlyName, sizeof(gIF_NAME) ) != 0 ) {
// This is not the interface we're looking for. /* This is not the interface we're looking for. */
continue; continue;
} }
} }
// Loop thru this adapter's unicast IP addresses. /* Loop thru this adapter's unicast IP addresses. */
uni_addr = adapts_item->FirstUnicastAddress; uni_addr = adapts_item->FirstUnicastAddress;
while( uni_addr ) { while( uni_addr ) {
ip_addr = uni_addr->Address.lpSockaddr; ip_addr = uni_addr->Address.lpSockaddr;
@ -3051,7 +3051,7 @@ int UpnpGetIfInfo(const char *IfName)
valid_addr_found = 1; valid_addr_found = 1;
break; break;
case AF_INET6: case AF_INET6:
// Only keep IPv6 link-local addresses. /* Only keep IPv6 link-local addresses. */
if( IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)ip_addr)->sin6_addr) ) { if( IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)ip_addr)->sin6_addr) ) {
memcpy( &v6_addr, &((struct sockaddr_in6 *)ip_addr)->sin6_addr, sizeof(v6_addr) ); memcpy( &v6_addr, &((struct sockaddr_in6 *)ip_addr)->sin6_addr, sizeof(v6_addr) );
valid_addr_found = 1; valid_addr_found = 1;
@ -3059,14 +3059,14 @@ int UpnpGetIfInfo(const char *IfName)
break; break;
default: default:
if( valid_addr_found == 0 ) { if( valid_addr_found == 0 ) {
// Address is not IPv4 or IPv6 and no valid address has /* Address is not IPv4 or IPv6 and no valid address has */
// yet been found for this interface. Discard interface name. /* yet been found for this interface. Discard interface name. */
ifname_found = 0; ifname_found = 0;
} }
break; break;
} }
// Next address. /* Next address. */
uni_addr = uni_addr->Next; uni_addr = uni_addr->Next;
} }
@ -3075,11 +3075,11 @@ int UpnpGetIfInfo(const char *IfName)
break; break;
} }
// Next adapter. /* Next adapter. */
adapts_item = adapts_item->Next; adapts_item = adapts_item->Next;
} }
// Failed to find a valid interface, or valid address. /* Failed to find a valid interface, or valid address. */
if( ifname_found == 0 || valid_addr_found == 0 ) { if( ifname_found == 0 || valid_addr_found == 0 ) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"Failed to find an adapter with valid IP addresses for use.\n" ); "Failed to find an adapter with valid IP addresses for use.\n" );
@ -3095,7 +3095,7 @@ int UpnpGetIfInfo(const char *IfName)
int ifname_found = 0; int ifname_found = 0;
int valid_addr_found = 0; int valid_addr_found = 0;
// Copy interface name, if it was provided. /* Copy interface name, if it was provided. */
if( IfName != NULL ) { if( IfName != NULL ) {
if( strlen(IfName) > sizeof(gIF_NAME) ) if( strlen(IfName) > sizeof(gIF_NAME) )
return UPNP_E_INVALID_INTERFACE; return UPNP_E_INVALID_INTERFACE;
@ -3104,18 +3104,18 @@ int UpnpGetIfInfo(const char *IfName)
ifname_found = 1; ifname_found = 1;
} }
// Get system interface addresses. /* Get system interface addresses. */
if( getifaddrs(&ifap) != 0 ) { if( getifaddrs(&ifap) != 0 ) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"getifaddrs failed to find list of addresses\n" ); "getifaddrs failed to find list of addresses\n" );
return UPNP_E_INIT; return UPNP_E_INIT;
} }
// cycle through available interfaces and their addresses. /* cycle through available interfaces and their addresses. */
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next)
{ {
// Skip LOOPBACK interfaces, DOWN interfaces and interfaces that /* Skip LOOPBACK interfaces, DOWN interfaces and interfaces that */
// don't support MULTICAST. /* don't support MULTICAST. */
if( ( ifa->ifa_flags & IFF_LOOPBACK ) if( ( ifa->ifa_flags & IFF_LOOPBACK )
|| ( !( ifa->ifa_flags & IFF_UP ) ) || ( !( ifa->ifa_flags & IFF_UP ) )
|| ( !( ifa->ifa_flags & IFF_MULTICAST ) ) ) { || ( !( ifa->ifa_flags & IFF_MULTICAST ) ) ) {
@ -3123,17 +3123,17 @@ int UpnpGetIfInfo(const char *IfName)
} }
if( ifname_found == 0 ) { if( ifname_found == 0 ) {
// We have found a valid interface name. Keep it. /* We have found a valid interface name. Keep it. */
strncpy( gIF_NAME, ifa->ifa_name, sizeof(gIF_NAME) ); strncpy( gIF_NAME, ifa->ifa_name, sizeof(gIF_NAME) );
ifname_found = 1; ifname_found = 1;
} else { } else {
if( strncmp( gIF_NAME, ifa->ifa_name, sizeof(gIF_NAME) ) != 0 ) { if( strncmp( gIF_NAME, ifa->ifa_name, sizeof(gIF_NAME) ) != 0 ) {
// This is not the interface we're looking for. /* This is not the interface we're looking for. */
continue; continue;
} }
} }
// Keep interface addresses for later. /* Keep interface addresses for later. */
switch( ifa->ifa_addr->sa_family ) switch( ifa->ifa_addr->sa_family )
{ {
case AF_INET: case AF_INET:
@ -3141,7 +3141,7 @@ int UpnpGetIfInfo(const char *IfName)
valid_addr_found = 1; valid_addr_found = 1;
break; break;
case AF_INET6: case AF_INET6:
// Only keep IPv6 link-local addresses. /* Only keep IPv6 link-local addresses. */
if( IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr) ) { if( IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr) ) {
memcpy( &v6_addr, &((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr, sizeof(v6_addr) ); memcpy( &v6_addr, &((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr, sizeof(v6_addr) );
valid_addr_found = 1; valid_addr_found = 1;
@ -3149,8 +3149,8 @@ int UpnpGetIfInfo(const char *IfName)
break; break;
default: default:
if( valid_addr_found == 0 ) { if( valid_addr_found == 0 ) {
// Address is not IPv4 or IPv6 and no valid address has /* Address is not IPv4 or IPv6 and no valid address has */
// yet been found for this interface. Discard interface name. /* yet been found for this interface. Discard interface name. */
ifname_found = 0; ifname_found = 0;
} }
break; break;
@ -3158,7 +3158,7 @@ int UpnpGetIfInfo(const char *IfName)
} }
freeifaddrs(ifap); freeifaddrs(ifap);
// Failed to find a valid interface, or valid address. /* Failed to find a valid interface, or valid address. */
if( ifname_found == 0 || valid_addr_found == 0 ) { if( ifname_found == 0 || valid_addr_found == 0 ) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"Failed to find an adapter with valid IP addresses for use.\n" ); "Failed to find an adapter with valid IP addresses for use.\n" );
@ -3178,11 +3178,11 @@ int UpnpGetIfInfo(const char *IfName)
struct in6_addr v6_addr; struct in6_addr v6_addr;
int if_idx; int if_idx;
char addr6[8][5]; char addr6[8][5];
char buf[65]; // INET6_ADDRSTRLEN char buf[65]; /* INET6_ADDRSTRLEN */
int ifname_found = 0; int ifname_found = 0;
int valid_addr_found = 0; int valid_addr_found = 0;
// Copy interface name, if it was provided. /* Copy interface name, if it was provided. */
if( IfName != NULL ) { if( IfName != NULL ) {
if( strlen(IfName) > sizeof(gIF_NAME) ) if( strlen(IfName) > sizeof(gIF_NAME) )
return UPNP_E_INVALID_INTERFACE; return UPNP_E_INVALID_INTERFACE;
@ -3191,14 +3191,14 @@ int UpnpGetIfInfo(const char *IfName)
ifname_found = 1; ifname_found = 1;
} }
// Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. /* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
if( ( LocalSock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) { if( ( LocalSock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) {
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Can't create addrlist socket\n" ); "Can't create addrlist socket\n" );
return UPNP_E_INIT; return UPNP_E_INIT;
} }
// Get the interface configuration information... /* Get the interface configuration information... */
ifConf.ifc_len = sizeof szBuffer; ifConf.ifc_len = sizeof szBuffer;
ifConf.ifc_ifcu.ifcu_buf = ( caddr_t ) szBuffer; ifConf.ifc_ifcu.ifcu_buf = ( caddr_t ) szBuffer;
@ -3208,13 +3208,13 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INIT; return UPNP_E_INIT;
} }
// Cycle through the list of interfaces looking for IP addresses. /* Cycle through the list of interfaces looking for IP addresses. */
for( i = 0; i < ifConf.ifc_len ; ) { for( i = 0; i < ifConf.ifc_len ; ) {
struct ifreq *pifReq = struct ifreq *pifReq =
( struct ifreq * )( ( caddr_t ) ifConf.ifc_req + i ); ( struct ifreq * )( ( caddr_t ) ifConf.ifc_req + i );
i += sizeof *pifReq; i += sizeof *pifReq;
// See if this is the sort of interface we want to deal with. /* See if this is the sort of interface we want to deal with. */
strcpy( ifReq.ifr_name, pifReq->ifr_name ); strcpy( ifReq.ifr_name, pifReq->ifr_name );
if( ioctl( LocalSock, SIOCGIFFLAGS, &ifReq ) < 0 ) { if( ioctl( LocalSock, SIOCGIFFLAGS, &ifReq ) < 0 ) {
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
@ -3222,8 +3222,8 @@ int UpnpGetIfInfo(const char *IfName)
ifReq.ifr_name ); ifReq.ifr_name );
} }
// Skip LOOPBACK interfaces, DOWN interfaces and interfaces that /* Skip LOOPBACK interfaces, DOWN interfaces and interfaces that */
// don't support MULTICAST. /* don't support MULTICAST. */
if( ( ifReq.ifr_flags & IFF_LOOPBACK ) if( ( ifReq.ifr_flags & IFF_LOOPBACK )
|| ( !( ifReq.ifr_flags & IFF_UP ) ) || ( !( ifReq.ifr_flags & IFF_UP ) )
|| ( !( ifReq.ifr_flags & IFF_MULTICAST ) ) ) { || ( !( ifReq.ifr_flags & IFF_MULTICAST ) ) ) {
@ -3231,19 +3231,19 @@ int UpnpGetIfInfo(const char *IfName)
} }
if( ifname_found == 0 ) { if( ifname_found == 0 ) {
// We have found a valid interface name. Keep it. /* We have found a valid interface name. Keep it. */
strncpy( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) ); strncpy( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) );
ifname_found = 1; ifname_found = 1;
} else { } else {
if( strncmp( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) ) != 0 ) { if( strncmp( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) ) != 0 ) {
// This is not the interface we're looking for. /* This is not the interface we're looking for. */
continue; continue;
} }
} }
// Check address family. /* Check address family. */
if( pifReq->ifr_addr.sa_family == AF_INET ) { if( pifReq->ifr_addr.sa_family == AF_INET ) {
// Copy interface name, IPv4 address and interface index. /* Copy interface name, IPv4 address and interface index. */
strncpy( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) ); strncpy( gIF_NAME, pifReq->ifr_name, sizeof(gIF_NAME) );
inet_ntop(AF_INET, &((struct sockaddr_in*)&pifReq->ifr_addr)->sin_addr, gIF_IPV4, sizeof(gIF_IPV4)); inet_ntop(AF_INET, &((struct sockaddr_in*)&pifReq->ifr_addr)->sin_addr, gIF_IPV4, sizeof(gIF_IPV4));
gIF_INDEX = if_nametoindex(gIF_NAME); gIF_INDEX = if_nametoindex(gIF_NAME);
@ -3251,13 +3251,13 @@ int UpnpGetIfInfo(const char *IfName)
valid_addr_found = 1; valid_addr_found = 1;
break; break;
} else { } else {
// Address is not IPv4 /* Address is not IPv4 */
ifname_found = 0; ifname_found = 0;
} }
} }
close( LocalSock ); close( LocalSock );
// Failed to find a valid interface, or valid address. /* Failed to find a valid interface, or valid address. */
if (ifname_found == 0 || valid_addr_found == 0) { if (ifname_found == 0 || valid_addr_found == 0) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"Failed to find an adapter with valid IP addresses for use.\n"); "Failed to find an adapter with valid IP addresses for use.\n");
@ -3265,31 +3265,31 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INVALID_INTERFACE; return UPNP_E_INVALID_INTERFACE;
} }
// Try to get the IPv6 address for the same interface /* Try to get the IPv6 address for the same interface */
// from "/proc/net/if_inet6", if possible. /* from "/proc/net/if_inet6", if possible. */
inet6_procfd = fopen("/proc/net/if_inet6", "r"); inet6_procfd = fopen("/proc/net/if_inet6", "r");
if (inet6_procfd) { if (inet6_procfd) {
while (fscanf(inet6_procfd, while (fscanf(inet6_procfd,
"%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*20s\n", "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*20s\n",
addr6[0],addr6[1],addr6[2],addr6[3], addr6[0],addr6[1],addr6[2],addr6[3],
addr6[4],addr6[5],addr6[6],addr6[7], &if_idx) != EOF) { addr6[4],addr6[5],addr6[6],addr6[7], &if_idx) != EOF) {
// Get same interface as IPv4 address retrieved. /* Get same interface as IPv4 address retrieved. */
if( gIF_INDEX == if_idx ) { if( gIF_INDEX == if_idx ) {
snprintf(buf, sizeof(buf), "%s:%s:%s:%s:%s:%s:%s:%s", snprintf(buf, sizeof(buf), "%s:%s:%s:%s:%s:%s:%s:%s",
addr6[0],addr6[1],addr6[2],addr6[3], addr6[0],addr6[1],addr6[2],addr6[3],
addr6[4],addr6[5],addr6[6],addr6[7]); addr6[4],addr6[5],addr6[6],addr6[7]);
// Validate formed address and check for link-local. /* Validate formed address and check for link-local. */
if (inet_pton(AF_INET6, buf, &v6_addr) > 0) { if (inet_pton(AF_INET6, buf, &v6_addr) > 0) {
if (IN6_IS_ADDR_ULA(&v6_addr)) { if (IN6_IS_ADDR_ULA(&v6_addr)) {
// Got valid IPv6 ula. /* Got valid IPv6 ula. */
strncpy(gIF_IPV6_ULA_GUA, buf, sizeof(gIF_IPV6_ULA_GUA)); strncpy(gIF_IPV6_ULA_GUA, buf, sizeof(gIF_IPV6_ULA_GUA));
} else if (IN6_IS_ADDR_GLOBAL(&v6_addr) && } else if (IN6_IS_ADDR_GLOBAL(&v6_addr) &&
strlen(gIF_IPV6_ULA_GUA) == 0) { strlen(gIF_IPV6_ULA_GUA) == 0) {
// got a GUA, should store it while no ULA is found /* got a GUA, should store it while no ULA is found */
strncpy(gIF_IPV6_ULA_GUA, buf, sizeof(gIF_IPV6_ULA_GUA)); strncpy(gIF_IPV6_ULA_GUA, buf, sizeof(gIF_IPV6_ULA_GUA));
} else if (IN6_IS_ADDR_LINKLOCAL(&v6_addr) && } else if (IN6_IS_ADDR_LINKLOCAL(&v6_addr) &&
strlen(gIF_IPV6) == 0) { strlen(gIF_IPV6) == 0) {
// got a Link local IPv6 address. /* got a Link local IPv6 address. */
strncpy(gIF_IPV6, buf, sizeof(gIF_IPV6)); strncpy(gIF_IPV6, buf, sizeof(gIF_IPV6));
} }
} }
@ -3710,7 +3710,7 @@ int UpnpAddVirtualDir(const char *newDirName)
char dirName[NAME_SIZE]; char dirName[NAME_SIZE];
if( UpnpSdkInit != 1 ) { if( UpnpSdkInit != 1 ) {
// SDK is not initialized /* SDK is not initialized */
return UPNP_E_FINISH; return UPNP_E_FINISH;
} }
@ -3727,7 +3727,7 @@ int UpnpAddVirtualDir(const char *newDirName)
pCurVirtualDir = pVirtualDirList; pCurVirtualDir = pVirtualDirList;
while( pCurVirtualDir != NULL ) { while( pCurVirtualDir != NULL ) {
// already has this entry /* already has this entry */
if( strcmp( pCurVirtualDir->dirName, dirName ) == 0 ) { if( strcmp( pCurVirtualDir->dirName, dirName ) == 0 ) {
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -3744,7 +3744,7 @@ int UpnpAddVirtualDir(const char *newDirName)
strcpy( pNewVirtualDir->dirName, dirName ); strcpy( pNewVirtualDir->dirName, dirName );
*( pNewVirtualDir->dirName + strlen( dirName ) ) = 0; *( pNewVirtualDir->dirName + strlen( dirName ) ) = 0;
if( pVirtualDirList == NULL ) { // first virtual dir if( pVirtualDirList == NULL ) { /* first virtual dir */
pVirtualDirList = pNewVirtualDir; pVirtualDirList = pNewVirtualDir;
} else { } else {
pLast = pVirtualDirList; pLast = pVirtualDirList;
@ -3775,11 +3775,8 @@ int UpnpRemoveVirtualDir(const char *dirName)
if( pVirtualDirList == NULL ) { if( pVirtualDirList == NULL ) {
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
// /* Handle the special case where the directory that we are */
// Handle the special case where the directory that we are /* removing is the first and only one in the list. */
// removing is the first and only one in the list.
//
if( ( pVirtualDirList->next == NULL ) && if( ( pVirtualDirList->next == NULL ) &&
( strcmp( pVirtualDirList->dirName, dirName ) == 0 ) ) { ( strcmp( pVirtualDirList->dirName, dirName ) == 0 ) ) {
free( pVirtualDirList ); free( pVirtualDirList );

View File

@ -314,7 +314,7 @@ static IXML_Document *makeAction(
} }
if (NumArg > 0) { if (NumArg > 0) {
//va_start(ArgList, Arg); /*va_start(ArgList, Arg); */
ArgName = Arg; ArgName = Arg;
for ( ; ; ) { for ( ; ; ) {
ArgValue = va_arg(ArgList, const char *); ArgValue = va_arg(ArgList, const char *);
@ -333,7 +333,7 @@ static IXML_Document *makeAction(
break; break;
} }
} }
//va_end(ArgList); /*va_end(ArgList); */
} }
return ActionDoc; return ActionDoc;

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "config.h" #include "config.h"
#if EXCLUDE_GENA == 0 #if EXCLUDE_GENA == 0
@ -63,7 +63,7 @@ error_respond( IN SOCKINFO * info,
int major, int major,
minor; minor;
// retrieve the minor and major version from the GENA request /* retrieve the minor and major version from the GENA request */
http_CalcResponseVersion( hmsg->major_version, http_CalcResponseVersion( hmsg->major_version,
hmsg->minor_version, &major, &minor ); hmsg->minor_version, &major, &minor );
@ -96,32 +96,32 @@ genaCallback( IN http_parser_t * parser,
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
found_function = TRUE; found_function = TRUE;
if( httpmsg_find_hdr( request, HDR_NT, NULL ) == NULL ) { if( httpmsg_find_hdr( request, HDR_NT, NULL ) == NULL ) {
// renew subscription /* renew subscription */
gena_process_subscription_renewal_request gena_process_subscription_renewal_request
( info, request ); ( info, request );
} else { } else {
// subscribe /* subscribe */
gena_process_subscription_request( info, request ); gena_process_subscription_request( info, request );
} }
UpnpPrintf( UPNP_ALL, GENA, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, GENA, __FILE__, __LINE__,
"got subscription request\n" ); "got subscription request\n" );
} else if( request->method == HTTPMETHOD_UNSUBSCRIBE ) { } else if( request->method == HTTPMETHOD_UNSUBSCRIBE ) {
found_function = TRUE; found_function = TRUE;
// unsubscribe /* unsubscribe */
gena_process_unsubscribe_request( info, request ); gena_process_unsubscribe_request( info, request );
#endif #endif
} else if( request->method == HTTPMETHOD_NOTIFY ) { } else if( request->method == HTTPMETHOD_NOTIFY ) {
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
found_function = TRUE; found_function = TRUE;
// notify /* notify */
gena_process_notification_event( info, request ); gena_process_notification_event( info, request );
#endif #endif
} }
if( !found_function ) { if( !found_function ) {
// handle missing functions of device or ctrl pt /* handle missing functions of device or ctrl pt */
error_respond( info, HTTP_NOT_IMPLEMENTED, request ); error_respond( info, HTTP_NOT_IMPLEMENTED, request );
} }
} }
#endif // EXCLUDE_GENA #endif /* EXCLUDE_GENA */

View File

@ -106,7 +106,7 @@ static void GenaAutoRenewSubscription(
} }
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID"); UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID");
// make callback /* make callback */
callback_fun = handle_info->Callback; callback_fun = handle_info->Callback;
cookie = handle_info->Cookie; cookie = handle_info->Cookie;
HandleUnlock(); HandleUnlock();
@ -160,14 +160,14 @@ static int ScheduleGenaAutoRenew(
goto end_function; goto end_function;
} }
// schedule expire event /* schedule expire event */
RenewEventStruct->ErrCode = UPNP_E_SUCCESS; RenewEventStruct->ErrCode = UPNP_E_SUCCESS;
RenewEventStruct->TimeOut = TimeOut; RenewEventStruct->TimeOut = TimeOut;
strcpy(RenewEventStruct->Sid, UpnpString_get_String(tmpSID)); strcpy(RenewEventStruct->Sid, UpnpString_get_String(tmpSID));
strncpy(RenewEventStruct->PublisherUrl, strncpy(RenewEventStruct->PublisherUrl,
UpnpString_get_String(tmpEventURL), NAME_SIZE - 1); UpnpString_get_String(tmpEventURL), NAME_SIZE - 1);
// RenewEvent->EventType=UPNP_EVENT_SUBSCRIPTION_EXPIRE; /* RenewEvent->EventType=UPNP_EVENT_SUBSCRIPTION_EXPIRE; */
RenewEvent->handle = client_handle; RenewEvent->handle = client_handle;
RenewEvent->Event = RenewEventStruct; RenewEvent->Event = RenewEventStruct;
@ -175,7 +175,7 @@ static int ScheduleGenaAutoRenew(
TPJobSetFreeFunction(&job, (free_routine)free_upnp_timeout); TPJobSetFreeFunction(&job, (free_routine)free_upnp_timeout);
TPJobSetPriority(&job, MED_PRIORITY); TPJobSetPriority(&job, MED_PRIORITY);
// Schedule the job /* Schedule the job */
return_code = TimerThreadSchedule( return_code = TimerThreadSchedule(
&gTimerThread, &gTimerThread,
TimeOut - AUTO_RENEW_TIME, TimeOut - AUTO_RENEW_TIME,
@ -215,7 +215,7 @@ static int gena_unsubscribe(
uri_type dest_url; uri_type dest_url;
membuffer request; membuffer request;
// parse url /* parse url */
return_code = http_FixStrUrl( return_code = http_FixStrUrl(
UpnpString_get_String(url), UpnpString_get_String(url),
UpnpString_get_Length(url), UpnpString_get_Length(url),
@ -224,7 +224,7 @@ static int gena_unsubscribe(
return return_code; return return_code;
} }
// make request msg /* make request msg */
membuffer_init(&request); membuffer_init(&request);
request.size_inc = 30; request.size_inc = 30;
return_code = http_MakeMessage( return_code = http_MakeMessage(
@ -233,14 +233,14 @@ static int gena_unsubscribe(
HTTPMETHOD_UNSUBSCRIBE, &dest_url, HTTPMETHOD_UNSUBSCRIBE, &dest_url,
"SID: ", UpnpString_get_String(sid)); "SID: ", UpnpString_get_String(sid));
// Not able to make the message so destroy the existing buffer /* Not able to make the message so destroy the existing buffer */
if (return_code != 0) { if (return_code != 0) {
membuffer_destroy(&request); membuffer_destroy(&request);
return return_code; return return_code;
} }
// send request and get reply /* send request and get reply */
return_code = http_RequestAndResponse( return_code = http_RequestAndResponse(
&dest_url, request.buf, request.length, &dest_url, request.buf, request.length,
HTTPMETHOD_UNSUBSCRIBE, HTTP_DEFAULT_TIMEOUT, response); HTTPMETHOD_UNSUBSCRIBE, HTTP_DEFAULT_TIMEOUT, response);
@ -286,7 +286,7 @@ static int gena_subscribe(
UpnpString_clear(sid); UpnpString_clear(sid);
// request timeout to string /* request timeout to string */
if (timeout == NULL) { if (timeout == NULL) {
timeout = &local_timeout; timeout = &local_timeout;
} }
@ -298,7 +298,7 @@ static int gena_subscribe(
sprintf(timeout_str, "%d", *timeout); sprintf(timeout_str, "%d", *timeout);
} }
// parse url /* parse url */
return_code = http_FixStrUrl( return_code = http_FixStrUrl(
UpnpString_get_String(url), UpnpString_get_String(url),
UpnpString_get_Length(url), UpnpString_get_Length(url),
@ -307,11 +307,11 @@ static int gena_subscribe(
return return_code; return return_code;
} }
// make request msg /* make request msg */
membuffer_init(&request); membuffer_init(&request);
request.size_inc = 30; request.size_inc = 30;
if (renewal_sid) { if (renewal_sid) {
// renew subscription /* renew subscription */
return_code = http_MakeMessage( return_code = http_MakeMessage(
&request, 1, 1, &request, 1, 1,
"q" "ssc" "sscc", "q" "ssc" "sscc",
@ -319,7 +319,7 @@ static int gena_subscribe(
"SID: ", UpnpString_get_String(renewal_sid), "SID: ", UpnpString_get_String(renewal_sid),
"TIMEOUT: Second-", timeout_str ); "TIMEOUT: Second-", timeout_str );
} else { } else {
// subscribe /* subscribe */
if (dest_url.hostport.IPaddress.ss_family == AF_INET6) { if (dest_url.hostport.IPaddress.ss_family == AF_INET6) {
struct sockaddr_in6* DestAddr6 = (struct sockaddr_in6*)&dest_url.hostport.IPaddress; struct sockaddr_in6* DestAddr6 = (struct sockaddr_in6*)&dest_url.hostport.IPaddress;
return_code = http_MakeMessage( return_code = http_MakeMessage(
@ -346,7 +346,7 @@ static int gena_subscribe(
return return_code; return return_code;
} }
// send request and get reply /* send request and get reply */
return_code = http_RequestAndResponse(&dest_url, request.buf, return_code = http_RequestAndResponse(&dest_url, request.buf,
request.length, request.length,
HTTPMETHOD_SUBSCRIBE, HTTPMETHOD_SUBSCRIBE,
@ -365,7 +365,7 @@ static int gena_subscribe(
return UPNP_E_SUBSCRIBE_UNACCEPTED; return UPNP_E_SUBSCRIBE_UNACCEPTED;
} }
// get SID and TIMEOUT /* get SID and TIMEOUT */
if (httpmsg_find_hdr(&response.msg, HDR_SID, &sid_hdr) == NULL || if (httpmsg_find_hdr(&response.msg, HDR_SID, &sid_hdr) == NULL ||
sid_hdr.length == 0 || sid_hdr.length == 0 ||
httpmsg_find_hdr( &response.msg, HDR_TIMEOUT, &timeout_hdr ) == NULL || httpmsg_find_hdr( &response.msg, HDR_TIMEOUT, &timeout_hdr ) == NULL ||
@ -375,10 +375,10 @@ static int gena_subscribe(
return UPNP_E_BAD_RESPONSE; return UPNP_E_BAD_RESPONSE;
} }
// save timeout /* save timeout */
parse_ret = matchstr(timeout_hdr.buf, timeout_hdr.length, "%iSecond-%d%0", timeout); parse_ret = matchstr(timeout_hdr.buf, timeout_hdr.length, "%iSecond-%d%0", timeout);
if (parse_ret == PARSE_OK) { if (parse_ret == PARSE_OK) {
// nothing to do /* nothing to do */
} else if (memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) { } else if (memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) {
*timeout = -1; *timeout = -1;
} else { } else {
@ -387,7 +387,7 @@ static int gena_subscribe(
return UPNP_E_BAD_RESPONSE; return UPNP_E_BAD_RESPONSE;
} }
// save SID /* save SID */
UpnpString_set_StringN(sid, sid_hdr.buf, sid_hdr.length); UpnpString_set_StringN(sid, sid_hdr.buf, sid_hdr.length);
if (UpnpString_get_String(sid) == NULL) { if (UpnpString_get_String(sid) == NULL) {
httpmsg_destroy(&response.msg); httpmsg_destroy(&response.msg);
@ -456,7 +456,7 @@ int genaUnSubscribe(
ClientSubscription *sub_copy = UpnpClientSubscription_new(); ClientSubscription *sub_copy = UpnpClientSubscription_new();
http_parser_t response; http_parser_t response;
// validate handle and sid /* validate handle and sid */
HandleLock(); HandleLock();
if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) { if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) {
HandleUnlock(); HandleUnlock();
@ -518,7 +518,7 @@ int genaSubscribe(
UpnpString_clear(out_sid); UpnpString_clear(out_sid);
HandleReadLock(); HandleReadLock();
// validate handle /* validate handle */
if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) { if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) {
HandleUnlock(); HandleUnlock();
@ -526,7 +526,7 @@ int genaSubscribe(
} }
HandleUnlock(); HandleUnlock();
// subscribe /* subscribe */
SubscribeLock(); SubscribeLock();
return_code = gena_subscribe(PublisherURL, TimeOut, NULL, ActualSID); return_code = gena_subscribe(PublisherURL, TimeOut, NULL, ActualSID);
HandleLock(); HandleLock();
@ -542,16 +542,16 @@ int genaSubscribe(
goto error_handler; goto error_handler;
} }
// generate client SID /* generate client SID */
uuid_create(&uid ); uuid_create(&uid );
uuid_unpack(&uid, temp_sid); uuid_unpack(&uid, temp_sid);
sprintf(temp_sid2, "uuid:%s", temp_sid); sprintf(temp_sid2, "uuid:%s", temp_sid);
UpnpString_set_String(out_sid, temp_sid2); UpnpString_set_String(out_sid, temp_sid2);
// create event url /* create event url */
UpnpString_assign(EventURL, PublisherURL); UpnpString_assign(EventURL, PublisherURL);
// fill subscription /* fill subscription */
if (newSubscription == NULL) { if (newSubscription == NULL) {
return_code = UPNP_E_OUTOF_MEMORY; return_code = UPNP_E_OUTOF_MEMORY;
goto error_handler; goto error_handler;
@ -563,7 +563,7 @@ int genaSubscribe(
UpnpClientSubscription_set_Next(newSubscription, handle_info->ClientSubList); UpnpClientSubscription_set_Next(newSubscription, handle_info->ClientSubList);
handle_info->ClientSubList = newSubscription; handle_info->ClientSubList = newSubscription;
// schedule expiration event /* schedule expiration event */
return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, newSubscription); return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, newSubscription);
error_handler: error_handler:
@ -594,7 +594,7 @@ int genaRenewSubscription(
HandleLock(); HandleLock();
// validate handle and sid /* validate handle and sid */
if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) { if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) {
HandleUnlock(); HandleUnlock();
@ -610,7 +610,7 @@ int genaRenewSubscription(
goto exit_function; goto exit_function;
} }
// remove old events /* remove old events */
if (TimerThreadRemove( if (TimerThreadRemove(
&gTimerThread, &gTimerThread,
UpnpClientSubscription_get_RenewEventId(sub), UpnpClientSubscription_get_RenewEventId(sub),
@ -639,17 +639,17 @@ int genaRenewSubscription(
goto exit_function; goto exit_function;
} }
// we just called GetHandleInfo, so we don't check for return value /* we just called GetHandleInfo, so we don't check for return value */
//GetHandleInfo(client_handle, &handle_info); /*GetHandleInfo(client_handle, &handle_info); */
if (return_code != UPNP_E_SUCCESS) { if (return_code != UPNP_E_SUCCESS) {
// network failure (remove client sub) /* network failure (remove client sub) */
RemoveClientSubClientSID(&handle_info->ClientSubList, in_sid); RemoveClientSubClientSID(&handle_info->ClientSubList, in_sid);
free_client_subscription(sub_copy); free_client_subscription(sub_copy);
HandleUnlock(); HandleUnlock();
goto exit_function; goto exit_function;
} }
// get subscription /* get subscription */
sub = GetClientSubClientSID(handle_info->ClientSubList, in_sid); sub = GetClientSubClientSID(handle_info->ClientSubList, in_sid);
if (sub == NULL) { if (sub == NULL) {
free_client_subscription(sub_copy); free_client_subscription(sub_copy);
@ -658,10 +658,10 @@ int genaRenewSubscription(
goto exit_function; goto exit_function;
} }
// store actual sid /* store actual sid */
UpnpClientSubscription_set_ActualSID(sub, ActualSID); UpnpClientSubscription_set_ActualSID(sub, ActualSID);
// start renew subscription timer /* start renew subscription timer */
return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, sub); return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, sub);
if (return_code != GENA_SUCCESS) { if (return_code != GENA_SUCCESS) {
RemoveClientSubClientSID( RemoveClientSubClientSID(
@ -698,7 +698,7 @@ void gena_process_notification_event(
nts_hdr; nts_hdr;
memptr seq_hdr; memptr seq_hdr;
// get SID /* get SID */
if (httpmsg_find_hdr(event, HDR_SID, &sid_hdr) == NULL) { if (httpmsg_find_hdr(event, HDR_SID, &sid_hdr) == NULL) {
error_respond(info, HTTP_PRECONDITION_FAILED, event); error_respond(info, HTTP_PRECONDITION_FAILED, event);
goto exit_function; goto exit_function;
@ -706,28 +706,28 @@ void gena_process_notification_event(
sid.buff = sid_hdr.buf; sid.buff = sid_hdr.buf;
sid.size = sid_hdr.length; sid.size = sid_hdr.length;
// get event key /* get event key */
if (httpmsg_find_hdr(event, HDR_SEQ, &seq_hdr) == NULL || if (httpmsg_find_hdr(event, HDR_SEQ, &seq_hdr) == NULL ||
matchstr(seq_hdr.buf, seq_hdr.length, "%d%0", &eventKey) != PARSE_OK) { matchstr(seq_hdr.buf, seq_hdr.length, "%d%0", &eventKey) != PARSE_OK) {
error_respond( info, HTTP_BAD_REQUEST, event ); error_respond( info, HTTP_BAD_REQUEST, event );
goto exit_function; goto exit_function;
} }
// get NT and NTS headers /* get NT and NTS headers */
if (httpmsg_find_hdr(event, HDR_NT, &nt_hdr) == NULL || if (httpmsg_find_hdr(event, HDR_NT, &nt_hdr) == NULL ||
httpmsg_find_hdr(event, HDR_NTS, &nts_hdr) == NULL) { httpmsg_find_hdr(event, HDR_NTS, &nts_hdr) == NULL) {
error_respond( info, HTTP_BAD_REQUEST, event ); error_respond( info, HTTP_BAD_REQUEST, event );
goto exit_function; goto exit_function;
} }
// verify NT and NTS headers /* verify NT and NTS headers */
if (memptr_cmp(&nt_hdr, "upnp:event") != 0 || if (memptr_cmp(&nt_hdr, "upnp:event") != 0 ||
memptr_cmp(&nts_hdr, "upnp:propchange") != 0) { memptr_cmp(&nts_hdr, "upnp:propchange") != 0) {
error_respond(info, HTTP_PRECONDITION_FAILED, event); error_respond(info, HTTP_PRECONDITION_FAILED, event);
goto exit_function; goto exit_function;
} }
// parse the content (should be XML) /* parse the content (should be XML) */
if (!has_xml_content_type(event) || if (!has_xml_content_type(event) ||
event->msg.length == 0 || event->msg.length == 0 ||
ixmlParseBufferEx(event->entity.buf, &ChangedVars) != IXML_SUCCESS) { ixmlParseBufferEx(event->entity.buf, &ChangedVars) != IXML_SUCCESS) {
@ -737,28 +737,28 @@ void gena_process_notification_event(
HandleLock(); HandleLock();
// get client info /* get client info */
if (GetClientHandleInfo(&client_handle, &handle_info) != HND_CLIENT) { if (GetClientHandleInfo(&client_handle, &handle_info) != HND_CLIENT) {
error_respond(info, HTTP_PRECONDITION_FAILED, event); error_respond(info, HTTP_PRECONDITION_FAILED, event);
HandleUnlock(); HandleUnlock();
goto exit_function; goto exit_function;
} }
// get subscription based on SID /* get subscription based on SID */
subscription = GetClientSubActualSID(handle_info->ClientSubList, &sid); subscription = GetClientSubActualSID(handle_info->ClientSubList, &sid);
if (subscription == NULL) { if (subscription == NULL) {
if (eventKey == 0) { if (eventKey == 0) {
// wait until we've finished processing a subscription /* wait until we've finished processing a subscription */
// (if we are in the middle) /* (if we are in the middle) */
// this is to avoid mistakenly rejecting the first event if we /* this is to avoid mistakenly rejecting the first event if we */
// receive it before the subscription response /* receive it before the subscription response */
HandleUnlock(); HandleUnlock();
// try and get Subscription Lock /* try and get Subscription Lock */
// (in case we are in the process of subscribing) /* (in case we are in the process of subscribing) */
SubscribeLock(); SubscribeLock();
// get HandleLock again /* get HandleLock again */
HandleLock(); HandleLock();
if (GetClientHandleInfo(&client_handle, &handle_info) != HND_CLIENT) { if (GetClientHandleInfo(&client_handle, &handle_info) != HND_CLIENT) {
@ -784,25 +784,25 @@ void gena_process_notification_event(
} }
} }
// success /* success */
error_respond(info, HTTP_OK, event); error_respond(info, HTTP_OK, event);
// fill event struct /* fill event struct */
tmpSID = UpnpClientSubscription_get_SID(subscription); tmpSID = UpnpClientSubscription_get_SID(subscription);
strcpy(event_struct.Sid, UpnpString_get_String(tmpSID)); strcpy(event_struct.Sid, UpnpString_get_String(tmpSID));
event_struct.EventKey = eventKey; event_struct.EventKey = eventKey;
event_struct.ChangedVariables = ChangedVars; event_struct.ChangedVariables = ChangedVars;
// copy callback /* copy callback */
callback = handle_info->Callback; callback = handle_info->Callback;
cookie = handle_info->Cookie; cookie = handle_info->Cookie;
HandleUnlock(); HandleUnlock();
// make callback with event struct /* make callback with event struct */
// In future, should find a way of mainting /* In future, should find a way of mainting */
// that the handle is not unregistered in the middle of a /* that the handle is not unregistered in the middle of a */
// callback /* callback */
callback(UPNP_EVENT_RECEIVED, &event_struct, cookie); callback(UPNP_EVENT_RECEIVED, &event_struct, cookie);
exit_function: exit_function:

View File

@ -280,7 +280,7 @@ static int genaNotify(
membuffer_init( &mid_msg ); membuffer_init( &mid_msg );
// make 'end' msg (the part that won't vary with the destination) /* make 'end' msg (the part that won't vary with the destination) */
endmsg.size_inc = 30; endmsg.size_inc = 30;
if( http_MakeMessage( if( http_MakeMessage(
&mid_msg, 1, 1, &mid_msg, 1, 1,
@ -291,7 +291,7 @@ static int genaNotify(
membuffer_destroy( &mid_msg ); membuffer_destroy( &mid_msg );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send a notify to each url until one goes thru /* send a notify to each url until one goes thru */
for( i = 0; i < sub->DeliveryURLs.size; i++ ) { for( i = 0; i < sub->DeliveryURLs.size; i++ ) {
url = &sub->DeliveryURLs.parsedURLs[i]; url = &sub->DeliveryURLs.parsedURLs[i];
return_code = notify_send_and_recv( return_code = notify_send_and_recv(
@ -308,7 +308,7 @@ static int genaNotify(
return_code = GENA_SUCCESS; return_code = GENA_SUCCESS;
} else { } else {
if( response.msg.status_code == HTTP_PRECONDITION_FAILED ) { if( response.msg.status_code == HTTP_PRECONDITION_FAILED ) {
//Invalid SID gets removed /*Invalid SID gets removed */
return_code = GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB; return_code = GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB;
} else { } else {
return_code = GENA_E_NOTIFY_UNACCEPTED; return_code = GENA_E_NOTIFY_UNACCEPTED;
@ -345,9 +345,9 @@ static void genaNotifyThread(
* is a lot of notifications, then multiple threads will acquire a read * is a lot of notifications, then multiple threads will acquire a read
* lock and the thread which sends the notification will be blocked forever * lock and the thread which sends the notification will be blocked forever
* on the HandleLock at the end of this function. */ * on the HandleLock at the end of this function. */
//HandleReadLock(); /*HandleReadLock(); */
HandleLock(); HandleLock();
//validate context /*validate context */
if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) { if( GetHandleInfo( in->device_handle, &handle_info ) != HND_DEVICE ) {
free_notify_struct( in ); free_notify_struct( in );
@ -366,7 +366,7 @@ static void genaNotifyThread(
} }
#ifdef UPNP_ENABLE_NOTIFICATION_REORDERING #ifdef UPNP_ENABLE_NOTIFICATION_REORDERING
//If the event is out of order push it back to the job queue /*If the event is out of order push it back to the job queue */
if( in->eventKey != sub->ToSendEventKey ) { if( in->eventKey != sub->ToSendEventKey ) {
TPJobInit( &job, ( start_routine ) genaNotifyThread, input ); TPJobInit( &job, ( start_routine ) genaNotifyThread, input );
@ -388,7 +388,7 @@ static void genaNotifyThread(
HandleUnlock(); HandleUnlock();
//send the notify /*send the notify */
return_code = genaNotify( in->headers, in->propertySet, &sub_copy ); return_code = genaNotify( in->headers, in->propertySet, &sub_copy );
freeSubscription( &sub_copy ); freeSubscription( &sub_copy );
@ -400,7 +400,7 @@ static void genaNotifyThread(
HandleUnlock(); HandleUnlock();
return; return;
} }
//validate context /*validate context */
if( ( ( service = FindServiceId( &handle_info->ServiceTable, if( ( ( service = FindServiceId( &handle_info->ServiceTable,
in->servId, in->UDN ) ) == NULL ) in->servId, in->UDN ) ) == NULL )
|| ( !service->active ) || ( !service->active )
@ -412,7 +412,7 @@ static void genaNotifyThread(
sub->ToSendEventKey++; sub->ToSendEventKey++;
if( sub->ToSendEventKey < 0 ) //wrap to 1 for overflow if( sub->ToSendEventKey < 0 ) /*wrap to 1 for overflow */
sub->ToSendEventKey = 1; sub->ToSendEventKey = 1;
if( return_code == GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB ) { if( return_code == GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB ) {
@ -1233,20 +1233,20 @@ void gena_process_subscription_request(
goto exit_function; goto exit_function;
} }
// check NT header /* check NT header */
// Windows Millenium Interoperability: /* Windows Millenium Interoperability: */
// we accept either upnp:event, or upnp:propchange for the NT header /* we accept either upnp:event, or upnp:propchange for the NT header */
if (memptr_cmp_nocase(&nt_hdr, "upnp:event") != 0) { if (memptr_cmp_nocase(&nt_hdr, "upnp:event") != 0) {
error_respond(info, HTTP_PRECONDITION_FAILED, request); error_respond(info, HTTP_PRECONDITION_FAILED, request);
goto exit_function; goto exit_function;
} }
// if a SID is present then the we have a bad request "incompatible headers" /* if a SID is present then the we have a bad request "incompatible headers" */
if (httpmsg_find_hdr(request, HDR_SID, NULL) != NULL) { if (httpmsg_find_hdr(request, HDR_SID, NULL) != NULL) {
error_respond(info, HTTP_BAD_REQUEST, request); error_respond(info, HTTP_BAD_REQUEST, request);
goto exit_function; goto exit_function;
} }
// look up service by eventURL /* look up service by eventURL */
event_url_path = str_alloc(request->uri.pathquery.buff, request->uri.pathquery.size); event_url_path = str_alloc(request->uri.pathquery.buff, request->uri.pathquery.size);
if (event_url_path == NULL) { if (event_url_path == NULL) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
@ -1259,7 +1259,7 @@ void gena_process_subscription_request(
HandleLock(); HandleLock();
// CURRENTLY, ONLY ONE DEVICE /* CURRENTLY, ONLY ONE DEVICE */
if (GetDeviceHandleInfo(info->foreign_sockaddr.ss_family , if (GetDeviceHandleInfo(info->foreign_sockaddr.ss_family ,
&device_handle, &handle_info) != HND_DEVICE) { &device_handle, &handle_info) != HND_DEVICE) {
free(event_url_path); free(event_url_path);
@ -1282,14 +1282,14 @@ void gena_process_subscription_request(
service->TotalSubscriptions, service->TotalSubscriptions,
handle_info->MaxSubscriptions); handle_info->MaxSubscriptions);
// too many subscriptions /* too many subscriptions */
if (handle_info->MaxSubscriptions != -1 && if (handle_info->MaxSubscriptions != -1 &&
service->TotalSubscriptions >= handle_info->MaxSubscriptions) { service->TotalSubscriptions >= handle_info->MaxSubscriptions) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
HandleUnlock(); HandleUnlock();
goto exit_function; goto exit_function;
} }
// generate new subscription /* generate new subscription */
sub = (subscription *)malloc(sizeof (subscription)); sub = (subscription *)malloc(sizeof (subscription));
if (sub == NULL) { if (sub == NULL) {
error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request); error_respond(info, HTTP_INTERNAL_SERVER_ERROR, request);
@ -1304,7 +1304,7 @@ void gena_process_subscription_request(
sub->DeliveryURLs.URLs = NULL; sub->DeliveryURLs.URLs = NULL;
sub->DeliveryURLs.parsedURLs = NULL; sub->DeliveryURLs.parsedURLs = NULL;
// check for valid callbacks /* check for valid callbacks */
if (httpmsg_find_hdr( request, HDR_CALLBACK, &callback_hdr) == NULL) { if (httpmsg_find_hdr( request, HDR_CALLBACK, &callback_hdr) == NULL) {
error_respond(info, HTTP_PRECONDITION_FAILED, request); error_respond(info, HTTP_PRECONDITION_FAILED, request);
freeSubscriptionList(sub); freeSubscriptionList(sub);
@ -1324,20 +1324,20 @@ void gena_process_subscription_request(
HandleUnlock(); HandleUnlock();
goto exit_function; goto exit_function;
} }
// set the timeout /* set the timeout */
if (httpmsg_find_hdr(request, HDR_TIMEOUT, &timeout_hdr) != NULL) { if (httpmsg_find_hdr(request, HDR_TIMEOUT, &timeout_hdr) != NULL) {
if (matchstr(timeout_hdr.buf, timeout_hdr.length, if (matchstr(timeout_hdr.buf, timeout_hdr.length,
"%iSecond-%d%0", &time_out) == PARSE_OK) { "%iSecond-%d%0", &time_out) == PARSE_OK) {
// nothing /* nothing */
} else if(memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) { } else if(memptr_cmp_nocase(&timeout_hdr, "Second-infinite") == 0) {
// infinite timeout /* infinite timeout */
time_out = -1; time_out = -1;
} else { } else {
// default is > 1800 seconds /* default is > 1800 seconds */
time_out = DEFAULT_TIMEOUT; time_out = DEFAULT_TIMEOUT;
} }
} }
// replace infinite timeout with max timeout, if possible /* replace infinite timeout with max timeout, if possible */
if (handle_info->MaxSubscriptionTimeOut != -1) { if (handle_info->MaxSubscriptionTimeOut != -1) {
if (time_out == -1 || if (time_out == -1 ||
time_out > handle_info->MaxSubscriptionTimeOut) { time_out > handle_info->MaxSubscriptionTimeOut) {
@ -1347,40 +1347,40 @@ void gena_process_subscription_request(
if (time_out >= 0) { if (time_out >= 0) {
sub->expireTime = time(NULL) + time_out; sub->expireTime = time(NULL) + time_out;
} else { } else {
// infinite time /* infinite time */
sub->expireTime = 0; sub->expireTime = 0;
} }
// generate SID /* generate SID */
uuid_create(&uid); uuid_create(&uid);
uuid_unpack(&uid, temp_sid); uuid_unpack(&uid, temp_sid);
sprintf(sub->sid, "uuid:%s", temp_sid); sprintf(sub->sid, "uuid:%s", temp_sid);
// respond OK /* respond OK */
if (respond_ok(info, time_out, sub, request) != UPNP_E_SUCCESS) { if (respond_ok(info, time_out, sub, request) != UPNP_E_SUCCESS) {
freeSubscriptionList(sub); freeSubscriptionList(sub);
HandleUnlock(); HandleUnlock();
goto exit_function; goto exit_function;
} }
// add to subscription list /* add to subscription list */
sub->next = service->subscriptionList; sub->next = service->subscriptionList;
service->subscriptionList = sub; service->subscriptionList = sub;
service->TotalSubscriptions++; service->TotalSubscriptions++;
// finally generate callback for init table dump /* finally generate callback for init table dump */
request_struct.ServiceId = service->serviceId; request_struct.ServiceId = service->serviceId;
request_struct.UDN = service->UDN; request_struct.UDN = service->UDN;
strcpy((char *)request_struct.Sid, sub->sid); strcpy((char *)request_struct.Sid, sub->sid);
// copy callback /* copy callback */
callback_fun = handle_info->Callback; callback_fun = handle_info->Callback;
cookie = handle_info->Cookie; cookie = handle_info->Cookie;
HandleUnlock(); HandleUnlock();
// make call back with request struct /* make call back with request struct */
// in the future should find a way of mainting that the handle /* in the future should find a way of mainting that the handle */
// is not unregistered in the middle of a callback /* is not unregistered in the middle of a callback */
callback_fun(UPNP_EVENT_SUBSCRIPTION_REQUEST, &request_struct, cookie); callback_fun(UPNP_EVENT_SUBSCRIPTION_REQUEST, &request_struct, cookie);
exit_function: exit_function:
@ -1402,13 +1402,13 @@ void gena_process_subscription_renewal_request(
membuffer event_url_path; membuffer event_url_path;
memptr timeout_hdr; memptr timeout_hdr;
// if a CALLBACK or NT header is present, then it is an error /* if a CALLBACK or NT header is present, then it is an error */
if( httpmsg_find_hdr( request, HDR_CALLBACK, NULL ) != NULL || if( httpmsg_find_hdr( request, HDR_CALLBACK, NULL ) != NULL ||
httpmsg_find_hdr( request, HDR_NT, NULL ) != NULL ) { httpmsg_find_hdr( request, HDR_NT, NULL ) != NULL ) {
error_respond( info, HTTP_BAD_REQUEST, request ); error_respond( info, HTTP_BAD_REQUEST, request );
return; return;
} }
// get SID /* get SID */
if( httpmsg_find_hdr( request, HDR_SID, &temp_hdr ) == NULL || if( httpmsg_find_hdr( request, HDR_SID, &temp_hdr ) == NULL ||
temp_hdr.length > SID_SIZE ) { temp_hdr.length > SID_SIZE ) {
error_respond( info, HTTP_PRECONDITION_FAILED, request ); error_respond( info, HTTP_PRECONDITION_FAILED, request );
@ -1417,7 +1417,7 @@ void gena_process_subscription_renewal_request(
memcpy( sid, temp_hdr.buf, temp_hdr.length ); memcpy( sid, temp_hdr.buf, temp_hdr.length );
sid[temp_hdr.length] = '\0'; sid[temp_hdr.length] = '\0';
// lookup service by eventURL /* lookup service by eventURL */
membuffer_init( &event_url_path ); membuffer_init( &event_url_path );
if( membuffer_append( &event_url_path, request->uri.pathquery.buff, if( membuffer_append( &event_url_path, request->uri.pathquery.buff,
request->uri.pathquery.size ) != 0 ) { request->uri.pathquery.size ) != 0 ) {
@ -1427,7 +1427,7 @@ void gena_process_subscription_renewal_request(
HandleLock(); HandleLock();
// CURRENTLY, ONLY SUPPORT ONE DEVICE /* CURRENTLY, ONLY SUPPORT ONE DEVICE */
if( GetDeviceHandleInfo( info->foreign_sockaddr.ss_family, if( GetDeviceHandleInfo( info->foreign_sockaddr.ss_family,
&device_handle, &handle_info ) != HND_DEVICE ) { &device_handle, &handle_info ) != HND_DEVICE ) {
error_respond( info, HTTP_PRECONDITION_FAILED, request ); error_respond( info, HTTP_PRECONDITION_FAILED, request );
@ -1439,7 +1439,7 @@ void gena_process_subscription_renewal_request(
event_url_path.buf ); event_url_path.buf );
membuffer_destroy( &event_url_path ); membuffer_destroy( &event_url_path );
// get subscription /* get subscription */
if( service == NULL || if( service == NULL ||
!service->active || !service->active ||
( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) ) { ( ( sub = GetSubscriptionSID( sid, service ) ) == NULL ) ) {
@ -1453,7 +1453,7 @@ void gena_process_subscription_renewal_request(
"Max Subscriptions allowed:%d\n", "Max Subscriptions allowed:%d\n",
service->TotalSubscriptions, service->TotalSubscriptions,
handle_info->MaxSubscriptions ); handle_info->MaxSubscriptions );
// too many subscriptions /* too many subscriptions */
if( handle_info->MaxSubscriptions != -1 && if( handle_info->MaxSubscriptions != -1 &&
service->TotalSubscriptions > handle_info->MaxSubscriptions ) { service->TotalSubscriptions > handle_info->MaxSubscriptions ) {
error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request );
@ -1461,25 +1461,25 @@ void gena_process_subscription_renewal_request(
HandleUnlock(); HandleUnlock();
return; return;
} }
// set the timeout /* set the timeout */
if( httpmsg_find_hdr( request, HDR_TIMEOUT, &timeout_hdr ) != NULL ) { if( httpmsg_find_hdr( request, HDR_TIMEOUT, &timeout_hdr ) != NULL ) {
if( matchstr( timeout_hdr.buf, timeout_hdr.length, if( matchstr( timeout_hdr.buf, timeout_hdr.length,
"%iSecond-%d%0", &time_out ) == PARSE_OK ) { "%iSecond-%d%0", &time_out ) == PARSE_OK ) {
//nothing /*nothing */
} else if( memptr_cmp_nocase( &timeout_hdr, "Second-infinite" ) == } else if( memptr_cmp_nocase( &timeout_hdr, "Second-infinite" ) ==
0 ) { 0 ) {
time_out = -1; // inifinite timeout time_out = -1; /* inifinite timeout */
} else { } else {
time_out = DEFAULT_TIMEOUT; // default is > 1800 seconds time_out = DEFAULT_TIMEOUT; /* default is > 1800 seconds */
} }
} }
// replace infinite timeout with max timeout, if possible /* replace infinite timeout with max timeout, if possible */
if( handle_info->MaxSubscriptionTimeOut != -1 ) { if( handle_info->MaxSubscriptionTimeOut != -1 ) {
if( time_out == -1 || if( time_out == -1 ||
time_out > handle_info->MaxSubscriptionTimeOut ) { time_out > handle_info->MaxSubscriptionTimeOut ) {
@ -1513,13 +1513,13 @@ void gena_process_unsubscribe_request(
memptr temp_hdr; memptr temp_hdr;
membuffer event_url_path; membuffer event_url_path;
// if a CALLBACK or NT header is present, then it is an error /* if a CALLBACK or NT header is present, then it is an error */
if( httpmsg_find_hdr( request, HDR_CALLBACK, NULL ) != NULL || if( httpmsg_find_hdr( request, HDR_CALLBACK, NULL ) != NULL ||
httpmsg_find_hdr( request, HDR_NT, NULL ) != NULL ) { httpmsg_find_hdr( request, HDR_NT, NULL ) != NULL ) {
error_respond( info, HTTP_BAD_REQUEST, request ); error_respond( info, HTTP_BAD_REQUEST, request );
return; return;
} }
// get SID /* get SID */
if( httpmsg_find_hdr( request, HDR_SID, &temp_hdr ) == NULL || if( httpmsg_find_hdr( request, HDR_SID, &temp_hdr ) == NULL ||
temp_hdr.length > SID_SIZE ) { temp_hdr.length > SID_SIZE ) {
error_respond( info, HTTP_PRECONDITION_FAILED, request ); error_respond( info, HTTP_PRECONDITION_FAILED, request );
@ -1528,7 +1528,7 @@ void gena_process_unsubscribe_request(
memcpy( sid, temp_hdr.buf, temp_hdr.length ); memcpy( sid, temp_hdr.buf, temp_hdr.length );
sid[temp_hdr.length] = '\0'; sid[temp_hdr.length] = '\0';
// lookup service by eventURL /* lookup service by eventURL */
membuffer_init( &event_url_path ); membuffer_init( &event_url_path );
if( membuffer_append( &event_url_path, request->uri.pathquery.buff, if( membuffer_append( &event_url_path, request->uri.pathquery.buff,
request->uri.pathquery.size ) != 0 ) { request->uri.pathquery.size ) != 0 ) {
@ -1538,7 +1538,7 @@ void gena_process_unsubscribe_request(
HandleLock(); HandleLock();
// CURRENTLY, ONLY SUPPORT ONE DEVICE /* CURRENTLY, ONLY SUPPORT ONE DEVICE */
if( GetDeviceHandleInfo( info->foreign_sockaddr.ss_family, if( GetDeviceHandleInfo( info->foreign_sockaddr.ss_family,
&device_handle, &handle_info ) != HND_DEVICE ) { &device_handle, &handle_info ) != HND_DEVICE ) {
error_respond( info, HTTP_PRECONDITION_FAILED, request ); error_respond( info, HTTP_PRECONDITION_FAILED, request );
@ -1550,7 +1550,7 @@ void gena_process_unsubscribe_request(
event_url_path.buf ); event_url_path.buf );
membuffer_destroy( &event_url_path ); membuffer_destroy( &event_url_path );
// validate service /* validate service */
if( service == NULL || if( service == NULL ||
!service->active || GetSubscriptionSID( sid, service ) == NULL ) !service->active || GetSubscriptionSID( sid, service ) == NULL )
{ {
@ -1560,7 +1560,7 @@ void gena_process_unsubscribe_request(
} }
RemoveSubscriptionSID(sid, service); RemoveSubscriptionSID(sid, service);
error_respond(info, HTTP_OK, request); // success error_respond(info, HTTP_OK, request); /* success */
HandleUnlock(); HandleUnlock();
} }

View File

@ -46,7 +46,7 @@
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
#include <stdlib.h> // for calloc(), free() #include <stdlib.h> /* for calloc(), free() */
struct SClientSubscription { struct SClientSubscription {
@ -113,12 +113,12 @@ ClientSubscription *UpnpClientSubscription_dup(const ClientSubscription *p)
void UpnpClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p) void UpnpClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p)
{ {
if (q != p) { if (q != p) {
// Do not copy RenewEventId /* Do not copy RenewEventId */
((struct SClientSubscription *)q)->m_renewEventId = -1; ((struct SClientSubscription *)q)->m_renewEventId = -1;
UpnpClientSubscription_set_SID(q, UpnpClientSubscription_get_SID(p)); UpnpClientSubscription_set_SID(q, UpnpClientSubscription_get_SID(p));
UpnpClientSubscription_set_ActualSID(q, UpnpClientSubscription_get_ActualSID(p)); UpnpClientSubscription_set_ActualSID(q, UpnpClientSubscription_get_ActualSID(p));
UpnpClientSubscription_set_EventURL(q, UpnpClientSubscription_get_EventURL(p)); UpnpClientSubscription_set_EventURL(q, UpnpClientSubscription_get_EventURL(p));
// Do not copy m_next /* Do not copy m_next */
((struct SClientSubscription *)q)->m_next = NULL; ((struct SClientSubscription *)q)->m_next = NULL;
} }
} }
@ -238,8 +238,8 @@ void free_client_subscription(ClientSubscription *sub)
UpnpClientSubscription_strcpy_ActualSID(sub, ""); UpnpClientSubscription_strcpy_ActualSID(sub, "");
UpnpClientSubscription_strcpy_EventURL(sub, ""); UpnpClientSubscription_strcpy_EventURL(sub, "");
if (renewEventId != -1) { if (renewEventId != -1) {
// do not remove timer event of copy /* do not remove timer event of copy */
// invalid timer event id /* invalid timer event id */
if (TimerThreadRemove(&gTimerThread, renewEventId, &tempJob) == 0) { if (TimerThreadRemove(&gTimerThread, renewEventId, &tempJob) == 0) {
event = (upnp_timeout *)tempJob.arg; event = (upnp_timeout *)tempJob.arg;
free_upnp_timeout(event); free_upnp_timeout(event);

File diff suppressed because it is too large Load Diff

View File

@ -394,7 +394,7 @@ int http_RecvMessage(
while (TRUE) { while (TRUE) {
num_read = sock_read(info, buf, sizeof buf, timeout_secs); num_read = sock_read(info, buf, sizeof buf, timeout_secs);
if (num_read > 0) { if (num_read > 0) {
// got data /* got data */
status = parser_append(parser, buf, num_read); status = parser_append(parser, buf, num_read);
if (status == PARSE_SUCCESS) { if (status == PARSE_SUCCESS) {
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
@ -416,10 +416,10 @@ int http_RecvMessage(
ret = UPNP_E_BAD_HTTPMSG; ret = UPNP_E_BAD_HTTPMSG;
goto ExitFunction; goto ExitFunction;
} else if (status == PARSE_INCOMPLETE_ENTITY) { } else if (status == PARSE_INCOMPLETE_ENTITY) {
// read until close /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if (status == PARSE_CONTINUE_1) { } else if (status == PARSE_CONTINUE_1) {
// Web post request. /* Web post request. */
line = __LINE__; line = __LINE__;
ret = PARSE_SUCCESS; ret = PARSE_SUCCESS;
goto ExitFunction; goto ExitFunction;
@ -434,8 +434,8 @@ int http_RecvMessage(
ret = 0; ret = 0;
goto ExitFunction; goto ExitFunction;
} else { } else {
// partial msg /* partial msg */
*http_error_code = HTTP_BAD_REQUEST; // or response *http_error_code = HTTP_BAD_REQUEST; /* or response */
line = __LINE__; line = __LINE__;
ret = UPNP_E_BAD_HTTPMSG; ret = UPNP_E_BAD_HTTPMSG;
goto ExitFunction; goto ExitFunction;
@ -478,8 +478,8 @@ ExitFunction:
* char *buf = "POST /xyz.cgi http/1.1\r\n\r\n"; * char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
* char *filename = "foo.dat"; * char *filename = "foo.dat";
* int status = http_SendMessage( tcpsock, "mf", * int status = http_SendMessage( tcpsock, "mf",
* buf, strlen(buf), // args for memory buffer * buf, strlen(buf),
* filename ); // arg for file * filename );
* *
* Returns: * Returns:
* UPNP_E_OUTOF_MEMORY * UPNP_E_OUTOF_MEMORY
@ -507,7 +507,7 @@ http_SendMessage( IN SOCKINFO * info,
char Chunk_Header[CHUNK_HEADER_SIZE]; char Chunk_Header[CHUNK_HEADER_SIZE];
int RetVal = 0; int RetVal = 0;
// 10 byte allocated for chunk header. /* 10 byte allocated for chunk header. */
int Data_Buf_Size = WEB_SERVER_BUF_SIZE; int Data_Buf_Size = WEB_SERVER_BUF_SIZE;
va_start( argp, fmt ); va_start( argp, fmt );
@ -536,7 +536,7 @@ http_SendMessage( IN SOCKINFO * info,
file_buf = ChunkBuf + CHUNK_HEADER_SIZE; file_buf = ChunkBuf + CHUNK_HEADER_SIZE;
} else if( c == 'f' ) { } else if( c == 'f' ) {
// file name /* file name */
filename = va_arg(argp, char *); filename = va_arg(argp, char *);
if( Instr && Instr->IsVirtualFile ) { if( Instr && Instr->IsVirtualFile ) {
Fp = (virtualDirCallback.open)( filename, UPNP_READ ); Fp = (virtualDirCallback.open)( filename, UPNP_READ );
@ -572,7 +572,7 @@ http_SendMessage( IN SOCKINFO * info,
} }
amount_to_be_read = amount_to_be_read - num_read; amount_to_be_read = amount_to_be_read - num_read;
if( Instr->ReadSendSize < 0 ) { if( Instr->ReadSendSize < 0 ) {
// read until close /* read until close */
amount_to_be_read = Data_Buf_Size; amount_to_be_read = Data_Buf_Size;
} }
} else { } else {
@ -580,7 +580,7 @@ http_SendMessage( IN SOCKINFO * info,
} }
if( num_read == 0 ) { if( num_read == 0 ) {
// EOF so no more to send. /* EOF so no more to send. */
if( Instr && Instr->IsChunkActive ) { if( Instr && Instr->IsChunkActive ) {
char *str = "0\r\n\r\n"; char *str = "0\r\n\r\n";
num_written = sock_write(info, str, strlen(str), TimeOut); num_written = sock_write(info, str, strlen(str), TimeOut);
@ -589,45 +589,45 @@ http_SendMessage( IN SOCKINFO * info,
} }
goto Cleanup_File; goto Cleanup_File;
} }
// Create chunk for the current buffer. /* Create chunk for the current buffer. */
if( Instr && Instr->IsChunkActive ) { if( Instr && Instr->IsChunkActive ) {
// Copy CRLF at the end of the chunk /* Copy CRLF at the end of the chunk */
memcpy( file_buf + num_read, "\r\n", 2 ); memcpy( file_buf + num_read, "\r\n", 2 );
// Hex length for the chunk size. /* Hex length for the chunk size. */
sprintf( Chunk_Header, "%x", num_read ); sprintf( Chunk_Header, "%x", num_read );
//itoa(num_read,Chunk_Header,16); /*itoa(num_read,Chunk_Header,16); */
strcat( Chunk_Header, "\r\n" ); strcat( Chunk_Header, "\r\n" );
// Copy the chunk size header /* Copy the chunk size header */
memcpy( file_buf - strlen( Chunk_Header ), memcpy( file_buf - strlen( Chunk_Header ),
Chunk_Header, strlen( Chunk_Header ) ); Chunk_Header, strlen( Chunk_Header ) );
// on the top of the buffer. /* on the top of the buffer. */
//file_buf[num_read+strlen(Chunk_Header)] = NULL; /*file_buf[num_read+strlen(Chunk_Header)] = NULL; */
//printf("Sending %s\n",file_buf-strlen(Chunk_Header)); /*printf("Sending %s\n",file_buf-strlen(Chunk_Header)); */
num_written = sock_write( num_written = sock_write(
info, file_buf - strlen( Chunk_Header ), info, file_buf - strlen( Chunk_Header ),
num_read + strlen( Chunk_Header ) + 2, TimeOut ); num_read + strlen( Chunk_Header ) + 2, TimeOut );
if( num_written != if( num_written !=
num_read + ( int )strlen( Chunk_Header ) + 2 ) { num_read + ( int )strlen( Chunk_Header ) + 2 ) {
// Send error nothing we can do. /* Send error nothing we can do. */
goto Cleanup_File; goto Cleanup_File;
} }
} else { } else {
// write data /* write data */
num_written = sock_write( info, file_buf, num_read, TimeOut ); num_written = sock_write( info, file_buf, num_read, TimeOut );
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
">>> (SENT) >>>\n%.*s\n------------\n", ">>> (SENT) >>>\n%.*s\n------------\n",
( int )num_written, file_buf ); ( int )num_written, file_buf );
// Send error nothing we can do /* Send error nothing we can do */
if( num_written != num_read ) { if( num_written != num_read ) {
goto Cleanup_File; goto Cleanup_File;
} }
} }
} // while } /* while */
Cleanup_File: Cleanup_File:
va_end( argp ); va_end( argp );
if( Instr && Instr->IsVirtualFile ) { if( Instr && Instr->IsVirtualFile ) {
@ -639,7 +639,7 @@ Cleanup_File:
return RetVal; return RetVal;
} else if( c == 'b' ) { } else if( c == 'b' ) {
// memory buffer /* memory buffer */
buf = va_arg(argp, char *); buf = va_arg(argp, char *);
buf_length = va_arg(argp, size_t); buf_length = va_arg(argp, size_t);
if( buf_length > 0 ) { if( buf_length > 0 ) {
@ -779,7 +779,7 @@ http_Download( IN const char *url_str,
membuffer request; membuffer request;
char *urlPath = alloca( strlen( url_str ) + 1 ); char *urlPath = alloca( strlen( url_str ) + 1 );
//ret_code = parse_uri( (char*)url_str, strlen(url_str), &url ); /*ret_code = parse_uri( (char*)url_str, strlen(url_str), &url ); */
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "DOWNLOAD URL : %s\n", UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "DOWNLOAD URL : %s\n",
url_str ); url_str );
ret_code = ret_code =
@ -787,7 +787,7 @@ http_Download( IN const char *url_str,
if( ret_code != UPNP_E_SUCCESS ) { if( ret_code != UPNP_E_SUCCESS ) {
return ret_code; return ret_code;
} }
// make msg /* make msg */
membuffer_init( &request ); membuffer_init( &request );
strcpy( urlPath, url_str ); strcpy( urlPath, url_str );
@ -824,7 +824,7 @@ http_Download( IN const char *url_str,
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"HTTP Buffer:\n%s\n" "----------END--------\n", "HTTP Buffer:\n%s\n" "----------END--------\n",
request.buf); request.buf);
// get doc msg /* get doc msg */
ret_code = ret_code =
http_RequestAndResponse( &url, request.buf, request.length, http_RequestAndResponse( &url, request.buf, request.length,
HTTPMETHOD_GET, timeout_secs, &response ); HTTPMETHOD_GET, timeout_secs, &response );
@ -838,13 +838,13 @@ http_Download( IN const char *url_str,
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "Response\n" ); UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, "Response\n" );
print_http_headers( &response.msg ); print_http_headers( &response.msg );
// optional content-type /* optional content-type */
if( content_type ) { if( content_type ) {
if( httpmsg_find_hdr( &response.msg, HDR_CONTENT_TYPE, &ctype ) == if( httpmsg_find_hdr( &response.msg, HDR_CONTENT_TYPE, &ctype ) ==
NULL ) { NULL ) {
*content_type = '\0'; // no content-type *content_type = '\0'; /* no content-type */
} else { } else {
// safety /* safety */
copy_len = ctype.length < LINE_SIZE - 1 ? copy_len = ctype.length < LINE_SIZE - 1 ?
ctype.length : LINE_SIZE - 1; ctype.length : LINE_SIZE - 1;
@ -852,36 +852,36 @@ http_Download( IN const char *url_str,
content_type[copy_len] = '\0'; content_type[copy_len] = '\0';
} }
} }
// /* */
// extract doc from msg /* extract doc from msg */
// /* */
if( ( *doc_length = ( int )response.msg.entity.length ) == 0 ) { if( ( *doc_length = ( int )response.msg.entity.length ) == 0 ) {
// 0-length msg /* 0-length msg */
*document = NULL; *document = NULL;
} else if( response.msg.status_code == HTTP_OK ) { } else if( response.msg.status_code == HTTP_OK ) {
//LEAK_FIX_MK /*LEAK_FIX_MK */
// copy entity /* copy entity */
entity_start = response.msg.entity.buf; // what we want entity_start = response.msg.entity.buf; /* what we want */
msg_length = response.msg.msg.length; // save for posterity msg_length = response.msg.msg.length; /* save for posterity */
msg_start = membuffer_detach( &response.msg.msg ); // whole msg msg_start = membuffer_detach( &response.msg.msg ); /* whole msg */
// move entity to the start; copy null-terminator too /* move entity to the start; copy null-terminator too */
memmove( msg_start, entity_start, *doc_length + 1 ); memmove( msg_start, entity_start, *doc_length + 1 );
// save mem for body only /* save mem for body only */
*document = realloc( msg_start, *doc_length + 1 ); //LEAK_FIX_MK *document = realloc( msg_start, *doc_length + 1 ); /*LEAK_FIX_MK */
// *document = Realloc( msg_start,msg_length, *doc_length + 1 );//LEAK_FIX_MK /* *document = Realloc( msg_start,msg_length, *doc_length + 1 ); LEAK_FIX_MK */
// shrink can't fail /* shrink can't fail */
assert( ( int )msg_length > *doc_length ); assert( ( int )msg_length > *doc_length );
assert( *document != NULL ); assert( *document != NULL );
} }
if( response.msg.status_code == HTTP_OK ) { if( response.msg.status_code == HTTP_OK ) {
ret_code = 0; // success ret_code = 0; /* success */
} else { } else {
// server sent error msg (not requested doc) /* server sent error msg (not requested doc) */
ret_code = response.msg.status_code; ret_code = response.msg.status_code;
} }
@ -935,7 +935,7 @@ MakePostMessage( const char *url_str,
if( ret_code != UPNP_E_SUCCESS ) { if( ret_code != UPNP_E_SUCCESS ) {
return ret_code; return ret_code;
} }
// make msg /* make msg */
membuffer_init( request ); membuffer_init( request );
strcpy( urlPath, url_str ); strcpy( urlPath, url_str );
@ -1045,12 +1045,12 @@ http_WriteHttpPost( IN void *Handle,
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// begin chunk /* begin chunk */
sprintf( tempbuf, "%x\r\n", ( *size ) ); sprintf( tempbuf, "%x\r\n", ( *size ) );
tempSize = strlen( tempbuf ); tempSize = strlen( tempbuf );
memcpy( tempbuf + tempSize, buf, ( *size ) ); memcpy( tempbuf + tempSize, buf, ( *size ) );
memcpy( tempbuf + tempSize + ( *size ), "\r\n", 2 ); memcpy( tempbuf + tempSize + ( *size ), "\r\n", 2 );
// end of chunk /* end of chunk */
tempbufSize = tempSize + ( *size ) + 2; tempbufSize = tempSize + ( *size ) + 2;
freeTempbuf = 1; freeTempbuf = 1;
} }
@ -1061,7 +1061,7 @@ http_WriteHttpPost( IN void *Handle,
numWritten = numWritten =
sock_write( &handle->sock_info, tempbuf, tempbufSize, &timeout ); sock_write( &handle->sock_info, tempbuf, tempbufSize, &timeout );
//(*size) = sock_write(&handle->sock_info,tempbuf,tempbufSize,&timeout); /*(*size) = sock_write(&handle->sock_info,tempbuf,tempbufSize,&timeout); */
if( freeTempbuf ) { if( freeTempbuf ) {
free( tempbuf ); free( tempbuf );
@ -1109,9 +1109,9 @@ http_CloseHttpPost( IN void *Handle,
} }
if( handle->contentLength == UPNP_USING_CHUNKED ) { if( handle->contentLength == UPNP_USING_CHUNKED ) {
retc = sock_write( &handle->sock_info, "0\r\n\r\n", strlen( "0\r\n\r\n" ), &timeout ); //send last chunk retc = sock_write( &handle->sock_info, "0\r\n\r\n", strlen( "0\r\n\r\n" ), &timeout ); /*send last chunk */
} }
//read response /*read response */
parser_response_init( &response, HTTPMETHOD_POST ); parser_response_init( &response, HTTPMETHOD_POST );
retc = retc =
@ -1120,7 +1120,7 @@ http_CloseHttpPost( IN void *Handle,
( *httpStatus ) = http_error_code; ( *httpStatus ) = http_error_code;
sock_destroy( &handle->sock_info, SD_BOTH ); //should shutdown completely sock_destroy( &handle->sock_info, SD_BOTH ); /*should shutdown completely */
httpmsg_destroy( &response.msg ); httpmsg_destroy( &response.msg );
free( handle ); free( handle );
@ -1262,7 +1262,7 @@ MakeGetMessage( const char *url_str,
if( ret_code != UPNP_E_SUCCESS ) { if( ret_code != UPNP_E_SUCCESS ) {
return ret_code; return ret_code;
} }
// make msg /* make msg */
membuffer_init( request ); membuffer_init( request );
strcpy( urlPath, url_str ); strcpy( urlPath, url_str );
@ -1339,7 +1339,7 @@ static int ReadResponseLineAndHeaders(
int done = 0; int done = 0;
int ret_code = 0; int ret_code = 0;
//read response line /*read response line */
status = parser_parse_responseline( parser ); status = parser_parse_responseline( parser );
if( status == PARSE_OK ) { if( status == PARSE_OK ) {
@ -1347,17 +1347,17 @@ static int ReadResponseLineAndHeaders(
} else if( status == PARSE_INCOMPLETE ) { } else if( status == PARSE_INCOMPLETE ) {
done = 0; done = 0;
} else { } else {
//error /*error */
return status; return status;
} }
while( !done ) { while( !done ) {
num_read = sock_read( info, buf, sizeof( buf ), timeout_secs ); num_read = sock_read( info, buf, sizeof( buf ), timeout_secs );
if( num_read > 0 ) { if( num_read > 0 ) {
// append data to buffer /* append data to buffer */
ret_code = membuffer_append( &parser->msg.msg, buf, num_read ); ret_code = membuffer_append( &parser->msg.msg, buf, num_read );
if( ret_code != 0 ) { if( ret_code != 0 ) {
// set failure status /* set failure status */
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR; parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
return PARSE_FAILURE; return PARSE_FAILURE;
} }
@ -1367,13 +1367,13 @@ static int ReadResponseLineAndHeaders(
} else if( status == PARSE_INCOMPLETE ) { } else if( status == PARSE_INCOMPLETE ) {
done = 0; done = 0;
} else { } else {
//error /*error */
return status; return status;
} }
} else if( num_read == 0 ) { } else if( num_read == 0 ) {
// partial msg /* partial msg */
*http_error_code = HTTP_BAD_REQUEST; // or response *http_error_code = HTTP_BAD_REQUEST; /* or response */
return UPNP_E_BAD_HTTPMSG; return UPNP_E_BAD_HTTPMSG;
} else { } else {
@ -1391,18 +1391,18 @@ static int ReadResponseLineAndHeaders(
} else if( status == PARSE_INCOMPLETE ) { } else if( status == PARSE_INCOMPLETE ) {
done = 0; done = 0;
} else { } else {
//error /*error */
return status; return status;
} }
//read headers /*read headers */
while( !done ) { while( !done ) {
num_read = sock_read( info, buf, sizeof( buf ), timeout_secs ); num_read = sock_read( info, buf, sizeof( buf ), timeout_secs );
if( num_read > 0 ) { if( num_read > 0 ) {
// append data to buffer /* append data to buffer */
ret_code = membuffer_append( &parser->msg.msg, buf, num_read ); ret_code = membuffer_append( &parser->msg.msg, buf, num_read );
if( ret_code != 0 ) { if( ret_code != 0 ) {
// set failure status /* set failure status */
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR; parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
return PARSE_FAILURE; return PARSE_FAILURE;
} }
@ -1414,13 +1414,13 @@ static int ReadResponseLineAndHeaders(
} else if( status == PARSE_INCOMPLETE ) { } else if( status == PARSE_INCOMPLETE ) {
done = 0; done = 0;
} else { } else {
//error /*error */
return status; return status;
} }
} else if( num_read == 0 ) { } else if( num_read == 0 ) {
// partial msg /* partial msg */
*http_error_code = HTTP_BAD_REQUEST; // or response *http_error_code = HTTP_BAD_REQUEST; /* or response */
return UPNP_E_BAD_HTTPMSG; return UPNP_E_BAD_HTTPMSG;
} else { } else {
@ -1473,7 +1473,7 @@ int http_ReadHttpGet(
} }
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
//first parse what has already been gotten /*first parse what has already been gotten */
if( handle->response.position != POS_COMPLETE ) { if( handle->response.position != POS_COMPLETE ) {
status = parser_parse_entity( &handle->response ); status = parser_parse_entity( &handle->response );
} else { } else {
@ -1481,16 +1481,16 @@ int http_ReadHttpGet(
} }
if( status == PARSE_INCOMPLETE_ENTITY ) { if( status == PARSE_INCOMPLETE_ENTITY ) {
// read until close /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if( ( status != PARSE_SUCCESS ) } else if( ( status != PARSE_SUCCESS )
&& ( status != PARSE_CONTINUE_1 ) && ( status != PARSE_CONTINUE_1 )
&& ( status != PARSE_INCOMPLETE ) ) { && ( status != PARSE_INCOMPLETE ) ) {
//error /*error */
*size = 0; *size = 0;
return UPNP_E_BAD_RESPONSE; return UPNP_E_BAD_RESPONSE;
} }
//read more if necessary entity /*read more if necessary entity */
while( ( ( handle->response.msg.entity_offset + *size ) > while( ( ( handle->response.msg.entity_offset + *size ) >
handle->response.msg.entity.length ) handle->response.msg.entity.length )
&& ( ! handle->cancel ) && ( ! handle->cancel )
@ -1499,11 +1499,11 @@ int http_ReadHttpGet(
sock_read( &handle->sock_info, tempbuf, sizeof( tempbuf ), sock_read( &handle->sock_info, tempbuf, sizeof( tempbuf ),
&timeout ); &timeout );
if( num_read > 0 ) { if( num_read > 0 ) {
// append data to buffer /* append data to buffer */
ret_code = membuffer_append( &handle->response.msg.msg, ret_code = membuffer_append( &handle->response.msg.msg,
tempbuf, num_read ); tempbuf, num_read );
if( ret_code != 0 ) { if( ret_code != 0 ) {
// set failure status /* set failure status */
handle->response.http_error_code = handle->response.http_error_code =
HTTP_INTERNAL_SERVER_ERROR; HTTP_INTERNAL_SERVER_ERROR;
*size = 0; *size = 0;
@ -1511,12 +1511,12 @@ int http_ReadHttpGet(
} }
status = parser_parse_entity( &handle->response ); status = parser_parse_entity( &handle->response );
if( status == PARSE_INCOMPLETE_ENTITY ) { if( status == PARSE_INCOMPLETE_ENTITY ) {
// read until close /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if( ( status != PARSE_SUCCESS ) } else if( ( status != PARSE_SUCCESS )
&& ( status != PARSE_CONTINUE_1 ) && ( status != PARSE_CONTINUE_1 )
&& ( status != PARSE_INCOMPLETE ) ) { && ( status != PARSE_INCOMPLETE ) ) {
//error /*error */
*size = 0; *size = 0;
return UPNP_E_BAD_RESPONSE; return UPNP_E_BAD_RESPONSE;
} }
@ -1527,9 +1527,9 @@ int http_ReadHttpGet(
handle->response.msg.msg.buf ); handle->response.msg.msg.buf );
handle->response.position = POS_COMPLETE; handle->response.position = POS_COMPLETE;
} else { } else {
// partial msg /* partial msg */
*size = 0; *size = 0;
handle->response.http_error_code = HTTP_BAD_REQUEST; // or response handle->response.http_error_code = HTTP_BAD_REQUEST; /* or response */
return UPNP_E_BAD_HTTPMSG; return UPNP_E_BAD_HTTPMSG;
} }
} else { } else {
@ -1641,7 +1641,7 @@ http_CloseHttpGet( IN void *Handle )
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
sock_destroy( &handle->sock_info, SD_BOTH ); //should shutdown completely sock_destroy( &handle->sock_info, SD_BOTH ); /*should shutdown completely */
httpmsg_destroy( &handle->response.msg ); httpmsg_destroy( &handle->response.msg );
free( handle ); free( handle );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
@ -1864,8 +1864,8 @@ http_SendStatusResponse( IN SOCKINFO * info,
ret = http_MakeMessage( ret = http_MakeMessage(
&membuf, response_major, response_minor, &membuf, response_major, response_minor,
"RSCB", "RSCB",
http_status_code, // response start line http_status_code, /* response start line */
http_status_code ); // body http_status_code ); /* body */
if( ret == 0 ) { if( ret == 0 ) {
timeout = HTTP_DEFAULT_TIMEOUT; timeout = HTTP_DEFAULT_TIMEOUT;
ret = http_SendMessage( info, &timeout, "b", ret = http_SendMessage( info, &timeout, "b",
@ -1903,25 +1903,25 @@ http_SendStatusResponse( IN SOCKINFO * info,
* depending on major,minor version * depending on major,minor version
* 'c': (no args) appends CRLF "\r\n" * 'c': (no args) appends CRLF "\r\n"
* 'D': (no args) appends HTTP DATE: header * 'D': (no args) appends HTTP DATE: header
* 'd': arg = int number // appends decimal number * 'd': arg = int number -- appends decimal number
* 'G': arg = range information // add range header * 'G': arg = range information -- add range header
* 'h': arg = off_t number // appends off_t number * 'h': arg = off_t number -- appends off_t number
* 'K': (no args) // add chunky header * 'K': (no args) -- add chunky header
* 'L': arg = language information // add Content-Language header if * 'L': arg = language information -- add Content-Language header if
* Accept-Language header is not empty and if * Accept-Language header is not empty and if
* WEB_SERVER_CONTENT_LANGUAGE is not empty * WEB_SERVER_CONTENT_LANGUAGE is not empty
* 'N': arg1 = off_t content_length // content-length header * 'N': arg1 = off_t content_length -- content-length header
* 'q': arg1 = http_method_t // request start line and HOST header * 'q': arg1 = http_method_t -- request start line and HOST header
* arg2 = (uri_type *) * arg2 = (uri_type *)
* 'Q': arg1 = http_method_t; // start line of request * 'Q': arg1 = http_method_t; -- start line of request
* arg2 = char* url; * arg2 = char* url;
* arg3 = size_t url_length * arg3 = size_t url_length
* 'R': arg = int status_code // adds a response start line * 'R': arg = int status_code -- adds a response start line
* 'S': (no args) appends HTTP SERVER: header * 'S': (no args) appends HTTP SERVER: header
* 's': arg = const char* C_string * 's': arg = const char* C_string
* 'T': arg = char * content_type; format * 'T': arg = char * content_type; format
* e.g: "text/html"; content-type header * e.g: "text/html"; content-type header
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt * 't': arg = time_t * gmt_time -- appends time in RFC 1123 fmt
* 'U': (no args) appends HTTP USER-AGENT: header * 'U': (no args) appends HTTP USER-AGENT: header
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent * 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
* *
@ -1967,7 +1967,7 @@ http_MakeMessage( INOUT membuffer * buf,
while( ( c = *fmt++ ) != 0 ) { while( ( c = *fmt++ ) != 0 ) {
if( c == 's' ) { if( c == 's' ) {
// C string /* C string */
s = ( char * )va_arg( argp, char * ); s = ( char * )va_arg( argp, char * );
assert( s ); assert( s );
UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,"Adding a string : %s\n", s); UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,"Adding a string : %s\n", s);
@ -1975,26 +1975,26 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'K' ) { } else if( c == 'K' ) {
// Add Chunky header /* Add Chunky header */
if( membuffer_append if( membuffer_append
( buf, "TRANSFER-ENCODING: chunked\r\n", ( buf, "TRANSFER-ENCODING: chunked\r\n",
strlen( "Transfer-Encoding: chunked\r\n" ) ) != 0 ) { strlen( "Transfer-Encoding: chunked\r\n" ) ) != 0 ) {
goto error_handler; goto error_handler;
} }
} else if( c == 'G' ) { } else if( c == 'G' ) {
// Add Range header /* Add Range header */
struct SendInstruction *RespInstr; struct SendInstruction *RespInstr;
RespInstr = (struct SendInstruction *) RespInstr = (struct SendInstruction *)
va_arg( argp, struct SendInstruction *); va_arg( argp, struct SendInstruction *);
assert( RespInstr ); assert( RespInstr );
// connection header /* connection header */
if( membuffer_append if( membuffer_append
( buf, RespInstr->RangeHeader, ( buf, RespInstr->RangeHeader,
strlen( RespInstr->RangeHeader ) ) != 0 ) { strlen( RespInstr->RangeHeader ) ) != 0 ) {
goto error_handler; goto error_handler;
} }
} else if( c == 'b' ) { } else if( c == 'b' ) {
// mem buffer /* mem buffer */
s = ( char * )va_arg( argp, char * ); s = ( char * )va_arg( argp, char * );
UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__, UpnpPrintf(UPNP_ALL,HTTP,__FILE__,__LINE__,
@ -2006,13 +2006,13 @@ http_MakeMessage( INOUT membuffer * buf,
} }
} }
else if( c == 'c' ) { else if( c == 'c' ) {
// crlf /* crlf */
if( membuffer_append( buf, "\r\n", 2 ) != 0 ) { if( membuffer_append( buf, "\r\n", 2 ) != 0 ) {
goto error_handler; goto error_handler;
} }
} }
else if( c == 'd' ) { else if( c == 'd' ) {
// integer /* integer */
num = ( int )va_arg( argp, int ); num = ( int )va_arg( argp, int );
sprintf( tempbuf, "%"PRIzu, num ); sprintf( tempbuf, "%"PRIzu, num );
if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) { if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) {
@ -2020,7 +2020,7 @@ http_MakeMessage( INOUT membuffer * buf,
} }
} }
else if( c == 'h' ) { else if( c == 'h' ) {
// off_t /* off_t */
bignum = ( off_t )va_arg( argp, off_t ); bignum = ( off_t )va_arg( argp, off_t );
sprintf( tempbuf, "%"PRId64, (int64_t)bignum ); sprintf( tempbuf, "%"PRId64, (int64_t)bignum );
@ -2029,15 +2029,15 @@ http_MakeMessage( INOUT membuffer * buf,
} }
} }
else if( c == 't' || c == 'D' ) { else if( c == 't' || c == 'D' ) {
// date /* date */
if( c == 'D' ) { if( c == 'D' ) {
// header /* header */
start_str = "DATE: "; start_str = "DATE: ";
end_str = "\r\n"; end_str = "\r\n";
curr_time = time( NULL ); curr_time = time( NULL );
date = gmtime( &curr_time ); date = gmtime( &curr_time );
} else { } else {
// date value only /* date value only */
start_str = end_str = ""; start_str = end_str = "";
loc_time = ( time_t * ) va_arg( argp, time_t * ); loc_time = ( time_t * ) va_arg( argp, time_t * );
assert( loc_time ); assert( loc_time );
@ -2054,8 +2054,8 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if ( c == 'L' ) { } else if ( c == 'L' ) {
// Add CONTENT-LANGUAGE header only if WEB_SERVER_CONTENT_LANGUAGE /* Add CONTENT-LANGUAGE header only if WEB_SERVER_CONTENT_LANGUAGE */
// is not empty and if Accept-Language header is not empty /* is not empty and if Accept-Language header is not empty */
struct SendInstruction *RespInstr; struct SendInstruction *RespInstr;
RespInstr = (struct SendInstruction *) RespInstr = (struct SendInstruction *)
va_arg( argp, struct SendInstruction *); va_arg( argp, struct SendInstruction *);
@ -2071,14 +2071,14 @@ http_MakeMessage( INOUT membuffer * buf,
if( ( http_major_version > 1 ) || if( ( http_major_version > 1 ) ||
( http_major_version == 1 && http_minor_version == 1 ) ( http_major_version == 1 && http_minor_version == 1 )
) { ) {
// connection header /* connection header */
if( membuffer_append_str( buf, "CONNECTION: close\r\n" ) != if( membuffer_append_str( buf, "CONNECTION: close\r\n" ) !=
0 ) { 0 ) {
goto error_handler; goto error_handler;
} }
} }
} else if( c == 'N' ) { } else if( c == 'N' ) {
// content-length header /* content-length header */
bignum = ( off_t )va_arg( argp, off_t ); bignum = ( off_t )va_arg( argp, off_t );
assert( bignum >= 0 ); assert( bignum >= 0 );
@ -2089,7 +2089,7 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'S' || c == 'U' ) { } else if( c == 'S' || c == 'U' ) {
// SERVER or USER-AGENT header /* SERVER or USER-AGENT header */
temp_str = ( c == 'S' ) ? "SERVER: " : "USER-AGENT: "; temp_str = ( c == 'S' ) ? "SERVER: " : "USER-AGENT: ";
get_sdk_info( tempbuf ); get_sdk_info( tempbuf );
if (http_MakeMessage( if (http_MakeMessage(
@ -2099,7 +2099,7 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'X' ) { } else if( c == 'X' ) {
// C string /* C string */
s = ( char * )va_arg( argp, char * ); s = ( char * )va_arg( argp, char * );
assert( s ); assert( s );
if( membuffer_append_str( buf, "X-User-Agent: ") != 0 ) { if( membuffer_append_str( buf, "X-User-Agent: ") != 0 ) {
@ -2109,15 +2109,15 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'R' ) { } else if( c == 'R' ) {
// response start line /* response start line */
// e.g.: 'HTTP/1.1 200 OK' /* e.g.: 'HTTP/1.1 200 OK' */
// /* */
// code /* code */
status_code = ( int )va_arg( argp, int ); status_code = ( int )va_arg( argp, int );
assert( status_code > 0 ); assert( status_code > 0 );
sprintf( tempbuf, "HTTP/%d.%d %d ", sprintf( tempbuf, "HTTP/%d.%d %d ",
http_major_version, http_minor_version, status_code ); http_major_version, http_minor_version, status_code );
// str /* str */
status_msg = http_get_code_text( status_code ); status_msg = http_get_code_text( status_code );
if (http_MakeMessage( if (http_MakeMessage(
buf, http_major_version, http_minor_version, buf, http_major_version, http_minor_version,
@ -2127,8 +2127,8 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'B' ) { } else if( c == 'B' ) {
// body of a simple reply /* body of a simple reply */
// /* */
status_code = ( int )va_arg( argp, int ); status_code = ( int )va_arg( argp, int );
sprintf( tempbuf, "%s%d %s%s", sprintf( tempbuf, "%s%d %s%s",
"<html><body><h1>", "<html><body><h1>",
@ -2138,29 +2138,29 @@ http_MakeMessage( INOUT membuffer * buf,
if (http_MakeMessage( if (http_MakeMessage(
buf, http_major_version, http_minor_version, buf, http_major_version, http_minor_version,
"NTcs", "NTcs",
bignum, // content-length bignum, /* content-length */
"text/html", // content-type "text/html", /* content-type */
tempbuf ) != 0 // body tempbuf ) != 0 /* body */
) { ) {
goto error_handler; goto error_handler;
} }
} else if( c == 'Q' ) { } else if( c == 'Q' ) {
// request start line /* request start line */
// GET /foo/bar.html HTTP/1.1\r\n /* GET /foo/bar.html HTTP/1.1\r\n */
method = ( http_method_t ) va_arg( argp, http_method_t ); method = ( http_method_t ) va_arg( argp, http_method_t );
method_str = method_to_str( method ); method_str = method_to_str( method );
url_str = ( const char * )va_arg( argp, const char * ); url_str = ( const char * )va_arg( argp, const char * );
num = ( size_t )va_arg( argp, size_t ); // length of url_str num = ( size_t )va_arg( argp, size_t ); /* length of url_str */
if (http_MakeMessage( if (http_MakeMessage(
buf, http_major_version, http_minor_version, buf, http_major_version, http_minor_version,
"ssbsdsdc", "ssbsdsdc",
method_str, // method method_str, /* method */
" ", url_str, num, // url " ", url_str, num, /* url */
" HTTP/", http_major_version, ".", http_minor_version ) != 0 ) { " HTTP/", http_major_version, ".", http_minor_version ) != 0 ) {
goto error_handler; goto error_handler;
} }
} else if( c == 'q' ) { } else if( c == 'q' ) {
// request start line and HOST header /* request start line and HOST header */
method = ( http_method_t ) va_arg( argp, http_method_t ); method = ( http_method_t ) va_arg( argp, http_method_t );
uri_ptr = ( uri_type * ) va_arg( argp, uri_type * ); uri_ptr = ( uri_type * ) va_arg( argp, uri_type * );
assert( uri_ptr ); assert( uri_ptr );
@ -2176,8 +2176,8 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler; goto error_handler;
} }
} else if( c == 'T' ) { } else if( c == 'T' ) {
// content type header /* content type header */
temp_str = ( const char * )va_arg( argp, const char * ); // type/subtype format temp_str = ( const char * )va_arg( argp, const char * ); /* type/subtype format */
if (http_MakeMessage( if (http_MakeMessage(
buf, http_major_version, http_minor_version, buf, http_major_version, http_minor_version,
"ssc", "ssc",
@ -2266,7 +2266,7 @@ MakeGetMessageEx( const char *url_str,
strlen( url_str ), url ) ) != UPNP_E_SUCCESS ) { strlen( url_str ), url ) ) != UPNP_E_SUCCESS ) {
break; break;
} }
// make msg /* make msg */
membuffer_init( request ); membuffer_init( request );
urlPath = alloca( strlen( url_str ) + 1 ); urlPath = alloca( strlen( url_str ) + 1 );
if( !urlPath ) { if( !urlPath ) {
@ -2483,7 +2483,7 @@ int http_OpenHttpGetEx(
* Return: * Return:
* UPNP_INLINE void * UPNP_INLINE void
************************************************************************/ ************************************************************************/
// 'info' should have a size of at least 100 bytes /* 'info' should have a size of at least 100 bytes */
void void
get_sdk_info( OUT char *info ) get_sdk_info( OUT char *info )
{ {

View File

@ -1,38 +1,40 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/************************************************************************ /*!
* Purpose: This file a function to extract the header information from * * \file
* an http message and then matches the data with XML data. * *
************************************************************************/ * Purpose: This file a function to extract the header information from
* an http message and then matches the data with XML data.
*/
#include "config.h" #include "config.h"
#include <assert.h> #include <assert.h>
@ -42,30 +44,17 @@
#include "statcodes.h" #include "statcodes.h"
#include "parsetools.h" #include "parsetools.h"
/************************************************************************ xboolean has_xml_content_type(http_message_t *hmsg)
* Function: has_xml_content_type
*
* Parameters:
* IN http_message_t* hmsg ; HTTP Message object
*
* Description: Find the header from the HTTP message and match the
* header for xml data.
*
* Returns:
* BOOLEAN
************************************************************************/
xboolean
has_xml_content_type( IN http_message_t * hmsg )
{ {
memptr hdr_value; memptr hdr_value;
assert(hmsg); assert(hmsg);
// find 'content-type' header which must have text/xml /* find 'content-type' header which must have text/xml */
if( httpmsg_find_hdr( hmsg, HDR_CONTENT_TYPE, &hdr_value ) != NULL && if (httpmsg_find_hdr(hmsg, HDR_CONTENT_TYPE, &hdr_value) &&
matchstr( hdr_value.buf, hdr_value.length, matchstr(hdr_value.buf, hdr_value.length, "%itext%w/%wxml" ) == PARSE_OK) {
"%itext%w/%wxml" ) == PARSE_OK ) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/************************************************************************ /************************************************************************
* Purpose: This file defines status codes, buffers to store the status * * Purpose: This file defines status codes, buffers to store the status *
@ -128,7 +128,7 @@ init_table( IN const char *encoded_str,
for( i = 0; i < tbl_size; i++ ) { for( i = 0; i < tbl_size; i++ ) {
table[i] = s; table[i] = s;
s += strlen( s ) + 1; // next entry s += strlen( s ) + 1; /* next entry */
} }
} }
@ -153,7 +153,7 @@ init_tables( void )
init_table( Http4xxStr, Http4xxCodes, NUM_4XX_CODES ); init_table( Http4xxStr, Http4xxCodes, NUM_4XX_CODES );
init_table( Http5xxStr, Http5xxCodes, NUM_5XX_CODES ); init_table( Http5xxStr, Http5xxCodes, NUM_5XX_CODES );
gInitialized = TRUE; // mark only after complete gInitialized = TRUE; /* mark only after complete */
} }
/************************************************************************ /************************************************************************

View File

@ -315,7 +315,7 @@ static UPNP_INLINE int get_content_type(
(*content_type) = NULL; (*content_type) = NULL;
// get ext /* get ext */
extension = strrchr(filename, '.'); extension = strrchr(filename, '.');
if (extension != NULL) { if (extension != NULL) {
if (search_extension(extension + 1, &type, &subtype) == 0) { if (search_extension(extension + 1, &type, &subtype) == 0) {
@ -324,7 +324,7 @@ static UPNP_INLINE int get_content_type(
} }
if (!ctype_found) { if (!ctype_found) {
// unknown content type /* unknown content type */
type = gMediaTypes[APPLICATION_INDEX]; type = gMediaTypes[APPLICATION_INDEX];
subtype = "octet-stream"; subtype = "octet-stream";
} }
@ -395,7 +395,7 @@ static void alias_release(
struct xml_alias_t *alias) struct xml_alias_t *alias)
{ {
ithread_mutex_lock(&gWebMutex); ithread_mutex_lock(&gWebMutex);
// ignore invalid alias /* ignore invalid alias */
if (!is_valid_alias(alias)) { if (!is_valid_alias(alias)) {
ithread_mutex_unlock(&gWebMutex); ithread_mutex_unlock(&gWebMutex);
return; return;
@ -419,7 +419,7 @@ int web_server_set_alias(const char *alias_name,
alias_release(&gAliasDoc); alias_release(&gAliasDoc);
if (alias_name == NULL) { if (alias_name == NULL) {
// don't serve aliased doc anymore /* don't serve aliased doc anymore */
return 0; return 0;
} }
assert(alias_content != NULL); assert(alias_content != NULL);
@ -427,24 +427,24 @@ int web_server_set_alias(const char *alias_name,
membuffer_init(&alias.name); membuffer_init(&alias.name);
alias.ct = NULL; alias.ct = NULL;
do { do {
// insert leading /, if missing /* insert leading /, if missing */
if (*alias_name != '/') { if (*alias_name != '/') {
if (membuffer_assign_str(&alias.name, "/") != 0) { if (membuffer_assign_str(&alias.name, "/") != 0) {
break; // error; out of mem break; /* error; out of mem */
} }
} }
ret_code = membuffer_append_str(&alias.name, alias_name); ret_code = membuffer_append_str(&alias.name, alias_name);
if (ret_code != 0) { if (ret_code != 0) {
break; // error break; /* error */
} }
if ((alias.ct = (int *)malloc(sizeof(int))) == NULL) { if ((alias.ct = (int *)malloc(sizeof(int))) == NULL) {
break; // error break; /* error */
} }
*alias.ct = 1; *alias.ct = 1;
membuffer_attach(&alias.doc, (char *)alias_content, membuffer_attach(&alias.doc, (char *)alias_content,
alias_content_length); alias_content_length);
alias.last_modified = last_modified; alias.last_modified = last_modified;
// save in module var /* save in module var */
ithread_mutex_lock(&gWebMutex); ithread_mutex_lock(&gWebMutex);
gAliasDoc = alias; gAliasDoc = alias;
ithread_mutex_unlock(&gWebMutex); ithread_mutex_unlock(&gWebMutex);
@ -452,8 +452,8 @@ int web_server_set_alias(const char *alias_name,
return 0; return 0;
} while (FALSE); } while (FALSE);
// error handler /* error handler */
// free temp alias /* free temp alias */
membuffer_destroy(&alias.name); membuffer_destroy(&alias.name);
membuffer_destroy(&alias.doc); membuffer_destroy(&alias.doc);
free(alias.ct); free(alias.ct);
@ -464,13 +464,13 @@ int web_server_init()
{ {
int ret = 0; int ret = 0;
if (bWebServerState == WEB_SERVER_DISABLED) { if (bWebServerState == WEB_SERVER_DISABLED) {
// decode media list /* decode media list */
media_list_init(); media_list_init();
membuffer_init(&gDocumentRootDir); membuffer_init(&gDocumentRootDir);
glob_alias_init(); glob_alias_init();
pVirtualDirList = NULL; pVirtualDirList = NULL;
// Initialize callbacks /* Initialize callbacks */
virtualDirCallback.get_info = NULL; virtualDirCallback.get_info = NULL;
virtualDirCallback.open = NULL; virtualDirCallback.open = NULL;
virtualDirCallback.read = NULL; virtualDirCallback.read = NULL;
@ -541,7 +541,7 @@ static int get_file_info(
return -1; return -1;
} }
// check readable /* check readable */
fp = fopen(filename, "r"); fp = fopen(filename, "r");
info->is_readable = (fp != NULL); info->is_readable = (fp != NULL);
if (fp) { if (fp) {
@ -570,9 +570,9 @@ int web_server_set_root_dir(const char *root_dir)
if (ret != 0) { if (ret != 0) {
return ret; return ret;
} }
// remove trailing '/', if any /* remove trailing '/', if any */
if (gDocumentRootDir.length > 0) { if (gDocumentRootDir.length > 0) {
index = gDocumentRootDir.length - 1; // last char index = gDocumentRootDir.length - 1; /* last char */
if (gDocumentRootDir.buf[index] == '/') { if (gDocumentRootDir.buf[index] == '/') {
membuffer_delete(&gDocumentRootDir, index, 1); membuffer_delete(&gDocumentRootDir, index, 1);
} }
@ -600,7 +600,7 @@ static UPNP_INLINE xboolean get_alias(
{ {
int cmp = strcmp(alias->name.buf, request_file); int cmp = strcmp(alias->name.buf, request_file);
if (cmp == 0) { if (cmp == 0) {
// fill up info /* fill up info */
info->file_length = alias->doc.length; info->file_length = alias->doc.length;
info->is_readable = TRUE; info->is_readable = TRUE;
info->is_directory = FALSE; info->is_directory = FALSE;
@ -896,7 +896,7 @@ static int CheckOtherHTTPHeaders(
{ {
http_header_t *header; http_header_t *header;
ListNode *node; ListNode *node;
//NNS: dlist_node* node; /*NNS: dlist_node* node; */
int index, RetCode = HTTP_OK; int index, RetCode = HTTP_OK;
char *TmpBuf; char *TmpBuf;
@ -906,7 +906,7 @@ static int CheckOtherHTTPHeaders(
node = ListHead(&Req->headers); node = ListHead(&Req->headers);
while (node != NULL) { while (node != NULL) {
header = (http_header_t *) node->item; header = (http_header_t *) node->item;
// find header type. /* find header type. */
index = map_str_to_int((const char *)header->name.buf, index = map_str_to_int((const char *)header->name.buf,
header->name.length, Http_Header_Names, header->name.length, Http_Header_Names,
NUM_HTTP_HEADER_NAMES, FALSE); NUM_HTTP_HEADER_NAMES, FALSE);
@ -955,23 +955,23 @@ static int CheckOtherHTTPHeaders(
header.value is the value. header.value is the value.
*/ */
/* /*
case HDR_CONTENT_TYPE: //return 1; case HDR_CONTENT_TYPE: return 1;
case HDR_CONTENT_LANGUAGE://return 1; case HDR_CONTENT_LANGUAGE:return 1;
case HDR_LOCATION: //return 1; case HDR_LOCATION: return 1;
case HDR_CONTENT_LOCATION://return 1; case HDR_CONTENT_LOCATION:return 1;
case HDR_ACCEPT: //return 1; case HDR_ACCEPT: return 1;
case HDR_ACCEPT_CHARSET://return 1; case HDR_ACCEPT_CHARSET: return 1;
case HDR_USER_AGENT: break;//return 1; case HDR_USER_AGENT: return 1;
*/ */
//Header check for encoding /*Header check for encoding */
/* /*
case HDR_ACCEPT_RANGE: //Server capability. case HDR_ACCEPT_RANGE:
case HDR_CONTENT_RANGE://Response. case HDR_CONTENT_RANGE:
case HDR_IF_RANGE: case HDR_IF_RANGE:
*/ */
//Header check for encoding /*Header check for encoding */
/* /*
case HDR_ACCEPT_ENCODING: case HDR_ACCEPT_ENCODING:
if(StrStr(TmpBuf, "identity")) if(StrStr(TmpBuf, "identity"))
@ -980,7 +980,7 @@ static int CheckOtherHTTPHeaders(
} }
else return -1; else return -1;
case HDR_CONTENT_ENCODING: case HDR_CONTENT_ENCODING:
case HDR_TRANSFER_ENCODING: //Response case HDR_TRANSFER_ENCODING:
*/ */
break; break;
} }
@ -1036,22 +1036,22 @@ static int process_request(
req->method == HTTPMETHOD_HEAD || req->method == HTTPMETHOD_HEAD ||
req->method == HTTPMETHOD_POST || req->method == HTTPMETHOD_POST ||
req->method == HTTPMETHOD_SIMPLEGET); req->method == HTTPMETHOD_SIMPLEGET);
// init /* init */
request_doc = NULL; request_doc = NULL;
finfo.content_type = NULL; finfo.content_type = NULL;
alias_grabbed = FALSE; alias_grabbed = FALSE;
err_code = HTTP_INTERNAL_SERVER_ERROR; // default error err_code = HTTP_INTERNAL_SERVER_ERROR; /* default error */
using_virtual_dir = FALSE; using_virtual_dir = FALSE;
using_alias = FALSE; using_alias = FALSE;
http_CalcResponseVersion(req->major_version, req->minor_version, http_CalcResponseVersion(req->major_version, req->minor_version,
&resp_major, &resp_minor); &resp_major, &resp_minor);
// /* */
// remove dots /* remove dots */
// /* */
request_doc = malloc(url->pathquery.size + 1); request_doc = malloc(url->pathquery.size + 1);
if (request_doc == NULL) { if (request_doc == NULL) {
goto error_handler; // out of mem goto error_handler; /* out of mem */
} }
memcpy(request_doc, url->pathquery.buff, url->pathquery.size); memcpy(request_doc, url->pathquery.buff, url->pathquery.size);
request_doc[url->pathquery.size] = '\0'; request_doc[url->pathquery.size] = '\0';
@ -1063,7 +1063,7 @@ static int process_request(
goto error_handler; goto error_handler;
} }
if (*request_doc != '/') { if (*request_doc != '/') {
// no slash /* no slash */
err_code = HTTP_BAD_REQUEST; err_code = HTTP_BAD_REQUEST;
goto error_handler; goto error_handler;
} }
@ -1092,13 +1092,13 @@ static int process_request(
} }
if (using_virtual_dir) { if (using_virtual_dir) {
if (req->method != HTTPMETHOD_POST) { if (req->method != HTTPMETHOD_POST) {
// get file info /* get file info */
if (virtualDirCallback. if (virtualDirCallback.
get_info(filename->buf, &finfo) != 0) { get_info(filename->buf, &finfo) != 0) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
// try index.html if req is a dir /* try index.html if req is a dir */
if (finfo.is_directory) { if (finfo.is_directory) {
if (filename->buf[filename->length - 1] == '/') { if (filename->buf[filename->length - 1] == '/') {
temp_str = "index.html"; temp_str = "index.html";
@ -1109,7 +1109,7 @@ static int process_request(
0) { 0) {
goto error_handler; goto error_handler;
} }
// get info /* get info */
if ((virtualDirCallback. if ((virtualDirCallback.
get_info(filename->buf, get_info(filename->buf,
&finfo) != UPNP_E_SUCCESS) &finfo) != UPNP_E_SUCCESS)
@ -1118,42 +1118,42 @@ static int process_request(
goto error_handler; goto error_handler;
} }
} }
// not readable /* not readable */
if (!finfo.is_readable) { if (!finfo.is_readable) {
err_code = HTTP_FORBIDDEN; err_code = HTTP_FORBIDDEN;
goto error_handler; goto error_handler;
} }
// finally, get content type /* finally, get content type */
// if ( get_content_type(filename->buf, &content_type) != 0 ) /* if ( get_content_type(filename->buf, &content_type) != 0 ) */
//{ /*{ */
// goto error_handler; /* goto error_handler; */
// } /* } */
} }
} else if (!using_alias) { } else if (!using_alias) {
if (gDocumentRootDir.length == 0) { if (gDocumentRootDir.length == 0) {
goto error_handler; goto error_handler;
} }
// /* */
// get file name /* get file name */
// /* */
// filename str /* filename str */
if (membuffer_assign_str(filename, gDocumentRootDir.buf) != 0 || if (membuffer_assign_str(filename, gDocumentRootDir.buf) != 0 ||
membuffer_append_str(filename, request_doc) != 0) { membuffer_append_str(filename, request_doc) != 0) {
goto error_handler; // out of mem goto error_handler; /* out of mem */
} }
// remove trailing slashes /* remove trailing slashes */
while (filename->length > 0 && while (filename->length > 0 &&
filename->buf[filename->length - 1] == '/') { filename->buf[filename->length - 1] == '/') {
membuffer_delete(filename, filename->length - 1, 1); membuffer_delete(filename, filename->length - 1, 1);
} }
if (req->method != HTTPMETHOD_POST) { if (req->method != HTTPMETHOD_POST) {
// get info on file /* get info on file */
if (get_file_info(filename->buf, &finfo) != 0) { if (get_file_info(filename->buf, &finfo) != 0) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
// try index.html if req is a dir /* try index.html if req is a dir */
if (finfo.is_directory) { if (finfo.is_directory) {
if (filename->buf[filename->length - 1] == '/') { if (filename->buf[filename->length - 1] == '/') {
temp_str = "index.html"; temp_str = "index.html";
@ -1164,27 +1164,27 @@ static int process_request(
0) { 0) {
goto error_handler; goto error_handler;
} }
// get info /* get info */
if (get_file_info(filename->buf, &finfo) != 0 || if (get_file_info(filename->buf, &finfo) != 0 ||
finfo.is_directory) { finfo.is_directory) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
} }
// not readable /* not readable */
if (!finfo.is_readable) { if (!finfo.is_readable) {
err_code = HTTP_FORBIDDEN; err_code = HTTP_FORBIDDEN;
goto error_handler; goto error_handler;
} }
} }
// finally, get content type /* finally, get content type */
// if ( get_content_type(filename->buf, &content_type) != 0 ) /* if ( get_content_type(filename->buf, &content_type) != 0 ) */
// { /* { */
// goto error_handler; /* goto error_handler; */
// } /* } */
} }
RespInstr->ReadSendSize = finfo.file_length; RespInstr->ReadSendSize = finfo.file_length;
// Check other header field. /* Check other header field. */
if ((err_code = if ((err_code =
CheckOtherHTTPHeaders(req, RespInstr, CheckOtherHTTPHeaders(req, RespInstr,
finfo.file_length)) != HTTP_OK) { finfo.file_length)) != HTTP_OK) {
@ -1200,58 +1200,58 @@ static int process_request(
extra_headers = ""; extra_headers = "";
} }
if (RespInstr->IsRangeActive && RespInstr->IsChunkActive) { if (RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT /* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
// Transfer-Encoding: chunked /* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor, if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "T" "GKLD" "s" "tcS" "Xc" "sCc", "R" "T" "GKLD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code HTTP_PARTIAL_CONTENT, /* status code */
finfo.content_type, // content type finfo.content_type, /* content type */
RespInstr, // range info RespInstr, /* range info */
RespInstr, // language info RespInstr, /* language info */
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, &finfo.last_modified,
X_USER_AGENT, extra_headers) != 0) { X_USER_AGENT, extra_headers) != 0) {
goto error_handler; goto error_handler;
} }
} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) { } else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT /* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
// Transfer-Encoding: chunked /* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor, if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc", "R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code HTTP_PARTIAL_CONTENT, /* status code */
RespInstr->ReadSendSize, // content length RespInstr->ReadSendSize, /* content length */
finfo.content_type, // content type finfo.content_type, /* content type */
RespInstr, // range info RespInstr, /* range info */
RespInstr, // language info RespInstr, /* language info */
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, &finfo.last_modified,
X_USER_AGENT, extra_headers) != 0) { X_USER_AGENT, extra_headers) != 0) {
goto error_handler; goto error_handler;
} }
} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) { } else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT /* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
// Transfer-Encoding: chunked /* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor, if (http_MakeMessage(headers, resp_major, resp_minor,
"RK" "TLD" "s" "tcS" "Xc" "sCc", "RK" "TLD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, /* status code */
finfo.content_type, // content type finfo.content_type, /* content type */
RespInstr, // language info RespInstr, /* language info */
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, &finfo.last_modified,
X_USER_AGENT, extra_headers) != 0) { X_USER_AGENT, extra_headers) != 0) {
goto error_handler; goto error_handler;
} }
} else { } else {
// !RespInstr->IsRangeActive && !RespInstr->IsChunkActive /* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
if (RespInstr->ReadSendSize >= 0) { if (RespInstr->ReadSendSize >= 0) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT /* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
// Transfer-Encoding: chunked /* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor, if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "N" "TLD" "s" "tcS" "Xc" "sCc", "R" "N" "TLD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, /* status code */
RespInstr->ReadSendSize, // content length RespInstr->ReadSendSize, /* content length */
finfo.content_type, // content type finfo.content_type, /* content type */
RespInstr, // language info RespInstr, /* language info */
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, &finfo.last_modified,
X_USER_AGENT, X_USER_AGENT,
@ -1259,13 +1259,13 @@ static int process_request(
goto error_handler; goto error_handler;
} }
} else { } else {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT /* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
// Transfer-Encoding: chunked /* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor, if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "TLD" "s" "tcS" "b" "Xc" "sCc", "R" "TLD" "s" "tcS" "b" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, /* status code */
finfo.content_type, // content type finfo.content_type, /* content type */
RespInstr, // language info RespInstr, /* language info */
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, &finfo.last_modified,
X_USER_AGENT, X_USER_AGENT,
@ -1277,16 +1277,16 @@ static int process_request(
if (req->method == HTTPMETHOD_HEAD) { if (req->method == HTTPMETHOD_HEAD) {
*rtype = RESP_HEADERS; *rtype = RESP_HEADERS;
} else if (using_alias) { } else if (using_alias) {
// GET xml /* GET xml */
*rtype = RESP_XMLDOC; *rtype = RESP_XMLDOC;
} else if (using_virtual_dir) { } else if (using_virtual_dir) {
*rtype = RESP_WEBDOC; *rtype = RESP_WEBDOC;
} else { } else {
// GET filename /* GET filename */
*rtype = RESP_FILEDOC; *rtype = RESP_FILEDOC;
} }
// simple get http 0.9 as specified in http 1.0 /* simple get http 0.9 as specified in http 1.0 */
// don't send headers /* don't send headers */
if (req->method == HTTPMETHOD_SIMPLEGET) { if (req->method == HTTPMETHOD_SIMPLEGET) {
membuffer_destroy(headers); membuffer_destroy(headers);
} }
@ -1346,37 +1346,37 @@ static int http_RecvPostMessage(
} }
parser->position = POS_ENTITY; parser->position = POS_ENTITY;
do { do {
// first parse what has already been gotten /* first parse what has already been gotten */
if (parser->position != POS_COMPLETE) { if (parser->position != POS_COMPLETE) {
status = parser_parse_entity(parser); status = parser_parse_entity(parser);
} }
if (status == PARSE_INCOMPLETE_ENTITY) { if (status == PARSE_INCOMPLETE_ENTITY) {
// read until close /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if ((status != PARSE_SUCCESS) } else if ((status != PARSE_SUCCESS)
&& (status != PARSE_CONTINUE_1) && (status != PARSE_CONTINUE_1)
&& (status != PARSE_INCOMPLETE)) { && (status != PARSE_INCOMPLETE)) {
// error /* error */
fclose(Fp); fclose(Fp);
return HTTP_BAD_REQUEST; return HTTP_BAD_REQUEST;
} }
// read more if necessary entity /* read more if necessary entity */
while (entity_offset + Data_Buf_Size > parser->msg.entity.length && while (entity_offset + Data_Buf_Size > parser->msg.entity.length &&
parser->position != POS_COMPLETE) { parser->position != POS_COMPLETE) {
num_read = sock_read(info, Buf, sizeof(Buf), &Timeout); num_read = sock_read(info, Buf, sizeof(Buf), &Timeout);
if (num_read > 0) { if (num_read > 0) {
// append data to buffer /* append data to buffer */
ret_code = membuffer_append(&parser->msg.msg, ret_code = membuffer_append(&parser->msg.msg,
Buf, num_read); Buf, num_read);
if (ret_code != 0) { if (ret_code != 0) {
// set failure status /* set failure status */
parser->http_error_code = parser->http_error_code =
HTTP_INTERNAL_SERVER_ERROR; HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR; return HTTP_INTERNAL_SERVER_ERROR;
} }
status = parser_parse_entity(parser); status = parser_parse_entity(parser);
if (status == PARSE_INCOMPLETE_ENTITY) { if (status == PARSE_INCOMPLETE_ENTITY) {
// read until close /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if ((status != PARSE_SUCCESS) } else if ((status != PARSE_SUCCESS)
&& (status != PARSE_CONTINUE_1) && (status != PARSE_CONTINUE_1)
@ -1391,7 +1391,7 @@ static int http_RecvPostMessage(
print_http_headers(&parser->msg); print_http_headers(&parser->msg);
parser->position = POS_COMPLETE; parser->position = POS_COMPLETE;
} else { } else {
// partial msg or response /* partial msg or response */
parser->http_error_code = HTTP_BAD_REQUEST; parser->http_error_code = HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST; return HTTP_BAD_REQUEST;
} }
@ -1442,36 +1442,36 @@ void web_server_callback(http_parser_t *parser, INOUT http_message_t *req,
struct xml_alias_t xmldoc; struct xml_alias_t xmldoc;
struct SendInstruction RespInstr; struct SendInstruction RespInstr;
//Initialize instruction header. /*Initialize instruction header. */
RespInstr.IsVirtualFile = 0; RespInstr.IsVirtualFile = 0;
RespInstr.IsChunkActive = 0; RespInstr.IsChunkActive = 0;
RespInstr.IsRangeActive = 0; RespInstr.IsRangeActive = 0;
RespInstr.IsTrailers = 0; RespInstr.IsTrailers = 0;
memset(RespInstr.AcceptLanguageHeader, 0, memset(RespInstr.AcceptLanguageHeader, 0,
sizeof(RespInstr.AcceptLanguageHeader)); sizeof(RespInstr.AcceptLanguageHeader));
// init /* init */
membuffer_init(&headers); membuffer_init(&headers);
membuffer_init(&filename); membuffer_init(&filename);
//Process request should create the different kind of header depending on the /*Process request should create the different kind of header depending on the */
//the type of request. /*the type of request. */
ret = process_request(req, &rtype, &headers, &filename, &xmldoc, ret = process_request(req, &rtype, &headers, &filename, &xmldoc,
&RespInstr); &RespInstr);
if (ret != UPNP_E_SUCCESS) { if (ret != UPNP_E_SUCCESS) {
// send error code /* send error code */
http_SendStatusResponse(info, ret, req->major_version, http_SendStatusResponse(info, ret, req->major_version,
req->minor_version); req->minor_version);
} else { } else {
// send response /* send response */
switch (rtype) { switch (rtype) {
case RESP_FILEDOC: case RESP_FILEDOC:
// send file, I = further instruction to send data. /* send file, I = further instruction to send data. */
http_SendMessage(info, &timeout, "Ibf", &RespInstr, http_SendMessage(info, &timeout, "Ibf", &RespInstr,
headers.buf, headers.length, headers.buf, headers.length,
filename.buf); filename.buf);
break; break;
case RESP_XMLDOC: case RESP_XMLDOC:
// send xmldoc , I = further instruction to send data. /* send xmldoc , I = further instruction to send data. */
http_SendMessage(info, &timeout, http_SendMessage(info, &timeout,
"Ibb", &RespInstr, "Ibb", &RespInstr,
headers.buf, headers.length, headers.buf, headers.length,
@ -1479,7 +1479,7 @@ void web_server_callback(http_parser_t *parser, INOUT http_message_t *req,
alias_release(&xmldoc); alias_release(&xmldoc);
break; break;
case RESP_WEBDOC: case RESP_WEBDOC:
//, I = further instruction to send data. /*, I = further instruction to send data. */
/* /*
http_SendVirtualDirDoc( info, &timeout, "Ibf",&RespInstr, http_SendVirtualDirDoc( info, &timeout, "Ibf",&RespInstr,
headers.buf, headers.length, headers.buf, headers.length,
@ -1491,16 +1491,16 @@ void web_server_callback(http_parser_t *parser, INOUT http_message_t *req,
filename.buf); filename.buf);
break; break;
case RESP_HEADERS: case RESP_HEADERS:
// headers only /* headers only */
http_SendMessage(info, &timeout, http_SendMessage(info, &timeout,
"b", "b",
headers.buf, headers.length); headers.buf, headers.length);
break; break;
case RESP_POST: case RESP_POST:
// headers only /* headers only */
ret = http_RecvPostMessage(parser, info, filename.buf, ret = http_RecvPostMessage(parser, info, filename.buf,
&RespInstr); &RespInstr);
// Send response. /* Send response. */
http_MakeMessage(&headers, 1, 1, http_MakeMessage(&headers, 1, 1,
"RTLSXcCc", "RTLSXcCc",
ret, "text/html", X_USER_AGENT); ret, "text/html", X_USER_AGENT);

View File

@ -228,7 +228,7 @@ int copy_URL_list(URL_list *in, URL_list *out)
memcpy( out->URLs, in->URLs, len ); memcpy( out->URLs, in->URLs, len );
for( i = 0; i < in->size; i++ ) { for( i = 0; i < in->size; i++ ) {
//copy the parsed uri /*copy the parsed uri */
out->parsedURLs[i].type = in->parsedURLs[i].type; out->parsedURLs[i].type = in->parsedURLs[i].type;
copy_token( &in->parsedURLs[i].scheme, in->URLs, copy_token( &in->parsedURLs[i].scheme, in->URLs,
&out->parsedURLs[i].scheme, out->URLs ); &out->parsedURLs[i].scheme, out->URLs );
@ -343,22 +343,22 @@ int parse_hostport(
memset( out, 0, sizeof(hostport_type) ); memset( out, 0, sizeof(hostport_type) );
// Work on a copy of the input string. /* Work on a copy of the input string. */
strncpy( workbuf, in, sizeof(workbuf) ); strncpy( workbuf, in, sizeof(workbuf) );
c = workbuf; c = workbuf;
if( *c == '[' ) { if( *c == '[' ) {
// IPv6 addresses are enclosed in square brackets. /* IPv6 addresses are enclosed in square brackets. */
srvname = ++c; srvname = ++c;
while( *c != '\0' && *c != ']' ) { while( *c != '\0' && *c != ']' ) {
c++; c++;
} }
if( *c == '\0' ) { if( *c == '\0' ) {
// did not find closing bracket. /* did not find closing bracket. */
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
// NULL terminate the srvname and then increment c. /* NULL terminate the srvname and then increment c. */
*c++ = '\0'; // overwrite the ']' *c++ = '\0'; /* overwrite the ']' */
if( *c == ':' ) { if( *c == ':' ) {
has_port = 1; has_port = 1;
c++; c++;
@ -366,7 +366,7 @@ int parse_hostport(
af = AF_INET6; af = AF_INET6;
} }
else { else {
// IPv4 address -OR- host name. /* IPv4 address -OR- host name. */
srvname = c; srvname = c;
while( (*c != ':') && (*c != '/') && ( (isalnum(*c)) || (*c == '.') || (*c == '-') ) ) { while( (*c != ':') && (*c != '/') && ( (isalnum(*c)) || (*c == '.') || (*c == '-') ) ) {
if( *c == '.' ) if( *c == '.' )
@ -374,17 +374,17 @@ int parse_hostport(
c++; c++;
} }
has_port = (*c == ':') ? 1 : 0; has_port = (*c == ':') ? 1 : 0;
// NULL terminate the srvname /* NULL terminate the srvname */
*c = '\0'; *c = '\0';
if( has_port == 1 ) if( has_port == 1 )
c++; c++;
if( last_dot != NULL && isdigit(*(last_dot+1)) ) { if( last_dot != NULL && isdigit(*(last_dot+1)) ) {
// Must be an IPv4 address. /* Must be an IPv4 address. */
af = AF_INET; af = AF_INET;
} }
else { else {
// Must be a host name. /* Must be a host name. */
struct addrinfo hints, *res, *res0; struct addrinfo hints, *res, *res0;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -396,7 +396,7 @@ int parse_hostport(
for (res = res0; res; res = res->ai_next) { for (res = res0; res; res = res->ai_next) {
if( res->ai_family == AF_INET || if( res->ai_family == AF_INET ||
res->ai_family == AF_INET6 ) { res->ai_family == AF_INET6 ) {
// Found a valid IPv4 or IPv6 address. /* Found a valid IPv4 or IPv6 address. */
memcpy( &out->IPaddress, res->ai_addr, memcpy( &out->IPaddress, res->ai_addr,
res->ai_addrlen ); res->ai_addrlen );
break; break;
@ -405,40 +405,40 @@ int parse_hostport(
freeaddrinfo(res0); freeaddrinfo(res0);
if( res == NULL ) { if( res == NULL ) {
// Didn't find an AF_INET or AF_INET6 address. /* Didn't find an AF_INET or AF_INET6 address. */
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
} }
else { else {
// getaddrinfo failed. /* getaddrinfo failed. */
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
} }
} }
// Check if a port is specified. /* Check if a port is specified. */
if( has_port == 1 ) { if( has_port == 1 ) {
// Port is specified. /* Port is specified. */
srvport = c; srvport = c;
while( *c != '\0' && isdigit(*c) ) { while( *c != '\0' && isdigit(*c) ) {
c++; c++;
} }
port = (unsigned short int)atoi(srvport); port = (unsigned short int)atoi(srvport);
if( port == 0 ) { if( port == 0 ) {
// Bad port number. /* Bad port number. */
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
} }
else { else {
// Port was not specified, use default port. /* Port was not specified, use default port. */
port = 80; port = 80;
} }
// The length of the host and port string can be calculated by /* The length of the host and port string can be calculated by */
// subtracting pointers. /* subtracting pointers. */
hostport_size = (int)(c - workbuf); hostport_size = (int)(c - workbuf);
// Fill in the 'out' information. /* Fill in the 'out' information. */
if( af == AF_INET ) { if( af == AF_INET ) {
sai4->sin_family = AF_INET; sai4->sin_family = AF_INET;
sai4->sin_port = htons(port); sai4->sin_port = htons(port);
@ -450,8 +450,8 @@ int parse_hostport(
sai6->sin6_scope_id = gIF_INDEX; sai6->sin6_scope_id = gIF_INDEX;
ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr); ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr);
} else { } else {
// IP address was set by the hostname (getaddrinfo). /* IP address was set by the hostname (getaddrinfo). */
// Override port: /* Override port: */
if( out->IPaddress.ss_family == AF_INET ) if( out->IPaddress.ss_family == AF_INET )
sai4->sin_port = htons(port); sai4->sin_port = htons(port);
else else
@ -562,7 +562,7 @@ int remove_dots(char *in, size_t size)
copyTo = Segments[--lastSegment]; copyTo = Segments[--lastSegment];
} else { } else {
free( Segments ); free( Segments );
//TRACE("ERROR RESOLVING URL, ../ at ROOT"); /*TRACE("ERROR RESOLVING URL, ../ at ROOT"); */
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
continue; continue;

View File

@ -135,7 +135,7 @@ subscription *GetSubscriptionSID(const Upnp_SID sid, service_info *service)
} }
} }
if( found ) { if( found ) {
//get the current_time /*get the current_time */
time( &current_time ); time( &current_time );
if( ( found->expireTime != 0 ) if( ( found->expireTime != 0 )
&& ( found->expireTime < current_time ) ) { && ( found->expireTime < current_time ) ) {
@ -161,7 +161,7 @@ subscription *GetNextSubscription(service_info *service, subscription *current)
subscription *previous = NULL; subscription *previous = NULL;
int notDone = 1; int notDone = 1;
// get the current_time /* get the current_time */
time( &current_time ); time( &current_time );
while( ( notDone ) && ( current ) ) { while( ( notDone ) && ( current ) ) {
previous = current; previous = current;
@ -195,7 +195,7 @@ subscription *GetFirstSubscription(service_info *service)
temp.next = service->subscriptionList; temp.next = service->subscriptionList;
next = GetNextSubscription(service, &temp); next = GetNextSubscription(service, &temp);
service->subscriptionList = temp.next; service->subscriptionList = temp.next;
// service->subscriptionList = next; /* service->subscriptionList = next; */
return next; return next;
} }
@ -980,9 +980,9 @@ removeServiceTable( IXML_Node * node,
&& ( ( getSubElement( "UDN", node, &currentUDN ) ) && ( ( getSubElement( "UDN", node, &currentUDN ) )
&& ( UDN = getElementValue( currentUDN ) ) ) ) { && ( UDN = getElementValue( currentUDN ) ) ) ) {
current_service = start_search; current_service = start_search;
//Services are put in the service table in the order in which they appear in the /*Services are put in the service table in the order in which they appear in the */
//description document, therefore we go through the list only once to remove a particular /*description document, therefore we go through the list only once to remove a particular */
//root device /*root device */
while( ( current_service ) while( ( current_service )
&& ( strcmp( current_service->UDN, UDN ) ) ) { && ( strcmp( current_service->UDN, UDN ) ) ) {
current_service = current_service->next; current_service = current_service->next;
@ -1108,4 +1108,5 @@ getServiceTable( IXML_Node * node,
return 0; return 0;
} }
#endif // INCLUDE_DEVICE_APIS #endif /* INCLUDE_DEVICE_APIS */

View File

@ -70,7 +70,7 @@ str_alloc( IN const char *str,
s = ( char * )malloc( str_len + 1 ); s = ( char * )malloc( str_len + 1 );
if( s == NULL ) { if( s == NULL ) {
return NULL; // no mem return NULL; /* no mem */
} }
memcpy( s, str, str_len ); memcpy( s, str, str_len );
@ -111,8 +111,8 @@ memptr_cmp( IN memptr * m,
cmp = strncmp( m->buf, s, m->length ); cmp = strncmp( m->buf, s, m->length );
if( cmp == 0 && m->length < strlen( s ) ) { if( cmp == 0 && m->length < strlen( s ) ) {
// both strings equal for 'm->length' chars /* both strings equal for 'm->length' chars */
// if m is shorter than s, then s is greater /* if m is shorter than s, then s is greater */
return -1; return -1;
} }
@ -147,8 +147,8 @@ memptr_cmp_nocase( IN memptr * m,
cmp = strncasecmp( m->buf, s, m->length ); cmp = strncasecmp( m->buf, s, m->length );
if( cmp == 0 && m->length < strlen( s ) ) { if( cmp == 0 && m->length < strlen( s ) ) {
// both strings equal for 'm->length' chars /* both strings equal for 'm->length' chars */
// if m is shorter than s, then s is greater /* if m is shorter than s, then s is greater */
return -1; return -1;
} }
@ -204,20 +204,20 @@ membuffer_set_size( INOUT membuffer * m,
size_t alloc_len; size_t alloc_len;
char *temp_buf; char *temp_buf;
if( new_length >= m->length ) // increase length if( new_length >= m->length ) /* increase length */
{ {
// need more mem? /* need more mem? */
if( new_length <= m->capacity ) { if( new_length <= m->capacity ) {
return 0; // have enough mem; done return 0; /* have enough mem; done */
} }
diff = new_length - m->length; diff = new_length - m->length;
alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity; alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity;
} else // decrease length } else /* decrease length */
{ {
assert( new_length <= m->length ); assert( new_length <= m->length );
// if diff is 0..m->size_inc, don't free /* if diff is 0..m->size_inc, don't free */
if( ( m->capacity - new_length ) <= m->size_inc ) { if( ( m->capacity - new_length ) <= m->size_inc ) {
return 0; return 0;
} }
@ -227,21 +227,21 @@ membuffer_set_size( INOUT membuffer * m,
assert( alloc_len >= new_length ); assert( alloc_len >= new_length );
temp_buf = realloc( m->buf, alloc_len + 1 ); //LEAK_FIX_MK temp_buf = realloc( m->buf, alloc_len + 1 ); /*LEAK_FIX_MK */
//temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );//LEAK_FIX_MK /*temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );LEAK_FIX_MK */
if( temp_buf == NULL ) { if( temp_buf == NULL ) {
// try smaller size /* try smaller size */
alloc_len = new_length; alloc_len = new_length;
temp_buf = realloc( m->buf, alloc_len + 1 ); //LEAK_FIX_MK temp_buf = realloc( m->buf, alloc_len + 1 ); /*LEAK_FIX_MK */
//temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );//LEAK_FIX_MK /*temp_buf = Realloc( m->buf,m->length, alloc_len + 1 );LEAK_FIX_MK */
if( temp_buf == NULL ) { if( temp_buf == NULL ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
} }
// save /* save */
m->buf = temp_buf; m->buf = temp_buf;
m->capacity = alloc_len; m->capacity = alloc_len;
return 0; return 0;
@ -320,20 +320,20 @@ membuffer_assign( INOUT membuffer * m,
assert( m != NULL ); assert( m != NULL );
// set value to null /* set value to null */
if( buf == NULL ) { if( buf == NULL ) {
membuffer_destroy( m ); membuffer_destroy( m );
return 0; return 0;
} }
// alloc mem /* alloc mem */
return_code = membuffer_set_size( m, buf_len ); return_code = membuffer_set_size( m, buf_len );
if( return_code != 0 ) { if( return_code != 0 ) {
return return_code; return return_code;
} }
// copy /* copy */
if( buf_len ) { if( buf_len ) {
memcpy( m->buf, buf, buf_len ); memcpy( m->buf, buf, buf_len );
m->buf[buf_len] = 0; // null-terminate m->buf[buf_len] = 0; /* null-terminate */
} }
m->length = buf_len; m->length = buf_len;
@ -446,18 +446,18 @@ membuffer_insert( INOUT membuffer * m,
if( buf == NULL || buf_len == 0 ) { if( buf == NULL || buf_len == 0 ) {
return 0; return 0;
} }
// alloc mem /* alloc mem */
return_code = membuffer_set_size( m, m->length + buf_len ); return_code = membuffer_set_size( m, m->length + buf_len );
if( return_code != 0 ) { if( return_code != 0 ) {
return return_code; return return_code;
} }
// insert data /* insert data */
// move data to right of insertion point /* move data to right of insertion point */
memmove( m->buf + index + buf_len, m->buf + index, m->length - index ); memmove( m->buf + index + buf_len, m->buf + index, m->length - index );
memcpy( m->buf + index, buf, buf_len ); memcpy( m->buf + index, buf, buf_len );
m->length += buf_len; m->length += buf_len;
m->buf[m->length] = 0; // null-terminate m->buf[m->length] = 0; /* null-terminate */
return 0; return 0;
} }
@ -499,22 +499,22 @@ membuffer_delete( INOUT membuffer * m,
assert( index >= 0 && index < ( int )m->length ); assert( index >= 0 && index < ( int )m->length );
// shrink count if it goes beyond buffer /* shrink count if it goes beyond buffer */
if( index + num_bytes > m->length ) { if( index + num_bytes > m->length ) {
num_bytes = m->length - ( size_t ) index; num_bytes = m->length - ( size_t ) index;
copy_len = 0; // every thing at and after index purged copy_len = 0; /* every thing at and after index purged */
} else { } else {
// calc num bytes after deleted string /* calc num bytes after deleted string */
copy_len = m->length - ( index + num_bytes ); copy_len = m->length - ( index + num_bytes );
} }
memmove( m->buf + index, m->buf + index + num_bytes, copy_len ); memmove( m->buf + index, m->buf + index + num_bytes, copy_len );
new_length = m->length - num_bytes; new_length = m->length - num_bytes;
return_value = membuffer_set_size( m, new_length ); // trim buffer return_value = membuffer_set_size( m, new_length ); /* trim buffer */
assert( return_value == 0 ); // shrinking should always work assert( return_value == 0 ); /* shrinking should always work */
// don't modify until buffer is set /* don't modify until buffer is set */
m->length = new_length; m->length = new_length;
m->buf[new_length] = 0; m->buf[new_length] = 0;
} }
@ -543,7 +543,7 @@ membuffer_detach( INOUT membuffer * m )
buf = m->buf; buf = m->buf;
// free all /* free all */
membuffer_initialize( m ); membuffer_initialize( m );
return buf; return buf;

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
/************************************************************************ /************************************************************************
* Purpose: This file contains string to integer and integer to string * Purpose: This file contains string to integer and integer to string
@ -82,24 +82,24 @@ map_str_to_int( IN const char *name,
while( top <= bot ) { while( top <= bot ) {
mid = ( top + bot ) / 2; mid = ( top + bot ) / 2;
if( case_sensitive ) { if( case_sensitive ) {
//cmp = strcmp( name, table[mid].name ); /*cmp = strcmp( name, table[mid].name ); */
cmp = memptr_cmp( &name_ptr, table[mid].name ); cmp = memptr_cmp( &name_ptr, table[mid].name );
} else { } else {
//cmp = strcasecmp( name, table[mid].name ); /*cmp = strcasecmp( name, table[mid].name ); */
cmp = memptr_cmp_nocase( &name_ptr, table[mid].name ); cmp = memptr_cmp_nocase( &name_ptr, table[mid].name );
} }
if( cmp > 0 ) { if( cmp > 0 ) {
top = mid + 1; // look below mid top = mid + 1; /* look below mid */
} else if( cmp < 0 ) { } else if( cmp < 0 ) {
bot = mid - 1; // look above mid bot = mid - 1; /* look above mid */
} else // cmp == 0 } else /* cmp == 0 */
{ {
return mid; // match; return table index return mid; /* match; return table index */
} }
} }
return -1; // header name not found return -1; /* header name not found */
} }
/************************************************************************ /************************************************************************

View File

@ -29,86 +29,34 @@
* *
******************************************************************************/ ******************************************************************************/
/************************************************************************ /*!
* \file
*
* Purpose: This file contains functions for copying strings based on * Purpose: This file contains functions for copying strings based on
* different options. * different options.
************************************************************************/ */
#include "config.h" #include "config.h"
#include "upnp.h" #include "upnp.h"
#include "upnputil.h" #include "upnputil.h"
#include <string.h> #include <string.h>
void linecopy(char dest[LINE_SIZE], const char *src)
/************************************************************************
* Function : linecopy
*
* Parameters :
* OUT char dest[LINE_SIZE] ; output buffer
* IN const char* src ; input buffer
*
* Description : Copy no of bytes spcified by the LINE_SIZE constant,
* from the source buffer. Null terminate the destination buffer
*
* Return : void ;
*
* Note :
************************************************************************/
void
linecopy( OUT char dest[LINE_SIZE],
IN const char *src )
{ {
strncpy(dest, src, LINE_SIZE - 1); strncpy(dest, src, LINE_SIZE - 1);
dest[LINE_SIZE - 1] = '\0'; // null-terminate if len(src) >= LINE_SIZE /* null-terminate if len(src) >= LINE_SIZE. */
dest[LINE_SIZE - 1] = '\0';
} }
/************************************************************************ void namecopy(char dest[NAME_SIZE], const char *src)
* Function : namecopy
*
* Parameters :
* OUT char dest[NAME_SIZE] ; output buffer
* IN const char* src ; input buffer
*
* Description : Copy no of bytes spcified by the NAME_SIZE constant,
* from the source buffer. Null terminate the destination buffer
*
* Return : void ;
*
* Note :
************************************************************************/
void
namecopy( OUT char dest[NAME_SIZE],
IN const char *src )
{ {
strncpy(dest, src, NAME_SIZE - 1); strncpy(dest, src, NAME_SIZE - 1);
dest[NAME_SIZE - 1] = '\0'; // null-terminate if len(src) >= NAME_SIZE /* null-terminate if len(src) >= NAME_SIZE. */
dest[NAME_SIZE - 1] = '\0';
} }
/************************************************************************ void linecopylen(char dest[LINE_SIZE], const char *src, size_t srclen)
* Function : linecopylen
*
* Parameters :
* OUT char dest[LINE_SIZE] ; output buffer
* IN const char* src ; input buffer
* IN size_t srclen ; bytes to be copied.
*
* Description : Determine if the srclen passed in paramter is less than
* the permitted LINE_SIZE. If it is use the passed parameter, if not
* use the permitted LINE_SIZE as the length parameter
* Copy no of bytes spcified by the LINE_SIZE constant,
* from the source buffer. Null terminate the destination buffer
*
* Return : void ;
*
* Note :
************************************************************************/
void
linecopylen( OUT char dest[LINE_SIZE],
IN const char *src,
IN size_t srclen )
{ {
int len; int len;
@ -116,3 +64,4 @@ linecopylen( OUT char dest[LINE_SIZE],
strncpy(dest, src, len); strncpy(dest, src, len);
dest[len] = '\0'; dest[len] = '\0';
} }

View File

@ -29,11 +29,9 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef GLOBAL_H #ifndef GLOBAL_H
#define GLOBAL_H #define GLOBAL_H
/* GLOBAL.H - RSAREF types and constants */ /* GLOBAL.H - RSAREF types and constants */
/* PROTOTYPES should be set to one if and only if the compiler supports /* PROTOTYPES should be set to one if and only if the compiler supports
function argument prototyping. function argument prototyping.
@ -42,7 +40,6 @@
been defined with C compiler flags. been defined with C compiler flags.
*/ */
#ifndef PROTOTYPES #ifndef PROTOTYPES
#define PROTOTYPES 1 #define PROTOTYPES 1
#endif #endif

View File

@ -29,49 +29,45 @@
* *
******************************************************************************/ ******************************************************************************/
#ifndef GENLIB_NET_HTTP_HTTPPARSER_H #ifndef GENLIB_NET_HTTP_HTTPPARSER_H
#define GENLIB_NET_HTTP_HTTPPARSER_H #define GENLIB_NET_HTTP_HTTPPARSER_H
/*! /*!
* \file * \file
*/ */
#include "LinkedList.h" #include "LinkedList.h"
#include "membuffer.h" #include "membuffer.h"
#include "uri.h" #include "uri.h"
#include "upnputil.h" #include "upnputil.h"
/* private types */
////// private types //////////// /* scanner */
/* Used to represent different types of tokens in input. */
////////////////////// typedef enum
// scanner
///////////////////////
// Used to represent different types of tokens in input
typedef enum // token_type_t
{ {
TT_IDENTIFIER, TT_IDENTIFIER,
TT_WHITESPACE, TT_WHITESPACE,
TT_CRLF, TT_CRLF,
TT_CTRL, // needed ?? TT_CTRL,
TT_SEPARATOR, // ?? TT_SEPARATOR,
TT_QUOTEDSTRING, // ?? TT_QUOTEDSTRING,
} token_type_t; } token_type_t;
typedef struct // scanner_t typedef struct
{ {
membuffer* msg; // raw http msg /*! raw http msg. */
size_t cursor; // current position in buffer membuffer* msg;
xboolean entire_msg_loaded; // set this to TRUE if the entire msg is loaded in /*! current position in buffer. */
// in 'msg'; else FALSE if only partial msg in 'msg' size_t cursor;
// (default is FALSE) /*! set this to TRUE if the entire msg is loaded in 'msg';
* else FALSE if only partial msg in 'msg' (default is FALSE). */
xboolean entire_msg_loaded;
} scanner_t; } scanner_t;
typedef enum // parser_pos_t typedef enum
{ {
POS_REQUEST_LINE, POS_REQUEST_LINE,
POS_RESPONSE_LINE, POS_RESPONSE_LINE,
@ -80,7 +76,6 @@ typedef enum // parser_pos_t
POS_COMPLETE, POS_COMPLETE,
} parser_pos_t; } parser_pos_t;
#define ENTREAD_DETERMINE_READ_METHOD 1 #define ENTREAD_DETERMINE_READ_METHOD 1
#define ENTREAD_USING_CLEN 2 #define ENTREAD_USING_CLEN 2
#define ENTREAD_USING_CHUNKED 3 #define ENTREAD_USING_CHUNKED 3
@ -88,13 +83,10 @@ typedef enum // parser_pos_t
#define ENTREAD_CHUNKY_BODY 5 #define ENTREAD_CHUNKY_BODY 5
#define ENTREAD_CHUNKY_HEADERS 6 #define ENTREAD_CHUNKY_HEADERS 6
/* end of private section. */
// end of private section /* method in a HTTP request. */
////////////////// typedef enum
// ##################################################################################
// method in a HTTP request
typedef enum // http_method_t
{ {
HTTPMETHOD_POST, HTTPMETHOD_POST,
HTTPMETHOD_MPOST, HTTPMETHOD_MPOST,
@ -105,11 +97,11 @@ typedef enum // http_method_t
HTTPMETHOD_HEAD, HTTPMETHOD_HEAD,
HTTPMETHOD_MSEARCH, HTTPMETHOD_MSEARCH,
HTTPMETHOD_UNKNOWN, HTTPMETHOD_UNKNOWN,
SOAPMETHOD_POST, //murari SOAPMETHOD_POST,
HTTPMETHOD_SIMPLEGET HTTPMETHOD_SIMPLEGET
} http_method_t; } http_method_t;
// different types of HTTP headers /* different types of HTTP headers */
#define HDR_UNKNOWN -1 #define HDR_UNKNOWN -1
#define HDR_CACHE_CONTROL 1 #define HDR_CACHE_CONTROL 1
#define HDR_CALLBACK 2 #define HDR_CALLBACK 2
@ -118,9 +110,9 @@ typedef enum // http_method_t
#define HDR_DATE 5 #define HDR_DATE 5
#define HDR_EXT 6 #define HDR_EXT 6
#define HDR_HOST 7 #define HDR_HOST 7
//#define HDR_IF_MODIFIED_SINCE 8 /*define HDR_IF_MODIFIED_SINCE 8 */
//#define HDR_IF_UNMODIFIED_SINCE 9 /*define HDR_IF_UNMODIFIED_SINCE 9 */
//#define HDR_LAST_MODIFIED 10 /*define HDR_LAST_MODIFIED 10 */
#define HDR_LOCATION 11 #define HDR_LOCATION 11
#define HDR_MAN 12 #define HDR_MAN 12
#define HDR_MX 13 #define HDR_MX 13
@ -136,7 +128,7 @@ typedef enum // http_method_t
#define HDR_USN 23 #define HDR_USN 23
#define HDR_USER_AGENT 24 #define HDR_USER_AGENT 24
//Adding new header difinition//Beg_Murari /* Adding new header difinition */
#define HDR_ACCEPT 25 #define HDR_ACCEPT 25
#define HDR_ACCEPT_ENCODING 26 #define HDR_ACCEPT_ENCODING 26
#define HDR_ACCEPT_CHARSET 27 #define HDR_ACCEPT_CHARSET 27
@ -149,72 +141,77 @@ typedef enum // http_method_t
#define HDR_IF_RANGE 34 #define HDR_IF_RANGE 34
#define HDR_RANGE 35 #define HDR_RANGE 35
#define HDR_TE 36 #define HDR_TE 36
//End_Murari
// status of parsing /*! status of parsing */
typedef enum // parse_status_t typedef enum {
{ /*! msg was parsed successfully. */
PARSE_SUCCESS = 0, // msg was parsed successfully PARSE_SUCCESS = 0,
PARSE_INCOMPLETE, // need more data to continue /*! need more data to continue. */
PARSE_INCOMPLETE_ENTITY, // for responses that don't have length specified PARSE_INCOMPLETE,
PARSE_FAILURE, // parse failed; check status code for details /*! for responses that don't have length specified. */
PARSE_OK, // done partial PARSE_INCOMPLETE_ENTITY,
PARSE_NO_MATCH, // token not matched /*! parse failed; check status code for details. */
PARSE_FAILURE,
// private /*! done partial. */
PARSE_OK,
/*! token not matched. */
PARSE_NO_MATCH,
/*! private. */
PARSE_CONTINUE_1 PARSE_CONTINUE_1
} parse_status_t; } parse_status_t;
typedef struct // http_header_t typedef struct {
{ /*! header name as a string. */
memptr name; // header name as a string memptr name;
int name_id; // header name id (for a selective group of headers only) /*! header name id (for a selective group of headers only). */
membuffer value; // raw-value; could be multi-lined; min-length = 0 int name_id;
/*! raw-value; could be multi-lined; min-length = 0. */
// private membuffer value;
/* private. */
membuffer name_buf; membuffer name_buf;
} http_header_t; } http_header_t;
typedef struct // http_message_t typedef struct {
{
int initialized; int initialized;
// request only /*! request only. */
http_method_t method; http_method_t method;
/*! request only. */
uri_type uri; uri_type uri;
/*! response only. */
// response only
http_method_t request_method; http_method_t request_method;
/*! response only. */
int status_code; int status_code;
/*! response only. */
membuffer status_msg; membuffer status_msg;
/* fields used in both request or response messages. */
// fields used in both request or response messages /*! if TRUE, msg is a request, else response. */
xboolean is_request; // if TRUE, msg is a request, else response xboolean is_request;
/* http major version. */
int major_version; // http major.minor version int major_version;
/* http minor version. */
int minor_version; int minor_version;
/*! . */
LinkedList headers; LinkedList headers;
//NNS: dlist headers; // dlist<http_header_t *> /*! message body(entity). */
memptr entity; // message body(entity) memptr entity;
/* private fields. */
// private fields /*! entire raw message. */
membuffer msg; // entire raw message membuffer msg;
char *urlbuf; // storage for url string /*! storage for url string. */
char *urlbuf;
/*! . */
size_t entity_offset; size_t entity_offset;
} http_message_t; } http_message_t;
typedef struct // http_parser_t typedef struct {
{
http_message_t msg; http_message_t msg;
int http_error_code; // read-only; in case of parse error, this /*! read-only; in case of parse error, this
// contains the HTTP error code (4XX or 5XX) * contains the HTTP error code (4XX or 5XX). */
int http_error_code;
// read-only; this is set to true if a NOTIFY request has no content-length. /*! read-only; this is set to true if a NOTIFY request has no
// used to read valid sspd notify msg. * content-length. used to read valid sspd notify msg. */
xboolean valid_ssdp_notify_hack; xboolean valid_ssdp_notify_hack;
/* private data -- don't touch. */
// private data -- don't touch
parser_pos_t position; parser_pos_t position;
int ent_position; int ent_position;
unsigned int content_length; unsigned int content_length;
@ -223,15 +220,9 @@ typedef struct // http_parser_t
scanner_t scanner; scanner_t scanner;
} http_parser_t; } http_parser_t;
//--------------------------------------------------
//////////////// functions /////////////////////////
//--------------------------------------------------
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif // __cplusplus #endif /* __cplusplus */
/************************************************************************ /************************************************************************
* Function : httpmsg_init * Function : httpmsg_init
@ -273,7 +264,6 @@ void httpmsg_destroy( INOUT http_message_t* msg );
* *
* Return : http_header_t* - Pointer to a header on success; * Return : http_header_t* - Pointer to a header on success;
* NULL on failure * NULL on failure
*
* Note : * Note :
************************************************************************/ ************************************************************************/
http_header_t* httpmsg_find_hdr_str( IN http_message_t* msg, http_header_t* httpmsg_find_hdr_str( IN http_message_t* msg,
@ -289,7 +279,7 @@ http_header_t* httpmsg_find_hdr_str( IN http_message_t* msg,
* *
* Description : Finds header from a list, with the given 'name_id'. * Description : Finds header from a list, with the given 'name_id'.
* *
* Return : http_header_t* - Pointer to a header on success; * * Return : http_header_t* - Pointer to a header on success;
* NULL on failure * NULL on failure
* *
* Note : * Note :
@ -437,10 +427,6 @@ parse_status_t parser_append( INOUT http_parser_t* parser,
************************************************************************/ ************************************************************************/
int matchstr( IN char *str, IN size_t slen, IN const char* fmt, ... ); int matchstr( IN char *str, IN size_t slen, IN const char* fmt, ... );
// ====================================================
// misc functions
/************************************************************************ /************************************************************************
* Function: raw_to_int * Function: raw_to_int
* *
@ -481,11 +467,10 @@ int raw_find_str( IN memptr* raw_value, IN const char* str );
* nameConverts a http_method id stored in the HTTP Method * nameConverts a http_method id stored in the HTTP Method
* *
* Returns: * Returns:
* const char* ptr - Ptr to the HTTP Method * * const char* ptr - Ptr to the HTTP Method
************************************************************************/ ************************************************************************/
const char* method_to_str( IN http_method_t method ); const char* method_to_str( IN http_method_t method );
/*! /*!
* \brief Print the HTTP headers. * \brief Print the HTTP headers.
*/ */
@ -494,13 +479,16 @@ void print_http_headers(
/*! [in] HTTP Message object. */ /*! [in] HTTP Message object. */
http_message_t *hmsg); http_message_t *hmsg);
#else #else
static UPNP_INLINE void print_http_headers(http_message_t *hmsg) {} static UPNP_INLINE void print_http_headers(http_message_t *hmsg)
{
return;
hmsg = hmsg;
}
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* GENLIB_NET_HTTP_HTTPPARSER_H */ #endif /* GENLIB_NET_HTTP_HTTPPARSER_H */

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H #ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H
#define GENLIB_NET_HTTP_HTTPREADWRITE_H #define GENLIB_NET_HTTP_HTTPREADWRITE_H
@ -37,17 +37,14 @@
#include "sock.h" #include "sock.h"
#include "httpparser.h" #include "httpparser.h"
// timeout in secs /*! timeout in secs. */
#define HTTP_DEFAULT_TIMEOUT 30 #define HTTP_DEFAULT_TIMEOUT 30
#ifdef __cplusplus #ifdef __cplusplus
#extern "C" { #extern "C" {
#endif #endif
int int http_CancelHttpGet(IN void *Handle);
http_CancelHttpGet( IN void *Handle );
/************************************************************************ /************************************************************************
* Function: http_FixUrl * Function: http_FixUrl
@ -65,7 +62,6 @@ http_CancelHttpGet( IN void *Handle );
************************************************************************/ ************************************************************************/
int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url ); int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
/************************************************************************ /************************************************************************
* Function: http_FixStrUrl * Function: http_FixStrUrl
* *
@ -597,9 +593,9 @@ int http_OpenHttpGetEx(IN const char *url_str,
void get_sdk_info( OUT char *info ); void get_sdk_info( OUT char *info );
#ifdef __cplusplus #ifdef __cplusplus
} // #extern "C" } /* #extern "C" */
#endif #endif
#endif // GENLIB_NET_HTTP_HTTPREADWRITE_H #endif /* GENLIB_NET_HTTP_HTTPREADWRITE_H */

View File

@ -1,72 +1,72 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENLIB_UTIL_MEMBUFFER_H #ifndef GENLIB_UTIL_MEMBUFFER_H
#define GENLIB_UTIL_MEMBUFFER_H #define GENLIB_UTIL_MEMBUFFER_H
#include <stdlib.h> #include <stdlib.h>
#include "upnputil.h" #include "upnputil.h"
#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) ) #define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) )
#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) ) #define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) )
// pointer to a chunk of memory /*! pointer to a chunk of memory. */
typedef struct // memptr typedef struct
{ {
char *buf; // start of memory (read/write) /*! start of memory (read/write). */
size_t length; // length of memory (read-only) char *buf;
/*! length of memory (read-only). */
size_t length;
} memptr; } memptr;
// maintains a block of dynamically allocated memory /*! Maintains a block of dynamically allocated memory
// note: Total length/capacity should not exceed MAX_INT * note: Total length/capacity should not exceed MAX_INT */
typedef struct // membuffer typedef struct
{ {
char *buf; // mem buffer; must not write beyond buf[length-1] (read/write) /*! mem buffer; must not write beyond buf[length-1] (read/write). */
size_t length; // length of buffer (read-only) char *buf;
size_t capacity; // total allocated memory (read-only) /*! length of buffer (read-only). */
size_t size_inc; // used to increase size; MUST be > 0; (read/write) size_t length;
/*! total allocated memory (read-only). */
// default value of size_inc size_t capacity;
/*! used to increase size; MUST be > 0; (read/write). */
size_t size_inc;
/*! default value of size_inc. */
#define MEMBUF_DEF_SIZE_INC 5 #define MEMBUF_DEF_SIZE_INC 5
} membuffer; } membuffer;
//--------------------------------------------------
//////////////// functions /////////////////////////
//--------------------------------------------------
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif // __cplusplus #endif /* __cplusplus */
/************************************************************************ /************************************************************************
* Function : str_alloc * Function : str_alloc
@ -332,7 +332,8 @@ char* membuffer_detach( INOUT membuffer* m );
************************************************************************/ ************************************************************************/
void membuffer_attach( INOUT membuffer* m, IN char* new_buf, IN size_t buf_len ); void membuffer_attach( INOUT membuffer* m, IN char* new_buf, IN size_t buf_len );
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } /* extern "C" */
#endif // __cplusplus #endif /* __cplusplus */
#endif /* GENLIB_UTIL_H */
#endif // GENLIB_UTIL_H

View File

@ -1,63 +1,61 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENLIB_NET_HTTP_PARSETOOLS_H #ifndef GENLIB_NET_HTTP_PARSETOOLS_H
#define GENLIB_NET_HTTP_PARSETOOLS_H #define GENLIB_NET_HTTP_PARSETOOLS_H
/*!
* \file
*/
#include "upnputil.h" #include "upnputil.h"
#include "httpparser.h" #include "httpparser.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*!
/************************************************************************ * \brief Find the header from the HTTP message and match the header for
* Function: has_xml_content_type * xml data.
* *
* Parameters: * \return boolean.
* IN http_message_t* hmsg ; HTTP Message object */
* xboolean has_xml_content_type(
* Description: Find the header from the HTTP message and match the /*! HTTP Message object. */
* header for xml data. IN http_message_t *hmsg);
*
* Returns:
* BOOLEAN
************************************************************************/
xboolean has_xml_content_type( IN http_message_t* hmsg );
#ifdef __cplusplus #ifdef __cplusplus
} // extern C } /* extern C */
#endif #endif
#endif /* GENLIB_NET_HTTP_PARSETOOLS_H */
#endif // GENLIB_NET_HTTP_PARSETOOLS_H

View File

@ -29,38 +29,30 @@
* *
******************************************************************************/ ******************************************************************************/
#ifndef SERVICE_TABLE_H #ifndef SERVICE_TABLE_H
#define SERVICE_TABLE_H #define SERVICE_TABLE_H
/*! /*!
* \file * \file
*/ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "config.h" #include "config.h"
#include "uri.h" #include "uri.h"
#include "ixml.h" #include "ixml.h"
#include "upnp.h" #include "upnp.h"
#include "upnpdebug.h" #include "upnpdebug.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#define SID_SIZE 41 #define SID_SIZE 41
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
typedef struct SUBSCRIPTION { typedef struct SUBSCRIPTION {
Upnp_SID sid; Upnp_SID sid;
int eventKey; int eventKey;
@ -71,7 +63,6 @@ typedef struct SUBSCRIPTION {
struct SUBSCRIPTION *next; struct SUBSCRIPTION *next;
} subscription; } subscription;
typedef struct SERVICE_INFO { typedef struct SERVICE_INFO {
DOMString serviceType; DOMString serviceType;
DOMString serviceId; DOMString serviceId;
@ -85,17 +76,14 @@ typedef struct SERVICE_INFO {
struct SERVICE_INFO *next; struct SERVICE_INFO *next;
} service_info; } service_info;
typedef struct SERVICE_TABLE { typedef struct SERVICE_TABLE {
DOMString URLBase; DOMString URLBase;
service_info *serviceList; service_info *serviceList;
service_info *endServiceList; service_info *endServiceList;
} service_table; } service_table;
/* Functions for Subscriptions */ /* Functions for Subscriptions */
/*! /*!
* \brief Makes a copy of the subscription. * \brief Makes a copy of the subscription.
* *
@ -107,7 +95,6 @@ int copy_subscription(
/*! [in] Destination subscription. */ /*! [in] Destination subscription. */
subscription *out); subscription *out);
/* /*
* \brief Remove the subscription represented by the const Upnp_SID sid parameter * \brief Remove the subscription represented by the const Upnp_SID sid parameter
* from the service table and update the service table. * from the service table and update the service table.
@ -118,7 +105,6 @@ void RemoveSubscriptionSID(
/*! [in] Service object providing the list of subscriptions. */ /*! [in] Service object providing the list of subscriptions. */
service_info *service); service_info *service);
/*! /*!
* \brief Return the subscription from the service table that matches * \brief Return the subscription from the service table that matches
* const Upnp_SID sid value. * const Upnp_SID sid value.
@ -131,7 +117,6 @@ subscription *GetSubscriptionSID(
/*! [in] Service object providing the list of subscriptions. */ /*! [in] Service object providing the list of subscriptions. */
service_info *service); service_info *service);
/*! /*!
* \brief Gets pointer to the first subscription node in the service table. * \brief Gets pointer to the first subscription node in the service table.
* *
@ -141,7 +126,6 @@ subscription *GetFirstSubscription(
/*! [in] Service object providing the list of subscriptions. */ /*! [in] Service object providing the list of subscriptions. */
service_info *service); service_info *service);
/*! /*!
* \brief Get current and valid subscription from the service table. * \brief Get current and valid subscription from the service table.
* *
@ -153,7 +137,6 @@ subscription *GetNextSubscription(
/*! [in] Current subscription object. */ /*! [in] Current subscription object. */
subscription *current); subscription *current);
/*! /*!
* \brief Free's the memory allocated for storing the URL of the subscription. * \brief Free's the memory allocated for storing the URL of the subscription.
*/ */
@ -161,7 +144,6 @@ void freeSubscription(
/*! [in] Subscription object to be freed. */ /*! [in] Subscription object to be freed. */
subscription *sub); subscription *sub);
/*! /*!
* \brief Free's memory allocated for all the subscriptions in the service table. * \brief Free's memory allocated for all the subscriptions in the service table.
*/ */
@ -169,7 +151,6 @@ void freeSubscriptionList(
/*! [in] Head of the subscription list. */ /*! [in] Head of the subscription list. */
subscription * head); subscription * head);
/*! /*!
* \brief Traverses through the service table and returns a pointer to the * \brief Traverses through the service table and returns a pointer to the
* service node that matches a known service id and a known UDN. * service node that matches a known service id and a known UDN.
@ -186,7 +167,6 @@ service_info *FindServiceId(
* table. */ * table. */
const char *UDN); const char *UDN);
/*! /*!
* \brief Traverses the service table and finds the node whose event URL Path * \brief Traverses the service table and finds the node whose event URL Path
* matches a know value. * matches a know value.
@ -200,7 +180,6 @@ service_info *FindServiceEventURLPath(
/*! [in] Event URL path used to find a service from the table. */ /*! [in] Event URL path used to find a service from the table. */
char *eventURLPath); char *eventURLPath);
/*! /*!
* \brief Traverses the service table and finds the node whose control URL Path * \brief Traverses the service table and finds the node whose control URL Path
* matches a know value. * matches a know value.
@ -214,7 +193,6 @@ service_info * FindServiceControlURLPath(
/*! [in] Control URL path used to find a service from the table. */ /*! [in] Control URL path used to find a service from the table. */
const char *controlURLPath); const char *controlURLPath);
/*! /*!
* \brief For debugging purposes prints information from the service passed * \brief For debugging purposes prints information from the service passed
* into the function. * into the function.
@ -231,10 +209,15 @@ void printService(
static UPNP_INLINE void printService( static UPNP_INLINE void printService(
service_info *service, service_info *service,
Upnp_LogLevel level, Upnp_LogLevel level,
Dbg_Module module) {} Dbg_Module module)
{
return;
service = service;
level = level;
module = module;
}
#endif #endif
/*! /*!
* \brief For debugging purposes prints information of each service from the * \brief For debugging purposes prints information of each service from the
* service table passed into the function. * service table passed into the function.
@ -251,10 +234,15 @@ void printServiceList(
static UPNP_INLINE void printServiceList( static UPNP_INLINE void printServiceList(
service_info *service, service_info *service,
Upnp_LogLevel level, Upnp_LogLevel level,
Dbg_Module module) {} Dbg_Module module)
{
return;
service = service;
level = level;
module = module;
}
#endif #endif
/*! /*!
* \brief For debugging purposes prints the URL base of the table and information * \brief For debugging purposes prints the URL base of the table and information
* of each service from the service table passed into the function. * of each service from the service table passed into the function.
@ -271,10 +259,15 @@ void printServiceTable(
static UPNP_INLINE void printServiceTable( static UPNP_INLINE void printServiceTable(
service_table *table, service_table *table,
Upnp_LogLevel level, Upnp_LogLevel level,
Dbg_Module module) {} Dbg_Module module)
{
return;
table = table;
level = level;
module = module;
}
#endif #endif
/*! /*!
* \brief Free's memory allocated for the various components of the service * \brief Free's memory allocated for the various components of the service
* entry in the service table. * entry in the service table.
@ -283,7 +276,6 @@ void freeService(
/*! [in] Service information that is to be freed. */ /*! [in] Service information that is to be freed. */
service_info *in); service_info *in);
/*! /*!
* \brief Free's memory allocated for the various components of each service * \brief Free's memory allocated for the various components of each service
* entry in the service table. * entry in the service table.
@ -292,7 +284,6 @@ void freeServiceList(
/*! [in] Head of the service list to be freed. */ /*! [in] Head of the service list to be freed. */
service_info *head); service_info *head);
/*! /*!
* \brief Free's dynamic memory in table (does not free table, only memory * \brief Free's dynamic memory in table (does not free table, only memory
* within the structure). * within the structure).
@ -301,7 +292,6 @@ void freeServiceTable(
/*! [in] Service table whose internal memory needs to be freed. */ /*! [in] Service table whose internal memory needs to be freed. */
service_table *table); service_table *table);
/*! /*!
* \brief This function assumes that services for a particular root device are * \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 * placed linearly in the service table, and in the order in which they are
@ -316,7 +306,6 @@ int removeServiceTable(
/*! [in] Service table from which services will be removed. */ /*! [in] Service table from which services will be removed. */
service_table *in); service_table *in);
/*! /*!
* \brief Add Service to the table. * \brief Add Service to the table.
*/ */
@ -329,7 +318,6 @@ int addServiceTable(
* service list. */ * service list. */
const char *DefaultURLBase); const char *DefaultURLBase);
/*! /*!
* \brief Retrieve service from the table. * \brief Retrieve service from the table.
* *
@ -343,10 +331,8 @@ int getServiceTable(
/*! [in] Default base URL on which the URL will be returned. */ /*! [in] Default base URL on which the URL will be returned. */
const char *DefaultURLBase); const char *DefaultURLBase);
/* Misc helper functions */ /* Misc helper functions */
/*! /*!
* \brief Returns the clone of the element value. * \brief Returns the clone of the element value.
* *
@ -358,7 +344,6 @@ DOMString getElementValue(
/*! [in] Input node which provides the list of child nodes. */ /*! [in] Input node which provides the list of child nodes. */
IXML_Node *node); IXML_Node *node);
/*! /*!
* \brief Traverses through a list of XML nodes to find the node with the * \brief Traverses through a list of XML nodes to find the node with the
* known element name. * known element name.
@ -375,7 +360,6 @@ int getSubElement(
/*! [out] Ouput node to which the matched child node is returned. */ /*! [out] Ouput node to which the matched child node is returned. */
IXML_Node **out); IXML_Node **out);
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -29,7 +29,6 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef SSDPLIB_H #ifndef SSDPLIB_H
#define SSDPLIB_H #define SSDPLIB_H
@ -113,11 +112,8 @@ typedef enum SsdpCmdType{
#define E_SOCKET -7 #define E_SOCKET -7
#define RQST_TIMEOUT 20 #define RQST_TIMEOUT 20
/*! Structure to store the SSDP information */
typedef struct SsdpEventStruct {
/* Structure to store the SSDP information */
typedef struct SsdpEventStruct
{
enum SsdpCmdType Cmd; enum SsdpCmdType Cmd;
enum SsdpSearchType RequestType; enum SsdpSearchType RequestType;
int ErrCode; int ErrCode;
@ -125,7 +121,8 @@ typedef struct SsdpEventStruct
int Mx; int Mx;
char UDN[LINE_SIZE]; char UDN[LINE_SIZE];
char DeviceType[LINE_SIZE]; char DeviceType[LINE_SIZE];
char ServiceType[LINE_SIZE]; //NT or ST /* NT or ST */
char ServiceType[LINE_SIZE];
char Location[LINE_SIZE]; char Location[LINE_SIZE];
char HostAddr[LINE_SIZE]; char HostAddr[LINE_SIZE];
char Os[LINE_SIZE]; char Os[LINE_SIZE];
@ -139,7 +136,7 @@ typedef void (* SsdpFunPtr)(Event *);
typedef Event SsdpEvent ; typedef Event SsdpEvent ;
// Structure to contain Discovery response /*! Structure to contain Discovery response. */
typedef struct resultData typedef struct resultData
{ {
struct Upnp_Discovery param; struct Upnp_Discovery param;

View File

@ -1,38 +1,38 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENLIB_NET_HTTP_STATCODES_H #ifndef GENLIB_NET_HTTP_STATCODES_H
#define GENLIB_NET_HTTP_STATCODES_H #define GENLIB_NET_HTTP_STATCODES_H
// HTTP response status codes /* HTTP response status codes */
#define HTTP_CONTINUE 100 #define HTTP_CONTINUE 100
#define HTTP_SWITCHING_PROCOTOLS 101 #define HTTP_SWITCHING_PROCOTOLS 101
@ -80,15 +80,13 @@
#define HTTP_GATEWAY_TIMEOUT 504 #define HTTP_GATEWAY_TIMEOUT 504
#define HTTP_HTTP_VERSION_NOT_SUPPORTED 505 #define HTTP_HTTP_VERSION_NOT_SUPPORTED 505
// *********** HTTP lib error codes ********** /* HTTP lib error codes */
#define HTTP_E_OUT_OF_MEMORY -2 #define HTTP_E_OUT_OF_MEMORY -2
#define HTTP_E_BAD_MSG_FORMAT -3 #define HTTP_E_BAD_MSG_FORMAT -3
#define HTTP_E_TIMEDOUT -4 #define HTTP_E_TIMEDOUT -4
#define HTTP_E_FILE_READ -5 #define HTTP_E_FILE_READ -5
// *******************************************
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -109,7 +107,8 @@ extern "C" {
const char* http_get_code_text( int statusCode ); const char* http_get_code_text( int statusCode );
#ifdef __cplusplus #ifdef __cplusplus
} // extern C } /* extern C */
#endif #endif
#endif /* GENLIB_NET_HTTP_STATCODES_H */ #endif /* GENLIB_NET_HTTP_STATCODES_H */

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef GENLIB_UTIL_STRINTMAP_H #ifndef GENLIB_UTIL_STRINTMAP_H
#define GENLIB_UTIL_STRINTMAP_H #define GENLIB_UTIL_STRINTMAP_H
@ -35,12 +35,12 @@
#include <stdlib.h> #include <stdlib.h>
#include "upnputil.h" #include "upnputil.h"
// Util to map from a string to an integer and vice versa /* Util to map from a string to an integer and vice versa */
typedef struct // str_int_entry typedef struct /* str_int_entry */
{ {
char *name; // a value in string form char *name; /* a value in string form */
int id; // same value in integer form int id; /* same value in integer form */
} str_int_entry; } str_int_entry;
#ifdef __cplusplus #ifdef __cplusplus
@ -95,8 +95,9 @@ int map_int_to_str( IN int id, IN str_int_entry* table,
IN int num_entries ); IN int num_entries );
#ifdef __cplusplus #ifdef __cplusplus
} // extern C } /* extern C */
#endif #endif
#endif // GENLIB_UTIL_STRINTMAP_H #endif /* GENLIB_UTIL_STRINTMAP_H */

View File

@ -1,42 +1,44 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#ifndef UTIL_H #ifndef UTIL_H
#define UTIL_H #define UTIL_H
/*!
* \file
*/
#include "upnp.h" #include "upnp.h"
/* usually used to specify direction of parameters in functions */
// usually used to specify direction of parameters in functions
#ifndef IN #ifndef IN
#define IN #define IN
#endif #endif
@ -55,7 +57,7 @@
#define EVENT_TERMINATE -3 #define EVENT_TERMINATE -3
// boolean type in C /*! boolean type in C. */
typedef char xboolean; typedef char xboolean;
#ifndef TRUE #ifndef TRUE
@ -66,108 +68,73 @@ typedef char xboolean;
#define FALSE 0 #define FALSE 0
#endif #endif
///////////////////////////
// funcs
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/************************************************************************ /*!
* Function: logerror * \brief Copy no of bytes spcified by the LINE_SIZE constant, from the
* * source buffer. Null terminate the destination buffer.
* Parameters: */
* IN const char *fmt; format string void linecopy(
* /*! [out] output buffer. */
* Description: Log an error message. char dest[LINE_SIZE],
* /*! [in] input buffer. */
* Return: void const char *src);
************************************************************************/
void log_error( IN const char *fmt, ... );
/************************************************************************ /*!
* Function: linecopy * \brief Copy no of bytes spcified by the NAME_SIZE constant, from the
* * source buffer. Null terminate the destination buffer
* Parameters: */
* OUT char dest[LINE_SIZE]; output buffer void namecopy(
* IN const char *src; input buffer /*! [out] output buffer. */
* char dest[NAME_SIZE],
* Description: Copy no of bytes spcified by the LINE_SIZE constant, /*! [in] input buffer. */
* from the source buffer. Null terminate the destination buffer. const char *src);
*
* Return: void
************************************************************************/
void linecopy( OUT char dest[LINE_SIZE], IN const char* src );
/************************************************************************ /*!
* Function: namecopy * \brief Determine if the srclen passed in paramter is less than the
* permitted LINE_SIZE. If it is use the passed parameter, if not
* use the permitted LINE_SIZE as the length parameter.
* *
* Parameters: * Copy no of bytes spcified by the LINE_SIZE constant, from the source
* OUT char dest[NAME_SIZE]; output buffer * buffer. Null terminate the destination buffer.
* IN const char *src; input buffer */
* void linecopylen(
* Description: Copy no of bytes spcified by the NAME_SIZE constant, /*! [out] output buffer. */
* from the source buffer. Null terminate the destination buffer char dest[LINE_SIZE],
* /*! [in] input buffer. */
* Return: void const char *src,
************************************************************************/ /*! [in] bytes to be copied. */
void namecopy( OUT char dest[NAME_SIZE], IN const char* src ); size_t srclen);
/************************************************************************
* Function: linecopylen
*
* Parameters:
* OUT char dest[LINE_SIZE]; output buffer
* IN const char *src; input buffer
* IN size_t srclen; bytes to be copied.
*
* Description : Determine if the srclen passed in paramter is less than
* the permitted LINE_SIZE. If it is use the passed parameter, if not
* use the permitted LINE_SIZE as the length parameter
* Copy no of bytes spcified by the LINE_SIZE constant,
* from the source buffer. Null terminate the destination buffer
*
* Return: void
************************************************************************/
void linecopylen( OUT char dest[LINE_SIZE], IN const char* src, IN size_t srclen );
#ifdef __cplusplus #ifdef __cplusplus
} // extern C }
#endif #endif
/* Size of the errorBuffer variable, passed to the strerror_r() function */ /* Size of the errorBuffer variable, passed to the strerror_r() function */
#define ERROR_BUFFER_LEN 256 #define ERROR_BUFFER_LEN 256
////////////////////////////////// /* C specific */
// C specific
#ifndef __cplusplus #ifndef __cplusplus
#ifdef WIN32 #ifdef WIN32
#ifndef S_ISREG #ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif #endif
#ifndef S_ISDIR #ifndef S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif #endif
#define EADDRINUSE WSAEADDRINUSE #define EADDRINUSE WSAEADDRINUSE
#define strcasecmp stricmp #define strcasecmp stricmp
#define strncasecmp strnicmp #define strncasecmp strnicmp
#define sleep(a) Sleep((a)*1000) #define sleep(a) Sleep((a)*1000)
#define usleep(a) Sleep((a)/1000) #define usleep(a) Sleep((a)/1000)
#define strerror_r(a,b,c) (strerror_s((b),(c),(a))) #define strerror_r(a,b,c) (strerror_s((b),(c),(a)))
#else #else
#define max(a, b) (((a)>(b))? (a):(b)) #define max(a, b) (((a)>(b))? (a):(b))
#define min(a, b) (((a)<(b))? (a):(b)) #define min(a, b) (((a)<(b))? (a):(b))
#endif /* WIN32 */ #endif /* WIN32 */
#endif /* __cplusplus */
#endif // __cplusplus
#endif /* UTIL_H */ #endif /* UTIL_H */

View File

@ -29,11 +29,9 @@
* *
******************************************************************************/ ******************************************************************************/
#ifndef GENLIB_NET_URI_H #ifndef GENLIB_NET_URI_H
#define GENLIB_NET_URI_H #define GENLIB_NET_URI_H
/*! /*!
* \file * \file
*/ */
@ -42,11 +40,9 @@
#include <sys/param.h> #include <sys/param.h>
#endif #endif
#include "UpnpGlobal.h" /* for */ #include "UpnpGlobal.h" /* for */
#include "UpnpInet.h" #include "UpnpInet.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -58,7 +54,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
#include "inet_pton.h" #include "inet_pton.h"
#else #else
@ -66,49 +61,45 @@
#include <netdb.h> /* for struct addrinfo */ #include <netdb.h> /* for struct addrinfo */
#endif #endif
#ifdef WIN32 #ifdef WIN32
#define strncasecmp strnicmp #define strncasecmp strnicmp
#else #else
/* Other systems have strncasecmp */ /* Other systems have strncasecmp */
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*! length for HTTP DATE: "DATE: Sun, 01 Jul 2000 08:15:23 GMT<cr><lf>" */
#define HTTP_DATE_LENGTH 37
#define HTTP_DATE_LENGTH 37 // length for HTTP DATE:
//"DATE: Sun, 01 Jul 2000 08:15:23 GMT<cr><lf>"
#define SEPARATORS "()<>@,;:\\\"/[]?={} \t" #define SEPARATORS "()<>@,;:\\\"/[]?={} \t"
#define MARK "-_.!~*'()" #define MARK "-_.!~*'()"
#define RESERVED ";/?:@&=+$,{}" //added {} for compatibility
/*! added {} for compatibility */
#define RESERVED ";/?:@&=+$,{}"
#define HTTP_SUCCESS 1 #define HTTP_SUCCESS 1
#define FALSE 0 #define FALSE 0
#define TAB 9 #define TAB 9
#define CR 13 #define CR 13
#define LF 10 #define LF 10
#define SOCKET_BUFFER_SIZE 5000 #define SOCKET_BUFFER_SIZE 5000
enum hostType { enum hostType {
HOSTNAME, HOSTNAME,
IPv4address IPv4address
}; };
enum pathType { enum pathType {
ABS_PATH, ABS_PATH,
REL_PATH, REL_PATH,
OPAQUE_PART OPAQUE_PART
}; };
#ifdef WIN32 #ifdef WIN32
/* there is a conflict in windows with other symbols */ /* there is a conflict in windows with other symbols. */
enum uriType { enum uriType {
absolute, absolute,
relative relative
@ -120,7 +111,6 @@ enum pathType {
}; };
#endif #endif
/*! /*!
* \brief Buffer used in parsinghttp messages, urls, etc. generally this simply * \brief Buffer used in parsinghttp messages, urls, etc. generally this simply
* holds a pointer into a larger array. * holds a pointer into a larger array.
@ -130,7 +120,6 @@ typedef struct TOKEN {
size_t size; size_t size;
} token; } token;
/*! /*!
* \brief Represents a host port: e.g. "127.127.0.1:80" text is a token * \brief Represents a host port: e.g. "127.127.0.1:80" text is a token
* pointing to the full string representation. * pointing to the full string representation.
@ -142,7 +131,6 @@ typedef struct HOSTPORT {
struct sockaddr_storage IPaddress; struct sockaddr_storage IPaddress;
} hostport_type; } hostport_type;
/*! /*!
* \brief Represents a URI used in parse_uri and elsewhere * \brief Represents a URI used in parse_uri and elsewhere
*/ */
@ -155,7 +143,6 @@ typedef struct URI{
hostport_type hostport; hostport_type hostport;
} uri_type; } uri_type;
/*! /*!
* \brief Represents a list of URLs as in the "callback" header of SUBSCRIBE * \brief Represents a list of URLs as in the "callback" header of SUBSCRIBE
* message in GENA. "char *" URLs holds dynamic memory. * message in GENA. "char *" URLs holds dynamic memory.
@ -169,7 +156,6 @@ typedef struct URL_LIST {
uri_type *parsedURLs; uri_type *parsedURLs;
} URL_list; } URL_list;
/*! /*!
* \brief Replaces an escaped sequence with its unescaped version as in * \brief Replaces an escaped sequence with its unescaped version as in
* http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs) * http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)
@ -190,7 +176,6 @@ int replace_escaped(
/*! [out] . */ /*! [out] . */
size_t *max); size_t *max);
/*! /*!
* \brief Copies one URL_list into another. * \brief Copies one URL_list into another.
* *
@ -218,7 +203,6 @@ void free_URL_list(
/*! [in] URL list object. */ /*! [in] URL list object. */
URL_list *list); URL_list *list);
/*! /*!
* \brief Function useful in debugging for printing a parsed uri. * \brief Function useful in debugging for printing a parsed uri.
*/ */
@ -227,10 +211,13 @@ void print_uri(
/*! [in] URI object to print. */ /*! [in] URI object to print. */
uri_type *in); uri_type *in);
#else #else
static UPNP_INLINE void print_uri(uri_type *in) {} static UPNP_INLINE void print_uri(uri_type *in)
{
return;
in = in;
}
#endif #endif
/*! /*!
* \brief Function useful in debugging for printing a token. * \brief Function useful in debugging for printing a token.
*/ */
@ -239,10 +226,15 @@ void print_token(
/*! [in] Token object to print. */ /*! [in] Token object to print. */
token *in); token *in);
#else #else
static UPNP_INLINE void print_token(token * in) {} static UPNP_INLINE void print_token(
/*! [in] Token object to print. */
token *in)
{
return;
in = in;
}
#endif #endif
/*! /*!
* \brief Compares buffer in the token object with the buffer in in2. * \brief Compares buffer in the token object with the buffer in in2.
* *
@ -257,7 +249,6 @@ int token_string_casecmp(
/*! [in] String of characters to compare with. */ /*! [in] String of characters to compare with. */
char *in2); char *in2);
/*! /*!
* \brief Compares a null terminated string to a token (exact). * \brief Compares a null terminated string to a token (exact).
* *
@ -272,7 +263,6 @@ int token_string_cmp(
/*! [in] String of characters to compare with. */ /*! [in] String of characters to compare with. */
char *in2); char *in2);
/*! /*!
* \brief Compares two tokens. * \brief Compares two tokens.
* *
@ -287,7 +277,6 @@ int token_cmp(
/*! [in] Second token object used for the comparison. */ /*! [in] Second token object used for the comparison. */
token *in2); token *in2);
/*! /*!
* \brief Parses a string representing a host and port (e.g. "127.127.0.1:80" * \brief 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 * or "localhost") and fills out a hostport_type struct with internet address
@ -304,7 +293,6 @@ int parse_hostport(
* an internet address. */ * an internet address. */
hostport_type *out); hostport_type *out);
/*! /*!
* \brief Removes http escaped characters such as: "%20" and replaces them with * \brief Removes http escaped characters such as: "%20" and replaces them with
* their character representation. i.e. "hello%20foo" -> "hello foo". * their character representation. i.e. "hello%20foo" -> "hello foo".
@ -320,7 +308,6 @@ int remove_escaped_chars(
/*! [in,out] Size limit for the number of characters. */ /*! [in,out] Size limit for the number of characters. */
size_t *size); size_t *size);
/*! /*!
* \brief Removes ".", and ".." from a path. * \brief Removes ".", and ".." from a path.
* *
@ -349,7 +336,6 @@ int remove_dots(
/*! [in] Size limit for the number of characters. */ /*! [in] Size limit for the number of characters. */
size_t size); size_t size);
/*! /*!
* \brief resolves a relative url with a base url returning a NEW (dynamically * \brief resolves a relative url with a base url returning a NEW (dynamically
* allocated with malloc) full url. * allocated with malloc) full url.
@ -370,7 +356,6 @@ char *resolve_rel_url(
/*! [in] Relative URL. */ /*! [in] Relative URL. */
char *rel_url); char *rel_url);
/*! /*!
* \brief Parses a uri as defined in http://www.ietf.org/rfc/rfc2396.txt * \brief Parses a uri as defined in http://www.ietf.org/rfc/rfc2396.txt
* (RFC explaining URIs). * (RFC explaining URIs).
@ -391,7 +376,6 @@ int parse_uri(
/*! [out] Output parameter which will have the parsed uri information. */ /*! [out] Output parameter which will have the parsed uri information. */
uri_type *out); uri_type *out);
/*! /*!
* \brief Same as parse_uri(), except that all strings are unescaped * \brief Same as parse_uri(), except that all strings are unescaped
* (%XX replaced by chars). * (%XX replaced by chars).
@ -408,7 +392,6 @@ int parse_uri_and_unescape(
/*! [out] Output parameter which will have the parsed uri information. */ /*! [out] Output parameter which will have the parsed uri information. */
uri_type *out); uri_type *out);
/*! /*!
* \brief * \brief
* *
@ -422,7 +405,6 @@ int parse_token(
/*! [in] . */ /*! [in] . */
int max_size); int max_size);
/* Commented #defines, functions and typdefs */ /* Commented #defines, functions and typdefs */
#if 0 #if 0

View File

@ -130,9 +130,9 @@ void web_server_callback(
#ifdef __cplusplus #ifdef __cplusplus
} // extern C } /* extern C */
#endif #endif
#endif // GENLIB_NET_HTTP_WEBSERVER_H #endif /* GENLIB_NET_HTTP_WEBSERVER_H */

View File

@ -1,33 +1,33 @@
/////////////////////////////////////////////////////////////////////////// /*******************************************************************************
// *
// Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
// All rights reserved. * All rights reserved.
// *
// Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
// *
// * Redistributions of source code must retain the above copyright notice, * - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, * - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors * - Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
// without specific prior written permission. * without specific prior written permission.
// *
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// *
/////////////////////////////////////////////////////////////////////////// ******************************************************************************/
#include "config.h" #include "config.h"
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -54,7 +54,7 @@
#define SOAP_ACTION_RESP 1 #define SOAP_ACTION_RESP 1
#define SOAP_VAR_RESP 2 #define SOAP_VAR_RESP 2
//#define SOAP_ERROR_RESP 3 /*#define SOAP_ERROR_RESP 3*/
#define SOAP_ACTION_RESP_ERROR 3 #define SOAP_ACTION_RESP_ERROR 3
#define SOAP_VAR_RESP_ERROR 4 #define SOAP_VAR_RESP_ERROR 4
@ -96,7 +96,7 @@ dom_cmp_name( IN char *name,
strcmp( nameptr.buf, name ) == 0 ) { strcmp( nameptr.buf, name ) == 0 ) {
ret_code = 0; ret_code = 0;
} else { } else {
ret_code = 1; // names are not the same ret_code = 1; /* names are not the same */
} }
return ret_code; return ret_code;
@ -125,20 +125,20 @@ dom_find_node( IN char *node_name,
{ {
IXML_Node *node; IXML_Node *node;
// invalid args /* invalid args */
if( node_name == NULL || start_node == NULL ) { if( node_name == NULL || start_node == NULL ) {
return UPNP_E_NOT_FOUND; return UPNP_E_NOT_FOUND;
} }
node = ixmlNode_getFirstChild( start_node ); node = ixmlNode_getFirstChild( start_node );
while( node != NULL ) { while( node != NULL ) {
// match name /* match name */
if( dom_cmp_name( node_name, node ) == 0 ) { if( dom_cmp_name( node_name, node ) == 0 ) {
*matching_node = node; *matching_node = node;
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
// free and next node /* free and next node */
node = ixmlNode_getNextSibling( node ); // next node node = ixmlNode_getNextSibling( node ); /* next node */
} }
return UPNP_E_NOT_FOUND; return UPNP_E_NOT_FOUND;
@ -193,10 +193,10 @@ dom_find_deep_node( IN char *names[],
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
node = match_node; // try again node = match_node; /* try again */
} }
return UPNP_E_NOT_FOUND; // this line not reached return UPNP_E_NOT_FOUND; /* this line not reached */
} }
/**************************************************************************** /****************************************************************************
@ -253,7 +253,7 @@ get_host_and_path( IN char *ctrl_url,
if( parse_uri( ctrl_url, strlen( ctrl_url ), url ) != HTTP_SUCCESS ) { if( parse_uri( ctrl_url, strlen( ctrl_url ), url ) != HTTP_SUCCESS ) {
return -1; return -1;
} }
// This is done to ensure that the buffer is kept const /* This is done to ensure that the buffer is kept const */
((memptr *)host)->buf = (char *)url->hostport.text.buff; ((memptr *)host)->buf = (char *)url->hostport.text.buff;
((memptr *)host)->length = url->hostport.text.size; ((memptr *)host)->length = url->hostport.text.size;
@ -310,15 +310,15 @@ add_man_header( INOUT membuffer * headers )
char *man_hdr = "MAN: \"http://schemas.xmlsoap.org/soap/envelope/\"; " char *man_hdr = "MAN: \"http://schemas.xmlsoap.org/soap/envelope/\"; "
"ns=01\r\n01-"; "ns=01\r\n01-";
// change POST to M-POST /* change POST to M-POST */
if( membuffer_insert( headers, "M-", 2, 0 ) != 0 ) { if( membuffer_insert( headers, "M-", 2, 0 ) != 0 ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
soap_action_hdr = strstr( headers->buf, "SOAPACTION:" ); soap_action_hdr = strstr( headers->buf, "SOAPACTION:" );
assert( soap_action_hdr != NULL ); // can't fail assert( soap_action_hdr != NULL ); /* can't fail */
// insert MAN header /* insert MAN header */
if( membuffer_insert( headers, man_hdr, strlen( man_hdr ), if( membuffer_insert( headers, man_hdr, strlen( man_hdr ),
soap_action_hdr - headers->buf ) != 0 ) { soap_action_hdr - headers->buf ) != 0 ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
@ -357,16 +357,16 @@ soap_request_and_response( IN membuffer * request,
httpmsg_destroy( &response->msg ); httpmsg_destroy( &response->msg );
return ret_code; return ret_code;
} }
// method-not-allowed error /* method-not-allowed error */
if( response->msg.status_code == HTTP_METHOD_NOT_ALLOWED ) { if( response->msg.status_code == HTTP_METHOD_NOT_ALLOWED ) {
ret_code = add_man_header( request ); // change to M-POST msg ret_code = add_man_header( request ); /* change to M-POST msg */
if( ret_code != 0 ) { if( ret_code != 0 ) {
return ret_code; return ret_code;
} }
httpmsg_destroy( &response->msg ); // about to reuse response httpmsg_destroy( &response->msg ); /* about to reuse response */
// try again /* try again */
ret_code = http_RequestAndResponse( destination_url, request->buf, ret_code = http_RequestAndResponse( destination_url, request->buf,
request->length, request->length,
HTTPMETHOD_MPOST, HTTPMETHOD_MPOST,
@ -423,9 +423,9 @@ get_response_value( IN http_message_t * hmsg,
char *names[5]; char *names[5];
const DOMString nodeValue; const DOMString nodeValue;
err_code = UPNP_E_BAD_RESPONSE; // default error err_code = UPNP_E_BAD_RESPONSE; /* default error */
// only 200 and 500 status codes are relevant /* only 200 and 500 status codes are relevant */
if( ( hmsg->status_code != HTTP_OK && if( ( hmsg->status_code != HTTP_OK &&
hmsg->status_code != HTTP_INTERNAL_SERVER_ERROR ) || hmsg->status_code != HTTP_INTERNAL_SERVER_ERROR ) ||
!has_xml_content_type( hmsg ) ) { !has_xml_content_type( hmsg ) ) {
@ -445,9 +445,9 @@ get_response_value( IN http_message_t * hmsg,
} }
if( code == SOAP_ACTION_RESP ) { if( code == SOAP_ACTION_RESP ) {
// /* */
// try reading soap action response /* try reading soap action response */
// /* */
assert( action_value != NULL ); assert( action_value != NULL );
*action_value = NULL; *action_value = NULL;
@ -474,7 +474,7 @@ get_response_value( IN http_message_t * hmsg,
done = TRUE; done = TRUE;
} }
} else if( code == SOAP_VAR_RESP ) { } else if( code == SOAP_VAR_RESP ) {
// try reading var response /* try reading var response */
assert( str_value != NULL ); assert( str_value != NULL );
*str_value = NULL; *str_value = NULL;
@ -496,7 +496,7 @@ get_response_value( IN http_message_t * hmsg,
} }
if( !done ) { if( !done ) {
// not action or var resp; read error code and description /* not action or var resp; read error code and description */
*str_value = NULL; *str_value = NULL;
names[0] = "Envelope"; names[0] = "Envelope";
@ -522,7 +522,7 @@ get_response_value( IN http_message_t * hmsg,
*upnp_error_code = atoi( temp_str ); *upnp_error_code = atoi( temp_str );
if( *upnp_error_code < 400 ) { if( *upnp_error_code < 400 ) {
err_code = *upnp_error_code; err_code = *upnp_error_code;
goto error_handler; // bad SOAP error code goto error_handler; /* bad SOAP error code */
} }
if( code == SOAP_VAR_RESP ) { if( code == SOAP_VAR_RESP ) {
@ -616,27 +616,27 @@ SoapSendAction( IN char *action_url,
size_t xml_end_len; size_t xml_end_len;
size_t action_str_len; size_t action_str_len;
*response_node = NULL; // init *response_node = NULL; /* init */
err_code = UPNP_E_OUTOF_MEMORY; // default error err_code = UPNP_E_OUTOF_MEMORY; /* default error */
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
"Inside SoapSendAction():" ); "Inside SoapSendAction():" );
// init /* init */
membuffer_init( &request ); membuffer_init( &request );
membuffer_init( &responsename ); membuffer_init( &responsename );
// print action /* print action */
action_str = ixmlPrintNode( ( IXML_Node * ) action_node ); action_str = ixmlPrintNode( ( IXML_Node * ) action_node );
if( action_str == NULL ) { if( action_str == NULL ) {
goto error_handler; goto error_handler;
} }
// get action name /* get action name */
if( get_action_name( action_str, &name ) != 0 ) { if( get_action_name( action_str, &name ) != 0 ) {
err_code = UPNP_E_INVALID_ACTION; err_code = UPNP_E_INVALID_ACTION;
goto error_handler; goto error_handler;
} }
// parse url /* parse url */
if( http_FixStrUrl( action_url, strlen( action_url ), &url ) != 0 ) { if( http_FixStrUrl( action_url, strlen( action_url ), &url ) != 0 ) {
err_code = UPNP_E_INVALID_URL; err_code = UPNP_E_INVALID_URL;
goto error_handler; goto error_handler;
@ -653,7 +653,7 @@ SoapSendAction( IN char *action_url,
xml_end_len = strlen( xml_end ); xml_end_len = strlen( xml_end );
action_str_len = strlen( action_str ); action_str_len = strlen( action_str );
// make request msg /* make request msg */
request.size_inc = 50; request.size_inc = 50;
content_length = xml_start_len + action_str_len + xml_end_len; content_length = xml_start_len + action_str_len + xml_end_len;
if (http_MakeMessage( if (http_MakeMessage(
@ -680,7 +680,7 @@ SoapSendAction( IN char *action_url,
membuffer_append_str( &responsename, "Response" ) != 0 ) { membuffer_append_str( &responsename, "Response" ) != 0 ) {
goto error_handler; goto error_handler;
} }
// get action node from the response /* get action node from the response */
ret_code = get_response_value( &response.msg, SOAP_ACTION_RESP, ret_code = get_response_value( &response.msg, SOAP_ACTION_RESP,
responsename.buf, &upnp_error_code, responsename.buf, &upnp_error_code,
( IXML_Node ** ) response_node, ( IXML_Node ** ) response_node,
@ -767,32 +767,32 @@ SoapSendActionEx( IN char *action_url,
size_t xml_end_len; size_t xml_end_len;
off_t content_length; off_t content_length;
*response_node = NULL; // init *response_node = NULL; /* init */
err_code = UPNP_E_OUTOF_MEMORY; // default error err_code = UPNP_E_OUTOF_MEMORY; /* default error */
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
"Inside SoapSendActionEx():" ); "Inside SoapSendActionEx():" );
// init /* init */
membuffer_init( &request ); membuffer_init( &request );
membuffer_init( &responsename ); membuffer_init( &responsename );
// header string /* header string */
xml_header_str = ixmlPrintNode( ( IXML_Node * ) header ); xml_header_str = ixmlPrintNode( ( IXML_Node * ) header );
if( xml_header_str == NULL ) { if( xml_header_str == NULL ) {
goto error_handler; goto error_handler;
} }
// print action /* print action */
action_str = ixmlPrintNode( ( IXML_Node * ) action_node ); action_str = ixmlPrintNode( ( IXML_Node * ) action_node );
if( action_str == NULL ) { if( action_str == NULL ) {
goto error_handler; goto error_handler;
} }
// get action name /* get action name */
if( get_action_name( action_str, &name ) != 0 ) { if( get_action_name( action_str, &name ) != 0 ) {
err_code = UPNP_E_INVALID_ACTION; err_code = UPNP_E_INVALID_ACTION;
goto error_handler; goto error_handler;
} }
// parse url /* parse url */
if( http_FixStrUrl( action_url, strlen( action_url ), &url ) != 0 ) { if( http_FixStrUrl( action_url, strlen( action_url ), &url ) != 0 ) {
err_code = UPNP_E_INVALID_URL; err_code = UPNP_E_INVALID_URL;
goto error_handler; goto error_handler;
@ -814,7 +814,7 @@ SoapSendActionEx( IN char *action_url,
xml_header_end_len = strlen( xml_header_end ); xml_header_end_len = strlen( xml_header_end );
xml_header_str_len = strlen( xml_header_str ); xml_header_str_len = strlen( xml_header_str );
// make request msg /* make request msg */
request.size_inc = 50; request.size_inc = 50;
content_length = content_length =
xml_start_len + xml_start_len +
@ -848,7 +848,7 @@ SoapSendActionEx( IN char *action_url,
membuffer_append_str( &responsename, "Response" ) != 0 ) { membuffer_append_str( &responsename, "Response" ) != 0 ) {
goto error_handler; goto error_handler;
} }
// get action node from the response /* get action node from the response */
ret_code = get_response_value( &response.msg, SOAP_ACTION_RESP, ret_code = get_response_value( &response.msg, SOAP_ACTION_RESP,
responsename.buf, &upnp_error_code, responsename.buf, &upnp_error_code,
( IXML_Node ** ) response_node, ( IXML_Node ** ) response_node,
@ -896,8 +896,8 @@ SoapGetServiceVarStatus( IN char *action_url,
IN char *var_name, IN char *var_name,
OUT char **var_value ) OUT char **var_value )
{ {
const memptr host; // value for HOST header const memptr host; /* value for HOST header */
const memptr path; // ctrl path in first line in msg const memptr path; /* ctrl path in first line in msg */
uri_type url; uri_type url;
membuffer request; membuffer request;
int ret_code; int ret_code;
@ -919,15 +919,15 @@ SoapGetServiceVarStatus( IN char *action_url,
"</s:Body>\r\n" "</s:Body>\r\n"
"</s:Envelope>\r\n"; "</s:Envelope>\r\n";
*var_value = NULL; // return NULL in case of an error *var_value = NULL; /* return NULL in case of an error */
membuffer_init( &request ); membuffer_init( &request );
// get host hdr and url path /* get host hdr and url path */
if( get_host_and_path( action_url, &host, &path, &url ) == -1 ) { if( get_host_and_path( action_url, &host, &path, &url ) == -1 ) {
return UPNP_E_INVALID_URL; return UPNP_E_INVALID_URL;
} }
// make headers /* make headers */
request.size_inc = 50; request.size_inc = 50;
content_length = strlen( xml_start ) + strlen( var_name ) + strlen( xml_end ); content_length = strlen( xml_start ) + strlen( var_name ) + strlen( xml_end );
if (http_MakeMessage( if (http_MakeMessage(
@ -941,13 +941,13 @@ SoapGetServiceVarStatus( IN char *action_url,
xml_start, var_name, xml_end ) != 0 ) { xml_start, var_name, xml_end ) != 0 ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send msg and get reply /* send msg and get reply */
ret_code = soap_request_and_response( &request, &url, &response ); ret_code = soap_request_and_response( &request, &url, &response );
membuffer_destroy( &request ); membuffer_destroy( &request );
if( ret_code != UPNP_E_SUCCESS ) { if( ret_code != UPNP_E_SUCCESS ) {
return ret_code; return ret_code;
} }
// get variable value from the response /* get variable value from the response */
ret_code = get_response_value( &response.msg, SOAP_VAR_RESP, NULL, ret_code = get_response_value( &response.msg, SOAP_VAR_RESP, NULL,
&upnp_error_code, NULL, var_value ); &upnp_error_code, NULL, var_value );
@ -962,5 +962,6 @@ SoapGetServiceVarStatus( IN char *action_url,
} }
} }
#endif // EXCLUDE_SOAP #endif /* EXCLUDE_SOAP */
#endif // INCLUDE_CLIENT_APIS #endif /* INCLUDE_CLIENT_APIS */

View File

@ -29,19 +29,15 @@
* *
******************************************************************************/ ******************************************************************************/
/*! /*!
* \file * \file
*/ */
#include "config.h" #include "config.h"
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
#if EXCLUDE_SOAP == 0 #if EXCLUDE_SOAP == 0
#define SOAP_BODY "Body" #define SOAP_BODY "Body"
#define SOAP_URN "http:/""/schemas.xmlsoap.org/soap/envelope/" #define SOAP_URN "http:/""/schemas.xmlsoap.org/soap/envelope/"
@ -56,12 +52,10 @@
#include "unixutil.h" #include "unixutil.h"
#include "upnpapi.h" #include "upnpapi.h"
#ifdef WIN32 #ifdef WIN32
#define snprintf _snprintf #define snprintf _snprintf
#endif #endif
/*! timeout duration in secs for transmission/reception */ /*! timeout duration in secs for transmission/reception */
#define SOAP_TIMEOUT UPNP_TIMEOUT #define SOAP_TIMEOUT UPNP_TIMEOUT
@ -83,23 +77,16 @@ static const char *Soap_Invalid_Var = "Invalid Var";
const char *ContentTypeHeader = const char *ContentTypeHeader =
"CONTENT-TYPE: text/xml; charset=\"utf-8\"\r\n"; "CONTENT-TYPE: text/xml; charset=\"utf-8\"\r\n";
/*!
/**************************************************************************** * \brief This function retrives the name of the SOAP action.
* Function : get_request_type
* *
* Parameters : * \return 0 if successful else returns appropriate error.
* IN http_message_t* request : HTTP request */
* OUT memptr* action_name : SOAP action name static UPNP_INLINE int get_request_type(
* /*! [in] HTTP request. */
* Description : This function retrives the name of the SOAP action http_message_t *request,
* /*! [out] SOAP action name. */
* Return : int memptr *action_name)
* 0 if successful else returns appropriate error.
* Note :
****************************************************************************/
static UPNP_INLINE int
get_request_type( IN http_message_t * request,
OUT memptr * action_name )
{ {
memptr value; memptr value;
memptr ns_value, memptr ns_value,
@ -109,16 +96,15 @@ get_request_type( IN http_message_t * request,
char *s; char *s;
membuffer soap_action_name; membuffer soap_action_name;
// find soapaction header /* find soapaction header */
//
if( request->method == SOAPMETHOD_POST ) { if( request->method == SOAPMETHOD_POST ) {
if( httpmsg_find_hdr( request, HDR_SOAPACTION, &value ) if( httpmsg_find_hdr( request, HDR_SOAPACTION, &value )
== NULL ) { == NULL ) {
return SREQ_HDR_NOT_FOUND; return SREQ_HDR_NOT_FOUND;
} }
} else // M-POST } else {
{ /* M-POST */
// get NS value from MAN header /* get NS value from MAN header */
hdr = httpmsg_find_hdr( request, HDR_MAN, &value ); hdr = httpmsg_find_hdr( request, HDR_MAN, &value );
if( hdr == NULL ) { if( hdr == NULL ) {
return SREQ_HDR_NOT_FOUND; return SREQ_HDR_NOT_FOUND;
@ -128,7 +114,7 @@ get_request_type( IN http_message_t * request,
&dummy_quote, &ns_value ) != 0 ) { &dummy_quote, &ns_value ) != 0 ) {
return SREQ_BAD_HDR_FORMAT; return SREQ_BAD_HDR_FORMAT;
} }
// create soapaction name header /* create soapaction name header */
membuffer_init( &soap_action_name ); membuffer_init( &soap_action_name );
if( ( membuffer_assign( &soap_action_name, if( ( membuffer_assign( &soap_action_name,
ns_value.buf, ns_value.length ) ns_value.buf, ns_value.length )
@ -151,8 +137,7 @@ get_request_type( IN http_message_t * request,
value.length = hdr->value.length; value.length = hdr->value.length;
} }
// determine type /* determine type */
//
save_char = value.buf[value.length]; save_char = value.buf[value.length];
value.buf[value.length] = '\0'; value.buf[value.length] = '\0';
@ -162,21 +147,22 @@ get_request_type( IN http_message_t * request,
return SREQ_BAD_HDR_FORMAT; return SREQ_BAD_HDR_FORMAT;
} }
s++; // move to value /* move to value */
s++;
if( matchstr( s, value.length - ( s - value.buf ), "%s", if( matchstr( s, value.length - ( s - value.buf ), "%s",
action_name ) != PARSE_OK ) { action_name ) != PARSE_OK ) {
value.buf[value.length] = save_char; value.buf[value.length] = save_char;
return SREQ_BAD_HDR_FORMAT; return SREQ_BAD_HDR_FORMAT;
} }
// action name or variable ? /* action name or variable ? */
if( memptr_cmp( action_name, "QueryStateVariable" ) == 0 ) { if( memptr_cmp( action_name, "QueryStateVariable" ) == 0 ) {
// query variable /* query variable */
action_name->buf = NULL; action_name->buf = NULL;
action_name->length = 0; action_name->length = 0;
} }
/* restore */
value.buf[value.length] = save_char; // restore value.buf[value.length] = save_char;
return 0; return 0;
} }
@ -206,7 +192,7 @@ send_error_response( IN SOCKINFO * info,
int major, int major,
minor; minor;
const char *start_body = const char *start_body =
// "<?xml version=\"1.0\"?>\n" required?? /* "<?xml version=\"1.0\"?>\n" required?? */
"<s:Envelope " "<s:Envelope "
"xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
@ -231,14 +217,14 @@ send_error_response( IN SOCKINFO * info,
sprintf( err_code_str, "%d", error_code ); sprintf( err_code_str, "%d", error_code );
// calc body len /* calc body len */
content_length = strlen( start_body ) + strlen( err_code_str ) + content_length = strlen( start_body ) + strlen( err_code_str ) +
strlen( mid_body ) + strlen( err_msg ) + strlen( end_body ); strlen( mid_body ) + strlen( err_msg ) + strlen( end_body );
http_CalcResponseVersion( hmsg->major_version, hmsg->minor_version, http_CalcResponseVersion( hmsg->major_version, hmsg->minor_version,
&major, &minor ); &major, &minor );
// make headers /* make headers */
membuffer_init( &headers ); membuffer_init( &headers );
if (http_MakeMessage( if (http_MakeMessage(
&headers, major, minor, &headers, major, minor,
@ -251,9 +237,9 @@ send_error_response( IN SOCKINFO * info,
start_body, err_code_str, mid_body, err_msg, start_body, err_code_str, mid_body, err_msg,
end_body ) != 0 ) { end_body ) != 0 ) {
membuffer_destroy( &headers ); membuffer_destroy( &headers );
return; // out of mem return; /* out of mem */
} }
// send err msg /* send err msg */
http_SendMessage( info, &timeout_secs, "b", http_SendMessage( info, &timeout_secs, "b",
headers.buf, headers.length ); headers.buf, headers.length );
@ -304,7 +290,7 @@ send_var_query_response( IN SOCKINFO * info,
content_length = strlen( start_body ) + strlen( var_value ) + content_length = strlen( start_body ) + strlen( var_value ) +
strlen( end_body ); strlen( end_body );
// make headers /* make headers */
membuffer_init( &response ); membuffer_init( &response );
if (http_MakeMessage( if (http_MakeMessage(
@ -317,10 +303,10 @@ send_var_query_response( IN SOCKINFO * info,
X_USER_AGENT, X_USER_AGENT,
start_body, var_value, end_body ) != 0 ) { start_body, var_value, end_body ) != 0 ) {
membuffer_destroy( &response ); membuffer_destroy( &response );
return; // out of mem return; /* out of mem */
} }
// send msg /* send msg */
http_SendMessage( info, &timeout_secs, "b", http_SendMessage( info, &timeout_secs, "b",
response.buf, response.length ); response.buf, response.length );
@ -353,7 +339,7 @@ get_action_node( IN IXML_Document * TempDoc,
IXML_Node *ActNode = NULL; IXML_Node *ActNode = NULL;
DOMString ActNodeName = NULL; DOMString ActNodeName = NULL;
const DOMString nodeName; const DOMString nodeName;
int ret_code = -1; // error, by default int ret_code = -1; /* error, by default */
IXML_NodeList *nl = NULL; IXML_NodeList *nl = NULL;
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
@ -361,7 +347,7 @@ get_action_node( IN IXML_Document * TempDoc,
*RespNode = NULL; *RespNode = NULL;
// Got the Envelope node here /* Got the Envelope node here */
EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc ); EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc );
if( EnvpNode == NULL ) { if( EnvpNode == NULL ) {
goto error_handler; goto error_handler;
@ -379,12 +365,12 @@ get_action_node( IN IXML_Document * TempDoc,
if( BodyNode == NULL ) { if( BodyNode == NULL ) {
goto error_handler; goto error_handler;
} }
// Got action node here /* Got action node here */
ActNode = ixmlNode_getFirstChild( BodyNode ); ActNode = ixmlNode_getFirstChild( BodyNode );
if( ActNode == NULL ) { if( ActNode == NULL ) {
goto error_handler; goto error_handler;
} }
//Test whether this is the action node /* Test whether this is the action node */
nodeName = ixmlNode_getNodeName( ActNode ); nodeName = ixmlNode_getNodeName( ActNode );
if( nodeName == NULL ) { if( nodeName == NULL ) {
goto error_handler; goto error_handler;
@ -406,7 +392,7 @@ get_action_node( IN IXML_Document * TempDoc,
} }
} }
ret_code = 0; // success ret_code = 0; /* success */
error_handler: error_handler:
@ -498,8 +484,7 @@ check_soap_action_header( IN http_message_t * request,
char *temp = NULL; char *temp = NULL;
char *temp2 = NULL; char *temp2 = NULL;
//check soap action header /* check soap action header */
soap_action_header = httpmsg_find_hdr( request, HDR_SOAPACTION, soap_action_header = httpmsg_find_hdr( request, HDR_SOAPACTION,
&header_name ); &header_name );
@ -533,35 +518,28 @@ check_soap_action_header( IN http_message_t * request,
return ret_code; return ret_code;
} }
( *temp ) = 0; //temp make string ( *temp ) = 0; /* temp make string */
//check to see if it is Query State Variable or
//Service Action
/* check to see if it is Query State Variable or
* Service Action */
tempSize = strlen( urn ) + 2; tempSize = strlen( urn ) + 2;
ns_compare = ( char * )malloc( tempSize ); ns_compare = ( char * )malloc( tempSize );
if( !ns_compare ) { if( !ns_compare ) {
ret_code = UPNP_E_OUTOF_MEMORY; ret_code = UPNP_E_OUTOF_MEMORY;
free( temp_header_value ); free( temp_header_value );
return ret_code; return ret_code;
} }
snprintf( ns_compare, tempSize, "\"%s", urn ); snprintf( ns_compare, tempSize, "\"%s", urn );
if( strcmp( temp_header_value, ns_compare ) ) { if( strcmp( temp_header_value, ns_compare ) ) {
ret_code = UPNP_E_INVALID_ACTION; ret_code = UPNP_E_INVALID_ACTION;
} else { } else {
ret_code = UPNP_E_SUCCESS; ret_code = UPNP_E_SUCCESS;
temp++; temp++;
temp2 = strchr( temp, '\"' ); temp2 = strchr( temp, '\"' );
if( temp2 ) /* remove ending " if present */
if( temp2 ) //remove ending " if present
{ {
( *temp2 ) = 0; ( *temp2 ) = 0;
} }
if( *temp ) if( *temp )
( *actionName ) = strdup( temp ); ( *actionName ) = strdup( temp );
if( !*actionName ) { if( !*actionName ) {
@ -611,11 +589,11 @@ get_device_info( IN http_message_t *request,
int device_hnd; int device_hnd;
service_info *serv_info; service_info *serv_info;
char save_char; char save_char;
int ret_code = -1; // error by default int ret_code = -1; /* error by default */
const char *control_url; const char *control_url;
char *actionName = NULL; char *actionName = NULL;
// null-terminate pathquery of url /* null-terminate pathquery of url */
control_url = request->uri.pathquery.buff; control_url = request->uri.pathquery.buff;
save_char = control_url[request->uri.pathquery.size]; save_char = control_url[request->uri.pathquery.size];
((char *)control_url)[request->uri.pathquery.size] = '\0'; ((char *)control_url)[request->uri.pathquery.size] = '\0';
@ -641,7 +619,7 @@ get_device_info( IN http_message_t *request,
ret_code = UPNP_E_INVALID_ACTION; ret_code = UPNP_E_INVALID_ACTION;
goto error_handler; goto error_handler;
} }
//check soap body /* check soap body */
ret_code = ret_code =
check_soap_body( actionDoc, QUERY_STATE_VAR_URN, actionName ); check_soap_body( actionDoc, QUERY_STATE_VAR_URN, actionName );
free( actionName ); free( actionName );
@ -657,7 +635,7 @@ get_device_info( IN http_message_t *request,
ret_code = UPNP_E_INVALID_SERVICE; ret_code = UPNP_E_INVALID_SERVICE;
goto error_handler; goto error_handler;
} }
//check soap body /* check soap body */
ret_code = ret_code =
check_soap_body( actionDoc, serv_info->serviceType, check_soap_body( actionDoc, serv_info->serviceType,
actionName ); actionName );
@ -676,7 +654,7 @@ get_device_info( IN http_message_t *request,
ret_code = 0; ret_code = 0;
error_handler: error_handler:
((char *)control_url)[request->uri.pathquery.size] = save_char; // restore ((char *)control_url)[request->uri.pathquery.size] = save_char; /* restore */
HandleUnlock(); HandleUnlock();
return ret_code; return ret_code;
} }
@ -709,19 +687,18 @@ send_action_response( IN SOCKINFO * info,
int ret_code; int ret_code;
int timeout_secs = SOAP_TIMEOUT; int timeout_secs = SOAP_TIMEOUT;
static char *start_body = static char *start_body =
// "<?xml version=\"1.0\"?>" required?? /*"<?xml version=\"1.0\"?>" required?? */
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap." "<s:Envelope xmlns:s=\"http://schemas.xmlsoap."
"org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap." "org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap."
"org/soap/encoding/\"><s:Body>\n"; "org/soap/encoding/\"><s:Body>\n";
static char *end_body = "</s:Body> </s:Envelope>"; static char *end_body = "</s:Body> </s:Envelope>";
// init /* init */
http_CalcResponseVersion( request->major_version, http_CalcResponseVersion( request->major_version,
request->minor_version, &major, &minor ); request->minor_version, &major, &minor );
membuffer_init( &headers ); membuffer_init( &headers );
err_code = UPNP_E_OUTOF_MEMORY; // one error only err_code = UPNP_E_OUTOF_MEMORY; /* one error only */
/* get xml */
// get xml
xml_response = ixmlPrintNode( ( IXML_Node * ) action_resp ); xml_response = ixmlPrintNode( ( IXML_Node * ) action_resp );
if( xml_response == NULL ) { if( xml_response == NULL ) {
goto error_handler; goto error_handler;
@ -731,20 +708,18 @@ send_action_response( IN SOCKINFO * info,
strlen( start_body ) + strlen( start_body ) +
strlen( xml_response ) + strlen( xml_response ) +
strlen( end_body ); strlen( end_body );
/* make headers */
// make headers
if (http_MakeMessage( if (http_MakeMessage(
&headers, major, minor, &headers, major, minor,
"RNsDsSXcc", "RNsDsSXcc",
HTTP_OK, // status code HTTP_OK, /* status code */
content_length, content_length,
ContentTypeHeader, ContentTypeHeader,
"EXT:\r\n", "EXT:\r\n",
X_USER_AGENT) != 0 ) { X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
/* send whole msg */
// send whole msg
ret_code = http_SendMessage( info, &timeout_secs, "bbbb", ret_code = http_SendMessage( info, &timeout_secs, "bbbb",
headers.buf, headers.length, headers.buf, headers.length,
start_body, strlen( start_body ), start_body, strlen( start_body ),
@ -763,7 +738,7 @@ error_handler:
ixmlFreeDOMString( xml_response ); ixmlFreeDOMString( xml_response );
membuffer_destroy( &headers ); membuffer_destroy( &headers );
if( err_code != 0 ) { if( err_code != 0 ) {
// only one type of error to worry about - out of mem /* only one type of error to worry about - out of mem */
send_error_response( info, SOAP_ACTION_FAILED, "Out of memory", send_error_response( info, SOAP_ACTION_FAILED, "Out of memory",
request ); request );
} }
@ -796,22 +771,22 @@ get_var_name( IN IXML_Document * TempDoc,
const DOMString Temp = NULL; const DOMString Temp = NULL;
int ret_val = -1; int ret_val = -1;
// Got the Envelop node here /* Got the Envelop node here */
EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc ); EnvpNode = ixmlNode_getFirstChild( ( IXML_Node * ) TempDoc );
if( EnvpNode == NULL ) { if( EnvpNode == NULL ) {
goto error_handler; goto error_handler;
} }
// Got Body here /* Got Body here */
BodyNode = ixmlNode_getFirstChild( EnvpNode ); BodyNode = ixmlNode_getFirstChild( EnvpNode );
if( BodyNode == NULL ) { if( BodyNode == NULL ) {
goto error_handler; goto error_handler;
} }
// Got action node here /* Got action node here */
StNode = ixmlNode_getFirstChild( BodyNode ); StNode = ixmlNode_getFirstChild( BodyNode );
if( StNode == NULL ) { if( StNode == NULL ) {
goto error_handler; goto error_handler;
} }
//Test whether this is the action node /* Test whether this is the action node */
StNodeName = ixmlNode_getNodeName( StNode ); StNodeName = ixmlNode_getNodeName( StNode );
if( StNodeName == NULL || strstr( StNodeName, if( StNodeName == NULL || strstr( StNodeName,
"QueryStateVariable" ) == NULL ) { "QueryStateVariable" ) == NULL ) {
@ -831,7 +806,7 @@ get_var_name( IN IXML_Document * TempDoc,
"Received query for variable name %s\n", "Received query for variable name %s\n",
VarName ); VarName );
ret_val = 0; // success ret_val = 0; /* success */
error_handler: error_handler:
return ret_val; return ret_val;
@ -866,13 +841,13 @@ static UPNP_INLINE void handle_query_variable(
const char *err_str; const char *err_str;
int err_code; int err_code;
// get var name /* get var name */
if( get_var_name( xml_doc, var_name ) != 0 ) { if( get_var_name( xml_doc, var_name ) != 0 ) {
send_error_response( info, SOAP_INVALID_VAR, send_error_response( info, SOAP_INVALID_VAR,
Soap_Invalid_Var, request ); Soap_Invalid_Var, request );
return; return;
} }
// get info for event /* get info for event */
err_code = get_device_info( err_code = get_device_info(
request, 1, xml_doc, request, 1, xml_doc,
info->foreign_sockaddr.ss_family, info->foreign_sockaddr.ss_family,
@ -892,13 +867,13 @@ static UPNP_INLINE void handle_query_variable(
variable.CurrentVal = NULL; variable.CurrentVal = NULL;
variable.CtrlPtIPAddr = info->foreign_sockaddr; variable.CtrlPtIPAddr = info->foreign_sockaddr;
// send event /* send event */
soap_event_callback( UPNP_CONTROL_GET_VAR_REQUEST, &variable, cookie ); soap_event_callback( UPNP_CONTROL_GET_VAR_REQUEST, &variable, cookie );
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
"Return from callback for var request\n" ); "Return from callback for var request\n" );
// validate, and handle result /* validate, and handle result */
if( variable.CurrentVal == NULL ) { if( variable.CurrentVal == NULL ) {
err_code = SOAP_ACTION_FAILED; err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed; err_str = Soap_Action_Failed;
@ -917,7 +892,7 @@ static UPNP_INLINE void handle_query_variable(
send_error_response( info, err_code, err_str, request ); send_error_response( info, err_code, err_str, request );
return; return;
} }
// send response /* send response */
send_var_query_response( info, variable.CurrentVal, request ); send_var_query_response( info, variable.CurrentVal, request );
ixmlFreeDOMString( variable.CurrentVal ); ixmlFreeDOMString( variable.CurrentVal );
@ -957,19 +932,19 @@ handle_invoke_action( IN SOCKINFO * info,
action.ActionResult = NULL; action.ActionResult = NULL;
// null-terminate /* null-terminate */
save_char = action_name.buf[action_name.length]; save_char = action_name.buf[action_name.length];
action_name.buf[action_name.length] = '\0'; action_name.buf[action_name.length] = '\0';
// set default error /* set default error */
err_code = SOAP_INVALID_ACTION; err_code = SOAP_INVALID_ACTION;
err_str = Soap_Invalid_Action; err_str = Soap_Invalid_Action;
// get action node /* get action node */
if( get_action_node( xml_doc, action_name.buf, &resp_node ) == -1 ) { if( get_action_node( xml_doc, action_name.buf, &resp_node ) == -1 ) {
goto error_handler; goto error_handler;
} }
// get device info for action event /* get device info for action event */
err_code = get_device_info( err_code = get_device_info(
request, request,
0, 0,
@ -1005,22 +980,22 @@ handle_invoke_action( IN SOCKINFO * info,
} }
goto error_handler; goto error_handler;
} }
// validate, and handle action error /* validate, and handle action error */
if( action.ActionResult == NULL ) { if( action.ActionResult == NULL ) {
err_code = SOAP_ACTION_FAILED; err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed; err_str = Soap_Action_Failed;
goto error_handler; goto error_handler;
} }
// send response /* send response */
send_action_response( info, action.ActionResult, request ); send_action_response( info, action.ActionResult, request );
err_code = 0; err_code = 0;
// error handling and cleanup /* error handling and cleanup */
error_handler: error_handler:
ixmlDocument_free( action.ActionResult ); ixmlDocument_free( action.ActionResult );
ixmlDocument_free( resp_node ); ixmlDocument_free( resp_node );
action_name.buf[action_name.length] = save_char; // restore action_name.buf[action_name.length] = save_char; /* restore */
if( err_code != 0 ) { if( err_code != 0 ) {
send_error_response( info, err_code, err_str, request ); send_error_response( info, err_code, err_str, request );
} }
@ -1053,19 +1028,19 @@ soap_device_callback( IN http_parser_t * parser,
memptr action_name; memptr action_name;
IXML_Document *xml_doc = NULL; IXML_Document *xml_doc = NULL;
// set default error /* set default error */
err_code = SOAP_INVALID_ACTION; err_code = SOAP_INVALID_ACTION;
err_str = Soap_Invalid_Action; err_str = Soap_Invalid_Action;
// validate: content-type == text/xml /* validate: content-type == text/xml */
if( !has_xml_content_type( request ) ) { if( !has_xml_content_type( request ) ) {
goto error_handler; goto error_handler;
} }
// type of request /* type of request */
if( get_request_type( request, &action_name ) != 0 ) { if( get_request_type( request, &action_name ) != 0 ) {
goto error_handler; goto error_handler;
} }
// parse XML /* parse XML */
err_code = ixmlParseBufferEx( request->entity.buf, &xml_doc ); err_code = ixmlParseBufferEx( request->entity.buf, &xml_doc );
if( err_code != IXML_SUCCESS ) { if( err_code != IXML_SUCCESS ) {
if( err_code == IXML_INSUFFICIENT_MEMORY ) { if( err_code == IXML_INSUFFICIENT_MEMORY ) {
@ -1079,14 +1054,14 @@ soap_device_callback( IN http_parser_t * parser,
} }
if( action_name.length == 0 ) { if( action_name.length == 0 ) {
// query var /* query var */
handle_query_variable( info, request, xml_doc ); handle_query_variable( info, request, xml_doc );
} else { } else {
// invoke action /* invoke action */
handle_invoke_action( info, request, action_name, xml_doc ); handle_invoke_action( info, request, action_name, xml_doc );
} }
err_code = 0; // no error err_code = 0; /* no error */
error_handler: error_handler:
ixmlDocument_free( xml_doc ); ixmlDocument_free( xml_doc );
@ -1095,6 +1070,7 @@ soap_device_callback( IN http_parser_t * parser,
} }
} }
#endif // EXCLUDE_SOAP #endif /* EXCLUDE_SOAP */
#endif /* INCLUDE_DEVICE_APIS */
#endif // INCLUDE_DEVICE_APIS

View File

@ -29,17 +29,13 @@
* *
**************************************************************************/ **************************************************************************/
#include "config.h" #include "config.h"
#include "upnputil.h" #include "upnputil.h"
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
#if EXCLUDE_SSDP == 0 #if EXCLUDE_SSDP == 0
#include "httpparser.h" #include "httpparser.h"
#include "httpreadwrite.h" #include "httpreadwrite.h"
/*#include "ssdp_ResultData.h"*/ /*#include "ssdp_ResultData.h"*/
@ -50,15 +46,12 @@
#include "UpnpInet.h" #include "UpnpInet.h"
#include "ThreadPool.h" #include "ThreadPool.h"
#include <stdio.h> #include <stdio.h>
#ifdef WIN32 #ifdef WIN32
#include <string.h> #include <string.h>
#endif /* WIN32 */ #endif /* WIN32 */
/************************************************************************ /************************************************************************
* Function: send_search_result * Function: send_search_result
* *
@ -107,13 +100,16 @@ void send_search_result(IN void *data)
void ssdp_handle_ctrlpt_msg( void ssdp_handle_ctrlpt_msg(
IN http_message_t *hmsg, IN http_message_t *hmsg,
IN struct sockaddr *dest_addr, IN struct sockaddr *dest_addr,
IN xboolean timeout, // only in search reply /* only in search reply */
IN void *cookie) // only in search reply IN xboolean timeout,
/* only in search reply */
IN void *cookie)
{ {
int handle; int handle;
struct Handle_Info *ctrlpt_info = NULL; struct Handle_Info *ctrlpt_info = NULL;
memptr hdr_value; memptr hdr_value;
xboolean is_byebye; // byebye or alive /* byebye or alive */
xboolean is_byebye;
struct Upnp_Discovery param; struct Upnp_Discovery param;
SsdpEvent event; SsdpEvent event;
xboolean nt_found; xboolean nt_found;
@ -129,67 +125,59 @@ void ssdp_handle_ctrlpt_msg(
ResultData *threadData = NULL; ResultData *threadData = NULL;
ThreadPoolJob job; ThreadPoolJob job;
// we are assuming that there can be only one client supported at a time /* we are assuming that there can be only one client supported at a time */
HandleReadLock(); HandleReadLock();
if ( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) { if ( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock(); HandleUnlock();
return; return;
} }
// copy /* copy */
ctrlpt_callback = ctrlpt_info->Callback; ctrlpt_callback = ctrlpt_info->Callback;
ctrlpt_cookie = ctrlpt_info->Cookie; ctrlpt_cookie = ctrlpt_info->Cookie;
HandleUnlock(); HandleUnlock();
/* search timeout */
// search timeout
if ( timeout ) { if ( timeout ) {
ctrlpt_callback( UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie ); ctrlpt_callback( UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie );
return; return;
} }
param.ErrCode = UPNP_E_SUCCESS; param.ErrCode = UPNP_E_SUCCESS;
/* MAX-AGE, assume error */
// MAX-AGE
// assume error
param.Expires = -1; param.Expires = -1;
if ( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) {
if( matchstr( hdr_value.buf, hdr_value.length, if( matchstr( hdr_value.buf, hdr_value.length,
"%imax-age = %d%0", &param.Expires ) != PARSE_OK ) "%imax-age = %d%0", &param.Expires ) != PARSE_OK )
return; return;
} }
/* DATE */
// DATE
param.Date[0] = '\0'; param.Date[0] = '\0';
if ( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) {
linecopylen( param.Date, hdr_value.buf, hdr_value.length ); linecopylen( param.Date, hdr_value.buf, hdr_value.length );
} }
/* dest addr */
// dest addr
memcpy(&param.DestAddr, dest_addr, sizeof(struct sockaddr_in) ); memcpy(&param.DestAddr, dest_addr, sizeof(struct sockaddr_in) );
/* EXT */
// EXT
param.Ext[0] = '\0'; param.Ext[0] = '\0';
if ( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) {
linecopylen( param.Ext, hdr_value.buf, hdr_value.length ); linecopylen( param.Ext, hdr_value.buf, hdr_value.length );
} }
// LOCATION /* LOCATION */
param.Location[0] = '\0'; param.Location[0] = '\0';
if ( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) {
linecopylen( param.Location, hdr_value.buf, hdr_value.length ); linecopylen( param.Location, hdr_value.buf, hdr_value.length );
} }
// SERVER / USER-AGENT /* SERVER / USER-AGENT */
param.Os[0] = '\0'; param.Os[0] = '\0';
if ( httpmsg_find_hdr( hmsg, HDR_SERVER, &hdr_value ) != NULL || if ( httpmsg_find_hdr( hmsg, HDR_SERVER, &hdr_value ) != NULL ||
httpmsg_find_hdr( hmsg, HDR_USER_AGENT, &hdr_value ) != NULL ) { httpmsg_find_hdr( hmsg, HDR_USER_AGENT, &hdr_value ) != NULL ) {
linecopylen( param.Os, hdr_value.buf, hdr_value.length ); linecopylen( param.Os, hdr_value.buf, hdr_value.length );
} }
// clear everything /* clear everything */
param.DeviceId[0] = '\0'; param.DeviceId[0] = '\0';
param.DeviceType[0] = '\0'; param.DeviceType[0] = '\0';
param.ServiceType[0] = '\0'; param.ServiceType[0] = '\0';
/* not used; version is in ServiceType */
param.ServiceVer[0] = '\0'; // not used; version is in ServiceType param.ServiceVer[0] = '\0';
event.UDN[0] = '\0'; event.UDN[0] = '\0';
event.DeviceType[0] = '\0'; event.DeviceType[0] = '\0';
@ -218,44 +206,44 @@ void ssdp_handle_ctrlpt_msg(
strcpy( param.ServiceType, event.ServiceType ); strcpy( param.ServiceType, event.ServiceType );
} }
// ADVERT. OR BYEBYE /* ADVERT. OR BYEBYE */
if( hmsg->is_request ) { if( hmsg->is_request ) {
// use NTS hdr to determine advert., or byebye /* use NTS hdr to determine advert., or byebye */
if ( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) {
return; // error; NTS header not found return; /* error; NTS header not found */
} }
if ( memptr_cmp( &hdr_value, "ssdp:alive" ) == 0 ) { if ( memptr_cmp( &hdr_value, "ssdp:alive" ) == 0 ) {
is_byebye = FALSE; is_byebye = FALSE;
} else if( memptr_cmp( &hdr_value, "ssdp:byebye" ) == 0 ) { } else if( memptr_cmp( &hdr_value, "ssdp:byebye" ) == 0 ) {
is_byebye = TRUE; is_byebye = TRUE;
} else { } else {
return; // bad value return; /* bad value */
} }
if ( is_byebye ) { if ( is_byebye ) {
// check device byebye /* check device byebye */
if( !nt_found || !usn_found ) { if( !nt_found || !usn_found ) {
return; // bad byebye return; /* bad byebye */
} }
event_type = UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE; event_type = UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE;
} else { } else {
// check advertisement /* check advertisement.
// .Expires is valid if positive. This is for testing * Expires is valid if positive. This is for testing
// only. Expires should be greater than 1800 (30 mins) * only. Expires should be greater than 1800 (30 mins) */
if( !nt_found || if( !nt_found ||
!usn_found || !usn_found ||
strlen( param.Location ) == 0 || param.Expires <= 0 ) { strlen( param.Location ) == 0 || param.Expires <= 0 ) {
return; // bad advertisement return; /* bad advertisement */
} }
event_type = UPNP_DISCOVERY_ADVERTISEMENT_ALIVE; event_type = UPNP_DISCOVERY_ADVERTISEMENT_ALIVE;
} }
// call callback /* call callback */
ctrlpt_callback( event_type, &param, ctrlpt_cookie ); ctrlpt_callback( event_type, &param, ctrlpt_cookie );
} else // reply (to a SEARCH) } else {
{ /* reply (to a SEARCH) */
// only checking to see if there is a valid ST header /* only checking to see if there is a valid ST header */
st_found = FALSE; st_found = FALSE;
if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) != NULL ) { if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) != NULL ) {
save_char = hdr_value.buf[hdr_value.length]; save_char = hdr_value.buf[hdr_value.length];
@ -266,9 +254,9 @@ void ssdp_handle_ctrlpt_msg(
if( hmsg->status_code != HTTP_OK || if( hmsg->status_code != HTTP_OK ||
param.Expires <= 0 || param.Expires <= 0 ||
strlen( param.Location ) == 0 || !usn_found || !st_found ) { strlen( param.Location ) == 0 || !usn_found || !st_found ) {
return; // bad reply return; /* bad reply */
} }
// check each current search /* check each current search */
HandleLock(); HandleLock();
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) { if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock(); HandleUnlock();
@ -276,14 +264,14 @@ void ssdp_handle_ctrlpt_msg(
} }
node = ListHead( &ctrlpt_info->SsdpSearchList ); node = ListHead( &ctrlpt_info->SsdpSearchList );
// temporary add null termination /* temporary add null termination */
//save_char = hdr_value.buf[ hdr_value.length ]; /*save_char = hdr_value.buf[ hdr_value.length ]; */
//hdr_value.buf[ hdr_value.length ] = '\0'; /*hdr_value.buf[ hdr_value.length ] = '\0'; */
while( node != NULL ) { while( node != NULL ) {
searchArg = node->item; searchArg = node->item;
matched = 0; matched = 0;
// check for match of ST header and search target /* check for match of ST header and search target */
switch ( searchArg->requestType ) { switch ( searchArg->requestType ) {
case SSDP_ALL: case SSDP_ALL:
matched = 1; matched = 1;
@ -317,7 +305,7 @@ void ssdp_handle_ctrlpt_msg(
} }
if (matched) { if (matched) {
// schedule call back /* schedule call back*/
threadData = threadData =
( ResultData * ) malloc( sizeof( ResultData ) ); ( ResultData * ) malloc( sizeof( ResultData ) );
if (threadData != NULL) { if (threadData != NULL) {
@ -335,7 +323,7 @@ void ssdp_handle_ctrlpt_msg(
} }
HandleUnlock(); HandleUnlock();
//ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT, &param, cookie ); /*ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT, &param, cookie );*/
} }
} }
@ -428,15 +416,14 @@ static void CreateClientRequestPacketUlaGua(
* Returns: void * Returns: void
* *
***************************************************************************/ ***************************************************************************/
void void searchExpired(void *arg)
searchExpired( void *arg )
{ {
int *id = (int *)arg; int *id = (int *)arg;
int handle = -1; int handle = -1;
struct Handle_Info *ctrlpt_info = NULL; struct Handle_Info *ctrlpt_info = NULL;
//remove search Target from list and call client back /* remove search Target from list and call client back */
ListNode *node = NULL; ListNode *node = NULL;
SsdpSearchArg *item; SsdpSearchArg *item;
Upnp_FunPtr ctrlpt_callback; Upnp_FunPtr ctrlpt_callback;
@ -445,18 +432,14 @@ searchExpired( void *arg )
HandleLock(); HandleLock();
//remove search target from search list /* remove search target from search list */
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) { if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
free( id ); free( id );
HandleUnlock(); HandleUnlock();
return; return;
} }
ctrlpt_callback = ctrlpt_info->Callback; ctrlpt_callback = ctrlpt_info->Callback;
node = ListHead( &ctrlpt_info->SsdpSearchList ); node = ListHead( &ctrlpt_info->SsdpSearchList );
while( node != NULL ) { while( node != NULL ) {
item = ( SsdpSearchArg * ) node->item; item = ( SsdpSearchArg * ) node->item;
if( item->timeoutEventId == ( *id ) ) { if( item->timeoutEventId == ( *id ) ) {
@ -528,7 +511,7 @@ int SearchByTarget(
unsigned long addrv4 = inet_addr(gIF_IPV4); unsigned long addrv4 = inet_addr(gIF_IPV4);
int max_fd = 0; int max_fd = 0;
//ThreadData *ThData; /*ThreadData *ThData;*/
ThreadPoolJob job; ThreadPoolJob job;
requestType = ssdp_request_type1(St); requestType = ssdp_request_type1(St);
@ -644,7 +627,7 @@ int SearchByTarget(
imillisleep(SSDP_PAUSE); imillisleep(SSDP_PAUSE);
} }
} }
#endif //IPv6 #endif /* IPv6 */
if (gSsdpReqSocket4 != INVALID_SOCKET && if (gSsdpReqSocket4 != INVALID_SOCKET &&
FD_ISSET(gSsdpReqSocket4, &wrSet)) { FD_ISSET(gSsdpReqSocket4, &wrSet)) {
@ -665,5 +648,6 @@ int SearchByTarget(
return 1; return 1;
} }
#endif // EXCLUDE_SSDP #endif /* EXCLUDE_SSDP */
#endif // INCLUDE_CLIENT_APIS #endif /* INCLUDE_CLIENT_APIS */

View File

@ -120,34 +120,38 @@ void ssdp_handle_device_request(
int replyTime; int replyTime;
int maxAge; int maxAge;
// check man hdr /* check man hdr. */
if( httpmsg_find_hdr( hmsg, HDR_MAN, &hdr_value ) == NULL || if( httpmsg_find_hdr( hmsg, HDR_MAN, &hdr_value ) == NULL ||
memptr_cmp( &hdr_value, "\"ssdp:discover\"" ) != 0 ) { memptr_cmp( &hdr_value, "\"ssdp:discover\"" ) != 0 ) {
return; // bad or missing hdr /* bad or missing hdr. */
return;
} }
// MX header /* MX header. */
if( httpmsg_find_hdr( hmsg, HDR_MX, &hdr_value ) == NULL || if( httpmsg_find_hdr( hmsg, HDR_MX, &hdr_value ) == NULL ||
( mx = raw_to_int( &hdr_value, 10 ) ) < 0 ) { ( mx = raw_to_int( &hdr_value, 10 ) ) < 0 ) {
return; return;
} }
// ST header /* ST header. */
if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) == NULL ) { if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) == NULL ) {
return; return;
} }
save_char = hdr_value.buf[hdr_value.length]; save_char = hdr_value.buf[hdr_value.length];
hdr_value.buf[hdr_value.length] = '\0'; hdr_value.buf[hdr_value.length] = '\0';
ret_code = ssdp_request_type( hdr_value.buf, &event ); ret_code = ssdp_request_type( hdr_value.buf, &event );
hdr_value.buf[hdr_value.length] = save_char; // restore /* restore. */
hdr_value.buf[hdr_value.length] = save_char;
if( ret_code == -1 ) { if( ret_code == -1 ) {
return; // bad ST header /* bad ST header. */
return;
} }
HandleLock(); HandleLock();
// device info /* device info. */
if( GetDeviceHandleInfo( dest_addr->sa_family, if( GetDeviceHandleInfo( dest_addr->sa_family,
&handle, &dev_info ) != HND_DEVICE ) { &handle, &dev_info ) != HND_DEVICE ) {
HandleUnlock(); HandleUnlock();
return; // no info found /* no info found. */
return;
} }
maxAge = dev_info->MaxAge; maxAge = dev_info->MaxAge;
HandleUnlock(); HandleUnlock();
@ -180,11 +184,9 @@ void ssdp_handle_device_request(
TPJobInit( &job, advertiseAndReplyThread, threadArg ); TPJobInit( &job, advertiseAndReplyThread, threadArg );
TPJobSetFreeFunction( &job, ( free_routine ) free ); TPJobSetFreeFunction( &job, ( free_routine ) free );
//Subtract a percentage from the mx /* Subtract a percentage from the mx to allow for network and processing
//to allow for network and processing delays * delays (i.e. if search is for 30 seconds, respond
// (i.e. if search is for 30 seconds, * within 0 - 27 seconds). */
// respond withing 0 - 27 seconds)
if( mx >= 2 ) { if( mx >= 2 ) {
mx -= MAXVAL( 1, mx / MX_FUDGE_FACTOR ); mx -= MAXVAL( 1, mx / MX_FUDGE_FACTOR );
} }
@ -225,7 +227,8 @@ NewRequestHandler( IN struct sockaddr *DestAddr,
int socklen = sizeof( struct sockaddr_storage ); int socklen = sizeof( struct sockaddr_storage );
int Index; int Index;
unsigned long replyAddr = inet_addr( gIF_IPV4 ); unsigned long replyAddr = inet_addr( gIF_IPV4 );
int ttl = 4; // a/c to UPNP Spec /* a/c to UPNP Spec */
int ttl = 4;
int hops = 1; int hops = 1;
char buf_ntop[64]; char buf_ntop[64];
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
@ -480,7 +483,7 @@ DeviceAdvertisement( IN char *DevType,
struct sockaddr_in* DestAddr4 = (struct sockaddr_in*)&__ss; struct sockaddr_in* DestAddr4 = (struct sockaddr_in*)&__ss;
struct sockaddr_in6* DestAddr6 = (struct sockaddr_in6*)&__ss; struct sockaddr_in6* DestAddr6 = (struct sockaddr_in6*)&__ss;
//char Mil_Nt[LINE_SIZE] /* char Mil_Nt[LINE_SIZE] */
char Mil_Usn[LINE_SIZE]; char Mil_Usn[LINE_SIZE];
char *msgs[3]; char *msgs[3];
int ret_code = UPNP_E_SUCCESS; int ret_code = UPNP_E_SUCCESS;
@ -509,24 +512,20 @@ DeviceAdvertisement( IN char *DevType,
msgs[1] = NULL; msgs[1] = NULL;
msgs[2] = NULL; msgs[2] = NULL;
//If deviceis a root device , here we need to /* If deviceis a root device , here we need to send 3 advertisement
//send 3 advertisement or reply * or reply */
if( RootDev ) { if( RootDev ) {
sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn ); sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn );
CreateServicePacket( MSGTYPE_ADVERTISEMENT, "upnp:rootdevice", CreateServicePacket( MSGTYPE_ADVERTISEMENT, "upnp:rootdevice",
Mil_Usn, Location, Duration, &msgs[0], AddressFamily ); Mil_Usn, Location, Duration, &msgs[0], AddressFamily );
} }
// both root and sub-devices need to send these two messages /* both root and sub-devices need to send these two messages */
//
CreateServicePacket( MSGTYPE_ADVERTISEMENT, Udn, Udn, CreateServicePacket( MSGTYPE_ADVERTISEMENT, Udn, Udn,
Location, Duration, &msgs[1], AddressFamily ); Location, Duration, &msgs[1], AddressFamily );
sprintf( Mil_Usn, "%s::%s", Udn, DevType ); sprintf( Mil_Usn, "%s::%s", Udn, DevType );
CreateServicePacket( MSGTYPE_ADVERTISEMENT, DevType, Mil_Usn, CreateServicePacket( MSGTYPE_ADVERTISEMENT, DevType, Mil_Usn,
Location, Duration, &msgs[2], AddressFamily ); Location, Duration, &msgs[2], AddressFamily );
/* check error */
// check error
if( ( RootDev && msgs[0] == NULL ) || if( ( RootDev && msgs[0] == NULL ) ||
msgs[1] == NULL || msgs[2] == NULL ) { msgs[1] == NULL || msgs[2] == NULL ) {
free( msgs[0] ); free( msgs[0] );
@ -534,17 +533,17 @@ DeviceAdvertisement( IN char *DevType,
free( msgs[2] ); free( msgs[2] );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send packets /* send packets */
if( RootDev ) { if( RootDev ) {
// send 3 msg types /* send 3 msg types */
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] ); ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] );
} else // sub-device } else /* sub-device */
{ {
// send 2 msg types /* send 2 msg types */
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] ); ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] );
} }
// free msgs /* free msgs */
free( msgs[0] ); free( msgs[0] );
free( msgs[1] ); free( msgs[1] );
free( msgs[2] ); free( msgs[2] );
@ -590,17 +589,17 @@ SendReply( IN struct sockaddr *DestAddr,
msgs[1] = NULL; msgs[1] = NULL;
if( RootDev ) { if( RootDev ) {
// one msg for root device /* one msg for root device */
num_msgs = 1; num_msgs = 1;
sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn ); sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn );
CreateServicePacket( MSGTYPE_REPLY, "upnp:rootdevice", CreateServicePacket( MSGTYPE_REPLY, "upnp:rootdevice",
Mil_Usn, Location, Duration, &msgs[0], DestAddr->sa_family ); Mil_Usn, Location, Duration, &msgs[0], DestAddr->sa_family );
} else { } else {
// two msgs for embedded devices /* two msgs for embedded devices */
num_msgs = 1; num_msgs = 1;
//NK: FIX for extra response when someone searches by udn /*NK: FIX for extra response when someone searches by udn */
if( !ByType ) { if( !ByType ) {
CreateServicePacket( MSGTYPE_REPLY, Udn, Udn, Location, CreateServicePacket( MSGTYPE_REPLY, Udn, Udn, Location,
Duration, &msgs[0], DestAddr->sa_family ); Duration, &msgs[0], DestAddr->sa_family );
@ -611,7 +610,7 @@ SendReply( IN struct sockaddr *DestAddr,
} }
} }
// check error /* check error */
for( i = 0; i < num_msgs; i++ ) { for( i = 0; i < num_msgs; i++ ) {
if( msgs[i] == NULL ) { if( msgs[i] == NULL ) {
free( msgs[0] ); free( msgs[0] );
@ -619,7 +618,7 @@ SendReply( IN struct sockaddr *DestAddr,
} }
} }
// send msgs /* send msgs */
ret_code = NewRequestHandler( DestAddr, num_msgs, msgs ); ret_code = NewRequestHandler( DestAddr, num_msgs, msgs );
for( i = 0; i < num_msgs; i++ ) { for( i = 0; i < num_msgs; i++ ) {
if( msgs[i] != NULL ) if( msgs[i] != NULL )
@ -663,28 +662,23 @@ DeviceReply( IN struct sockaddr *DestAddr,
szReq[1] = NULL; szReq[1] = NULL;
szReq[2] = NULL; szReq[2] = NULL;
// create 2 or 3 msgs /* create 2 or 3 msgs */
if( RootDev ) { if( RootDev ) {
// 3 replies for root device /* 3 replies for root device */
strcpy( Mil_Nt, "upnp:rootdevice" ); strcpy( Mil_Nt, "upnp:rootdevice" );
sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn ); sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn );
CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[0], DestAddr->sa_family ); Location, Duration, &szReq[0], DestAddr->sa_family );
} }
sprintf( Mil_Nt, "%s", Udn ); sprintf( Mil_Nt, "%s", Udn );
sprintf( Mil_Usn, "%s", Udn ); sprintf( Mil_Usn, "%s", Udn );
CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[1], DestAddr->sa_family ); Location, Duration, &szReq[1], DestAddr->sa_family );
sprintf( Mil_Nt, "%s", DevType ); sprintf( Mil_Nt, "%s", DevType );
sprintf( Mil_Usn, "%s::%s", Udn, DevType ); sprintf( Mil_Usn, "%s::%s", Udn, DevType );
CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn, CreateServicePacket( MSGTYPE_REPLY, Mil_Nt, Mil_Usn,
Location, Duration, &szReq[2], DestAddr->sa_family ); Location, Duration, &szReq[2], DestAddr->sa_family );
/* check error */
// check error
if( ( RootDev && szReq[0] == NULL ) || if( ( RootDev && szReq[0] == NULL ) ||
szReq[1] == NULL || szReq[2] == NULL ) { szReq[1] == NULL || szReq[2] == NULL ) {
free( szReq[0] ); free( szReq[0] );
@ -692,14 +686,13 @@ DeviceReply( IN struct sockaddr *DestAddr,
free( szReq[2] ); free( szReq[2] );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send replies /* send replies */
if( RootDev ) { if( RootDev ) {
RetVal = NewRequestHandler( DestAddr, 3, szReq ); RetVal = NewRequestHandler( DestAddr, 3, szReq );
} else { } else {
RetVal = NewRequestHandler( DestAddr, 2, &szReq[1] ); RetVal = NewRequestHandler( DestAddr, 2, &szReq[1] );
} }
/* free */
// free
free( szReq[0] ); free( szReq[0] );
free( szReq[1] ); free( szReq[1] );
free( szReq[2] ); free( szReq[2] );
@ -756,8 +749,8 @@ ServiceAdvertisement( IN char *Udn,
sprintf( Mil_Usn, "%s::%s", Udn, ServType ); sprintf( Mil_Usn, "%s::%s", Udn, ServType );
//CreateServiceRequestPacket(1,szReq[0],Mil_Nt,Mil_Usn, /* CreateServiceRequestPacket(1,szReq[0],Mil_Nt,Mil_Usn,
//Server,Location,Duration); * Server,Location,Duration); */
CreateServicePacket( MSGTYPE_ADVERTISEMENT, ServType, Mil_Usn, CreateServicePacket( MSGTYPE_ADVERTISEMENT, ServType, Mil_Usn,
Location, Duration, &szReq[0], AddressFamily ); Location, Duration, &szReq[0], AddressFamily );
if( szReq[0] == NULL ) { if( szReq[0] == NULL ) {
@ -860,10 +853,10 @@ ServiceShutdown( IN char *Udn,
"Invalid device address family.\n" ); "Invalid device address family.\n" );
} }
//sprintf(Mil_Nt,"%s",ServType); /* sprintf(Mil_Nt,"%s",ServType); */
sprintf( Mil_Usn, "%s::%s", Udn, ServType ); sprintf( Mil_Usn, "%s::%s", Udn, ServType );
//CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn, /* CreateServiceRequestPacket(0,szReq[0],Mil_Nt,Mil_Usn,
//Server,Location,Duration); * Server,Location,Duration); */
CreateServicePacket( MSGTYPE_SHUTDOWN, ServType, Mil_Usn, CreateServicePacket( MSGTYPE_SHUTDOWN, ServType, Mil_Usn,
Location, Duration, &szReq[0], AddressFamily ); Location, Duration, &szReq[0], AddressFamily );
if( szReq[0] == NULL ) { if( szReq[0] == NULL ) {
@ -929,25 +922,21 @@ DeviceShutdown( IN char *DevType,
UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Invalid device address family.\n" ); "Invalid device address family.\n" );
} }
/* root device has one extra msg */
// root device has one extra msg
if( RootDev ) { if( RootDev ) {
sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn ); sprintf( Mil_Usn, "%s::upnp:rootdevice", Udn );
CreateServicePacket( MSGTYPE_SHUTDOWN, "upnp:rootdevice", CreateServicePacket( MSGTYPE_SHUTDOWN, "upnp:rootdevice",
Mil_Usn, Location, Duration, &msgs[0], AddressFamily ); Mil_Usn, Location, Duration, &msgs[0], AddressFamily );
} }
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
"In function DeviceShutdown\n" ); "In function DeviceShutdown\n" );
// both root and sub-devices need to send these two messages /* both root and sub-devices need to send these two messages */
CreateServicePacket( MSGTYPE_SHUTDOWN, Udn, Udn, CreateServicePacket( MSGTYPE_SHUTDOWN, Udn, Udn,
Location, Duration, &msgs[1], AddressFamily ); Location, Duration, &msgs[1], AddressFamily );
sprintf( Mil_Usn, "%s::%s", Udn, DevType ); sprintf( Mil_Usn, "%s::%s", Udn, DevType );
CreateServicePacket( MSGTYPE_SHUTDOWN, DevType, Mil_Usn, CreateServicePacket( MSGTYPE_SHUTDOWN, DevType, Mil_Usn,
Location, Duration, &msgs[2], AddressFamily ); Location, Duration, &msgs[2], AddressFamily );
/* check error */
// check error
if( ( RootDev && msgs[0] == NULL ) || if( ( RootDev && msgs[0] == NULL ) ||
msgs[1] == NULL || msgs[2] == NULL ) { msgs[1] == NULL || msgs[2] == NULL ) {
free( msgs[0] ); free( msgs[0] );
@ -955,17 +944,16 @@ DeviceShutdown( IN char *DevType,
free( msgs[2] ); free( msgs[2] );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send packets /* send packets */
if( RootDev ) { if( RootDev ) {
// send 3 msg types /* send 3 msg types */
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] ); ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 3, &msgs[0] );
} else // sub-device } else {
{ /* sub-device */
// send 2 msg types /* send 2 msg types */
ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] ); ret_code = NewRequestHandler( (struct sockaddr*)&__ss, 2, &msgs[1] );
} }
/* free msgs */
// free msgs
free( msgs[0] ); free( msgs[0] );
free( msgs[1] ); free( msgs[1] );
free( msgs[2] ); free( msgs[2] );
@ -973,6 +961,6 @@ DeviceShutdown( IN char *DevType,
return ret_code; return ret_code;
} }
#endif // EXCLUDE_SSDP #endif /* EXCLUDE_SSDP */
#endif // INCLUDE_DEVICE_APIS #endif /* INCLUDE_DEVICE_APIS */

View File

@ -595,11 +595,9 @@ ssdp_request_type1( IN char *cmd )
* Returns: int * Returns: int
* 0 on success; -1 on error * 0 on success; -1 on error
***************************************************************************/ ***************************************************************************/
int int ssdp_request_type(IN char *cmd, OUT SsdpEvent *Evt)
ssdp_request_type( IN char *cmd,
OUT SsdpEvent * Evt )
{ {
// clear event /* clear event */
memset( Evt, 0, sizeof( SsdpEvent ) ); memset( Evt, 0, sizeof( SsdpEvent ) );
unique_service_name( cmd, Evt ); unique_service_name( cmd, Evt );
Evt->ErrCode = NO_ERROR_FOUND; Evt->ErrCode = NO_ERROR_FOUND;
@ -624,15 +622,13 @@ ssdp_request_type( IN char *cmd,
* Returns: VOID * Returns: VOID
* *
***************************************************************************/ ***************************************************************************/
static void static void free_ssdp_event_handler_data(void *the_data)
free_ssdp_event_handler_data( void *the_data )
{ {
ssdp_thread_data *data = ( ssdp_thread_data * ) the_data; ssdp_thread_data *data = ( ssdp_thread_data * ) the_data;
if( data != NULL ) { if( data != NULL ) {
http_message_t *hmsg = &data->parser.msg; http_message_t *hmsg = &data->parser.msg;
/* free data */
// free data
httpmsg_destroy( hmsg ); httpmsg_destroy( hmsg );
free( data ); free( data );
} }
@ -699,8 +695,7 @@ static UPNP_INLINE xboolean valid_ssdp_msg(IN http_message_t *hmsg)
* Returns: int * Returns: int
* 0 if successful -1 if error * 0 if successful -1 if error
***************************************************************************/ ***************************************************************************/
static UPNP_INLINE int static UPNP_INLINE int start_event_handler(void *Data)
start_event_handler( void *Data )
{ {
http_parser_t *parser = NULL; http_parser_t *parser = NULL;
@ -716,21 +711,21 @@ start_event_handler( void *Data )
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
"SSDP recvd bad msg code = %d\n", "SSDP recvd bad msg code = %d\n",
status ); status );
// ignore bad msg, or not enuf mem /* ignore bad msg, or not enuf mem */
goto error_handler; goto error_handler;
} }
// valid notify msg /* valid notify msg */
} else if( status != PARSE_SUCCESS ) { } else if( status != PARSE_SUCCESS ) {
UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SSDP, __FILE__, __LINE__,
"SSDP recvd bad msg code = %d\n", status ); "SSDP recvd bad msg code = %d\n", status );
goto error_handler; goto error_handler;
} }
// check msg /* check msg */
if( valid_ssdp_msg( &parser->msg ) != TRUE ) { if( valid_ssdp_msg( &parser->msg ) != TRUE ) {
goto error_handler; goto error_handler;
} }
return 0; //////// done; thread will free 'data' return 0; /* done; thread will free 'data' */
error_handler: error_handler:
free_ssdp_event_handler_data( data ); free_ssdp_event_handler_data( data );
@ -798,16 +793,13 @@ readFromSSDPSocket( SOCKET socket )
requestBuf = staticBuf; requestBuf = staticBuf;
//in case memory /* in case memory can't be allocated, still drain the socket using a
//can't be allocated, still drain the * static buffer. */
//socket using a static buffer
data = ( ssdp_thread_data * ) data = ( ssdp_thread_data * )
malloc( sizeof( ssdp_thread_data ) ); malloc( sizeof( ssdp_thread_data ) );
if( data != NULL ) { if( data != NULL ) {
//initialize parser /* initialize parser */
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
if( socket == gSsdpReqSocket4 || socket == gSsdpReqSocket6 ) { if( socket == gSsdpReqSocket4 || socket == gSsdpReqSocket6 ) {
@ -826,11 +818,9 @@ readFromSSDPSocket( SOCKET socket )
#else #else
parser_request_init( &data->parser ); parser_request_init( &data->parser );
#endif #endif
/* set size of parser buffer */
//set size of parser buffer
if( membuffer_set_size( &data->parser.msg.msg, BUFSIZE ) == 0 ) { if( membuffer_set_size( &data->parser.msg.msg, BUFSIZE ) == 0 ) {
//use this as the buffer for recv /* use this as the buffer for recv */
requestBuf = data->parser.msg.msg.buf; requestBuf = data->parser.msg.msg.buf;
} else { } else {
@ -867,10 +857,10 @@ readFromSSDPSocket( SOCKET socket )
"%s\n" "%s\n"
"End of received multicast packet ----------------------------------------------\n", "End of received multicast packet ----------------------------------------------\n",
requestBuf ); requestBuf );
//add thread pool job to handle request /* add thread pool job to handle request */
if( data != NULL ) { if( data != NULL ) {
data->parser.msg.msg.length += byteReceived; data->parser.msg.msg.length += byteReceived;
// null-terminate /* null-terminate */
data->parser.msg.msg.buf[byteReceived] = 0; data->parser.msg.msg.buf[byteReceived] = 0;
memcpy( &data->dest_addr, &__ss, sizeof(__ss) ); memcpy( &data->dest_addr, &__ss, sizeof(__ss) );
TPJobInit( &job, ( start_routine ) TPJobInit( &job, ( start_routine )
@ -935,7 +925,7 @@ int get_ssdp_sockets(MiniServerSockArray *out)
} else { } else {
out->ssdpReqSock6 = INVALID_SOCKET; out->ssdpReqSock6 = INVALID_SOCKET;
} }
#endif //IPv6 #endif /* IPv6 */
#endif /* INCLUDE_CLIENT_APIS */ #endif /* INCLUDE_CLIENT_APIS */
@ -993,8 +983,7 @@ int get_ssdp_sockets(MiniServerSockArray *out)
} else { } else {
out->ssdpSock6UlaGua = INVALID_SOCKET; out->ssdpSock6UlaGua = INVALID_SOCKET;
} }
#endif //IPv6 #endif /* IPv6 */
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -1030,7 +1019,7 @@ int create_ssdp_sock_reqv4( SOCKET* ssdpReqSock )
setsockopt( *ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL, setsockopt( *ssdpReqSock, IPPROTO_IP, IP_MULTICAST_TTL,
&ttl, sizeof (ttl) ); &ttl, sizeof (ttl) );
// just do it, regardless if fails or not. /* just do it, regardless if fails or not. */
Make_Socket_NoBlocking( *ssdpReqSock ); Make_Socket_NoBlocking( *ssdpReqSock );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
@ -1064,18 +1053,18 @@ int create_ssdp_sock_reqv6( SOCKET* ssdpReqSock )
return UPNP_E_OUTOF_SOCKET; return UPNP_E_OUTOF_SOCKET;
} }
// MUST use scoping of IPv6 addresses to control the propagation os SSDP /* MUST use scoping of IPv6 addresses to control the propagation os SSDP
// messages instead of relying on the Hop Limit (Equivalent to the TTL * messages instead of relying on the Hop Limit (Equivalent to the TTL
// limit in IPv4). * limit in IPv4). */
setsockopt( *ssdpReqSock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, setsockopt( *ssdpReqSock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
&hops, sizeof(hops) ); &hops, sizeof(hops) );
// just do it, regardless if fails or not. /* just do it, regardless if fails or not. */
Make_Socket_NoBlocking( *ssdpReqSock ); Make_Socket_NoBlocking( *ssdpReqSock );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
#endif // IPv6 #endif /* IPv6 */
#endif /* INCLUDE_CLIENT_APIS */ #endif /* INCLUDE_CLIENT_APIS */
@ -1317,7 +1306,7 @@ int create_ssdp_sock_v6( SOCKET* ssdpSock )
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
#endif // IPv6 #endif /* IPv6 */
/************************************************************************ /************************************************************************
* Function : create_ssdp_sock_v6_ula_gua * Function : create_ssdp_sock_v6_ula_gua
@ -1429,7 +1418,7 @@ int create_ssdp_sock_v6_ula_gua(SOCKET *ssdpSock)
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
#endif //IPv6 #endif /* IPv6 */
#endif /* EXCLUDE_SSDP */ #endif /* EXCLUDE_SSDP */

View File

@ -120,15 +120,15 @@ calc_alias( IN const char *alias,
assert( rootPath ); assert( rootPath );
assert( alias ); assert( alias );
// add / suffix, if missing /* add / suffix, if missing */
root_len = strlen( rootPath ); root_len = strlen( rootPath );
if( root_len == 0 || rootPath[root_len - 1] != '/' ) { if( root_len == 0 || rootPath[root_len - 1] != '/' ) {
temp_str = "/"; temp_str = "/";
} else { } else {
temp_str = ""; // suffix already present temp_str = ""; /* suffix already present */
} }
// discard / prefix, if present /* discard / prefix, if present */
if( alias[0] == '/' ) { if( alias[0] == '/' ) {
aliasPtr = alias + 1; aliasPtr = alias + 1;
} else { } else {
@ -241,11 +241,11 @@ config_description_doc( INOUT IXML_Document * doc,
membuffer_init( &url_str ); membuffer_init( &url_str );
membuffer_init( &root_path ); membuffer_init( &root_path );
err_code = UPNP_E_OUTOF_MEMORY; // default error err_code = UPNP_E_OUTOF_MEMORY; /* default error */
baseList = ixmlDocument_getElementsByTagName( doc, urlBaseStr ); baseList = ixmlDocument_getElementsByTagName( doc, urlBaseStr );
if( baseList == NULL ) { if( baseList == NULL ) {
// urlbase not found -- create new one /* urlbase not found -- create new one */
addNew = TRUE; addNew = TRUE;
element = ixmlDocument_createElement( doc, urlBaseStr ); element = ixmlDocument_createElement( doc, urlBaseStr );
if( element == NULL ) { if( element == NULL ) {
@ -284,7 +284,7 @@ config_description_doc( INOUT IXML_Document * doc,
} }
} else { } else {
// urlbase found /* urlbase found */
urlbase_node = ixmlNodeList_item( baseList, 0 ); urlbase_node = ixmlNodeList_item( baseList, 0 );
assert( urlbase_node != NULL ); assert( urlbase_node != NULL );
@ -312,7 +312,7 @@ config_description_doc( INOUT IXML_Document * doc,
membuffer_append_str( &url_str, ip_str ) != 0 ) { membuffer_append_str( &url_str, ip_str ) != 0 ) {
goto error_handler; goto error_handler;
} }
// add leading '/' if missing from relative path /* add leading '/' if missing from relative path */
if( ( uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/' ) || if( ( uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/' ) ||
( uri.pathquery.size == 0 ) ( uri.pathquery.size == 0 )
) { ) {
@ -328,7 +328,7 @@ config_description_doc( INOUT IXML_Document * doc,
uri.pathquery.size ) != 0 ) { uri.pathquery.size ) != 0 ) {
goto error_handler; goto error_handler;
} }
// add trailing '/' if missing /* add trailing '/' if missing */
if( url_str.buf[url_str.length - 1] != '/' ) { if( url_str.buf[url_str.length - 1] != '/' ) {
if( membuffer_append( &url_str, "/", 1 ) != 0 ) { if( membuffer_append( &url_str, "/", 1 ) != 0 ) {
goto error_handler; goto error_handler;
@ -341,7 +341,7 @@ config_description_doc( INOUT IXML_Document * doc,
} }
} }
*root_path_str = membuffer_detach( &root_path ); // return path *root_path_str = membuffer_detach( &root_path ); /* return path */
err_code = UPNP_E_SUCCESS; err_code = UPNP_E_SUCCESS;
error_handler: error_handler:
@ -400,27 +400,27 @@ configure_urlbase( INOUT IXML_Document * doc,
int err_code; int err_code;
char ipaddr_port[LINE_SIZE]; char ipaddr_port[LINE_SIZE];
err_code = UPNP_E_OUTOF_MEMORY; // default error err_code = UPNP_E_OUTOF_MEMORY; /* default error */
// get IP address and port /* get IP address and port */
addrToString( serverAddr, ipaddr_port ); addrToString( serverAddr, ipaddr_port );
// config url-base in 'doc' /* config url-base in 'doc' */
err_code = config_description_doc( doc, ipaddr_port, &root_path ); err_code = config_description_doc( doc, ipaddr_port, &root_path );
if( err_code != UPNP_E_SUCCESS ) { if( err_code != UPNP_E_SUCCESS ) {
goto error_handler; goto error_handler;
} }
// calc alias /* calc alias */
err_code = calc_alias( alias, root_path, &new_alias ); err_code = calc_alias( alias, root_path, &new_alias );
if( err_code != UPNP_E_SUCCESS ) { if( err_code != UPNP_E_SUCCESS ) {
goto error_handler; goto error_handler;
} }
// calc full url for desc doc /* calc full url for desc doc */
err_code = calc_descURL( ipaddr_port, new_alias, docURL ); err_code = calc_descURL( ipaddr_port, new_alias, docURL );
if( err_code != UPNP_E_SUCCESS ) { if( err_code != UPNP_E_SUCCESS ) {
goto error_handler; goto error_handler;
} }
// xml doc to str /* xml doc to str */
xml_str = ixmlPrintDocument( doc ); xml_str = ixmlPrintDocument( doc );
if( xml_str == NULL ) { if( xml_str == NULL ) {
goto error_handler; goto error_handler;
@ -430,7 +430,7 @@ configure_urlbase( INOUT IXML_Document * doc,
"desc url: %s\n", docURL ); "desc url: %s\n", docURL );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"doc = %s\n", xml_str ); "doc = %s\n", xml_str );
// store in web server /* store in web server */
err_code = err_code =
web_server_set_alias( new_alias, xml_str, strlen( xml_str ), web_server_set_alias( new_alias, xml_str, strlen( xml_str ),
last_modified ); last_modified );

View File

@ -1,31 +1,28 @@
/* /*
** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc. * Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. & * Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
** Digital Equipment Corporation, Maynard, Mass. * Digital Equipment Corporation, Maynard, Mass.
** Copyright (c) 1998 Microsoft. * Copyright (c) 1998 Microsoft.
** To anyone who acknowledges that this file is provided "AS IS" * To anyone who acknowledges that this file is provided "AS IS"
** without any express or implied warranty: permission to use, copy, * without any express or implied warranty: permission to use, copy,
** modify, and distribute this file for any purpose is hereby * modify, and distribute this file for any purpose is hereby
** granted without fee, provided that the above copyright notices and * granted without fee, provided that the above copyright notices and
** this notice appears in all source code copies, and that none of * this notice appears in all source code copies, and that none of
** the names of Open Software Foundation, Inc., Hewlett-Packard * the names of Open Software Foundation, Inc., Hewlett-Packard
** Company, or Digital Equipment Corporation be used in advertising * Company, or Digital Equipment Corporation be used in advertising
** or publicity pertaining to distribution of the software without * or publicity pertaining to distribution of the software without
** specific, written prior permission. Neither Open Software * specific, written prior permission. Neither Open Software
** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment * Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment
** Corporation makes any representations about the suitability of * Corporation makes any representations about the suitability of
** this software for any purpose. * this software for any purpose.
*/ */
#include "config.h" #include "config.h"
#include "sysdep.h" #include "sysdep.h"
#include "UpnpInet.h" #include "UpnpInet.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -74,9 +71,9 @@ get_system_time( uuid_time_t * uuid_time )
+ 18 years and 5 leap days. + 18 years and 5 leap days.
*/ */
time.QuadPart += ( unsigned __int64 )( 1000 * 1000 * 10 ) // seconds time.QuadPart += ( unsigned __int64 )( 1000 * 1000 * 10 ) /* seconds */
* ( unsigned __int64 )( 60 * 60 * 24 ) // days * ( unsigned __int64 )( 60 * 60 * 24 ) /* days */
* ( unsigned __int64 )( 17 + 30 + 31 + 365 * 18 + 5 ); // # of days * ( unsigned __int64 )( 17 + 30 + 31 + 365 * 18 + 5 ); /* # of days */
*uuid_time = time.QuadPart; *uuid_time = time.QuadPart;
@ -146,7 +143,7 @@ get_random_info(unsigned char seed[16])
{ {
MD5_CTX c; MD5_CTX c;
typedef struct { typedef struct {
//struct sysinfo s; /*struct sysinfo s; */
struct timeval t; struct timeval t;
char hostname[257]; char hostname[257];
} randomness; } randomness;