Refactor HTTP Client API

This commit is contained in:
Chandra Penke 2011-02-07 17:20:18 +05:30 committed by Marcelo Roberto Jimenez
parent ee9f83c3d5
commit 8eec345e49
7 changed files with 967 additions and 721 deletions

View File

@ -2,6 +2,38 @@
Version 1.8.0
*******************************************************************************
2011-02-07 Chandra Penke <chandrapenke(at)mcntech.com>
Refactor HTTP Client API to be more generic.
The following features are added:
- Support for persistent HTTP connections (reusing HTTP
connections). Tthis is still a work in progress and relies on
applications to interpret the 'Connection' header
appropriately.
- Support for specifying request headers when making
requests. Useful for interacting with web services that require
custom headers.
- Support for retrieving response headers (this is a API only
change, some more work needs to be done to implement the actual
functionality. Specifically copy_msg_headers in httpreadwrite.c
needs to be implemented)
- Common API for all HTTP methods.
- Support for PUT, and DELETE methods.
The following methods are introduced to the public HTTP Client API
UpnpOpenHttpConnection, UpnpCloseHttpConnection, UpnpMakeHttpRequest,
UpnpWriteHttpRequest, UpnpEndHttpRequest, UpnpGetHttpResponse,
UpnpReadHttpResponse.
Removed a lot of duplicate code in httpreadwrite.c
2011-01-17 Chandra Penke <chandrapenke(at)mcntech.com>
Include upnpconfig.h in FileInfo.h to automatically include large

View File

