libUPnP
1.6.17
|
#include "config.h"
#include "httpreadwrite.h"
#include "unixutil.h"
#include "upnp.h"
#include "upnpapi.h"
#include "membuffer.h"
#include "uri.h"
#include "statcodes.h"
#include "sock.h"
#include "UpnpInet.h"
#include "UpnpIntTypes.h"
#include "UpnpStdInt.h"
#include "webserver.h"
#include <assert.h>
#include <stdarg.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/utsname.h>
Data Structures | |
struct | HTTPPOSTHANDLE |
struct | HTTPGETHANDLE |
Defines | |
#define | CHUNK_HEADER_SIZE (size_t)10 |
#define | CHUNK_TAIL_SIZE (size_t)10 |
#define | DEFAULT_TCP_CONNECT_TIMEOUT 5 |
#define | SIZE_RANGE_BUFFER 50 |
Typedefs | |
typedef struct HTTPPOSTHANDLE | http_post_handle_t |
typedef struct HTTPGETHANDLE | http_get_handle_t |
Functions | |
static int | Check_Connect_And_Wait_Connection (SOCKET sock, int connect_res) |
Checks socket connection and wait if it is not connected. It should be called just after connect. | |
static int | private_connect (SOCKET sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) |
int | http_FixUrl (IN uri_type *url, OUT uri_type *fixed_url) |
int | http_FixStrUrl (IN const char *urlstr, IN size_t urlstrlen, OUT uri_type *fixed_url) |
SOCKET | http_Connect (IN uri_type *destination_url, OUT uri_type *url) |
int | http_RecvMessage (IN SOCKINFO *info, OUT http_parser_t *parser, IN http_method_t request_method, IN OUT int *timeout_secs, OUT 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 (IN uri_type *destination, IN const char *request, IN size_t request_length, IN http_method_t req_method, IN int timeout_secs, OUT http_parser_t *response) |
int | http_Download (IN const char *url_str, IN int timeout_secs, OUT char **document, OUT size_t *doc_length, OUT char *content_type) |
int | MakePostMessage (const char *url_str, membuffer *request, uri_type *url, int contentLength, const char *contentType) |
int | http_WriteHttpPost (IN void *Handle, IN char *buf, IN size_t *size, IN int timeout) |
int | http_CloseHttpPost (IN void *Handle, IN OUT int *httpStatus, IN int timeout) |
int | http_OpenHttpPost (IN const char *url_str, IN OUT void **Handle, IN const char *contentType, IN int contentLength, IN int timeout) |
int | MakeGetMessage (const char *url_str, const char *proxy_str, membuffer *request, uri_type *url) |
static int | ReadResponseLineAndHeaders (IN SOCKINFO *info, IN OUT http_parser_t *parser, IN OUT int *timeout_secs, IN OUT int *http_error_code) |
Parses already exiting data. If not complete reads more data on the connected socket. The read data is then parsed. The same methid is carried out for headers. | |
int | http_ReadHttpGet (IN void *Handle, IN OUT char *buf, IN OUT size_t *size, IN int timeout) |
int | http_HttpGetProgress (IN void *Handle, OUT size_t *length, OUT size_t *total) |
int | http_CancelHttpGet (IN void *Handle) |
int | http_CloseHttpGet (IN void *Handle) |
int | http_OpenHttpGet (IN const char *url_str, IN OUT void **Handle, IN OUT char **contentType, OUT int *contentLength, OUT int *httpStatus, IN int timeout) |
int | http_OpenHttpGetProxy (const char *url_str, const char *proxy_str, void **Handle, char **contentType, int *contentLength, int *httpStatus, int timeout) |
Makes the HTTP GET message, connects to the peer, sends the HTTP GET request, gets the response and parses the response. | |
int | http_SendStatusResponse (IN SOCKINFO *info, IN int http_status_code, IN int request_major_version, IN int request_minor_version) |
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 (IN int request_major_vers, IN int request_minor_vers, OUT int *response_major_vers, OUT int *response_minor_vers) |
int | MakeGetMessageEx (const char *url_str, membuffer *request, uri_type *url, struct SendInstruction *pRangeSpecifier) |
int | http_OpenHttpGetEx (IN const char *url_str, IN OUT void **Handle, IN OUT char **contentType, OUT int *contentLength, OUT int *httpStatus, IN int lowRange, IN int highRange, IN int timeout) |
void | get_sdk_info (OUT char *info, IN size_t infoSize) |
Purpose: This file defines the functionality making use of the http. It defines functions to receive messages, process messages, send messages.
static int Check_Connect_And_Wait_Connection | ( | SOCKET | sock, |
int | connect_res | ||
) | [static] |
Checks socket connection and wait if it is not connected. It should be called just after connect.
[in] | sock | socket. |
[in] | connect_res | result of connect. |
References INVALID_SOCKET, parse_uri(), sock_make_blocking(), sock_make_no_blocking(), token_string_casecmp(), UPNP_E_INVALID_URL, UPNP_E_OUTOF_SOCKET, UPNP_E_SOCKET_CONNECT, UPNP_E_SUCCESS, UpnpCloseSocket, and UpnpPrintf().
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; arg2 = size_t buf_length memory ptr 'C': (no args) -- appends a HTTP CONNECTION: close header depending on major, minor version. 'c': (no args) -- appends CRLF "\r\n" 'D': (no args) -- appends HTTP DATE: header 'd': arg = int number -- appends decimal number 'G': arg = range information -- add range header 'h': arg = off_t number -- appends off_t number 'K': (no args) -- add chunky header '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
0
- On Success UPNP_E_OUTOF_MEMORY
UPNP_E_INVALID_URL
References HOSTPORT::text, UPNP_E_INVALID_URL, and UPNP_E_OUTOF_MEMORY.
Referenced by CreateServicePacket(), gena_subscribe(), gena_unsubscribe(), genaNotify(), notify_send_and_recv(), process_request(), respond_ok(), send_action_response(), send_error_response(), and send_var_query_response().
int http_OpenHttpGetProxy | ( | const char * | url_str, |
const char * | proxy_str, | ||
void ** | Handle, | ||
char ** | contentType, | ||
int * | contentLength, | ||
int * | httpStatus, | ||
int | timeout | ||
) |
Makes the HTTP GET message, connects to the peer, sends the HTTP GET request, gets the response and parses the response.
If a proxy URL is defined then the connection is made there.
UPNP_E_SUCCESS
- On Success UPNP_E_INVALID_PARAM
- Invalid Paramters UPNP_E_OUTOF_MEMORY
UPNP_E_SOCKET_ERROR
UPNP_E_BAD_RESPONSE
References memptr::buf, membuffer::buf, http_SendMessage(), INVALID_SOCKET, membuffer::length, PARSE_CONTINUE_1, PARSE_OK, PARSE_SUCCESS, ReadResponseLineAndHeaders(), sock_destroy(), sock_init(), http_message_t::status_code, UPNP_E_BAD_RESPONSE, UPNP_E_INVALID_PARAM, UPNP_E_OUTOF_MEMORY, UPNP_E_SOCKET_CONNECT, UPNP_E_SOCKET_ERROR, and UPNP_E_SUCCESS.
Referenced by UpnpOpenHttpGetProxy().
int http_RecvMessage | ( | IN SOCKINFO * | info, |
OUT http_parser_t * | parser, | ||
IN http_method_t | request_method, | ||
IN OUT int * | timeout_secs, | ||
OUT 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_errr_code parameter.
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
References FALSE, g_maxContentLength, PARSE_CONTINUE_1, PARSE_FAILURE, PARSE_INCOMPLETE_ENTITY, PARSE_SUCCESS, sock_read(), UPNP_E_BAD_HTTPMSG, UPNP_E_SUCCESS, and UpnpPrintf().
Referenced by notify_send_and_recv().
int http_SendMessage | ( | SOCKINFO * | info, |
int * | timeout_secs, | ||
const char * | fmt, | ||
... | |||
) |
Sends a message to the destination based on the format parameter.
fmt types:
'f'
: arg = "const char *" file name 'b'
: arg1 = "const char *" mem_buffer; arg2 = "size_t" buffer length. 'I'
: arg = "struct SendInstruction *"E.g.:
char *buf = "POST /xyz.cgi http/1.1\r\n\r\n"; char *filename = "foo.dat"; int status = http_SendMessage(tcpsock, "bf", buf, strlen(buf), // args for memory buffer filename); // arg for file
UPNP_E_OUTOF_MEMORY
UPNP_E_FILE_READ_ERROR
UPNP_E_SUCCESS
References VirtualDirCallbacks::close, VirtualDirCallbacks::open, PRIzd, VirtualDirCallbacks::read, SendInstruction::ReadSendSize, VirtualDirCallbacks::seek, sock_write(), UPNP_E_FILE_READ_ERROR, UPNP_E_INTERNAL_ERROR, UPNP_E_OUTOF_MEMORY, UpnpPrintf(), and virtualDirCallback.
Referenced by http_OpenHttpGetProxy(), notify_send_and_recv(), respond_ok(), send_action_response(), send_error_response(), and send_var_query_response().
static int ReadResponseLineAndHeaders | ( | IN SOCKINFO * | info, |
IN OUT http_parser_t * | parser, | ||
IN OUT int * | timeout_secs, | ||
IN OUT int * | http_error_code | ||
) | [static] |
Parses already exiting data. If not complete reads more data on the connected socket. The read data is then parsed. The same methid is carried out for headers.
PARSE_OK
- On Success PARSE_FAILURE
- Failure to parse data correctly UPNP_E_BAD_HTTPMSG
- Socker read() returns an error info | Socket information object. |
parser | HTTP Parser object. |
timeout_secs | Time out value. |
http_error_code | HTTP errror code returned. |
References PARSE_FAILURE, PARSE_INCOMPLETE, PARSE_OK, sock_read(), and UPNP_E_BAD_HTTPMSG.
Referenced by http_OpenHttpGetProxy().