Doxygen, reformating, compiler warnings.
This commit is contained in:
@@ -2522,7 +2522,7 @@ EXPORT_SPEC int UpnpWriteHttpPost(
|
|||||||
/*! [in] The buffer to be posted. */
|
/*! [in] The buffer to be posted. */
|
||||||
char *buf,
|
char *buf,
|
||||||
/*! [in] The size, in bytes of \b buf. */
|
/*! [in] The size, in bytes of \b buf. */
|
||||||
unsigned int *size,
|
size_t *size,
|
||||||
/*! [in] A timeout value sent with the request during which a response is
|
/*! [in] A timeout value sent with the request during which a response is
|
||||||
* expected from the server, failing which, an error is reported. */
|
* expected from the server, failing which, an error is reported. */
|
||||||
int timeout);
|
int timeout);
|
||||||
|
@@ -2801,7 +2801,7 @@ int UpnpOpenHttpPost(
|
|||||||
int UpnpWriteHttpPost(
|
int UpnpWriteHttpPost(
|
||||||
void *handle,
|
void *handle,
|
||||||
char *buf,
|
char *buf,
|
||||||
unsigned int *size,
|
size_t *size,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
return http_WriteHttpPost(handle, buf, size, timeout);
|
return http_WriteHttpPost(handle, buf, size, timeout);
|
||||||
@@ -2888,18 +2888,15 @@ int UpnpHttpGetProgress(void *Handle, size_t *length, size_t *total)
|
|||||||
int UpnpDownloadUrlItem(const char *url, char **outBuf, char *contentType)
|
int UpnpDownloadUrlItem(const char *url, char **outBuf, char *contentType)
|
||||||
{
|
{
|
||||||
int ret_code;
|
int ret_code;
|
||||||
int dummy;
|
size_t dummy;
|
||||||
|
|
||||||
if( url == NULL || outBuf == NULL || contentType == NULL ) {
|
if (url == NULL || outBuf == NULL || contentType == NULL)
|
||||||
return UPNP_E_INVALID_PARAM;
|
return UPNP_E_INVALID_PARAM;
|
||||||
}
|
ret_code = http_Download(url, HTTP_DEFAULT_TIMEOUT, outBuf, &dummy,
|
||||||
|
contentType);
|
||||||
ret_code = http_Download( url, HTTP_DEFAULT_TIMEOUT, outBuf, &dummy,
|
if (ret_code > 0)
|
||||||
contentType );
|
|
||||||
if( ret_code > 0 ) {
|
|
||||||
/* error reply was received */
|
/* error reply was received */
|
||||||
ret_code = UPNP_E_INVALID_URL;
|
ret_code = UPNP_E_INVALID_URL;
|
||||||
}
|
|
||||||
|
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
|
@@ -483,7 +483,7 @@ static int get_port(
|
|||||||
*port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port);
|
*port = ntohs(((struct sockaddr_in6*)&sockinfo)->sin6_port);
|
||||||
}
|
}
|
||||||
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
|
||||||
"sockfd = %d, .... port = %d\n", sockfd, port);
|
"sockfd = %d, .... port = %u\n", sockfd, *port);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -139,11 +139,8 @@ static UPNP_INLINE void scanner_init(OUT scanner_t *scanner, IN membuffer *bufpt
|
|||||||
*
|
*
|
||||||
* Description : Finds the separator character.
|
* Description : Finds the separator character.
|
||||||
*
|
*
|
||||||
* Return : xboolean ;
|
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE xboolean is_separator_char(IN char c)
|
static UPNP_INLINE int is_separator_char(IN char c)
|
||||||
{
|
{
|
||||||
return strchr(" \t()<>@,;:\\\"/[]?={}", c) != NULL;
|
return strchr(" \t()<>@,;:\\\"/[]?={}", c) != NULL;
|
||||||
}
|
}
|
||||||
@@ -156,11 +153,8 @@ static UPNP_INLINE xboolean is_separator_char(IN char c)
|
|||||||
*
|
*
|
||||||
* Description : Calls the function to indentify separator character
|
* Description : Calls the function to indentify separator character
|
||||||
*
|
*
|
||||||
* Return : xboolean ;
|
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE xboolean is_identifier_char(IN char c)
|
static UPNP_INLINE int is_identifier_char(IN char c)
|
||||||
{
|
{
|
||||||
return c >= 32 && c <= 126 && !is_separator_char(c);
|
return c >= 32 && c <= 126 && !is_separator_char(c);
|
||||||
}
|
}
|
||||||
@@ -173,11 +167,8 @@ static UPNP_INLINE xboolean is_identifier_char(IN char c)
|
|||||||
*
|
*
|
||||||
* Description : Determines if the passed value is a control character
|
* Description : Determines if the passed value is a control character
|
||||||
*
|
*
|
||||||
* Return : xboolean ;
|
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE xboolean is_control_char(IN char c)
|
static UPNP_INLINE int is_control_char(IN char c)
|
||||||
{
|
{
|
||||||
return (c >= 0 && c <= 31) || c == 127;
|
return (c >= 0 && c <= 31) || c == 127;
|
||||||
}
|
}
|
||||||
@@ -190,11 +181,8 @@ static UPNP_INLINE xboolean is_control_char(IN char c)
|
|||||||
*
|
*
|
||||||
* Description : Checks to see if the passed in value is CR/LF
|
* Description : Checks to see if the passed in value is CR/LF
|
||||||
*
|
*
|
||||||
* Return : xboolean ;
|
|
||||||
*
|
|
||||||
* Note :
|
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE xboolean is_qdtext_char(IN char cc)
|
static UPNP_INLINE int is_qdtext_char(IN char cc)
|
||||||
{
|
{
|
||||||
unsigned char c = ( unsigned char )cc;
|
unsigned char c = ( unsigned char )cc;
|
||||||
|
|
||||||
@@ -237,60 +225,46 @@ static parse_status_t scanner_get_token(
|
|||||||
char *null_terminator; /* point to null-terminator in buffer */
|
char *null_terminator; /* point to null-terminator in buffer */
|
||||||
char c;
|
char c;
|
||||||
token_type_t token_type;
|
token_type_t token_type;
|
||||||
xboolean got_end_quote;
|
int got_end_quote;
|
||||||
|
|
||||||
assert( scanner );
|
assert(scanner);
|
||||||
assert( token );
|
assert(token);
|
||||||
assert( tok_type );
|
assert(tok_type);
|
||||||
|
|
||||||
/* point to next char in buffer */
|
/* point to next char in buffer */
|
||||||
cursor = scanner->msg->buf + scanner->cursor;
|
cursor = scanner->msg->buf + scanner->cursor;
|
||||||
null_terminator = scanner->msg->buf + scanner->msg->length;
|
null_terminator = scanner->msg->buf + scanner->msg->length;
|
||||||
|
|
||||||
/* not enough chars in input to parse */
|
/* not enough chars in input to parse */
|
||||||
if( cursor == null_terminator ) {
|
if (cursor == null_terminator)
|
||||||
return PARSE_INCOMPLETE;
|
return PARSE_INCOMPLETE;
|
||||||
}
|
|
||||||
|
|
||||||
c = *cursor;
|
c = *cursor;
|
||||||
if( is_identifier_char( c ) ) {
|
if (is_identifier_char(c)) {
|
||||||
/* scan identifier */
|
/* scan identifier */
|
||||||
|
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token_type = TT_IDENTIFIER;
|
token_type = TT_IDENTIFIER;
|
||||||
|
while (is_identifier_char(*cursor))
|
||||||
while( is_identifier_char( *cursor ) ) {
|
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
if (!scanner->entire_msg_loaded && cursor == null_terminator)
|
||||||
|
|
||||||
if( !scanner->entire_msg_loaded && cursor == null_terminator ) {
|
|
||||||
/* possibly more valid chars */
|
/* possibly more valid chars */
|
||||||
return PARSE_INCOMPLETE;
|
return PARSE_INCOMPLETE;
|
||||||
}
|
|
||||||
/* calc token length */
|
/* calc token length */
|
||||||
token->length = cursor - token->buf;
|
token->length = (size_t)(cursor - token->buf);
|
||||||
} else if( c == ' ' || c == '\t' ) {
|
} else if (c == ' ' || c == '\t') {
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token_type = TT_WHITESPACE;
|
token_type = TT_WHITESPACE;
|
||||||
|
while (*cursor == ' ' || *cursor == '\t')
|
||||||
while( *cursor == ' ' || *cursor == '\t' ) {
|
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
if (!scanner->entire_msg_loaded && cursor == null_terminator)
|
||||||
|
|
||||||
if( !scanner->entire_msg_loaded && cursor == null_terminator ) {
|
|
||||||
/* possibly more chars */
|
/* possibly more chars */
|
||||||
return PARSE_INCOMPLETE;
|
return PARSE_INCOMPLETE;
|
||||||
}
|
token->length = (size_t)(cursor - token->buf);
|
||||||
token->length = cursor - token->buf;
|
} else if (c == TOKCHAR_CR) {
|
||||||
} else if( c == TOKCHAR_CR ) {
|
|
||||||
/* scan CRLF */
|
/* scan CRLF */
|
||||||
|
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
if( cursor == null_terminator ) {
|
if (cursor == null_terminator)
|
||||||
/* not enuf info to determine CRLF */
|
/* not enuf info to determine CRLF */
|
||||||
return PARSE_INCOMPLETE;
|
return PARSE_INCOMPLETE;
|
||||||
}
|
if (*cursor != TOKCHAR_LF) {
|
||||||
if( *cursor != TOKCHAR_LF ) {
|
|
||||||
/* couldn't match CRLF; match as CR */
|
/* couldn't match CRLF; match as CR */
|
||||||
token_type = TT_CTRL; /* ctrl char */
|
token_type = TT_CTRL; /* ctrl char */
|
||||||
token->length = 1;
|
token->length = 1;
|
||||||
@@ -300,60 +274,53 @@ static parse_status_t scanner_get_token(
|
|||||||
token_type = TT_CRLF;
|
token_type = TT_CRLF;
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
} else if( c == TOKCHAR_LF ) /* accept \n as CRLF */
|
} else if (c == TOKCHAR_LF) { /* accept \n as CRLF */
|
||||||
{
|
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token->length = 1;
|
token->length = 1;
|
||||||
token_type = TT_CRLF;
|
token_type = TT_CRLF;
|
||||||
} else if( c == '"' ) {
|
} else if (c == '"') {
|
||||||
/* quoted text */
|
/* quoted text */
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token_type = TT_QUOTEDSTRING;
|
token_type = TT_QUOTEDSTRING;
|
||||||
got_end_quote = FALSE;
|
got_end_quote = FALSE;
|
||||||
|
while (cursor < null_terminator) {
|
||||||
while( cursor < null_terminator ) {
|
|
||||||
c = *cursor++;
|
c = *cursor++;
|
||||||
if( c == '"' ) {
|
if (c == '"') {
|
||||||
got_end_quote = TRUE;
|
got_end_quote = TRUE;
|
||||||
break;
|
break;
|
||||||
} else if( c == '\\' ) {
|
} else if (c == '\\') {
|
||||||
if( cursor < null_terminator ) {
|
if (cursor < null_terminator) {
|
||||||
c = *cursor++;
|
c = *cursor++;
|
||||||
/*if ( !(c > 0 && c <= 127) ) */
|
/*if ( !(c > 0 && c <= 127) ) */
|
||||||
if( c == 0 ) {
|
if (c == 0)
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* else, while loop handles incomplete buf */
|
/* else, while loop handles incomplete buf */
|
||||||
} else if( is_qdtext_char( c ) ) {
|
} else if (is_qdtext_char(c)) {
|
||||||
/* just accept char */
|
/* just accept char */
|
||||||
} else {
|
} else
|
||||||
/* bad quoted text */
|
/* bad quoted text */
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
if (got_end_quote)
|
||||||
if( got_end_quote ) {
|
token->length = (size_t)(cursor - token->buf);
|
||||||
token->length = cursor - token->buf;
|
else { /* incomplete */
|
||||||
} else /* incomplete */
|
|
||||||
{
|
assert(cursor == null_terminator);
|
||||||
assert( cursor == null_terminator );
|
|
||||||
return PARSE_INCOMPLETE;
|
return PARSE_INCOMPLETE;
|
||||||
}
|
}
|
||||||
} else if( is_separator_char( c ) ) {
|
} else if (is_separator_char(c)) {
|
||||||
/* scan separator */
|
/* scan separator */
|
||||||
|
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token_type = TT_SEPARATOR;
|
token_type = TT_SEPARATOR;
|
||||||
token->length = 1;
|
token->length = 1;
|
||||||
} else if( is_control_char( c ) ) {
|
} else if (is_control_char(c)) {
|
||||||
/* scan ctrl char */
|
/* scan ctrl char */
|
||||||
|
|
||||||
token->buf = cursor++;
|
token->buf = cursor++;
|
||||||
token_type = TT_CTRL;
|
token_type = TT_CTRL;
|
||||||
token->length = 1;
|
token->length = 1;
|
||||||
} else {
|
} else
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
|
||||||
|
|
||||||
scanner->cursor += token->length; /* move to next token */
|
scanner->cursor += token->length; /* move to next token */
|
||||||
*tok_type = token_type;
|
*tok_type = token_type;
|
||||||
@@ -596,7 +563,7 @@ static UPNP_INLINE int skip_lws(INOUT scanner_t *scanner)
|
|||||||
token_type_t tok_type;
|
token_type_t tok_type;
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
size_t save_pos;
|
size_t save_pos;
|
||||||
xboolean matched;
|
int matched;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
save_pos = scanner->cursor;
|
save_pos = scanner->cursor;
|
||||||
@@ -651,7 +618,7 @@ static UPNP_INLINE parse_status_t match_non_ws_string(
|
|||||||
memptr token;
|
memptr token;
|
||||||
token_type_t tok_type;
|
token_type_t tok_type;
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
xboolean done = FALSE;
|
int done = FALSE;
|
||||||
size_t save_cursor;
|
size_t save_cursor;
|
||||||
|
|
||||||
save_cursor = scanner->cursor;
|
save_cursor = scanner->cursor;
|
||||||
@@ -717,8 +684,8 @@ static UPNP_INLINE parse_status_t match_raw_value(
|
|||||||
memptr token;
|
memptr token;
|
||||||
token_type_t tok_type;
|
token_type_t tok_type;
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
xboolean done = FALSE;
|
int done = FALSE;
|
||||||
xboolean saw_crlf = FALSE;
|
int saw_crlf = FALSE;
|
||||||
size_t pos_at_crlf = 0;
|
size_t pos_at_crlf = 0;
|
||||||
size_t save_pos;
|
size_t save_pos;
|
||||||
char c;
|
char c;
|
||||||
@@ -814,29 +781,24 @@ static UPNP_INLINE int match_int(
|
|||||||
size_t save_pos;
|
size_t save_pos;
|
||||||
|
|
||||||
save_pos = scanner->cursor;
|
save_pos = scanner->cursor;
|
||||||
|
status = scanner_get_token(scanner, &token, &tok_type);
|
||||||
status = scanner_get_token( scanner, &token, &tok_type );
|
if (status == PARSE_OK) {
|
||||||
if( status == PARSE_OK ) {
|
if (tok_type == TT_IDENTIFIER) {
|
||||||
if( tok_type == TT_IDENTIFIER ) {
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
num = strtol(token.buf, &end_ptr, base);
|
||||||
num = strtol( token.buf, &end_ptr, base );
|
|
||||||
if( ( num < 0 )
|
|
||||||
/* all and only those chars in token should be used for num */
|
/* all and only those chars in token should be used for num */
|
||||||
|| ( end_ptr != token.buf + token.length )
|
if (num < 0 || end_ptr != token.buf + token.length ||
|
||||||
|| ( ( num == LONG_MIN || num == LONG_MAX )
|
((num == LONG_MIN || num == LONG_MAX) && (errno == ERANGE))) {
|
||||||
&& ( errno == ERANGE ) )
|
|
||||||
) {
|
|
||||||
status = PARSE_NO_MATCH;
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
|
/* save result */
|
||||||
*value = num; /* save result */
|
*value = (int)num;
|
||||||
} else {
|
} else {
|
||||||
status = PARSE_NO_MATCH; /* token must be an identifier */
|
/* token must be an identifier */
|
||||||
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (status != PARSE_OK) {
|
||||||
if( status != PARSE_OK ) {
|
|
||||||
/* restore scanner position for bad values */
|
/* restore scanner position for bad values */
|
||||||
scanner->cursor = save_pos;
|
scanner->cursor = save_pos;
|
||||||
}
|
}
|
||||||
@@ -894,7 +856,7 @@ read_until_crlf( INOUT scanner_t * scanner,
|
|||||||
* Parameters:
|
* Parameters:
|
||||||
* INOUT scanner_t* scanner ; Scanner Object
|
* INOUT scanner_t* scanner ; Scanner Object
|
||||||
* IN char c ; Character to be compared with
|
* IN char c ; Character to be compared with
|
||||||
* IN xboolean case_sensitive; Flag indicating whether
|
* IN int case_sensitive; Flag indicating whether
|
||||||
* comparison should be case sensitive
|
* comparison should be case sensitive
|
||||||
*
|
*
|
||||||
* Description: Compares a character to the next char in the scanner;
|
* Description: Compares a character to the next char in the scanner;
|
||||||
@@ -908,7 +870,7 @@ read_until_crlf( INOUT scanner_t * scanner,
|
|||||||
static UPNP_INLINE parse_status_t
|
static UPNP_INLINE parse_status_t
|
||||||
match_char( INOUT scanner_t * scanner,
|
match_char( INOUT scanner_t * scanner,
|
||||||
IN char c,
|
IN char c,
|
||||||
IN xboolean case_sensitive )
|
IN int case_sensitive )
|
||||||
{
|
{
|
||||||
char scan_char;
|
char scan_char;
|
||||||
|
|
||||||
@@ -982,10 +944,10 @@ match_char( INOUT scanner_t * scanner,
|
|||||||
*
|
*
|
||||||
* Note :
|
* Note :
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int
|
static int vfmatch(
|
||||||
vfmatch( INOUT scanner_t * scanner,
|
INOUT scanner_t *scanner,
|
||||||
IN const char *fmt,
|
IN const char *fmt,
|
||||||
va_list argp )
|
va_list argp)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
const char *fmt_ptr = fmt;
|
const char *fmt_ptr = fmt;
|
||||||
@@ -996,7 +958,7 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
uri_type *uri_ptr;
|
uri_type *uri_ptr;
|
||||||
size_t save_pos;
|
size_t save_pos;
|
||||||
int stat;
|
int stat;
|
||||||
xboolean case_sensitive = TRUE;
|
int case_sensitive = TRUE;
|
||||||
memptr token;
|
memptr token;
|
||||||
token_type_t tok_type;
|
token_type_t tok_type;
|
||||||
int base;
|
int base;
|
||||||
@@ -1012,15 +974,12 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
) {
|
) {
|
||||||
if( c == '%' ) {
|
if( c == '%' ) {
|
||||||
c = *fmt_ptr++;
|
c = *fmt_ptr++;
|
||||||
|
|
||||||
switch ( c ) {
|
switch ( c ) {
|
||||||
|
|
||||||
case 'R': /* raw value */
|
case 'R': /* raw value */
|
||||||
str_ptr = va_arg( argp, memptr * );
|
str_ptr = va_arg( argp, memptr * );
|
||||||
assert( str_ptr != NULL );
|
assert( str_ptr != NULL );
|
||||||
status = match_raw_value( scanner, str_ptr );
|
status = match_raw_value( scanner, str_ptr );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': /* simple identifier */
|
case 's': /* simple identifier */
|
||||||
str_ptr = va_arg( argp, memptr * );
|
str_ptr = va_arg( argp, memptr * );
|
||||||
assert( str_ptr != NULL );
|
assert( str_ptr != NULL );
|
||||||
@@ -1031,7 +990,6 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
status = PARSE_NO_MATCH;
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* crlf */
|
case 'c': /* crlf */
|
||||||
status = scanner_get_token( scanner,
|
status = scanner_get_token( scanner,
|
||||||
&token, &tok_type );
|
&token, &tok_type );
|
||||||
@@ -1040,16 +998,13 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
status = PARSE_NO_MATCH;
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd': /* integer */
|
case 'd': /* integer */
|
||||||
case 'x': /* hex number */
|
case 'x': /* hex number */
|
||||||
int_ptr = va_arg( argp, int * );
|
int_ptr = va_arg(argp, int *);
|
||||||
|
assert(int_ptr != NULL);
|
||||||
assert( int_ptr != NULL );
|
base = c == 'd' ? 10 : 16;
|
||||||
base = ( c == 'd' ? 10 : 16 );
|
status = match_int(scanner, base, int_ptr);
|
||||||
status = match_int( scanner, base, int_ptr );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S': /* non-whitespace string */
|
case 'S': /* non-whitespace string */
|
||||||
case 'U': /* uri */
|
case 'U': /* uri */
|
||||||
if( c == 'S' ) {
|
if( c == 'S' ) {
|
||||||
@@ -1069,26 +1024,21 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L': /* string till eol */
|
case 'L': /* string till eol */
|
||||||
str_ptr = va_arg( argp, memptr * );
|
str_ptr = va_arg( argp, memptr * );
|
||||||
assert( str_ptr != NULL );
|
assert( str_ptr != NULL );
|
||||||
status = read_until_crlf( scanner, str_ptr );
|
status = read_until_crlf( scanner, str_ptr );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ' ': /* match space */
|
case ' ': /* match space */
|
||||||
case '%': /* match percentage symbol */
|
case '%': /* match percentage symbol */
|
||||||
status = match_char( scanner, c, case_sensitive );
|
status = match_char( scanner, c, case_sensitive );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n': /* case-sensitive match */
|
case 'n': /* case-sensitive match */
|
||||||
case_sensitive = TRUE;
|
case_sensitive = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i': /* ignore case */
|
case 'i': /* ignore case */
|
||||||
case_sensitive = FALSE;
|
case_sensitive = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q': /* quoted string */
|
case 'q': /* quoted string */
|
||||||
str_ptr = ( memptr * ) va_arg( argp, memptr * );
|
str_ptr = ( memptr * ) va_arg( argp, memptr * );
|
||||||
status =
|
status =
|
||||||
@@ -1097,8 +1047,8 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
status = PARSE_NO_MATCH; /* not a quoted string */
|
status = PARSE_NO_MATCH; /* not a quoted string */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
case 'w': /* optional whitespace */
|
/* optional whitespace */
|
||||||
status = scanner_get_token( scanner,
|
status = scanner_get_token( scanner,
|
||||||
&token, &tok_type );
|
&token, &tok_type );
|
||||||
if( status == PARSE_OK && tok_type != TT_WHITESPACE ) {
|
if( status == PARSE_OK && tok_type != TT_WHITESPACE ) {
|
||||||
@@ -1106,16 +1056,15 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
scanner->cursor -= token.length;
|
scanner->cursor -= token.length;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
case 'P': /* current pos of scanner */
|
/* current pos of scanner */
|
||||||
int_ptr = va_arg( argp, int * );
|
int_ptr = va_arg( argp, int * );
|
||||||
|
|
||||||
assert( int_ptr != NULL );
|
assert( int_ptr != NULL );
|
||||||
*int_ptr = scanner->cursor;
|
*int_ptr = (int)scanner->cursor;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* valid only in matchstr() */
|
/* valid only in matchstr() */
|
||||||
case '0': /* end of msg? */
|
case '0':
|
||||||
|
/* end of msg? */
|
||||||
/* check that we are 1 beyond last char */
|
/* check that we are 1 beyond last char */
|
||||||
if( scanner->cursor == scanner->msg->length &&
|
if( scanner->cursor == scanner->msg->length &&
|
||||||
scanner->msg->buf[scanner->cursor] == '\0' ) {
|
scanner->msg->buf[scanner->cursor] == '\0' ) {
|
||||||
@@ -1124,16 +1073,15 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
status = PARSE_NO_MATCH;
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert( 0 ); /* unknown option */
|
/* unknown option */
|
||||||
|
assert( 0 );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch ( c ) {
|
switch ( c ) {
|
||||||
case ' ': /* LWS* */
|
case ' ': /* LWS* */
|
||||||
status = skip_lws( scanner );
|
status = skip_lws( scanner );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\t': /* Whitespace */
|
case '\t': /* Whitespace */
|
||||||
status = scanner_get_token( scanner,
|
status = scanner_get_token( scanner,
|
||||||
&token, &tok_type );
|
&token, &tok_type );
|
||||||
@@ -1142,7 +1090,6 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
status = PARSE_NO_MATCH;
|
status = PARSE_NO_MATCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* match characters */
|
default: /* match characters */
|
||||||
{
|
{
|
||||||
status = match_char( scanner, c, case_sensitive );
|
status = match_char( scanner, c, case_sensitive );
|
||||||
@@ -1150,7 +1097,6 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( status != PARSE_OK ) {
|
if( status != PARSE_OK ) {
|
||||||
/* on error, restore original scanner pos */
|
/* on error, restore original scanner pos */
|
||||||
scanner->cursor = save_pos;
|
scanner->cursor = save_pos;
|
||||||
@@ -1175,17 +1121,17 @@ vfmatch( INOUT scanner_t * scanner,
|
|||||||
* PARSE_NO_MATCH
|
* PARSE_NO_MATCH
|
||||||
* PARSE_INCOMPLETE
|
* PARSE_INCOMPLETE
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int
|
static int match(
|
||||||
match( INOUT scanner_t * scanner,
|
INOUT scanner_t *scanner,
|
||||||
IN const char *fmt,
|
IN const char *fmt,
|
||||||
... )
|
...)
|
||||||
{
|
{
|
||||||
int ret_code;
|
int ret_code;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start( args, fmt );
|
va_start(args, fmt);
|
||||||
ret_code = vfmatch( scanner, fmt, args );
|
ret_code = vfmatch(scanner, fmt, args);
|
||||||
va_end( args );
|
va_end(args);
|
||||||
|
|
||||||
return ret_code;
|
return ret_code;
|
||||||
}
|
}
|
||||||
@@ -1397,8 +1343,7 @@ parser_parse_requestline( INOUT http_parser_t * parser )
|
|||||||
* PARSE_SUCCESS
|
* PARSE_SUCCESS
|
||||||
* PARSE_FAILURE
|
* PARSE_FAILURE
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
parse_status_t
|
parse_status_t parser_parse_responseline(INOUT http_parser_t *parser)
|
||||||
parser_parse_responseline( INOUT http_parser_t * parser )
|
|
||||||
{
|
{
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
http_message_t *hmsg = &parser->msg;
|
http_message_t *hmsg = &parser->msg;
|
||||||
@@ -1406,78 +1351,58 @@ parser_parse_responseline( INOUT http_parser_t * parser )
|
|||||||
char save_char;
|
char save_char;
|
||||||
int num_scanned;
|
int num_scanned;
|
||||||
int i;
|
int i;
|
||||||
|
size_t n;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
assert( parser->position == POS_RESPONSE_LINE );
|
assert(parser->position == POS_RESPONSE_LINE);
|
||||||
|
|
||||||
status = skip_blank_lines( &parser->scanner );
|
status = skip_blank_lines(&parser->scanner);
|
||||||
if( status != PARSE_OK ) {
|
if (status != PARSE_OK)
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
/* response line */
|
/* response line */
|
||||||
/*status = match( &parser->scanner, "%ihttp%w/%w%d\t.\t%d\t%d\t%L%c", */
|
/*status = match( &parser->scanner, "%ihttp%w/%w%d\t.\t%d\t%d\t%L%c", */
|
||||||
/* &hmsg->major_version, &hmsg->minor_version, */
|
/* &hmsg->major_version, &hmsg->minor_version, */
|
||||||
/* &hmsg->status_code, &hmsg->status_msg ); */
|
/* &hmsg->status_code, &hmsg->status_msg ); */
|
||||||
|
status = match(&parser->scanner, "%ihttp%w/%w%L%c", &line);
|
||||||
status = match( &parser->scanner, "%ihttp%w/%w%L%c", &line );
|
if (status != PARSE_OK)
|
||||||
if( status != PARSE_OK ) {
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
save_char = line.buf[line.length];
|
save_char = line.buf[line.length];
|
||||||
line.buf[line.length] = '\0'; /* null-terminate */
|
line.buf[line.length] = '\0'; /* null-terminate */
|
||||||
|
|
||||||
/* scan http version and ret code */
|
/* scan http version and ret code */
|
||||||
num_scanned = sscanf( line.buf, "%d . %d %d",
|
num_scanned = sscanf(line.buf, "%d . %d %d",
|
||||||
&hmsg->major_version, &hmsg->minor_version,
|
&hmsg->major_version, &hmsg->minor_version,
|
||||||
&hmsg->status_code );
|
&hmsg->status_code);
|
||||||
|
|
||||||
line.buf[line.length] = save_char; /* restore */
|
line.buf[line.length] = save_char; /* restore */
|
||||||
|
if (num_scanned != 3 || hmsg->major_version < 0 ||
|
||||||
if( num_scanned != 3 ||
|
|
||||||
hmsg->major_version < 0 ||
|
|
||||||
/* HTTP version equals to 1.0 should fail as required by the
|
/* HTTP version equals to 1.0 should fail as required by the
|
||||||
* UPnP certification tool */
|
* UPnP certification tool */
|
||||||
hmsg->minor_version < 1 || hmsg->status_code < 0 ) {
|
hmsg->minor_version < 1 || hmsg->status_code < 0)
|
||||||
/* bad response line */
|
/* bad response line */
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
|
||||||
/* */
|
|
||||||
/* point to status msg */
|
/* point to status msg */
|
||||||
/* */
|
|
||||||
|
|
||||||
p = line.buf;
|
p = line.buf;
|
||||||
|
|
||||||
/* skip 3 ints */
|
/* skip 3 ints */
|
||||||
for( i = 0; i < 3; i++ ) {
|
for (i = 0; i < 3; i++) {
|
||||||
/* go to start of num */
|
/* go to start of num */
|
||||||
while( !isdigit( *p ) ) {
|
while (!isdigit(*p))
|
||||||
p++;
|
p++;
|
||||||
}
|
|
||||||
|
|
||||||
/* skip int */
|
/* skip int */
|
||||||
while( isdigit( *p ) ) {
|
while (isdigit(*p))
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* whitespace must exist after status code */
|
/* whitespace must exist after status code */
|
||||||
if( *p != ' ' && *p != '\t' ) {
|
if (*p != ' ' && *p != '\t')
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
|
||||||
/* skip whitespace */
|
/* skip whitespace */
|
||||||
while( *p == ' ' || *p == '\t' ) {
|
while (*p == ' ' || *p == '\t')
|
||||||
p++;
|
p++;
|
||||||
}
|
|
||||||
|
|
||||||
/* now, p is at start of status msg */
|
/* now, p is at start of status msg */
|
||||||
if( membuffer_assign( &hmsg->status_msg, p,
|
n = line.length - (size_t)(p - line.buf);
|
||||||
line.length - ( p - line.buf ) ) != 0 ) {
|
if (membuffer_assign(&hmsg->status_msg, p, n) != 0) {
|
||||||
/* out of mem */
|
/* out of mem */
|
||||||
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->position = POS_HEADERS; /* move to headers */
|
parser->position = POS_HEADERS; /* move to headers */
|
||||||
|
|
||||||
return PARSE_OK;
|
return PARSE_OK;
|
||||||
@@ -1496,8 +1421,7 @@ parser_parse_responseline( INOUT http_parser_t * parser )
|
|||||||
* PARSE_SUCCESS
|
* PARSE_SUCCESS
|
||||||
* PARSE_FAILURE
|
* PARSE_FAILURE
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
parse_status_t
|
parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
|
||||||
parser_parse_headers( INOUT http_parser_t * parser )
|
|
||||||
{
|
{
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
memptr token;
|
memptr token;
|
||||||
@@ -1513,131 +1437,108 @@ parser_parse_headers( INOUT http_parser_t * parser )
|
|||||||
char save_char;
|
char save_char;
|
||||||
int ret2;
|
int ret2;
|
||||||
|
|
||||||
assert( parser->position == POS_HEADERS ||
|
assert(parser->position == POS_HEADERS ||
|
||||||
parser->ent_position == ENTREAD_CHUNKY_HEADERS );
|
parser->ent_position == ENTREAD_CHUNKY_HEADERS);
|
||||||
|
|
||||||
while( TRUE ) {
|
while (TRUE) {
|
||||||
save_pos = scanner->cursor;
|
save_pos = scanner->cursor;
|
||||||
|
|
||||||
/* */
|
|
||||||
/* check end of headers */
|
/* check end of headers */
|
||||||
/* */
|
status = scanner_get_token(scanner, &token, &tok_type);
|
||||||
status = scanner_get_token( scanner, &token, &tok_type );
|
if (status != PARSE_OK) {
|
||||||
if( status != PARSE_OK ) {
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
if (tok_type == TT_CRLF) {
|
||||||
if( tok_type == TT_CRLF ) {
|
|
||||||
|
|
||||||
/* end of headers */
|
/* end of headers */
|
||||||
if( ( parser->msg.is_request )
|
if ((parser->msg.is_request)
|
||||||
&& ( parser->msg.method == HTTPMETHOD_POST ) ) {
|
&& (parser->msg.method == HTTPMETHOD_POST)) {
|
||||||
parser->position = POS_COMPLETE; /*post entity parsing */
|
parser->position = POS_COMPLETE; /*post entity parsing */
|
||||||
/*is handled separately */
|
/*is handled separately */
|
||||||
return PARSE_SUCCESS;
|
return PARSE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->position = POS_ENTITY; /* read entity next */
|
parser->position = POS_ENTITY; /* read entity next */
|
||||||
return PARSE_OK;
|
return PARSE_OK;
|
||||||
}
|
}
|
||||||
/* */
|
|
||||||
/* not end; read header */
|
/* not end; read header */
|
||||||
/* */
|
if (tok_type != TT_IDENTIFIER) {
|
||||||
if( tok_type != TT_IDENTIFIER ) {
|
|
||||||
return PARSE_FAILURE; /* didn't see header name */
|
return PARSE_FAILURE; /* didn't see header name */
|
||||||
}
|
}
|
||||||
|
status = match(scanner, " : %R%c", &hdr_value);
|
||||||
status = match( scanner, " : %R%c", &hdr_value );
|
if (status != PARSE_OK) {
|
||||||
if( status != PARSE_OK ) {
|
|
||||||
/* pushback tokens; useful only on INCOMPLETE error */
|
/* pushback tokens; useful only on INCOMPLETE error */
|
||||||
scanner->cursor = save_pos;
|
scanner->cursor = save_pos;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
/* */
|
|
||||||
/* add header */
|
/* add header */
|
||||||
/* */
|
|
||||||
|
|
||||||
/* find header */
|
/* find header */
|
||||||
index = map_str_to_int( token.buf, token.length, Http_Header_Names,
|
index =
|
||||||
NUM_HTTP_HEADER_NAMES, FALSE );
|
map_str_to_int(token.buf, token.length, Http_Header_Names,
|
||||||
if( index != -1 ) {
|
NUM_HTTP_HEADER_NAMES, FALSE);
|
||||||
|
if (index != -1) {
|
||||||
/*Check if it is a soap header */
|
/*Check if it is a soap header */
|
||||||
if( Http_Header_Names[index].id == HDR_SOAPACTION ) {
|
if (Http_Header_Names[index].id == HDR_SOAPACTION) {
|
||||||
parser->msg.method = SOAPMETHOD_POST;
|
parser->msg.method = SOAPMETHOD_POST;
|
||||||
}
|
}
|
||||||
|
|
||||||
header_id = Http_Header_Names[index].id;
|
header_id = Http_Header_Names[index].id;
|
||||||
orig_header =
|
orig_header =
|
||||||
httpmsg_find_hdr( &parser->msg, header_id, NULL );
|
httpmsg_find_hdr(&parser->msg, header_id, NULL);
|
||||||
} else {
|
} else {
|
||||||
header_id = HDR_UNKNOWN;
|
header_id = HDR_UNKNOWN;
|
||||||
|
|
||||||
save_char = token.buf[token.length];
|
save_char = token.buf[token.length];
|
||||||
token.buf[token.length] = '\0';
|
token.buf[token.length] = '\0';
|
||||||
|
orig_header =
|
||||||
orig_header = httpmsg_find_hdr_str( &parser->msg, token.buf );
|
httpmsg_find_hdr_str(&parser->msg, token.buf);
|
||||||
|
|
||||||
token.buf[token.length] = save_char; /* restore */
|
token.buf[token.length] = save_char; /* restore */
|
||||||
}
|
}
|
||||||
|
if (orig_header == NULL) {
|
||||||
if( orig_header == NULL ) {
|
|
||||||
/* */
|
|
||||||
/* add new header */
|
/* add new header */
|
||||||
/* */
|
header =
|
||||||
|
(http_header_t *) malloc(sizeof(http_header_t));
|
||||||
header = ( http_header_t * ) malloc( sizeof( http_header_t ) );
|
if (header == NULL) {
|
||||||
if( header == NULL ) {
|
parser->http_error_code =
|
||||||
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
HTTP_INTERNAL_SERVER_ERROR;
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
membuffer_init( &header->name_buf );
|
membuffer_init(&header->name_buf);
|
||||||
membuffer_init( &header->value );
|
membuffer_init(&header->value);
|
||||||
|
|
||||||
/* value can be 0 length */
|
/* value can be 0 length */
|
||||||
if( hdr_value.length == 0 ) {
|
if (hdr_value.length == 0) {
|
||||||
|
/* FIXME: Is this a bug? buf is not const. */
|
||||||
hdr_value.buf = "\0";
|
hdr_value.buf = "\0";
|
||||||
hdr_value.length = 1;
|
hdr_value.length = 1;
|
||||||
}
|
}
|
||||||
/* save in header in buffers */
|
/* save in header in buffers */
|
||||||
if( membuffer_assign
|
if (membuffer_assign(&header->name_buf, token.buf, token.length) ||
|
||||||
( &header->name_buf, token.buf, token.length ) != 0
|
membuffer_assign(&header->value, hdr_value.buf, hdr_value.length)) {
|
||||||
|| membuffer_assign( &header->value, hdr_value.buf,
|
/* not enough mem */
|
||||||
hdr_value.length ) != 0 ) {
|
free(header);
|
||||||
/* not enuf mem */
|
|
||||||
free (header);
|
|
||||||
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
header->name.buf = header->name_buf.buf;
|
header->name.buf = header->name_buf.buf;
|
||||||
header->name.length = header->name_buf.length;
|
header->name.length = header->name_buf.length;
|
||||||
header->name_id = header_id;
|
header->name_id = header_id;
|
||||||
|
ListAddTail(&parser->msg.headers, header);
|
||||||
ListAddTail( &parser->msg.headers, header );
|
|
||||||
|
|
||||||
/*NNS: ret = dlist_append( &parser->msg.headers, header ); */
|
/*NNS: ret = dlist_append( &parser->msg.headers, header ); */
|
||||||
/** TODO: remove that? */
|
/** TODO: remove that? */
|
||||||
if( ret == UPNP_E_OUTOF_MEMORY ) {
|
if (ret == UPNP_E_OUTOF_MEMORY) {
|
||||||
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
parser->http_error_code =
|
||||||
|
HTTP_INTERNAL_SERVER_ERROR;
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
/** end of remove that? */
|
/** end of remove that? */
|
||||||
} else if( hdr_value.length > 0 ) {
|
} else if (hdr_value.length > 0) {
|
||||||
/* */
|
|
||||||
/* append value to existing header */
|
/* append value to existing header */
|
||||||
/* */
|
|
||||||
|
|
||||||
/* append space */
|
/* append space */
|
||||||
ret = membuffer_append_str( &orig_header->value, ", " );
|
ret = membuffer_append_str(&orig_header->value, ", ");
|
||||||
|
|
||||||
/* append continuation of header value */
|
/* append continuation of header value */
|
||||||
ret2 = membuffer_append( &orig_header->value,
|
ret2 = membuffer_append(&orig_header->value,
|
||||||
hdr_value.buf, hdr_value.length );
|
hdr_value.buf,
|
||||||
|
hdr_value.length);
|
||||||
if( ret == UPNP_E_OUTOF_MEMORY || ret2 == UPNP_E_OUTOF_MEMORY ) {
|
if (ret == UPNP_E_OUTOF_MEMORY
|
||||||
|
|| ret2 == UPNP_E_OUTOF_MEMORY) {
|
||||||
/* not enuf mem */
|
/* not enuf mem */
|
||||||
parser->http_error_code = HTTP_INTERNAL_SERVER_ERROR;
|
parser->http_error_code =
|
||||||
|
HTTP_INTERNAL_SERVER_ERROR;
|
||||||
return PARSE_FAILURE;
|
return PARSE_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1706,36 +1607,35 @@ parser_parse_entity_using_clen( INOUT http_parser_t * parser )
|
|||||||
* PARSE_FAILURE -- entity length > content-length value
|
* PARSE_FAILURE -- entity length > content-length value
|
||||||
* PARSE_SUCCESS
|
* PARSE_SUCCESS
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static UPNP_INLINE parse_status_t
|
static UPNP_INLINE parse_status_t parser_parse_chunky_body(
|
||||||
parser_parse_chunky_body( INOUT http_parser_t * parser )
|
INOUT http_parser_t *parser)
|
||||||
{
|
{
|
||||||
parse_status_t status;
|
parse_status_t status;
|
||||||
size_t save_pos;
|
size_t save_pos;
|
||||||
|
|
||||||
/* if 'chunk_size' of bytes have been read; read next chunk */
|
/* if 'chunk_size' of bytes have been read; read next chunk */
|
||||||
if( ( int )( parser->msg.msg.length - parser->scanner.cursor ) >=
|
if ((int)(parser->msg.msg.length - parser->scanner.cursor) >= parser->chunk_size) {
|
||||||
parser->chunk_size ) {
|
|
||||||
/* move to next chunk */
|
/* move to next chunk */
|
||||||
parser->scanner.cursor += parser->chunk_size;
|
parser->scanner.cursor += parser->chunk_size;
|
||||||
save_pos = parser->scanner.cursor;
|
save_pos = parser->scanner.cursor;
|
||||||
|
/* discard CRLF */
|
||||||
/*discard CRLF */
|
status = match(&parser->scanner, "%c");
|
||||||
status = match( &parser->scanner, "%c" );
|
if (status != PARSE_OK) {
|
||||||
if( status != PARSE_OK ) {
|
/*move back */
|
||||||
parser->scanner.cursor -= parser->chunk_size; /*move back */
|
parser->scanner.cursor -= parser->chunk_size;
|
||||||
/*parser->scanner.cursor = save_pos; */
|
/*parser->scanner.cursor = save_pos; */
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
membuffer_delete(&parser->msg.msg, save_pos,
|
||||||
membuffer_delete( &parser->msg.msg, save_pos,
|
(parser->scanner.cursor - save_pos));
|
||||||
( parser->scanner.cursor - save_pos ) );
|
|
||||||
parser->scanner.cursor = save_pos;
|
parser->scanner.cursor = save_pos;
|
||||||
parser->msg.entity.length += parser->chunk_size; /*update temp */
|
/*update temp */
|
||||||
|
parser->msg.entity.length += parser->chunk_size;
|
||||||
parser->ent_position = ENTREAD_USING_CHUNKED;
|
parser->ent_position = ENTREAD_USING_CHUNKED;
|
||||||
return PARSE_CONTINUE_1;
|
return PARSE_CONTINUE_1;
|
||||||
} else {
|
} else
|
||||||
return PARSE_INCOMPLETE; /* need more data for chunk */
|
/* need more data for chunk */
|
||||||
}
|
return PARSE_INCOMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@@ -1943,11 +1843,7 @@ parser_get_entity_read_method( INOUT http_parser_t * parser )
|
|||||||
}
|
}
|
||||||
/* * use content length */
|
/* * use content length */
|
||||||
if( httpmsg_find_hdr( hmsg, HDR_CONTENT_LENGTH, &hdr_value ) ) {
|
if( httpmsg_find_hdr( hmsg, HDR_CONTENT_LENGTH, &hdr_value ) ) {
|
||||||
parser->content_length = raw_to_int( &hdr_value, 10 );
|
parser->content_length = (unsigned int)raw_to_int(&hdr_value, 10);
|
||||||
if( parser->content_length < 0 ) {
|
|
||||||
/* bad content-length */
|
|
||||||
return PARSE_FAILURE;
|
|
||||||
}
|
|
||||||
parser->ent_position = ENTREAD_USING_CLEN;
|
parser->ent_position = ENTREAD_USING_CLEN;
|
||||||
return PARSE_CONTINUE_1;
|
return PARSE_CONTINUE_1;
|
||||||
}
|
}
|
||||||
@@ -2175,22 +2071,19 @@ int raw_to_int(IN memptr *raw_value, IN int base)
|
|||||||
long num;
|
long num;
|
||||||
char *end_ptr;
|
char *end_ptr;
|
||||||
|
|
||||||
if( raw_value->length == 0 ) {
|
if (raw_value->length == 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
num = strtol( raw_value->buf, &end_ptr, base );
|
num = strtol(raw_value->buf, &end_ptr, base);
|
||||||
if( ( num < 0 )
|
if ((num < 0)
|
||||||
/* all and only those chars in token should be used for num */
|
/* all and only those chars in token should be used for num */
|
||||||
|| ( end_ptr != raw_value->buf + raw_value->length )
|
|| (end_ptr != raw_value->buf + raw_value->length)
|
||||||
|| ( ( num == LONG_MIN || num == LONG_MAX )
|
|| ((num == LONG_MIN || num == LONG_MAX)
|
||||||
&& ( errno == ERANGE ) )
|
&& (errno == ERANGE))
|
||||||
) {
|
) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return num;
|
return (int)num;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@@ -2218,7 +2111,7 @@ int raw_find_str(IN memptr *raw_value, IN const char *str)
|
|||||||
|
|
||||||
/* Make it lowercase */
|
/* Make it lowercase */
|
||||||
for (i = 0; raw_value->buf[i]; ++i) {
|
for (i = 0; raw_value->buf[i]; ++i) {
|
||||||
raw_value->buf[i] = tolower(raw_value->buf[i]);
|
raw_value->buf[i] = (char)tolower(raw_value->buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* null-terminate */
|
/* null-terminate */
|
||||||
@@ -2235,7 +2128,7 @@ int raw_find_str(IN memptr *raw_value, IN const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* return index */
|
/* return index */
|
||||||
return ptr - raw_value->buf;
|
return (int)(ptr - raw_value->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -396,8 +396,8 @@ static void alias_release(
|
|||||||
ithread_mutex_unlock(&gWebMutex);
|
ithread_mutex_unlock(&gWebMutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(alias->ct > 0);
|
assert(*alias->ct > 0);
|
||||||
*alias->ct = *alias->ct - 1;
|
*alias->ct -= 1;
|
||||||
if (*alias->ct <= 0) {
|
if (*alias->ct <= 0) {
|
||||||
membuffer_destroy(&alias->doc);
|
membuffer_destroy(&alias->doc);
|
||||||
membuffer_destroy(&alias->name);
|
membuffer_destroy(&alias->name);
|
||||||
|
@@ -107,7 +107,7 @@ static int sock_read_write(
|
|||||||
/*! Buffer to get data to or send data from. */
|
/*! Buffer to get data to or send data from. */
|
||||||
OUT char *buffer,
|
OUT char *buffer,
|
||||||
/*! Size of the buffer. */
|
/*! Size of the buffer. */
|
||||||
IN size_t bufsize,
|
IN int bufsize,
|
||||||
/*! timeout value. */
|
/*! timeout value. */
|
||||||
IN int *timeoutSecs,
|
IN int *timeoutSecs,
|
||||||
/*! Boolean value specifying read or write option. */
|
/*! Boolean value specifying read or write option. */
|
||||||
@@ -120,40 +120,37 @@ static int sock_read_write(
|
|||||||
long numBytes;
|
long numBytes;
|
||||||
time_t start_time = time(NULL);
|
time_t start_time = time(NULL);
|
||||||
SOCKET sockfd = info->socket;
|
SOCKET sockfd = info->socket;
|
||||||
long bytes_sent = 0, byte_left = 0, num_written;
|
long bytes_sent = 0;
|
||||||
|
long byte_left = 0;
|
||||||
|
long num_written;
|
||||||
|
|
||||||
if (*timeoutSecs < 0) {
|
if (*timeoutSecs < 0)
|
||||||
return UPNP_E_TIMEDOUT;
|
return UPNP_E_TIMEDOUT;
|
||||||
}
|
|
||||||
FD_ZERO(&readSet);
|
FD_ZERO(&readSet);
|
||||||
FD_ZERO(&writeSet);
|
FD_ZERO(&writeSet);
|
||||||
if (bRead) {
|
if (bRead)
|
||||||
FD_SET(sockfd, &readSet);
|
FD_SET(sockfd, &readSet);
|
||||||
} else {
|
else
|
||||||
FD_SET(sockfd, &writeSet);
|
FD_SET(sockfd, &writeSet);
|
||||||
}
|
|
||||||
timeout.tv_sec = *timeoutSecs;
|
timeout.tv_sec = *timeoutSecs;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (*timeoutSecs == 0) {
|
if (*timeoutSecs == 0)
|
||||||
retCode = select(sockfd + 1, &readSet, &writeSet,
|
retCode = select(sockfd + 1, &readSet, &writeSet,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
} else {
|
else
|
||||||
retCode = select(sockfd + 1, &readSet, &writeSet,
|
retCode = select(sockfd + 1, &readSet, &writeSet,
|
||||||
NULL, &timeout);
|
NULL, &timeout);
|
||||||
}
|
if (retCode == 0)
|
||||||
if (retCode == 0) {
|
|
||||||
return UPNP_E_TIMEDOUT;
|
return UPNP_E_TIMEDOUT;
|
||||||
}
|
|
||||||
if (retCode == -1) {
|
if (retCode == -1) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
return UPNP_E_SOCKET_ERROR;
|
return UPNP_E_SOCKET_ERROR;
|
||||||
} else {
|
} else
|
||||||
/* read or write. */
|
/* read or write. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#ifdef SO_NOSIGPIPE
|
#ifdef SO_NOSIGPIPE
|
||||||
{
|
{
|
||||||
int old;
|
int old;
|
||||||
@@ -164,21 +161,21 @@ static int sock_read_write(
|
|||||||
#endif
|
#endif
|
||||||
if (bRead) {
|
if (bRead) {
|
||||||
/* read data. */
|
/* read data. */
|
||||||
numBytes = (long)recv(sockfd, buffer, bufsize, MSG_NOSIGNAL);
|
numBytes = (long)recv(sockfd, buffer, (size_t)bufsize, MSG_NOSIGNAL);
|
||||||
} else {
|
} else {
|
||||||
byte_left = bufsize;
|
byte_left = bufsize;
|
||||||
bytes_sent = 0;
|
bytes_sent = 0;
|
||||||
while (byte_left > 0) {
|
while (byte_left > 0) {
|
||||||
/* write data. */
|
/* write data. */
|
||||||
num_written = send(sockfd,
|
num_written = send(sockfd,
|
||||||
buffer + bytes_sent, byte_left,
|
buffer + bytes_sent, (size_t)byte_left,
|
||||||
MSG_DONTROUTE | MSG_NOSIGNAL);
|
MSG_DONTROUTE | MSG_NOSIGNAL);
|
||||||
if (num_written == -1) {
|
if (num_written == -1) {
|
||||||
#ifdef SO_NOSIGPIPE
|
#ifdef SO_NOSIGPIPE
|
||||||
setsockopt(sockfd, SOL_SOCKET,
|
setsockopt(sockfd, SOL_SOCKET,
|
||||||
SO_NOSIGPIPE, &old, olen);
|
SO_NOSIGPIPE, &old, olen);
|
||||||
#endif
|
#endif
|
||||||
return num_written;
|
return (int)num_written;
|
||||||
}
|
}
|
||||||
byte_left = byte_left - num_written;
|
byte_left = byte_left - num_written;
|
||||||
bytes_sent += num_written;
|
bytes_sent += num_written;
|
||||||
@@ -189,26 +186,24 @@ static int sock_read_write(
|
|||||||
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen);
|
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &old, olen);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (numBytes < 0) {
|
if (numBytes < 0)
|
||||||
return UPNP_E_SOCKET_ERROR;
|
return UPNP_E_SOCKET_ERROR;
|
||||||
}
|
|
||||||
/* subtract time used for reading/writing. */
|
/* subtract time used for reading/writing. */
|
||||||
if (*timeoutSecs != 0) {
|
if (*timeoutSecs != 0)
|
||||||
*timeoutSecs -= time(NULL) - start_time;
|
*timeoutSecs -= (int)(time(NULL) - start_time);
|
||||||
}
|
|
||||||
|
|
||||||
return numBytes;
|
return (int)numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sock_read(IN SOCKINFO *info, OUT char *buffer, IN size_t bufsize,
|
int sock_read(IN SOCKINFO *info, OUT char *buffer, IN int bufsize,
|
||||||
INOUT int *timeoutSecs)
|
INOUT int *timeoutSecs)
|
||||||
{
|
{
|
||||||
return sock_read_write(info, buffer, bufsize, timeoutSecs, TRUE);
|
return sock_read_write(info, buffer, bufsize, timeoutSecs, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sock_write(IN SOCKINFO *info, IN char *buffer, IN size_t bufsize,
|
int sock_write(IN SOCKINFO *info, IN const char *buffer, IN int bufsize,
|
||||||
INOUT int *timeoutSecs)
|
INOUT int *timeoutSecs)
|
||||||
{
|
{
|
||||||
return sock_read_write(info, buffer, bufsize, timeoutSecs, FALSE);
|
return sock_read_write(info, (char *)buffer, bufsize, timeoutSecs, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -271,111 +271,98 @@ void print_uri(uri_type *in)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void print_token(token * in)
|
void print_token(token * in)
|
||||||
{
|
{
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
printf( "Token Size : %"PRIzu"\n\'", in->size );
|
|
||||||
for( i = 0; i < in->size; i++ ) {
|
printf("Token Size : %" PRIzu "\n\'", in->size);
|
||||||
putchar( in->buff[i] );
|
for (i = 0; i < in->size; i++)
|
||||||
}
|
putchar(in->buff[i]);
|
||||||
putchar( '\'' );
|
putchar('\'');
|
||||||
putchar( '\n' );
|
putchar('\n');
|
||||||
}
|
}
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
|
||||||
int token_string_casecmp(token *in1, char *in2)
|
int token_string_casecmp(token *in1, const char *in2)
|
||||||
{
|
{
|
||||||
size_t in2_length = strlen(in2);
|
size_t in2_length = strlen(in2);
|
||||||
|
if (in1->size != in2_length)
|
||||||
if (in1->size != in2_length) {
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
else
|
||||||
return strncasecmp(in1->buff, in2, in1->size);
|
return strncasecmp(in1->buff, in2, in1->size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int token_string_cmp(token * in1, char *in2)
|
int token_string_cmp(token * in1, char *in2)
|
||||||
{
|
{
|
||||||
size_t in2_length = strlen(in2);
|
size_t in2_length = strlen(in2);
|
||||||
|
if (in1->size != in2_length)
|
||||||
if (in1->size != in2_length) {
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
else
|
||||||
return strncmp(in1->buff, in2, in1->size);
|
return strncmp(in1->buff, in2, in1->size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int token_cmp(token *in1, token *in2)
|
int token_cmp(token *in1, token *in2)
|
||||||
{
|
{
|
||||||
if (in1->size != in2->size) {
|
if (in1->size != in2->size)
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
else
|
||||||
return memcmp(in1->buff, in2->buff, in1->size);
|
return memcmp(in1->buff, in2->buff, in1->size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int parse_hostport(
|
int parse_hostport(
|
||||||
const char *in,
|
const char *in,
|
||||||
size_t max,
|
size_t max,
|
||||||
hostport_type *out)
|
hostport_type *out)
|
||||||
{
|
{
|
||||||
char workbuf[256];
|
char workbuf[256];
|
||||||
char* c;
|
char *c;
|
||||||
struct sockaddr_in* sai4 = (struct sockaddr_in*)&out->IPaddress;
|
struct sockaddr_in *sai4 = (struct sockaddr_in *)&out->IPaddress;
|
||||||
struct sockaddr_in6* sai6 = (struct sockaddr_in6*)&out->IPaddress;
|
struct sockaddr_in6 *sai6 = (struct sockaddr_in6 *)&out->IPaddress;
|
||||||
char *srvname = NULL;
|
char *srvname = NULL;
|
||||||
char *srvport = NULL;
|
char *srvport = NULL;
|
||||||
char *last_dot = NULL;
|
char *last_dot = NULL;
|
||||||
unsigned short int port;
|
unsigned short int port;
|
||||||
int af = AF_UNSPEC;
|
int af = AF_UNSPEC;
|
||||||
int hostport_size;
|
size_t hostport_size;
|
||||||
int has_port = 0;
|
int has_port = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
memset( out, 0, sizeof(hostport_type) );
|
memset(out, 0, sizeof(hostport_type));
|
||||||
|
|
||||||
/* Work on a copy of the input string. */
|
/* Work on a copy of the input string. */
|
||||||
strncpy( workbuf, in, sizeof(workbuf) );
|
strncpy(workbuf, in, sizeof(workbuf));
|
||||||
|
|
||||||
c = workbuf;
|
c = workbuf;
|
||||||
if( *c == '[' ) {
|
if (*c == '[') {
|
||||||
/* IPv6 addresses are enclosed in square brackets. */
|
/* IPv6 addresses are enclosed in square brackets. */
|
||||||
srvname = ++c;
|
srvname = ++c;
|
||||||
while( *c != '\0' && *c != ']' ) {
|
while (*c != '\0' && *c != ']')
|
||||||
c++;
|
c++;
|
||||||
}
|
if (*c == '\0')
|
||||||
if( *c == '\0' ) {
|
|
||||||
/* did not find closing bracket. */
|
/* did not find closing bracket. */
|
||||||
return UPNP_E_INVALID_URL;
|
return UPNP_E_INVALID_URL;
|
||||||
}
|
|
||||||
/* NULL terminate the srvname and then increment c. */
|
/* NULL terminate the srvname and then increment c. */
|
||||||
*c++ = '\0'; /* overwrite the ']' */
|
*c++ = '\0'; /* overwrite the ']' */
|
||||||
if( *c == ':' ) {
|
if (*c == ':') {
|
||||||
has_port = 1;
|
has_port = 1;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
af = AF_INET6;
|
af = AF_INET6;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* IPv4 address -OR- host name. */
|
/* IPv4 address -OR- host name. */
|
||||||
srvname = c;
|
srvname = c;
|
||||||
while( (*c != ':') && (*c != '/') && ( (isalnum(*c)) || (*c == '.') || (*c == '-') ) ) {
|
while (*c != ':' && *c != '/' &&
|
||||||
if( *c == '.' )
|
(isalnum(*c) || *c == '.' || *c == '-')) {
|
||||||
|
if (*c == '.')
|
||||||
last_dot = c;
|
last_dot = c;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
has_port = (*c == ':') ? 1 : 0;
|
has_port = (*c == ':') ? 1 : 0;
|
||||||
/* NULL terminate the srvname */
|
/* NULL terminate the srvname */
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
if( has_port == 1 )
|
if (has_port == 1)
|
||||||
c++;
|
c++;
|
||||||
|
if (last_dot != NULL && isdigit(*(last_dot + 1)))
|
||||||
if( last_dot != NULL && isdigit(*(last_dot+1)) ) {
|
|
||||||
/* Must be an IPv4 address. */
|
/* Must be an IPv4 address. */
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
/* Must be a host name. */
|
/* Must be a host name. */
|
||||||
struct addrinfo hints, *res, *res0;
|
struct addrinfo hints, *res, *res0;
|
||||||
@@ -385,59 +372,48 @@ int parse_hostport(
|
|||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
ret = getaddrinfo(srvname, NULL, &hints, &res0);
|
ret = getaddrinfo(srvname, NULL, &hints, &res0);
|
||||||
if( ret == 0 ) {
|
if (ret == 0) {
|
||||||
for (res = res0; res; res = res->ai_next) {
|
for (res = res0; res; res = res->ai_next) {
|
||||||
if( res->ai_family == AF_INET ||
|
if (res->ai_family == AF_INET ||
|
||||||
res->ai_family == AF_INET6 ) {
|
res->ai_family == AF_INET6) {
|
||||||
/* Found a valid IPv4 or IPv6 address. */
|
/* Found a valid IPv4 or IPv6 address. */
|
||||||
memcpy( &out->IPaddress, res->ai_addr,
|
memcpy(&out->IPaddress,
|
||||||
res->ai_addrlen );
|
res->ai_addr,
|
||||||
|
res->ai_addrlen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
|
if (res == NULL)
|
||||||
if( res == NULL ) {
|
|
||||||
/* Didn't find an AF_INET or AF_INET6 address. */
|
/* Didn't find an AF_INET or AF_INET6 address. */
|
||||||
return UPNP_E_INVALID_URL;
|
return UPNP_E_INVALID_URL;
|
||||||
}
|
} else
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* getaddrinfo failed. */
|
/* getaddrinfo failed. */
|
||||||
return UPNP_E_INVALID_URL;
|
return UPNP_E_INVALID_URL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if a port is specified. */
|
/* Check if a port is specified. */
|
||||||
if( has_port == 1 ) {
|
if (has_port == 1) {
|
||||||
/* Port is specified. */
|
/* Port is specified. */
|
||||||
srvport = c;
|
srvport = c;
|
||||||
while( *c != '\0' && isdigit(*c) ) {
|
while (*c != '\0' && isdigit(*c))
|
||||||
c++;
|
c++;
|
||||||
}
|
|
||||||
port = (unsigned short int)atoi(srvport);
|
port = (unsigned short int)atoi(srvport);
|
||||||
if( port == 0 ) {
|
if (port == 0)
|
||||||
/* Bad port number. */
|
/* Bad port number. */
|
||||||
return UPNP_E_INVALID_URL;
|
return UPNP_E_INVALID_URL;
|
||||||
}
|
} else
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Port was not specified, use default port. */
|
/* Port was not specified, use default port. */
|
||||||
port = 80;
|
port = 80;
|
||||||
}
|
|
||||||
|
|
||||||
/* The length of the host and port string can be calculated by */
|
/* The length of the host and port string can be calculated by */
|
||||||
/* subtracting pointers. */
|
/* subtracting pointers. */
|
||||||
hostport_size = (int)(c - workbuf);
|
hostport_size = (size_t)(c - workbuf);
|
||||||
|
|
||||||
/* Fill in the 'out' information. */
|
/* Fill in the 'out' information. */
|
||||||
if( af == AF_INET ) {
|
if (af == AF_INET) {
|
||||||
sai4->sin_family = AF_INET;
|
sai4->sin_family = AF_INET;
|
||||||
sai4->sin_port = htons(port);
|
sai4->sin_port = htons(port);
|
||||||
ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
|
ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
|
||||||
}
|
} else if (af == AF_INET6) {
|
||||||
else if( af == AF_INET6 ) {
|
|
||||||
sai6->sin6_family = AF_INET6;
|
sai6->sin6_family = AF_INET6;
|
||||||
sai6->sin6_port = htons(port);
|
sai6->sin6_port = htons(port);
|
||||||
sai6->sin6_scope_id = gIF_INDEX;
|
sai6->sin6_scope_id = gIF_INDEX;
|
||||||
@@ -445,22 +421,19 @@ int parse_hostport(
|
|||||||
} else {
|
} else {
|
||||||
/* IP address was set by the hostname (getaddrinfo). */
|
/* IP address was set by the hostname (getaddrinfo). */
|
||||||
/* Override port: */
|
/* Override port: */
|
||||||
if( out->IPaddress.ss_family == AF_INET )
|
if (out->IPaddress.ss_family == AF_INET)
|
||||||
sai4->sin_port = htons(port);
|
sai4->sin_port = htons(port);
|
||||||
else
|
else
|
||||||
sai6->sin6_port = htons(port);
|
sai6->sin6_port = htons(port);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if address was converted successfully. */
|
/* Check if address was converted successfully. */
|
||||||
if (ret <= 0) {
|
if (ret <= 0)
|
||||||
return UPNP_E_INVALID_URL;
|
return UPNP_E_INVALID_URL;
|
||||||
}
|
|
||||||
|
|
||||||
out->text.size = hostport_size;
|
out->text.size = hostport_size;
|
||||||
out->text.buff = in;
|
out->text.buff = in;
|
||||||
|
|
||||||
return hostport_size;
|
return (int)hostport_size;
|
||||||
max = max;
|
max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -206,7 +206,7 @@ int http_RequestAndResponse(
|
|||||||
* IN int timeout_secs; time out value
|
* IN int timeout_secs; time out value
|
||||||
* OUT char** document; buffer to store the document extracted
|
* OUT char** document; buffer to store the document extracted
|
||||||
* from the donloaded message.
|
* from the donloaded message.
|
||||||
* OUT int* doc_length; length of the extracted document
|
* OUT size_t* doc_length; length of the extracted document
|
||||||
* OUT char* content_type; Type of content
|
* OUT char* content_type; Type of content
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@@ -221,7 +221,7 @@ int http_Download(
|
|||||||
IN const char* url,
|
IN const char* url,
|
||||||
IN int timeout_secs,
|
IN int timeout_secs,
|
||||||
OUT char** document,
|
OUT char** document,
|
||||||
OUT int* doc_length,
|
OUT size_t *doc_length,
|
||||||
OUT char* content_type );
|
OUT char* content_type );
|
||||||
|
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ int http_Download(
|
|||||||
* IN void *Handle: Handle to the http post object
|
* IN void *Handle: Handle to the http post object
|
||||||
* IN char *buf: Buffer to send to peer, if format used
|
* IN char *buf: Buffer to send to peer, if format used
|
||||||
* is not UPNP_USING_CHUNKED,
|
* is not UPNP_USING_CHUNKED,
|
||||||
* IN unsigned int *size: Size of the data to be sent.
|
* IN size_t *size: Size of the data to be sent.
|
||||||
* IN int timeout: time out value
|
* IN int timeout: time out value
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@@ -246,7 +246,7 @@ int http_Download(
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
int http_WriteHttpPost(IN void *Handle,
|
int http_WriteHttpPost(IN void *Handle,
|
||||||
IN char *buf,
|
IN char *buf,
|
||||||
IN unsigned int *size,
|
IN size_t *size,
|
||||||
IN int timeout);
|
IN int timeout);
|
||||||
|
|
||||||
|
|
||||||
@@ -350,7 +350,6 @@ int http_HttpGetProgress(
|
|||||||
OUT size_t *length,
|
OUT size_t *length,
|
||||||
OUT size_t *total);
|
OUT size_t *total);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: http_CloseHttpGet
|
* Function: http_CloseHttpGet
|
||||||
*
|
*
|
||||||
@@ -367,74 +366,61 @@ int http_HttpGetProgress(
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
int http_CloseHttpGet(IN void *Handle);
|
int http_CloseHttpGet(IN void *Handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
/************************************************************************
|
* \brief Makes the HTTP GET message, connects to the peer,
|
||||||
* Function: http_OpenHttpGet
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* IN const char *url_str: String as a URL
|
|
||||||
* IN OUT void **Handle: Pointer to buffer to store HTTP
|
|
||||||
* post handle
|
|
||||||
* IN OUT char **contentType: Type of content
|
|
||||||
* OUT int *contentLength: length of content
|
|
||||||
* OUT int *httpStatus: HTTP status returned on receiving a
|
|
||||||
* response message
|
|
||||||
* IN int timeout: time out value
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Makes the HTTP GET message, connects to the peer,
|
|
||||||
* sends the HTTP GET request, gets the response and parses the
|
|
||||||
* response.
|
|
||||||
*
|
|
||||||
* Return: int
|
|
||||||
* UPNP_E_SUCCESS - On Success
|
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Paramters
|
|
||||||
* UPNP_E_OUTOF_MEMORY
|
|
||||||
* UPNP_E_SOCKET_ERROR
|
|
||||||
* UPNP_E_BAD_RESPONSE
|
|
||||||
************************************************************************/
|
|
||||||
int http_OpenHttpGet(
|
|
||||||
IN const char *url_str,
|
|
||||||
IN OUT void **Handle,
|
|
||||||
IN OUT char **contentType,
|
|
||||||
OUT int *contentLength,
|
|
||||||
OUT int *httpStatus,
|
|
||||||
IN int timeout);
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
|
||||||
* Function: http_OpenHttpGetProxy
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* IN const char *url_str; String as a URL
|
|
||||||
* IN const char *proxy_str; String as a URL
|
|
||||||
* IN OUT void **Handle; Pointer to buffer to store HTTP
|
|
||||||
* post handle
|
|
||||||
* IN OUT char **contentType; Type of content
|
|
||||||
* OUT int *contentLength; length of content
|
|
||||||
* OUT int *httpStatus; HTTP status returned on receiving a
|
|
||||||
* response message
|
|
||||||
* IN int timeout: time out value
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Makes the HTTP GET message, connects to the peer,
|
|
||||||
* sends the HTTP GET request, gets the response and parses the response.
|
* sends the HTTP GET request, gets the response and parses the response.
|
||||||
|
*
|
||||||
* If a proxy URL is defined then the connection is made there.
|
* If a proxy URL is defined then the connection is made there.
|
||||||
*
|
*
|
||||||
* Return: int
|
* \return integer
|
||||||
* UPNP_E_SUCCESS - On Success
|
* \li \c UPNP_E_SUCCESS - On Success
|
||||||
* UPNP_E_INVALID_PARAM - Invalid Paramters
|
* \li \c UPNP_E_INVALID_PARAM - Invalid Paramters
|
||||||
* UPNP_E_OUTOF_MEMORY
|
* \li \c UPNP_E_OUTOF_MEMORY
|
||||||
* UPNP_E_SOCKET_ERROR
|
* \li \c UPNP_E_SOCKET_ERROR
|
||||||
* UPNP_E_BAD_RESPONSE
|
* \li \c UPNP_E_BAD_RESPONSE
|
||||||
************************************************************************/
|
*/
|
||||||
int http_OpenHttpGetProxy(IN const char *url_str,
|
int http_OpenHttpGet(
|
||||||
IN const char *proxy_str,
|
/* [in] String as a URL. */
|
||||||
IN OUT void **Handle,
|
const char *url_str,
|
||||||
IN OUT char **contentType,
|
/* [in,out] Pointer to buffer to store HTTP post handle. */
|
||||||
OUT int *contentLength,
|
void **Handle,
|
||||||
OUT int *httpStatus,
|
/* [in,out] Type of content. */
|
||||||
IN int timeout);
|
char **contentType,
|
||||||
|
/* [out] length of content. */
|
||||||
|
int *contentLength,
|
||||||
|
/* [out] HTTP status returned on receiving a response message. */
|
||||||
|
int *httpStatus,
|
||||||
|
/* [in] time out value. */
|
||||||
|
int timeout);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Makes the HTTP GET message, connects to the peer,
|
||||||
|
* sends the HTTP GET request, gets the response and parses the response.
|
||||||
|
*
|
||||||
|
* If a proxy URL is defined then the connection is made there.
|
||||||
|
*
|
||||||
|
* \return integer
|
||||||
|
* \li \c UPNP_E_SUCCESS - On Success
|
||||||
|
* \li \c UPNP_E_INVALID_PARAM - Invalid Paramters
|
||||||
|
* \li \c UPNP_E_OUTOF_MEMORY
|
||||||
|
* \li \c UPNP_E_SOCKET_ERROR
|
||||||
|
* \li \c UPNP_E_BAD_RESPONSE
|
||||||
|
*/
|
||||||
|
int http_OpenHttpGetProxy(
|
||||||
|
/* [in] String as a URL. */
|
||||||
|
const char *url_str,
|
||||||
|
/* [in] String as a URL. */
|
||||||
|
const char *proxy_str,
|
||||||
|
/* [in,out] Pointer to buffer to store HTTP post handle. */
|
||||||
|
void **Handle,
|
||||||
|
/* [in,out] Type of content. */
|
||||||
|
char **contentType,
|
||||||
|
/* [out] length of content. */
|
||||||
|
int *contentLength,
|
||||||
|
/* [out] HTTP status returned on receiving a response message. */
|
||||||
|
int *httpStatus,
|
||||||
|
/* [in] time out value. */
|
||||||
|
int timeout);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@@ -463,61 +449,55 @@ int http_SendStatusResponse(
|
|||||||
IN int request_major_version,
|
IN int request_major_version,
|
||||||
IN int request_minor_version );
|
IN int request_minor_version );
|
||||||
|
|
||||||
|
/*!
|
||||||
/************************************************************************
|
* \brief Generate an HTTP message based on the format that is specified in
|
||||||
* Function: http_MakeMessage
|
* the input parameters.
|
||||||
*
|
*
|
||||||
* Parameters:
|
\verbatim
|
||||||
* INOUT membuffer* buf; buffer with the contents of the
|
Format types:
|
||||||
* message
|
'B': arg = int status_code -- appends content-length, content-type and HTML body for given code.
|
||||||
* IN int http_major_version; HTTP major version
|
'b': arg1 = const char *buf;
|
||||||
* IN int http_minor_version; HTTP minor version
|
arg2 = size_t buf_length memory ptr
|
||||||
* IN const char* fmt; Pattern format
|
'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
|
||||||
|
'L': arg = language information -- add Content-Language header if Accept-Language header is not empty and if
|
||||||
|
WEB_SERVER_CONTENT_LANGUAGE is not empty
|
||||||
|
'N': arg1 = off_t content_length -- content-length header
|
||||||
|
'q': arg1 = http_method_t -- request start line and HOST header
|
||||||
|
arg2 = (uri_type *)
|
||||||
|
'Q': arg1 = http_method_t; -- start line of request
|
||||||
|
arg2 = char* url;
|
||||||
|
arg3 = size_t url_length
|
||||||
|
'R': arg = int status_code -- adds a response start line
|
||||||
|
'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
|
||||||
|
'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
|
||||||
|
\endverbatim
|
||||||
*
|
*
|
||||||
* Description:
|
* \return
|
||||||
* Generate an HTTP message based on the format that is specified
|
* \li \c 0 - On Success
|
||||||
* in the input parameters.
|
* \li \c UPNP_E_OUTOF_MEMORY
|
||||||
*
|
* \li \c UPNP_E_INVALID_URL
|
||||||
* fmt types:
|
*/
|
||||||
* '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 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 = off_t content_length // content-length header
|
|
||||||
* 'q': arg1 = http_method_t // request start line and HOST header
|
|
||||||
* arg2 = (uri_type *)
|
|
||||||
* 'Q': arg1 = http_method_t; // start line of request
|
|
||||||
* arg2 = char* url;
|
|
||||||
* arg3 = size_t url_length
|
|
||||||
* 'R': arg = int status_code // adds a response start line
|
|
||||||
* '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
|
|
||||||
* '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
|
|
||||||
* UPNP_E_OUTOF_MEMORY
|
|
||||||
* UPNP_E_INVALID_URL
|
|
||||||
************************************************************************/
|
|
||||||
int http_MakeMessage(
|
int http_MakeMessage(
|
||||||
|
/* [in,out] Buffer with the contents of the message. */
|
||||||
INOUT membuffer* buf,
|
INOUT membuffer* buf,
|
||||||
|
/* [in] HTTP major version. */
|
||||||
IN int http_major_version,
|
IN int http_major_version,
|
||||||
|
/* [in] HTTP minor version. */
|
||||||
IN int http_minor_version,
|
IN int http_minor_version,
|
||||||
IN const char* fmt, ... );
|
/* [in] Pattern format. */
|
||||||
|
IN const char* fmt,
|
||||||
|
/* [in] Format arguments. */
|
||||||
|
... );
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@@ -110,7 +110,7 @@ int sock_read(
|
|||||||
/*! Buffer to get data to. */
|
/*! Buffer to get data to. */
|
||||||
OUT char* buffer,
|
OUT char* buffer,
|
||||||
/*! Size of the buffer. */
|
/*! Size of the buffer. */
|
||||||
IN size_t bufsize,
|
IN int bufsize,
|
||||||
/*! timeout value. */
|
/*! timeout value. */
|
||||||
INOUT int *timeoutSecs);
|
INOUT int *timeoutSecs);
|
||||||
|
|
||||||
@@ -126,9 +126,9 @@ int sock_write(
|
|||||||
/*! Socket Information Object. */
|
/*! Socket Information Object. */
|
||||||
IN SOCKINFO *info,
|
IN SOCKINFO *info,
|
||||||
/*! Buffer to send data from. */
|
/*! Buffer to send data from. */
|
||||||
IN char* buffer,
|
IN const char *buffer,
|
||||||
/*! Size of the buffer. */
|
/*! Size of the buffer. */
|
||||||
IN size_t bufsize,
|
IN int bufsize,
|
||||||
/*! timeout value. */
|
/*! timeout value. */
|
||||||
INOUT int *timeoutSecs);
|
INOUT int *timeoutSecs);
|
||||||
|
|
||||||
|
@@ -247,7 +247,7 @@ int token_string_casecmp(
|
|||||||
/*! [in] Token object whose buffer is to be compared. */
|
/*! [in] Token object whose buffer is to be compared. */
|
||||||
token *in1,
|
token *in1,
|
||||||
/*! [in] String of characters to compare with. */
|
/*! [in] String of characters to compare with. */
|
||||||
char *in2);
|
const char *in2);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Compares a null terminated string to a token (exact).
|
* \brief Compares a null terminated string to a token (exact).
|
||||||
|
@@ -157,42 +157,39 @@ int AdvertiseAndReply(
|
|||||||
if (NumCopy != 0)
|
if (NumCopy != 0)
|
||||||
imillisleep(SSDP_PAUSE);
|
imillisleep(SSDP_PAUSE);
|
||||||
NumCopy++;
|
NumCopy++;
|
||||||
|
|
||||||
for (i = 0;; i++) {
|
for (i = 0;; i++) {
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Entering new device list with i = %d\n\n", i);
|
"Entering new device list with i = %lu\n\n", i);
|
||||||
tmpNode = ixmlNodeList_item(SInfo->DeviceList, i);
|
tmpNode = ixmlNodeList_item(SInfo->DeviceList, i);
|
||||||
if (!tmpNode) {
|
if (!tmpNode) {
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Exiting new device list with i = %d\n\n", i);
|
"Exiting new device list with i = %lu\n\n", i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dbgStr = ixmlNode_getNodeName(tmpNode);
|
dbgStr = ixmlNode_getNodeName(tmpNode);
|
||||||
|
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Extracting device type once for %s\n", dbgStr);
|
"Extracting device type once for %s\n", dbgStr);
|
||||||
ixmlNodeList_free(nodeList);
|
ixmlNodeList_free(nodeList);
|
||||||
nodeList = ixmlElement_getElementsByTagName(
|
nodeList = ixmlElement_getElementsByTagName(
|
||||||
(IXML_Element *)tmpNode, "deviceType");
|
(IXML_Element *)tmpNode, "deviceType");
|
||||||
if (!nodeList) continue;
|
if (!nodeList)
|
||||||
|
continue;
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting UDN for %s\n", dbgStr);
|
"Extracting UDN for %s\n", dbgStr);
|
||||||
dbgStr = ixmlNode_getNodeName(tmpNode);
|
dbgStr = ixmlNode_getNodeName(tmpNode);
|
||||||
|
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting device type\n");
|
"Extracting device type\n");
|
||||||
tmpNode2 = ixmlNodeList_item(nodeList, 0);
|
tmpNode2 = ixmlNodeList_item(nodeList, 0);
|
||||||
if (!tmpNode2) continue;
|
if (!tmpNode2)
|
||||||
|
continue;
|
||||||
textNode = ixmlNode_getFirstChild(tmpNode2);
|
textNode = ixmlNode_getFirstChild(tmpNode2);
|
||||||
if (!textNode) continue;
|
if (!textNode) continue;
|
||||||
|
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting device type \n");
|
"Extracting device type \n");
|
||||||
tmpStr = ixmlNode_getNodeValue(textNode);
|
tmpStr = ixmlNode_getNodeValue(textNode);
|
||||||
if (!tmpStr) continue;
|
if (!tmpStr)
|
||||||
|
continue;
|
||||||
strcpy(devType, tmpStr);
|
strcpy(devType, tmpStr);
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting device type = %s\n", devType);
|
"Extracting device type = %s\n", devType);
|
||||||
@@ -201,7 +198,6 @@ int AdvertiseAndReply(
|
|||||||
"TempNode is NULL\n");
|
"TempNode is NULL\n");
|
||||||
}
|
}
|
||||||
dbgStr = ixmlNode_getNodeName(tmpNode);
|
dbgStr = ixmlNode_getNodeName(tmpNode);
|
||||||
|
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"Extracting UDN for %s\n", dbgStr);
|
"Extracting UDN for %s\n", dbgStr);
|
||||||
ixmlNodeList_free(nodeList);
|
ixmlNodeList_free(nodeList);
|
||||||
@@ -226,8 +222,8 @@ int AdvertiseAndReply(
|
|||||||
}
|
}
|
||||||
tmpStr = ixmlNode_getNodeValue(textNode);
|
tmpStr = ixmlNode_getNodeValue(textNode);
|
||||||
if (!tmpStr) {
|
if (!tmpStr) {
|
||||||
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_CRITICAL, API, __FILE__,
|
||||||
"UDN not found!\n");
|
__LINE__, "UDN not found!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strcpy(UDNstr, tmpStr);
|
strcpy(UDNstr, tmpStr);
|
||||||
@@ -237,11 +233,13 @@ int AdvertiseAndReply(
|
|||||||
/* send the device advertisement */
|
/* send the device advertisement */
|
||||||
if (AdFlag == 1) {
|
if (AdFlag == 1) {
|
||||||
DeviceAdvertisement(devType, i == 0,
|
DeviceAdvertisement(devType, i == 0,
|
||||||
UDNstr, SInfo->DescURL, Exp, SInfo->DeviceAf );
|
UDNstr, SInfo->DescURL, Exp,
|
||||||
|
SInfo->DeviceAf);
|
||||||
} else {
|
} else {
|
||||||
/* AdFlag == -1 */
|
/* AdFlag == -1 */
|
||||||
DeviceShutdown(devType, i == 0, UDNstr,
|
DeviceShutdown(devType, i == 0, UDNstr,
|
||||||
SERVER, SInfo->DescURL, Exp, SInfo->DeviceAf );
|
SERVER, SInfo->DescURL, Exp,
|
||||||
|
SInfo->DeviceAf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (SearchType) {
|
switch (SearchType) {
|
||||||
|
@@ -31,8 +31,7 @@
|
|||||||
system dependent call to get IEEE node ID.
|
system dependent call to get IEEE node ID.
|
||||||
This sample implementation generates a random node ID
|
This sample implementation generates a random node ID
|
||||||
*/
|
*/
|
||||||
void
|
void get_ieee_node_identifier(uuid_node_t *node)
|
||||||
get_ieee_node_identifier(uuid_node_t *node)
|
|
||||||
{
|
{
|
||||||
unsigned char seed[16];
|
unsigned char seed[16];
|
||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
@@ -41,10 +40,9 @@ get_ieee_node_identifier(uuid_node_t *node)
|
|||||||
if (!inited) {
|
if (!inited) {
|
||||||
get_random_info(seed);
|
get_random_info(seed);
|
||||||
seed[0] |= 0x80;
|
seed[0] |= 0x80;
|
||||||
memcpy(&saved_node, seed, sizeof (uuid_node_t));
|
memcpy(&saved_node, seed, sizeof(uuid_node_t));
|
||||||
inited = 1;
|
inited = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
*node = saved_node;
|
*node = saved_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,31 +55,25 @@ get_ieee_node_identifier(uuid_node_t *node)
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
void
|
void get_system_time(uuid_time_t *uuid_time)
|
||||||
get_system_time( uuid_time_t * uuid_time )
|
|
||||||
{
|
{
|
||||||
ULARGE_INTEGER time;
|
ULARGE_INTEGER time;
|
||||||
|
|
||||||
GetSystemTimeAsFileTime( ( FILETIME * ) & time );
|
GetSystemTimeAsFileTime((FILETIME *) & time);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NT keeps time in FILETIME format which is 100ns ticks since
|
NT keeps time in FILETIME format which is 100ns ticks since
|
||||||
Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
|
Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
|
||||||
The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
|
The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
|
||||||
+ 18 years and 5 leap days.
|
+ 18 years and 5 leap days.
|
||||||
*/
|
*/
|
||||||
|
time.QuadPart += (unsigned __int64)(1000 * 1000 * 10) /* seconds */
|
||||||
time.QuadPart += ( unsigned __int64 )( 1000 * 1000 * 10 ) /* seconds */
|
*(unsigned __int64)(60 * 60 * 24) /* days */
|
||||||
* ( unsigned __int64 )( 60 * 60 * 24 ) /* days */
|
*(unsigned __int64)(17 + 30 + 31 + 365 * 18 + 5); /* # of days */
|
||||||
* ( unsigned __int64 )( 17 + 30 + 31 + 365 * 18 + 5 ); /* # of days */
|
|
||||||
|
|
||||||
*uuid_time = time.QuadPart;
|
*uuid_time = time.QuadPart;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void get_random_info(char seed[16])
|
||||||
get_random_info(char seed[16])
|
|
||||||
{
|
{
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -121,25 +113,22 @@ get_random_info(char seed[16])
|
|||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void get_system_time(uuid_time_t *uuid_time)
|
||||||
get_system_time(uuid_time_t *uuid_time)
|
|
||||||
{
|
{
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
|
|
||||||
gettimeofday( &tp, ( struct timezone * )0 );
|
gettimeofday(&tp, (struct timezone *)0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Offset between UUID formatted times and Unix formatted times.
|
Offset between UUID formatted times and Unix formatted times.
|
||||||
UUID UTC base time is October 15, 1582.
|
UUID UTC base time is October 15, 1582.
|
||||||
Unix base time is January 1, 1970.
|
Unix base time is January 1, 1970.
|
||||||
*/
|
*/
|
||||||
*uuid_time = ( tp.tv_sec * 10000000 ) + ( tp.tv_usec * 10 ) +
|
*uuid_time = (uuid_time_t) (tp.tv_sec * 10000000 + tp.tv_usec * 10 +
|
||||||
I64( 0x01B21DD213814000 );
|
I64(0x01B21DD213814000));
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void
|
void get_random_info(unsigned char seed[16])
|
||||||
get_random_info(unsigned char seed[16])
|
|
||||||
{
|
{
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Reference in New Issue
Block a user