UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
httpreadwrite.cpp File Reference

This file defines the functionality making use of the http. More...

#include <httpreadwrite.hpp>
#include <UPnPsdk/synclog.hpp>
#include <UPnPsdk/sockaddr.hpp>
#include <UpnpExtraHeaders.hpp>
#include <UpnpIntTypes.hpp>
#include <statcodes.hpp>
#include <upnpapi.hpp>
#include <webserver.hpp>
#include <umock/pupnp_sock.hpp>
#include <umock/pupnp_httprw.hpp>
#include <umock/stdio.hpp>
#include <umock/sys_socket.hpp>
#include <umock/winsock2.hpp>
#include <umock/sysinfo.hpp>
+ Include dependency graph for httpreadwrite.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{httpreadwrite.cpp}::http_connection_handle_t
 Handle for a connection. More...
 

Functions

tm * http_gmtime_r (const time_t *clock, tm *result)
 Portable gmtime_r for Microsoft Windows.
 
int http_FixUrl (uri_type *url, uri_type *fixed_url)
 Validates URL.
 
int http_FixStrUrl (const char *urlstr, size_t urlstrlen, uri_type *fixed_url)
 Parses URL and then validates URL.
 
SOCKET http_Connect (uri_type *destination_url, uri_type *url)
 Gets destination address from URL and then connects to the remote end.
 
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 buffer.
 
int http_SendMessage (SOCKINFO *info, int *TimeOut, const char *fmt,...)
 Sends a message to the destination based on the format parameter.
 
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)
 Initiates socket, connects to the remote host, sends a request and waits for the response from the remote end.
 
int http_Download (const char *url_str, int timeout_secs, char **document, size_t *doc_length, char *content_type)
 Download the document message and extract the document from the message.
 
int http_HttpGetProgress (void *Handle, size_t *length, size_t *total)
 Extracts information from the Handle to the HTTP get object.
 
int http_CancelHttpGet (void *Handle)
 Set the cancel flag of the HttpGet handle.
 
int http_OpenHttpConnection (const char *url_str, void **Handle, int timeout)
 Opens a connection to the server.
 
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().
 
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 should be indicated by a call to UpnpEndHttpRequest().
 
int http_EndHttpRequest (void *Handle, int timeout)
 Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest().
 
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().
 
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().
 
int http_CloseHttpConnection (void *Handle)
 Closes the connection created with UpnpOpenHttpConnection() and frees any memory associated with the connection.
 
int http_SendStatusResponse (SOCKINFO *info, int http_status_code, int request_major_version, int request_minor_version)
 Generate a response message for the status query and send the status response.
 
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.
 
void http_CalcResponseVersion (int request_major_vers, int request_minor_vers, int *response_major_vers, int *response_minor_vers)
 Calculate HTTP response versions based on the request versions.
 
int http_OpenHttpGetEx (const char *url_str, void **Handle, char **contentType, int *contentLength, int *httpStatus, int lowRange, int highRange, int timeout)
 Makes the HTTP GET message, connects to the peer, sends the HTTP GET request, gets the response and parses the response.
 
void get_sdk_info (char *info, size_t infoSize)
 Returns the server information for the operating system.
 
Scope restricted to file
int anonymous_namespace{httpreadwrite.cpp}::Check_Connect_And_Wait_Connection (const SOCKET a_sock, const int connect_res)
 Checks socket connection and wait if it is not connected.
 
int anonymous_namespace{httpreadwrite.cpp}::get_hoststr (const char *url_str, const char **hoststr, size_t *hostlen)
 Point to the hostname within a URL C-string.
 
void anonymous_namespace{httpreadwrite.cpp}::copy_msg_headers (LinkedList *msgHeaders, UpnpString *headers)
 Dummy function. It do nothing since years. Do we need it?
 
int anonymous_namespace{httpreadwrite.cpp}::MakeGenericMessage (http_method_t method, const char *url_str, membuffer *request, uri_type *url, int contentLength, const char *contentType, const UpnpString *headers)
 Make a generic message, what ever this mean.
 
