Remove more implicit casts in upnp part

Remove more "implicit integer or enum conversions" as well as memset
before snprintf.

(forward port of commit 2eb3e069badd5c8676738c3ead37f9551fd8448e)
This commit is contained in:
Fabrice Fontaine 2012-03-10 21:27:55 +01:00 committed by Marcelo Roberto Jimenez
parent e2de269593
commit d56a68d771
12 changed files with 96 additions and 86 deletions

View File

@ -318,6 +318,13 @@ Version 1.8.0
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

@ -1313,9 +1313,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
@ -337,7 +337,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);
@ -348,12 +348,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;
@ -362,19 +363,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) {
@ -427,7 +430,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;
@ -482,7 +485,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) {
@ -490,9 +493,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";
@ -529,10 +532,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 {
@ -559,7 +562,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__,
@ -619,7 +622,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;
@ -1225,8 +1228,11 @@ int http_GetHttpResponse(void *Handle, UpnpString *headers,
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;
} }
@ -1242,7 +1248,7 @@ int http_GetHttpResponse(void *Handle, UpnpString *headers,
*contentType = ctype.buf; *contentType = ctype.buf;
} }
if (contentLength) { if (contentLength) {
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;
@ -1404,7 +1410,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:
@ -147,7 +148,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. */
@ -164,6 +165,8 @@ static int sock_read_write(
long byte_left = 0; long byte_left = 0;
long num_written; long num_written;
if (*timeoutSecs < 0)
return UPNP_E_TIMEDOUT;
FD_ZERO(&readSet); FD_ZERO(&readSet);
FD_ZERO(&writeSet); FD_ZERO(&writeSet);
if (bRead) if (bRead)
@ -173,7 +176,7 @@ static int sock_read_write(
timeout.tv_sec = *timeoutSecs; timeout.tv_sec = *timeoutSecs;
timeout.tv_usec = 0; timeout.tv_usec = 0;
while (TRUE) { while (TRUE) {
if (*timeoutSecs < 0) if (*timeoutSecs == 0)
retCode = select(sockfd + 1, &readSet, &writeSet, retCode = select(sockfd + 1, &readSet, &writeSet,
NULL, NULL); NULL, NULL);
else else
@ -206,7 +209,7 @@ static int sock_read_write(
else { else {
#endif #endif
/* read data. */ /* read data. */
numBytes = (long)recv(sockfd, buffer, (size_t)bufsize, MSG_NOSIGNAL); numBytes = (long)recv(sockfd, buffer, bufsize, MSG_NOSIGNAL);
#ifdef UPNP_ENABLE_OPEN_SSL #ifdef UPNP_ENABLE_OPEN_SSL
} }
#endif #endif
@ -253,12 +256,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;
} }
@ -316,7 +316,7 @@ int token_cmp(token *in1, token *in2)
int parse_hostport( int parse_hostport(
const char *in, const char *in,
size_t max, size_t max,
int defaultPort, unsigned short int defaultPort,
hostport_type *out) hostport_type *out)
{ {
char workbuf[256]; char workbuf[256];
@ -327,7 +327,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;
@ -408,27 +408,26 @@ int parse_hostport(
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 = defaultPort; port = defaultPort;
}
/* 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);
@ -686,7 +685,7 @@ int parse_uri(const char *in, size_t max, uri_type *out)
int begin_path = 0; int begin_path = 0;
size_t begin_hostport = (size_t)0; size_t begin_hostport = (size_t)0;
size_t begin_fragment = (size_t)0; size_t begin_fragment = (size_t)0;
int defaultPort = 80; unsigned short int defaultPort = 80;
begin_hostport = parse_scheme(in, max, &out->scheme); begin_hostport = parse_scheme(in, max, &out->scheme);
if (begin_hostport) { if (begin_hostport) {
@ -705,9 +704,9 @@ int parse_uri(const char *in, size_t max, uri_type *out)
defaultPort = 443; defaultPort = 443;
} }
begin_path = parse_hostport(&in[begin_hostport], begin_path = parse_hostport(&in[begin_hostport],
max - begin_hostport, max - begin_hostport,
defaultPort, defaultPort,
&out->hostport); &out->hostport);
if (begin_path >= 0) { if (begin_path >= 0) {
begin_path += (int)begin_hostport; begin_path += (int)begin_hostport;
} else } else

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:
@ -164,7 +165,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);
@ -182,7 +183,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

@ -289,7 +289,7 @@ int parse_hostport(
/*! [in] Sets a maximum limit. */ /*! [in] Sets a maximum limit. */
size_t max, size_t max,
/*! [in] The default port if the port is not specified. */ /*! [in] The default port if the port is not specified. */
int defaultPort, unsigned short int defaultPort,
/*! [out] Output parameter where the host and port are represented as /*! [out] Output parameter where the host and port are represented as
* an internet address. */ * an internet address. */
hostport_type *out); hostport_type *out);

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);