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 06aa3b17c4e20c482de3865b4e8608077db8284b) Conflicts: upnp/src/genlib/net/http/webserver.c
This commit is contained in:
parent
4f630b1213
commit
a01cf2817a
10
ChangeLog
10
ChangeLog
@ -357,6 +357,16 @@ Version 1.8.0
|
|||||||
Version 1.6.19
|
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>
|
2013-09-10 zexian chen <chenzexian88(at)gmail.com>
|
||||||
|
|
||||||
Hi,
|
Hi,
|
||||||
|
@ -774,7 +774,7 @@ static int GetNextRange(
|
|||||||
*
|
*
|
||||||
* \return
|
* \return
|
||||||
* \li \c HTTP_BAD_REQUEST
|
* \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_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* \li \c HTTP_OK
|
* \li \c HTTP_OK
|
||||||
*/
|
*/
|
||||||
@ -797,7 +797,7 @@ static int CreateHTTPRangeResponseHeader(
|
|||||||
return HTTP_BAD_REQUEST;
|
return HTTP_BAD_REQUEST;
|
||||||
RangeInput = malloc(strlen(ByteRangeSpecifier) + 1);
|
RangeInput = malloc(strlen(ByteRangeSpecifier) + 1);
|
||||||
if (!RangeInput)
|
if (!RangeInput)
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
memset(RangeInput, 0, strlen(ByteRangeSpecifier) + 1);
|
memset(RangeInput, 0, strlen(ByteRangeSpecifier) + 1);
|
||||||
strncpy(RangeInput, ByteRangeSpecifier, strlen(ByteRangeSpecifier));
|
strncpy(RangeInput, ByteRangeSpecifier, strlen(ByteRangeSpecifier));
|
||||||
/* CONTENT-RANGE: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
/* CONTENT-RANGE: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
||||||
@ -833,7 +833,7 @@ static int CreateHTTPRangeResponseHeader(
|
|||||||
(int64_t)FileLength);
|
(int64_t)FileLength);
|
||||||
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
||||||
free(RangeInput);
|
free(RangeInput);
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
} else if (FirstByte >= 0 && LastByte == -1
|
} else if (FirstByte >= 0 && LastByte == -1
|
||||||
&& FirstByte < FileLength) {
|
&& FirstByte < FileLength) {
|
||||||
@ -848,7 +848,7 @@ static int CreateHTTPRangeResponseHeader(
|
|||||||
(int64_t)FileLength);
|
(int64_t)FileLength);
|
||||||
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
||||||
free(RangeInput);
|
free(RangeInput);
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
} else if (FirstByte == -1 && LastByte > 0) {
|
} else if (FirstByte == -1 && LastByte > 0) {
|
||||||
if (LastByte >= FileLength) {
|
if (LastByte >= FileLength) {
|
||||||
@ -873,7 +873,7 @@ static int CreateHTTPRangeResponseHeader(
|
|||||||
}
|
}
|
||||||
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
|
||||||
free(RangeInput);
|
free(RangeInput);
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
free(RangeInput);
|
free(RangeInput);
|
||||||
@ -894,7 +894,7 @@ static int CreateHTTPRangeResponseHeader(
|
|||||||
*
|
*
|
||||||
* \return
|
* \return
|
||||||
* \li \c HTTP_BAD_REQUEST
|
* \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_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
* \li \c HTTP_OK
|
* \li \c HTTP_OK
|
||||||
*/
|
*/
|
||||||
@ -915,7 +915,7 @@ static int CheckOtherHTTPHeaders(
|
|||||||
|
|
||||||
TmpBuf = (char *)malloc(TmpBufSize);
|
TmpBuf = (char *)malloc(TmpBufSize);
|
||||||
if (!TmpBuf)
|
if (!TmpBuf)
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
node = ListHead(&Req->headers);
|
node = ListHead(&Req->headers);
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
header = (http_header_t *) node->item;
|
header = (http_header_t *) node->item;
|
||||||
@ -928,7 +928,7 @@ static int CheckOtherHTTPHeaders(
|
|||||||
TmpBufSize = header->value.length + 1;
|
TmpBufSize = header->value.length + 1;
|
||||||
TmpBuf = (char *)malloc(TmpBufSize);
|
TmpBuf = (char *)malloc(TmpBufSize);
|
||||||
if (!TmpBuf)
|
if (!TmpBuf)
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
memcpy(TmpBuf, header->value.buf, header->value.length);
|
memcpy(TmpBuf, header->value.buf, header->value.length);
|
||||||
TmpBuf[header->value.length] = '\0';
|
TmpBuf[header->value.length] = '\0';
|
||||||
@ -1017,8 +1017,11 @@ static int CheckOtherHTTPHeaders(
|
|||||||
*
|
*
|
||||||
* \return
|
* \return
|
||||||
* \li \c HTTP_BAD_REQUEST
|
* \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_REQUEST_RANGE_NOT_SATISFIABLE
|
||||||
|
* \li \c HTTP_FORBIDDEN
|
||||||
|
* \li \c HTTP_NOT_FOUND
|
||||||
|
* \li \c HTTP_NOT_ACCEPTABLE
|
||||||
* \li \c HTTP_OK
|
* \li \c HTTP_OK
|
||||||
*/
|
*/
|
||||||
static int process_request(
|
static int process_request(
|
||||||
@ -1203,14 +1206,15 @@ static int process_request(
|
|||||||
}
|
}
|
||||||
RespInstr->ReadSendSize = UpnpFileInfo_get_FileLength(finfo);
|
RespInstr->ReadSendSize = UpnpFileInfo_get_FileLength(finfo);
|
||||||
/* Check other header field. */
|
/* Check other header field. */
|
||||||
err_code = CheckOtherHTTPHeaders(req, RespInstr,
|
code = CheckOtherHTTPHeaders(req, RespInstr,
|
||||||
UpnpFileInfo_get_FileLength(finfo));
|
UpnpFileInfo_get_FileLength(finfo));
|
||||||
if (err_code != HTTP_OK) {
|
if (code != HTTP_OK) {
|
||||||
|
err_code = code;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
if (req->method == HTTPMETHOD_POST) {
|
if (req->method == HTTPMETHOD_POST) {
|
||||||
*rtype = RESP_POST;
|
*rtype = RESP_POST;
|
||||||
err_code = UPNP_E_SUCCESS;
|
err_code = HTTP_OK;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo);
|
extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo);
|
||||||
@ -1249,7 +1253,6 @@ static int process_request(
|
|||||||
}
|
}
|
||||||
} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
|
} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
|
||||||
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
||||||
/* Transfer-Encoding: chunked */
|
|
||||||
if (http_MakeMessage(headers, resp_major, resp_minor,
|
if (http_MakeMessage(headers, resp_major, resp_minor,
|
||||||
"R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
|
"R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
|
||||||
HTTP_PARTIAL_CONTENT, /* status code */
|
HTTP_PARTIAL_CONTENT, /* status code */
|
||||||
@ -1263,7 +1266,6 @@ static int process_request(
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
|
} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
|
||||||
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
|
||||||
/* Transfer-Encoding: chunked */
|
/* Transfer-Encoding: chunked */
|
||||||
if (http_MakeMessage(headers, resp_major, resp_minor,
|
if (http_MakeMessage(headers, resp_major, resp_minor,
|
||||||
"RK" "TLD" "s" "tcS" "Xc" "sCc",
|
"RK" "TLD" "s" "tcS" "Xc" "sCc",
|
||||||
@ -1278,8 +1280,6 @@ static int process_request(
|
|||||||
} else {
|
} else {
|
||||||
/* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
|
/* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
|
||||||
if (RespInstr->ReadSendSize >= 0) {
|
if (RespInstr->ReadSendSize >= 0) {
|
||||||
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
|
||||||
/* Transfer-Encoding: chunked */
|
|
||||||
if (http_MakeMessage(headers, resp_major, resp_minor,
|
if (http_MakeMessage(headers, resp_major, resp_minor,
|
||||||
"R" "N" "TLD" "s" "tcS" "Xc" "sCc",
|
"R" "N" "TLD" "s" "tcS" "Xc" "sCc",
|
||||||
HTTP_OK, /* status code */
|
HTTP_OK, /* status code */
|
||||||
@ -1293,8 +1293,6 @@ static int process_request(
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT */
|
|
||||||
/* Transfer-Encoding: chunked */
|
|
||||||
if (http_MakeMessage(headers, resp_major, resp_minor,
|
if (http_MakeMessage(headers, resp_major, resp_minor,
|
||||||
"R" "TLD" "s" "tcS" "Xc" "sCc",
|
"R" "TLD" "s" "tcS" "Xc" "sCc",
|
||||||
HTTP_OK, /* status code */
|
HTTP_OK, /* status code */
|
||||||
@ -1324,12 +1322,12 @@ static int process_request(
|
|||||||
if (req->method == HTTPMETHOD_SIMPLEGET) {
|
if (req->method == HTTPMETHOD_SIMPLEGET) {
|
||||||
membuffer_destroy(headers);
|
membuffer_destroy(headers);
|
||||||
}
|
}
|
||||||
err_code = UPNP_E_SUCCESS;
|
err_code = HTTP_OK;
|
||||||
|
|
||||||
error_handler:
|
error_handler:
|
||||||
free(request_doc);
|
free(request_doc);
|
||||||
UpnpFileInfo_delete(finfo);
|
UpnpFileInfo_delete(finfo);
|
||||||
if (err_code != UPNP_E_SUCCESS && alias_grabbed) {
|
if (err_code != HTTP_OK && alias_grabbed) {
|
||||||
alias_release(alias);
|
alias_release(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1491,7 +1489,7 @@ void web_server_callback(http_parser_t *parser, INOUT http_message_t *req,
|
|||||||
/*the type of request. */
|
/*the type of request. */
|
||||||
ret = process_request(req, &rtype, &headers, &filename, &xmldoc,
|
ret = process_request(req, &rtype, &headers, &filename, &xmldoc,
|
||||||
&RespInstr);
|
&RespInstr);
|
||||||
if (ret != UPNP_E_SUCCESS) {
|
if (ret != HTTP_OK) {
|
||||||
/* send error code */
|
/* send error code */
|
||||||
http_SendStatusResponse(info, ret, req->major_version,
|
http_SendStatusResponse(info, ret, req->major_version,
|
||||||
req->minor_version);
|
req->minor_version);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user