gena: fix several compiler warnings.

This commit is contained in:
Marcelo Roberto Jimenez 2010-11-20 13:48:50 -02:00
parent 5bb8ee4b02
commit 2685b5bb65
13 changed files with 231 additions and 307 deletions

View File

@ -122,6 +122,8 @@ genaCallback( IN http_parser_t * parser,
/* handle missing functions of device or ctrl pt */ /* handle missing functions of device or ctrl pt */
error_respond( info, HTTP_NOT_IMPLEMENTED, request ); error_respond( info, HTTP_NOT_IMPLEMENTED, request );
} }
return;
parser = parser;
} }
#endif /* EXCLUDE_GENA */ #endif /* EXCLUDE_GENA */

View File

@ -271,7 +271,7 @@ static int genaNotify(
/*! [in] subscription to be Notified, assumes this is valid for life of function. */ /*! [in] subscription to be Notified, assumes this is valid for life of function. */
subscription *sub) subscription *sub)
{ {
int i; size_t i;
membuffer mid_msg; membuffer mid_msg;
membuffer endmsg; membuffer endmsg;
uri_type *url; uri_type *url;
@ -1134,7 +1134,7 @@ static int create_url_list(
/*! [out] . */ /*! [out] . */
URL_list *out) URL_list *out)
{ {
int URLcount = 0; size_t URLcount = 0;
size_t i; size_t i;
int return_code = 0; int return_code = 0;
uri_type temp; uri_type temp;
@ -1165,12 +1165,11 @@ static int create_url_list(
} }
if( URLcount > 0 ) { if( URLcount > 0 ) {
out->URLs = ( char * )malloc( URLS->size + 1 ); out->URLs = malloc(URLS->size + 1);
out->parsedURLs = out->parsedURLs = malloc(sizeof(uri_type) * URLcount);
( uri_type * ) malloc( sizeof( uri_type ) * URLcount ); if (!out->URLs || !out->parsedURLs) {
if( ( out->URLs == NULL ) || ( out->parsedURLs == NULL ) ) { free(out->URLs);
free( out->URLs ); free(out->parsedURLs);
free( out->parsedURLs );
out->URLs = NULL; out->URLs = NULL;
out->parsedURLs = NULL; out->parsedURLs = NULL;
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
@ -1201,7 +1200,7 @@ static int create_url_list(
} }
out->size = URLcount; out->size = URLcount;
return URLcount; return (int)URLcount;
} }

View File

@ -92,7 +92,7 @@ typedef enum {
/*! . */ /*! . */
unsigned short miniStopSockPort; uint16_t miniStopSockPort;
/*! /*!
@ -342,7 +342,7 @@ static void ssdp_read(SOCKET rsock, fd_set *set)
static int receive_from_stopSock(SOCKET ssock, fd_set *set) static int receive_from_stopSock(SOCKET ssock, fd_set *set)
{ {
int byteReceived; ssize_t byteReceived;
socklen_t clientLen; socklen_t clientLen;
struct sockaddr_storage clientAddr; struct sockaddr_storage clientAddr;
char requestBuf[256]; char requestBuf[256];
@ -460,16 +460,17 @@ static void RunMiniServer(
/*! /*!
* \brief Returns port to which socket, sockfd, is bound. * \brief Returns port to which socket, sockfd, is bound.
* *
* \return -1 on error; check errno, otherwise > 0 means port number. * \return -1 on error; check errno. 0 if successfull.
*/ */
static int get_port( static int get_port(
/*! [in] Socket descriptor. */ /*! [in] Socket descriptor. */
SOCKET sockfd) SOCKET sockfd,
/*! [out] The port value if successful, otherwise, untouched. */
uint16_t *port)
{ {
struct sockaddr_storage sockinfo; struct sockaddr_storage sockinfo;
socklen_t len; socklen_t len;
int code; int code;
int port = 0;
len = sizeof(sockinfo); len = sizeof(sockinfo);
code = getsockname(sockfd, (struct sockaddr *)&sockinfo, &len); code = getsockname(sockfd, (struct sockaddr *)&sockinfo, &len);
@ -477,14 +478,14 @@ static int get_port(
return -1; return -1;
} }
if (sockinfo.ss_family == AF_INET) { if (sockinfo.ss_family == AF_INET) {
port = ntohs(((struct sockaddr_in*)&sockinfo)->sin_port); *port = ntohs(((struct sockaddr_in*)&sockinfo)->sin_port);
} else if(sockinfo.ss_family == AF_INET6) { } else if(sockinfo.ss_family == AF_INET6) {
port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port); *port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port);
} }
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
"sockfd = %d, .... port = %d\n", sockfd, port); "sockfd = %d, .... port = %d\n", sockfd, port);
return port; return 0;
} }
@ -509,10 +510,10 @@ static int get_miniserver_sockets(
MiniServerSockArray *out, MiniServerSockArray *out,
/*! [in] port on which the server is listening for incoming IPv4 /*! [in] port on which the server is listening for incoming IPv4
* connections. */ * connections. */
unsigned short listen_port4, uint16_t listen_port4,
/*! [in] port on which the server is listening for incoming IPv6 /*! [in] port on which the server is listening for incoming IPv6
* connections. */ * connections. */
unsigned short listen_port6) uint16_t listen_port6)
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
struct sockaddr_storage __ss_v4; struct sockaddr_storage __ss_v4;
@ -723,8 +724,8 @@ static int get_miniserver_sockets(
#endif #endif
return UPNP_E_LISTEN; return UPNP_E_LISTEN;
} }
actual_port4 = get_port(listenfd4); ret_code = get_port(listenfd4, &actual_port4);
if (actual_port4 <= 0) { if (ret_code < 0) {
sock_close(listenfd4); sock_close(listenfd4);
#ifdef UPNP_ENABLE_IPV6 #ifdef UPNP_ENABLE_IPV6
sock_close(listenfd6); sock_close(listenfd6);
@ -745,8 +746,8 @@ static int get_miniserver_sockets(
sock_close(listenfd6); sock_close(listenfd6);
return UPNP_E_LISTEN; return UPNP_E_LISTEN;
} }
actual_port6 = get_port(listenfd6); ret_code = get_port(listenfd6, &actual_port6);
if (actual_port6 <= 0) { if (ret_code <= 0) {
sock_close(listenfd4); sock_close(listenfd4);
sock_close(listenfd6); sock_close(listenfd6);
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
@ -802,8 +803,8 @@ static int get_miniserver_stopsock(
sock_close(miniServerStopSock); sock_close(miniServerStopSock);
return UPNP_E_SOCKET_BIND; return UPNP_E_SOCKET_BIND;
} }
miniStopSockPort = get_port( miniServerStopSock ); ret = get_port(miniServerStopSock, &miniStopSockPort);
if (miniStopSockPort <= 0) { if (ret < 0) {
sock_close(miniServerStopSock); sock_close(miniServerStopSock);
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
@ -821,9 +822,9 @@ static UPNP_INLINE void InitMiniServerSockArray(MiniServerSockArray *miniSocket)
miniSocket->ssdpSock4 = INVALID_SOCKET; miniSocket->ssdpSock4 = INVALID_SOCKET;
miniSocket->ssdpSock6 = INVALID_SOCKET; miniSocket->ssdpSock6 = INVALID_SOCKET;
miniSocket->ssdpSock6UlaGua = INVALID_SOCKET; miniSocket->ssdpSock6UlaGua = INVALID_SOCKET;
miniSocket->stopPort = -1; miniSocket->stopPort = 0;
miniSocket->miniServerPort4 = -1; miniSocket->miniServerPort4 = 0;
miniSocket->miniServerPort6 = -1; miniSocket->miniServerPort6 = 0;
miniSocket->ssdpReqSock4 = INVALID_SOCKET; miniSocket->ssdpReqSock4 = INVALID_SOCKET;
miniSocket->ssdpReqSock6 = INVALID_SOCKET; miniSocket->ssdpReqSock6 = INVALID_SOCKET;
} }
@ -924,7 +925,7 @@ int StartMiniServer(
int StopMiniServer() int StopMiniServer()
{ {
char errorBuffer[ERROR_BUFFER_LEN]; char errorBuffer[ERROR_BUFFER_LEN];
int socklen = sizeof (struct sockaddr_in); socklen_t socklen = sizeof (struct sockaddr_in);
SOCKET sock; SOCKET sock;
struct sockaddr_in ssdpAddr; struct sockaddr_in ssdpAddr;
char buf[256] = "ShutDown"; char buf[256] = "ShutDown";
@ -947,7 +948,7 @@ int StopMiniServer()
ssdpAddr.sin_family = AF_INET; ssdpAddr.sin_family = AF_INET;
ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ssdpAddr.sin_port = htons(miniStopSockPort); ssdpAddr.sin_port = htons(miniStopSockPort);
sendto(sock, buf, (int)bufLen, 0, sendto(sock, buf, bufLen, 0,
(struct sockaddr *)&ssdpAddr, socklen); (struct sockaddr *)&ssdpAddr, socklen);
usleep(1000); usleep(1000);
if (gMServState == MSERV_IDLE) { if (gMServState == MSERV_IDLE) {

View File

@ -240,21 +240,6 @@ static int private_connect(
#endif /* UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS */ #endif /* UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS */
} }
/************************************************************************
* Function: http_FixUrl
*
* Parameters:
* IN uri_type* url; URL to be validated and fixed
* OUT uri_type* fixed_url; URL after being fixed.
*
* Description:
* Validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
int http_FixUrl(IN uri_type *url, OUT uri_type *fixed_url) int http_FixUrl(IN uri_type *url, OUT uri_type *fixed_url)
{ {
char *temp_path = "/"; char *temp_path = "/";
@ -275,26 +260,10 @@ int http_FixUrl(IN uri_type *url, OUT uri_type *fixed_url)
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/************************************************************************
* Function: http_FixStrUrl
*
* Parameters:
* IN const char* urlstr; Character string as a URL
* IN int urlstrlen; Length of the character string
* OUT uri_type* fixed_url; Fixed and corrected URL
*
* Description:
* Parses URL and then validates URL
*
* Returns:
* UPNP_E_INVALID_URL
* UPNP_E_SUCCESS
************************************************************************/
int http_FixStrUrl( int http_FixStrUrl(
IN const char *urlstr, IN const char *urlstr,
IN int urlstrlen, IN size_t urlstrlen,
OUT uri_type * fixed_url) OUT uri_type *fixed_url)
{ {
uri_type url; uri_type url;
@ -305,7 +274,6 @@ int http_FixStrUrl(
return http_FixUrl(&url, fixed_url); return http_FixUrl(&url, fixed_url);
} }
/************************************************************************ /************************************************************************
* Function: http_Connect * Function: http_Connect
* *

View File

@ -310,12 +310,11 @@ static UPNP_INLINE int get_content_type(
const char *extension; const char *extension;
const char *type; const char *type;
const char *subtype; const char *subtype;
xboolean ctype_found = FALSE; int ctype_found = FALSE;
char *temp = NULL; char *temp = NULL;
int length = 0; size_t length = 0;
UpnpFileInfo_set_ContentType(fileInfo, NULL); UpnpFileInfo_set_ContentType(fileInfo, NULL);
/* get ext */ /* get ext */
extension = strrchr(filename, '.'); extension = strrchr(filename, '.');
if (extension != NULL) { if (extension != NULL) {
@ -323,15 +322,13 @@ static UPNP_INLINE int get_content_type(
ctype_found = TRUE; ctype_found = TRUE;
} }
} }
if (!ctype_found) { if (!ctype_found) {
/* unknown content type */ /* unknown content type */
type = gMediaTypes[APPLICATION_INDEX]; type = gMediaTypes[APPLICATION_INDEX];
subtype = "octet-stream"; subtype = "octet-stream";
} }
length = strlen(type) + strlen("/") + strlen(subtype) + 1; length = strlen(type) + strlen("/") + strlen(subtype) + 1;
temp = (char *)malloc(length); temp = malloc(length);
if (!temp) { if (!temp) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
@ -342,7 +339,6 @@ static UPNP_INLINE int get_content_type(
if (!UpnpFileInfo_get_ContentType(fileInfo)) { if (!UpnpFileInfo_get_ContentType(fileInfo)) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
return 0; return 0;
} }
@ -365,7 +361,7 @@ static UPNP_INLINE void glob_alias_init(void)
* *
* \return BOOLEAN. * \return BOOLEAN.
*/ */
static UPNP_INLINE xboolean is_valid_alias( static UPNP_INLINE int is_valid_alias(
/*! [in] XML alias object. */ /*! [in] XML alias object. */
const struct xml_alias_t *alias) const struct xml_alias_t *alias)
{ {
@ -568,7 +564,7 @@ static int get_file_info(
int web_server_set_root_dir(const char *root_dir) int web_server_set_root_dir(const char *root_dir)
{ {
int index; size_t index;
int ret; int ret;
ret = membuffer_assign_str(&gDocumentRootDir, root_dir); ret = membuffer_assign_str(&gDocumentRootDir, root_dir);
@ -594,7 +590,7 @@ int web_server_set_root_dir(const char *root_dir)
* \li \c TRUE - On Success * \li \c TRUE - On Success
* \li \c FALSE if request is not an alias * \li \c FALSE if request is not an alias
*/ */
static UPNP_INLINE xboolean get_alias( static UPNP_INLINE int get_alias(
/*! [in] request file passed in to be compared with. */ /*! [in] request file passed in to be compared with. */
const char *request_file, const char *request_file,
/*! [out] xml alias object which has a file name stored. */ /*! [out] xml alias object which has a file name stored. */
@ -618,32 +614,36 @@ static UPNP_INLINE xboolean get_alias(
* \brief Compares filePath with paths from the list of virtual directory * \brief Compares filePath with paths from the list of virtual directory
* lists. * lists.
* *
* \return BOOLEAN * \return BOOLEAN.
*/ */
static int isFileInVirtualDir( static int isFileInVirtualDir(
/*! [in] Directory path to be tested for virtual directory. */ /*! [in] Directory path to be tested for virtual directory. */
char *filePath) char *filePath)
{ {
virtualDirList *pCurVirtualDir; virtualDirList *pCurVirtualDir;
int webDirLen; size_t webDirLen;
pCurVirtualDir = pVirtualDirList; pCurVirtualDir = pVirtualDirList;
while (pCurVirtualDir != NULL) { while (pCurVirtualDir != NULL) {
webDirLen = strlen(pCurVirtualDir->dirName); webDirLen = strlen(pCurVirtualDir->dirName);
if (webDirLen) {
if (pCurVirtualDir->dirName[webDirLen - 1] == '/') { if (pCurVirtualDir->dirName[webDirLen - 1] == '/') {
if (strncmp(pCurVirtualDir->dirName, filePath, webDirLen) == 0) if (strncmp(pCurVirtualDir->dirName, filePath,
return TRUE; webDirLen) == 0)
return !0;
} else { } else {
if (strncmp(pCurVirtualDir->dirName, filePath, webDirLen) == 0 && if (strncmp(pCurVirtualDir->dirName, filePath,
webDirLen) == 0 &&
(filePath[webDirLen] == '/' || (filePath[webDirLen] == '/' ||
filePath[webDirLen] == '\0' || filePath[webDirLen] == '\0' ||
filePath[webDirLen] == '?')) filePath[webDirLen] == '?'))
return TRUE; return !0;
}
} }
pCurVirtualDir = pCurVirtualDir->next; pCurVirtualDir = pCurVirtualDir->next;
} }
return FALSE; return 0;
} }
/*! /*!
@ -654,7 +654,7 @@ static void ToUpperCase(
char *s) char *s)
{ {
while (*s) { while (*s) {
*s = toupper(*s); *s = (char)toupper(*s);
++s; ++s;
} }
} }
@ -668,13 +668,12 @@ static char *StrStr(
/*! Input string. */ /*! Input string. */
char *s1, char *s1,
/*! Input sub-string. */ /*! Input sub-string. */
char *s2) const char *s2)
{ {
char *Str1; char *Str1;
char *Str2; char *Str2;
char *Ptr; const char *Ptr;
char *ret = NULL; char *ret = NULL;
int Pos;
Str1 = strdup(s1); Str1 = strdup(s1);
if (!Str1) if (!Str1)
@ -689,8 +688,7 @@ static char *StrStr(
if (!Ptr) { if (!Ptr) {
ret = NULL; ret = NULL;
} else { } else {
Pos = Ptr - Str1; ret = s1 + (Ptr - Str1);
ret = s1 + Pos;
} }
free(Str2); free(Str2);
@ -709,9 +707,10 @@ static char *StrTok(
/*! String containing the token. */ /*! String containing the token. */
char **Src, char **Src,
/*! Set of delimiter characters. */ /*! Set of delimiter characters. */
char *Del) const char *Del)
{ {
char *TmpPtr, *RetPtr; char *TmpPtr;
char *RetPtr;
if (*Src != NULL) { if (*Src != NULL) {
RetPtr = *Src; RetPtr = *Src;
@ -798,7 +797,8 @@ static int CreateHTTPRangeResponseHeader(
struct SendInstruction *Instr) struct SendInstruction *Instr)
{ {
off_t FirstByte, LastByte; off_t FirstByte, LastByte;
char *RangeInput, *Ptr; char *RangeInput;
char *Ptr;
Instr->IsRangeActive = 1; Instr->IsRangeActive = 1;
Instr->ReadSendSize = FileLength; Instr->ReadSendSize = FileLength;
@ -1024,13 +1024,13 @@ static int process_request(
char *request_doc; char *request_doc;
UpnpFileInfo *finfo; UpnpFileInfo *finfo;
xboolean using_alias; int using_alias;
xboolean using_virtual_dir; int using_virtual_dir;
uri_type *url; uri_type *url;
char *temp_str; const char *temp_str;
int resp_major; int resp_major;
int resp_minor; int resp_minor;
xboolean alias_grabbed; int alias_grabbed;
size_t dummy; size_t dummy;
const char *extra_headers = NULL; const char *extra_headers = NULL;
@ -1322,14 +1322,13 @@ static int http_RecvPostMessage(
* is a virtual file or not. */ * is a virtual file or not. */
struct SendInstruction *Instr) struct SendInstruction *Instr)
{ {
unsigned int Data_Buf_Size = 1024; size_t Data_Buf_Size = 1024;
char Buf[1024]; char Buf[1024];
int Timeout = -1; int Timeout = -1;
long Num_Write = 0;
FILE *Fp; FILE *Fp;
parse_status_t status = PARSE_OK; parse_status_t status = PARSE_OK;
xboolean ok_on_close = FALSE; int ok_on_close = FALSE;
unsigned int entity_offset = 0; size_t entity_offset = 0;
int num_read = 0; int num_read = 0;
int ret_code = 0; int ret_code = 0;
@ -1367,7 +1366,7 @@ static int http_RecvPostMessage(
if (num_read > 0) { if (num_read > 0) {
/* append data to buffer */ /* append data to buffer */
ret_code = membuffer_append(&parser->msg.msg, ret_code = membuffer_append(&parser->msg.msg,
Buf, num_read); Buf, (size_t)num_read);
if (ret_code != 0) { if (ret_code != 0) {
/* set failure status */ /* set failure status */
parser->http_error_code = parser->http_error_code =
@ -1408,14 +1407,14 @@ static int http_RecvPostMessage(
Data_Buf_Size); Data_Buf_Size);
entity_offset += Data_Buf_Size; entity_offset += Data_Buf_Size;
if (Instr->IsVirtualFile) { if (Instr->IsVirtualFile) {
Num_Write = virtualDirCallback.write(Fp, Buf, Data_Buf_Size); int n = virtualDirCallback.write(Fp, Buf, Data_Buf_Size);
if (Num_Write < 0) { if (n < 0) {
virtualDirCallback.close(Fp); virtualDirCallback.close(Fp);
return HTTP_INTERNAL_SERVER_ERROR; return HTTP_INTERNAL_SERVER_ERROR;
} }
} else { } else {
Num_Write = fwrite(Buf, 1, Data_Buf_Size, Fp); size_t n = fwrite(Buf, 1, Data_Buf_Size, Fp);
if (Num_Write < 0) { if (n != Data_Buf_Size) {
fclose(Fp); fclose(Fp);
return HTTP_INTERNAL_SERVER_ERROR; return HTTP_INTERNAL_SERVER_ERROR;
} }

View File

@ -111,7 +111,7 @@ static int sock_read_write(
/*! timeout value. */ /*! timeout value. */
IN int *timeoutSecs, IN int *timeoutSecs,
/*! Boolean value specifying read or write option. */ /*! Boolean value specifying read or write option. */
IN xboolean bRead) IN int bRead)
{ {
int retCode; int retCode;
fd_set readSet; fd_set readSet;

View File

@ -128,13 +128,12 @@ int is_escaped(
} }
} }
int replace_escaped(char *in, size_t index, size_t *max)
int replace_escaped(char *in, int index, size_t *max)
{ {
int tempInt = 0; int tempInt = 0;
char tempChar = 0; char tempChar = 0;
int i = 0; size_t i = 0;
int j = 0; size_t j = 0;
if (in[index] == '%' && isxdigit(in[index + 1]) && isxdigit(in[index + 2])) { if (in[index] == '%' && isxdigit(in[index + 1]) && isxdigit(in[index + 2])) {
/* Note the "%2x", makes sure that we convert a maximum of two /* Note the "%2x", makes sure that we convert a maximum of two
@ -142,8 +141,7 @@ int replace_escaped(char *in, int index, size_t *max)
if (sscanf(&in[index + 1], "%2x", &tempInt) != 1) { if (sscanf(&in[index + 1], "%2x", &tempInt) != 1) {
return 0; return 0;
} }
tempChar = (char)tempInt;
tempChar = ( char )tempInt;
for (i = index + 3, j = index; j < *max; i++, j++) { for (i = index + 3, j = index; j < *max; i++, j++) {
in[j] = tempChar; in[j] = tempChar;
if (i < *max) { if (i < *max) {
@ -166,15 +164,15 @@ int replace_escaped(char *in, int index, size_t *max)
* *
* \return * \return
*/ */
static int parse_uric( static size_t parse_uric(
/*! [in] String of characters. */ /*! [in] String of characters. */
const char *in, const char *in,
/*! [in] Maximum limit. */ /*! [in] Maximum limit. */
int max, size_t max,
/*! [out] Token object where the string of characters is copied. */ /*! [out] Token object where the string of characters is copied. */
token *out) token *out)
{ {
int i = 0; size_t i = 0;
while (i < max && while (i < max &&
(is_unreserved(in[i]) || (is_unreserved(in[i]) ||
@ -211,28 +209,24 @@ static void copy_token(
int copy_URL_list(URL_list *in, URL_list *out) int copy_URL_list(URL_list *in, URL_list *out)
{ {
int len = strlen( in->URLs ) + 1; size_t len = strlen(in->URLs) + 1;
int i = 0; size_t i = 0;
out->URLs = NULL; out->URLs = NULL;
out->parsedURLs = NULL; out->parsedURLs = NULL;
out->size = 0; out->size = 0;
out->URLs = ( char * )malloc( len ); out->URLs = malloc(len);
out->parsedURLs = out->parsedURLs = malloc(sizeof(uri_type) * in->size);
( uri_type * ) malloc( sizeof( uri_type ) * in->size );
if( ( out->URLs == NULL ) || ( out->parsedURLs == NULL ) ) 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 = 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,
&out->parsedURLs[i].scheme, out->URLs ); &out->parsedURLs[i].scheme, out->URLs );
out->parsedURLs[i].path_type = in->parsedURLs[i].path_type; out->parsedURLs[i].path_type = in->parsedURLs[i].path_type;
copy_token( &in->parsedURLs[i].pathquery, in->URLs, copy_token( &in->parsedURLs[i].pathquery, in->URLs,
&out->parsedURLs[i].pathquery, out->URLs ); &out->parsedURLs[i].pathquery, out->URLs );
@ -241,7 +235,6 @@ int copy_URL_list(URL_list *in, URL_list *out)
copy_token( &in->parsedURLs[i].hostport.text, copy_token( &in->parsedURLs[i].hostport.text,
in->URLs, &out->parsedURLs[i].hostport.text, in->URLs, &out->parsedURLs[i].hostport.text,
out->URLs ); out->URLs );
memcpy( &out->parsedURLs[i].hostport.IPaddress, memcpy( &out->parsedURLs[i].hostport.IPaddress,
&in->parsedURLs[i].hostport.IPaddress, &in->parsedURLs[i].hostport.IPaddress,
sizeof(struct sockaddr_storage) ); sizeof(struct sockaddr_storage) );
@ -291,7 +284,7 @@ void print_token(token * in)
int token_string_casecmp(token *in1, char *in2) int token_string_casecmp(token *in1, char *in2)
{ {
int in2_length = strlen(in2); size_t in2_length = strlen(in2);
if (in1->size != in2_length) { if (in1->size != in2_length) {
return 1; return 1;
@ -303,7 +296,7 @@ int token_string_casecmp(token *in1, char *in2)
int token_string_cmp(token * in1, char *in2) int token_string_cmp(token * in1, char *in2)
{ {
int in2_length = strlen(in2); size_t in2_length = strlen(in2);
if (in1->size != in2_length) { if (in1->size != in2_length) {
return 1; return 1;
@ -325,7 +318,7 @@ int token_cmp(token *in1, token *in2)
int parse_hostport( int parse_hostport(
const char *in, const char *in,
int max, size_t max,
hostport_type *out) hostport_type *out)
{ {
char workbuf[256]; char workbuf[256];
@ -468,6 +461,7 @@ int parse_hostport(
out->text.buff = in; out->text.buff = in;
return hostport_size; return hostport_size;
max = max;
} }
/*! /*!
@ -480,29 +474,27 @@ int parse_hostport(
* *
* \return * \return
*/ */
static int parse_scheme( static size_t parse_scheme(
/*! [in] String of characters representing a scheme. */ /*! [in] String of characters representing a scheme. */
const char *in, const char *in,
/*! [in] Maximum number of characters. */ /*! [in] Maximum number of characters. */
int max, size_t max,
/*! [out] Output parameter whose buffer is filled in with the scheme. */ /*! [out] Output parameter whose buffer is filled in with the scheme. */
token *out) token *out)
{ {
int i = 0; size_t i = 0;
out->size = 0; out->size = 0;
out->buff = NULL; out->buff = NULL;
if( ( max == 0 ) || ( !isalpha( in[0] ) ) ) if( ( max == 0 ) || ( !isalpha( in[0] ) ) )
return FALSE; return 0;
i++; i++;
while( ( i < max ) && ( in[i] != ':' ) ) { while( ( i < max ) && ( in[i] != ':' ) ) {
if( !( isalnum( in[i] ) || ( in[i] == '+' ) || ( in[i] == '-' ) if( !( isalnum( in[i] ) || ( in[i] == '+' ) || ( in[i] == '-' )
|| ( in[i] == '.' ) ) ) || ( in[i] == '.' ) ) )
return FALSE; return 0;
i++; i++;
} }
if( i < max ) { if( i < max ) {
@ -511,18 +503,18 @@ static int parse_scheme(
return i; return i;
} }
return FALSE; return 0;
} }
int remove_escaped_chars(INOUT char *in, INOUT size_t *size ) int remove_escaped_chars(INOUT char *in, INOUT size_t *size)
{ {
int i = 0; size_t i = 0;
for( i = 0; i < *size; i++ ) { for (i = 0; i < *size; i++) {
replace_escaped( in, i, size ); replace_escaped(in, i, size);
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -599,7 +591,7 @@ char *resolve_rel_url(char *base_url, char *rel_url)
uri_type rel; uri_type rel;
char temp_path = '/'; char temp_path = '/';
int i = 0; size_t i = 0;
char *finger = NULL; char *finger = NULL;
char *last_slash = NULL; char *last_slash = NULL;
@ -665,7 +657,6 @@ char *resolve_rel_url(char *base_url, char *rel_url)
finger = out_finger; finger = out_finger;
last_slash = finger; last_slash = finger;
i = 0; i = 0;
while( ( i < base.pathquery.size ) && while( ( i < base.pathquery.size ) &&
( base.pathquery.buff[i] != '?' ) ) { ( base.pathquery.buff[i] != '?' ) ) {
( *finger ) = base.pathquery.buff[i]; ( *finger ) = base.pathquery.buff[i];
@ -675,7 +666,6 @@ char *resolve_rel_url(char *base_url, char *rel_url)
finger++; finger++;
} }
i = 0;
strcpy( last_slash, rel_url ); strcpy( last_slash, rel_url );
if( remove_dots( out_finger, if( remove_dots( out_finger,
strlen( out_finger ) ) != strlen( out_finger ) ) !=
@ -708,10 +698,11 @@ char *resolve_rel_url(char *base_url, char *rel_url)
int parse_uri(const char *in, size_t max, uri_type *out) int parse_uri(const char *in, size_t max, uri_type *out)
{ {
int begin_path = 0; int begin_path = 0;
int begin_hostport = 0; size_t begin_hostport = 0;
int begin_fragment = 0; size_t begin_fragment = 0;
if( ( begin_hostport = parse_scheme( in, max, &out->scheme ) ) ) { begin_hostport = parse_scheme(in, max, &out->scheme);
if (begin_hostport) {
out->type = ABSOLUTE; out->type = ABSOLUTE;
out->path_type = OPAQUE_PART; out->path_type = OPAQUE_PART;
begin_hostport++; begin_hostport++;
@ -719,44 +710,40 @@ int parse_uri(const char *in, size_t max, uri_type *out)
out->type = RELATIVE; out->type = RELATIVE;
out->path_type = REL_PATH; out->path_type = REL_PATH;
} }
if (begin_hostport + 1 < max &&
if( ( ( begin_hostport + 1 ) < max ) && ( in[begin_hostport] == '/' ) in[begin_hostport] == '/' &&
&& ( in[begin_hostport + 1] == '/' ) ) { in[begin_hostport + 1] == '/') {
begin_hostport += 2; begin_hostport += 2;
begin_path = parse_hostport(&in[begin_hostport],
if( ( begin_path = parse_hostport( &in[begin_hostport],
max - begin_hostport, max - begin_hostport,
&out->hostport ) ) >= 0 ) { &out->hostport);
begin_path += begin_hostport; if (begin_path >= 0) {
begin_path += (int)begin_hostport;
} else } else
return begin_path; return begin_path;
} else { } else {
memset( &out->hostport, 0, sizeof(out->hostport) ); memset(&out->hostport, 0, sizeof(out->hostport));
begin_path = begin_hostport; begin_path = (int)begin_hostport;
} }
begin_fragment = parse_uric(&in[begin_path],
begin_fragment = max - (size_t)begin_path,
parse_uric( &in[begin_path], max - begin_path, &out->pathquery) + (size_t)begin_path;
&out->pathquery ) + begin_path; if (out->pathquery.size && out->pathquery.buff[0] == '/') {
if( ( out->pathquery.size ) && ( out->pathquery.buff[0] == '/' ) ) {
out->path_type = ABS_PATH; out->path_type = ABS_PATH;
} }
if (begin_fragment < max && in[begin_fragment] == '#') {
if( ( begin_fragment < max ) && ( in[begin_fragment] == '#' ) ) {
begin_fragment++; begin_fragment++;
parse_uric( &in[begin_fragment], max - begin_fragment, parse_uric(&in[begin_fragment], max - begin_fragment,
&out->fragment ); &out->fragment);
} else { } else {
out->fragment.buff = NULL; out->fragment.buff = NULL;
out->fragment.size = 0; out->fragment.size = 0;
} }
return HTTP_SUCCESS; return HTTP_SUCCESS;
} }
int parse_uri_and_unescape(char *in, size_t max, uri_type *out)
int parse_uri_and_unescape(char *in, int max, uri_type *out)
{ {
int ret = parse_uri(in, max, out); int ret = parse_uri(in, max, out);

View File

@ -462,57 +462,31 @@ membuffer_insert( INOUT membuffer * m,
return 0; return 0;
} }
/************************************************************************ void membuffer_delete(membuffer *m, size_t index, size_t num_bytes)
* Function : membuffer_delete
*
* Parameters :
* INOUT membuffer* m ; buffer whose memory size is to be decreased
* and copied to the odified location
* IN int index ; index to determine bounds while moving data
* IN size_t num_bytes ; number of bytes that the data needs to
* shrink by
*
* Description : Shrink the size of the buffer depending on the current
* size of the bufer and te input parameters. Move contents from the
* old buffer to the new sized buffer.
*
* Return : void ;
*
* Note :
************************************************************************/
void
membuffer_delete( INOUT membuffer * m,
IN int index,
IN size_t num_bytes )
{ {
int return_value; int return_value;
int new_length; int new_length;
size_t copy_len; size_t copy_len;
assert( m != NULL ); assert(m != NULL);
if (!m) return; if (!m || !m->length)
if( m->length == 0 ) {
return; return;
}
assert( index >= 0 && index < ( int )m->length );
/* shrink count if it goes beyond buffer */ /* shrink count if it goes beyond buffer */
if( index + num_bytes > m->length ) { if (index + num_bytes > m->length) {
num_bytes = m->length - ( size_t ) index; num_bytes = m->length - index;
copy_len = 0; /* every thing at and after index purged */ /* every thing at and after index purged */
copy_len = 0;
} else { } else {
/* calc num bytes after deleted string */ /* calc num bytes after deleted string */
copy_len = m->length - ( index + num_bytes ); copy_len = m->length - (index + num_bytes);
} }
memmove(m->buf + index, m->buf + index + num_bytes, copy_len);
memmove( m->buf + index, m->buf + index + num_bytes, copy_len );
new_length = m->length - num_bytes; new_length = m->length - num_bytes;
return_value = membuffer_set_size( m, new_length ); /* trim buffer */ /* trim buffer */
assert( return_value == 0 ); /* shrinking should always work */ return_value = membuffer_set_size(m, new_length);
/* shrinking should always work */
assert(return_value == 0);
/* don't modify until buffer is set */ /* don't modify until buffer is set */
m->length = new_length; m->length = new_length;

View File

@ -32,6 +32,10 @@
#ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H #ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H
#define GENLIB_NET_HTTP_HTTPREADWRITE_H #define GENLIB_NET_HTTP_HTTPREADWRITE_H
/*
* \file
*/
#include "config.h" #include "config.h"
#include "upnputil.h" #include "upnputil.h"
#include "sock.h" #include "sock.h"
@ -46,39 +50,33 @@
int http_CancelHttpGet(IN void *Handle); int http_CancelHttpGet(IN void *Handle);
/************************************************************************ /*!
* Function: http_FixUrl * \brief Validates URL.
* *
* Parameters: * \return
* IN uri_type* url; URL to be validated and fixed * \li \c UPNP_E_INVALID_URL
* OUT uri_type* fixed_url; URL after being fixed. * \li \c UPNP_E_SUCCESS
* */
* Description: int http_FixUrl(
* Validates URL /*! [in] URL to be validated and fixed. */
* uri_type *url,
* Returns: /*! [out] URL after being fixed. */
* UPNP_E_INVALID_URL uri_type *fixed_url);
* UPNP_E_SUCCESS
************************************************************************/
int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
/************************************************************************ /*!
* Function: http_FixStrUrl * \brief Parses URL and then validates URL.
* *
* Parameters: * \return
* IN char* urlstr ; Character string as a URL * \li \c UPNP_E_INVALID_URL
* IN int urlstrlen ; Length of the character string * \li \c UPNP_E_SUCCESS
* OUT uri_type* fixed_url ; Fixed and corrected URL */
* int http_FixStrUrl(
* Description: /*! [in] Character string as a URL. */
* Parses URL and then validates URL const char *urlstr,
* /*! [in] Length of the character string. */
* Returns: size_t urlstrlen,
* UPNP_E_INVALID_URL /*! [out] Fixed and corrected URL. */
* UPNP_E_SUCCESS uri_type *fixed_url);
************************************************************************/
int http_FixStrUrl( IN const char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
/************************************************************************ /************************************************************************
* Function: http_Connect * Function: http_Connect

View File

@ -32,6 +32,10 @@
#ifndef GENLIB_UTIL_MEMBUFFER_H #ifndef GENLIB_UTIL_MEMBUFFER_H
#define GENLIB_UTIL_MEMBUFFER_H #define GENLIB_UTIL_MEMBUFFER_H
/*!
* \file
*/
#include <stdlib.h> #include <stdlib.h>
#include "upnputil.h" #include "upnputil.h"
@ -275,25 +279,19 @@ int membuffer_append_str( INOUT membuffer* m, IN const char* c_str );
int membuffer_insert( INOUT membuffer* m, IN const void* buf, IN size_t buf_len, int index ); int membuffer_insert( INOUT membuffer* m, IN const void* buf, IN size_t buf_len, int index );
/************************************************************************ /*!
* Function : membuffer_delete * \brief Shrink the size of the buffer depending on the current size of the
* * bufer and te input parameters. Move contents from the old buffer to the
* Parameters : * new sized buffer.
* INOUT membuffer* m ; buffer whose memory size is to be decreased */
* and copied to the odified location void membuffer_delete(
* IN int index ; index to determine bounds while moving data /* [in,out] Buffer whose memory size is to be decreased and copied
* IN size_t num_bytes ; number of bytes that the data needs to * to the modified location. */
* shrink by INOUT membuffer *m,
* /* [in] Index to determine bounds while moving data. */
* Description : Shrink the size of the buffer depending on the current IN size_t index,
* size of the bufer and te input parameters. Move contents from the /* [in] Number of bytes that the data needs to shrink by. */
* old buffer to the new sized buffer. IN size_t num_bytes);
*
* Return : void ;
*
* Note :
************************************************************************/
void membuffer_delete( INOUT membuffer* m, IN int index, IN size_t num_bytes );
/************************************************************************ /************************************************************************

View File

@ -59,11 +59,11 @@ typedef struct MServerSockArray {
/*! IPv6 SSDP Socket for incoming advertisments and search requests. */ /*! IPv6 SSDP Socket for incoming advertisments and search requests. */
SOCKET ssdpSock6UlaGua; SOCKET ssdpSock6UlaGua;
/* ! . */ /* ! . */
SOCKET stopPort; uint16_t stopPort;
/* ! . */ /* ! . */
unsigned short miniServerPort4; uint16_t miniServerPort4;
/* ! . */ /* ! . */
unsigned short miniServerPort6; uint16_t miniServerPort6;
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
/*! IPv4 SSDP socket for sending search requests and receiving search /*! IPv4 SSDP socket for sending search requests and receiving search
* replies */ * replies */

View File

@ -149,7 +149,7 @@ typedef struct URI{
*/ */
typedef struct URL_LIST { typedef struct URL_LIST {
/*! */ /*! */
int size; size_t size;
/*! All the urls, delimited by <> */ /*! All the urls, delimited by <> */
char *URLs; char *URLs;
/*! */ /*! */
@ -169,10 +169,10 @@ typedef struct URL_LIST {
* \return * \return
*/ */
int replace_escaped( int replace_escaped(
/*! [in] String of characters. */ /*! [in,out] String of characters. */
char *in, char *in,
/*! [in] Index at which to start checking the characters. */ /*! [in] Index at which to start checking the characters. */
int index, size_t index,
/*! [out] . */ /*! [out] . */
size_t *max); size_t *max);
@ -288,7 +288,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. */
int max, size_t max,
/*! [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);
@ -388,7 +388,7 @@ int parse_uri_and_unescape(
/*! [in] Character string containing uri information to be parsed. */ /*! [in] Character string containing uri information to be parsed. */
char *in, char *in,
/*! [in] Maximum limit on the number of characters. */ /*! [in] Maximum limit on the number of characters. */
int max, size_t max,
/*! [out] Output parameter which will have the parsed uri information. */ /*! [out] Output parameter which will have the parsed uri information. */
uri_type *out); uri_type *out);

View File

@ -6,7 +6,5 @@
#include "sock.h" #include "sock.h"
#include "soaplib.h" #include "soaplib.h"
#endif /* EXCLUDE_SOAP */
#endif // EXCLUDE_SOAP