upnp: fix for compiler warnings.

This commit is contained in:
Marcelo Roberto Jimenez 2010-11-18 14:57:11 -02:00
parent d8a27bca96
commit 9b3a0999a9
8 changed files with 235 additions and 272 deletions

View File

@ -282,7 +282,7 @@ void UpnpDisplayBanner(
/*! [in] Size of the buffer. */
size_t size,
/*! [in] This parameter provides the width of the banner. */
int starlength);
size_t starlength);
#else
static UPNP_INLINE void UpnpDisplayBanner(
FILE *fd,

View File

@ -229,51 +229,50 @@ void UpnpDisplayFileAndLine(
fflush(fd);
}
void UpnpDisplayBanner(
FILE * fd,
const char **lines,
size_t size,
int starLength)
size_t starLength)
{
int leftMarginLength = starLength / 2 + 1;
int rightMarginLength = starLength / 2 + 1;
int i = 0;
int LineSize = 0;
int starLengthMinus2 = starLength - 2;
size_t leftMarginLength = starLength / 2 + 1;
size_t rightMarginLength = starLength / 2 + 1;
size_t i = 0;
size_t LineSize = 0;
size_t starLengthMinus2 = starLength - 2;
char *leftMargin = ( char * )malloc( leftMarginLength );
char *rightMargin = ( char * )malloc( rightMarginLength );
char *stars = ( char * )malloc( starLength + 1 );
char *currentLine = ( char * )malloc( starLength + 1 );
char *leftMargin = malloc(leftMarginLength);
char *rightMargin = malloc(rightMarginLength);
char *stars = malloc(starLength + 1);
char *currentLine = malloc(starLength + 1);
const char *line = NULL;
memset( stars, '*', starLength );
memset(stars, '*', starLength);
stars[starLength] = 0;
memset( leftMargin, 0, leftMarginLength );
memset( rightMargin, 0, rightMarginLength );
fprintf( fd, "\n%s\n", stars );
for( i = 0; i < size; i++ ) {
LineSize = strlen( lines[i] );
memset(leftMargin, 0, leftMarginLength);
memset(rightMargin, 0, rightMarginLength);
fprintf(fd, "\n%s\n", stars);
for (i = 0; i < size; i++) {
LineSize = strlen(lines[i]);
line = lines[i];
while( LineSize > starLengthMinus2 ) {
memcpy( currentLine, line, starLengthMinus2 );
while (LineSize > starLengthMinus2) {
memcpy(currentLine, line, starLengthMinus2);
currentLine[starLengthMinus2] = 0;
fprintf( fd, "*%s*\n", currentLine );
fprintf(fd, "*%s*\n", currentLine);
LineSize -= starLengthMinus2;
line += starLengthMinus2;
}
leftMarginLength = (starLengthMinus2 - LineSize)/2;
if( LineSize % 2 == 0 ) {
leftMarginLength = (starLengthMinus2 - LineSize) / 2;
if (LineSize % 2 == 0) {
rightMarginLength = leftMarginLength;
} else {
rightMarginLength = leftMarginLength + 1;
}
memset( leftMargin, ' ', leftMarginLength );
memset( rightMargin, ' ', rightMarginLength );
memset(leftMargin, ' ', leftMarginLength);
memset(rightMargin, ' ', rightMarginLength);
leftMargin[leftMarginLength] = 0;
rightMargin[rightMarginLength] = 0;
fprintf( fd, "*%s%s%s*\n", leftMargin, line, rightMargin );
fprintf(fd, "*%s%s%s*\n", leftMargin, line, rightMargin);
}
fprintf(fd, "%s\n\n", stars);
@ -283,7 +282,6 @@ void UpnpDisplayBanner(
free(leftMargin);
}
void PrintThreadPoolStats(
ThreadPool *tp,
const char *DbgFileName,

View File

@ -119,10 +119,9 @@ struct ErrorString ErrorMessages[] = {
{UPNP_E_INTERNAL_ERROR, "UPNP_E_INTERNAL_ERROR"},
};
const char *UpnpGetErrorMessage(int rc)
{
int i;
size_t i;
for (i = 0; i < sizeof (ErrorMessages) / sizeof (ErrorMessages[0]); ++i) {
if (rc == ErrorMessages[i].rc) {
@ -133,7 +132,6 @@ const char *UpnpGetErrorMessage(int rc)
return "Unknown error code";
}
/*!
* \todo There is some unnecessary allocation and deallocation going on here
* because of the way resolve_rel_url() was originally written and used. In the

View File

@ -29,27 +29,22 @@
*
******************************************************************************/
/*
* \file
*
* \brief Contains functions for scanner and parser for http messages.
*/
#define _GNU_SOURCE /* For strcasestr() in string.h */
#include "config.h"
#include "strintmap.h"
#include "httpparser.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpdebug.h"
#include <assert.h>
#include <ctype.h>
#include <limits.h>
@ -57,58 +52,56 @@
#include <stdio.h>
#include <string.h>
/* entity positions */
#define NUM_HTTP_METHODS 9
static str_int_entry Http_Method_Table[NUM_HTTP_METHODS] = {
{"GET", HTTPMETHOD_GET},
{"HEAD", HTTPMETHOD_HEAD},
{"M-POST", HTTPMETHOD_MPOST},
{"M-SEARCH", HTTPMETHOD_MSEARCH},
{"NOTIFY", HTTPMETHOD_NOTIFY},
{"POST", HTTPMETHOD_POST},
{"SUBSCRIBE", HTTPMETHOD_SUBSCRIBE},
{"UNSUBSCRIBE", HTTPMETHOD_UNSUBSCRIBE},
{"POST", SOAPMETHOD_POST},
{"GET", HTTPMETHOD_GET},
{"HEAD", HTTPMETHOD_HEAD},
{"M-POST", HTTPMETHOD_MPOST},
{"M-SEARCH", HTTPMETHOD_MSEARCH},
{"NOTIFY", HTTPMETHOD_NOTIFY},
{"POST", HTTPMETHOD_POST},
{"SUBSCRIBE", HTTPMETHOD_SUBSCRIBE},
{"UNSUBSCRIBE", HTTPMETHOD_UNSUBSCRIBE},
{"POST", SOAPMETHOD_POST},
};
#define NUM_HTTP_HEADER_NAMES 33
str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES] = {
{"ACCEPT", HDR_ACCEPT},
{"ACCEPT-CHARSET", HDR_ACCEPT_CHARSET},
{"ACCEPT-ENCODING", HDR_ACCEPT_ENCODING},
{"ACCEPT-LANGUAGE", HDR_ACCEPT_LANGUAGE},
{"ACCEPT-RANGES", HDR_ACCEPT_RANGE},
{"CACHE-CONTROL", HDR_CACHE_CONTROL},
{"CALLBACK", HDR_CALLBACK},
{"CONTENT-ENCODING", HDR_CONTENT_ENCODING},
{"CONTENT-LANGUAGE", HDR_CONTENT_LANGUAGE},
{"CONTENT-LENGTH", HDR_CONTENT_LENGTH},
{"CONTENT-LOCATION", HDR_CONTENT_LOCATION},
{"CONTENT-RANGE", HDR_CONTENT_RANGE},
{"CONTENT-TYPE", HDR_CONTENT_TYPE},
{"DATE", HDR_DATE},
{"EXT", HDR_EXT},
{"HOST", HDR_HOST},
{"IF-RANGE", HDR_IF_RANGE},
{"LOCATION", HDR_LOCATION},
{"MAN", HDR_MAN},
{"MX", HDR_MX},
{"NT", HDR_NT},
{"NTS", HDR_NTS},
{"RANGE", HDR_RANGE},
{"SEQ", HDR_SEQ},
{"SERVER", HDR_SERVER},
{"SID", HDR_SID},
{"SOAPACTION", HDR_SOAPACTION},
{"ST", HDR_ST},
{"TE", HDR_TE},
{"TIMEOUT", HDR_TIMEOUT},
{"TRANSFER-ENCODING", HDR_TRANSFER_ENCODING},
{"USER-AGENT", HDR_USER_AGENT},
{"USN", HDR_USN}
{"ACCEPT", HDR_ACCEPT},
{"ACCEPT-CHARSET", HDR_ACCEPT_CHARSET},
{"ACCEPT-ENCODING", HDR_ACCEPT_ENCODING},
{"ACCEPT-LANGUAGE", HDR_ACCEPT_LANGUAGE},
{"ACCEPT-RANGES", HDR_ACCEPT_RANGE},
{"CACHE-CONTROL", HDR_CACHE_CONTROL},
{"CALLBACK", HDR_CALLBACK},
{"CONTENT-ENCODING", HDR_CONTENT_ENCODING},
{"CONTENT-LANGUAGE", HDR_CONTENT_LANGUAGE},
{"CONTENT-LENGTH", HDR_CONTENT_LENGTH},
{"CONTENT-LOCATION", HDR_CONTENT_LOCATION},
{"CONTENT-RANGE", HDR_CONTENT_RANGE},
{"CONTENT-TYPE", HDR_CONTENT_TYPE},
{"DATE", HDR_DATE},
{"EXT", HDR_EXT},
{"HOST", HDR_HOST},
{"IF-RANGE", HDR_IF_RANGE},
{"LOCATION", HDR_LOCATION},
{"MAN", HDR_MAN},
{"MX", HDR_MX},
{"NT", HDR_NT},
{"NTS", HDR_NTS},
{"RANGE", HDR_RANGE},
{"SEQ", HDR_SEQ},
{"SERVER", HDR_SERVER},
{"SID", HDR_SID},
{"SOAPACTION", HDR_SOAPACTION},
{"ST", HDR_ST},
{"TE", HDR_TE},
{"TIMEOUT", HDR_TIMEOUT},
{"TRANSFER-ENCODING", HDR_TRANSFER_ENCODING},
{"USER-AGENT", HDR_USER_AGENT},
{"USN", HDR_USN},
};
/***********************************************************************/

View File

@ -705,7 +705,7 @@ char *resolve_rel_url(char *base_url, char *rel_url)
}
int parse_uri(const char *in, int max, uri_type *out)
int parse_uri(const char *in, size_t max, uri_type *out)
{
int begin_path = 0;
int begin_hostport = 0;

View File

@ -39,7 +39,7 @@
typedef struct /* str_int_entry */
{
char *name; /* a value in string form */
const char *name; /* a value in string form */
int id; /* same value in integer form */
} str_int_entry;

View File

@ -372,7 +372,7 @@ int parse_uri(
/*! [in] Character string containing uri information to be parsed. */
const char *in,
/*! [in] Maximum limit on the number of characters. */
int max,
size_t max,
/*! [out] Output parameter which will have the parsed uri information. */
uri_type *out);

View File

@ -106,47 +106,41 @@ addrToString( IN const struct sockaddr *addr,
*
* Note : 'newAlias' should be freed using free()
************************************************************************/
static UPNP_INLINE int
calc_alias( IN const char *alias,
IN const char *rootPath,
OUT char **newAlias )
static UPNP_INLINE int calc_alias(
IN const char *alias,
IN const char *rootPath,
OUT char **newAlias)
{
const char *aliasPtr;
size_t root_len;
char *temp_str;
size_t new_alias_len;
char *alias_temp;
const char *aliasPtr;
size_t root_len;
const char *temp_str;
size_t new_alias_len;
char *alias_temp;
assert( rootPath );
assert( alias );
assert(rootPath);
assert(alias);
/* add / suffix, if missing */
root_len = strlen( rootPath );
if( root_len == 0 || rootPath[root_len - 1] != '/' ) {
temp_str = "/";
} else {
temp_str = ""; /* suffix already present */
}
/* add / suffix, if missing */
root_len = strlen(rootPath);
if (root_len == 0 || rootPath[root_len - 1] != '/')
temp_str = "/";
else
temp_str = ""; /* suffix already present */
/* discard / prefix, if present */
if (alias[0] == '/')
aliasPtr = alias + 1;
else
aliasPtr = alias;
new_alias_len = root_len + strlen(temp_str) + strlen(aliasPtr);
alias_temp = malloc(new_alias_len + 1);
if (alias_temp == NULL)
return UPNP_E_OUTOF_MEMORY;
strcpy(alias_temp, rootPath);
strcat(alias_temp, temp_str);
strcat(alias_temp, aliasPtr);
/* discard / prefix, if present */
if( alias[0] == '/' ) {
aliasPtr = alias + 1;
} else {
aliasPtr = alias;
}
new_alias_len = root_len + strlen( temp_str ) + strlen( aliasPtr );
alias_temp = ( char * )malloc( new_alias_len + 1 );
if( alias_temp == NULL ) {
return UPNP_E_OUTOF_MEMORY;
}
strcpy( alias_temp, rootPath );
strcat( alias_temp, temp_str );
strcat( alias_temp, aliasPtr );
*newAlias = alias_temp;
return UPNP_E_SUCCESS;
*newAlias = alias_temp;
return UPNP_E_SUCCESS;
}
/************************************************************************
@ -167,30 +161,27 @@ calc_alias( IN const char *alias,
*
* Note :
************************************************************************/
static UPNP_INLINE int
calc_descURL( IN const char *ipPortStr,
IN const char *alias,
OUT char descURL[LINE_SIZE] )
static UPNP_INLINE int calc_descURL(
IN const char *ipPortStr,
IN const char *alias,
OUT char descURL[LINE_SIZE])
{
size_t len;
const char *http_scheme = "http://";
size_t len;
const char *http_scheme = "http://";
assert( ipPortStr != NULL && strlen( ipPortStr ) > 0 );
assert( alias != NULL && strlen( alias ) > 0 );
assert(ipPortStr != NULL && strlen(ipPortStr) > 0);
assert(alias != NULL && strlen(alias) > 0);
len = strlen( http_scheme ) + strlen( ipPortStr ) + strlen( alias );
len = strlen(http_scheme) + strlen(ipPortStr) + strlen(alias);
if (len > (LINE_SIZE - 1))
return UPNP_E_URL_TOO_BIG;
strcpy(descURL, http_scheme);
strcat(descURL, ipPortStr);
strcat(descURL, alias);
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"desc url: %s\n", descURL);
if( len > ( LINE_SIZE - 1 ) ) {
return UPNP_E_URL_TOO_BIG;
}
strcpy( descURL, http_scheme );
strcat( descURL, ipPortStr );
strcat( descURL, alias );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"desc url: %s\n", descURL );
return UPNP_E_SUCCESS;
return UPNP_E_SUCCESS;
}
/************************************************************************
@ -218,143 +209,126 @@ calc_descURL( IN const char *ipPortStr,
*
* Note :
************************************************************************/
static int
config_description_doc( INOUT IXML_Document * doc,
IN const char *ip_str,
OUT char **root_path_str )
static int config_description_doc(
INOUT IXML_Document *doc,
IN const char *ip_str,
OUT char **root_path_str )
{
xboolean addNew = FALSE;
IXML_NodeList *baseList;
IXML_Element *element = NULL;
IXML_Element *newElement = NULL;
IXML_Node *textNode = NULL;
IXML_Node *rootNode = NULL;
IXML_Node *urlbase_node = NULL;
char *urlBaseStr = "URLBase";
const DOMString domStr = NULL;
uri_type uri;
int err_code;
int len;
membuffer url_str;
membuffer root_path;
xboolean addNew = FALSE;
IXML_NodeList *baseList;
IXML_Element *element = NULL;
IXML_Element *newElement = NULL;
IXML_Node *textNode = NULL;
IXML_Node *rootNode = NULL;
IXML_Node *urlbase_node = NULL;
const char *urlBaseStr = "URLBase";
const DOMString domStr = NULL;
uri_type uri;
int err_code;
int len;
membuffer url_str;
membuffer root_path;
membuffer_init( &url_str );
membuffer_init( &root_path );
membuffer_init(&url_str);
membuffer_init(&root_path);
err_code = UPNP_E_OUTOF_MEMORY; /* default error */
baseList = ixmlDocument_getElementsByTagName(doc, urlBaseStr);
if (baseList == NULL) {
/* urlbase not found -- create new one */
addNew = TRUE;
element = ixmlDocument_createElement(doc, urlBaseStr);
if (element == NULL) {
goto error_handler;
}
if (membuffer_append_str(&url_str, "http://") != 0 ||
membuffer_append_str(&url_str, ip_str) != 0 ||
membuffer_append_str(&url_str, "/") != 0 ||
membuffer_append_str(&root_path, "/") != 0) {
goto error_handler;
}
rootNode = ixmlNode_getFirstChild((IXML_Node *) doc);
if (rootNode == NULL) {
err_code = UPNP_E_INVALID_DESC;
goto error_handler;
}
err_code =
ixmlNode_appendChild(rootNode, (IXML_Node *) element);
if (err_code != IXML_SUCCESS) {
goto error_handler;
}
textNode =
ixmlDocument_createTextNode(doc, (char *)url_str.buf);
if (textNode == NULL) {
goto error_handler;
}
err_code =
ixmlNode_appendChild((IXML_Node *) element, textNode);
if (err_code != IXML_SUCCESS) {
goto error_handler;
}
} else {
/* urlbase found */
urlbase_node = ixmlNodeList_item(baseList, 0);
assert(urlbase_node != NULL);
textNode = ixmlNode_getFirstChild(urlbase_node);
if (textNode == NULL) {
err_code = UPNP_E_INVALID_DESC;
goto error_handler;
}
domStr = ixmlNode_getNodeValue(textNode);
if (domStr == NULL) {
err_code = UPNP_E_INVALID_URL;
goto error_handler;
}
len = parse_uri(domStr, strlen(domStr), &uri);
if (len < 0 || uri.type != ABSOLUTE) {
err_code = UPNP_E_INVALID_URL;
goto error_handler;
}
if (membuffer_assign(&url_str, uri.scheme.buff,
uri.scheme.size) != 0 ||
membuffer_append_str(&url_str, "://") != 0 ||
membuffer_append_str(&url_str, ip_str) != 0) {
goto error_handler;
}
/* add leading '/' if missing from relative path */
if ((uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/') ||
(uri.pathquery.size == 0)
) {
if (membuffer_append_str(&url_str, "/") != 0 ||
membuffer_append_str(&root_path, "/") != 0) {
goto error_handler;
}
}
if (membuffer_append(&url_str, uri.pathquery.buff,
uri.pathquery.size) != 0 ||
membuffer_append(&root_path, uri.pathquery.buff,
uri.pathquery.size) != 0) {
goto error_handler;
}
/* add trailing '/' if missing */
if (url_str.buf[url_str.length - 1] != '/') {
if (membuffer_append(&url_str, "/", 1) != 0) {
goto error_handler;
}
}
err_code = ixmlNode_setNodeValue(textNode, url_str.buf);
if (err_code != IXML_SUCCESS) {
goto error_handler;
}
}
*root_path_str = membuffer_detach(&root_path); /* return path */
err_code = UPNP_E_SUCCESS;
err_code = UPNP_E_OUTOF_MEMORY; /* default error */
error_handler:
if (err_code != UPNP_E_SUCCESS) {
ixmlElement_free(newElement);
}
ixmlNodeList_free(baseList);
membuffer_destroy(&root_path);
membuffer_destroy(&url_str);
baseList = ixmlDocument_getElementsByTagName( doc, urlBaseStr );
if( baseList == NULL ) {
/* urlbase not found -- create new one */
addNew = TRUE;
element = ixmlDocument_createElement( doc, urlBaseStr );
if( element == NULL ) {
goto error_handler;
}
if( membuffer_append_str( &url_str, "http://" ) != 0 ||
membuffer_append_str( &url_str, ip_str ) != 0 ||
membuffer_append_str( &url_str, "/" ) != 0 ||
membuffer_append_str( &root_path, "/" ) != 0 ) {
goto error_handler;
}
rootNode = ixmlNode_getFirstChild( ( IXML_Node * ) doc );
if( rootNode == NULL ) {
err_code = UPNP_E_INVALID_DESC;
goto error_handler;
}
err_code =
ixmlNode_appendChild( rootNode, ( IXML_Node * ) element );
if( err_code != IXML_SUCCESS ) {
goto error_handler;
}
textNode =
ixmlDocument_createTextNode( doc, ( char * )url_str.buf );
if( textNode == NULL ) {
goto error_handler;
}
err_code =
ixmlNode_appendChild( ( IXML_Node * ) element, textNode );
if( err_code != IXML_SUCCESS ) {
goto error_handler;
}
} else {
/* urlbase found */
urlbase_node = ixmlNodeList_item( baseList, 0 );
assert( urlbase_node != NULL );
textNode = ixmlNode_getFirstChild( urlbase_node );
if( textNode == NULL ) {
err_code = UPNP_E_INVALID_DESC;
goto error_handler;
}
domStr = ixmlNode_getNodeValue( textNode );
if( domStr == NULL ) {
err_code = UPNP_E_INVALID_URL;
goto error_handler;
}
len = parse_uri( domStr, strlen( domStr ), &uri );
if( len < 0 || uri.type != ABSOLUTE ) {
err_code = UPNP_E_INVALID_URL;
goto error_handler;
}
if( membuffer_assign( &url_str, uri.scheme.buff,
uri.scheme.size ) != 0 ||
membuffer_append_str( &url_str, "://" ) != 0 ||
membuffer_append_str( &url_str, ip_str ) != 0 ) {
goto error_handler;
}
/* add leading '/' if missing from relative path */
if( ( uri.pathquery.size > 0 && uri.pathquery.buff[0] != '/' ) ||
( uri.pathquery.size == 0 )
) {
if( membuffer_append_str( &url_str, "/" ) != 0 ||
membuffer_append_str( &root_path, "/" ) != 0 ) {
goto error_handler;
}
}
if( membuffer_append( &url_str, uri.pathquery.buff,
uri.pathquery.size ) != 0 ||
membuffer_append( &root_path, uri.pathquery.buff,
uri.pathquery.size ) != 0 ) {
goto error_handler;
}
/* add trailing '/' if missing */
if( url_str.buf[url_str.length - 1] != '/' ) {
if( membuffer_append( &url_str, "/", 1 ) != 0 ) {
goto error_handler;
}
}
err_code = ixmlNode_setNodeValue( textNode, url_str.buf );
if( err_code != IXML_SUCCESS ) {
goto error_handler;
}
}
*root_path_str = membuffer_detach( &root_path ); /* return path */
err_code = UPNP_E_SUCCESS;
error_handler:
if( err_code != UPNP_E_SUCCESS ) {
ixmlElement_free( newElement );
}
ixmlNodeList_free( baseList );
membuffer_destroy( &root_path );
membuffer_destroy( &url_str );
return err_code;
return err_code;
}
/************************************************************************