From 2685b5bb657eda6e37b47c58b04fdb3cefb0d3e7 Mon Sep 17 00:00:00 2001 From: Marcelo Roberto Jimenez Date: Sat, 20 Nov 2010 13:48:50 -0200 Subject: [PATCH] gena: fix several compiler warnings. --- upnp/src/gena/gena_callback2.c | 2 + upnp/src/gena/gena_device.c | 17 ++- upnp/src/genlib/miniserver/miniserver.c | 43 +++--- upnp/src/genlib/net/http/httpreadwrite.c | 36 +---- upnp/src/genlib/net/http/webserver.c | 87 ++++++------ upnp/src/genlib/net/sock.c | 2 +- upnp/src/genlib/net/uri/uri.c | 161 +++++++++++------------ upnp/src/genlib/util/membuffer.c | 76 ++++------- upnp/src/inc/httpreadwrite.h | 58 ++++---- upnp/src/inc/membuffer.h | 36 +++-- upnp/src/inc/miniserver.h | 6 +- upnp/src/inc/uri.h | 10 +- upnp/src/soap/soap_common.c | 4 +- 13 files changed, 231 insertions(+), 307 deletions(-) diff --git a/upnp/src/gena/gena_callback2.c b/upnp/src/gena/gena_callback2.c index 12b3650..e193c60 100644 --- a/upnp/src/gena/gena_callback2.c +++ b/upnp/src/gena/gena_callback2.c @@ -122,6 +122,8 @@ genaCallback( IN http_parser_t * parser, /* handle missing functions of device or ctrl pt */ error_respond( info, HTTP_NOT_IMPLEMENTED, request ); } + return; + parser = parser; } #endif /* EXCLUDE_GENA */ diff --git a/upnp/src/gena/gena_device.c b/upnp/src/gena/gena_device.c index e80a297..cf9de3a 100644 --- a/upnp/src/gena/gena_device.c +++ b/upnp/src/gena/gena_device.c @@ -271,7 +271,7 @@ static int genaNotify( /*! [in] subscription to be Notified, assumes this is valid for life of function. */ subscription *sub) { - int i; + size_t i; membuffer mid_msg; membuffer endmsg; uri_type *url; @@ -1134,7 +1134,7 @@ static int create_url_list( /*! [out] . */ URL_list *out) { - int URLcount = 0; + size_t URLcount = 0; size_t i; int return_code = 0; uri_type temp; @@ -1165,12 +1165,11 @@ static int create_url_list( } if( URLcount > 0 ) { - out->URLs = ( char * )malloc( URLS->size + 1 ); - out->parsedURLs = - ( uri_type * ) malloc( sizeof( uri_type ) * URLcount ); - if( ( out->URLs == NULL ) || ( out->parsedURLs == NULL ) ) { - free( out->URLs ); - free( out->parsedURLs ); + out->URLs = malloc(URLS->size + 1); + out->parsedURLs = malloc(sizeof(uri_type) * URLcount); + if (!out->URLs || !out->parsedURLs) { + free(out->URLs); + free(out->parsedURLs); out->URLs = NULL; out->parsedURLs = NULL; return UPNP_E_OUTOF_MEMORY; @@ -1201,7 +1200,7 @@ static int create_url_list( } out->size = URLcount; - return URLcount; + return (int)URLcount; } diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c index 38257f5..423ae31 100644 --- a/upnp/src/genlib/miniserver/miniserver.c +++ b/upnp/src/genlib/miniserver/miniserver.c @@ -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) { - int byteReceived; + ssize_t byteReceived; socklen_t clientLen; struct sockaddr_storage clientAddr; char requestBuf[256]; @@ -460,16 +460,17 @@ static void RunMiniServer( /*! * \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( /*! [in] Socket descriptor. */ - SOCKET sockfd) + SOCKET sockfd, + /*! [out] The port value if successful, otherwise, untouched. */ + uint16_t *port) { struct sockaddr_storage sockinfo; socklen_t len; int code; - int port = 0; len = sizeof(sockinfo); code = getsockname(sockfd, (struct sockaddr *)&sockinfo, &len); @@ -477,14 +478,14 @@ static int get_port( return -1; } 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) { - port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port); + *port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port); } UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__, "sockfd = %d, .... port = %d\n", sockfd, port); - return port; + return 0; } @@ -509,10 +510,10 @@ static int get_miniserver_sockets( MiniServerSockArray *out, /*! [in] port on which the server is listening for incoming IPv4 * connections. */ - unsigned short listen_port4, + uint16_t listen_port4, /*! [in] port on which the server is listening for incoming IPv6 * connections. */ - unsigned short listen_port6) + uint16_t listen_port6) { char errorBuffer[ERROR_BUFFER_LEN]; struct sockaddr_storage __ss_v4; @@ -723,8 +724,8 @@ static int get_miniserver_sockets( #endif return UPNP_E_LISTEN; } - actual_port4 = get_port(listenfd4); - if (actual_port4 <= 0) { + ret_code = get_port(listenfd4, &actual_port4); + if (ret_code < 0) { sock_close(listenfd4); #ifdef UPNP_ENABLE_IPV6 sock_close(listenfd6); @@ -745,8 +746,8 @@ static int get_miniserver_sockets( sock_close(listenfd6); return UPNP_E_LISTEN; } - actual_port6 = get_port(listenfd6); - if (actual_port6 <= 0) { + ret_code = get_port(listenfd6, &actual_port6); + if (ret_code <= 0) { sock_close(listenfd4); sock_close(listenfd6); return UPNP_E_INTERNAL_ERROR; @@ -802,8 +803,8 @@ static int get_miniserver_stopsock( sock_close(miniServerStopSock); return UPNP_E_SOCKET_BIND; } - miniStopSockPort = get_port( miniServerStopSock ); - if (miniStopSockPort <= 0) { + ret = get_port(miniServerStopSock, &miniStopSockPort); + if (ret < 0) { sock_close(miniServerStopSock); return UPNP_E_INTERNAL_ERROR; } @@ -821,9 +822,9 @@ static UPNP_INLINE void InitMiniServerSockArray(MiniServerSockArray *miniSocket) miniSocket->ssdpSock4 = INVALID_SOCKET; miniSocket->ssdpSock6 = INVALID_SOCKET; miniSocket->ssdpSock6UlaGua = INVALID_SOCKET; - miniSocket->stopPort = -1; - miniSocket->miniServerPort4 = -1; - miniSocket->miniServerPort6 = -1; + miniSocket->stopPort = 0; + miniSocket->miniServerPort4 = 0; + miniSocket->miniServerPort6 = 0; miniSocket->ssdpReqSock4 = INVALID_SOCKET; miniSocket->ssdpReqSock6 = INVALID_SOCKET; } @@ -924,7 +925,7 @@ int StartMiniServer( int StopMiniServer() { char errorBuffer[ERROR_BUFFER_LEN]; - int socklen = sizeof (struct sockaddr_in); + socklen_t socklen = sizeof (struct sockaddr_in); SOCKET sock; struct sockaddr_in ssdpAddr; char buf[256] = "ShutDown"; @@ -947,7 +948,7 @@ int StopMiniServer() ssdpAddr.sin_family = AF_INET; ssdpAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ssdpAddr.sin_port = htons(miniStopSockPort); - sendto(sock, buf, (int)bufLen, 0, + sendto(sock, buf, bufLen, 0, (struct sockaddr *)&ssdpAddr, socklen); usleep(1000); if (gMServState == MSERV_IDLE) { diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 69b4f40..e217d10 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -240,21 +240,6 @@ static int private_connect( #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) { char *temp_path = "/"; @@ -275,26 +260,10 @@ int http_FixUrl(IN uri_type *url, OUT uri_type *fixed_url) 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( IN const char *urlstr, - IN int urlstrlen, - OUT uri_type * fixed_url) + IN size_t urlstrlen, + OUT uri_type *fixed_url) { uri_type url; @@ -305,7 +274,6 @@ int http_FixStrUrl( return http_FixUrl(&url, fixed_url); } - /************************************************************************ * Function: http_Connect * diff --git a/upnp/src/genlib/net/http/webserver.c b/upnp/src/genlib/net/http/webserver.c index c0d0370..32fe51d 100644 --- a/upnp/src/genlib/net/http/webserver.c +++ b/upnp/src/genlib/net/http/webserver.c @@ -310,12 +310,11 @@ static UPNP_INLINE int get_content_type( const char *extension; const char *type; const char *subtype; - xboolean ctype_found = FALSE; + int ctype_found = FALSE; char *temp = NULL; - int length = 0; + size_t length = 0; UpnpFileInfo_set_ContentType(fileInfo, NULL); - /* get ext */ extension = strrchr(filename, '.'); if (extension != NULL) { @@ -323,15 +322,13 @@ static UPNP_INLINE int get_content_type( ctype_found = TRUE; } } - if (!ctype_found) { /* unknown content type */ type = gMediaTypes[APPLICATION_INDEX]; subtype = "octet-stream"; } - length = strlen(type) + strlen("/") + strlen(subtype) + 1; - temp = (char *)malloc(length); + temp = malloc(length); if (!temp) { return UPNP_E_OUTOF_MEMORY; } @@ -342,7 +339,6 @@ static UPNP_INLINE int get_content_type( if (!UpnpFileInfo_get_ContentType(fileInfo)) { return UPNP_E_OUTOF_MEMORY; } - return 0; } @@ -365,7 +361,7 @@ static UPNP_INLINE void glob_alias_init(void) * * \return BOOLEAN. */ -static UPNP_INLINE xboolean is_valid_alias( +static UPNP_INLINE int is_valid_alias( /*! [in] XML alias object. */ 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 index; + size_t index; int ret; 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 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. */ const char *request_file, /*! [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 * lists. * - * \return BOOLEAN + * \return BOOLEAN. */ static int isFileInVirtualDir( /*! [in] Directory path to be tested for virtual directory. */ char *filePath) { virtualDirList *pCurVirtualDir; - int webDirLen; + size_t webDirLen; pCurVirtualDir = pVirtualDirList; while (pCurVirtualDir != NULL) { webDirLen = strlen(pCurVirtualDir->dirName); - if (pCurVirtualDir->dirName[webDirLen - 1] == '/') { - if (strncmp(pCurVirtualDir->dirName, filePath, webDirLen) == 0) - return TRUE; - } else { - if (strncmp(pCurVirtualDir->dirName, filePath, webDirLen) == 0 && - (filePath[webDirLen] == '/' || - filePath[webDirLen] == '\0' || - filePath[webDirLen] == '?')) - return TRUE; + if (webDirLen) { + if (pCurVirtualDir->dirName[webDirLen - 1] == '/') { + if (strncmp(pCurVirtualDir->dirName, filePath, + webDirLen) == 0) + return !0; + } else { + if (strncmp(pCurVirtualDir->dirName, filePath, + webDirLen) == 0 && + (filePath[webDirLen] == '/' || + filePath[webDirLen] == '\0' || + filePath[webDirLen] == '?')) + return !0; + } } pCurVirtualDir = pCurVirtualDir->next; } - return FALSE; + return 0; } /*! @@ -654,7 +654,7 @@ static void ToUpperCase( char *s) { while (*s) { - *s = toupper(*s); + *s = (char)toupper(*s); ++s; } } @@ -668,13 +668,12 @@ static char *StrStr( /*! Input string. */ char *s1, /*! Input sub-string. */ - char *s2) + const char *s2) { char *Str1; char *Str2; - char *Ptr; + const char *Ptr; char *ret = NULL; - int Pos; Str1 = strdup(s1); if (!Str1) @@ -689,8 +688,7 @@ static char *StrStr( if (!Ptr) { ret = NULL; } else { - Pos = Ptr - Str1; - ret = s1 + Pos; + ret = s1 + (Ptr - Str1); } free(Str2); @@ -709,9 +707,10 @@ static char *StrTok( /*! String containing the token. */ char **Src, /*! Set of delimiter characters. */ - char *Del) + const char *Del) { - char *TmpPtr, *RetPtr; + char *TmpPtr; + char *RetPtr; if (*Src != NULL) { RetPtr = *Src; @@ -798,7 +797,8 @@ static int CreateHTTPRangeResponseHeader( struct SendInstruction *Instr) { off_t FirstByte, LastByte; - char *RangeInput, *Ptr; + char *RangeInput; + char *Ptr; Instr->IsRangeActive = 1; Instr->ReadSendSize = FileLength; @@ -1024,13 +1024,13 @@ static int process_request( char *request_doc; UpnpFileInfo *finfo; - xboolean using_alias; - xboolean using_virtual_dir; + int using_alias; + int using_virtual_dir; uri_type *url; - char *temp_str; + const char *temp_str; int resp_major; int resp_minor; - xboolean alias_grabbed; + int alias_grabbed; size_t dummy; const char *extra_headers = NULL; @@ -1322,14 +1322,13 @@ static int http_RecvPostMessage( * is a virtual file or not. */ struct SendInstruction *Instr) { - unsigned int Data_Buf_Size = 1024; + size_t Data_Buf_Size = 1024; char Buf[1024]; int Timeout = -1; - long Num_Write = 0; FILE *Fp; parse_status_t status = PARSE_OK; - xboolean ok_on_close = FALSE; - unsigned int entity_offset = 0; + int ok_on_close = FALSE; + size_t entity_offset = 0; int num_read = 0; int ret_code = 0; @@ -1367,7 +1366,7 @@ static int http_RecvPostMessage( if (num_read > 0) { /* append data to buffer */ ret_code = membuffer_append(&parser->msg.msg, - Buf, num_read); + Buf, (size_t)num_read); if (ret_code != 0) { /* set failure status */ parser->http_error_code = @@ -1408,14 +1407,14 @@ static int http_RecvPostMessage( Data_Buf_Size); entity_offset += Data_Buf_Size; if (Instr->IsVirtualFile) { - Num_Write = virtualDirCallback.write(Fp, Buf, Data_Buf_Size); - if (Num_Write < 0) { + int n = virtualDirCallback.write(Fp, Buf, Data_Buf_Size); + if (n < 0) { virtualDirCallback.close(Fp); return HTTP_INTERNAL_SERVER_ERROR; } } else { - Num_Write = fwrite(Buf, 1, Data_Buf_Size, Fp); - if (Num_Write < 0) { + size_t n = fwrite(Buf, 1, Data_Buf_Size, Fp); + if (n != Data_Buf_Size) { fclose(Fp); return HTTP_INTERNAL_SERVER_ERROR; } diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index cce3d7b..3617379 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -111,7 +111,7 @@ static int sock_read_write( /*! timeout value. */ IN int *timeoutSecs, /*! Boolean value specifying read or write option. */ - IN xboolean bRead) + IN int bRead) { int retCode; fd_set readSet; diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index 44f4be8..89fa47c 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -128,13 +128,12 @@ int is_escaped( } } - -int replace_escaped(char *in, int index, size_t *max) +int replace_escaped(char *in, size_t index, size_t *max) { int tempInt = 0; char tempChar = 0; - int i = 0; - int j = 0; + size_t i = 0; + size_t j = 0; if (in[index] == '%' && isxdigit(in[index + 1]) && isxdigit(in[index + 2])) { /* 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) { return 0; } - - tempChar = ( char )tempInt; + tempChar = (char)tempInt; for (i = index + 3, j = index; j < *max; i++, j++) { in[j] = tempChar; if (i < *max) { @@ -166,15 +164,15 @@ int replace_escaped(char *in, int index, size_t *max) * * \return */ -static int parse_uric( +static size_t parse_uric( /*! [in] String of characters. */ const char *in, /*! [in] Maximum limit. */ - int max, + size_t max, /*! [out] Token object where the string of characters is copied. */ token *out) { - int i = 0; + size_t i = 0; while (i < max && (is_unreserved(in[i]) || @@ -211,28 +209,24 @@ static void copy_token( int copy_URL_list(URL_list *in, URL_list *out) { - int len = strlen( in->URLs ) + 1; - int i = 0; + size_t len = strlen(in->URLs) + 1; + size_t i = 0; out->URLs = NULL; out->parsedURLs = NULL; out->size = 0; - out->URLs = ( char * )malloc( len ); - out->parsedURLs = - ( uri_type * ) malloc( sizeof( uri_type ) * in->size ); + out->URLs = malloc(len); + out->parsedURLs = malloc(sizeof(uri_type) * in->size); - if( ( out->URLs == NULL ) || ( out->parsedURLs == NULL ) ) + if ( !out->URLs || !out->parsedURLs) return UPNP_E_OUTOF_MEMORY; - - memcpy( out->URLs, in->URLs, len ); - + memcpy(out->URLs, in->URLs, len); for( i = 0; i < in->size; i++ ) { /*copy the parsed uri */ out->parsedURLs[i].type = in->parsedURLs[i].type; copy_token( &in->parsedURLs[i].scheme, in->URLs, &out->parsedURLs[i].scheme, out->URLs ); - out->parsedURLs[i].path_type = in->parsedURLs[i].path_type; copy_token( &in->parsedURLs[i].pathquery, in->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, in->URLs, &out->parsedURLs[i].hostport.text, out->URLs ); - memcpy( &out->parsedURLs[i].hostport.IPaddress, &in->parsedURLs[i].hostport.IPaddress, sizeof(struct sockaddr_storage) ); @@ -291,7 +284,7 @@ void print_token(token * in) int token_string_casecmp(token *in1, char *in2) { - int in2_length = strlen(in2); + size_t in2_length = strlen(in2); if (in1->size != in2_length) { return 1; @@ -303,7 +296,7 @@ int token_string_casecmp(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) { return 1; @@ -325,7 +318,7 @@ int token_cmp(token *in1, token *in2) int parse_hostport( const char *in, - int max, + size_t max, hostport_type *out) { char workbuf[256]; @@ -468,6 +461,7 @@ int parse_hostport( out->text.buff = in; return hostport_size; + max = max; } /*! @@ -480,29 +474,27 @@ int parse_hostport( * * \return */ -static int parse_scheme( +static size_t parse_scheme( /*! [in] String of characters representing a scheme. */ const char *in, /*! [in] Maximum number of characters. */ - int max, + size_t max, /*! [out] Output parameter whose buffer is filled in with the scheme. */ token *out) { - int i = 0; + size_t i = 0; out->size = 0; out->buff = NULL; if( ( max == 0 ) || ( !isalpha( in[0] ) ) ) - return FALSE; + return 0; i++; while( ( i < max ) && ( in[i] != ':' ) ) { - if( !( isalnum( in[i] ) || ( in[i] == '+' ) || ( in[i] == '-' ) || ( in[i] == '.' ) ) ) - return FALSE; - + return 0; i++; } if( i < max ) { @@ -511,19 +503,19 @@ static int parse_scheme( 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++ ) { - replace_escaped( in, i, size ); - } - return UPNP_E_SUCCESS; + for (i = 0; i < *size; i++) { + replace_escaped(in, i, size); + } + + return UPNP_E_SUCCESS; } @@ -599,7 +591,7 @@ char *resolve_rel_url(char *base_url, char *rel_url) uri_type rel; char temp_path = '/'; - int i = 0; + size_t i = 0; char *finger = NULL; char *last_slash = NULL; @@ -665,7 +657,6 @@ char *resolve_rel_url(char *base_url, char *rel_url) finger = out_finger; last_slash = finger; i = 0; - while( ( i < base.pathquery.size ) && ( base.pathquery.buff[i] != '?' ) ) { ( *finger ) = base.pathquery.buff[i]; @@ -675,7 +666,6 @@ char *resolve_rel_url(char *base_url, char *rel_url) finger++; } - i = 0; strcpy( last_slash, rel_url ); if( remove_dots( out_finger, strlen( out_finger ) ) != @@ -707,56 +697,53 @@ char *resolve_rel_url(char *base_url, char *rel_url) int parse_uri(const char *in, size_t max, uri_type *out) { - int begin_path = 0; - int begin_hostport = 0; - int begin_fragment = 0; + int begin_path = 0; + size_t begin_hostport = 0; + size_t begin_fragment = 0; - if( ( begin_hostport = parse_scheme( in, max, &out->scheme ) ) ) { - out->type = ABSOLUTE; - out->path_type = OPAQUE_PART; - begin_hostport++; - } else { - out->type = RELATIVE; - out->path_type = REL_PATH; - } + begin_hostport = parse_scheme(in, max, &out->scheme); + if (begin_hostport) { + out->type = ABSOLUTE; + out->path_type = OPAQUE_PART; + begin_hostport++; + } else { + out->type = RELATIVE; + out->path_type = REL_PATH; + } + if (begin_hostport + 1 < max && + in[begin_hostport] == '/' && + in[begin_hostport + 1] == '/') { + begin_hostport += 2; + begin_path = parse_hostport(&in[begin_hostport], + max - begin_hostport, + &out->hostport); + if (begin_path >= 0) { + begin_path += (int)begin_hostport; + } else + return begin_path; + } else { + memset(&out->hostport, 0, sizeof(out->hostport)); + begin_path = (int)begin_hostport; + } + begin_fragment = parse_uric(&in[begin_path], + max - (size_t)begin_path, + &out->pathquery) + (size_t)begin_path; + if (out->pathquery.size && out->pathquery.buff[0] == '/') { + out->path_type = ABS_PATH; + } + if (begin_fragment < max && in[begin_fragment] == '#') { + begin_fragment++; + parse_uric(&in[begin_fragment], max - begin_fragment, + &out->fragment); + } else { + out->fragment.buff = NULL; + out->fragment.size = 0; + } - if( ( ( begin_hostport + 1 ) < max ) && ( in[begin_hostport] == '/' ) - && ( in[begin_hostport + 1] == '/' ) ) { - begin_hostport += 2; - - if( ( begin_path = parse_hostport( &in[begin_hostport], - max - begin_hostport, - &out->hostport ) ) >= 0 ) { - begin_path += begin_hostport; - } else - return begin_path; - - } else { - memset( &out->hostport, 0, sizeof(out->hostport) ); - begin_path = begin_hostport; - } - - begin_fragment = - parse_uric( &in[begin_path], max - begin_path, - &out->pathquery ) + begin_path; - - if( ( out->pathquery.size ) && ( out->pathquery.buff[0] == '/' ) ) { - out->path_type = ABS_PATH; - } - - if( ( begin_fragment < max ) && ( in[begin_fragment] == '#' ) ) { - begin_fragment++; - parse_uric( &in[begin_fragment], max - begin_fragment, - &out->fragment ); - } else { - out->fragment.buff = NULL; - out->fragment.size = 0; - } - return HTTP_SUCCESS; + return HTTP_SUCCESS; } - -int parse_uri_and_unescape(char *in, int max, uri_type *out) +int parse_uri_and_unescape(char *in, size_t max, uri_type *out) { int ret = parse_uri(in, max, out); diff --git a/upnp/src/genlib/util/membuffer.c b/upnp/src/genlib/util/membuffer.c index 6ac3831..582ca67 100644 --- a/upnp/src/genlib/util/membuffer.c +++ b/upnp/src/genlib/util/membuffer.c @@ -462,61 +462,35 @@ membuffer_insert( INOUT membuffer * m, return 0; } -/************************************************************************ -* 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 ) +void membuffer_delete(membuffer *m, size_t index, size_t num_bytes) { - int return_value; - int new_length; - size_t copy_len; + int return_value; + int new_length; + size_t copy_len; - assert( m != NULL ); + assert(m != NULL); - if (!m) return; + if (!m || !m->length) + return; + /* shrink count if it goes beyond buffer */ + if (index + num_bytes > m->length) { + num_bytes = m->length - index; + /* every thing at and after index purged */ + copy_len = 0; + } else { + /* calc num bytes after deleted string */ + copy_len = m->length - (index + num_bytes); + } + memmove(m->buf + index, m->buf + index + num_bytes, copy_len); + new_length = m->length - num_bytes; + /* trim buffer */ + return_value = membuffer_set_size(m, new_length); + /* shrinking should always work */ + assert(return_value == 0); - if( m->length == 0 ) { - return; - } - - assert( index >= 0 && index < ( int )m->length ); - - /* shrink count if it goes beyond buffer */ - if( index + num_bytes > m->length ) { - num_bytes = m->length - ( size_t ) index; - copy_len = 0; /* every thing at and after index purged */ - } else { - /* calc num bytes after deleted string */ - copy_len = m->length - ( index + num_bytes ); - } - - memmove( m->buf + index, m->buf + index + num_bytes, copy_len ); - - new_length = m->length - num_bytes; - return_value = membuffer_set_size( m, new_length ); /* trim buffer */ - assert( return_value == 0 ); /* shrinking should always work */ - - /* don't modify until buffer is set */ - m->length = new_length; - m->buf[new_length] = 0; + /* don't modify until buffer is set */ + m->length = new_length; + m->buf[new_length] = 0; } /************************************************************************ diff --git a/upnp/src/inc/httpreadwrite.h b/upnp/src/inc/httpreadwrite.h index 4723ff0..713d826 100644 --- a/upnp/src/inc/httpreadwrite.h +++ b/upnp/src/inc/httpreadwrite.h @@ -32,6 +32,10 @@ #ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H #define GENLIB_NET_HTTP_HTTPREADWRITE_H +/* + * \file + */ + #include "config.h" #include "upnputil.h" #include "sock.h" @@ -46,39 +50,33 @@ int http_CancelHttpGet(IN void *Handle); -/************************************************************************ - * Function: http_FixUrl +/*! + * \brief Validates URL. * - * 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 ); + * \return + * \li \c UPNP_E_INVALID_URL + * \li \c UPNP_E_SUCCESS + */ +int http_FixUrl( + /*! [in] URL to be validated and fixed. */ + uri_type *url, + /*! [out] URL after being fixed. */ + uri_type *fixed_url); -/************************************************************************ - * Function: http_FixStrUrl +/*! + * \brief Parses URL and then validates URL. * - * Parameters: - * IN 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( IN const char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url ); - + * \return + * \li \c UPNP_E_INVALID_URL + * \li \c UPNP_E_SUCCESS + */ +int http_FixStrUrl( + /*! [in] Character string as a URL. */ + const char *urlstr, + /*! [in] Length of the character string. */ + size_t urlstrlen, + /*! [out] Fixed and corrected URL. */ + uri_type *fixed_url); /************************************************************************ * Function: http_Connect diff --git a/upnp/src/inc/membuffer.h b/upnp/src/inc/membuffer.h index 1be14c4..bbc3e5b 100644 --- a/upnp/src/inc/membuffer.h +++ b/upnp/src/inc/membuffer.h @@ -32,6 +32,10 @@ #ifndef GENLIB_UTIL_MEMBUFFER_H #define GENLIB_UTIL_MEMBUFFER_H +/*! + * \file + */ + #include #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 ); -/************************************************************************ -* 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 ); +/*! + * \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 + * new sized buffer. + */ +void membuffer_delete( + /* [in,out] Buffer whose memory size is to be decreased and copied + * to the modified location. */ + INOUT membuffer *m, + /* [in] Index to determine bounds while moving data. */ + IN size_t index, + /* [in] Number of bytes that the data needs to shrink by. */ + IN size_t num_bytes); /************************************************************************ diff --git a/upnp/src/inc/miniserver.h b/upnp/src/inc/miniserver.h index 5ccd515..9f7ffe5 100644 --- a/upnp/src/inc/miniserver.h +++ b/upnp/src/inc/miniserver.h @@ -59,11 +59,11 @@ typedef struct MServerSockArray { /*! IPv6 SSDP Socket for incoming advertisments and search requests. */ SOCKET ssdpSock6UlaGua; /* ! . */ - SOCKET stopPort; + uint16_t stopPort; /* ! . */ - unsigned short miniServerPort4; + uint16_t miniServerPort4; /* ! . */ - unsigned short miniServerPort6; + uint16_t miniServerPort6; #ifdef INCLUDE_CLIENT_APIS /*! IPv4 SSDP socket for sending search requests and receiving search * replies */ diff --git a/upnp/src/inc/uri.h b/upnp/src/inc/uri.h index 34b3458..8b3d055 100644 --- a/upnp/src/inc/uri.h +++ b/upnp/src/inc/uri.h @@ -149,7 +149,7 @@ typedef struct URI{ */ typedef struct URL_LIST { /*! */ - int size; + size_t size; /*! All the urls, delimited by <> */ char *URLs; /*! */ @@ -169,10 +169,10 @@ typedef struct URL_LIST { * \return */ int replace_escaped( - /*! [in] String of characters. */ + /*! [in,out] String of characters. */ char *in, /*! [in] Index at which to start checking the characters. */ - int index, + size_t index, /*! [out] . */ size_t *max); @@ -288,7 +288,7 @@ int parse_hostport( /*! [in] String of characters representing host and port. */ const char *in, /*! [in] Sets a maximum limit. */ - int max, + size_t max, /*! [out] Output parameter where the host and port are represented as * an internet address. */ hostport_type *out); @@ -388,7 +388,7 @@ int parse_uri_and_unescape( /*! [in] Character string containing uri information to be parsed. */ char *in, /*! [in] Maximum limit on the number of characters. */ - int max, + size_t max, /*! [out] Output parameter which will have the parsed uri information. */ uri_type *out); diff --git a/upnp/src/soap/soap_common.c b/upnp/src/soap/soap_common.c index fc0263e..312c681 100644 --- a/upnp/src/soap/soap_common.c +++ b/upnp/src/soap/soap_common.c @@ -6,7 +6,5 @@ #include "sock.h" #include "soaplib.h" - - -#endif // EXCLUDE_SOAP +#endif /* EXCLUDE_SOAP */