int anonymous_namespace{httpreadwrite.cpp}::ReadResponseLineAndHeaders (SOCKINFO *info, http_parser_t *parser, int *timeout_secs, int *http_error_code)
 Parses already exiting data.
 
int anonymous_namespace{httpreadwrite.cpp}::MakeGetMessageEx (const char *url_str, membuffer *request, uri_type *url, SendInstruction *pRangeSpecifier)
 Make extended GetMessage.
 
static int private_connect (const SOCKET sockfd, const sockaddr *const serv_addr, const socklen_t addrlen)
 Initiate a connection on a socket.
 

Variables

constexpr size_t anonymous_namespace{httpreadwrite.cpp}::CHUNK_HEADER_SIZE {10}
 ???
 
constexpr size_t anonymous_namespace{httpreadwrite.cpp}::CHUNK_TAIL_SIZE {10}
 ???
 
constexpr time_t anonymous_namespace{httpreadwrite.cpp}::DEFAULT_TCP_CONNECT_TIMEOUT {5}
 Default TCP connection timeout.
 

Detailed Description

This file defines the functionality making use of the http.

It defines functions to receive messages, process messages, send messages.

Definition in file httpreadwrite.cpp.


Class Documentation

◆ anonymous_namespace{httpreadwrite.cpp}::http_connection_handle_t

struct anonymous_namespace{httpreadwrite.cpp}::http_connection_handle_t

Handle for a connection.

Definition at line 317 of file httpreadwrite.cpp.

+ Collaboration diagram for anonymous_namespace{httpreadwrite.cpp}::http_connection_handle_t:
Class Members
SOCKINFO sock_info
int contentLength
http_parser_t response
int requestStarted
int cancel

Function Documentation

◆ private_connect()

static int private_connect ( const SOCKET  sockfd,
const sockaddr *const  serv_addr,
const socklen_t  addrlen 
)
static

Initiate a connection on a socket.

Returns
On success: 0
On error: SOCKET_ERROR
Todo:
Return more detailed error codes, e.g. with 'getsockopt()' valopt == 111: ECONNREFUSED "Connection refused" if there is a remote host but no server service listening.
Parameters
[in]sockfdSocket file descriptor.
[in]serv_addrSocket address of a remote network node.
[in]addrlenSize of the socket address.

Definition at line 506 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_gmtime_r()

tm * http_gmtime_r ( const time_t *  clock,
tm *  result 
)

Portable gmtime_r for Microsoft Windows.

Definition at line 553 of file httpreadwrite.cpp.

+ Here is the caller graph for this function:

◆ http_FixUrl()

int http_FixUrl ( uri_type url,
uri_type fixed_url 
)

Validates URL.

Returns
  • UPNP_E_INVALID_URL
  • UPNP_E_SUCCESS
Parameters
[in]urlURL to be validated and fixed.
[out]fixed_urlURL after being fixed.

Definition at line 563 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_FixStrUrl()

int http_FixStrUrl ( const char *  urlstr,
size_t  urlstrlen,
uri_type fixed_url 
)

Parses URL and then validates URL.

Returns
  • UPNP_E_INVALID_URL
  • UPNP_E_SUCCESS
Parameters
[in]urlstrCharacter string as a URL.
[in]urlstrlenLength of the character string.
[out]fixed_urlFixed and corrected URL.

Definition at line 589 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_Connect()

SOCKET http_Connect ( uri_type destination_url,
uri_type url 
)

Gets destination address from URL and then connects to the remote end.

Returns
On success: Socket descriptor
On error:
  • UPNP_E_OUTOF_SOCKET
  • UPNP_E_SOCKET_CONNECT
Parameters
[in]destination_urlURL containing destination information.
[out]urlFixed and corrected URL.

Definition at line 599 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 buffer.

If an error is reported while parsing the data, the error code is passed in the http_error_code parameter.

Returns
On success: UPNP_E_SUCCESS
On error: UPNP_E_BAD_HTTPMSG
Parameters
[in]infoSocket information object.
[out]parserHTTP parser object.
[in]request_methodHTTP request method.
[in,out]timeout_secstime out.
[out]http_error_codeHTTP error code returned.

