Add more explicit casts and remove dead code

Comment unused SERVER from DeviceShutdown.
Comment unused max from parse_hostport.
Comment unused nodeptr from ixmlNode_cloneDoc.
Comment unused newNode from Parser_hasDefaultNamespace.
Comment unused Parser_parseReference function
Check return code of shutdown and display an error if needed.

(forward port of commit cb07623ddece5c5cd1f2867336d92aee938a1334)
This commit is contained in:
Fabrice Fontaine 2012-03-15 14:49:26 +01:00 committed by Marcelo Roberto Jimenez
parent 21c881cbf9
commit 06f87abc2c
13 changed files with 164 additions and 123 deletions

View File

@ -318,6 +318,17 @@ Version 1.8.0
Version 1.6.16 Version 1.6.16
******************************************************************************* *******************************************************************************
2012-03-16 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Add more explicit casts and remove dead code
Comment unused SERVER from DeviceShutdown.
Comment unused max from parse_hostport.
Comment unused nodeptr from ixmlNode_cloneDoc.
Comment unused newNode from Parser_hasDefaultNamespace.
Comment unused Parser_parseReference function
Check return code of shutdown and display an error if needed.
2012-03-15 Fabrice Fontaine <fabrice.fontaine(at)orange.com> 2012-03-15 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Fix previous commit Fix previous commit

View File

