Fix return value of process_request and related subroutines

1) Only HTTP_XXX should be return
2) Make default return value work for process_request
(cherry picked from commit 06aa3b17c4)

Conflicts:
	upnp/src/genlib/net/http/webserver.c
This commit is contained in:
Peng 2013-10-17 23:33:52 +08:00 committed by Marcelo Roberto Jimenez
parent 4f630b1213
commit a01cf2817a
2 changed files with 29 additions and 21 deletions

View File

@ -357,6 +357,16 @@ Version 1.8.0
Version 1.6.19
*******************************************************************************
2013-10-17 Peng <howtofly(at)gmail.com>
Fix return value of process_request and related subroutines
1) Only HTTP_XXX should be return
2) Make default return value work for process_request
2013-10-15 Peng <howtofly(at)gmail.com>
Fix Content-Range generation bug
2013-09-10 zexian chen <chenzexian88(at)gmail.com>
Hi,

View File

@ -774,7 +774,7 @@ static int GetNextRange(
*
* \return
* \li \c HTTP_BAD_REQUEST
* \li \c UPNP_E_OUTOF_MEMORY
* \li \c HTTP_INTERNAL_SERVER_ERROR
* \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* \li \c HTTP_OK
*/
@ -797,7 +797,7 @@ static int CreateHTTPRangeResponseHeader(
return HTTP_BAD_REQUEST;
RangeInput = malloc(strlen(ByteRangeSpecifier) + 1);
if (!RangeInput)
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
memset(RangeInput, 0, strlen(ByteRangeSpecifier) + 1);
strncpy(RangeInput, ByteRangeSpecifier, strlen(ByteRangeSpecifier));
/* CONTENT-RANGE: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
@ -833,7 +833,7 @@ static int CreateHTTPRangeResponseHeader(
(int64_t)FileLength);
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
free(RangeInput);
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
}
} else if (FirstByte >= 0 && LastByte == -1
&& FirstByte < FileLength) {
@ -848,7 +848,7 @@ static int CreateHTTPRangeResponseHeader(
(int64_t)FileLength);
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
free(RangeInput);
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
}
} else if (FirstByte == -1 && LastByte > 0) {
if (LastByte >= FileLength) {
@ -873,7 +873,7 @@ static int CreateHTTPRangeResponseHeader(
}
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
free(RangeInput);
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
}
} else {
free(RangeInput);
@ -894,7 +894,7 @@ static int CreateHTTPRangeResponseHeader(
*
* \return
* \li \c HTTP_BAD_REQUEST
* \li \c UPNP_E_OUTOF_MEMORY
* \li \c HTTP_INTERNAL_SERVER_ERROR
* \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* \li \c HTTP_OK
*/
@ -915,7 +915,7 @@ static int CheckOtherHTTPHeaders(
TmpBuf = (char *)malloc(TmpBufSize);
if (!TmpBuf)
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
node = ListHead(&Req->headers);
while (node != NULL) {
header = (http_header_t *) node->item;
@ -928,7 +928,7 @@ static int CheckOtherHTTPHeaders(
TmpBufSize = header->value.length + 1;
TmpBuf = (char *)malloc(TmpBufSize);
if (!TmpBuf)
return UPNP_E_OUTOF_MEMORY;
return HTTP_INTERNAL_SERVER_ERROR;
}
memcpy(TmpBuf, header->value.buf, header->value.length);
TmpBuf[header->value.length] = '\0';
@ -1017,8 +1017,11 @@ static int CheckOtherHTTPHeaders(
*
* \return
* \li \c HTTP_BAD_REQUEST
* \li \c UPNP_E_OUTOF_MEMORY
* \li \c HTTP_INTERNAL_SERVER_ERROR
* \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
* \li \c HTTP_FORBIDDEN
* \li \c HTTP_NOT_FOUND
* \li \c HTTP_NOT_ACCEPTABLE
* \li \c HTTP_OK
*/
static int process_request(
@ -1203,14 +1206,15 @@ static int process_request(
}
RespInstr->ReadSendSize = UpnpFileInfo_get_FileLength(finfo);
/* Check other header field. */
err_code = CheckOtherHTTPHeaders(req, RespInstr,
code = CheckOtherHTTPHeaders(req, RespInstr,
UpnpFileInfo_get_FileLength(finfo));
if (err_code != HTTP_OK) {
if (code != HTTP_OK) {
err_code = code;
goto error_handler;
}
if (req->method == HTTPMETHOD_POST) {
*rtype = RESP_POST;
err_code = UPNP_E_SUCCESS;
err_code = HTTP_OK;
goto error_handler;
}
extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo);
@ -1249,7 +1253,6 @@ static int process_request(
}
} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
/* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, /* status code */
@ -1263,7 +1266,6 @@ static int process_request(
goto error_handler;
}
} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
/* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor,
"RK" "TLD" "s" "tcS" "Xc" "sCc",
@ -1278,8 +1280,6 @@ static int process_request(
} else {
/* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
if (RespInstr->ReadSendSize >= 0) {
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
/* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "N" "TLD" "s" "tcS" "Xc" "sCc",
HTTP_OK, /* status code */
@ -1293,8 +1293,6 @@ static int process_request(
goto error_handler;
}
} else {
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
/* Transfer-Encoding: chunked */
if (http_MakeMessage(headers, resp_major, resp_minor,
"R" "TLD" "s" "tcS" "Xc" "sCc",
HTTP_OK, /* status code */
@ -1324,12 +1322,12 @@ static int process_request(
if (req->method == HTTPMETHOD_SIMPLEGET) {
membuffer_destroy(headers);
}
err_code = UPNP_E_SUCCESS;
err_code = HTTP_OK;
error_handler:
free(request_doc);
UpnpFileInfo_delete(finfo);
if (err_code != UPNP_E_SUCCESS && alias_grabbed) {
if (err_code != HTTP_OK && alias_grabbed) {
alias_release(alias);
}
@ -1491,7 +1489,7 @@ void web_server_callback(http_parser_t *parser, INOUT http_message_t *req,
/*the type of request. */
ret = process_request(req, &rtype, &headers, &filename, &xmldoc,
&RespInstr);
if (ret != UPNP_E_SUCCESS) {
if (ret != HTTP_OK) {
/* send error code */
http_SendStatusResponse(info, ret, req->major_version,
req->minor_version);