qLibc
|
HTTP client object. More...
Go to the source code of this file.
Macros | |
#define | HTTP_NO_RESPONSE (0) |
#define | HTTP_CODE_CONTINUE (100) |
#define | HTTP_CODE_OK (200) |
#define | HTTP_CODE_CREATED (201) |
#define | HTTP_CODE_NO_CONTENT (204) |
#define | HTTP_CODE_MULTI_STATUS (207) |
#define | HTTP_CODE_MOVED_TEMPORARILY (302) |
#define | HTTP_CODE_NOT_MODIFIED (304) |
#define | HTTP_CODE_BAD_REQUEST (400) |
#define | HTTP_CODE_FORBIDDEN (403) |
#define | HTTP_CODE_NOT_FOUND (404) |
#define | HTTP_CODE_METHOD_NOT_ALLOWED (405) |
#define | HTTP_CODE_REQUEST_TIME_OUT (408) |
#define | HTTP_CODE_REQUEST_URI_TOO_LONG (414) |
#define | HTTP_CODE_INTERNAL_SERVER_ERROR (500) |
#define | HTTP_CODE_NOT_IMPLEMENTED (501) |
#define | HTTP_CODE_SERVICE_UNAVAILABLE (503) |
#define | HTTP_PROTOCOL_11 "HTTP/1.1" |
#define | SET_TCP_LINGER_TIMEOUT (15) /*< linger seconds, 0 for disable */ |
#define | SET_TCP_NODELAY (1) /*< 0 for disable */ |
#define | MAX_SHUTDOWN_WAIT (100) /*< maximum shutdown wait, unit is ms */ |
#define | MAX_ATOMIC_DATA_SIZE (32 * 1024) /*< maximum sending bytes */ |
Functions | |
qhttpclient_t * | qhttpclient (const char *destname, int port) |
Initialize & create new HTTP client. | |
static bool | setssl (qhttpclient_t *client) |
qhttpclient->setssl(): Sets connection to HTTPS connection | |
static void | settimeout (qhttpclient_t *client, int timeoutms) |
qhttpclient->settimeout(): Sets connection wait timeout. | |
static void | setkeepalive (qhttpclient_t *client, bool keepalive) |
qhttpclient->setkeepalive(): Sets KEEP-ALIVE feature on/off. | |
static void | setuseragent (qhttpclient_t *client, const char *useragent) |
qhttpclient->setuseragent(): Sets user-agent string. | |
static bool | open_ (qhttpclient_t *client) |
qhttpclient->open(): Opens a connection to the remote host. | |
static bool | head (qhttpclient_t *client, const char *uri, int *rescode, qlisttbl_t *reqheaders, qlisttbl_t *resheaders) |
qhttpclient->head(): Sends a HEAD request. | |
static bool | get (qhttpclient_t *client, const char *uri, int fd, off_t *savesize, int *rescode, qlisttbl_t *reqheaders, qlisttbl_t *resheaders, bool(*callback)(void *userdata, off_t recvbytes), void *userdata) |
qhttpclient->get(): Downloads a file from the remote host using GET method. | |
static bool | put (qhttpclient_t *client, const char *uri, int fd, off_t length, int *rescode, qlisttbl_t *reqheaders, qlisttbl_t *resheaders, bool(*callback)(void *userdata, off_t sentbytes), void *userdata) |
qhttpclient->put(): Uploads a file to the remote host using PUT method. | |
static void * | cmd (qhttpclient_t *client, const char *method, const char *uri, void *data, size_t size, int *rescode, size_t *contentslength, qlisttbl_t *reqheaders, qlisttbl_t *resheaders) |
qhttpclient->cmd(): Sends a custom request(method) to the remote host and reads it's response. | |
static bool | sendrequest (qhttpclient_t *client, const char *method, const char *uri, qlisttbl_t *reqheaders) |
qhttpclient->sendrequest(): Sends a HTTP request to the remote host. | |
static int | readresponse (qhttpclient_t *client, qlisttbl_t *resheaders, off_t *contentlength) |
qhttpclient->readresponse(): Reads HTTP response header from the remote host. | |
static ssize_t | gets_ (qhttpclient_t *client, char *buf, size_t bufsize) |
qhttpclient->gets(): Reads a text line from a HTTP/HTTPS stream. | |
static ssize_t | read_ (qhttpclient_t *client, void *buf, size_t nbytes) |
qhttpclient->read(): Reads data from a HTTP/HTTPS stream. | |
static ssize_t | write_ (qhttpclient_t *client, const void *buf, size_t nbytes) |
qhttpclient->write(): Writes data to a HTTP/HTTPS stream. | |
static off_t | recvfile (qhttpclient_t *client, int fd, off_t nbytes) |
qhttpclient->recvfile(): Reads data from a HTTP/HTTPS stream and save into a file descriptor. | |
static off_t | sendfile_ (qhttpclient_t *client, int fd, off_t nbytes) |
qhttpclient->sendfile(): Send file data to a HTTP/HTTPS stream. | |
static bool | _close (qhttpclient_t *client) |
qhttpclient->close(): Closes the connection. | |
static void | _free (qhttpclient_t *client) |
qhttpclient->free(): Free object. | |
HTTP client object.
qhttpclient implements HTTP client.
Example code for simple HTTP GET operation.
Example code for multiple PUT operation using same keep-alive connection.
Definition in file qhttpclient.c.
#define HTTP_NO_RESPONSE (0) |
Definition at line 188 of file qhttpclient.c.
#define HTTP_CODE_CONTINUE (100) |
Definition at line 189 of file qhttpclient.c.
#define HTTP_CODE_OK (200) |
Definition at line 190 of file qhttpclient.c.
#define HTTP_CODE_CREATED (201) |
Definition at line 191 of file qhttpclient.c.
#define HTTP_CODE_NO_CONTENT (204) |
Definition at line 192 of file qhttpclient.c.
#define HTTP_CODE_MULTI_STATUS (207) |
Definition at line 193 of file qhttpclient.c.
#define HTTP_CODE_MOVED_TEMPORARILY (302) |
Definition at line 194 of file qhttpclient.c.
#define HTTP_CODE_NOT_MODIFIED (304) |
Definition at line 195 of file qhttpclient.c.
#define HTTP_CODE_BAD_REQUEST (400) |
Definition at line 196 of file qhttpclient.c.
#define HTTP_CODE_FORBIDDEN (403) |
Definition at line 197 of file qhttpclient.c.
#define HTTP_CODE_NOT_FOUND (404) |
Definition at line 198 of file qhttpclient.c.
#define HTTP_CODE_METHOD_NOT_ALLOWED (405) |
Definition at line 199 of file qhttpclient.c.
#define HTTP_CODE_REQUEST_TIME_OUT (408) |
Definition at line 200 of file qhttpclient.c.
#define HTTP_CODE_REQUEST_URI_TOO_LONG (414) |
Definition at line 201 of file qhttpclient.c.
#define HTTP_CODE_INTERNAL_SERVER_ERROR (500) |
Definition at line 202 of file qhttpclient.c.
#define HTTP_CODE_NOT_IMPLEMENTED (501) |
Definition at line 203 of file qhttpclient.c.
#define HTTP_CODE_SERVICE_UNAVAILABLE (503) |
Definition at line 204 of file qhttpclient.c.
#define HTTP_PROTOCOL_11 "HTTP/1.1" |
Definition at line 206 of file qhttpclient.c.
#define SET_TCP_LINGER_TIMEOUT (15) /*< linger seconds, 0 for disable */ |
Definition at line 211 of file qhttpclient.c.
#define SET_TCP_NODELAY (1) /*< 0 for disable */ |
Definition at line 212 of file qhttpclient.c.
#define MAX_SHUTDOWN_WAIT (100) /*< maximum shutdown wait, unit is ms */ |
Definition at line 213 of file qhttpclient.c.
#define MAX_ATOMIC_DATA_SIZE (32 * 1024) /*< maximum sending bytes */ |
Definition at line 214 of file qhttpclient.c.
qhttpclient_t * qhttpclient | ( | const char * | destname, |
int | port | ||
) |
Initialize & create new HTTP client.
destname | remote address, one of IP address, FQDN domain name and URI. |
port | remote port number. (can be 0 when destname is URI) |
Definition at line 245 of file qhttpclient.c.
|
static |
qhttpclient->setssl(): Sets connection to HTTPS connection
client | qhttpclient object pointer |
Definition at line 323 of file qhttpclient.c.
|
static |
qhttpclient->settimeout(): Sets connection wait timeout.
client | qhttpclient object pointer |
timeoutms | timeout mili-seconds. 0 for system defaults |
Definition at line 363 of file qhttpclient.c.
|
static |
qhttpclient->setkeepalive(): Sets KEEP-ALIVE feature on/off.
client | qhttpclient object pointer |
keepalive | true to set keep-alive on, false to set keep-alive off |
Definition at line 380 of file qhttpclient.c.
|
static |
qhttpclient->setuseragent(): Sets user-agent string.
client | qhttpclient object pointer |
useragent | user-agent string |
Definition at line 394 of file qhttpclient.c.
|
static |
qhttpclient->open(): Opens a connection to the remote host.
client | qhttpclient object pointer |
Definition at line 417 of file qhttpclient.c.
|
static |
qhttpclient->head(): Sends a HEAD request.
client | qhttpclient object pointer. |
uri | URL encoded remote URI for downloading file. ("/path" or "http://.../path") |
rescode | if not NULL, remote response code will be stored. (can be NULL) |
reqheaders | qlisttbl_t pointer which contains additional user request headers. (can be NULL) |
resheaders | qlisttbl_t pointer for storing response headers. (can be NULL) |
Definition at line 558 of file qhttpclient.c.
|
static |
qhttpclient->get(): Downloads a file from the remote host using GET method.
client | qhttpclient object pointer. |
uri | URL encoded remote URI for downloading file. ("/path" or "http://.../path") |
fd | opened file descriptor for writing. |
savesize | if not NULL, the length of stored bytes will be stored. (can be NULL) |
rescode | if not NULL, remote response code will be stored. (can be NULL) |
reqheaders | qlisttbl_t pointer which contains additional user request headers. (can be NULL) |
resheaders | qlisttbl_t pointer for storing response headers. (can be NULL) |
callback | set user call-back function. (can be NULL) |
userdata | set user data for call-back. (can be NULL) |
Definition at line 694 of file qhttpclient.c.
|
static |
qhttpclient->put(): Uploads a file to the remote host using PUT method.
client | qhttpclient object pointer. |
uri | remote URL for uploading file. ("/path" or "http://.../path") |
fd | opened file descriptor for reading. |
length | send size. |
rescode | if not NULL, remote response code will be stored. (can be NULL) |
reqheaders | qlisttbl_t pointer which contains additional user request headers. (can be NULL) |
resheaders | qlisttbl_t pointer for storing response headers. (can be NULL) |
callback | set user call-back function. (can be NULL) |
userdata | set user data for call-back. (can be NULL) |
Definition at line 926 of file qhttpclient.c.
|
static |
qhttpclient->cmd(): Sends a custom request(method) to the remote host and reads it's response.
client | qhttpclient object pointer. |
method | method name. |
uri | remote URL for uploading file. ("/path" or "http://.../path") |
data | data to send. (can be NULL) |
size | data size. |
rescode | if not NULL, remote response code will be stored. (can be NULL) |
contentslength | if not NULL, the contents length will be stored. (can be NULL) |
reqheaders | qlisttbl_t pointer which contains additional user request headers. (can be NULL) |
resheaders | qlisttbl_t pointer for storing response headers. (can be NULL) |
Definition at line 1099 of file qhttpclient.c.
|
static |
qhttpclient->sendrequest(): Sends a HTTP request to the remote host.
client | qhttpclient object pointer |
method | HTTP method name |
uri | URI string for the method. ("/path" or "http://.../path") |
reqheaders | qlisttbl_t pointer which contains additional user request headers. (can be NULL) |
Definition at line 1194 of file qhttpclient.c.
|
static |
qhttpclient->readresponse(): Reads HTTP response header from the remote host.
client | qhttpclient object pointer |
resheaders | qlisttbl_t pointer for storing response headers. (can be NULL) |
contentlength | length of content body(or -1 for chunked transfer encoding) will be stored. (can be NULL) |
Definition at line 1293 of file qhttpclient.c.
|
static |
qhttpclient->gets(): Reads a text line from a HTTP/HTTPS stream.
client | qhttpclient object pointer |
buf | data buffer pointer |
bufsize | buffer size |
Definition at line 1372 of file qhttpclient.c.
|
static |
qhttpclient->read(): Reads data from a HTTP/HTTPS stream.
client | qhttpclient object pointer. |
buf | a buffer pointer for storing content. (can be NULL, then read & throw out content) |
length | content size to read. |
Definition at line 1436 of file qhttpclient.c.
|
static |
qhttpclient->write(): Writes data to a HTTP/HTTPS stream.
client | qhttpclient object pointer. |
buf | a data pointer. |
length | content size to write. |
Definition at line 1490 of file qhttpclient.c.
|
static |
qhttpclient->recvfile(): Reads data from a HTTP/HTTPS stream and save into a file descriptor.
client | qhttpclient object pointer. |
fd | output file descriptor |
nbytes | the number of bytes to read and save. |
Definition at line 1534 of file qhttpclient.c.
|
static |
qhttpclient->sendfile(): Send file data to a HTTP/HTTPS stream.
client | qhttpclient object pointer. |
fd | input file descriptor |
nbytes | the number of bytes to read and send. |
Definition at line 1580 of file qhttpclient.c.
|
static |
qhttpclient->close(): Closes the connection.
qhttpclient_t | HTTP object pointer |
Definition at line 1628 of file qhttpclient.c.
|
static |
qhttpclient->free(): Free object.
qhttpclient_t | HTTP object pointer |
Definition at line 1678 of file qhttpclient.c.