Definition at line 633 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_SendMessage()

int http_SendMessage ( SOCKINFO info,
int *  TimeOut,
const char *  fmt,
  ... 
)

Sends a message to the destination based on the format parameter.

format (fmt) types:

  • 'f': arg = "const char*" file name
  • 'b': arg1 = "const char*" mem_buffer, arg2 = "size_t" buffer length
  • 'I': arg = "SendInstruction*" send instruction
Note
Sending from file (fmt = "If") always needs an instruction tag before with at least SendInstruction.ReadSendSize set. Otherwise nothing is sent.
.ReadSendSize > 0: amount of bytes to send
.ReadSendSize = 0: nothing to send
.ReadSendSize < 0: send until end from data in file or until internal sendbuffer size.
For example:
   char *buf = "POST /xyz.cgi http/1.1\r\n\r\n";
   char *filename = "foo.dat";
   SendInstruction instruct;
   instruct.ReadSendSize = -1;
   int status = http_SendMessage(tcpsock, "Ibf",
       &instruct,              // arg pointer to send instruction
       buf, strlen(buf),       // args for memory buffer
       filename);              // arg for file
Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_FILE_READ_ERROR
  • UPNP_E_TIMEDOUT
  • UPNP_E_SOCKET_WRITE
  • UPNP_E_SOCKET_ERROR
Parameters
[in]infoSocket information object.
[in,out]TimeOutTime out value.
[in]fmtPattern format to take actions upon (like printf()).
[in]...Variable argument list (like printf()).

Definition at line 740 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_RequestAndResponse()

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 
)

Initiates socket, connects to the remote host, sends a request and waits for the response from the remote end.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_SOCKET_ERROR
  • UPNP_E_SOCKET_CONNECT
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_FILE_READ_ERROR
  • UPNP_E_TIMEDOUT
  • UPNP_E_SOCKET_WRITE
  • UPNP_E_BAD_HTTPMSG
Parameters
[in]destinationDestination URI object which contains remote IP address among other elements.
[in]requestRequest to be sent.
[in]request_lengthLength of the request.
[in]req_methodHTTP Request method.
[in]timeout_secstime out value.
[in]responseParser object to receive the repsonse.

Definition at line 975 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_Download()

int http_Download ( const char *  url_str,
int  timeout_secs,
char **  document,
size_t *  doc_length,
char *  content_type 
)

Download the document message and extract the document from the message.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_INVALID_URL
Parameters
[in]url_strString as a URL.
[in]timeout_secsTime out value.
[out]documentBuffer to store the document extracted from the donloaded message.
[out]doc_lengthLength of the extracted document.
[out]content_typeType of content.

Definition at line 1027 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_HttpGetProgress()

int http_HttpGetProgress ( void *  Handle,
size_t *  length,
size_t *  total 
)

Extracts information from the Handle to the HTTP get object.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_INVALID_PARAM
Parameters
[in]HandleHandle to the HTTP get object.
[out]lengthBuffer to get the read and parsed data.
[out]totalSize of tge buffer passed.

Definition at line 1143 of file httpreadwrite.cpp.

+ Here is the caller graph for this function:

◆ http_CancelHttpGet()

int http_CancelHttpGet ( void *  Handle)

Set the cancel flag of the HttpGet handle.

Returns
  • UPNP_E_SUCCESS - On Success
  • UPNP_E_INVALID_PARAM - Invalid Parameter
Parameters
[in]HandleHandle to HTTP get object.

Definition at line 1155 of file httpreadwrite.cpp.

+ Here is the caller graph for this function:

◆ http_OpenHttpConnection()

int http_OpenHttpConnection ( const char *  url_str,
void **  Handle,
int  timeout 
)

Opens a connection to the server.

The SDK allocates the memory for the handle.

