httpreadwrite.h
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef GENLIB_NET_HTTP_HTTPREADWRITE_H
#define GENLIB_NET_HTTP_HTTPREADWRITE_H
/*
* \file
*/
#include "config.h"
#include "httpparser.h"
#include "sock.h"
#include "upnputil.h"
#define HTTP_DEFAULT_TIMEOUT 30
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
struct tm *http_gmtime_r(const time_t *clock, struct tm *result);
#else
#define http_gmtime_r gmtime_r
#endif
int http_CancelHttpGet(/* IN */ void *Handle);
int http_FixUrl(
uri_type *url,
uri_type *fixed_url);
int http_FixStrUrl(
const char *urlstr,
size_t urlstrlen,
uri_type *fixed_url);
SOCKET http_Connect(
uri_type *destination_url,
uri_type *url);
/************************************************************************
* Function: http_RecvMessage
*
* Parameters:
* IN SOCKINFO *info; Socket information object
* OUT http_parser_t* parser; HTTP parser object
* IN http_method_t request_method; HTTP request method
* IN OUT int* timeout_secs; time out
* OUT int* http_error_code; HTTP error code returned
*
* Description:
* Get the data on the socket and take actions based on the read data
* to modify the parser objects buffer. If an error is reported while
* parsing the data, the error code is passed in the http_errr_code
* parameter
*
* Returns:
* UPNP_E_BAD_HTTPMSG
* UPNP_E_SUCCESS
************************************************************************/
int http_RecvMessage(SOCKINFO *info,
http_parser_t *parser,
http_method_t request_method,
int *timeout_secs,
int *http_error_code);
int http_SendMessage(
/* [in] Socket information object. */
SOCKINFO *info,
/* [in,out] Time out value. */
int *timeout_secs,
/* [in] Pattern format to take actions upon. */
const char *fmt,
/* [in] Variable parameter list. */
...);
/************************************************************************
* Function: http_RequestAndResponse
*
* Parameters:
* IN uri_type* destination; Destination URI object which contains
* remote IP address among other elements
* IN const char* request; Request to be sent
* IN size_t request_length; Length of the request
* IN http_method_t req_method; HTTP Request method
* IN int timeout_secs; time out value
* OUT http_parser_t* response; Parser object to receive the repsonse
*
* Description:
* Initiates socket, connects to the destination, sends a
* request and waits for the response from the remote end
*
* Returns:
* UPNP_E_SOCKET_ERROR
* UPNP_E_SOCKET_CONNECT
* Error Codes returned by http_SendMessage
* Error Codes returned by http_RecvMessage
************************************************************************/
int http_RequestAndResponse(uri_type *destination,
const char *request,
size_t request_length,
http_method_t req_method,
int timeout_secs,
http_parser_t *response);
/************************************************************************
* return codes:
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_TIMEDOUT
* UPNP_E_BAD_REQUEST
* UPNP_E_BAD_RESPONSE
* UPNP_E_INVALID_URL
* UPNP_E_SOCKET_READ
* UPNP_E_SOCKET_WRITE
************************************************************************/
/************************************************************************
* Function: http_Download
*
* Parameters:
* IN const char* url_str; String as a URL
* IN int timeout_secs; time out value
* OUT char** document; buffer to store the document extracted
* from the donloaded message.
* OUT size_t* doc_length; length of the extracted document
* OUT char* content_type; Type of content
*
* Description:
* Download the document message and extract the document
* from the message.
*
* Return: int
* UPNP_E_SUCCESS
* UPNP_E_INVALID_URL
************************************************************************/
int http_Download(const char *url,
int timeout_secs,
char **document,
size_t *doc_length,
char *content_type);
/************************************************************************
* Function: http_HttpGetProgress
*
* Parameters:
* IN void *Handle; Handle to the HTTP get object
* OUT size_t *length; Buffer to get the read and parsed data
* OUT size_t *total; Size of tge buffer passed
*
* Description:
* Extracts information from the Handle to the HTTP get object.
*
* Return: int
* UPNP_E_SUCCESS - On Sucess
* UPNP_E_INVALID_PARAM - Invalid Parameter
************************************************************************/
int http_HttpGetProgress(void *Handle, size_t *length, size_t *total);
UPNP_EXPORT_SPEC int http_OpenHttpConnection(
const char *url,
void **handle,
int timeout);
UPNP_EXPORT_SPEC int http_MakeHttpRequest(
/* ![in] The method to use to make the request. */
Upnp_HttpMethod method,
const char *url,
void *handle,
UpnpString *headers,
const char *contentType,
int contentLength,
int timeout);
UPNP_EXPORT_SPEC int http_WriteHttpRequest(
void *handle,
char *buf,
size_t *size,
int timeout);
UPNP_EXPORT_SPEC int http_EndHttpRequest(
void *handle,
int timeout);
UPNP_EXPORT_SPEC int http_GetHttpResponse(
void *handle,
UpnpString *headers,
char **contentType,
int *contentLength,
int *httpStatus,
int timeout);
UPNP_EXPORT_SPEC int http_ReadHttpResponse(
void *handle,
char *buf,
size_t *size,
int timeout);
UPNP_EXPORT_SPEC int http_CloseHttpConnection(
void *handle);
/************************************************************************
* Function: http_SendStatusResponse
*
* Parameters:
* IN SOCKINFO *info; Socket information object
* IN int http_status_code; error code returned while making
* or sending the response message
* IN int request_major_version; request major version
* IN int request_minor_version; request minor version
*
* Description:
* Generate a response message for the status query and send the
* status response.
*
* Return: int
* 0 -- success
* UPNP_E_OUTOF_MEMORY
* UPNP_E_SOCKET_WRITE
* UPNP_E_TIMEDOUT
************************************************************************/
int http_SendStatusResponse(SOCKINFO *info,
int http_status_code,
int request_major_version,
int request_minor_version);
int http_MakeMessage(
/* [in,out] Buffer with the contents of the message. */
membuffer *buf,
/* [in] HTTP major version. */
int http_major_version,
/* [in] HTTP minor version. */
int http_minor_version,
/* [in] Pattern format. */
const char *fmt,
/* [in] Format arguments. */
...);
/************************************************************************
* Function: http_CalcResponseVersion
*
* Parameters:
* IN int request_major_vers; Request major version
* IN int request_minor_vers; Request minor version
* OUT int* response_major_vers; Response mojor version
* OUT int* response_minor_vers; Response minor version
*
* Description:
* Calculate HTTP response versions based on the request versions.
*
* Return: void
************************************************************************/
void http_CalcResponseVersion(int request_major_vers,
int request_minor_vers,
int *response_major_vers,
int *response_minor_vers);
/************************************************************************
* Function: http_OpenHttpGetEx
*
* 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_OpenHttpGetEx(const char *url_str,
void **Handle,
char **contentType,
int *contentLength,
int *httpStatus,
int lowRange,
int highRange,
int timeout);
/************************************************************************
* Function: get_sdk_info
*
* Parameters:
* OUT char *info; buffer to store the operating system information
* IN size_t infoSize; size of buffer
*
* Description:
* Returns the server information for the operating system
*
* Return:
* UPNP_INLINE void
************************************************************************/
void get_sdk_info(char *info, size_t infoSize);
#ifdef __cplusplus
} /* #extern "C" */
#endif
#endif /* GENLIB_NET_HTTP_HTTPREADWRITE_H */
UPNP_EXPORT_SPEC
#define UPNP_EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition UpnpGlobal.h:105
SOCKET
int SOCKET
Definition UpnpInet.h:50
UpnpString
struct s_UpnpString UpnpString
Type of the string objects inside libupnp.
Definition UpnpString.h:33
httpparser.h
http_ReadHttpResponse
int http_ReadHttpResponse(void *Handle, char *buf, size_t *size, int timeout)
Reads the content of a response using a connection previously created by UpnpOpenHttpConnection.
Definition httpreadwrite.c:1492
http_OpenHttpConnection
int http_OpenHttpConnection(const char *url_str, void **Handle, int timeout)
Opens a connection to the server.
Definition httpreadwrite.c:1266
http_CloseHttpConnection
int http_CloseHttpConnection(void *Handle)
Closes the connection created with UpnpOpenHttpConnection and frees any memory associated with the co...
Definition httpreadwrite.c:1597
http_FixStrUrl
int http_FixStrUrl(const char *urlstr, size_t urlstrlen, uri_type *fixed_url)
Parses URL and then validates URL.
Definition httpreadwrite.c:276
http_SendMessage
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
Definition httpreadwrite.c:492
http_Connect
SOCKET http_Connect(uri_type *destination_url, uri_type *url)
Gets destination address from URL and then connects to the remote end.
Definition httpreadwrite.c:302
http_FixUrl
int http_FixUrl(uri_type *url, uri_type *fixed_url)
Validates URL.
Definition httpreadwrite.c:249
http_WriteHttpRequest
int http_WriteHttpRequest(void *Handle, char *buf, size_t *size, int timeout)
Writes the content of a HTTP request initiated by a UpnpMakeHttpRequest call. The end of the content ...
Definition httpreadwrite.c:1364
http_EndHttpRequest
int http_EndHttpRequest(void *Handle, int timeout)
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest.
Definition httpreadwrite.c:1410
http_GetHttpResponse
int http_GetHttpResponse(void *Handle, UpnpString *headers, char **contentType, int *contentLength, int *httpStatus, int timeout)
Gets the response from the server using a connection previously created by UpnpOpenHttpConnection.
Definition httpreadwrite.c:1429
http_MakeHttpRequest
int http_MakeHttpRequest(Upnp_HttpMethod method, const char *url_str, void *Handle, UpnpString *headers, const char *contentType, int contentLength, int timeout)
Makes a HTTP request using a connection previously created by UpnpOpenHttpConnection.
Definition httpreadwrite.c:1326
http_RecvMessage
int http_RecvMessage(SOCKINFO *info, http_parser_t *parser, http_method_t request_method, int *timeout_secs, int *http_error_code)
Get the data on the socket and take actions based on the read data to modify the parser objects buffe...
Definition httpreadwrite.c:364
http_MakeMessage
int http_MakeMessage(membuffer *buf, int http_major_version, int http_minor_version, const char *fmt,...)
Generate an HTTP message based on the format that is specified in the input parameters.
Definition httpreadwrite.c:1662
sock.h
SOCKINFO
Definition sock.h:60
URI
Represents a URI used in parse_uri and elsewhere.
Definition uri.h:134
http_parser_t
Definition httpparser.h:217
membuffer
Definition membuffer.h:58
upnputil.h