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

@@ -219,10 +219,11 @@ gena_unsubscribe( IN char *url,
// make request msg // make request msg
membuffer_init( &request ); membuffer_init( &request );
request.size_inc = 30; request.size_inc = 30;
return_code = http_MakeMessage( &request, 1, 1, return_code = http_MakeMessage(
"q" "ssc" "U" "c", &request, 1, 1,
HTTPMETHOD_UNSUBSCRIBE, &dest_url, "q" "ssc" "Uc",
"SID: ", sid ); HTTPMETHOD_UNSUBSCRIBE, &dest_url,
"SID: ", sid );
//Not able to make the message so destroy the existing buffer //Not able to make the message so destroy the existing buffer
if( return_code != 0 ) { if( return_code != 0 ) {
@@ -305,20 +306,21 @@ gena_subscribe( IN char *url,
request.size_inc = 30; request.size_inc = 30;
if( renewal_sid ) { if( renewal_sid ) {
// renew subscription // renew subscription
return_code = http_MakeMessage( &request, 1, 1, return_code = http_MakeMessage(
"q" "ssc" "ssc" "c", &request, 1, 1,
HTTPMETHOD_SUBSCRIBE, &dest_url, "q" "ssc" "sscc",
"SID: ", renewal_sid, HTTPMETHOD_SUBSCRIBE, &dest_url,
"TIMEOUT: Second-", timeout_str ); "SID: ", renewal_sid,
"TIMEOUT: Second-", timeout_str );
} else { } else {
// subscribe // subscribe
return_code = http_MakeMessage( &request, 1, 1, return_code = http_MakeMessage(
"q" "sssdsscc", &request, 1, 1,
HTTPMETHOD_SUBSCRIBE, &dest_url, "q" "sssdsc" "sc" "sscc",
"CALLBACK: <http://", LOCAL_HOST, HTTPMETHOD_SUBSCRIBE, &dest_url,
":", LOCAL_PORT, "CALLBACK: <http://", LOCAL_HOST, ":", LOCAL_PORT, "/>",
"/>\r\n" "NT: upnp:event\r\n" "NT: upnp:event",
"TIMEOUT: Second-", timeout_str ); "TIMEOUT: Second-", timeout_str );
} }
if( return_code != 0 ) { if( return_code != 0 ) {
return return_code; return return_code;

View File

@@ -219,9 +219,11 @@ notify_send_and_recv( IN uri_type * destination_url,
} }
// make start line and HOST header // make start line and HOST header
membuffer_init( &start_msg ); membuffer_init( &start_msg );
if( http_MakeMessage( &start_msg, 1, 1, if (http_MakeMessage(
"q" "s", &start_msg, 1, 1,
HTTPMETHOD_NOTIFY, &url, mid_msg->buf ) != 0 ) { "q" "s",
HTTPMETHOD_NOTIFY, &url,
mid_msg->buf ) != 0 ) {
membuffer_destroy( &start_msg ); membuffer_destroy( &start_msg );
sock_destroy( &info, SD_BOTH ); sock_destroy( &info, SD_BOTH );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
@@ -296,11 +298,12 @@ genaNotify( IN char *headers,
// make 'end' msg (the part that won't vary with the destination) // make 'end' msg (the part that won't vary with the destination)
endmsg.size_inc = 30; endmsg.size_inc = 30;
if( http_MakeMessage( &mid_msg, 1, 1, if( http_MakeMessage(
"s" "ssc" "sdcc", &mid_msg, 1, 1,
headers, "s" "ssc" "sdcc",
"SID: ", sub->sid, headers,
"SEQ: ", sub->ToSendEventKey ) != 0 ) { "SID: ", sub->sid,
"SEQ: ", sub->ToSendEventKey ) != 0 ) {
membuffer_destroy( &mid_msg ); membuffer_destroy( &mid_msg );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
@@ -1165,10 +1168,14 @@ respond_ok( IN SOCKINFO * info,
membuffer_init( &response ); membuffer_init( &response );
response.size_inc = 30; response.size_inc = 30;
if( http_MakeMessage( &response, major, minor, if( http_MakeMessage(
"R" "D" "S" "N" "Xc" "ssc" "sc" "c", &response, major, minor,
HTTP_OK, (off_t)0, X_USER_AGENT, "R" "D" "S" "N" "Xc" "ssc" "scc",
"SID: ", sub->sid, timeout_str ) != 0 ) { HTTP_OK,
(off_t)0,
X_USER_AGENT,
"SID: ", sub->sid,
timeout_str ) != 0 ) {
membuffer_destroy( &response ); membuffer_destroy( &response );
error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request ); error_respond( info, HTTP_INTERNAL_SERVER_ERROR, request );
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;

View File

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

View File

@@ -1377,21 +1377,19 @@ process_request( IN http_message_t * req,
if( RespInstr->IsRangeActive && RespInstr->IsChunkActive ) { if( RespInstr->IsRangeActive && RespInstr->IsChunkActive ) {
/* - PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net>
* added X-User-Agent header
*/
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT //Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked //Transfer-Encoding: chunked
// K means add chunky header ang G means range header. // K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RTGKDstcSXcCc", HTTP_PARTIAL_CONTENT, // status code if (http_MakeMessage(
// RespInstr->ReadSendSize,// content length headers, resp_major, resp_minor,
finfo.content_type, "RTGKDstcSXcCc",
// content_type.buf, // content type HTTP_PARTIAL_CONTENT, // status code
RespInstr, // Range // RespInstr->ReadSendSize,// content length
"LAST-MODIFIED: ", finfo.content_type,
&finfo.last_modified, // content_type.buf, // content type
X_USER_AGENT) != 0 ) { RespInstr, // Range
"LAST-MODIFIED: ", &finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
} else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) { } else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) {
@@ -1399,14 +1397,16 @@ process_request( IN http_message_t * req,
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT //Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked //Transfer-Encoding: chunked
// K means add chunky header ang G means range header. // K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RNTGDstcSXcCc", HTTP_PARTIAL_CONTENT, // status code if (http_MakeMessage(
RespInstr->ReadSendSize, // content length headers, resp_major, resp_minor,
finfo.content_type, "RNTGDstcSXcCc",
//content_type.buf, // content type HTTP_PARTIAL_CONTENT, // status code
RespInstr, //Range Info (off_t)RespInstr->ReadSendSize, // content length
"LAST-MODIFIED: ", finfo.content_type,
&finfo.last_modified, //content_type.buf, // content type
X_USER_AGENT) != 0 ) { RespInstr, //Range Info
"LAST-MODIFIED: ", &finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
@@ -1415,46 +1415,51 @@ process_request( IN http_message_t * req,
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT //Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked //Transfer-Encoding: chunked
// K means add chunky header ang G means range header. // K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RKTDstcSXcCc", HTTP_OK, // status code if (http_MakeMessage(
//RespInstr->ReadSendSize,// content length headers, resp_major, resp_minor,
finfo.content_type, "RKTDstcSXcCc",
// content_type.buf, // content type HTTP_OK, // status code
"LAST-MODIFIED: ", //RespInstr->ReadSendSize, // content length
&finfo.last_modified, finfo.content_type,
X_USER_AGENT) != 0 ) { // content_type.buf, // content type
"LAST-MODIFIED: ", &finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
} else { } else {
if( RespInstr->ReadSendSize >= 0 ) { if (RespInstr->ReadSendSize >= 0) {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT //Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked //Transfer-Encoding: chunked
// K means add chunky header ang G means range header. // K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RNTDstcSXcCc", HTTP_OK, // status code if (http_MakeMessage(
RespInstr->ReadSendSize, // content length headers, resp_major, resp_minor,
finfo.content_type, "RNTDstcSXcCc",
//content_type.buf, // content type HTTP_OK, // status code
"LAST-MODIFIED: ", (off_t)RespInstr->ReadSendSize, // content length
&finfo.last_modified, finfo.content_type,
X_USER_AGENT) != 0 ) { //content_type.buf, // content type
"LAST-MODIFIED: ", &finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
} else { } else {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT //Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked //Transfer-Encoding: chunked
// K means add chunky header ang G means range header. // K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RTDstcSXcCc", HTTP_OK, // status code if (http_MakeMessage(
//RespInstr->ReadSendSize,// content length headers, resp_major, resp_minor,
finfo.content_type, "RTDstcSXcCc",
//content_type.buf, // content type HTTP_OK, // status code
"LAST-MODIFIED: ", //RespInstr->ReadSendSize,// content length
&finfo.last_modified, finfo.content_type,
X_USER_AGENT) != 0 ) { //content_type.buf, // content type
"LAST-MODIFIED: ", &finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
} }
} }
/* -- PATCH END -- */
if( req->method == HTTPMETHOD_HEAD ) { if( req->method == HTTPMETHOD_HEAD ) {
*rtype = RESP_HEADERS; *rtype = RESP_HEADERS;
@@ -1738,12 +1743,12 @@ web_server_callback( IN http_parser_t * parser,
&RespInstr ); &RespInstr );
//Send response. //Send response.
/* - PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> http_MakeMessage(
* added X-User-Agent header &headers, 1, 1,
*/ "RTDSXcCc",
http_MakeMessage( &headers, 1, 1, "RTDSXcCc", ret, ret,
"text/html", X_USER_AGENT ); "text/html",
/* - PATCH END --- */ X_USER_AGENT );
http_SendMessage( info, &timeout, "b", headers.buf, http_SendMessage( info, &timeout, "b", headers.buf,
headers.length ); headers.length );

View File

@@ -601,9 +601,9 @@ SoapSendAction( IN char *action_url,
char *upnp_error_str; char *upnp_error_str;
xboolean got_response = FALSE; xboolean got_response = FALSE;
off_t content_length;
char *xml_start = char *xml_start =
// "<?xml version=\"1.0\"?>\n" required?? "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
"<s:Body>"; "<s:Body>";
char *xml_end = "</s:Body>\n" "</s:Envelope>\n"; char *xml_end = "</s:Body>\n" "</s:Envelope>\n";
@@ -644,19 +644,23 @@ SoapSendAction( IN char *action_url,
url.hostport.text.size, url.hostport.text.size,
url.hostport.text.buff ); ) url.hostport.text.buff ); )
xml_start_len = strlen( xml_start ); xml_start_len = strlen( xml_start );
xml_end_len = strlen( xml_end ); xml_end_len = strlen( xml_end );
action_str_len = strlen( action_str ); action_str_len = strlen( action_str );
// make request msg // make request msg
request.size_inc = 50; request.size_inc = 50;
if( http_MakeMessage( &request, 1, 1, "q" "N" "s" "sssbs" "U" "c" "bbb", SOAPMETHOD_POST, &url, content_length = xml_start_len + action_str_len + xml_end_len;
(off_t)xml_start_len + action_str_len + xml_end_len, // content-length if (http_MakeMessage(
ContentTypeHeader, &request, 1, 1,
"SOAPACTION: \"", service_type, "#", name.buf, "q" "N" "s" "sssbsc" "Uc" "b" "b" "b",
name.length, "\"\r\n", xml_start, xml_start_len, SOAPMETHOD_POST, &url,
action_str, action_str_len, xml_end, content_length,
xml_end_len ) != 0 ) { ContentTypeHeader,
"SOAPACTION: \"", service_type, "#", name.buf, name.length, "\"",
xml_start, xml_start_len,
action_str, action_str_len,
xml_end, xml_end_len ) != 0 ) {
goto error_handler; goto error_handler;
} }
@@ -737,7 +741,6 @@ SoapSendActionEx( IN char *action_url,
xboolean got_response = FALSE; xboolean got_response = FALSE;
char *xml_start = char *xml_start =
// "<?xml version=\"1.0\"?>\n" required??
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"; "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n";
char *xml_body_start = "<s:Body>"; char *xml_body_start = "<s:Body>";
@@ -751,6 +754,7 @@ SoapSendActionEx( IN char *action_url,
int xml_header_str_len; int xml_header_str_len;
int action_str_len; int action_str_len;
int xml_body_start_len; int xml_body_start_len;
off_t content_length;
*response_node = NULL; // init *response_node = NULL; // init
@@ -801,17 +805,24 @@ SoapSendActionEx( IN char *action_url,
// make request msg // make request msg
request.size_inc = 50; request.size_inc = 50;
if( http_MakeMessage( &request, 1, 1, "q" "N" "s" "sssbs" "U" "c" "bbbbbbb", SOAPMETHOD_POST, &url, xml_start_len + xml_header_start_len + xml_header_str_len + xml_header_end_len + xml_body_start_len + action_str_len + xml_end_len, // content-length content_length =
ContentTypeHeader, xml_start_len +
"SOAPACTION: \"", service_type, "#", name.buf, xml_header_start_len + xml_header_str_len + xml_header_end_len +
name.length, "\"\r\n", xml_body_start_len + action_str_len + xml_end_len;
xml_start, xml_start_len, if (http_MakeMessage(
xml_header_start, xml_header_start_len, &request, 1, 1,
xml_header_str, xml_header_str_len, "q" "N" "s" "sssbsc" "Uc" "bbbbbbb",
xml_header_end, xml_header_end_len, SOAPMETHOD_POST, &url,
xml_body_start, xml_body_start_len, content_length,
action_str, action_str_len, ContentTypeHeader,
xml_end, xml_end_len ) != 0 ) { "SOAPACTION: \"", service_type, "#", name.buf, name.length, "\"",
xml_start, xml_start_len,
xml_header_start, xml_header_start_len,
xml_header_str, xml_header_str_len,
xml_header_end, xml_header_end_len,
xml_body_start, xml_body_start_len,
action_str, action_str_len,
xml_end, xml_end_len ) != 0 ) {
goto error_handler; goto error_handler;
} }
@@ -882,6 +893,7 @@ SoapGetServiceVarStatus( IN char *action_url,
http_parser_t response; http_parser_t response;
int upnp_error_code; int upnp_error_code;
off_t content_length;
char *xml_start = char *xml_start =
// "<?xml version=\"1.0\"?>\n" required?? // "<?xml version=\"1.0\"?>\n" required??
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
@@ -903,11 +915,16 @@ SoapGetServiceVarStatus( IN char *action_url,
} }
// make headers // make headers
request.size_inc = 50; request.size_inc = 50;
if( http_MakeMessage( &request, 1, 1, "Q" "sbc" "N" "s" "s" "U" "c" "sss", SOAPMETHOD_POST, path.buf, path.length, "HOST: ", host.buf, host.length, strlen( xml_start ) + strlen( var_name ) + strlen( xml_end ), // content-length content_length = strlen( xml_start ) + strlen( var_name ) + strlen( xml_end );
ContentTypeHeader, if (http_MakeMessage(
"SOAPACTION: \"urn:schemas" &request, 1, 1,
"-upnp-org:control-1-0#QueryStateVariable\"\r\n", "Q" "sbc" "N" "s" "s" "Ucc" "sss",
xml_start, var_name, xml_end ) != 0 ) { SOAPMETHOD_POST, path.buf, path.length,
"HOST: ", host.buf, host.length,
content_length,
ContentTypeHeader,
"SOAPACTION: \"urn:schemas-upnp-org:control-1-0#QueryStateVariable\"",
xml_start, var_name, xml_end ) != 0 ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
// send msg and get reply // send msg and get reply

View File

@@ -228,20 +228,19 @@ send_error_response( IN SOCKINFO * info,
// make headers // make headers
membuffer_init( &headers ); membuffer_init( &headers );
/* -- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> */ if (http_MakeMessage(
if( http_MakeMessage( &headers, major, minor, &headers, major, minor,
"RNsDsSXcc" "sssss", "RNsDsSXcc" "sssss",
500, 500,
content_length, content_length,
ContentTypeHeader, ContentTypeHeader,
"EXT:\r\n", "EXT:\r\n",
X_USER_AGENT, X_USER_AGENT,
start_body, err_code_str, mid_body, err_msg, start_body, err_code_str, mid_body, err_msg,
end_body ) != 0 ) { end_body ) != 0 ) {
membuffer_destroy( &headers ); membuffer_destroy( &headers );
return; // out of mem return; // out of mem
} }
/*-- PATCH END - */
// send err msg // send err msg
http_SendMessage( info, &timeout_secs, "b", http_SendMessage( info, &timeout_secs, "b",
headers.buf, headers.length ); headers.buf, headers.length );
@@ -270,10 +269,9 @@ send_var_query_response( IN SOCKINFO * info,
{ {
off_t content_length; off_t content_length;
int timeout_secs = SOAP_TIMEOUT; int timeout_secs = SOAP_TIMEOUT;
int major, int major;
minor; int minor;
const char *start_body = const char *start_body =
// "<?xml version=\"1.0\"?>\n" required??
"<s:Envelope " "<s:Envelope "
"xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
@@ -297,19 +295,18 @@ send_var_query_response( IN SOCKINFO * info,
// make headers // make headers
membuffer_init( &response ); membuffer_init( &response );
/* -- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> */ if (http_MakeMessage(
if( http_MakeMessage( &response, major, minor, &response, major, minor,
"RNsDsSXcc" "sss", "RNsDsSXcc" "sss",
HTTP_OK, HTTP_OK,
content_length, content_length,
ContentTypeHeader, ContentTypeHeader,
"EXT:\r\n", "EXT:\r\n",
X_USER_AGENT, X_USER_AGENT,
start_body, var_value, end_body ) != 0 ) { start_body, var_value, end_body ) != 0 ) {
membuffer_destroy( &response ); membuffer_destroy( &response );
return; // out of mem return; // out of mem
} }
/* -- PATCH END - */
// send msg // send msg
http_SendMessage( info, &timeout_secs, "b", http_SendMessage( info, &timeout_secs, "b",
@@ -717,17 +714,22 @@ send_action_response( IN SOCKINFO * info,
goto error_handler; goto error_handler;
} }
content_length = strlen( start_body ) + strlen( xml_response ) + content_length =
strlen( start_body ) +
strlen( xml_response ) +
strlen( end_body ); strlen( end_body );
// make headers // make headers
/* -- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> */ if (http_MakeMessage(
if( http_MakeMessage( &headers, major, minor, "RNsDsSXcc", HTTP_OK, // status code &headers, major, minor,
content_length, ContentTypeHeader, "EXT:\r\n", X_USER_AGENT // EXT header "RNsDsSXcc",
) != 0 ) { HTTP_OK, // status code
content_length,
ContentTypeHeader,
"EXT:\r\n",
X_USER_AGENT) != 0 ) {
goto error_handler; goto error_handler;
} }
/* -- PATCH END - */
// send whole msg // send whole msg
ret_code = http_SendMessage( info, &timeout_secs, "bbbb", ret_code = http_SendMessage( info, &timeout_secs, "bbbb",

View File

@@ -295,16 +295,16 @@ CreateServicePacket( IN int msg_type,
*packet = NULL; *packet = NULL;
if( msg_type == MSGTYPE_REPLY ) { if( msg_type == MSGTYPE_REPLY ) {
/* -- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> */ ret_code = http_MakeMessage(
ret_code = http_MakeMessage( &buf, 1, 1, &buf, 1, 1,
"R" "sdc" "D" "s" "ssc" "S" "Xc" "ssc" "R" "sdc" "D" "sc" "ssc" "S" "Xc" "ssc" "sscc",
"ssc" "c", HTTP_OK, HTTP_OK,
"CACHE-CONTROL: max-age=", duration, "CACHE-CONTROL: max-age=", duration,
"EXT:\r\n", "LOCATION: ", location, "EXT:",
X_USER_AGENT, "LOCATION: ", location,
"ST: ", nt, "USN: ", usn ); X_USER_AGENT,
/* -- PATCH END - */ "ST: ", nt,
"USN: ", usn);
if( ret_code != 0 ) { if( ret_code != 0 ) {
return; return;
} }
@@ -320,15 +320,17 @@ CreateServicePacket( IN int msg_type,
// NOTE: The CACHE-CONTROL and LOCATION headers are not present in // NOTE: The CACHE-CONTROL and LOCATION headers are not present in
// a shutdown msg, but are present here for MS WinMe interop. // a shutdown msg, but are present here for MS WinMe interop.
/* -- PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net> */ ret_code = http_MakeMessage(
ret_code = http_MakeMessage( &buf, 1, 1, &buf, 1, 1,
"Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "Q" "sssdc" "sdc" "ssc" "ssc" "ssc" "S" "Xc" "sscc",
"S" "Xc" "ssc" "c", HTTPMETHOD_NOTIFY, "*", HTTPMETHOD_NOTIFY, "*",
1, "HOST: ", SSDP_IP, ":", SSDP_PORT, 1, "HOST: ", SSDP_IP, ":", SSDP_PORT,
"CACHE-CONTROL: max-age=", duration, "CACHE-CONTROL: max-age=", duration,
"LOCATION: ", location, "NT: ", nt, "LOCATION: ", location,
"NTS: ", nts, X_USER_AGENT, "USN: ", usn ); "NT: ", nt,
/* -- PATCH END - */ "NTS: ", nts,
X_USER_AGENT,
"USN: ", usn );
if( ret_code != 0 ) { if( ret_code != 0 ) {
return; return;
} }