@ -1766,6 +1766,19 @@ EXPORT_SPEC int UpnpUnSubscribeAsync(
* @{
*/
/*!
* \brief Different HTTP methods.
*/
enum Upnp_HttpMethod_e {
UPNP_HTTPMETHOD_PUT = 0,
UPNP_HTTPMETHOD_DELETE = 1,
UPNP_HTTPMETHOD_GET = 2,
UPNP_HTTPMETHOD_HEAD = 3,
UPNP_HTTPMETHOD_POST = 4
};
typedef enum Upnp_HttpMethod_e Upnp_HttpMethod;
/*!
* \brief Downloads a file specified in a URL.
*
@ -1807,10 +1820,12 @@ EXPORT_SPEC int UpnpDownloadUrlItem(
* The SDK allocates the memory for \b handle and \b contentType, the
* application is responsible for freeing this memory.
*
* \note Memory for \b contentType is freed when freeing the memory
* for handle.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, \b handle,
* \b contentType, \b contentLength or \b httpStatus
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
@ -1851,10 +1866,12 @@ EXPORT_SPEC int UpnpOpenHttpGet(
* The SDK allocates the memory for \b handle and \b contentType, the
* application is responsible for freeing this memory.
*
* \note Memory for \b contentType is freed when freeing the memory
* for handle.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, \b handle,
* \b contentType, \b contentLength or \b httpStatus
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
@ -2016,7 +2033,7 @@ EXPORT_SPEC int UpnpCloseHttpGet(
* and sends the POST request to the server if the connection to the server
* succeeds.
*
* The SDK allocates the memory for \b handle and \b contentType, the
* The SDK allocates the memory for \b handle, the
* application is responsible for freeing this memory.
*
* \return An integer representing one of the following:
@ -2042,7 +2059,7 @@ EXPORT_SPEC int UpnpOpenHttpPost(
/*! [in,out] A pointer in which to store the handle for this connection. This
* handle is required for futher operations over this connection. */
void **handle,
/*! [in] A buffer to store the media type of content being sent. */
/*! [in] A buffer to store the media type of content being sent. Can be NULL. */
const char *contentType,
/*! [in] The length of the content, in bytes, being posted. */
int contentLength,
@ -2101,6 +2118,234 @@ EXPORT_SPEC int UpnpCloseHttpPost(
* value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Opens a connection to the server.
*
* The SDK allocates the memory for \b handle, the
* application is responsible for freeing this memory.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, or \b handle
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int UpnpOpenHttpConnection(
/*! [in] The URL which contains the host, and the scheme to make the connection. */
const char *url,
/*! [in,out] A pointer in which to store the handle for this connection. This
* handle is required for futher operations over this connection. */
void **handle,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Makes a HTTP request using a connection previously created by
* \b UpnpOpenHttpConnection.
*
* \note Trying to make another request while a request is already being processed
* results in undefined behavior. It's up to the user to end a previous
* request by calling \b UpnpEndHttpRequest.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, \b handle
* or \b contentType is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int UpnpMakeHttpRequest(
/* ![in] The method to use to make the request. */
Upnp_HttpMethod method,
/*! [in] The URL to use to make the request. The URL should use the same
* scheme used to create the connection, but the host can be different
* if the request is being proxied. */
const char *url,
/*! [in] The handle to the connection. */
void *handle,
/*! [in] Headers to be used for the request. Each header should be terminated by a CRLF as specified
* in the HTTP specification. If NULL then the default headers will be used. */
UpnpString *headers,
/*! [in] The media type of content being sent. Can be NULL. */
const char *contentType,
/*! [in] The length of the content being sent, in bytes. Set to \b UPNP_USING_CHUNKED to use
* chunked encoding, or \b UPNP_UNTIL_CLOSE to avoid specifying the content length to the server.
* In this case the request is considered unfinished until the connection is closed. */
int contentLength,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Writes the content of a HTTP request initiated by a \b UpnpMakeHttpRequest call.
* The end of the content should be indicated by a call to \b UpnpEndHttpRequest
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle, \b buf
* or \b size is not a valid pointer.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int UpnpWriteHttpRequest(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in] The buffer containing date to be written. */
char *buf,
/*! [in] The size, in bytes of \b buf. */
size_t *size,
/*! [in] A timeout value sent with the request during which a response is
* expected from the server, failing which, an error is reported. If
* value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Indicates the end of a HTTP request previously made by
* \b UpnpMakeHttpRequest.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: \b handle is not a valid pointer.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int UpnpEndHttpRequest(
/*! [in] The handle to the connection. */
void *handle,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Gets the response from the server using a connection previously created
* by \b UpnpOpenHttpConnection
*
* \note Memory for \b contentType is only valid until the next call to the HTTP API
* for the same connection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle,
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_NETWORK_ERROR: A network error occurred.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_READ: An error or timeout occurred reading
* from a socket.
* \li \c UPNP_E_SOCKET_BIND: An error occurred binding a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
* \li \c UPNP_E_BAD_RESPONSE: A bad response was received from the
* remote server.
*/
EXPORT_SPEC int UpnpGetHttpResponse(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in] Headers sent by the server for the response. If NULL then the
* headers are not copied. */
UpnpString *headers,
/*! [out] A buffer to store the media type of the item. */
char **contentType,
/*! [out] A pointer to store the length of the item. */
int *contentLength,
/*! [out] The status returned on receiving a response message. */
int *httpStatus,
/*! [in] The time out value sent with the request during which a response
* is expected from the server, failing which, an error is reported
* back to the user. If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Reads the content of a response using a connection previously created
* by \b UpnpOpenHttpConnection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle, \b buf
* or \b size is not a valid pointer.
* \li \c UPNP_E_BAD_RESPONSE: A bad response was received from the
* remote server.
* \li \c UPNP_E_BAD_HTTPMSG: Either the request or response was in
* the incorrect format.
* \li \c UPNP_E_CANCELED: another thread called UpnpCancelHttpGet.
*
* Note: In case of return values, the status code parameter of the passed
* in handle value may provide additional information on the return
* value.
*/
EXPORT_SPEC int UpnpReadHttpResponse(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in,out] The buffer to store the read item. */
char *buf,
/*! [in,out] The size of the buffer to be read. */
size_t *size,
/*! [in] The time out value sent with the request during which a response is
* expected from the server, failing which, an error is reported back to
* the user. If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Closes the connection created with \b UpnpOpenHttpConnection
* and frees any memory associated with the connection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: \b handle, or is not a valid pointer.
* \li \c UPNP_E_SOCKET_READ: An error or timeout occurred reading
* from a socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int UpnpCloseHttpConnection(
/*! [in] The handle of the connection to close, created by the call to
* \b UpnpOpenHttpPost. */
void *handle);
/*!
* \brief Downloads an XML document specified in a URL.
*

View File

@ -2728,8 +2728,12 @@ int UpnpOpenHttpPost(
int contentLength,
int timeout)
{
return http_OpenHttpPost(
url, handle, contentType, contentLength, timeout);
int status = http_OpenHttpConnection(url, handle, timeout);
if (status == UPNP_E_SUCCESS) {
return http_MakeHttpRequest(HTTPMETHOD_POST, url, handle, NULL, contentType,
contentLength, timeout);
}
return status;
}
@ -2739,7 +2743,7 @@ int UpnpWriteHttpPost(
size_t *size,
int timeout)
{
return http_WriteHttpPost(handle, buf, size, timeout);
return http_WriteHttpRequest(handle, buf, size, timeout);
}
@ -2748,35 +2752,56 @@ int UpnpCloseHttpPost(
int *httpStatus,
int timeout)
{
return http_CloseHttpPost(handle, httpStatus, timeout);
}
int status = http_EndHttpRequest(handle, timeout);
if (status == UPNP_E_SUCCESS) {
status = http_GetHttpResponse(handle, NULL, NULL, NULL, httpStatus, timeout);
}
status = http_CloseHttpConnection(handle);
return status;}
int UpnpOpenHttpGet(
const char *url_str,
void **Handle,
const char *url,
void **handle,
char **contentType,
int *contentLength,
int *httpStatus,
int timeout)
{
return http_OpenHttpGet(
url_str, Handle, contentType, contentLength, httpStatus, timeout);
int status = UpnpOpenHttpConnection(url, handle, timeout);
if (status == UPNP_E_SUCCESS) {
status = UpnpMakeHttpRequest(HTTPMETHOD_GET, url, *handle, NULL, NULL, 0, timeout);
}
if (status == UPNP_E_SUCCESS) {
status = UpnpEndHttpRequest(*handle, timeout);
}
if (status == UPNP_E_SUCCESS) {
status = UpnpGetHttpResponse(*handle, NULL, contentType, contentLength, httpStatus, timeout);
}
return status;
}
int UpnpOpenHttpGetProxy(
const char *url_str,
const char *url,
const char *proxy_str,
void **Handle,
void **handle,
char **contentType,
int *contentLength,
int *httpStatus,
int timeout)
{
return http_OpenHttpGetProxy(
url_str, proxy_str, Handle, contentType, contentLength,
httpStatus, timeout);
int status = UpnpOpenHttpConnection(proxy_str, handle, timeout);
if (status == UPNP_E_SUCCESS) {
status = UpnpMakeHttpRequest(HTTPMETHOD_GET, url, *handle, NULL, NULL, 0, timeout);
}
if (status == UPNP_E_SUCCESS) {
status = UpnpEndHttpRequest(*handle, timeout);
}
if (status == UPNP_E_SUCCESS) {
status = UpnpGetHttpResponse(*handle, NULL, contentType, contentLength, httpStatus, timeout);
}
return status;
}
@ -2804,13 +2829,13 @@ int UpnpCancelHttpGet(void *Handle)
int UpnpCloseHttpGet(void *Handle)
{
return http_CloseHttpGet(Handle);
return UpnpCloseHttpConnection(Handle);
}
int UpnpReadHttpGet(void *Handle, char *buf, size_t *size, int timeout)
{
return http_ReadHttpGet(Handle, buf, size, timeout);
return http_ReadHttpResponse(Handle, buf, size, timeout);
}
@ -2820,6 +2845,57 @@ int UpnpHttpGetProgress(void *Handle, size_t *length, size_t *total)
}
int UpnpOpenHttpConnection(const char *url,
void **handle, int timeout)
{
return http_OpenHttpConnection(url, handle, timeout);
}
int UpnpMakeHttpRequest(Upnp_HttpMethod method, const char *url,
void *handle, UpnpString *headers,
const char *contentType, int contentLength,
int timeout)
{
return http_MakeHttpRequest(method, url, handle, headers, contentType,
contentLength, timeout);
}
int UpnpWriteHttpRequest(void *handle, char *buf,
size_t *size, int timeout)
{
return http_WriteHttpRequest(handle, buf, size, timeout);
}
int UpnpEndHttpRequest(void *handle, int timeout)
{
return http_EndHttpRequest(handle, timeout);
}
int UpnpGetHttpResponse(void *handle, UpnpString *headers,
char **contentType, int *contentLength, int *httpStatus,
int timeout)
{
return http_GetHttpResponse(handle, headers, contentType, contentLength,
httpStatus, timeout);
}
int UpnpReadHttpResponse(void *handle, char *buf,
size_t *size, int timeout)
{
return http_ReadHttpResponse(handle, buf, size, timeout);
}
int UpnpCloseHttpConnection(void *handle)
{
return http_CloseHttpConnection(handle);
}
int UpnpDownloadUrlItem(const char *url, char **outBuf, char *contentType)
{
int ret_code;

View File

@ -54,8 +54,9 @@
/* entity positions */
#define NUM_HTTP_METHODS 9
#define NUM_HTTP_METHODS 11
static str_int_entry Http_Method_Table[NUM_HTTP_METHODS] = {
{"DELETE", HTTPMETHOD_DELETE},
{"GET", HTTPMETHOD_GET},
{"HEAD", HTTPMETHOD_HEAD},
{"M-POST", HTTPMETHOD_MPOST},
@ -65,6 +66,7 @@ static str_int_entry Http_Method_Table[NUM_HTTP_METHODS] = {
{"SUBSCRIBE", HTTPMETHOD_SUBSCRIBE},
{"UNSUBSCRIBE", HTTPMETHOD_UNSUBSCRIBE},
{"POST", SOAPMETHOD_POST},
{"PUT", HTTPMETHOD_PUT}
};
#define NUM_HTTP_HEADER_NAMES 33
@ -1450,7 +1452,8 @@ parse_status_t parser_parse_headers(INOUT http_parser_t *parser)
if (tok_type == TT_CRLF) {
/* end of headers */
if ((parser->msg.is_request)
&& (parser->msg.method == HTTPMETHOD_POST)) {
&& (parser->msg.method == HTTPMETHOD_POST ||
parser->msg.method == HTTPMETHOD_PUT)) {
parser->position = POS_COMPLETE; /*post entity parsing */
/*is handled separately */
return PARSE_SUCCESS;

File diff suppressed because it is too large Load Diff

View File

@ -85,16 +85,20 @@ typedef enum
/* end of private section. */
/* method in a HTTP request. */
/* method in a HTTP request.
* IMPORTANT: The enum values of the standard HTTP method should match
* those of Upnp_HttpMethod enum defined in upnp.h */
typedef enum
{
HTTPMETHOD_POST,
HTTPMETHOD_PUT = 0,
HTTPMETHOD_DELETE = 1,
HTTPMETHOD_GET = 2,
HTTPMETHOD_HEAD = 3,
HTTPMETHOD_POST = 4,
HTTPMETHOD_MPOST,
HTTPMETHOD_SUBSCRIBE,
HTTPMETHOD_UNSUBSCRIBE,
HTTPMETHOD_NOTIFY,
HTTPMETHOD_GET,
HTTPMETHOD_HEAD,
HTTPMETHOD_MSEARCH,
HTTPMETHOD_UNKNOWN,
SOAPMETHOD_POST,

View File

@ -222,111 +222,6 @@ int http_Download(
OUT char* content_type );
/************************************************************************
* Function: http_WriteHttpPost
*
* Parameters:
* IN void *Handle: Handle to the http post object
* IN char *buf: Buffer to send to peer, if format used
* is not UPNP_USING_CHUNKED,
* IN size_t *size: Size of the data to be sent.
* IN int timeout: time out value
*
* Description:
* Formats data if format used is UPNP_USING_CHUNKED.
* Writes data on the socket connected to the peer.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
* -1 - On Socket Error.
************************************************************************/
int http_WriteHttpPost(IN void *Handle,
IN char *buf,
IN size_t *size,
IN int timeout);
/************************************************************************
* Function: http_CloseHttpPost
*
* Parameters:
* IN void *Handle; Handle to the http post object
* IN OUT int *httpStatus; HTTP status returned on receiving a
* response message
* IN int timeout; time out value
*
* Description:
* Sends remaining data if using UPNP_USING_CHUNKED
* format. Receives any more messages. Destroys socket and any socket
* associated memory. Frees handle associated with the HTTP POST msg.
*
* Return: int
* UPNP_E_SUCCESS - On success
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_CloseHttpPost(IN void *Handle,
IN OUT int *httpStatus,
IN int timeout);
/************************************************************************
* Function: http_OpenHttpPost
*
* Parameters:
* IN const char *url_str; String as a URL
* IN OUT void **Handle; Pointer to buffer to store HTTP
* post handle
* IN const char *contentType; Type of content
* IN int contentLength; length of content
* IN int timeout; time out value
*
* Description:
* Makes the HTTP POST message, connects to the peer,
* sends the HTTP POST request. Adds the post handle to buffer of
* such handles
*
* Return : int;
* UPNP_E_SUCCESS - On success
* UPNP_E_INVALID_PARAM - Invalid Parameter
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_ERROR
* UPNP_E_SOCKET_CONNECT
************************************************************************/
int http_OpenHttpPost(IN const char *url_str,
IN OUT void **Handle,
IN const char *contentType,
IN int contentLength,
IN int timeout);
/************************************************************************
* Function: http_ReadHttpGet
*
* Parameters:
* IN void *Handle; Handle to the HTTP get object
* IN OUT char *buf; Buffer to get the read and parsed data
* IN OUT size_t *size; Size of the buffer passed
* IN int timeout; time out value
*
* Description:
* Parses already existing data, then gets new data.
* Parses and extracts information from the new data.
*
* Return: int
* UPNP_E_SUCCESS - On success
* UPNP_E_INVALID_PARAM - Invalid Parameter
* UPNP_E_BAD_RESPONSE
* UPNP_E_BAD_HTTPMSG
* UPNP_E_CANCELED
************************************************************************/
int http_ReadHttpGet(
IN void *Handle,
IN OUT char *buf,
IN OUT size_t *size,
IN int timeout);
/************************************************************************
* Function: http_HttpGetProgress
*
@ -347,79 +242,242 @@ int http_HttpGetProgress(
OUT size_t *length,
OUT size_t *total);
/************************************************************************
* Function: http_CloseHttpGet
*
* Parameters:
* IN void *Handle; Handle to HTTP get object
*
* Description:
* Clears the handle allocated for the HTTP GET operation
* Clears socket states and memory allocated for socket operations.
*
* Return: int
* UPNP_E_SUCCESS - On Success
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_CloseHttpGet(IN void *Handle);
/*!
* \brief Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the response.
* \brief Opens a connection to the server.
*
* If a proxy URL is defined then the connection is made there.
* The SDK allocates the memory for \b handle, the
* application is responsible for freeing this memory.
*
* \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
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, or \b handle
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
int http_OpenHttpGet(
/* [in] String as a URL. */
const char *url_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. */
EXPORT_SPEC int http_OpenHttpConnection(
/*! [in] The URL which contains the host, and the scheme to make the connection. */
const char *url,
/*! [in,out] A pointer in which to store the handle for this connection. This
* handle is required for futher operations over this connection. */
void **handle,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Makes the HTTP GET message, connects to the peer,
* sends the HTTP GET request, gets the response and parses the response.
* \brief Makes a HTTP request using a connection previously created by
* \b UpnpOpenHttpConnection.
*
* If a proxy URL is defined then the connection is made there.
* \note Trying to make another request while a request is already being processed
* results in undefined behavior. It's up to the user to end a previous
* request by calling \b UpnpEndHttpRequest.
*
* \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
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b url, \b handle
* or \b contentType is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
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. */
EXPORT_SPEC int http_MakeHttpRequest(
/* ![in] The method to use to make the request. */
Upnp_HttpMethod method,
/*! [in] The URL to use to make the request. The URL should use the same
* host and scheme used to create the connection. */
const char *url,
/*! [in] The handle to the connection. */
void *handle,
/*! [in] Headers to be used for the request. Each header should be terminated by a CRLF as specified
* in the HTTP specification. If NULL then the default headers will be used. */
UpnpString *headers,
/*! [in] The media type of content being sent. Can be NULL. */
const char *contentType,
/*! [in] The length of the content being sent, in bytes. Set to \b UPNP_USING_CHUNKED to use
* chunked encoding, or \b UPNP_UNTIL_CLOSE to avoid specifying the content length to the server.
* In this case the request is considered unfinished until the connection is closed. */
int contentLength,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Writes the content of a HTTP request initiated by a \b UpnpMakeHttpRequest call.
* The end of the content should be indicated by a call to \b UpnpEndHttpRequest
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle, \b buf
* or \b size is not a valid pointer.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int http_WriteHttpRequest(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in] The buffer containing date to be written. */
char *buf,
/*! [in] The size, in bytes of \b buf. */
size_t *size,
/*! [in] A timeout value sent with the request during which a response is
* expected from the server, failing which, an error is reported. If
* value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Indicates the end of a HTTP request previously made by
* \b UpnpMakeHttpRequest.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: \b handle is not a valid pointer.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_SOCKET_ERROR: Error occured allocating a socket and
* resources or an error occurred binding a socket.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int http_EndHttpRequest(
/*! [in] The handle to the connection. */
void *handle,
/*! [in] The time out value sent with the request during which a response
* is expected from the receiver, failing which, an error is reported.
* If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Gets the response from the server using a connection previously created
* by \b UpnpOpenHttpConnection
*
* \note Memory for \b contentType is only valid until the next call to the HTTP API
* for the same connection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle,
* \b contentType, \b contentLength or \b httpStatus
* is not a valid pointer.
* \li \c UPNP_E_INVALID_URL: The \b url is not a valid
* URL.
* \li \c UPNP_E_OUTOF_MEMORY: Insufficient resources exist to
* download this file.
* \li \c UPNP_E_NETWORK_ERROR: A network error occurred.
* \li \c UPNP_E_SOCKET_WRITE: An error or timeout occurred writing
* to a socket.
* \li \c UPNP_E_SOCKET_READ: An error or timeout occurred reading
* from a socket.
* \li \c UPNP_E_SOCKET_BIND: An error occurred binding a socket.
* \li \c UPNP_E_SOCKET_CONNECT: An error occurred connecting a
* socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
* \li \c UPNP_E_BAD_RESPONSE: A bad response was received from the
* remote server.
*/
EXPORT_SPEC int http_GetHttpResponse(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in] Headers sent by the server for the response. If NULL then the
* headers are not copied. */
UpnpString *headers,
/*! [out] A buffer to store the media type of the item. */
char **contentType,
/*! [out] A pointer to store the length of the item. */
int *contentLength,
/*! [out] The status returned on receiving a response message. */
int *httpStatus,
/*! [in] The time out value sent with the request during which a response
* is expected from the server, failing which, an error is reported
* back to the user. If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Reads the content of a response using a connection previously created
* by \b UpnpOpenHttpConnection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: Either \b handle, \b buf
* or \b size is not a valid pointer.
* \li \c UPNP_E_BAD_RESPONSE: A bad response was received from the
* remote server.
* \li \c UPNP_E_BAD_HTTPMSG: Either the request or response was in
* the incorrect format.
* \li \c UPNP_E_CANCELED: another thread called UpnpCancelHttpGet.
*
* Note: In case of return values, the status code parameter of the passed
* in handle value may provide additional information on the return
* value.
*/
EXPORT_SPEC int http_ReadHttpResponse(
/*! [in] The handle of the connection created by the call to
* \b UpnpOpenHttpConnection. */
void *handle,
/*! [in,out] The buffer to store the read item. */
char *buf,
/*! [in,out] The size of the buffer to be read. */
size_t *size,
/*! [in] The time out value sent with the request during which a response is
* expected from the server, failing which, an error is reported back to
* the user. If value is negative, timeout is infinite. */
int timeout);
/*!
* \brief Closes the connection created with \b UpnpOpenHttpConnection
* and frees any memory associated with the connection.
*
* \return An integer representing one of the following:
* \li \c UPNP_E_SUCCESS: The operation completed successfully.
* \li \c UPNP_E_INVALID_PARAM: \b handle, or is not a valid pointer.
* \li \c UPNP_E_SOCKET_READ: An error or timeout occurred reading
* from a socket.
* \li \c UPNP_E_OUTOF_SOCKET: Too many sockets are currently
* allocated.
*/
EXPORT_SPEC int http_CloseHttpConnection(
/*! [in] The handle of the connection to close, created by the call to
* \b UpnpOpenHttpPost. */
void *handle);
/************************************************************************
* Function: http_SendStatusResponse
*