Note
The calling application is responsible for freeing the memory allocated for the handle.
Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_INVALID_PARAM - Either url, or handle is not a valid pointer.
  • UPNP_E_INVALID_URL - The url is not a valid URL.
  • UPNP_E_OUTOF_MEMORY - Insufficient resources exist to download this file.
  • UPNP_E_SOCKET_ERROR - Error occured allocating a socket and resources or an error occurred binding a socket.
  • UPNP_E_SOCKET_WRITE - An error or timeout occurred writing to a socket.
  • UPNP_E_SOCKET_CONNECT - An error occurred connecting a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
Parameters
[in]url_strThe URL which contains the host, and the scheme to make the connection.
[in,out]HandleA pointer in which to store the handle for this connection. This handle is required for futher operations over this connection.
[in]timeoutThis argument isn't used anymore and only available for downstream compatibility. It can be set to any value.

Definition at line 1165 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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().

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 UpnpEndHttpRequest().
Returns
An integer representing one of the following
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - Either url, handle or contentType is not a valid pointer.
  • UPNP_E_INVALID_URL - The url is not a valid URL.
  • UPNP_E_OUTOF_MEMORY - Insufficient resources exist to download this file.
  • UPNP_E_SOCKET_ERROR - Error occured allocating a socket and resources or an error occurred binding a socket.
  • UPNP_E_SOCKET_WRITE - An error or timeout occurred writing to a socket.
  • UPNP_E_SOCKET_CONNECT - An error occurred connecting a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
Parameters
[in]methodThe method to use to make the request.
[in]url_strThe URL to use to make the request. The URL should use the same host and scheme used to create the connection.
[in]HandleThe handle to the connection.
[in]headersHeaders 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.
[in]contentTypeThe media type of content being sent. Can be NULL.
[in]contentLengthThe length of the content being sent, in bytes. Set to UPNP_USING_CHUNKED to use chunked encoding, or 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.
[in]timeoutThe 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.

Definition at line 1229 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 should be indicated by a call to UpnpEndHttpRequest().

Returns
An integer representing one of the following
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - Either handle, buf or size is not a valid pointer.
  • UPNP_E_SOCKET_WRITE - An error or timeout occurred writing to a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
Parameters
[in]HandleThe handle of the connection created by the call to UpnpOpenHttpConnection().
[in]bufThe buffer containing date to be written.
[in]sizeThe size, in bytes of buf.
[in]timeoutA 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.

Definition at line 1258 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_EndHttpRequest()

int http_EndHttpRequest ( void *  Handle,
int  timeout 
)

Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest().

Returns
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - handle is not a valid pointer.
  • UPNP_E_OUTOF_MEMORY - Insufficient resources exist.
  • UPNP_E_SOCKET_ERROR - Error occured on handling a socket.
  • UPNP_E_SOCKET_WRITE - An error or timeout occurred writing to a socket.
  • UPNP_E_SOCKET_CONNECT - An error occurred connecting a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
Parameters
[in]HandleThe handle to the connection.
[in]timeoutThe 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.

Definition at line 1302 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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().

Note
Memory for contentType is only valid until the next call to the HTTP API for the same connection.
Returns
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - Either handle, contentType, contentLength or httpStatus is not a valid pointer.
  • UPNP_E_INVALID_URL - The url is not a valid URL.
  • UPNP_E_OUTOF_MEMORY - Insufficient resources exist to download this file.
  • UPNP_E_NETWORK_ERROR - A network error occurred.
  • UPNP_E_SOCKET_WRITE - An error or timeout occurred writing to a socket.
  • UPNP_E_SOCKET_READ - An error or timeout occurred reading from a socket.
  • UPNP_E_SOCKET_BIND - An error occurred binding a socket.
  • UPNP_E_SOCKET_CONNECT - An error occurred connecting a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
  • UPNP_E_BAD_RESPONSE - A bad response was received from the remote server.
Parameters
[in]HandleThe handle of the connection created by the call to UpnpOpenHttpConnection().
[in]headersHeaders sent by the server for the response. If nullptr then the headers are not copied.
[out]contentTypeA buffer to store the media type of the item.
[out]contentLengthA pointer to store the length of the item.
[out]httpStatusThe status returned on receiving a response message.
[in]timeoutThe 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.

