Doxygen, reformating, compiler warnings.

This commit is contained in:
Marcelo Roberto Jimenez
2010-11-21 21:40:07 -02:00
parent c449fd1521
commit c21a67f2d1
13 changed files with 1713 additions and 2210 deletions

View File

@@ -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);

View File

@@ -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);
@@ -2887,21 +2887,18 @@ 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);
if (ret_code > 0)
/* error reply was received */
ret_code = UPNP_E_INVALID_URL;
ret_code = http_Download( url, HTTP_DEFAULT_TIMEOUT, outBuf, &dummy, return ret_code;
contentType );
if( ret_code > 0 ) {
/* error reply was received */
ret_code = UPNP_E_INVALID_URL;
}
return ret_code;
} }

View File

@@ -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;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -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);

View File

@@ -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,39 +120,36 @@ 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
{ {
@@ -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);
} }

View File

@@ -271,197 +271,170 @@ 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. */
strncpy(workbuf, in, sizeof(workbuf));
c = workbuf;
if (*c == '[') {
/* IPv6 addresses are enclosed in square brackets. */
srvname = ++c;
while (*c != '\0' && *c != ']')
c++;
if (*c == '\0')
/* did not find closing bracket. */
return UPNP_E_INVALID_URL;
/* NULL terminate the srvname and then increment c. */
*c++ = '\0'; /* overwrite the ']' */
if (*c == ':') {
has_port = 1;
c++;
}
af = AF_INET6;
} else {
/* IPv4 address -OR- host name. */
srvname = c;
while (*c != ':' && *c != '/' &&
(isalnum(*c) || *c == '.' || *c == '-')) {
if (*c == '.')
last_dot = c;
c++;
}
has_port = (*c == ':') ? 1 : 0;
/* NULL terminate the srvname */
*c = '\0';
if (has_port == 1)
c++;
if (last_dot != NULL && isdigit(*(last_dot + 1)))
/* Must be an IPv4 address. */
af = AF_INET;
else {
/* Must be a host name. */
struct addrinfo hints, *res, *res0;
/* Work on a copy of the input string. */ memset(&hints, 0, sizeof(hints));
strncpy( workbuf, in, sizeof(workbuf) ); hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
c = workbuf; ret = getaddrinfo(srvname, NULL, &hints, &res0);
if( *c == '[' ) { if (ret == 0) {
/* IPv6 addresses are enclosed in square brackets. */ for (res = res0; res; res = res->ai_next) {
srvname = ++c; if (res->ai_family == AF_INET ||
while( *c != '\0' && *c != ']' ) { res->ai_family == AF_INET6) {
c++; /* Found a valid IPv4 or IPv6 address. */
} memcpy(&out->IPaddress,
if( *c == '\0' ) { res->ai_addr,
/* did not find closing bracket. */ res->ai_addrlen);
return UPNP_E_INVALID_URL; break;
} }
/* NULL terminate the srvname and then increment c. */ }
*c++ = '\0'; /* overwrite the ']' */ freeaddrinfo(res0);
if( *c == ':' ) { if (res == NULL)
has_port = 1; /* Didn't find an AF_INET or AF_INET6 address. */
c++; return UPNP_E_INVALID_URL;
} } else
af = AF_INET6; /* getaddrinfo failed. */
} return UPNP_E_INVALID_URL;
else { }
/* IPv4 address -OR- host name. */ }
srvname = c; /* Check if a port is specified. */
while( (*c != ':') && (*c != '/') && ( (isalnum(*c)) || (*c == '.') || (*c == '-') ) ) { if (has_port == 1) {
if( *c == '.' ) /* Port is specified. */
last_dot = c; srvport = c;
c++; while (*c != '\0' && isdigit(*c))
} c++;
has_port = (*c == ':') ? 1 : 0; port = (unsigned short int)atoi(srvport);
/* NULL terminate the srvname */ if (port == 0)
*c = '\0'; /* Bad port number. */
if( has_port == 1 ) return UPNP_E_INVALID_URL;
c++; } else
/* Port was not specified, use default port. */
port = 80;
/* The length of the host and port string can be calculated by */
/* subtracting pointers. */
hostport_size = (size_t)(c - workbuf);
/* Fill in the 'out' information. */
if (af == AF_INET) {
sai4->sin_family = AF_INET;
sai4->sin_port = htons(port);
ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
} else if (af == AF_INET6) {
sai6->sin6_family = AF_INET6;
sai6->sin6_port = htons(port);
sai6->sin6_scope_id = gIF_INDEX;
ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr);
} else {
/* IP address was set by the hostname (getaddrinfo). */
/* Override port: */
if (out->IPaddress.ss_family == AF_INET)
sai4->sin_port = htons(port);
else
sai6->sin6_port = htons(port);
ret = 1;
}
/* Check if address was converted successfully. */
if (ret <= 0)
return UPNP_E_INVALID_URL;
out->text.size = hostport_size;
out->text.buff = in;
if( last_dot != NULL && isdigit(*(last_dot+1)) ) { return (int)hostport_size;
/* Must be an IPv4 address. */ max = max;
af = AF_INET;
}
else {
/* Must be a host name. */
struct addrinfo hints, *res, *res0;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
ret = getaddrinfo(srvname, NULL, &hints, &res0);
if( ret == 0 ) {
for (res = res0; res; res = res->ai_next) {
if( res->ai_family == AF_INET ||
res->ai_family == AF_INET6 ) {
/* Found a valid IPv4 or IPv6 address. */
memcpy( &out->IPaddress, res->ai_addr,
res->ai_addrlen );
break;
}
}
freeaddrinfo(res0);
if( res == NULL ) {
/* Didn't find an AF_INET or AF_INET6 address. */
return UPNP_E_INVALID_URL;
}
}
else {
/* getaddrinfo failed. */
return UPNP_E_INVALID_URL;
}
}
}
/* Check if a port is specified. */
if( has_port == 1 ) {
/* Port is specified. */
srvport = c;
while( *c != '\0' && isdigit(*c) ) {
c++;
}
port = (unsigned short int)atoi(srvport);
if( port == 0 ) {
/* Bad port number. */
return UPNP_E_INVALID_URL;
}
}
else {
/* Port was not specified, use default port. */
port = 80;
}
/* The length of the host and port string can be calculated by */
/* subtracting pointers. */
hostport_size = (int)(c - workbuf);
/* Fill in the 'out' information. */
if( af == AF_INET ) {
sai4->sin_family = AF_INET;
sai4->sin_port = htons(port);
ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
}
else if( af == AF_INET6 ) {
sai6->sin6_family = AF_INET6;
sai6->sin6_port = htons(port);
sai6->sin6_scope_id = gIF_INDEX;
ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr);
} else {
/* IP address was set by the hostname (getaddrinfo). */
/* Override port: */
if( out->IPaddress.ss_family == AF_INET )
sai4->sin_port = htons(port);
else
sai6->sin6_port = htons(port);
ret = 1;
}
/* Check if address was converted successfully. */
if (ret <= 0) {
return UPNP_E_INVALID_URL;
}
out->text.size = hostport_size;
out->text.buff = in;
return hostport_size;
max = max;
} }
/*! /*!

View File

@@ -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 * sends the HTTP GET request, gets the response and parses the response.
* *
* Parameters: * If a proxy URL is defined then the connection is made there.
* 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: * \return integer
* Makes the HTTP GET message, connects to the peer, * \li \c UPNP_E_SUCCESS - On Success
* sends the HTTP GET request, gets the response and parses the * \li \c UPNP_E_INVALID_PARAM - Invalid Paramters
* response. * \li \c UPNP_E_OUTOF_MEMORY
* * \li \c UPNP_E_SOCKET_ERROR
* Return: int * \li \c UPNP_E_BAD_RESPONSE
* 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( int http_OpenHttpGet(
IN const char *url_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,
* Function: http_OpenHttpGetProxy * sends the HTTP GET request, gets the response and parses the response.
* *
* Parameters: * If a proxy URL is defined then the connection is made there.
* 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: * \return integer
* Makes the HTTP GET message, connects to the peer, * \li \c UPNP_E_SUCCESS - On Success
* sends the HTTP GET request, gets the response and parses the response. * \li \c UPNP_E_INVALID_PARAM - Invalid Paramters
* If a proxy URL is defined then the connection is made there. * \li \c UPNP_E_OUTOF_MEMORY
* * \li \c UPNP_E_SOCKET_ERROR
* Return: int * \li \c UPNP_E_BAD_RESPONSE
* UPNP_E_SUCCESS - On Success */
* UPNP_E_INVALID_PARAM - Invalid Paramters int http_OpenHttpGetProxy(
* UPNP_E_OUTOF_MEMORY /* [in] String as a URL. */
* UPNP_E_SOCKET_ERROR const char *url_str,
* UPNP_E_BAD_RESPONSE /* [in] String as a URL. */
************************************************************************/ const char *proxy_str,
int http_OpenHttpGetProxy(IN const char *url_str, /* [in,out] Pointer to buffer to store HTTP post handle. */
IN const char *proxy_str, void **Handle,
IN OUT void **Handle, /* [in,out] Type of content. */
IN OUT char **contentType, char **contentType,
OUT int *contentLength, /* [out] length of content. */
OUT int *httpStatus, int *contentLength,
IN int timeout); /* [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. */
... );
/************************************************************************ /************************************************************************

View File

@@ -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);

View File

@@ -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).

View File

@@ -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) {

View File

@@ -31,21 +31,19 @@
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;
static uuid_node_t saved_node; static uuid_node_t saved_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 );
/*
NT keeps time in FILETIME format which is 100ns ticks since
Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
+ 18 years and 5 leap days.
*/
time.QuadPart += ( unsigned __int64 )( 1000 * 1000 * 10 ) /* seconds */
* ( unsigned __int64 )( 60 * 60 * 24 ) /* days */
* ( unsigned __int64 )( 17 + 30 + 31 + 365 * 18 + 5 ); /* # of days */
*uuid_time = time.QuadPart;
GetSystemTimeAsFileTime((FILETIME *) & time);
/*
NT keeps time in FILETIME format which is 100ns ticks since
Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
+ 18 years and 5 leap days.
*/
time.QuadPart += (unsigned __int64)(1000 * 1000 * 10) /* seconds */
*(unsigned __int64)(60 * 60 * 24) /* days */
*(unsigned __int64)(17 + 30 + 31 + 365 * 18 + 5); /* # of days */
*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 = (uuid_time_t) (tp.tv_sec * 10000000 + tp.tv_usec * 10 +
*uuid_time = ( 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 {