Remove more implicit casts in upnp part

Remove more "implicit integer or enum conversions" as well as memset
before snprintf.
This commit is contained in:
Fabrice Fontaine
2012-03-10 21:27:55 +01:00
parent db532afb9b
commit 2eb3e069ba
11 changed files with 119 additions and 102 deletions

View File

@@ -2,6 +2,13 @@
Version 1.6.16 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" as well as memset
before snprintf.
2012-03-11 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com> 2012-03-11 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
Avoid out of range access in CheckOtherHTTPHeaders. Avoid out of range access in CheckOtherHTTPHeaders.

View File

@@ -1280,9 +1280,9 @@ int UpnpUnRegisterRootDeviceLowPower(UpnpDevice_Handle Hnd, int PowerState,
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 == (unsigned short)AF_INET)
UpnpSdkDeviceRegisteredV4 = 0; UpnpSdkDeviceRegisteredV4 = 0;
else if (HInfo->DeviceAf == AF_INET6) else if (HInfo->DeviceAf == (unsigned short)AF_INET6)
UpnpSdkDeviceregisteredV6 = 0; UpnpSdkDeviceregisteredV6 = 0;
FreeHandle(Hnd); FreeHandle(Hnd);
HandleUnlock(); HandleUnlock();

View File

@@ -76,8 +76,8 @@
const int CHUNK_HEADER_SIZE = 10; const int CHUNK_HEADER_SIZE = 10;
const int CHUNK_TAIL_SIZE = 10; const int CHUNK_TAIL_SIZE = 10;
*/ */
#define CHUNK_HEADER_SIZE 10 #define CHUNK_HEADER_SIZE (size_t)10
#define CHUNK_TAIL_SIZE 10 #define CHUNK_TAIL_SIZE (size_t)10
#ifndef UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS #ifndef UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS
@@ -277,7 +277,7 @@ int http_RecvMessage(
int ok_on_close = FALSE; int ok_on_close = FALSE;
char buf[2 * 1024]; char buf[2 * 1024];
if (request_method == HTTPMETHOD_UNKNOWN) { if (request_method == (http_method_t)HTTPMETHOD_UNKNOWN) {
parser_request_init(parser); parser_request_init(parser);
} else { } else {
parser_response_init(parser, request_method); parser_response_init(parser, request_method);
@@ -288,12 +288,13 @@ int http_RecvMessage(
if (num_read > 0) { if (num_read > 0) {
/* got data */ /* got data */
status = parser_append(parser, buf, (size_t)num_read); status = parser_append(parser, buf, (size_t)num_read);
if (status == PARSE_SUCCESS) { switch (status) {
case PARSE_SUCCESS:
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"<<< (RECVD) <<<\n%s\n-----------------\n", "<<< (RECVD) <<<\n%s\n-----------------\n",
parser->msg.msg.buf ); parser->msg.msg.buf );
print_http_headers( &parser->msg ); print_http_headers( &parser->msg );
if (g_maxContentLength > 0 && parser->content_length > (unsigned int)g_maxContentLength) { if (g_maxContentLength > (size_t)0 && parser->content_length > (unsigned int)g_maxContentLength) {
*http_error_code = HTTP_REQ_ENTITY_TOO_LARGE; *http_error_code = HTTP_REQ_ENTITY_TOO_LARGE;
line = __LINE__; line = __LINE__;
ret = UPNP_E_OUTOF_BOUNDS; ret = UPNP_E_OUTOF_BOUNDS;
@@ -302,19 +303,21 @@ int http_RecvMessage(
line = __LINE__; line = __LINE__;
ret = 0; ret = 0;
goto ExitFunction; goto ExitFunction;
} else if (status == PARSE_FAILURE) { case PARSE_FAILURE:
*http_error_code = parser->http_error_code; *http_error_code = parser->http_error_code;
line = __LINE__; line = __LINE__;
ret = UPNP_E_BAD_HTTPMSG; ret = UPNP_E_BAD_HTTPMSG;
goto ExitFunction; goto ExitFunction;
} else if (status == PARSE_INCOMPLETE_ENTITY) { case PARSE_INCOMPLETE_ENTITY:
/* read until close */ /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if (status == PARSE_CONTINUE_1) { case PARSE_CONTINUE_1:
/* Web post request. */ /* Web post request. */
line = __LINE__; line = __LINE__;
ret = PARSE_SUCCESS; ret = PARSE_SUCCESS;
goto ExitFunction; goto ExitFunction;
default:
break;
} }
} else if (num_read == 0) { } else if (num_read == 0) {
if (ok_on_close) { if (ok_on_close) {
@@ -367,7 +370,7 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...)
size_t buf_length; size_t buf_length;
size_t num_read; size_t num_read;
size_t num_written; size_t num_written;
size_t amount_to_be_read = 0; size_t amount_to_be_read = (size_t)0;
/* 10 byte allocated for chunk header. */ /* 10 byte allocated for chunk header. */
size_t Data_Buf_Size = WEB_SERVER_BUF_SIZE; size_t Data_Buf_Size = WEB_SERVER_BUF_SIZE;
@@ -422,7 +425,7 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...)
nr = virtualDirCallback.read(Fp, file_buf, n); nr = virtualDirCallback.read(Fp, file_buf, n);
num_read = (size_t)nr; num_read = (size_t)nr;
} else { } else {
num_read = fread(file_buf, 1, n, Fp); num_read = fread(file_buf, (size_t)1, n, Fp);
} }
amount_to_be_read -= num_read; amount_to_be_read -= num_read;
if (Instr->ReadSendSize < 0) { if (Instr->ReadSendSize < 0) {
@@ -430,9 +433,9 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...)
amount_to_be_read = Data_Buf_Size; amount_to_be_read = Data_Buf_Size;
} }
} else { } else {
num_read = fread(file_buf, 1, Data_Buf_Size, Fp); num_read = fread(file_buf, (size_t)1, Data_Buf_Size, Fp);
} }
if (num_read == 0) { if (num_read == (size_t)0) {
/* EOF so no more to send. */ /* EOF so no more to send. */
if (Instr && Instr->IsChunkActive) { if (Instr && Instr->IsChunkActive) {
const char *str = "0\r\n\r\n"; const char *str = "0\r\n\r\n";
@@ -469,10 +472,10 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...)
/*printf("Sending %s\n",file_buf-strlen(Chunk_Header)); */ /*printf("Sending %s\n",file_buf-strlen(Chunk_Header)); */
nw = sock_write(info, nw = sock_write(info,
file_buf - strlen(Chunk_Header), file_buf - strlen(Chunk_Header),
num_read + strlen(Chunk_Header) + 2, num_read + strlen(Chunk_Header) + (size_t)2,
TimeOut); TimeOut);
num_written = (size_t)nw; num_written = (size_t)nw;
if (nw <= 0 || num_written != num_read + strlen(Chunk_Header) + 2) if (nw <= 0 || num_written != num_read + strlen(Chunk_Header) + (size_t)2)
/* Send error nothing we can do. */ /* Send error nothing we can do. */
goto Cleanup_File; goto Cleanup_File;
} else { } else {
@@ -499,7 +502,7 @@ Cleanup_File:
/* 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 > (size_t)0) {
nw = sock_write(info, buf, buf_length, TimeOut); nw = sock_write(info, buf, buf_length, TimeOut);
num_written = (size_t)nw; num_written = (size_t)nw;
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
@@ -559,7 +562,7 @@ int http_RequestAndResponse(
SOCKINFO info; SOCKINFO info;
tcp_connection = socket( tcp_connection = socket(
destination->hostport.IPaddress.ss_family, SOCK_STREAM, 0); (int)destination->hostport.IPaddress.ss_family, SOCK_STREAM, 0);
if (tcp_connection == INVALID_SOCKET) { if (tcp_connection == INVALID_SOCKET) {
parser_response_init(response, req_method); parser_response_init(response, req_method);
return UPNP_E_SOCKET_ERROR; return UPNP_E_SOCKET_ERROR;
@@ -849,18 +852,18 @@ int http_WriteHttpPost( IN void *Handle,
{ {
http_post_handle_t *handle = (http_post_handle_t *)Handle; http_post_handle_t *handle = (http_post_handle_t *)Handle;
char *tempbuf = NULL; char *tempbuf = NULL;
size_t tempbufSize = 0; size_t tempbufSize = (size_t)0;
int freeTempbuf = 0; int freeTempbuf = 0;
int numWritten = 0; int numWritten = 0;
if (!handle || !size || !buf) { if (!handle || !size || !buf) {
if (size) if (size)
*size = 0; *size = (size_t)0;
return UPNP_E_INVALID_PARAM; return UPNP_E_INVALID_PARAM;
} }
if (handle->contentLength == UPNP_USING_CHUNKED) { if (handle->contentLength == UPNP_USING_CHUNKED) {
if (*size) { if (*size) {
size_t tempSize = 0; size_t tempSize = (size_t)0;
tempbuf = malloc(*size + tempbuf = malloc(*size +
CHUNK_HEADER_SIZE + CHUNK_TAIL_SIZE); CHUNK_HEADER_SIZE + CHUNK_TAIL_SIZE);
if (!tempbuf) if (!tempbuf)
@@ -871,7 +874,7 @@ int http_WriteHttpPost( IN void *Handle,
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 + (size_t)2;
freeTempbuf = 1; freeTempbuf = 1;
} }
} else { } else {
@@ -883,7 +886,7 @@ int http_WriteHttpPost( IN void *Handle,
if (freeTempbuf) if (freeTempbuf)
free(tempbuf); free(tempbuf);
if (numWritten < 0) { if (numWritten < 0) {
*size = 0; *size = (size_t)0;
return numWritten; return numWritten;
} else { } else {
*size = (size_t)numWritten; *size = (size_t)numWritten;
@@ -983,7 +986,7 @@ int http_OpenHttpPost(
if (!handle) if (!handle)
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
handle->contentLength = contentLength; handle->contentLength = contentLength;
tcp_connection = socket(url.hostport.IPaddress.ss_family, tcp_connection = socket((int)url.hostport.IPaddress.ss_family,
SOCK_STREAM, 0); SOCK_STREAM, 0);
if (tcp_connection == INVALID_SOCKET) { if (tcp_connection == INVALID_SOCKET) {
ret_code = UPNP_E_SOCKET_ERROR; ret_code = UPNP_E_SOCKET_ERROR;
@@ -1238,31 +1241,35 @@ int http_ReadHttpGet(
char tempbuf[2 * 1024]; char tempbuf[2 * 1024];
int ret_code = 0; int ret_code = 0;
if (!handle || !size || (*size > 0 && !buf)) { if (!handle || !size || (*size > (size_t)0 && !buf)) {
if (size) if (size)
*size = 0; *size = (size_t)0;
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 != (parser_pos_t)POS_COMPLETE)
status = parser_parse_entity(&handle->response); status = parser_parse_entity(&handle->response);
else else
status = PARSE_SUCCESS; status = PARSE_SUCCESS;
if (status == PARSE_INCOMPLETE_ENTITY) switch (status) {
case PARSE_INCOMPLETE_ENTITY:
/* read until close */ /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
else if ((status != PARSE_SUCCESS) break;
&& (status != PARSE_CONTINUE_1) case PARSE_SUCCESS:
&& (status != PARSE_INCOMPLETE)) { case PARSE_CONTINUE_1:
case PARSE_INCOMPLETE:
break;
default:
/*error */ /*error */
*size = 0; *size = (size_t)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.amount_discarded + *size > while (handle->response.msg.amount_discarded + *size >
handle->response.msg.entity.length && handle->response.msg.entity.length &&
!handle->cancel && !handle->cancel &&
handle->response.position != POS_COMPLETE) { handle->response.position != (parser_pos_t)POS_COMPLETE) {
num_read = sock_read(&handle->sock_info, tempbuf, num_read = sock_read(&handle->sock_info, tempbuf,
sizeof(tempbuf), &timeout); sizeof(tempbuf), &timeout);
if (num_read > 0) { if (num_read > 0) {
@@ -1273,18 +1280,22 @@ int http_ReadHttpGet(
/* 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 = (size_t)0;
return PARSE_FAILURE; return PARSE_FAILURE;
} }
status = parser_parse_entity(&handle->response); status = parser_parse_entity(&handle->response);
if (status == PARSE_INCOMPLETE_ENTITY) { switch (status) {
case PARSE_INCOMPLETE_ENTITY:
/* read until close */ /* read until close */
ok_on_close = TRUE; ok_on_close = TRUE;
} else if ((status != PARSE_SUCCESS) break;
&& (status != PARSE_CONTINUE_1) case PARSE_SUCCESS:
&& (status != PARSE_INCOMPLETE)) { case PARSE_CONTINUE_1:
case PARSE_INCOMPLETE:
break;
default:
/*error */ /*error */
*size = 0; *size = (size_t)0;
return UPNP_E_BAD_RESPONSE; return UPNP_E_BAD_RESPONSE;
} }
} else if (num_read == 0) { } else if (num_read == 0) {
@@ -1295,12 +1306,12 @@ int http_ReadHttpGet(
handle->response.position = POS_COMPLETE; handle->response.position = POS_COMPLETE;
} else { } else {
/* partial msg */ /* partial msg */
*size = 0; *size = (size_t)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 {
*size = 0; *size = (size_t)0;
return num_read; return num_read;
} }
} }
@@ -1313,7 +1324,7 @@ int http_ReadHttpGet(
*size = handle->response.msg.entity.length - *size = handle->response.msg.entity.length -
handle->response.msg.amount_discarded; handle->response.msg.amount_discarded;
/* copy data to user buffer. delete copied data */ /* copy data to user buffer. delete copied data */
if (*size > 0) { if (*size > (size_t)0) {
memcpy(buf, &handle->response.msg.msg.buf[handle->response.entity_start_position], memcpy(buf, &handle->response.msg.msg.buf[handle->response.entity_start_position],
*size); *size);
membuffer_delete(&handle->response.msg.msg, membuffer_delete(&handle->response.msg.msg,
@@ -1497,8 +1508,11 @@ int http_OpenHttpGetProxy(const char *url_str, const char *proxy_str,
goto errorHandler; goto errorHandler;
} }
status = parser_get_entity_read_method(&handle->response); status = parser_get_entity_read_method(&handle->response);
if (status != (parse_status_t)PARSE_CONTINUE_1 && switch (status) {
status != (parse_status_t)PARSE_SUCCESS) { case PARSE_CONTINUE_1:
case PARSE_SUCCESS:
break;
default:
ret_code = UPNP_E_BAD_RESPONSE; ret_code = UPNP_E_BAD_RESPONSE;
goto errorHandler; goto errorHandler;
} }
@@ -1509,7 +1523,7 @@ int http_OpenHttpGetProxy(const char *url_str, const char *proxy_str,
*contentType = NULL; *contentType = NULL;
else else
*contentType = ctype.buf; *contentType = ctype.buf;
if (handle->response.position == POS_COMPLETE) if (handle->response.position == (parser_pos_t)POS_COMPLETE)
*contentLength = 0; *contentLength = 0;
else if (handle->response.ent_position == ENTREAD_USING_CHUNKED) else if (handle->response.ent_position == ENTREAD_USING_CHUNKED)
*contentLength = UPNP_USING_CHUNKED; *contentLength = UPNP_USING_CHUNKED;
@@ -1557,7 +1571,7 @@ int http_SendStatusResponse(IN SOCKINFO *info, IN int http_status_code,
http_CalcResponseVersion(request_major_version, request_minor_version, http_CalcResponseVersion(request_major_version, request_minor_version,
&response_major, &response_minor); &response_major, &response_minor);
membuffer_init(&membuf); membuffer_init(&membuf);
membuf.size_inc = 70; membuf.size_inc = (size_t)70;
/* response start line */ /* response start line */
ret = http_MakeMessage(&membuf, response_major, response_minor, "RSCB", ret = http_MakeMessage(&membuf, response_major, response_minor, "RSCB",
http_status_code, http_status_code); http_status_code, http_status_code);

View File

@@ -129,7 +129,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 ) + (size_t)1; /* next entry */
} }
} }

View File

@@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom 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:
@@ -112,7 +113,7 @@ static int sock_read_write(
/*! [out] Buffer to get data to or send data from. */ /*! [out] Buffer to get data to or send data from. */
char *buffer, char *buffer,
/*! [in] Size of the buffer. */ /*! [in] Size of the buffer. */
int bufsize, size_t bufsize,
/*! [in] timeout value. */ /*! [in] timeout value. */
int *timeoutSecs, int *timeoutSecs,
/*! [in] Boolean value specifying read or write option. */ /*! [in] Boolean value specifying read or write option. */
@@ -166,7 +167,7 @@ static int sock_read_write(
#endif #endif
if (bRead) { if (bRead) {
/* read data. */ /* read data. */
numBytes = (long)recv(sockfd, buffer, (size_t)bufsize, MSG_NOSIGNAL); numBytes = (long)recv(sockfd, buffer, bufsize, MSG_NOSIGNAL);
} else { } else {
byte_left = bufsize; byte_left = bufsize;
bytes_sent = 0; bytes_sent = 0;
@@ -200,12 +201,12 @@ static int sock_read_write(
return (int)numBytes; return (int)numBytes;
} }
int sock_read(SOCKINFO *info, char *buffer, int bufsize, int *timeoutSecs) int sock_read(SOCKINFO *info, char *buffer, size_t bufsize, int *timeoutSecs)
{ {
return sock_read_write(info, buffer, bufsize, timeoutSecs, TRUE); return sock_read_write(info, buffer, bufsize, timeoutSecs, TRUE);
} }
int sock_write(SOCKINFO *info, const char *buffer, int bufsize, int *timeoutSecs) int sock_write(SOCKINFO *info, const char *buffer, size_t bufsize, int *timeoutSecs)
{ {
/* Consciently removing constness. */ /* Consciently removing constness. */
return sock_read_write(info, (char *)buffer, bufsize, timeoutSecs, FALSE); return sock_read_write(info, (char *)buffer, bufsize, timeoutSecs, FALSE);

View File

@@ -69,7 +69,7 @@ static int is_reserved(
/*! [in] Char to be matched for RESERVED characters. */ /*! [in] Char to be matched for RESERVED characters. */
char in) char in)
{ {
if (strchr(RESERVED, in)) { if (strchr(RESERVED, (int)in)) {
return 1; return 1;
} else { } else {
return 0; return 0;
@@ -87,7 +87,7 @@ int is_mark(
/*! [in] Char to be matched for MARKED characters. */ /*! [in] Char to be matched for MARKED characters. */
char in) char in)
{ {
if (strchr(MARK, in)) { if (strchr(MARK, (int)in)) {
return 1; return 1;
} else { } else {
return 0; return 0;
@@ -213,12 +213,12 @@ static void copy_token(
int copy_URL_list(URL_list *in, URL_list *out) int copy_URL_list(URL_list *in, URL_list *out)
{ {
size_t len = strlen(in->URLs) + 1; size_t len = strlen(in->URLs) + (size_t)1;
size_t i = 0; size_t i = (size_t)0;
out->URLs = NULL; out->URLs = NULL;
out->parsedURLs = NULL; out->parsedURLs = NULL;
out->size = 0; out->size = (size_t)0;
out->URLs = malloc(len); out->URLs = malloc(len);
out->parsedURLs = malloc(sizeof(uri_type) * in->size); out->parsedURLs = malloc(sizeof(uri_type) * in->size);
@@ -226,7 +226,7 @@ int copy_URL_list(URL_list *in, URL_list *out)
if ( !out->URLs || !out->parsedURLs) if ( !out->URLs || !out->parsedURLs)
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
memcpy(out->URLs, in->URLs, len); memcpy(out->URLs, in->URLs, len);
for( i = 0; i < in->size; i++ ) { for( i = (size_t)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,
@@ -257,7 +257,7 @@ void free_URL_list(URL_list *list)
if (list->parsedURLs) { if (list->parsedURLs) {
free(list->parsedURLs); free(list->parsedURLs);
} }
list->size = 0; list->size = (size_t)0;
} }
@@ -326,7 +326,7 @@ int parse_hostport(
char *srvport = NULL; char *srvport = NULL;
char *last_dot = NULL; char *last_dot = NULL;
unsigned short int port; unsigned short int port;
int af = AF_UNSPEC; unsigned short af = AF_UNSPEC;
size_t hostport_size; size_t hostport_size;
int has_port = 0; int has_port = 0;
int ret; int ret;
@@ -409,24 +409,24 @@ int parse_hostport(
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 = 80u;
/* 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 = (size_t)c - (size_t)workbuf; hostport_size = (size_t)c - (size_t)workbuf;
/* Fill in the 'out' information. */ /* Fill in the 'out' information. */
if (af == AF_INET) { if (af == (unsigned short)AF_INET) {
sai4->sin_family = (unsigned short)AF_INET; sai4->sin_family = af;
sai4->sin_port = htons(port); sai4->sin_port = htons(port);
ret = inet_pton(AF_INET, srvname, &sai4->sin_addr); ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
} else if (af == AF_INET6) { } else if (af == (unsigned short)AF_INET6) {
sai6->sin6_family = (unsigned short)AF_INET6; sai6->sin6_family = af;
sai6->sin6_port = htons(port); sai6->sin6_port = htons(port);
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 == (unsigned short)AF_INET)
sai4->sin_port = htons(port); sai4->sin_port = htons(port);
else else
sai6->sin6_port = htons(port); sai6->sin6_port = htons(port);

View File

@@ -2,6 +2,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom 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:
@@ -189,7 +190,7 @@
* *
* @{ * @{
*/ */
#define WEB_SERVER_BUF_SIZE (1024*1024) #define WEB_SERVER_BUF_SIZE (size_t)(1024*1024)
/* @} */ /* @} */
/*! /*!

View File

@@ -5,6 +5,7 @@
* *
* Copyright (c) 2000-2003 Intel Corporation * Copyright (c) 2000-2003 Intel Corporation
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 France Telecom 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:
@@ -143,7 +144,7 @@ int sock_read(
/*! [out] Buffer to get data to. */ /*! [out] Buffer to get data to. */
char* buffer, char* buffer,
/*! [in] Size of the buffer. */ /*! [in] Size of the buffer. */
int bufsize, size_t bufsize,
/*! [in,out] timeout value. */ /*! [in,out] timeout value. */
int *timeoutSecs); int *timeoutSecs);
@@ -161,7 +162,7 @@ int sock_write(
/*! [in] Buffer to send data from. */ /*! [in] Buffer to send data from. */
const char *buffer, const char *buffer,
/*! [in] Size of the buffer. */ /*! [in] Size of the buffer. */
int bufsize, size_t bufsize,
/*! [in,out] timeout value. */ /*! [in,out] timeout value. */
int *timeoutSecs); int *timeoutSecs);

View File

@@ -354,7 +354,7 @@ int DeviceAdvertisement(
/* [in] Service duration in sec. */ /* [in] Service duration in sec. */
int Duration, int Duration,
/* [in] Device address family. */ /* [in] Device address family. */
int AddressFamily, unsigned short AddressFamily,
/* [in] PowerState as defined by UPnP Low Power. */ /* [in] PowerState as defined by UPnP Low Power. */
int PowerState, int PowerState,
/* [in] SleepPeriod as defined by UPnP Low Power. */ /* [in] SleepPeriod as defined by UPnP Low Power. */
@@ -432,7 +432,7 @@ int ServiceAdvertisement(
/* [in] Life time of this device. */ /* [in] Life time of this device. */
int Duration, int Duration,
/* [in] Device address family. */ /* [in] Device address family. */
int AddressFamily, unsigned short AddressFamily,
/* [in] PowerState as defined by UPnP Low Power. */ /* [in] PowerState as defined by UPnP Low Power. */
int PowerState, int PowerState,
/* [in] SleepPeriod as defined by UPnP Low Power. */ /* [in] SleepPeriod as defined by UPnP Low Power. */
@@ -480,7 +480,7 @@ int ServiceShutdown(
/* [in] Service duration in sec. */ /* [in] Service duration in sec. */
int Duration, int Duration,
/* [in] Device address family. */ /* [in] Device address family. */
int AddressFamily, unsigned short AddressFamily,
/* [in] PowerState as defined by UPnP Low Power. */ /* [in] PowerState as defined by UPnP Low Power. */
int PowerState, int PowerState,
/* [in] SleepPeriod as defined by UPnP Low Power. */ /* [in] SleepPeriod as defined by UPnP Low Power. */
@@ -508,7 +508,7 @@ int DeviceShutdown(
/* [in] Device duration in sec. */ /* [in] Device duration in sec. */
int Duration, int Duration,
/* [in] Device address family. */ /* [in] Device address family. */
int AddressFamily, unsigned short AddressFamily,
/* [in] PowerState as defined by UPnP Low Power. */ /* [in] PowerState as defined by UPnP Low Power. */
int PowerState, int PowerState,
/* [in] SleepPeriod as defined by UPnP Low Power. */ /* [in] SleepPeriod as defined by UPnP Low Power. */

View File

@@ -107,7 +107,7 @@ struct Handle_Info
/*! . */ /*! . */
int MaxSubscriptionTimeOut; int MaxSubscriptionTimeOut;
/*! Address family: AF_INET or AF_INET6. */ /*! Address family: AF_INET or AF_INET6. */
int DeviceAf; unsigned short DeviceAf;
#endif #endif
/* Client only */ /* Client only */

View File

@@ -380,7 +380,7 @@ static void CreateServicePacket(
nts = "ssdp:byebye"; nts = "ssdp:byebye";
/* NOTE: The CACHE-CONTROL and LOCATION headers are not present in /* NOTE: The CACHE-CONTROL and LOCATION headers are not present in
* a shutdown msg, but are present here for MS WinMe interop. */ * a shutdown msg, but are present here for MS WinMe interop. */
if (AddressFamily == AF_INET) if (AddressFamily == (unsigned short)AF_INET)
host = SSDP_IP; host = SSDP_IP;
else { else {
if (isUrlV6UlaGua(location)) if (isUrlV6UlaGua(location))
@@ -430,7 +430,7 @@ static void CreateServicePacket(
} }
int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location, int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location,
int Duration, int AddressFamily, int PowerState, int Duration, unsigned short AddressFamily, int PowerState,
int SleepPeriod, int RegistrationState) int SleepPeriod, int RegistrationState)
{ {
struct sockaddr_storage __ss; struct sockaddr_storage __ss;
@@ -445,12 +445,11 @@ int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location,
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"In function DeviceAdvertisement\n"); "In function DeviceAdvertisement\n");
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
memset(Mil_Usn, 0, sizeof(Mil_Usn)); if (AddressFamily == (unsigned short)AF_INET) {
if (AddressFamily == AF_INET) {
DestAddr4->sin_family = (unsigned short)AF_INET; DestAddr4->sin_family = (unsigned short)AF_INET;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { } else if (AddressFamily == (unsigned short)AF_INET6) {
DestAddr6->sin6_family = (unsigned short)AF_INET6; DestAddr6->sin6_family = (unsigned short)AF_INET6;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
@@ -524,7 +523,6 @@ int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
msgs[0] = NULL; msgs[0] = NULL;
msgs[1] = NULL; msgs[1] = NULL;
memset(Mil_Usn, 0, sizeof(Mil_Usn));
if (RootDev) { if (RootDev) {
/* one msg for root device */ /* one msg for root device */
num_msgs = 1; num_msgs = 1;
@@ -587,11 +585,10 @@ int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev,
szReq[0] = NULL; szReq[0] = NULL;
szReq[1] = NULL; szReq[1] = NULL;
szReq[2] = NULL; szReq[2] = NULL;
memset(Mil_Nt, 0, sizeof(Mil_Nt));
memset(Mil_Usn, 0, sizeof(Mil_Usn));
/* create 2 or 3 msgs */ /* create 2 or 3 msgs */
if (RootDev) { if (RootDev) {
/* 3 replies for root device */ /* 3 replies for root device */
memset(Mil_Nt, 0, sizeof(Mil_Nt));
strncpy(Mil_Nt, "upnp:rootdevice", sizeof(Mil_Nt) - 1); strncpy(Mil_Nt, "upnp:rootdevice", sizeof(Mil_Nt) - 1);
rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::upnp:rootdevice", Udn); rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::upnp:rootdevice", Udn);
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn))
@@ -641,8 +638,8 @@ error_handler:
} }
int ServiceAdvertisement(char *Udn, char *ServType, char *Location, int ServiceAdvertisement(char *Udn, char *ServType, char *Location,
int Duration, int AddressFamily, int PowerState, int Duration, unsigned short AddressFamily,
int SleepPeriod, int RegistrationState) int PowerState, int SleepPeriod, int RegistrationState)
{ {
char Mil_Usn[LINE_SIZE]; char Mil_Usn[LINE_SIZE];
char *szReq[1]; char *szReq[1];
@@ -653,14 +650,13 @@ int ServiceAdvertisement(char *Udn, char *ServType, char *Location,
int rc = 0; int rc = 0;
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
memset(Mil_Usn, 0, sizeof(Mil_Usn));
szReq[0] = NULL; szReq[0] = NULL;
if (AddressFamily == AF_INET) { if (AddressFamily == (unsigned short)AF_INET) {
DestAddr4->sin_family = (unsigned short)AF_INET; DestAddr4->sin_family = AddressFamily;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { } else if (AddressFamily == (unsigned short)AF_INET6) {
DestAddr6->sin6_family = (unsigned short)AF_INET6; DestAddr6->sin6_family = AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
@@ -698,7 +694,6 @@ int ServiceReply(struct sockaddr *DestAddr, char *ServType, char *Udn,
int RetVal = UPNP_E_OUTOF_MEMORY; int RetVal = UPNP_E_OUTOF_MEMORY;
int rc = 0; int rc = 0;
memset(Mil_Usn, 0, sizeof(Mil_Usn));
szReq[0] = NULL; szReq[0] = NULL;
rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::%s", Udn, ServType); rc = snprintf(Mil_Usn, sizeof(Mil_Usn), "%s::%s", Udn, ServType);
if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn)) if (rc < 0 || (unsigned int) rc >= sizeof(Mil_Usn))
@@ -717,8 +712,8 @@ error_handler:
} }
int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration, int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration,
int AddressFamily, int PowerState, int SleepPeriod, unsigned short AddressFamily, int PowerState,
int RegistrationState) int SleepPeriod, int RegistrationState)
{ {
char Mil_Usn[LINE_SIZE]; char Mil_Usn[LINE_SIZE];
char *szReq[1]; char *szReq[1];
@@ -729,14 +724,13 @@ int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration,
int rc = 0; int rc = 0;
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
memset(Mil_Usn, 0, sizeof(Mil_Usn));
szReq[0] = NULL; szReq[0] = NULL;
if (AddressFamily == AF_INET) { if (AddressFamily == (unsigned short)AF_INET) {
DestAddr4->sin_family = AF_INET; DestAddr4->sin_family = AddressFamily;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { } else if (AddressFamily == (unsigned short)AF_INET6) {
DestAddr6->sin6_family = AF_INET6; DestAddr6->sin6_family = AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);
@@ -766,7 +760,7 @@ error_handler:
} }
int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server, int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server,
char *Location, int Duration, int AddressFamily, char *Location, int Duration, unsigned short AddressFamily,
int PowerState, int SleepPeriod, int RegistrationState) int PowerState, int SleepPeriod, int RegistrationState)
{ {
struct sockaddr_storage __ss; struct sockaddr_storage __ss;
@@ -781,13 +775,12 @@ int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *_Server,
msgs[1] = NULL; msgs[1] = NULL;
msgs[2] = NULL; msgs[2] = NULL;
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
memset(Mil_Usn, 0, sizeof(Mil_Usn)); if (AddressFamily == (unsigned short)AF_INET) {
if (AddressFamily == AF_INET) { DestAddr4->sin_family = AddressFamily;
DestAddr4->sin_family = (unsigned short)AF_INET;
inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr); inet_pton(AF_INET, SSDP_IP, &DestAddr4->sin_addr);
DestAddr4->sin_port = htons(SSDP_PORT); DestAddr4->sin_port = htons(SSDP_PORT);
} else if (AddressFamily == AF_INET6) { } else if (AddressFamily == (unsigned short)AF_INET6) {
DestAddr6->sin6_family = (unsigned short)AF_INET6; DestAddr6->sin6_family = AddressFamily;
inet_pton(AF_INET6, inet_pton(AF_INET6,
(isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL : (isUrlV6UlaGua(Location)) ? SSDP_IPV6_SITELOCAL :
SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr); SSDP_IPV6_LINKLOCAL, &DestAddr6->sin6_addr);