Debug code for http_RecvMessage().

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@448 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2008-07-10 03:55:07 +00:00
parent b0f782f9c2
commit 654363468a

View File

@@ -205,8 +205,12 @@ http_Connect( IN uri_type * destination_url,
}
/************************************************************************
* Function: http_RecvMessage
/*!
* \brief Get the data on the socket and take actions based on the read data to
* modify the parser objects buffer.
*
* If an error is reported while parsing the data, the error code is passed in
* the http_errr_code parameter.
*
* Parameters:
* IN SOCKINFO *info; Socket information object
@@ -215,23 +219,19 @@ http_Connect( IN uri_type * destination_url,
* IN OUT int* timeout_secs; time out
* OUT int* http_error_code; HTTP error code returned
*
* Description:
* Get the data on the socket and take actions based on the read data
* to modify the parser objects buffer. If an error is reported while
* parsing the data, the error code is passed in the http_errr_code
* parameter
*
* Returns:
* UPNP_E_BAD_HTTPMSG
* \return
* UPNP_E_SUCCESS
************************************************************************/
int
http_RecvMessage( IN SOCKINFO * info,
* UPNP_E_BAD_HTTPMSG
*/
int http_RecvMessage(
IN SOCKINFO *info,
OUT http_parser_t *parser,
IN http_method_t request_method,
IN OUT int *timeout_secs,
OUT int *http_error_code)
{
int ret = UPNP_E_SUCCESS;
int line = 0;
parse_status_t status;
int num_read;
xboolean ok_on_close = FALSE;
@@ -244,33 +244,37 @@ http_RecvMessage( IN SOCKINFO * info,
}
while (TRUE) {
num_read = sock_read( info, buf, sizeof( buf ), timeout_secs );
num_read = sock_read(info, buf, sizeof buf, timeout_secs);
if (num_read > 0) {
// got data
status = parser_append(parser, buf, num_read);
if (status == PARSE_SUCCESS) {
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"<<< (RECVD) <<<\n%s\n-----------------\n",
parser->msg.msg.buf );
print_http_headers( &parser->msg );
if( parser->content_length >
( unsigned int )g_maxContentLength ) {
if (parser->content_length > (unsigned int)g_maxContentLength) {
*http_error_code = HTTP_REQ_ENTITY_TOO_LARGE;
return UPNP_E_OUTOF_BOUNDS;
line = __LINE__;
ret = UPNP_E_OUTOF_BOUNDS;
goto ExitFunction;
}
return 0;
line = __LINE__;
ret = 0;
goto ExitFunction;
} else if (status == PARSE_FAILURE) {
*http_error_code = parser->http_error_code;
return UPNP_E_BAD_HTTPMSG;
line = __LINE__;
ret = UPNP_E_BAD_HTTPMSG;
goto ExitFunction;
} else if (status == PARSE_INCOMPLETE_ENTITY) {
// read until close
ok_on_close = TRUE;
} else if( status == PARSE_CONTINUE_1 ) //Web post request. murari
{
return PARSE_SUCCESS;
} else if (status == PARSE_CONTINUE_1) {
// Web post request.
line = __LINE__;
ret = PARSE_SUCCESS;
goto ExitFunction;
}
} else if (num_read == 0) {
if (ok_on_close) {
@@ -278,18 +282,33 @@ http_RecvMessage( IN SOCKINFO * info,
"<<< (RECVD) <<<\n%s\n-----------------\n",
parser->msg.msg.buf );
print_http_headers(&parser->msg);
return 0;
line = __LINE__;
ret = 0;
goto ExitFunction;
} else {
// partial msg
*http_error_code = HTTP_BAD_REQUEST; // or response
return UPNP_E_BAD_HTTPMSG;
line = __LINE__;
ret = UPNP_E_BAD_HTTPMSG;
goto ExitFunction;
}
} else {
*http_error_code = parser->http_error_code;
return num_read;
line = __LINE__;
ret = num_read;
goto ExitFunction;
}
}
ExitFunction:
if (ret != UPNP_E_SUCCESS) {
UpnpPrintf(UPNP_ALL, HTTP, __FILE__, line,
"(http_RecvMessage): Error %d, http_error_code = %d.\n",
ret,
*http_error_code);
}
return ret;
}