Improve upnp/genlib/net

Change ret_code from int to parse_status_t in match.
Set back return code of ReadResponseLineAndHeaders from parse_status_t
to int as this function can return UPNP_E_BAD_HTTPMSG. As a result, do
not cast the result of this function into parse_status_t in
http_OpenHttpGetProxy and http_OpenHttpGetEx.
Use switch with PARSE_OK in parsetools.c.
Add missing explicit casts of integer constants in uri.c and
httpreadwrite.c.
Use switch, int and sa_family_t with AF_INET in uri.c.
Print an error in http_Download if realloc failed.
This commit is contained in:
Fabrice Fontaine
2012-03-14 22:37:10 +01:00
parent 1a083479a9
commit b116d10f37
5 changed files with 56 additions and 27 deletions

View File

@@ -453,7 +453,7 @@ int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt, ...)
if (Instr && Instr->IsChunkActive) {
int rc;
/* Copy CRLF at the end of the chunk */
memcpy(file_buf + num_read, "\r\n", 2);
memcpy(file_buf + num_read, "\r\n", (size_t)2);
/* Hex length for the chunk size. */
memset(Chunk_Header, 0,
sizeof(Chunk_Header));
@@ -724,6 +724,10 @@ int http_Download( IN const char *url_str,
/* shrink can't fail */
assert(msg_length > *doc_length);
assert(*document != NULL);
if (msg_length <= *doc_length || *document == NULL)
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
"msg_length(%d) <= *doc_length(%d) or document"
" is NULL", msg_length, *doc_length);
}
if (response.msg.status_code == HTTP_OK) {
ret_code = 0; /* success */
@@ -874,7 +878,7 @@ int http_WriteHttpPost( IN void *Handle,
sprintf(tempbuf, "%" PRIzx "\r\n", *size);
tempSize = strlen(tempbuf);
memcpy(tempbuf + tempSize, buf, *size);
memcpy(tempbuf + tempSize + *size, "\r\n", 2);
memcpy(tempbuf + tempSize + *size, "\r\n", (size_t)2);
/* end of chunk */
tempbufSize = tempSize + *size + (size_t)2;
freeTempbuf = 1;
@@ -1113,7 +1117,7 @@ int MakeGetMessage(const char *url_str, const char *proxy_str,
* \li \c PARSE_FAILURE - Failure to parse data correctly
* \li \c UPNP_E_BAD_HTTPMSG - Socker read() returns an error
*/
static parse_status_t ReadResponseLineAndHeaders(
static int ReadResponseLineAndHeaders(
/*! Socket information object. */
IN SOCKINFO *info,
/*! HTTP Parser object. */
@@ -1511,10 +1515,9 @@ int http_OpenHttpGetProxy(const char *url_str, const char *proxy_str,
sock_destroy(&handle->sock_info, SD_BOTH);
goto errorHandler;
}
status = ReadResponseLineAndHeaders(&handle->sock_info,
&handle->response, &timeout,
&http_error_code);
if (status != (parse_status_t)PARSE_OK) {
if (ReadResponseLineAndHeaders(&handle->sock_info,
&handle->response, &timeout,
&http_error_code) != (int)PARSE_OK) {
ret_code = UPNP_E_BAD_RESPONSE;
goto errorHandler;
}
@@ -2055,9 +2058,8 @@ int http_OpenHttpGetEx(
free(handle);
break;
}
status = ReadResponseLineAndHeaders(&handle->sock_info,
&handle->response, &timeout, &http_error_code);
if (status != (parse_status_t)PARSE_OK) {
if (ReadResponseLineAndHeaders(&handle->sock_info,
&handle->response, &timeout, &http_error_code) != (int)PARSE_OK) {
errCode = UPNP_E_BAD_RESPONSE;
free(handle);
break;