Definition at line 1319 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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().

Returns
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - Either handle, buf or size is not a valid pointer.
  • UPNP_E_BAD_RESPONSE - A bad response was received from the remote server.
  • UPNP_E_BAD_HTTPMSG - Either the request or response was in the incorrect format.
  • 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.

Parameters
[in]HandleThe handle of the connection created by the call to UpnpOpenHttpConnection().
[in,out]bufThe buffer to store the read item.
[in,out]sizeThe size of the buffer to be read.
[in]timeoutThe 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.

Definition at line 1374 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_CloseHttpConnection()

int http_CloseHttpConnection ( void *  Handle)

Closes the connection created with UpnpOpenHttpConnection() and frees any memory associated with the connection.

Returns
On success: UPNP_E_SUCCESS - The operation completed successfully.
On error:
  • UPNP_E_INVALID_PARAM - handle is not a valid pointer.
  • UPNP_E_SOCKET_READ - An error or timeout occurred reading from a socket.
  • UPNP_E_OUTOF_SOCKET - Too many sockets are currently allocated.
Parameters
[in]HandleThe handle of the connection to close, created by the call to UpnpOpenHttpPost().

Definition at line 1472 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_SendStatusResponse()

int http_SendStatusResponse ( SOCKINFO info,
int  http_status_code,
int  request_major_version,
int  request_minor_version 
)

Generate a response message for the status query and send the status response.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_SOCKET_WRITE
  • UPNP_E_TIMEDOUT
Parameters
[in]infoSocket information object.
[in]http_status_codeError code returned while making or sending the response message.
[in]request_major_versionRequest major version.
[in]request_minor_versionRequest minor version.

Definition at line 1483 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Format types:
  'B':  arg = int status_code        -- appends content-length, content-type
                                        and HTML body for given code.
  'b':  arg1 = const char* buf       -- appends content of the buffer
        arg2 = size_t buf_length        with this buffer size
  '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
Returns
On success: 0
On error:
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_INVALID_URL
Parameters
[in,out]bufBuffer with the contents of the message.
[in]http_major_versionHTTP major version.
[in]http_minor_versionHTTP minor version.
[in]fmtPattern format (like printf()).
[in]...Variable Format arguments (like printf()(.

Definition at line 1512 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_CalcResponseVersion()

void http_CalcResponseVersion ( int  request_major_vers,
int  request_minor_vers,
int *  response_major_vers,
int *  response_minor_vers 
)

Calculate HTTP response versions based on the request versions.

Parameters
[in]request_major_versRequest major version.
[in]request_minor_versRequest minor version.
[in]response_major_versResponse mojor version.
[in]response_minor_versResponse minor version.

Definition at line 1786 of file httpreadwrite.cpp.

+ Here is the caller graph for this function:

◆ http_OpenHttpGetEx()

int http_OpenHttpGetEx ( const char *  url_str,
void **  Handle,
char **  contentType,
int *  contentLength,
int *  httpStatus,
int  lowRange,
int  highRange,
int  timeout 
)

Makes the HTTP GET message, connects to the peer, sends the HTTP GET request, gets the response and parses the response.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_INVALID_PARAM
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_SOCKET_ERROR
  • UPNP_E_BAD_RESPONSE
Parameters
[in]url_strString as a URL.
[in,out]HandlePointer to buffer to store HTTP post handle.
[in,out]contentTypeType of content.
[out]contentLengthlength of content.
[out]httpStatusHTTP status returned on receiving a response message.
lowRange???
highRange???
[in]timeouttime out value.

Definition at line 1800 of file httpreadwrite.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_sdk_info()

void get_sdk_info ( char *  info,
size_t  infoSize 
)

Returns the server information for the operating system.

Parameters
[out]infoBuffer to store the operating system information.
[in]infoSizeSize of buffer.

Definition at line 1922 of file httpreadwrite.cpp.

+ Here is the caller graph for this function: