Performs HTTP read and write messages. More...
Go to the source code of this file.
Macros | |
#define | HTTP_DEFAULT_TIMEOUT 30 |
Functions | |
tm * | http_gmtime_r (const time_t *clock, tm *result) |
Portable gmtime_r for Microsoft Windows. | |
int | http_CancelHttpGet (void *Handle) |
Set the cancel flag of the HttpGet handle. | |
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_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. | |
Performs HTTP read and write messages.
Definition in file httpreadwrite.hpp.
#define HTTP_DEFAULT_TIMEOUT 30 |
timeout in secs.
Definition at line 48 of file httpreadwrite.hpp.
tm * http_gmtime_r | ( | const time_t * | clock, |
tm * | result | ||
) |
Portable gmtime_r for Microsoft Windows.
Definition at line 553 of file httpreadwrite.cpp.
int http_CancelHttpGet | ( | void * | Handle | ) |
Set the cancel flag of the HttpGet handle.
[in] | Handle | Handle to HTTP get object. |
Definition at line 1155 of file httpreadwrite.cpp.
Validates URL.
[in] | url | URL to be validated and fixed. |
[out] | fixed_url | URL after being fixed. |
Definition at line 563 of file httpreadwrite.cpp.
int http_FixStrUrl | ( | const char * | urlstr, |
size_t | urlstrlen, | ||
uri_type * | fixed_url | ||
) |
Parses URL and then validates URL.
[in] | urlstr | Character string as a URL. |
[in] | urlstrlen | Length of the character string. |
[out] | fixed_url | Fixed and corrected URL. |
Definition at line 589 of file httpreadwrite.cpp.
Gets destination address from URL and then connects to the remote end.
[in] | destination_url | URL containing destination information. |
[out] | url | Fixed and corrected URL. |
Definition at line 599 of file httpreadwrite.cpp.
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.
[in] | info | Socket information object. |
[out] | parser | HTTP parser object. |
[in] | request_method | HTTP request method. |
[in,out] | timeout_secs | time out. |
[out] | http_error_code | HTTP error code returned. |
Definition at line 633 of file httpreadwrite.cpp.
int http_SendMessage | ( | SOCKINFO * | info, |
int * | TimeOut, | ||
const char * | fmt, | ||
... | |||
) |
Sends a message to the destination based on the format parameter.
format (fmt) types:
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
[in] | info | Socket information object. |
[in,out] | TimeOut | Time out value. |
[in] | fmt | Pattern format to take actions upon (like printf()). |
[in] | ... | Variable argument list (like printf()). |
Definition at line 740 of file httpreadwrite.cpp.
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.
[in] | destination | Destination URI object which contains remote IP address among other elements. |
[in] | request | Request to be sent. |
[in] | request_length | Length of the request. |
[in] | req_method | HTTP Request method. |
[in] | timeout_secs | time out value. |
[in] | response | Parser object to receive the repsonse. |
Definition at line 975 of file httpreadwrite.cpp.
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.
[in] | url_str | String as a URL. |
[in] | timeout_secs | Time out value. |
[out] | document | Buffer to store the document extracted from the donloaded message. |
[out] | doc_length | Length of the extracted document. |
[out] | content_type | Type of content. |
Definition at line 1027 of file httpreadwrite.cpp.
int http_HttpGetProgress | ( | void * | Handle, |
size_t * | length, | ||
size_t * | total | ||
) |
Extracts information from the Handle to the HTTP get object.
[in] | Handle | Handle to the HTTP get object. |
[out] | length | Buffer to get the read and parsed data. |
[out] | total | Size of tge buffer passed. |
Definition at line 1143 of file httpreadwrite.cpp.
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.
[in] | url_str | The URL which contains the host, and the scheme to make the connection. |
[in,out] | Handle | A pointer in which to store the handle for this connection. This handle is required for futher operations over this connection. |
[in] | timeout | This 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.
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().
[in] | method | The method to use to make the request. |
[in] | url_str | The URL to use to make the request. The URL should use the same host and scheme used to create the connection. |
[in] | Handle | The handle to the connection. |
[in] | headers | 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. |
[in] | contentType | The media type of content being sent. Can be NULL. |
[in] | contentLength | The 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] | timeout | 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. |
Definition at line 1229 of file httpreadwrite.cpp.
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().
[in] | Handle | The handle of the connection created by the call to UpnpOpenHttpConnection(). |
[in] | buf | The buffer containing date to be written. |
[in] | size | The size, in bytes of buf. |
[in] | timeout | 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. |
Definition at line 1258 of file httpreadwrite.cpp.
int http_EndHttpRequest | ( | void * | Handle, |
int | timeout | ||
) |
Indicates the end of a HTTP request previously made by UpnpMakeHttpRequest().
[in] | Handle | The handle to the connection. |
[in] | timeout | 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. |
Definition at line 1302 of file httpreadwrite.cpp.
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().
[in] | Handle | The handle of the connection created by the call to UpnpOpenHttpConnection(). |
[in] | headers | Headers sent by the server for the response. If nullptr then the headers are not copied. |
[out] | contentType | A buffer to store the media type of the item. |
[out] | contentLength | A pointer to store the length of the item. |
[out] | httpStatus | The status returned on receiving a response message. |
[in] | timeout | 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. |
Definition at line 1319 of file httpreadwrite.cpp.
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().
Note: In case of return values, the status code parameter of the passed in handle value may provide additional information on the return value.
[in] | Handle | The handle of the connection created by the call to UpnpOpenHttpConnection(). |
[in,out] | buf | The buffer to store the read item. |
[in,out] | size | The size of the buffer to be read. |
[in] | timeout | 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. |
Definition at line 1374 of file httpreadwrite.cpp.
int http_CloseHttpConnection | ( | void * | Handle | ) |
Closes the connection created with UpnpOpenHttpConnection() and frees any memory associated with the connection.
[in] | Handle | The handle of the connection to close, created by the call to UpnpOpenHttpPost(). |
Definition at line 1472 of file httpreadwrite.cpp.
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.
[in] | info | Socket information object. |
[in] | http_status_code | Error code returned while making or sending the response message. |
[in] | request_major_version | Request major version. |
[in] | request_minor_version | Request minor version. |
Definition at line 1483 of file httpreadwrite.cpp.
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
[in,out] | buf | Buffer with the contents of the message. |
[in] | http_major_version | HTTP major version. |
[in] | http_minor_version | HTTP minor version. |
[in] | fmt | Pattern format (like printf()). |
[in] | ... | Variable Format arguments (like printf()(. |
Definition at line 1512 of file httpreadwrite.cpp.
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.
[in] | request_major_vers | Request major version. |
[in] | request_minor_vers | Request minor version. |
[in] | response_major_vers | Response mojor version. |
[in] | response_minor_vers | Response minor version. |
Definition at line 1786 of file httpreadwrite.cpp.
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.
[in] | url_str | String as a URL. |
[in,out] | Handle | Pointer to buffer to store HTTP post handle. |
[in,out] | contentType | Type of content. |
[out] | contentLength | length of content. |
[out] | httpStatus | HTTP status returned on receiving a response message. |
lowRange | ??? | |
highRange | ??? | |
[in] | timeout | time out value. |
Definition at line 1800 of file httpreadwrite.cpp.
void get_sdk_info | ( | char * | info, |
size_t | infoSize | ||
) |
Returns the server information for the operating system.
[out] | info | Buffer to store the operating system information. |
[in] | infoSize | Size of buffer. |
Definition at line 1922 of file httpreadwrite.cpp.