Thorough revision of every call of http_MakeMessage() due to a bug introduced

in rev.79: largefile patch added.

http_MakeMessage() has a worst than brain damaged "printf" like interface.
In rev.79, the "N" format parameter must be an off_t. Every call of this
function with an "N" format parameter and an int passed on the stack 
would fail terribly.

Not every place I touched had a bug, but to review the format and keep my
sanity, I had to format it properly.



git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@96 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2006-12-23 18:38:00 +00:00
parent 819ad1f365
commit 1d9e8712b7
7 changed files with 265 additions and 216 deletions

View File

@@ -640,10 +640,11 @@ http_Download( IN const char *url_str,
"HOSTNAME : %s Length : %d\n", hoststr, hostlen );
)
ret_code = http_MakeMessage( &request, 1, 1, "QsbcDCUc",
HTTPMETHOD_GET, url.pathquery.buff,
url.pathquery.size, "HOST: ", hoststr,
hostlen );
ret_code = http_MakeMessage(
&request, 1, 1,
"QsbcDCUc",
HTTPMETHOD_GET, url.pathquery.buff, url.pathquery.size,
"HOST: ", hoststr, hostlen );
if( ret_code != 0 ) {
DBGONLY( UpnpPrintf
( UPNP_INFO, HTTP, __FILE__, __LINE__,
@@ -796,21 +797,27 @@ MakePostMessage( const char *url_str,
)
if( contentLength >= 0 ) {
ret_code = http_MakeMessage( request, 1, 1, "QsbcDCUTNc",
HTTPMETHOD_POST, url->pathquery.buff,
url->pathquery.size, "HOST: ",
hoststr, hostlen, contentType,
contentLength );
ret_code = http_MakeMessage(
request, 1, 1,
"QsbcDCUTNc",
HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size,
"HOST: ", hoststr, hostlen,
contentType,
(off_t)contentLength );
} else if( contentLength == UPNP_USING_CHUNKED ) {
ret_code = http_MakeMessage( request, 1, 1, "QsbcDCUTKc",
HTTPMETHOD_POST, url->pathquery.buff,
url->pathquery.size, "HOST: ",
hoststr, hostlen, contentType );
ret_code = http_MakeMessage(
request, 1, 1,
"QsbcDCUTKc",
HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size,
"HOST: ", hoststr, hostlen,
contentType );
} else if( contentLength == UPNP_UNTIL_CLOSE ) {
ret_code = http_MakeMessage( request, 1, 1, "QsbcDCUTc",
HTTPMETHOD_POST, url->pathquery.buff,
url->pathquery.size, "HOST: ",
hoststr, hostlen, contentType );
ret_code = http_MakeMessage(
request, 1, 1,
"QsbcDCUTc",
HTTPMETHOD_POST, url->pathquery.buff, url->pathquery.size,
"HOST: ", hoststr, hostlen,
contentType );
} else {
ret_code = UPNP_E_INVALID_PARAM;
}
@@ -1131,9 +1138,11 @@ MakeGetMessage( const char *url_str,
querylen = url->pathquery.size;
}
ret_code = http_MakeMessage( request, 1, 1, "QsbcDCUc",
HTTPMETHOD_GET, querystr, querylen,
"HOST: ", hoststr, hostlen );
ret_code = http_MakeMessage(
request, 1, 1,
"QsbcDCUc",
HTTPMETHOD_GET, querystr, querylen,
"HOST: ", hoststr, hostlen );
if( ret_code != 0 ) {
DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
@@ -1729,8 +1738,11 @@ http_SendStatusResponse( IN SOCKINFO * info,
membuffer_init( &membuf );
membuf.size_inc = 70;
ret = http_MakeMessage( &membuf, response_major, response_minor, "RSCB", http_status_code, // response start line
http_status_code ); // body
ret = http_MakeMessage(
&membuf, response_major, response_minor,
"RSCB",
http_status_code, // response start line
http_status_code ); // body
if( ret == 0 ) {
timeout = HTTP_DEFAULT_TIMEOUT;
ret = http_SendMessage( info, &timeout, "b",
@@ -1770,6 +1782,7 @@ http_SendStatusResponse( IN SOCKINFO * info,
* 'C': (no args) appends a HTTP CONNECTION: close header
* depending on major,minor version
* 'N': arg1 = int content_length // content-length header
* 'q': arg1 = http_method_t, arg2 = (uri_type *) // request start line and HOST header
* 'Q': arg1 = http_method_t; arg2 = char* url;
* arg3 = int url_length // start line of request
* 'R': arg = int status_code // adds a response start line
@@ -1777,9 +1790,7 @@ http_SendStatusResponse( IN SOCKINFO * info,
* appends content-length, content-type and HTML body for given code
* 'T': arg = char * content_type; format e.g: "text/html";
* content-type header
* --- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld@users.sourceforge.net>
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
* --- PATCH END ---
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
*
* Return : int;
* 0 - On Success
@@ -1940,9 +1951,10 @@ http_MakeMessage( INOUT membuffer * buf,
bignum = ( off_t )va_arg( argp, off_t );
assert( bignum >= 0 );
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "shc",
"CONTENT-LENGTH: ", bignum ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"shc",
"CONTENT-LENGTH: ", bignum ) != 0 ) {
goto error_handler;
}
}
@@ -1952,14 +1964,14 @@ http_MakeMessage( INOUT membuffer * buf,
temp_str = ( c == 'S' ) ? "SERVER: " : "USER-AGENT: ";
get_sdk_info( tempbuf );
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "ss",
temp_str, tempbuf ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"ss",
temp_str, tempbuf ) != 0 ) {
goto error_handler;
}
}
/* --- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld@users.sourceforge.net> */
else if( c == 'X' ) // C string
{
s = ( char * )va_arg( argp, char * );
@@ -1974,9 +1986,6 @@ http_MakeMessage( INOUT membuffer * buf,
}
}
/* --- PATCH END --- */
else if( c == 'R' ) {
// response start line
// e.g.: 'HTTP/1.1 200 OK'
@@ -1991,9 +2000,11 @@ http_MakeMessage( INOUT membuffer * buf,
// str
status_msg = http_get_code_text( status_code );
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "ssc",
tempbuf, status_msg ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"ssc",
tempbuf,
status_msg ) != 0 ) {
goto error_handler;
}
}
@@ -2010,9 +2021,12 @@ http_MakeMessage( INOUT membuffer * buf,
"</h1></body></html>" );
bignum = strlen( tempbuf );
if( http_MakeMessage( buf, http_major_version, http_minor_version, "NTcs", bignum, // content-length
"text/html", // content-type
tempbuf ) != 0 ) // body
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"NTcs",
bignum, // content-length
"text/html", // content-type
tempbuf ) != 0 ) // body
{
goto error_handler;
}
@@ -2021,17 +2035,18 @@ http_MakeMessage( INOUT membuffer * buf,
else if( c == 'Q' ) {
// request start line
// GET /foo/bar.html HTTP/1.1\r\n
//
method = ( http_method_t ) va_arg( argp, http_method_t );
method_str = method_to_str( method );
url_str = ( const char * )va_arg( argp, const char * );
num = ( int )va_arg( argp, int ); // length of url_str
if( http_MakeMessage( buf, http_major_version, http_minor_version, "ssbsdsdc", method_str, // method
" ", url_str, num, // url
" HTTP/", http_major_version, ".",
http_minor_version ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"ssbsdsdc",
method_str, // method
" ", url_str, num, // url
" HTTP/", http_major_version, ".", http_minor_version ) != 0 ) {
goto error_handler;
}
}
@@ -2048,10 +2063,11 @@ http_MakeMessage( INOUT membuffer * buf,
goto error_handler;
}
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "Q" "sbc",
method, url.pathquery.buff, url.pathquery.size, "HOST: ",
url.hostport.text.buff, url.hostport.text.size ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"Q" "sbc",
method, url.pathquery.buff, url.pathquery.size,
"HOST: ", url.hostport.text.buff, url.hostport.text.size ) != 0 ) {
goto error_handler;
}
}
@@ -2060,9 +2076,10 @@ http_MakeMessage( INOUT membuffer * buf,
// content type header
temp_str = ( const char * )va_arg( argp, const char * ); // type/subtype format
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "ssc",
"CONTENT-TYPE: ", temp_str ) != 0 ) {
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"ssc",
"CONTENT-TYPE: ", temp_str ) != 0 ) {
goto error_handler;
}
}
@@ -2186,16 +2203,13 @@ MakeGetMessageEx( const char *url_str,
hostlen );
)
errCode = http_MakeMessage( request,
1,
1,
"QsbcGDCUc",
HTTPMETHOD_GET,
url->pathquery.buff,
url->pathquery.size,
"HOST: ",
hoststr,
hostlen, pRangeSpecifier );
errCode = http_MakeMessage(
request, 1, 1,
"QsbcGDCUc",
HTTPMETHOD_GET,
url->pathquery.buff, url->pathquery.size,
"HOST: ", hoststr, hostlen,
pRangeSpecifier );
if( errCode != 0 ) {
DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,