@ -1096,7 +1096,7 @@ static char *safe_strdup(
assert(s != NULL); assert(s != NULL);
if (s == NULL) { if (s == NULL) {
return strdup(""); return strdup((const char*)"");
} }
return strdup(s); return strdup(s);
} }
@ -1215,7 +1215,7 @@ static int Parser_processCDSect(
IXML_Node *node) IXML_Node *node)
{ {
char *pEnd; char *pEnd;
size_t tokenLength = 0; size_t tokenLength = (size_t)0;
char *pCDataStart; char *pCDataStart;
if( *pSrc == NULL ) { if( *pSrc == NULL ) {
@ -1451,6 +1451,7 @@ ExitFunction:
* *
* \return IXML_SUCCESS. * \return IXML_SUCCESS.
*/ */
#if 0
static int Parser_parseReference( static int Parser_parseReference(
/*! [in] Currently unused. */ /*! [in] Currently unused. */
char *pStr) char *pStr)
@ -1459,6 +1460,7 @@ static int Parser_parseReference(
return IXML_SUCCESS; return IXML_SUCCESS;
pStr = pStr; pStr = pStr;
} }
#endif
/*! /*!
@ -1746,9 +1748,9 @@ static int Parser_processAttribute(
line = __LINE__; line = __LINE__;
goto ExitFunction; goto ExitFunction;
} }
if (*pCur == '&') { /*if (*pCur == '&') {
Parser_parseReference(++pCur); Parser_parseReference(++pCur);
} }*/
pCur++; pCur++;
} }
/* clear token buffer */ /* clear token buffer */
@ -1861,7 +1863,7 @@ static int Parser_getNextNode(
line = __LINE__; line = __LINE__;
ret = IXML_SUCCESS; ret = IXML_SUCCESS;
goto ExitFunction; goto ExitFunction;
} else if ((xmlParser->tokenBuf).length == 0) { } else if ((xmlParser->tokenBuf).length == (size_t)0) {
line = __LINE__; line = __LINE__;
ret = IXML_SYNTAX_ERR; ret = IXML_SYNTAX_ERR;
goto ExitFunction; goto ExitFunction;
@ -1901,8 +1903,16 @@ static int Parser_getNextNode(
line = __LINE__; line = __LINE__;
ret = IXML_SUCCESS; ret = IXML_SUCCESS;
goto ExitFunction; goto ExitFunction;
} else if (xmlParser->state == eATTRIBUTE && xmlParser->pCurElement != NULL) { } else if (xmlParser->pCurElement != NULL) {
if (Parser_processAttribute(xmlParser, node) != IXML_SUCCESS) { switch (xmlParser->state) {
case eATTRIBUTE:
if (Parser_processAttribute(xmlParser, node) != IXML_SUCCESS) {
line = __LINE__;
ret = IXML_SYNTAX_ERR;
goto ExitFunction;
}
break;
default:
line = __LINE__; line = __LINE__;
ret = IXML_SYNTAX_ERR; ret = IXML_SYNTAX_ERR;
goto ExitFunction; goto ExitFunction;
@ -2139,7 +2149,7 @@ static BOOL Parser_hasDefaultNamespace(
/*! [in] The XML parser. */ /*! [in] The XML parser. */
Parser *xmlParser, Parser *xmlParser,
/*! [in] The Node to process. */ /*! [in] The Node to process. */
IXML_Node *newNode, /*IXML_Node *newNode,*/
/*! [in,out] The name space URI. */ /*! [in,out] The name space URI. */
char **nsURI ) char **nsURI )
{ {
@ -2155,7 +2165,7 @@ static BOOL Parser_hasDefaultNamespace(
} }
return FALSE; return FALSE;
newNode = newNode; //newNode = newNode;
} }
@ -2208,7 +2218,7 @@ static int Parser_processElementName(
} else { } else {
/* does element has default namespace */ /* does element has default namespace */
/* the node may have default namespace definition */ /* the node may have default namespace definition */
if (Parser_hasDefaultNamespace(xmlParser, newNode, &nsURI)) { if (Parser_hasDefaultNamespace(xmlParser, /*newNode,*/ &nsURI)) {
Parser_setElementNamespace(newElement, nsURI); Parser_setElementNamespace(newElement, nsURI);
} else { } else {
switch (xmlParser->state) { switch (xmlParser->state) {
@ -2528,7 +2538,7 @@ static int Parser_readFileOrBuffer(
BOOL file) BOOL file)
{ {
long fileSize = 0; long fileSize = 0;
size_t bytesRead = 0; size_t bytesRead = (size_t)0;
FILE *xmlFilePtr = NULL; FILE *xmlFilePtr = NULL;
if( file ) { if( file ) {
@ -2543,7 +2553,7 @@ static int Parser_readFileOrBuffer(
return IXML_SYNTAX_ERR; return IXML_SYNTAX_ERR;
} }
xmlParser->dataBuffer = (char *)malloc((size_t)fileSize + 1); xmlParser->dataBuffer = (char *)malloc((size_t)fileSize + (size_t)1);
if( xmlParser->dataBuffer == NULL ) { if( xmlParser->dataBuffer == NULL ) {
fclose( xmlFilePtr ); fclose( xmlFilePtr );
return IXML_INSUFFICIENT_MEMORY; return IXML_INSUFFICIENT_MEMORY;

View File

@ -128,7 +128,7 @@ IXML_Node *ixmlNamedNodeMap_item(
unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap) unsigned long ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap)
{ {
IXML_Node *tempNode; IXML_Node *tempNode;
unsigned long length = 0; unsigned long length = 0lu;
if (nnMap != NULL) { if (nnMap != NULL) {
tempNode = nnMap->nodeItem; tempNode = nnMap->nodeItem;

View File

@ -776,13 +776,13 @@ static IXML_Element *ixmlNode_cloneElement(
*/ */
static IXML_Document *ixmlNode_cloneDoc( static IXML_Document *ixmlNode_cloneDoc(
/*! [in] The \b Node to clone. */ /*! [in] The \b Node to clone. */
IXML_Document *nodeptr) /*IXML_Document *nodeptr*/)
{ {
IXML_Document *newDoc; IXML_Document *newDoc;
IXML_Node *docNode; IXML_Node *docNode;
int rc; int rc;
assert(nodeptr != NULL); //assert(nodeptr != NULL);
newDoc = (IXML_Document *)malloc(sizeof (IXML_Document)); newDoc = (IXML_Document *)malloc(sizeof (IXML_Document));
if (newDoc == NULL) { if (newDoc == NULL) {
@ -801,7 +801,7 @@ static IXML_Document *ixmlNode_cloneDoc(
newDoc->n.nodeType = eDOCUMENT_NODE; newDoc->n.nodeType = eDOCUMENT_NODE;
return newDoc; return newDoc;
nodeptr = nodeptr; //nodeptr = nodeptr;
} }
/*! /*!
@ -968,7 +968,7 @@ static IXML_Node *ixmlNode_cloneNodeTreeRecursive(
break; break;
case eDOCUMENT_NODE: case eDOCUMENT_NODE:
newDoc = ixmlNode_cloneDoc((IXML_Document *)nodeptr); newDoc = ixmlNode_cloneDoc(/*(IXML_Document *)nodeptr*/);
if (newDoc == NULL) if (newDoc == NULL)
return NULL; return NULL;
newNode = (IXML_Node *)newDoc; newNode = (IXML_Node *)newDoc;

View File

@ -83,18 +83,18 @@ static void StatsInit(
/*! Must be valid non null stats structure. */ /*! Must be valid non null stats structure. */
ThreadPoolStats *stats) ThreadPoolStats *stats)
{ {
stats->totalIdleTime = 0; stats->totalIdleTime = 0.0;
stats->totalJobsHQ = 0; stats->totalJobsHQ = 0;
stats->totalJobsLQ = 0; stats->totalJobsLQ = 0;
stats->totalJobsMQ = 0; stats->totalJobsMQ = 0;
stats->totalTimeHQ = 0; stats->totalTimeHQ = 0.0;
stats->totalTimeMQ = 0; stats->totalTimeMQ = 0.0;
stats->totalTimeLQ = 0; stats->totalTimeLQ = 0.0;
stats->totalWorkTime = 0; stats->totalWorkTime = 0.0;
stats->totalIdleTime = 0; stats->totalIdleTime = 0.0;
stats->avgWaitHQ = 0; stats->avgWaitHQ = 0.0;
stats->avgWaitMQ = 0; stats->avgWaitMQ = 0.0;
stats->avgWaitLQ = 0; stats->avgWaitLQ = 0.0;
stats->workerThreads = 0; stats->workerThreads = 0;
stats->idleThreads = 0; stats->idleThreads = 0;
stats->persistentThreads = 0; stats->persistentThreads = 0;
@ -1205,7 +1205,7 @@ int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
if (stats->totalJobsHQ > 0) if (stats->totalJobsHQ > 0)
stats->avgWaitHQ = stats->totalTimeHQ / (double)stats->totalJobsHQ; stats->avgWaitHQ = stats->totalTimeHQ / (double)stats->totalJobsHQ;
else else
stats->avgWaitHQ = 0; stats->avgWaitHQ = 0.0;
if (stats->totalJobsMQ > 0) if (stats->totalJobsMQ > 0)
stats->avgWaitMQ = stats->totalTimeMQ / (double)stats->totalJobsMQ; stats->avgWaitMQ = stats->totalTimeMQ / (double)stats->totalJobsMQ;
else else

View File

@ -251,7 +251,7 @@ static parse_status_t scanner_get_token(
/* possibly more valid chars */ /* possibly more valid chars */
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
/* calc token length */ /* calc token length */
token->length = (size_t)(cursor - token->buf); token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == ' ' || c == '\t') { } else if (c == ' ' || c == '\t') {
token->buf = cursor++; token->buf = cursor++;
token_type = TT_WHITESPACE; token_type = TT_WHITESPACE;
@ -260,7 +260,7 @@ static parse_status_t scanner_get_token(
if (!scanner->entire_msg_loaded && cursor == null_terminator) if (!scanner->entire_msg_loaded && cursor == null_terminator)
/* possibly more chars */ /* possibly more chars */
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
token->length = (size_t)(cursor - token->buf); token->length = (size_t)cursor - (size_t)token->buf;
} else if (c == TOKCHAR_CR) { } else if (c == TOKCHAR_CR) {
/* scan CRLF */ /* scan CRLF */
token->buf = cursor++; token->buf = cursor++;
@ -306,7 +306,7 @@ static parse_status_t scanner_get_token(
return PARSE_FAILURE; return PARSE_FAILURE;
} }
if (got_end_quote) if (got_end_quote)
token->length = (size_t)(cursor - token->buf); token->length = (size_t)cursor - (size_t)token->buf;
else { /* incomplete */ else { /* incomplete */
assert(cursor == null_terminator); assert(cursor == null_terminator);
@ -1416,7 +1416,7 @@ parse_status_t parser_parse_responseline(INOUT http_parser_t *parser)
while (*p == ' ' || *p == '\t') while (*p == ' ' || *p == '\t')
p++; p++;
/* now, p is at start of status msg */ /* 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) { if (membuffer_assign(&hmsg->status_msg, p, n) != 0) {
/* out of mem */ /* out of mem */
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR; parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
@ -1737,7 +1737,7 @@ parser_parse_chunky_entity( INOUT http_parser_t * parser )
( scanner->cursor - save_pos ) ); ( scanner->cursor - save_pos ) );
scanner->cursor = save_pos; /* adjust scanner too */ scanner->cursor = save_pos; /* adjust scanner too */
if( parser->chunk_size == 0 ) { if( parser->chunk_size == (size_t)0 ) {
/* done reading entity; determine length of entity */ /* done reading entity; determine length of entity */
parser->msg.entity.length = parser->scanner.cursor - parser->msg.entity.length = parser->scanner.cursor -
parser->entity_start_position + parser->msg.amount_discarded; parser->entity_start_position + parser->msg.amount_discarded;

View File

@ -280,6 +280,7 @@ SOCKET http_Connect(
SOCKET connfd; SOCKET connfd;
socklen_t sockaddr_len; socklen_t sockaddr_len;
int ret_connect; int ret_connect;
char errorBuffer[ERROR_BUFFER_LEN];
http_FixUrl(destination_url, url); http_FixUrl(destination_url, url);
@ -297,7 +298,11 @@ SOCKET http_Connect(
UpnpPrintf(UPNP_CRITICAL, HTTP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, HTTP, __FILE__, __LINE__,
"connect error: %d\n", WSAGetLastError()); "connect error: %d\n", WSAGetLastError());
#endif #endif
shutdown(connfd, SD_BOTH); if (shutdown(connfd, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(connfd); UpnpCloseSocket(connfd);
return (SOCKET)(UPNP_E_SOCKET_CONNECT); return (SOCKET)(UPNP_E_SOCKET_CONNECT);
} }
@ -1501,7 +1506,7 @@ int http_MakeMessage(membuffer *buf, int http_major_version,
/* mem buffer */ /* mem buffer */
s = (char *)va_arg(argp, char *); s = (char *)va_arg(argp, char *);
UpnpPrintf(UPNP_ALL, HTTP, __FILE__, __LINE__, UpnpPrintf(UPNP_ALL, HTTP, __FILE__, __LINE__,
"Adding a char Buffer starting with: %c\n", s[0]); "Adding a char Buffer starting with: %c\n", (int)s[0]);
assert(s); assert(s);
length = (size_t) va_arg(argp, size_t); length = (size_t) va_arg(argp, size_t);
if (membuffer_append(buf, s, length)) if (membuffer_append(buf, s, length))

View File

@ -48,6 +48,9 @@
#include "upnp.h" #include "upnp.h"
#include "UpnpStdInt.h" /* for ssize_t */ #include "UpnpStdInt.h" /* for ssize_t */
#include "upnpdebug.h"
#include "upnputil.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> /* for F_GETFL, F_SETFL, O_NONBLOCK */ #include <fcntl.h> /* for F_GETFL, F_SETFL, O_NONBLOCK */
@ -115,16 +118,21 @@ int sock_ssl_connect(SOCKINFO *info)
int sock_destroy(SOCKINFO *info, int ShutdownMethod) int sock_destroy(SOCKINFO *info, int ShutdownMethod)
{ {
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
char errorBuffer[ERROR_BUFFER_LEN];
if (info->socket != INVALID_SOCKET) { if (info->socket != INVALID_SOCKET) {
#ifdef UPNP_ENABLE_OPEN_SSL #ifdef UPNP_ENABLE_OPEN_SSL
if (info->ssl) { if (info->ssl) {
SSL_shutdown(info->ssl); SSL_shutdown(info->ssl);
SSL_free(info->ssl); SSL_free(info->ssl);
info->ssl = NULL; info->ssl = NULL;
} }
#endif #endif
shutdown(info->socket, ShutdownMethod); if (shutdown(info->socket, ShutdownMethod) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
if (sock_close(info->socket) == -1) { if (sock_close(info->socket) == -1) {
ret = UPNP_E_SOCKET_ERROR; ret = UPNP_E_SOCKET_ERROR;
} }
@ -163,7 +171,7 @@ static int sock_read_write(
time_t start_time = time(NULL); time_t start_time = time(NULL);
SOCKET sockfd = info->socket; SOCKET sockfd = info->socket;
long bytes_sent = 0; long bytes_sent = 0;
size_t byte_left = 0; size_t byte_left = (size_t)0;
ssize_t num_written; ssize_t num_written;
if (*timeoutSecs < 0) if (*timeoutSecs < 0)
@ -217,7 +225,7 @@ static int sock_read_write(
} else { } else {
byte_left = bufsize; byte_left = bufsize;
bytes_sent = 0; bytes_sent = 0;
while (byte_left != 0) { while (byte_left != (size_t)0) {
#ifdef UPNP_ENABLE_OPEN_SSL #ifdef UPNP_ENABLE_OPEN_SSL
if (info->ssl) { if (info->ssl) {
num_written = SSL_write(info->ssl, num_written = SSL_write(info->ssl,

View File

@ -315,7 +315,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,*/
unsigned short int defaultPort, unsigned short int defaultPort,
hostport_type *out) hostport_type *out)
{ {
@ -447,7 +447,7 @@ int parse_hostport(
out->text.buff = in; out->text.buff = in;
return (int)hostport_size; return (int)hostport_size;
max = max; //max=max;
} }
/*! /*!
@ -711,7 +711,7 @@ 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) {

View File

@ -502,7 +502,7 @@ int DeviceShutdown(
/* [in] Device UDN. */ /* [in] Device UDN. */
char *Udn, char *Udn,
/* [in] . */ /* [in] . */
char *_Server, /*char *_Server,*/
/* [in] Location URL. */ /* [in] Location URL. */
char *Location, char *Location,
/* [in] Device duration in sec. */ /* [in] Device duration in sec. */

View File

@ -287,7 +287,7 @@ int parse_hostport(
/*! [in] String of characters representing host and port. */ /*! [in] String of characters representing host and port. */
const char *in, const char *in,
/*! [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. */
unsigned short 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

View File

@ -119,8 +119,11 @@ void ssdp_handle_device_request(http_message_t *hmsg, struct sockaddr_storage *d
HandleLock(); HandleLock();
/* device info. */ /* device info. */
if (GetDeviceHandleInfo(dest_addr->ss_family, switch (GetDeviceHandleInfo((int)dest_addr->ss_family,
&handle, &dev_info) != HND_DEVICE) { &handle, &dev_info)) {
case HND_DEVICE:
break;
default:
HandleUnlock(); HandleUnlock();
/* no info found. */ /* no info found. */
return; return;
@ -241,7 +244,12 @@ static int NewRequestHandler(
} }
end_NewRequestHandler: end_NewRequestHandler:
shutdown(ReplySock, SD_BOTH); ret = shutdown(ReplySock, SD_BOTH);
if (ret == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(ReplySock); UpnpCloseSocket(ReplySock);
return ret; return ret;
@ -823,7 +831,7 @@ error_handler:
return RetVal; return RetVal;
} }
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, int AddressFamily,
int PowerState, int SleepPeriod, int RegistrationState) int PowerState, int SleepPeriod, int RegistrationState)
{ {
@ -903,7 +911,7 @@ error_handler:
free(msgs[2]); free(msgs[2]);
return ret_code; return ret_code;
_Server = _Server; //_Server = _Server;
} }
#endif /* EXCLUDE_SSDP */ #endif /* EXCLUDE_SSDP */
#endif /* INCLUDE_DEVICE_APIS */ #endif /* INCLUDE_DEVICE_APIS */

View File

@ -108,7 +108,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
IXML_Node *tmpNode2 = NULL; IXML_Node *tmpNode2 = NULL;
IXML_Node *textNode = NULL; IXML_Node *textNode = NULL;
const DOMString tmpStr; const DOMString tmpStr;
char SERVER[200]; //char SERVER[200];
const DOMString dbgStr; const DOMString dbgStr;
int NumCopy = 0; int NumCopy = 0;
@ -127,7 +127,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} }
defaultExp = SInfo->MaxAge; defaultExp = SInfo->MaxAge;
/* get server info */ /* get server info */
get_sdk_info(SERVER); //get_sdk_info(SERVER);
/* parse the device list and send advertisements/replies */ /* parse the device list and send advertisements/replies */
while (NumCopy == 0 || (AdFlag && NumCopy < NUM_SSDP_COPY)) { while (NumCopy == 0 || (AdFlag && NumCopy < NUM_SSDP_COPY)) {
if (NumCopy != 0) if (NumCopy != 0)
@ -218,7 +218,7 @@ int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd,
} else { } else {
/* AdFlag == -1 */ /* AdFlag == -1 */
DeviceShutdown(devType, i == 0lu, UDNstr, DeviceShutdown(devType, i == 0lu, UDNstr,
SERVER, SInfo->DescURL, /*SERVER,*/ SInfo->DescURL,
Exp, SInfo->DeviceAf, Exp, SInfo->DeviceAf,
SInfo->PowerState, SInfo->PowerState,
SInfo->SleepPeriod, SInfo->SleepPeriod,
@ -812,10 +812,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n", "Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__) #if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1; onOff = 1;
@ -826,10 +824,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n", "Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#endif /* BSD, __OSX__, __APPLE__ */ #endif /* BSD, __OSX__, __APPLE__ */
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
@ -842,10 +838,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%08X, port=%d: %s\n", "Error in bind(), addr=0x%08X, port=%d: %s\n",
INADDR_ANY, SSDP_PORT, errorBuffer); INADDR_ANY, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_BIND;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_BIND;
} }
memset((void *)&ssdpMcastAddr, 0, sizeof(struct ip_mreq)); memset((void *)&ssdpMcastAddr, 0, sizeof(struct ip_mreq));
ssdpMcastAddr.imr_interface.s_addr = inet_addr(gIF_IPV4); ssdpMcastAddr.imr_interface.s_addr = inet_addr(gIF_IPV4);
@ -857,10 +851,8 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IP_ADD_MEMBERSHIP (join multicast group): %s\n", "Error in setsockopt() IP_ADD_MEMBERSHIP (join multicast group): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
/* Set multicast interface. */ /* Set multicast interface. */
memset((void *)&addr, 0, sizeof(struct in_addr)); memset((void *)&addr, 0, sizeof(struct in_addr));
@ -885,13 +877,22 @@ static int create_ssdp_sock_v4(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n", "Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_NETWORK_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR; error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
} }
return UPNP_E_SUCCESS; return ret;
} }
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -953,10 +954,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n", "Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__) #if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1; onOff = 1;
@ -967,10 +966,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n", "Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#endif /* BSD, __OSX__, __APPLE__ */ #endif /* BSD, __OSX__, __APPLE__ */
onOff = 1; onOff = 1;
@ -981,10 +978,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_V6ONLY: %s\n", "Error in setsockopt() IPV6_V6ONLY: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = (sa_family_t)AF_INET6; ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
@ -997,10 +992,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%032lX, port=%d: %s\n", "Error in bind(), addr=0x%032lX, port=%d: %s\n",
0lu, SSDP_PORT, errorBuffer); 0lu, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_BIND;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_BIND;
} }
memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr)); memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr));
ssdpMcastAddr.ipv6mr_interface = gIF_INDEX; ssdpMcastAddr.ipv6mr_interface = gIF_INDEX;
@ -1013,10 +1006,8 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n", "Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
onOff = 1; onOff = 1;
ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST, ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST,
@ -1026,13 +1017,22 @@ static int create_ssdp_sock_v6(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n", "Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_NETWORK_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR; error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
} }
return UPNP_E_SUCCESS; return ret;
} }
#endif /* IPv6 */ #endif /* IPv6 */
@ -1067,10 +1067,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEADDR: %s\n", "Error in setsockopt() SO_REUSEADDR: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#if defined(BSD) || defined(__OSX__) || defined(__APPLE__) #if defined(BSD) || defined(__OSX__) || defined(__APPLE__)
onOff = 1; onOff = 1;
@ -1081,10 +1079,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_REUSEPORT: %s\n", "Error in setsockopt() SO_REUSEPORT: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
#endif /* BSD, __OSX__, __APPLE__ */ #endif /* BSD, __OSX__, __APPLE__ */
onOff = 1; onOff = 1;
@ -1095,10 +1091,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_V6ONLY: %s\n", "Error in setsockopt() IPV6_V6ONLY: %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
memset(&__ss, 0, sizeof(__ss)); memset(&__ss, 0, sizeof(__ss));
ssdpAddr6->sin6_family = (sa_family_t)AF_INET6; ssdpAddr6->sin6_family = (sa_family_t)AF_INET6;
@ -1111,10 +1105,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in bind(), addr=0x%032lX, port=%d: %s\n", "Error in bind(), addr=0x%032lX, port=%d: %s\n",
0lu, SSDP_PORT, errorBuffer); 0lu, SSDP_PORT, errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_BIND;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_BIND;
} }
memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr)); memset((void *)&ssdpMcastAddr, 0, sizeof(ssdpMcastAddr));
ssdpMcastAddr.ipv6mr_interface = gIF_INDEX; ssdpMcastAddr.ipv6mr_interface = gIF_INDEX;
@ -1128,10 +1120,8 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n", "Error in setsockopt() IPV6_JOIN_GROUP (join multicast group): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_SOCKET_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
return UPNP_E_SOCKET_ERROR;
} }
onOff = 1; onOff = 1;
ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST, ret = setsockopt(*ssdpSock, SOL_SOCKET, SO_BROADCAST,
@ -1141,13 +1131,22 @@ static int create_ssdp_sock_v6_ula_gua(
UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
"Error in setsockopt() SO_BROADCAST (set broadcast): %s\n", "Error in setsockopt() SO_BROADCAST (set broadcast): %s\n",
errorBuffer); errorBuffer);
shutdown(*ssdpSock, SD_BOTH); ret = UPNP_E_NETWORK_ERROR;
UpnpCloseSocket(*ssdpSock); goto error_handler;
}
ret = UPNP_E_SUCCESS;
return UPNP_E_NETWORK_ERROR; error_handler:
if (ret != UPNP_E_SUCCESS) {
if (shutdown(*ssdpSock, SD_BOTH) == -1) {
strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
"Error in shutdown: %s\n", errorBuffer);
}
UpnpCloseSocket(*ssdpSock);
} }
return UPNP_E_SUCCESS; return ret;
} }
#endif /* IPv6 */ #endif /* IPv6 */