Merge of trunk into branch-1.4.x.

git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.4.x@127 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2007-02-03 19:30:31 +00:00
parent 9e775e662e
commit 8cfa0e488c
29 changed files with 874 additions and 443 deletions

View File

@@ -306,8 +306,8 @@ http_SendMessage( IN SOCKINFO * info,
char *filename = NULL;
FILE *Fp;
int num_read,
num_written,
amount_to_be_read = 0;
num_written;
off_t amount_to_be_read = 0;
va_list argp;
char *file_buf = NULL,
*ChunkBuf = NULL;
@@ -367,7 +367,7 @@ http_SendMessage( IN SOCKINFO * info,
return UPNP_E_FILE_READ_ERROR;
}
} else if( Instr && Instr->IsRangeActive ) {
if( fseek( Fp, Instr->RangeOffset, SEEK_CUR ) != 0 ) {
if( fseeko( Fp, Instr->RangeOffset, SEEK_CUR ) != 0 ) {
free( ChunkBuf );
return UPNP_E_FILE_READ_ERROR;
}
@@ -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",
@@ -1757,28 +1769,30 @@ http_SendStatusResponse( IN SOCKINFO * info,
* specified in the input parameters.
*
* fmt types:
* 's': arg = const char* C_string
* 'B': arg = int status_code
* appends content-length, content-type and HTML body for given code
* 'b': arg1 = const char* buf; arg2 = size_t buf_length
* memory ptr
* 'c': (no args) appends CRLF "\r\n"
* 'd': arg = int number // appends decimal number
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
* 'D': (no args) appends HTTP DATE: header
* 'S': (no args) appends HTTP SERVER: header
* 'U': (no args) appends HTTP USER-AGENT: header
* 'C': (no args) appends a HTTP CONNECTION: close header
* depending on major,minor version
* 'c': (no args) appends CRLF "\r\n"
* 'D': (no args) appends HTTP DATE: header
* 'd': arg = int number // appends decimal number
* 'G': arg = range information // add range header
* 'h': arg = off_t number // appends off_t number
* 'K': (no args) // add chunky 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;
* arg3 = int url_length // start line of request
* 'R': arg = int status_code // adds a response start line
* 'B': arg = int status_code
* appends content-length, content-type and HTML body for given code
* 'S': (no args) appends HTTP SERVER: header
* 's': arg = const char* C_string
* '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 ---
* 't': arg = time_t * gmt_time // appends time in RFC 1123 fmt
* 'U': (no args) appends HTTP USER-AGENT: header
* 'X': arg = const char useragent; "redsonic" HTTP X-User-Agent: useragent
*
* Return : int;
* 0 - On Success
@@ -1797,6 +1811,7 @@ http_MakeMessage( INOUT membuffer * buf,
char c;
char *s = NULL;
int num;
off_t bignum;
size_t length;
time_t *loc_time;
time_t curr_time;
@@ -1884,6 +1899,16 @@ http_MakeMessage( INOUT membuffer * buf,
}
}
else if( c == 'h' ) // off_t
{
bignum = ( off_t )va_arg( argp, off_t );
sprintf( tempbuf, "%lld", bignum );
if( membuffer_append( buf, tempbuf, strlen( tempbuf ) ) != 0 ) {
goto error_handler;
}
}
else if( c == 't' || c == 'D' ) // date
{
if( c == 'D' ) {
@@ -1925,12 +1950,13 @@ http_MakeMessage( INOUT membuffer * buf,
else if( c == 'N' ) {
// content-length header
num = ( int )va_arg( argp, int );
bignum = ( off_t )va_arg( argp, off_t );
assert( num >= 0 );
if( http_MakeMessage
( buf, http_major_version, http_minor_version, "sdc",
"CONTENT-LENGTH: ", num ) != 0 ) {
assert( bignum >= 0 );
if (http_MakeMessage(
buf, http_major_version, http_minor_version,
"shc",
"CONTENT-LENGTH: ", bignum ) != 0 ) {
goto error_handler;
}
}
@@ -1940,14 +1966,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 * );
@@ -1962,9 +1988,6 @@ http_MakeMessage( INOUT membuffer * buf,
}
}
/* --- PATCH END --- */
else if( c == 'R' ) {
// response start line
// e.g.: 'HTTP/1.1 200 OK'
@@ -1979,9 +2002,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;
}
}
@@ -1996,11 +2021,14 @@ http_MakeMessage( INOUT membuffer * buf,
"<html><body><h1>",
status_code, http_get_code_text( status_code ),
"</h1></body></html>" );
num = strlen( tempbuf );
bignum = strlen( tempbuf );
if( http_MakeMessage( buf, http_major_version, http_minor_version, "NTcs", num, // 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;
}
@@ -2009,17 +2037,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;
}
}
@@ -2036,10 +2065,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;
}
}
@@ -2048,9 +2078,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;
}
}
@@ -2174,16 +2205,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__,

View File

@@ -632,7 +632,7 @@ get_file_info( IN const char *filename,
rc = get_content_type( filename, &info->content_type );
DBGONLY( UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"file info: %s, length: %d, last_mod=%s readable=%d\n",
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
filename, info->file_length,
asctime( gmtime( &info->last_modified ) ),
info->is_readable ); )
@@ -871,8 +871,8 @@ StrTok( char **Src,
************************************************************************/
int
GetNextRange( char **SrcRangeStr,
int *FirstByte,
int *LastByte )
off_t *FirstByte,
off_t *LastByte )
{
char *Ptr,
*Tok;
@@ -936,11 +936,11 @@ GetNextRange( char **SrcRangeStr,
************************************************************************/
int
CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
long FileLength,
off_t FileLength,
OUT struct SendInstruction *Instr )
{
int FirstByte,
off_t FirstByte,
LastByte;
char *RangeInput,
*Ptr;
@@ -984,26 +984,26 @@ CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
Instr->RangeOffset = FirstByte;
Instr->ReadSendSize = LastByte - FirstByte + 1;
sprintf( Instr->RangeHeader, "CONTENT-RANGE: bytes %d-%d/%ld\r\n", FirstByte, LastByte, FileLength ); //Data between two range.
sprintf( Instr->RangeHeader, "CONTENT-RANGE: bytes %lld-%lld/%lld\r\n", FirstByte, LastByte, FileLength ); //Data between two range.
} else if( FirstByte >= 0 && LastByte == -1
&& FirstByte < FileLength ) {
Instr->RangeOffset = FirstByte;
Instr->ReadSendSize = FileLength - FirstByte;
sprintf( Instr->RangeHeader,
"CONTENT-RANGE: bytes %d-%ld/%ld\r\n", FirstByte,
"CONTENT-RANGE: bytes %lld-%lld/%lld\r\n", FirstByte,
FileLength - 1, FileLength );
} else if( FirstByte == -1 && LastByte > 0 ) {
if( LastByte >= FileLength ) {
Instr->RangeOffset = 0;
Instr->ReadSendSize = FileLength;
sprintf( Instr->RangeHeader,
"CONTENT-RANGE: bytes 0-%ld/%ld\r\n",
"CONTENT-RANGE: bytes 0-%lld/%lld\r\n",
FileLength - 1, FileLength );
} else {
Instr->RangeOffset = FileLength - LastByte;
Instr->ReadSendSize = LastByte;
sprintf( Instr->RangeHeader,
"CONTENT-RANGE: bytes %ld-%ld/%ld\r\n",
"CONTENT-RANGE: bytes %lld-%lld/%lld\r\n",
FileLength - LastByte + 1, FileLength,
FileLength );
}
@@ -1042,7 +1042,7 @@ CreateHTTPRangeResponseHeader( char *ByteRangeSpecifier,
int
CheckOtherHTTPHeaders( IN http_message_t * Req,
OUT struct SendInstruction *RespInstr,
int FileSize )
off_t FileSize )
{
http_header_t *header;
ListNode *node;
@@ -1184,7 +1184,6 @@ process_request( IN http_message_t * req,
int code;
int err_code;
//membuffer content_type;
char *request_doc;
struct File_Info finfo;
xboolean using_alias;
@@ -1208,7 +1207,6 @@ process_request( IN http_message_t * req,
// init
request_doc = NULL;
finfo.content_type = NULL;
//membuffer_init( &content_type );
alias_grabbed = FALSE;
err_code = HTTP_INTERNAL_SERVER_ERROR; // default error
using_virtual_dir = FALSE;
@@ -1362,7 +1360,7 @@ process_request( IN http_message_t * req,
RespInstr->ReadSendSize = finfo.file_length;
//Check other header field.
// Check other header field.
if( ( err_code =
CheckOtherHTTPHeaders( req, RespInstr,
finfo.file_length ) ) != HTTP_OK ) {
@@ -1376,85 +1374,80 @@ process_request( IN http_message_t * req,
}
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
//Transfer-Encoding: chunked
// K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RTGKDstcSXcCc", HTTP_PARTIAL_CONTENT, // status code
// RespInstr->ReadSendSize,// content length
finfo.content_type,
// content_type.buf, // content type
RespInstr, // Range
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "T" "GKD" "s" "tcS" "XcCc",
HTTP_PARTIAL_CONTENT, // status code
finfo.content_type, // content type
RespInstr, // range info
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler;
}
} else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked
// K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RNTGDstcSXcCc", HTTP_PARTIAL_CONTENT, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type,
//content_type.buf, // content type
RespInstr, //Range Info
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "N" "T" "GD" "s" "tcS" "XcCc",
HTTP_PARTIAL_CONTENT, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type, // content type
RespInstr, // range info
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler;
}
} else if( !RespInstr->IsRangeActive && RespInstr->IsChunkActive ) {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked
// K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RKTDstcSXcCc", HTTP_OK, // status code
//RespInstr->ReadSendSize,// content length
finfo.content_type,
// content_type.buf, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"RK" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
finfo.content_type, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler;
}
} else {
if( RespInstr->ReadSendSize >= 0 ) {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked
// K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RNTDstcSXcCc", HTTP_OK, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type,
//content_type.buf, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
} else { // !RespInstr->IsRangeActive && !RespInstr->IsChunkActive
if (RespInstr->ReadSendSize >= 0) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "N" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler;
}
} else {
//Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
//Transfer-Encoding: chunked
// K means add chunky header ang G means range header.
if( http_MakeMessage( headers, resp_major, resp_minor, "RTDstcSXcCc", HTTP_OK, // status code
//RespInstr->ReadSendSize,// content length
finfo.content_type,
//content_type.buf, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
finfo.content_type, // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
goto error_handler;
}
}
}
/* -- PATCH END -- */
if( req->method == HTTPMETHOD_HEAD ) {
*rtype = RESP_HEADERS;
@@ -1468,8 +1461,8 @@ process_request( IN http_message_t * req,
*rtype = RESP_FILEDOC;
}
//simple get http 0.9 as specified in http 1.0
//don't send headers
// simple get http 0.9 as specified in http 1.0
// don't send headers
if( req->method == HTTPMETHOD_SIMPLEGET ) {
membuffer_destroy( headers );
}
@@ -1479,7 +1472,6 @@ process_request( IN http_message_t * req,
error_handler:
free( request_doc );
ixmlFreeDOMString( finfo.content_type );
// membuffer_destroy( &content_type );
if( err_code != UPNP_E_SUCCESS && alias_grabbed ) {
alias_release( alias );
}
@@ -1738,12 +1730,12 @@ web_server_callback( IN http_parser_t * parser,
&RespInstr );
//Send response.
/* - PATCH START - Sergey 'Jin' Bostandzhyan <jin_eld at users.sourceforge.net>
* added X-User-Agent header
*/
http_MakeMessage( &headers, 1, 1, "RTDSXcCc", ret,
"text/html", X_USER_AGENT );
/* - PATCH END --- */
http_MakeMessage(
&headers, 1, 1,
"RTDSXcCc",
ret,
"text/html",
X_USER_AGENT );
http_SendMessage( info, &timeout, "b", headers.buf,
headers.length );