Remove more implicit casts in upnp part

Remove more "implicit integer or enum conversions" errors as well as
dead code.

(forward port of commit c40d2bc0c9)
This commit is contained in:
Fabrice Fontaine 2012-03-11 00:25:16 +01:00 committed by Marcelo Roberto Jimenez
parent 12b88a9fbf
commit 46da1738b9
8 changed files with 152 additions and 125 deletions

View File

@ -318,6 +318,13 @@ Version 1.8.0
Version 1.6.16
*******************************************************************************
2012-03-11 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Remove more implicit casts in upnp part
Remove more "implicit integer or enum conversions" errors as well as
dead code.
2012-03-11 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Remove more implicit casts in upnp part

View File

@ -77,7 +77,7 @@ struct SUpnpString
UpnpString *UpnpString_new()
{
/* All bytes are zero, and so is the length of the string. */
struct SUpnpString *p = calloc(1, sizeof (struct SUpnpString));
struct SUpnpString *p = calloc((size_t)1, sizeof (struct SUpnpString));
if (p == NULL) {
goto error_handler1;
}
@ -86,7 +86,7 @@ UpnpString *UpnpString_new()
#endif
/* This byte is zero, calloc does initialize it. */
p->m_string = calloc(1, 1);
p->m_string = calloc((size_t)1, (size_t)1);
if (p->m_string == NULL) {
goto error_handler2;
}
@ -106,7 +106,7 @@ void UpnpString_delete(UpnpString *p)
if (!q) return;
q->m_length = 0;
q->m_length = (size_t)0;
free(q->m_string);
q->m_string = NULL;
@ -116,7 +116,7 @@ void UpnpString_delete(UpnpString *p)
UpnpString *UpnpString_dup(const UpnpString *p)
{
struct SUpnpString *q = calloc(1, sizeof (struct SUpnpString));
struct SUpnpString *q = calloc((size_t)1, sizeof (struct SUpnpString));
if (q == NULL) {
goto error_handler1;
}
@ -187,7 +187,7 @@ error_handler1:
void UpnpString_clear(UpnpString *p)
{
((struct SUpnpString *)p)->m_length = 0;
((struct SUpnpString *)p)->m_length = (size_t)0;
/* No need to realloc now, will do later when needed. */
((struct SUpnpString *)p)->m_string[0] = 0;
}

View File

@ -452,7 +452,7 @@ int UpnpInit(const char *HostIP, unsigned short DestPort)
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"UpnpInit with HostIP=%s, DestPort=%d.\n",
HostIP ? HostIP : "", DestPort);
HostIP ? HostIP : "", (int)DestPort);
/* Verify HostIP, if provided, or find it ourselves. */
memset(gIF_IPV4, 0, sizeof(gIF_IPV4));
@ -477,7 +477,7 @@ int UpnpInit(const char *HostIP, unsigned short DestPort)
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"Host Ip: %s Host Port: %d\n", gIF_IPV4,
LOCAL_PORT_V4);
(int)LOCAL_PORT_V4);
exit_function:
ithread_mutex_unlock(&gSDKInitMutex);
@ -686,7 +686,7 @@ int UpnpFinish(void)
unsigned short UpnpGetServerPort(void)
{
if (UpnpSdkInit != 1)
return 0;
return 0u;
return LOCAL_PORT_V4;
}
@ -695,7 +695,7 @@ unsigned short UpnpGetServerPort(void)
unsigned short UpnpGetServerPort6(void)
{
if (UpnpSdkInit != 1)
return 0;
return 0u;
return LOCAL_PORT_V6;
}
@ -800,7 +800,7 @@ int UpnpRegisterRootDevice(
if (Hnd == NULL ||
Fun == NULL ||
DescUrl == NULL ||
strlen(DescUrl) == 0) {
strlen(DescUrl) == (size_t)0) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
@ -1124,7 +1124,7 @@ int UpnpRegisterRootDevice4(
if (Hnd == NULL ||
Fun == NULL ||
DescUrl == NULL ||
strlen(DescUrl) == 0 ||
strlen(DescUrl) == (size_t)0 ||
(AddressFamily != AF_INET && AddressFamily != AF_INET6)) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
@ -1514,15 +1514,16 @@ static int GetDescDocumentAndURL(
if (description == NULL)
return UPNP_E_INVALID_PARAM;
/* non-URL description must have configuration specified */
if (descriptionType != UPNPREG_URL_DESC && !config_baseURL)
if (descriptionType != (enum Upnp_DescType_e)UPNPREG_URL_DESC &&
!config_baseURL)
return UPNP_E_INVALID_PARAM;
/* Get XML doc and last modified time */
if (descriptionType == UPNPREG_URL_DESC) {
if (descriptionType == (enum Upnp_DescType_e)UPNPREG_URL_DESC) {
retVal = UpnpDownloadXmlDoc(description, xmlDoc);
if (retVal != UPNP_E_SUCCESS)
return retVal;
last_modified = time(NULL);
} else if (descriptionType == UPNPREG_FILENAME_DESC) {
} else if (descriptionType == (enum Upnp_DescType_e)UPNPREG_FILENAME_DESC) {
retVal = stat(description, &file_info);
if (retVal == -1)
return UPNP_E_FILE_NOT_FOUND;
@ -1531,12 +1532,12 @@ static int GetDescDocumentAndURL(
fp = fopen(description, "rb");
if (fp == NULL)
return UPNP_E_FILE_NOT_FOUND;
membuf = (char *)malloc(fileLen + 1);
membuf = (char *)malloc(fileLen + (size_t)1);
if (membuf == NULL) {
fclose(fp);
return UPNP_E_OUTOF_MEMORY;
}
num_read = fread(membuf, 1, fileLen, fp);
num_read = fread(membuf, (size_t)1, fileLen, fp);
if (num_read != fileLen) {
fclose(fp);
free(membuf);
@ -1546,14 +1547,15 @@ static int GetDescDocumentAndURL(
fclose(fp);
rc = ixmlParseBufferEx(membuf, xmlDoc);
free(membuf);
} else if (descriptionType == UPNPREG_BUF_DESC) {
} else if (descriptionType == (enum Upnp_DescType_e)UPNPREG_BUF_DESC) {
last_modified = time(NULL);
rc = ixmlParseBufferEx(description, xmlDoc);
} else {
return UPNP_E_INVALID_PARAM;
}
if (rc != IXML_SUCCESS && descriptionType != UPNPREG_URL_DESC) {
if (rc != IXML_SUCCESS &&
descriptionType != (enum Upnp_DescType_e)UPNPREG_URL_DESC) {
if (rc == IXML_INSUFFICIENT_MEMORY)
return UPNP_E_OUTOF_MEMORY;
else
@ -1561,7 +1563,7 @@ static int GetDescDocumentAndURL(
}
/* Determine alias */
if (config_baseURL) {
if (descriptionType == UPNPREG_BUF_DESC) {
if (descriptionType == (enum Upnp_DescType_e)UPNPREG_BUF_DESC) {
strncpy(aliasStr, "description.xml",
sizeof(aliasStr) - 1);
} else {
@ -1619,7 +1621,8 @@ static int GetDescDocumentAndURL(
{
int retVal = 0;
if (descriptionType != UPNPREG_URL_DESC || config_baseURL) {
if (descriptionType != (enum Upnp_DescType_e)UPNPREG_URL_DESC ||
config_baseURL) {
return UPNP_E_NO_WEB_SERVER;
}
@ -1627,7 +1630,7 @@ static int GetDescDocumentAndURL(
return UPNP_E_INVALID_PARAM;
}
if (strlen(description) > LINE_SIZE - 1) {
if (strlen(description) > LINE_SIZE - (size_t)1) {
return UPNP_E_URL_TOO_BIG;
}
strncpy(descURL, description, LINE_SIZE - 1);
@ -3442,7 +3445,7 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INIT;
}
/* Get the interface configuration information... */
ifConf.ifc_len = sizeof szBuffer;
ifConf.ifc_len = (int)sizeof szBuffer;
ifConf.ifc_ifcu.ifcu_buf = (caddr_t) szBuffer;
if (ioctl(LocalSock, SIOCGIFCONF, &ifConf) < 0) {
@ -3452,7 +3455,7 @@ int UpnpGetIfInfo(const char *IfName)
return UPNP_E_INIT;
}
/* Cycle through the list of interfaces looking for IP addresses. */
for (i = 0; i < (size_t)ifConf.ifc_len;) {
for (i = (size_t)0; i < (size_t)ifConf.ifc_len;) {
struct ifreq *pifReq =
(struct ifreq *)((caddr_t) ifConf.ifc_req + i);
i += sizeof *pifReq;
@ -3535,7 +3538,7 @@ int UpnpGetIfInfo(const char *IfName)
(gIF_IPV6_ULA_GUA) - 1);
} else if (IN6_IS_ADDR_GLOBAL(&v6_addr)
&& strlen(gIF_IPV6_ULA_GUA)
== 0) {
== (size_t)0) {
/* got a GUA, should store it while no ULA is found */
memset(gIF_IPV6_ULA_GUA, 0,
sizeof(gIF_IPV6_ULA_GUA));
@ -3544,7 +3547,7 @@ int UpnpGetIfInfo(const char *IfName)
(gIF_IPV6_ULA_GUA) - 1);
} else
if (IN6_IS_ADDR_LINKLOCAL(&v6_addr)
&& strlen(gIF_IPV6) == 0) {
&& strlen(gIF_IPV6) == (size_t)0) {
/* got a Link local IPv6 address. */
memset(gIF_IPV6, 0,
sizeof(gIF_IPV6));
@ -3875,7 +3878,7 @@ int getlocalhostname(char *out, size_t out_len)
return UPNP_E_INIT;
}
/* Get the interface configuration information... */
ifConf.ifc_len = sizeof szBuffer;
ifConf.ifc_len = (int)sizeof szBuffer;
ifConf.ifc_ifcu.ifcu_buf = (caddr_t) szBuffer;
nResult = ioctl(LocalSock, SIOCGIFCONF, &ifConf);
if (nResult < 0) {
@ -3886,7 +3889,7 @@ int getlocalhostname(char *out, size_t out_len)
}
/* Cycle through the list of interfaces looking for IP addresses. */
for (i = 0; i < (long unsigned int)ifConf.ifc_len && j < DEFAULT_INTERFACE; ) {
for (i = 0lu; i < (long unsigned int)ifConf.ifc_len && j < DEFAULT_INTERFACE; ) {
struct ifreq *pifReq =
(struct ifreq *)((caddr_t)ifConf.ifc_req + i);
i += sizeof *pifReq;
@ -3979,7 +3982,7 @@ int UpnpAddVirtualDir(const char *newDirName)
return UPNP_E_FINISH;
}
if( ( newDirName == NULL ) || ( strlen( newDirName ) == 0 ) ) {
if( ( newDirName == NULL ) || ( strlen( newDirName ) == ( size_t ) 0 ) ) {
return UPNP_E_INVALID_PARAM;
}
@ -4142,7 +4145,7 @@ int UpnpIsWebserverEnabled(void)
return 0;
}
return bWebServerState == WEB_SERVER_ENABLED;
return bWebServerState == (WebServerState)WEB_SERVER_ENABLED;
}

View File

@ -129,7 +129,7 @@ str_int_entry Http_Header_Names[NUM_HTTP_HEADER_NAMES] = {
************************************************************************/
static UPNP_INLINE void scanner_init(OUT scanner_t *scanner, IN membuffer *bufptr)
{
scanner->cursor = 0;
scanner->cursor = (size_t)0;
scanner->msg = bufptr;
scanner->entire_msg_loaded = FALSE;
}
@ -145,7 +145,7 @@ static UPNP_INLINE void scanner_init(OUT scanner_t *scanner, IN membuffer *bufpt
************************************************************************/
static UPNP_INLINE int is_separator_char(IN char c)
{
return strchr(" \t()<>@,;:\\\"/[]?={}", c) != NULL;
return strchr(" \t()<>@,;:\\\"/[]?={}", (int)c) != NULL;
}
/************************************************************************
@ -251,7 +251,7 @@ static parse_status_t scanner_get_token(
/* possibly more valid chars */
return PARSE_INCOMPLETE;
/* calc token length */
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == ' ' || c == '\t') {
token->buf = cursor++;
token_type = TT_WHITESPACE;
@ -260,7 +260,7 @@ static parse_status_t scanner_get_token(
if (!scanner->entire_msg_loaded && cursor == null_terminator)
/* possibly more chars */
return PARSE_INCOMPLETE;
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == TOKCHAR_CR) {
/* scan CRLF */
token->buf = cursor++;
@ -270,16 +270,16 @@ static parse_status_t scanner_get_token(
if (*cursor != TOKCHAR_LF) {
/* couldn't match CRLF; match as CR */
token_type = TT_CTRL; /* ctrl char */
token->length = 1;
token->length = (size_t)1;
} else {
/* got CRLF */
token->length = 2;
token->length = (size_t)2;
token_type = TT_CRLF;
cursor++;
}
} else if (c == TOKCHAR_LF) { /* accept \n as CRLF */
token->buf = cursor++;
token->length = 1;
token->length = (size_t)1;
token_type = TT_CRLF;
} else if (c == '"') {
/* quoted text */
@ -306,7 +306,7 @@ static parse_status_t scanner_get_token(
return PARSE_FAILURE;
}
if (got_end_quote)
token->length = (size_t)(cursor - token->buf);
token->length = (size_t)cursor - (size_t)token->buf;
else { /* incomplete */
assert(cursor == null_terminator);
@ -316,12 +316,12 @@ static parse_status_t scanner_get_token(
/* scan separator */
token->buf = cursor++;
token_type = TT_SEPARATOR;
token->length = 1;
token->length = (size_t)1;
} else if (is_control_char(c)) {
/* scan ctrl char */
token->buf = cursor++;
token_type = TT_CTRL;
token->length = 1;
token->length = (size_t)1;
} else
return PARSE_FAILURE;
@ -408,7 +408,7 @@ void httpmsg_init(INOUT http_message_t *msg)
{
msg->initialized = 1;
msg->entity.buf = NULL;
msg->entity.length = 0;
msg->entity.length = ( size_t ) 0;
ListInit( &msg->headers, httpmsg_compare, httpheader_free );
membuffer_init( &msg->msg );
membuffer_init( &msg->status_msg );
@ -536,7 +536,8 @@ static UPNP_INLINE parse_status_t skip_blank_lines(INOUT scanner_t *scanner)
do {
status = scanner_get_token(scanner, &token, &tok_type);
} while (status == (parse_status_t)PARSE_OK &&
(tok_type == TT_WHITESPACE || tok_type == TT_CRLF));
(tok_type == (token_type_t)TT_WHITESPACE ||
tok_type == (token_type_t)TT_CRLF));
if (status == (parse_status_t)PARSE_OK) {
/* pushback a non-whitespace token */
scanner->cursor -= token.length;
@ -575,13 +576,13 @@ static UPNP_INLINE parse_status_t skip_lws(INOUT scanner_t *scanner)
/* get CRLF or WS */
status = scanner_get_token( scanner, &token, &tok_type );
if( status == ( parse_status_t ) PARSE_OK ) {
if( tok_type == TT_CRLF ) {
if( tok_type == ( token_type_t ) TT_CRLF ) {
/* get WS */
status = scanner_get_token( scanner, &token, &tok_type );
}
if( status == ( parse_status_t ) PARSE_OK &&
tok_type == TT_WHITESPACE ) {
tok_type == ( token_type_t ) TT_WHITESPACE ) {
matched = TRUE;
} else {
/* did not match LWS; pushback token(s) */
@ -628,13 +629,14 @@ static UPNP_INLINE parse_status_t match_non_ws_string(
save_cursor = scanner->cursor;
str->length = 0;
str->length = ( size_t ) 0;
str->buf = scanner_get_str( scanner ); /* point to next char in input */
while( !done ) {
status = scanner_get_token( scanner, &token, &tok_type );
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != TT_WHITESPACE && tok_type != TT_CRLF ) {
tok_type != ( token_type_t ) TT_WHITESPACE &&
tok_type != ( token_type_t ) TT_CRLF ) {
/* append non-ws token */
str->length += token.length;
} else {
@ -648,9 +650,10 @@ static UPNP_INLINE parse_status_t match_non_ws_string(
}
/* tolerate 'incomplete' msg */
if( status == ( parse_status_t ) PARSE_OK ||
( status == ( parse_status_t ) PARSE_INCOMPLETE && scanner->entire_msg_loaded )
( status == ( parse_status_t ) PARSE_INCOMPLETE &&
scanner->entire_msg_loaded )
) {
if( str->length == 0 ) {
if( str->length == ( size_t ) 0 ) {
/* no strings found */
return PARSE_NO_MATCH;
} else {
@ -691,7 +694,7 @@ static UPNP_INLINE parse_status_t match_raw_value(
parse_status_t status;
int done = FALSE;
int saw_crlf = FALSE;
size_t pos_at_crlf = 0;
size_t pos_at_crlf = ( size_t ) 0;
size_t save_pos;
char c;
@ -699,13 +702,13 @@ static UPNP_INLINE parse_status_t match_raw_value(
/* value points to start of input */
raw_value->buf = scanner_get_str( scanner );
raw_value->length = 0;
raw_value->length = ( size_t ) 0;
while( !done ) {
status = scanner_get_token( scanner, &token, &tok_type );
if( status == ( parse_status_t ) PARSE_OK ) {
if( !saw_crlf ) {
if( tok_type == TT_CRLF ) {
if( tok_type == ( token_type_t ) TT_CRLF ) {
/* CRLF could end value */
saw_crlf = TRUE;
@ -716,7 +719,7 @@ static UPNP_INLINE parse_status_t match_raw_value(
raw_value->length += token.length;
} else /* already seen CRLF */
{
if( tok_type == TT_WHITESPACE ) {
if( tok_type == ( token_type_t ) TT_WHITESPACE ) {
/* start again; forget CRLF */
saw_crlf = FALSE;
raw_value->length += token.length;
@ -737,9 +740,9 @@ static UPNP_INLINE parse_status_t match_raw_value(
if( status == ( parse_status_t ) PARSE_OK ) {
/* trim whitespace on right side of value */
while( raw_value->length > 0 ) {
while( raw_value->length > ( size_t ) 0 ) {
/* get last char */
c = raw_value->buf[raw_value->length - 1];
c = raw_value->buf[raw_value->length - ( size_t ) 1];
if( c != ' ' && c != '\t' &&
c != TOKCHAR_CR && c != TOKCHAR_LF ) {
@ -788,7 +791,7 @@ static UPNP_INLINE parse_status_t match_int(
save_pos = scanner->cursor;
status = scanner_get_token(scanner, &token, &tok_type);
if (status == (parse_status_t)PARSE_OK) {
if (tok_type == TT_IDENTIFIER) {
if (tok_type == (token_type_t)TT_IDENTIFIER) {
errno = 0;
num = strtol(token.buf, &end_ptr, base);
/* all and only those chars in token should be used for num */
@ -842,7 +845,8 @@ read_until_crlf( INOUT scanner_t * scanner,
/* read until we hit a crlf */
do {
status = scanner_get_token( scanner, &token, &tok_type );
} while( status == ( parse_status_t ) PARSE_OK && tok_type != TT_CRLF );
} while( status == ( parse_status_t ) PARSE_OK &&
tok_type != ( token_type_t ) TT_CRLF );
if( status == ( parse_status_t ) PARSE_OK ) {
/* pushback crlf in stream */
@ -975,8 +979,8 @@ static parse_status_t vfmatch(
save_pos = scanner->cursor;
status = PARSE_OK;
while( ( ( c = *fmt_ptr++ ) != 0 ) && ( status == PARSE_OK )
) {
while( ( ( c = *fmt_ptr++ ) != 0 ) &&
( status == ( parse_status_t ) PARSE_OK ) ) {
if( c == '%' ) {
c = *fmt_ptr++;
switch ( c ) {
@ -991,7 +995,7 @@ static parse_status_t vfmatch(
status = scanner_get_token( scanner, str_ptr,
&tok_type );
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != TT_IDENTIFIER ) {
tok_type != ( token_type_t ) TT_IDENTIFIER ) {
/* not an identifier */
status = PARSE_NO_MATCH;
}
@ -1000,7 +1004,7 @@ static parse_status_t vfmatch(
status = scanner_get_token( scanner,
&token, &tok_type );
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != TT_CRLF ) {
tok_type != ( token_type_t ) TT_CRLF ) {
/* not CRLF token */
status = PARSE_NO_MATCH;
}
@ -1021,7 +1025,7 @@ static parse_status_t vfmatch(
}
assert( str_ptr != NULL );
status = match_non_ws_string( scanner, str_ptr );
if( c == 'U' && status == PARSE_OK ) {
if( c == 'U' && status == ( parse_status_t ) PARSE_OK ) {
uri_ptr = va_arg( argp, uri_type * );
assert( uri_ptr != NULL );
stat = parse_uri( str_ptr->buf, str_ptr->length,
@ -1051,7 +1055,7 @@ static parse_status_t vfmatch(
status =
scanner_get_token( scanner, str_ptr, &tok_type );
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != TT_QUOTEDSTRING ) {
tok_type != ( token_type_t ) TT_QUOTEDSTRING ) {
status = PARSE_NO_MATCH; /* not a quoted string */
}
break;
@ -1060,7 +1064,7 @@ static parse_status_t vfmatch(
status = scanner_get_token( scanner,
&token, &tok_type );
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != TT_WHITESPACE ) {
tok_type != ( token_type_t ) TT_WHITESPACE ) {
/* restore non-whitespace token */
scanner->cursor -= token.length;
}
@ -1094,7 +1098,8 @@ static parse_status_t vfmatch(
case '\t': /* Whitespace */
status = scanner_get_token( scanner,
&token, &tok_type );
if( status == PARSE_OK && tok_type != TT_WHITESPACE ) {
if( status == ( parse_status_t ) PARSE_OK &&
tok_type != (token_type_t) TT_WHITESPACE ) {
/* not whitespace token */
status = PARSE_NO_MATCH;
}
@ -1106,7 +1111,7 @@ static parse_status_t vfmatch(
}
}
}
if( status != PARSE_OK ) {
if( status != ( parse_status_t ) PARSE_OK ) {
/* on error, restore original scanner pos */
scanner->cursor = save_pos;
}
@ -1411,7 +1416,7 @@ parse_status_t parser_parse_responseline(INOUT http_parser_t *parser)
while (*p == ' ' || *p == '\t')
p++;
/* now, p is at start of status msg */
n = line.length - (size_t)(p - line.buf);
n = line.length - (size_t)p - (size_t)line.buf;
if (membuffer_assign(&hmsg->status_msg, p, n) != 0) {
/* out of mem */
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
@ -1451,34 +1456,35 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
char save_char;
int ret2;
assert(parser->position == POS_HEADERS ||
assert(parser->position == (parser_pos_t)POS_HEADERS ||
parser->ent_position == ENTREAD_CHUNKY_HEADERS);
while (TRUE) {
save_pos = scanner->cursor;
/* check end of headers */
status = scanner_get_token(scanner, &token, &tok_type);
if (status != PARSE_OK) {
if (status != (parse_status_t)PARSE_OK) {
return status;
}
if (tok_type == TT_CRLF) {
switch (tok_type) {
case TT_CRLF:
/* end of headers */
if ((parser->msg.is_request)
&& (parser->msg.method == HTTPMETHOD_POST ||
parser->msg.method == HTTPMETHOD_PUT)) {
&& (parser->msg.method == (http_method_t)HTTPMETHOD_POST)) {
parser->position = POS_COMPLETE; /*post entity parsing */
/*is handled separately */
return PARSE_SUCCESS;
}
parser->position = POS_ENTITY; /* read entity next */
return PARSE_OK;
}
/* not end; read header */
if (tok_type != TT_IDENTIFIER) {
case TT_IDENTIFIER:
/* not end; read header */
break;
default:
return PARSE_FAILURE; /* didn't see header name */
}
status = match(scanner, " : %R%c", &hdr_value);
if (status != PARSE_OK) {
if (status != (parse_status_t)PARSE_OK) {
/* pushback tokens; useful only on INCOMPLETE error */
scanner->cursor = save_pos;
return status;
@ -1516,10 +1522,10 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
membuffer_init(&header->name_buf);
membuffer_init(&header->value);
/* value can be 0 length */
if (hdr_value.length == 0) {
if (hdr_value.length == (size_t)0) {
/* FIXME: Is this a bug? buf is not const. */
hdr_value.buf = "\0";
hdr_value.length = 1;
hdr_value.length = (size_t)1;
}
/* save in header in buffers */
if (membuffer_assign(&header->name_buf, token.buf, token.length) ||
@ -1534,14 +1540,14 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
header->name_id = header_id;
ListAddTail(&parser->msg.headers, header);
/*NNS: ret = dlist_append( &parser->msg.headers, header ); */
/** TODO: remove that? */
/** TODO: remove that? Yes as ret is not set anymore
if (ret == UPNP_E_OUTOF_MEMORY) {
parser->http_error_code =
HTTP_INTERNAL_SERVER_ERROR;
return PARSE_FAILURE;
}
/** end of remove that? */
} else if (hdr_value.length > 0) {
end of remove that? */
} else if (hdr_value.length > (size_t)0) {
/* append value to existing header */
/* append space */
ret = membuffer_append_str(&orig_header->value, ", ");
@ -1629,13 +1635,13 @@ static UPNP_INLINE parse_status_t parser_parse_chunky_body(
size_t save_pos;
/* if 'chunk_size' of bytes have been read; read next chunk */
if ((int)(parser->msg.msg.length - parser->scanner.cursor) >= parser->chunk_size) {
if ((parser->msg.msg.length - parser->scanner.cursor) >= parser->chunk_size) {
/* move to next chunk */
parser->scanner.cursor += parser->chunk_size;
save_pos = parser->scanner.cursor;
/* discard CRLF */
status = match(&parser->scanner, "%c");
if (status != PARSE_OK) {
if (status != (parse_status_t)PARSE_OK) {
/*move back */
parser->scanner.cursor -= parser->chunk_size;
/*parser->scanner.cursor = save_pos; */
@ -1674,7 +1680,7 @@ parser_parse_chunky_headers( INOUT http_parser_t * parser )
save_pos = parser->scanner.cursor;
status = parser_parse_headers( parser );
if( status == PARSE_OK ) {
if( status == ( parse_status_t ) PARSE_OK ) {
/* finally, done with the whole msg */
parser->position = POS_COMPLETE;
@ -1720,7 +1726,7 @@ parser_parse_chunky_entity( INOUT http_parser_t * parser )
/* get size of chunk, discard extension, discard CRLF */
status = match( scanner, "%x%L%c", &parser->chunk_size, &dummy );
if( status != PARSE_OK ) {
if( status != ( parse_status_t ) PARSE_OK ) {
scanner->cursor = save_pos;
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"CHUNK COULD NOT BE PARSED\n" );
@ -1804,7 +1810,7 @@ parser_get_entity_read_method( INOUT http_parser_t * parser )
/* entity points to start of msg body */
parser->msg.entity.buf = scanner_get_str( &parser->scanner );
parser->msg.entity.length = 0;
parser->msg.entity.length = ( size_t ) 0;
/* remember start of body */
parser->entity_start_position = parser->scanner.cursor;
@ -1836,11 +1842,11 @@ parser_get_entity_read_method( INOUT http_parser_t * parser )
if( response_code == 204 ||
response_code == 304 ||
( response_code >= 100 && response_code <= 199 ) ||
hmsg->request_method == HTTPMETHOD_HEAD ||
hmsg->request_method == HTTPMETHOD_MSEARCH ||
hmsg->request_method == HTTPMETHOD_SUBSCRIBE ||
hmsg->request_method == HTTPMETHOD_UNSUBSCRIBE ||
hmsg->request_method == HTTPMETHOD_NOTIFY ) {
hmsg->request_method == ( http_method_t ) HTTPMETHOD_HEAD ||
hmsg->request_method == ( http_method_t ) HTTPMETHOD_MSEARCH ||
hmsg->request_method == ( http_method_t ) HTTPMETHOD_SUBSCRIBE ||
hmsg->request_method == ( http_method_t ) HTTPMETHOD_UNSUBSCRIBE ||
hmsg->request_method == ( http_method_t ) HTTPMETHOD_NOTIFY ) {
parser->position = POS_COMPLETE;
return PARSE_SUCCESS;
}
@ -1869,7 +1875,7 @@ parser_get_entity_read_method( INOUT http_parser_t * parser )
if( hmsg->is_request ) {
/* set hack flag for NOTIFY methods; if set to true this is */
/* a valid SSDP notify msg */
if( hmsg->method == HTTPMETHOD_NOTIFY ) {
if( hmsg->method == ( http_method_t ) HTTPMETHOD_NOTIFY ) {
parser->valid_ssdp_notify_hack = TRUE;
}
@ -1931,7 +1937,7 @@ parser_parse_entity( INOUT http_parser_t * parser )
assert( 0 );
}
} while( status == PARSE_CONTINUE_1 );
} while( status == ( parse_status_t ) PARSE_CONTINUE_1 );
return status;
}
@ -1974,7 +1980,7 @@ parser_response_init( OUT http_parser_t * parser,
parser_init( parser );
parser->msg.is_request = FALSE;
parser->msg.request_method = request_method;
parser->msg.amount_discarded = 0;
parser->msg.amount_discarded = (size_t)0;
parser->position = POS_RESPONSE_LINE;
}
@ -2028,7 +2034,7 @@ parser_parse( INOUT http_parser_t * parser )
}
}
} while( status == PARSE_OK );
} while( status == ( parse_status_t ) PARSE_OK );
return status;
@ -2087,7 +2093,7 @@ int raw_to_int(IN memptr *raw_value, IN int base)
long num;
char *end_ptr;
if (raw_value->length == 0)
if (raw_value->length == (size_t)0)
return -1;
errno = 0;
num = strtol(raw_value->buf, &end_ptr, base);

View File

@ -232,13 +232,13 @@ int http_FixUrl(IN uri_type *url, OUT uri_type *fixed_url)
return UPNP_E_INVALID_URL;
}
#endif
if( fixed_url->hostport.text.size == 0 ) {
if( fixed_url->hostport.text.size == ( size_t ) 0 ) {
return UPNP_E_INVALID_URL;
}
/* set pathquery to "/" if it is empty */
if (fixed_url->pathquery.size == 0) {
if (fixed_url->pathquery.size == (size_t)0) {
fixed_url->pathquery.buff = temp_path;
fixed_url->pathquery.size = 1;
fixed_url->pathquery.size = (size_t)1;
}
return UPNP_E_SUCCESS;
@ -283,7 +283,8 @@ SOCKET http_Connect(
http_FixUrl(destination_url, url);
connfd = socket(url->hostport.IPaddress.ss_family, SOCK_STREAM, 0);
connfd = socket((int)url->hostport.IPaddress.ss_family,
SOCK_STREAM, 0);
if (connfd == INVALID_SOCKET) {
return (SOCKET)(UPNP_E_OUTOF_SOCKET);
}
@ -699,7 +700,7 @@ int http_Download( IN const char *url_str,
memptr ctype;
size_t copy_len;
membuffer request;
char *urlPath = alloca(strlen(url_str) + 1);
char *urlPath = alloca(strlen(url_str) + (size_t)1);
/*ret_code = parse_uri( (char*)url_str, strlen(url_str), &url ); */
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
@ -709,7 +710,7 @@ int http_Download( IN const char *url_str,
return ret_code;
/* make msg */
membuffer_init(&request);
memset(urlPath, 0, strlen(url_str) + 1);
memset(urlPath, 0, strlen(url_str) + (size_t)1);
strncpy(urlPath, url_str, strlen(url_str));
hoststr = strstr(urlPath, "//");
if (hoststr == NULL)
@ -757,15 +758,15 @@ int http_Download( IN const char *url_str,
*content_type = '\0'; /* no content-type */
} else {
/* safety */
copy_len = ctype.length < LINE_SIZE - 1 ?
ctype.length : LINE_SIZE - 1;
copy_len = ctype.length < LINE_SIZE - (size_t)1 ?
ctype.length : LINE_SIZE - (size_t)1;
memcpy(content_type, ctype.buf, copy_len);
content_type[copy_len] = '\0';
}
}
/* extract doc from msg */
if ((*doc_length = response.msg.entity.length) == 0) {
if ((*doc_length = response.msg.entity.length) == (size_t)0) {
/* 0-length msg */
*document = NULL;
} else if (response.msg.status_code == HTTP_OK) {
@ -775,9 +776,9 @@ int http_Download( IN const char *url_str,
msg_length = response.msg.msg.length; /* save for posterity */
msg_start = membuffer_detach(&response.msg.msg); /* whole msg */
/* move entity to the start; copy null-terminator too */
memmove(msg_start, entity_start, *doc_length + 1);
memmove(msg_start, entity_start, *doc_length + (size_t)1);
/* save mem for body only */
*document = realloc(msg_start, *doc_length + 1); /*LEAK_FIX_MK */
*document = realloc(msg_start, *doc_length + (size_t)1); /*LEAK_FIX_MK */
/* *document = Realloc( msg_start,msg_length, *doc_length + 1 ); LEAK_FIX_MK */
/* shrink can't fail */
assert(msg_length > *doc_length);
@ -822,7 +823,7 @@ int MakeGenericMessage(http_method_t method,
const UpnpString *headers)
{
int ret_code = 0;
size_t hostlen = 0;
size_t hostlen = (size_t)0;
char *hoststr;
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
@ -923,13 +924,17 @@ static parse_status_t ReadResponseLineAndHeaders(
/*read response line */
status = parser_parse_responseline(parser);
if (status == PARSE_OK)
switch (status) {
case PARSE_OK:
done = 1;
else if (status == PARSE_INCOMPLETE)
break;
case PARSE_INCOMPLETE:
done = 0;
else
break;
default:
/*error */
return status;
}
while (!done) {
num_read = sock_read(info, buf, sizeof(buf), timeout_secs);
if (num_read > 0) {
@ -943,11 +948,14 @@ static parse_status_t ReadResponseLineAndHeaders(
return PARSE_FAILURE;
}
status = parser_parse_responseline(parser);
if (status == PARSE_OK) {
switch (status) {
case PARSE_OK:
done = 1;
} else if (status == PARSE_INCOMPLETE) {
break;
case PARSE_INCOMPLETE:
done = 0;
} else {
break;
default:
/*error */
return status;
}
@ -962,9 +970,10 @@ static parse_status_t ReadResponseLineAndHeaders(
}
done = 0;
status = parser_parse_headers(parser);
if ((status == PARSE_OK) && (parser->position == POS_ENTITY))
if ((status == (parse_status_t)PARSE_OK) &&
(parser->position == (parser_pos_t)POS_ENTITY))
done = 1;
else if (status == PARSE_INCOMPLETE)
else if (status == (parse_status_t)PARSE_INCOMPLETE)
done = 0;
else
/*error */
@ -982,9 +991,10 @@ static parse_status_t ReadResponseLineAndHeaders(
return PARSE_FAILURE;
}
status = parser_parse_headers(parser);
if (status == PARSE_OK && parser->position == POS_ENTITY)
if (status == (parse_status_t)PARSE_OK &&
parser->position == (parser_pos_t)POS_ENTITY)
done = 1;
else if (status == PARSE_INCOMPLETE)
else if (status == (parse_status_t)PARSE_INCOMPLETE)
done = 0;
else
/*error */
@ -1490,7 +1500,7 @@ int http_MakeMessage(membuffer *buf, int http_major_version,
goto error_handler;
} else if (c == 'c') {
/* crlf */
if (membuffer_append(buf, "\r\n", 2))
if (membuffer_append(buf, "\r\n", (size_t)2))
goto error_handler;
} else if (c == 'd') {
/* integer */
@ -1712,7 +1722,7 @@ int MakeGetMessageEx( const char *url_str,
{
int errCode = UPNP_E_SUCCESS;
char *urlPath = NULL;
size_t hostlen = 0;
size_t hostlen = (size_t)0;
char *hoststr, *temp;
do {
@ -1725,12 +1735,12 @@ int MakeGetMessageEx( const char *url_str,
}
/* make msg */
membuffer_init(request);
urlPath = alloca(strlen(url_str) + 1);
urlPath = alloca(strlen(url_str) + (size_t)1);
if (!urlPath) {
errCode = UPNP_E_OUTOF_MEMORY;
break;
}
memset(urlPath, 0, strlen(url_str) + 1);
memset(urlPath, 0, strlen(url_str) + (size_t)1);
strncpy(urlPath, url_str, strlen(url_str));
hoststr = strstr(urlPath, "//");
if (hoststr == NULL) {
@ -1851,7 +1861,8 @@ int http_OpenHttpGetEx(
}
memset(handle, 0, sizeof(*handle));
parser_response_init(&handle->response, HTTPMETHOD_GET);
tcp_connection = socket(url.hostport.IPaddress.ss_family, SOCK_STREAM, 0);
tcp_connection = socket((int)url.hostport.IPaddress.ss_family,
SOCK_STREAM, 0);
if (tcp_connection == INVALID_SOCKET) {
errCode = UPNP_E_SOCKET_ERROR;
free(handle);
@ -1904,7 +1915,7 @@ int http_OpenHttpGetEx(
*contentType = NULL;
else
*contentType = ctype.buf;
if (handle->response.position == POS_COMPLETE)
if (handle->response.position == (parser_pos_t)POS_COMPLETE)
*contentLength = 0;
else if(handle->response.ent_position == ENTREAD_USING_CHUNKED)
*contentLength = UPNP_USING_CHUNKED;

View File

@ -126,7 +126,7 @@
*
* @{
*/
#define THREAD_STACK_SIZE 0
#define THREAD_STACK_SIZE (size_t)0
/* @} */

View File

@ -222,7 +222,7 @@ typedef struct {
parser_pos_t position;
int ent_position;
unsigned int content_length;
int chunk_size;
size_t chunk_size;
/*! offset in the the raw message buffer, which contains the message body.
* preceding this are the headers of the messsage. */
size_t entity_start_position;

View File

@ -56,7 +56,7 @@
#define DEFAULT_MAXAGE 1800
#define DEFAULT_SOAP_CONTENT_LENGTH 16000
#define MAX_SOAP_CONTENT_LENGTH 32000
#define MAX_SOAP_CONTENT_LENGTH (size_t)32000
extern size_t g_maxContentLength;