Backport: Debug code for http_RecvMessage().
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@450 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
e0c9de0b1d
commit
bcf5a5c5e0
@ -1,33 +1,34 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
*
|
||||||
// Copyright (c) 2000-2003 Intel Corporation
|
* Copyright (c) 2000-2003 Intel Corporation
|
||||||
// All rights reserved.
|
* All rights reserved.
|
||||||
//
|
*
|
||||||
// Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
//
|
*
|
||||||
// * Redistributions of source code must retain the above copyright notice,
|
* - Redistributions of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
// * Neither name of Intel Corporation nor the names of its contributors
|
* - Neither name of Intel Corporation nor the names of its contributors
|
||||||
// may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
// without specific prior written permission.
|
* without specific prior written permission.
|
||||||
//
|
*
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
*
|
||||||
///////////////////////////////////////////////////////////////////////////
|
******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Purpose: This file defines the functionality making use of the http
|
* Purpose: This file defines the functionality making use of the http
|
||||||
@ -35,10 +36,27 @@
|
|||||||
* messages
|
* messages
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "httpreadwrite.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "unixutil.h"
|
||||||
|
#include "upnp.h"
|
||||||
|
#include "upnpapi.h"
|
||||||
|
#include "membuffer.h"
|
||||||
|
#include "uri.h"
|
||||||
|
#include "statcodes.h"
|
||||||
|
#include "sock.h"
|
||||||
|
#include "webserver.h"
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef UPNP_USE_BCBPP
|
#ifndef UPNP_USE_BCBPP
|
||||||
#ifndef UPNP_USE_MSVCPP
|
#ifndef UPNP_USE_MSVCPP
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -46,7 +64,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@ -56,19 +78,7 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#else
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include "unixutil.h"
|
|
||||||
#include "upnp.h"
|
|
||||||
#include "upnpapi.h"
|
|
||||||
#include "membuffer.h"
|
|
||||||
#include "uri.h"
|
|
||||||
#include "statcodes.h"
|
|
||||||
#include "httpreadwrite.h"
|
|
||||||
#include "sock.h"
|
|
||||||
#include "webserver.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -126,9 +136,9 @@ http_FixUrl( IN uri_type * url,
|
|||||||
* Function: http_FixStrUrl
|
* Function: http_FixStrUrl
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* IN char* urlstr ; Character string as a URL
|
* IN const char* urlstr; Character string as a URL
|
||||||
* IN int urlstrlen ; Length of the character string
|
* IN int urlstrlen; Length of the character string
|
||||||
* OUT uri_type* fixed_url ; Fixed and corrected URL
|
* OUT uri_type* fixed_url; Fixed and corrected URL
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Parses URL and then validates URL
|
* Parses URL and then validates URL
|
||||||
@ -138,7 +148,7 @@ http_FixUrl( IN uri_type * url,
|
|||||||
* UPNP_E_SUCCESS
|
* UPNP_E_SUCCESS
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int
|
int
|
||||||
http_FixStrUrl( IN char *urlstr,
|
http_FixStrUrl( IN const char *urlstr,
|
||||||
IN int urlstrlen,
|
IN int urlstrlen,
|
||||||
OUT uri_type * fixed_url )
|
OUT uri_type * fixed_url )
|
||||||
{
|
{
|
||||||
@ -195,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:
|
* Parameters:
|
||||||
* IN SOCKINFO *info; Socket information object
|
* IN SOCKINFO *info; Socket information object
|
||||||
@ -205,81 +219,96 @@ http_Connect( IN uri_type * destination_url,
|
|||||||
* IN OUT int* timeout_secs; time out
|
* IN OUT int* timeout_secs; time out
|
||||||
* OUT int* http_error_code; HTTP error code returned
|
* OUT int* http_error_code; HTTP error code returned
|
||||||
*
|
*
|
||||||
* Description:
|
* \return
|
||||||
* 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
|
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_SUCCESS
|
||||||
************************************************************************/
|
* UPNP_E_BAD_HTTPMSG
|
||||||
int
|
*/
|
||||||
http_RecvMessage( IN SOCKINFO * info,
|
int http_RecvMessage(
|
||||||
OUT http_parser_t * parser,
|
IN SOCKINFO *info,
|
||||||
|
OUT http_parser_t *parser,
|
||||||
IN http_method_t request_method,
|
IN http_method_t request_method,
|
||||||
IN OUT int *timeout_secs,
|
IN OUT int *timeout_secs,
|
||||||
OUT int *http_error_code )
|
OUT int *http_error_code)
|
||||||
{
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
int line = 0;
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
int num_read;
|
int num_read;
|
||||||
xboolean ok_on_close = FALSE;
|
xboolean ok_on_close = FALSE;
|
||||||
char buf[2 * 1024];
|
char buf[2 * 1024];
|
||||||
|
|
||||||
if( request_method == HTTPMETHOD_UNKNOWN ) {
|
if (request_method == HTTPMETHOD_UNKNOWN) {
|
||||||
parser_request_init( parser );
|
parser_request_init(parser);
|
||||||
} else {
|
} else {
|
||||||
parser_response_init( parser, request_method );
|
parser_response_init(parser, request_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
while( TRUE ) {
|
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 ) {
|
if (num_read > 0) {
|
||||||
// got data
|
// got data
|
||||||
status = parser_append( parser, buf, num_read );
|
status = parser_append(parser, buf, num_read);
|
||||||
|
if (status == PARSE_SUCCESS) {
|
||||||
if( status == PARSE_SUCCESS ) {
|
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"<<< (RECVD) <<<\n%s\n-----------------\n",
|
"<<< (RECVD) <<<\n%s\n-----------------\n",
|
||||||
parser->msg.msg.buf );
|
parser->msg.msg.buf );
|
||||||
print_http_headers( &parser->msg );
|
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;
|
*http_error_code = HTTP_REQ_ENTITY_TOO_LARGE;
|
||||||
return UPNP_E_OUTOF_BOUNDS;
|
line = __LINE__;
|
||||||
|
ret = UPNP_E_OUTOF_BOUNDS;
|
||||||
|
goto ExitFunction;
|
||||||
}
|
}
|
||||||
|
line = __LINE__;
|
||||||
return 0;
|
ret = 0;
|
||||||
} else if( status == PARSE_FAILURE ) {
|
goto ExitFunction;
|
||||||
|
} else if (status == PARSE_FAILURE) {
|
||||||
*http_error_code = parser->http_error_code;
|
*http_error_code = parser->http_error_code;
|
||||||
return UPNP_E_BAD_HTTPMSG;
|
line = __LINE__;
|
||||||
} else if( status == PARSE_INCOMPLETE_ENTITY ) {
|
ret = UPNP_E_BAD_HTTPMSG;
|
||||||
|
goto ExitFunction;
|
||||||
|
} else if (status == PARSE_INCOMPLETE_ENTITY) {
|
||||||
// read until close
|
// read until close
|
||||||
ok_on_close = TRUE;
|
ok_on_close = TRUE;
|
||||||
} else if( status == PARSE_CONTINUE_1 ) //Web post request. murari
|
} else if (status == PARSE_CONTINUE_1) {
|
||||||
{
|
// Web post request.
|
||||||
return PARSE_SUCCESS;
|
line = __LINE__;
|
||||||
|
ret = PARSE_SUCCESS;
|
||||||
|
goto ExitFunction;
|
||||||
}
|
}
|
||||||
} else if( num_read == 0 ) {
|
} else if (num_read == 0) {
|
||||||
if( ok_on_close ) {
|
if (ok_on_close) {
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"<<< (RECVD) <<<\n%s\n-----------------\n",
|
"<<< (RECVD) <<<\n%s\n-----------------\n",
|
||||||
parser->msg.msg.buf );
|
parser->msg.msg.buf );
|
||||||
print_http_headers( &parser->msg );
|
print_http_headers(&parser->msg);
|
||||||
|
line = __LINE__;
|
||||||
return 0;
|
ret = 0;
|
||||||
|
goto ExitFunction;
|
||||||
} else {
|
} else {
|
||||||
// partial msg
|
// partial msg
|
||||||
*http_error_code = HTTP_BAD_REQUEST; // or response
|
*http_error_code = HTTP_BAD_REQUEST; // or response
|
||||||
return UPNP_E_BAD_HTTPMSG;
|
line = __LINE__;
|
||||||
|
ret = UPNP_E_BAD_HTTPMSG;
|
||||||
|
goto ExitFunction;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*http_error_code = parser->http_error_code;
|
*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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -642,8 +671,9 @@ http_Download( IN const char *url_str,
|
|||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"HTTP Buffer:\n %s\n----------END--------\n", request.buf );
|
"HTTP Buffer:\n%s\n" "----------END--------\n",
|
||||||
|
request.buf);
|
||||||
// get doc msg
|
// get doc msg
|
||||||
ret_code =
|
ret_code =
|
||||||
http_RequestAndResponse( &url, request.buf, request.length,
|
http_RequestAndResponse( &url, request.buf, request.length,
|
||||||
@ -813,9 +843,9 @@ MakePostMessage( const char *url_str,
|
|||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"HTTP Buffer:\n %s\n" "----------END--------\n",
|
"HTTP Buffer:\n%s\n" "----------END--------\n",
|
||||||
request->buf );
|
request->buf);
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -1132,9 +1162,9 @@ MakeGetMessage( const char *url_str,
|
|||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"HTTP Buffer:\n %s\n" "----------END--------\n",
|
"HTTP Buffer:\n%s\n" "----------END--------\n",
|
||||||
request->buf );
|
request->buf);
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -2138,9 +2168,9 @@ MakeGetMessageEx( const char *url_str,
|
|||||||
}
|
}
|
||||||
} while( 0 );
|
} while( 0 );
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"HTTP Buffer:\n %s\n" "----------END--------\n",
|
"HTTP Buffer:\n%s\n" "----------END--------\n",
|
||||||
request->buf );
|
request->buf);
|
||||||
|
|
||||||
return errCode;
|
return errCode;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
|
|||||||
* UPNP_E_INVALID_URL
|
* UPNP_E_INVALID_URL
|
||||||
* UPNP_E_SUCCESS
|
* UPNP_E_SUCCESS
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int http_FixStrUrl( IN char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
|
int http_FixStrUrl( IN const char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user