Data Structures | |
struct | _cp_client |
cp_client is a 'client socket'. More... | |
struct | cp_http_status_code_entry |
struct | _cp_http_request |
http request descriptor More... | |
struct | _cp_http_response |
http response holder More... | |
struct | _cp_httpsocket |
http server socket More... | |
struct | _cp_http_service |
http service descriptor More... | |
struct | _cp_httpclient |
http client socket wrapper More... | |
struct | _cp_url_descriptor |
struct | _cp_httpclient_result |
wrapper for asynchronous interface callback More... | |
struct | _cp_httpclient_ctl |
asynchronous interface control block. More... | |
struct | _cp_http_transfer_descriptor |
transfer descriptor for async interface More... | |
struct | _cp_socket |
cp_socket is a 'server socket'. More... | |
struct | _cp_connection_descriptor |
connection descriptor structure More... | |
Files | |
file | client.h |
definitions for client socket abstraction api | |
file | http.c |
http framework implementation | |
file | http.h |
basic http feature implementations. | |
file | httpclient.h |
definitions for http client socket api | |
file | socket.c |
socket framework implementation | |
file | socket.h |
definitions for socket abstraction api | |
Defines | |
#define | DEFAULT_CLIENT_TIMEOUT 300 |
seconds to wait for responses | |
#define | DEFAULT_RETRIES 3 |
default connect retries | |
#define | HTTP_PARSE_BUFSIZE 0xFFFF |
#define | MATCHMAX 10 |
#define | HTTP_RE_MATCHMAX 10 |
#define | REQUEST_STAGE_START 0 |
#define | REQUEST_STAGE_STATUS_LINE 1 |
#define | REQUEST_STAGE_HEADERS 2 |
#define | REQUEST_STAGE_BODY 3 |
#define | REQUEST_STAGE_DONE 4 |
#define | HEXDIGIT(c) |
#define | DEFAULT_SERVER_NAME "libcprops-0.1.8" |
#define | DEFAULT_KEEPALIVE 300 |
#define | HTTP_KEEPALIVE DEFAULT_KEEPALIVE |
#define | MAX_URL_LENGTH 0x400 |
#define | DEFAULT_MAX_REDIRECTS 10 |
#define | CPSOCKET_DEFAULT_BACKLOG 50 |
#define | CPSOCKET_DEFAULT_DELAY_SEC 1 |
#define | CPSOCKET_DEFAULT_DELAY_USEC 0 |
#define | CPSOCKET_THREADPOOL_DEFAULT_SIZE_MIN 5 |
#define | CPSOCKET_THREADPOOL_DEFAULT_SIZE_MAX 50 |
#define | cp_connection_descriptor_get_socket(cd) ((cd)->sock) |
return cp_socket struct for given connection descriptor | |
#define | cp_connection_descriptor_get_addr(cd) ((cd)->addr) |
return client address for given connection descriptor | |
#define | cp_connection_descriptor_get_fd(cd) ((cd)->fd) |
return file descriptor for given connection descriptor | |
Typedefs | |
typedef CPROPS_DLL struct _cp_client | cp_client |
cp_client is a 'client socket'. | |
typedef CPROPS_DLL enum { ... } | cp_http_version |
HTTP versions. | |
typedef CPROPS_DLL enum { ... } | cp_http_status_code |
HTTP status codes. | |
typedef CPROPS_DLL enum { ... } | connection_policy |
connection handling policy. | |
typedef CPROPS_DLL enum { ... } | cp_http_content_type |
typedef CPROPS_DLL struct _cp_http_request | cp_http_request |
http request descriptor | |
typedef CPROPS_DLL struct _cp_http_response | cp_http_response |
http response holder | |
typedef int(* | cp_http_service_callback )(cp_http_request *request, cp_http_response *response) |
service function prototype | |
typedef CPROPS_DLL struct _cp_httpsocket | cp_httpsocket |
http server socket | |
typedef CPROPS_DLL struct _cp_http_service | cp_http_service |
http service descriptor | |
typedef CPROPS_DLL struct _cp_httpclient | cp_httpclient |
http client socket wrapper | |
typedef CPROPS_DLL struct _cp_url_descriptor | cp_url_descriptor |
wrapper for url information | |
typedef CPROPS_DLL struct _cp_httpclient_result | cp_httpclient_result |
wrapper for asynchronous interface callback | |
typedef CPROPS_DLL struct _cp_httpclient_ctl | cp_httpclient_ctl |
asynchronous interface control block. | |
typedef void(* | cp_httpclient_callback )(cp_httpclient_result *response) |
typedef CPROPS_DLL struct _cp_http_transfer_descriptor | cp_http_transfer_descriptor |
transfer descriptor for async interface | |
typedef CPROPS_DLL enum { ... } | cp_socket_strategy |
cp_socket connection handling strategy | |
typedef void *(* | cp_socket_thread_function )(void *) |
thread function for threadpool implementation | |
typedef int(* | cp_socket_callback )(struct _cp_socket *, int fd) |
function prototype for callback implementation | |
typedef CPROPS_DLL struct _cp_socket | cp_socket |
cp_socket is a 'server socket'. | |
typedef CPROPS_DLL struct _cp_connection_descriptor | cp_connection_descriptor |
connection descriptor structure | |
Enumerations | |
enum | { OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT } |
HTTP request types. | |
enum | { HTTP_1_0, HTTP_1_1 } |
HTTP versions. | |
enum | { HTTP_NULL_STATUS = -1, HTTP_100_CONTINUE = 100, HTTP_101_SWITCHING_PROTOCOLS = 101, HTTP_200_OK = 200, HTTP_201_CREATED = 201, HTTP_202_ACCEPTED = 202, HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203, HTTP_204_NO_CONTENT = 204, HTTP_205_RESET_CONTENT = 205, HTTP_206_PARTIAL_CONTENT = 206, HTTP_300_MULTIPLE_CHOICES = 300, HTTP_301_MOVED_PERMANENTLY = 301, HTTP_302_FOUND = 302, HTTP_303_SEE_OTHER = 303, HTTP_304_NOT_MODIFIED = 304, HTTP_305_USE_PROXY = 305, HTTP_307_TEMPORARY_REDIRECT = 307, HTTP_400_BAD_REQUEST = 400, HTTP_401_UNAUTHORIZED = 401, HTTP_402_PAYMENT_REQUIRED = 402, HTTP_403_FORBIDDEN = 403, HTTP_404_NOT_FOUND = 404, HTTP_405_METHOD_NOT_ALLOWED = 405, HTTP_406_NOT_ACCEPTABLE = 406, HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407, HTTP_408_REQUEST_TIME_OUT = 408, HTTP_409_CONFLICT = 409, HTTP_410_GONE = 410, HTTP_411_LENGTH_REQUIRED = 411, HTTP_412_PRECONDITION_FAILED = 412, HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413, HTTP_414_REQUEST_URI_TOO_LARGE = 414, HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415, HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416, HTTP_417_EXPECTATION_FAILED = 417, HTTP_500_INTERNAL_SERVER_ERROR = 500, HTTP_501_NOT_IMPLEMENTED = 501, HTTP_502_BAD_GATEWAY = 502, HTTP_503_SERVICE_UNAVAILABLE = 503, HTTP_504_GATEWAY_TIME_OUT = 504, HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505 } |
HTTP status codes. | |
enum | { HTTP_CONNECTION_POLICY_DEFAULT, HTTP_CONNECTION_POLICY_CLOSE, HTTP_CONNECTION_POLICY_KEEP_ALIVE } |
connection handling policy. More... | |
enum | { TEXT, HTML, JPEG } |
enum | cp_http_result_status { CP_HTTP_RESULT_SUCCESS, CP_HTTP_RESULT_CONNECTION_FAILED, CP_HTTP_RESULT_CONNECTION_RESET, CP_HTTP_RESULT_TIMED_OUT, CP_HTTP_RESULT_WRITE_ERROR, CP_HTTP_RESULT_READ_ERROR } |
result codes for HTTP requests | |
enum | { CPSOCKET_STRATEGY_CALLBACK, CPSOCKET_STRATEGY_THREADPOOL } |
cp_socket connection handling strategy | |
Functions | |
CPROPS_DLL void | cp_client_init () |
recommended to call before using tcp client socket functions | |
CPROPS_DLL void | cp_client_stop_all () |
call from signal handler to stop sockets in waiting select() and close all connections | |
CPROPS_DLL void | cp_client_shutdown () |
performs cleanup | |
CPROPS_DLL void | cp_tcp_add_shutdown_callback (void(*cb)(void *), void *prm) |
add callback to be made on tcp layer shutdown | |
CPROPS_DLL cp_client * | cp_client_create (char *host, int port) |
create a client socket | |
CPROPS_DLL cp_client * | cp_client_create_addr (struct sockaddr_in *) |
create a client socket with a struct sockaddr * | |
CPROPS_DLL void | cp_client_set_timeout (cp_client *client, int sec, int usec) |
set the timeout - (0, 0) for no timeout | |
CPROPS_DLL void | cp_client_set_retry (cp_client *client, int retry_count) |
number of connection retries | |
CPROPS_DLL void | cp_client_set_owner (cp_client *client, void *owner) |
useful free pointer for client code | |
CPROPS_DLL int | cp_client_connect (cp_client *client) |
opens a connection. | |
CPROPS_DLL int | cp_client_reopen (cp_client *client, char *host, int port) |
use the same wrapper for a different address. | |
CPROPS_DLL int | cp_client_close (cp_client *client) |
close a client connection | |
CPROPS_DLL void | cp_client_destroy (cp_client *client) |
deallocate a cp_client | |
CPROPS_DLL int | cp_client_read (cp_client *client, char *buf, int len) |
CPROPS_DLL int | cp_client_read_string (cp_client *client, cp_string *str, int len) |
CPROPS_DLL int | cp_client_write (cp_client *client, char *buf, int len) |
CPROPS_DLL int | cp_client_write_string (cp_client *client, cp_string *str) |
void | cp_http_signal_handler (int sig) |
void * | session_cleanup_thread (void *) |
int | cp_http_init () |
recommended to call before using cp_httpsocket api | |
void | cp_httpsocket_stop_all () |
void | cp_httpsocket_stop (cp_httpsocket *sock) |
void * | cp_http_add_shutdown_callback (void(*cb)(void *), void *prm) |
called when shutting down http layer | |
void | cp_http_shutdown () |
call to perform cleanup after using cp_httpsocket api | |
void | cp_http_request_delete (cp_http_request *request) |
deallocate an http request descriptor | |
char * | get_http_request_type_lit (cp_http_request_type type) |
static int | parse_request_line (cp_http_request *req, char *request, int *plen) |
static int | is_empty_line (char *c) |
static void | skip_eol (char **c) |
static int | parse_headers (cp_http_request *req, char *request, int *plen, int *stage) |
static int | parse_cp_http_request_body (cp_http_request *req, char *request, int *used) |
void | urldecode (char *str, char **decoded) |
static int | parse_cgi_vars (cp_http_request *req) |
char * | cp_http_request_get_header (cp_http_request *request, char *name) |
return value of specified header or NULL if none | |
char ** | cp_http_request_get_headers (cp_http_request *request) |
return a newly allocated array of header names | |
char * | cp_http_request_get_parameter (cp_http_request *request, char *name) |
return a single parameter with the specified name | |
void | cp_http_request_dump (cp_http_request *req) |
dump a cp_http_request descriptor (uses cp_info) | |
cp_http_response * | cp_http_response_create (cp_http_request *request) |
(internal) create a new response descriptor | |
void | cp_http_response_delete (cp_http_response *res) |
(internal) deallocate a response descriptor | |
void | cp_http_response_destroy (cp_http_response *res) |
deallocate a response descriptor | |
int | cp_http_response_write (cp_connection_descriptor *cdesc, cp_http_response *res) |
(internal) output an http response on given connection | |
void | cp_http_response_set_status (cp_http_response *response, cp_http_status_code code) |
set the status code on an http response | |
cp_http_status_code | cp_http_response_get_status (cp_http_response *response) |
get the status code of an http response | |
void | cp_http_response_set_content_type (cp_http_response *response, cp_http_content_type type) |
deprecated - use cp_http_response_set_content_type_string | |
void | cp_http_response_set_content_type_string (cp_http_response *response, char *content_type_lit) |
set the Content-Type header on an http response | |
char * | cp_http_response_get_content_type (cp_http_response *response) |
get the Content-Type header value for an http response | |
void | cp_http_response_set_header (cp_http_response *response, char *name, char *value) |
set an arbitrary header on an http response | |
char * | cp_http_response_get_header (cp_http_response *response, char *name) |
retrieve header content for one header | |
cp_vector * | cp_http_response_get_header_names (cp_http_response *response) |
returns a vector containing header names | |
void | cp_http_response_set_body (cp_http_response *response, char *body) |
deprecated - use cp_http_response_set_content instead | |
void | cp_http_response_set_content (cp_http_response *response, cp_string *content) |
set the (possibly binary) content on an http response | |
cp_string * | cp_http_response_get_content (cp_http_response *response) |
get the content of an http response | |
void | cp_http_response_set_connection_policy (cp_http_response *response, connection_policy policy) |
set the Connection header on a cp_http_response descriptor | |
void | cp_http_response_skip (cp_http_response *response) |
sets the 'skip' flag on an http response, which prevents the response being deserialized and written to the client by the http framework. | |
static int | cp_http_write_server_error (cp_connection_descriptor *cdesc, int status_code) |
cp_httpsocket * | cp_httpsocket_create (int port, cp_http_service_callback default_service) |
create a cp_http_socket with the specified default cp_http_service | |
void | cp_httpsocket_set_keepalive (cp_httpsocket *socket, int sec) |
set value for Keep-Alive header | |
void | cp_httpsocket_set_server_name (cp_httpsocket *socket, char *name) |
set value for Server header | |
void | cp_httpsocket_set_backlog (cp_httpsocket *socket, int backlog) |
set maximal number of queued requests before accept() starts refusing connections | |
void | cp_httpsocket_set_delay (cp_httpsocket *socket, struct timeval delay) |
set time to block in accept | |
void | cp_httpsocket_set_delay_sec (cp_httpsocket *socket, long sec) |
void | cp_httpsocket_set_delay_usec (cp_httpsocket *socket, long usec) |
set micro sec. | |
void | cp_httpsocket_set_poolsize_min (cp_httpsocket *socket, int min) |
set lower limit on thread pool size | |
void | cp_httpsocket_set_poolsize_max (cp_httpsocket *socket, int max) |
set upper limit on thread pool size | |
void | cp_httpsocket_delete (cp_httpsocket *svc) |
deallocate a cp_httpsocket structure | |
void * | cp_httpsocket_add_shutdown_callback (cp_httpsocket *socket, void(*cb)(void *), void *prm) |
called when closing a socket | |
int | cp_httpsocket_listen (cp_httpsocket *sock) |
puts socket in listening mode | |
int | cp_httpsocket_register_service (cp_httpsocket *server, cp_http_service *service) |
register a service on a socket | |
void * | cp_httpsocket_unregister_service (cp_httpsocket *server, cp_http_service *service) |
unregister a service on a socket | |
cp_http_service * | cp_http_service_create (char *name, char *path, cp_http_service_callback service) |
create a new cp_http_service descriptor. | |
void | cp_http_service_delete (cp_http_service *svc) |
deallocate a cp_http_service descriptor | |
static int | cp_http_default_response (cp_http_request *request, cp_http_response *response) |
void | cp_http_response_report_error (cp_http_response *response, cp_http_status_code code, char *message) |
set up a response reporting an error | |
static int | get_keepalive (cp_httpsocket *sock, cp_http_request *request) |
static int | cp_httpselect (cp_httpsocket *hsock, int sec, int fd) |
static int | find_newline (char *buf) |
static int | check_newline (char *buf, int *index) |
static int | incremental_request_parse (cp_httpsocket *sock, cp_http_request **request, int *stage, cp_string *state, char *curr, int len, int *used) |
static int | post_process (cp_httpsocket *socket, cp_http_request *req) |
static int | read_request (cp_list *req_list, cp_connection_descriptor *cdesc) |
void * | cp_http_thread_fn (void *prm) |
CPROPS_DLL cp_http_request * | cp_http_request_parse (struct _cp_httpsocket *owner, char *request, int *err) |
parse an http request | |
CPROPS_DLL cp_vector * | cp_http_request_get_param_vector (cp_http_request *request, char *name) |
return vector of GET or POST parameters with specified name | |
CPROPS_DLL cp_vector * | cp_http_request_get_params (cp_http_request *request) |
return all GET or POST parameters for given request | |
__BEGIN_DECLS CPROPS_DLL int | cp_httpclient_init () |
api initialization function | |
CPROPS_DLL int | cp_httpclient_shutdown () |
api cleanup function | |
CPROPS_DLL cp_httpclient * | cp_httpclient_create (char *host, int port) |
create an http client wrapper to communicate with the given host on the given port | |
CPROPS_DLL cp_httpclient * | cp_httpclient_create_proxy (char *host, int port, char *proxy_host, int proxy_port) |
create an http client wrapper to communicate with the given host on the given port using the given proxy settings | |
CPROPS_DLL void | cp_httpclient_destroy (cp_httpclient *client) |
deallocate a cp_httpclient wrapper. | |
CPROPS_DLL void | cp_httpclient_set_http_version (cp_httpclient *client, cp_http_version version) |
set the HTTP version for subsequent requests | |
CPROPS_DLL void | cp_httpclient_set_request_type (cp_httpclient *client, cp_http_request_type type) |
set the request type for subsequent requests. | |
CPROPS_DLL void | cp_httpclient_set_header (cp_httpclient *client, char *header, char *value) |
set an arbitrary header. | |
CPROPS_DLL void | cp_httpclient_set_auto_drop_headers (cp_httpclient *client, short mode) |
determine whether headers are automatically deleted or not - disabled by default | |
CPROPS_DLL void | cp_httpclient_drop_headers (cp_httpclient *client) |
deallocate cgi parameters | |
CPROPS_DLL void * | cp_httpclient_set_parameter (cp_httpclient *client, char *name, char *value) |
set a cgi parameter | |
CPROPS_DLL void | cp_httpclient_set_auto_drop_parameters (cp_httpclient *client, short mode) |
determine whether cgi parameters are automatically deleted or not - enabled by default | |
CPROPS_DLL void | cp_httpclient_drop_parameters (cp_httpclient *client) |
deallocate cgi parameters | |
CPROPS_DLL void | cp_httpclient_set_user_agent (cp_httpclient *client, char *agent) |
set a value for the 'User-Agent' header. | |
CPROPS_DLL void | cp_httpclient_set_timeout (cp_httpclient *client, int sec, int usec) |
set the timeout value for the underlying tcp socket | |
CPROPS_DLL void | cp_httpclient_set_retry (cp_httpclient *client, int retry_count) |
set the number of times to retry a connection on failure | |
CPROPS_DLL void | cp_httpclient_allow_redirects (cp_httpclient *client, int mode) |
set client behavior on HTTP 302, 302 etc. | |
CPROPS_DLL void | cp_httpclient_set_max_redirects (cp_httpclient *client, int max) |
maximal number of server redirect directives to follow - default is 10 | |
CPROPS_DLL int | cp_httpclient_reopen (cp_httpclient *client, char *host, int port) |
use the same wrapper for a different address. | |
CPROPS_DLL cp_url_descriptor * | cp_url_descriptor_create (char *host, short ssl, int port, char *uri) |
CPROPS_DLL void | cp_url_descriptor_destroy (cp_url_descriptor *desc) |
CPROPS_DLL short | cp_url_descriptor_ssl (cp_url_descriptor *desc) |
CPROPS_DLL char * | cp_url_descriptor_host (cp_url_descriptor *desc) |
CPROPS_DLL int | cp_url_descriptor_port (cp_url_descriptor *desc) |
CPROPS_DLL char * | cp_url_descriptor_uri (cp_url_descriptor *desc) |
CPROPS_DLL cp_url_descriptor * | cp_url_descriptor_parse (char *url) |
CPROPS_DLL cp_httpclient_result * | cp_httpclient_result_create (cp_httpclient *client) |
(internal) create a cp_httpclient_result object | |
CPROPS_DLL void | cp_httpclient_result_destroy (cp_httpclient_result *res) |
destructor for cp_httpclient_result objects | |
CPROPS_DLL void * | cp_httpclient_result_id (cp_httpclient_result *res) |
get the client assigned id from a result descriptor | |
CPROPS_DLL cp_http_result_status | cp_httpclient_result_status (cp_httpclient_result *res) |
get the result status code from a result descriptor | |
CPROPS_DLL cp_http_response * | cp_httpclient_result_get_response (cp_httpclient_result *res) |
get the response object from a result descriptor | |
CPROPS_DLL cp_httpclient * | cp_httpclient_result_get_client (cp_httpclient_result *res) |
get the client object the response was made on | |
CPROPS_DLL cp_httpclient_result * | cp_httpclient_fetch (cp_httpclient *client, char *uri) |
read uri content - synchronous interface | |
CPROPS_DLL cp_httpclient_ctl * | cp_httpclient_ctl_create (int background) |
create an asynchronous client transfer block for separate transfers. | |
CPROPS_DLL void | cp_httpclient_ctl_destroy (cp_httpclient_ctl *ctl) |
transfer blocks created with cp_httpclient_ctl_create() are not released by the framework and must be finalized by calling cp_httpclient_ctl_destroy(). | |
CPROPS_DLL fd_set * | cp_httpclient_ctl_default_get_read_fd_set (int *num) |
retrieve a read file descriptor set for select() for the default transfer control block. | |
CPROPS_DLL fd_set * | cp_httpclient_ctl_get_read_fd_set (cp_httpclient_ctl *ctl, int *num) |
retrieve a read file descriptor set prepared for select(). | |
CPROPS_DLL fd_set * | cp_httpclient_ctl_default_get_write_fd_set (int *num) |
retrieve a write file descriptor set for select() for the default transfer control block. | |
CPROPS_DLL fd_set * | cp_httpclient_ctl_get_write_fd_set (cp_httpclient_ctl *ctl, int *num) |
retrieve a write file descriptor set prepared for select(). | |
CPROPS_DLL cp_http_transfer_descriptor * | cp_http_transfer_descriptor_create (void *id, cp_httpclient *client, cp_httpclient_callback callback, char *uri) |
CPROPS_DLL void | cp_http_transfer_descriptor_destroy (cp_http_transfer_descriptor *desc) |
CPROPS_DLL int | cp_httpclient_fetch_nb (cp_httpclient *client, char *uri, void *id, cp_httpclient_callback callback, int background) |
perform an asynchronous fetch. | |
CPROPS_DLL int | cp_httpclient_fetch_ctl (cp_httpclient_ctl *ctl, cp_httpclient *client, char *uri, void *id, cp_httpclient_callback callback) |
same as cp_httpclient_fetch_nb but allows specifying a different asynchronous transfer control block. | |
CPROPS_DLL int | cp_httpclient_fetch_nb_exec () |
non-blocking fetches executing in the foreground must be driven by calls to cp_httpclient_fetch_nb_exec(). | |
CPROPS_DLL int | cp_httpclient_fetch_ctl_exec (cp_httpclient_ctl *ctl) |
same as cp_httpclient_fetch_nb_exec() but allows specifying a different aysnchronous transfer control block. | |
void | cp_socket_init () |
recommended to call before using socket functions | |
void | cp_socket_stop (cp_socket *sock) |
void | cp_socket_stop_all () |
call from signal handler to stop sockets in waiting select() and close all connections | |
void | cp_socket_shutdown () |
performs cleanup | |
int | setnonblocking (int sock) |
cp_connection_descriptor * | cp_connection_descriptor_create (cp_socket *sock, struct sockaddr_in *addr, int fd) |
internal: create a new connection descriptor | |
void | cp_connection_descriptor_destroy (cp_connection_descriptor *conn_desc) |
deallocate a connection descriptor | |
cp_socket * | cp_socket_create (int port, cp_socket_strategy strategy, void *fn) |
create a new cp_socket struct | |
void | cp_socket_set_backlog (cp_socket *socket, int backlog) |
set number of outstanding requests before accept() fails new connections | |
void | cp_socket_set_delay (cp_socket *socket, struct timeval delay) |
delay time before re-accept()ing | |
void | cp_socket_set_delay_sec (cp_socket *socket, long sec) |
seconds before re-accept()ing | |
void | cp_socket_set_delay_usec (cp_socket *socket, long usec) |
microseconds before re-accept()ing | |
void | cp_socket_set_poolsize_min (cp_socket *socket, int min) |
lower size limit for threadpool implementation | |
void | cp_socket_set_poolsize_max (cp_socket *socket, int max) |
upper size limit for threadpool implementation | |
void | cp_socket_set_owner (cp_socket *socket, void *owner) |
useful free pointer for client code | |
void * | cp_socket_add_shutdown_callback (cp_socket *sock, void(*cb)(void *), void *prm) |
add a callback to be made on socket shutdown | |
void | cp_socket_delete (cp_socket *sock) |
deallocate a socket descriptor | |
int | cp_socket_listen (cp_socket *sock) |
cp_socket_listen attempts to create a SOCK_STREAM socket with socket(), bind to a local port with bind(), and set the socket to listen for connections with listen(). | |
int | cp_socket_select_callback_impl (cp_socket *sock) |
int | cp_socket_select_threadpool_impl (cp_socket *sock) |
int | cp_socket_select (cp_socket *sock) |
block and wait for connections | |
int | cp_socket_connection_close (cp_socket *sock, int fd) |
close a (non ssl) connection | |
int | cp_connection_descrpitor_read (cp_connection_descriptor *desc, char *buf, int len) |
read from a connection descriptor | |
int | cp_connection_descriptor_write (cp_connection_descriptor *desc, char *buf, int len) |
write on a connection descriptor | |
Variables | |
__BEGIN_DECLS typedef CPROPS_DLL enum { ... } | cp_http_request_type |
HTTP request types. | |
static char * | re_request_line_str = "^(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT)[[:space:]]+([^ ]+)[[:space:]]+HTTP/([^[:space:]]*)[[:space:]]*$" |
static char * | re_request_header_str = "^([[:alnum:][:punct:]]+): (.*[^[:space:]])([[:space:]]?)$" |
static char * | re_request_vars_str = "([^&]+)=([^&]*[^&[:space:]])&?" |
static regex_t | re_request_line |
static regex_t | re_request_header |
static regex_t | re_request_vars |
static char * | cp_http_version_lit [] = { "1.0", "1.1" } |
static char * | connection_policy_lit [] = { "Close", "Close", "Keep-Alive" } |
static char * | content_type_lit [] = { "text/plain", "text/html", "image/jpeg" } |
static char * | server_error_fmt = "</html>" |
static int | cp_http_server_error_code [] |
static char * | cp_http_server_error_lit [] |
static cp_hashtable * | cp_http_server_error |
struct cp_http_status_code_entry | cp_http_status_code_list [] |
static cp_hashtable * | cp_http_status_lit |
static char * | cp_http_request_type_lit [] |
static volatile int | initialized = 0 |
static volatile int | socket_reg_id = 0 |
static cp_hashlist * | socket_registry = NULL |
static cp_vector * | shutdown_hook = NULL |
volatile int | cp_http_stopping = 0 |
static volatile int | cp_http_shutting_down = 0 |
struct CPROPS_DLL | _cp_httpsocket |
static volatile int | socket_reg_id = 0 |
static cp_hashlist * | socket_registry |
static cp_vector * | shutdown_hook = NULL |
static volatile int | initialized = 0 |
static volatile int | shutting = 0 |
volatile int | stopping_all = 0 |
#define HEXDIGIT | ( | c | ) |
((c) >= '0' && (c) <= '9' ? (c) - '0' : \ ((c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0xA : \ ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 0xA : -1)))
typedef { ... } connection_policy |
connection handling policy.
HTTP_CONNECTION_POLICY_DEFAULT defaults to HTTP_CONNECTION_POLICY_CLOSE for HTTP/1.0 and to HTTP_CONNECTION_POLICY_KEEP_ALIVE for HTTP/1.1.
typedef CPROPS_DLL struct _cp_client cp_client |
cp_client is a 'client socket'.
create a cp_client with address information, call cp_client_connect() and communicate on the resulting file descriptor.
typedef CPROPS_DLL struct _cp_httpclient_ctl cp_httpclient_ctl |
asynchronous interface control block.
By default asynchronous transfers use a static block shared between all client transfers. To separate transfers into different groups, create a cp_httpclient_ctl control block and use _fetch_ctl_nb and _fetch_ctl_nb_exec().
typedef CPROPS_DLL struct _cp_socket cp_socket |
cp_socket is a 'server socket'.
create a cp_socket to listen on a port, specify a callback to implemet your communication protocol (libcprops provides a basic http implementation you could plug in) and the strategy you want for handling handling multiple connections - use a thread pool to serve each connection on its own thread or a more select()-like approach.
If you create a socket with the CPSOCKET_STRATEGY_THREADPOOL, supply a thread function to handle communication once a connection has been accept()-ed. Your cp_thread function should close the connection when done and check the 'closing' flag, which is set to 1 on shutdown.
If you create a socket with the CPSOCKET_STRATEGY_CALLBACK, supply a callback to process incremental feeds as they come along.
anonymous enum |
connection handling policy.
HTTP_CONNECTION_POLICY_DEFAULT defaults to HTTP_CONNECTION_POLICY_CLOSE for HTTP/1.0 and to HTTP_CONNECTION_POLICY_KEEP_ALIVE for HTTP/1.1.
CPROPS_DLL int cp_client_connect | ( | cp_client * | client | ) |
opens a connection.
may return: 0 on success -1 on failure > 0 on SSL verification errors. a connection has been established but couldn't be properly verified. Client code should decide whether to proceed or not. The server_certificate
field on the client
will have been set to the server certificate if one has been presented.
return codes correspond to SSL_get_verify_result codes with the addition of X509_V_ERR_APPLICATION_VERIFICATION possibly indicating that no server certificate was presented. In this case the server_certificate
field will be NULL
.
References cp_error().
Referenced by cp_client_reopen().
CPROPS_DLL int cp_client_reopen | ( | cp_client * | client, | |
char * | host, | |||
int | port | |||
) |
use the same wrapper for a different address.
this will close an existing connection, change the host and port settings on the wrapper and attempt to connect. maybe rename this function.
References cp_client_close(), cp_client_connect(), cp_error(), and cp_perror().
Referenced by cp_httpclient_fetch(), and cp_httpclient_reopen().
CPROPS_DLL void cp_http_response_skip | ( | cp_http_response * | response | ) |
sets the 'skip' flag on an http response, which prevents the response being deserialized and written to the client by the http framework.
this is needed if the service function writes directly to the underlying socket.
CPROPS_DLL cp_http_service * cp_http_service_create | ( | char * | name, | |
char * | path, | |||
cp_http_service_callback | service | |||
) |
create a new cp_http_service descriptor.
client requests for uris beginning with 'path' will be delegated to this service once registered on a listening socket.
CPROPS_DLL void cp_httpclient_allow_redirects | ( | cp_httpclient * | client, | |
int | mode | |||
) |
set client behavior on HTTP 302, 302 etc.
responses
CPROPS_DLL cp_httpclient_ctl* cp_httpclient_ctl_create | ( | int | background | ) |
create an asynchronous client transfer block for separate transfers.
if background is 0, transfers must be driven by calling cp_httpclient_fetch_ctl_exec(). If background is 1, transfers will be run on a separate thread. If background is greater than 1, a thread pool is created to perform background transfers and the given value is used as the maximal size of the thread pool.
References cp_hash_addr(), cp_hash_compare_addr(), cp_hashlist_create, cp_httpclient_ctl_destroy(), and cp_thread_pool_create().
Referenced by cp_httpclient_init().
CPROPS_DLL fd_set* cp_httpclient_ctl_default_get_read_fd_set | ( | int * | num | ) |
retrieve a read file descriptor set for select() for the default transfer control block.
If num is non-null it is set to the number of entries in the file descriptor array.
References cp_httpclient_ctl_get_read_fd_set().
CPROPS_DLL fd_set* cp_httpclient_ctl_default_get_write_fd_set | ( | int * | num | ) |
retrieve a write file descriptor set for select() for the default transfer control block.
If num is non-null it is set to the number of entries in the file descriptor array.
References cp_httpclient_ctl_get_write_fd_set().
CPROPS_DLL fd_set* cp_httpclient_ctl_get_read_fd_set | ( | cp_httpclient_ctl * | ctl, | |
int * | num | |||
) |
retrieve a read file descriptor set prepared for select().
If num is non- null it is set to the number of entries in the file descriptor array.
Referenced by cp_httpclient_ctl_default_get_read_fd_set().
CPROPS_DLL fd_set* cp_httpclient_ctl_get_write_fd_set | ( | cp_httpclient_ctl * | ctl, | |
int * | num | |||
) |
retrieve a write file descriptor set prepared for select().
If num is non- null it is set to the number of entries in the file descriptor array.
Referenced by cp_httpclient_ctl_default_get_write_fd_set().
CPROPS_DLL void cp_httpclient_destroy | ( | cp_httpclient * | client | ) |
deallocate a cp_httpclient wrapper.
References cp_client_close(), cp_client_destroy(), and cp_hashtable_destroy().
Referenced by cp_httpclient_create(), and cp_httpclient_create_proxy().
CPROPS_DLL int cp_httpclient_fetch_nb | ( | cp_httpclient * | client, | |
char * | uri, | |||
void * | id, | |||
cp_httpclient_callback | callback, | |||
int | background | |||
) |
perform an asynchronous fetch.
If background is non-zero, the fetch happens in a separate thread and the callback is invoked asynchronously. Otherwise the caller must make repeated calls to cp_httpclient_fetch_nb_exec() until all transfers complete. cp_httpclient_fetch_nb_next() returns the number of active transfers. cp_httpclient_fetch_nb returns zero if the request could be registered, non-zero otherwise.
References cp_httpclient_fetch_ctl().
CPROPS_DLL int cp_httpclient_fetch_nb_exec | ( | ) |
non-blocking fetches executing in the foreground must be driven by calls to cp_httpclient_fetch_nb_exec().
The callback for each request is made once it completes or if an error occurs. cp_httplcient_fetch_nb_exec() returns the number of active requests. Zero indicates all transfers have completed.
References cp_httpclient_fetch_ctl_exec().
CPROPS_DLL int cp_httpclient_reopen | ( | cp_httpclient * | client, | |
char * | host, | |||
int | port | |||
) |
use the same wrapper for a different address.
this will close an existing connection, change the host and port settings on the wrapper and attempt to connect. maybe rename this function.
References cp_client_reopen().
CPROPS_DLL void cp_httpclient_set_header | ( | cp_httpclient * | client, | |
char * | header, | |||
char * | value | |||
) |
set an arbitrary header.
Any existing value is overriden.
References cp_hashtable_put(), and cp_hashtable_remove().
CPROPS_DLL void cp_httpclient_set_request_type | ( | cp_httpclient * | client, | |
cp_http_request_type | type | |||
) |
set the request type for subsequent requests.
GET by default.
CPROPS_DLL void cp_httpclient_set_user_agent | ( | cp_httpclient * | client, | |
char * | agent | |||
) |
set a value for the 'User-Agent' header.
Default is libcprops-(version)
References cp_hashtable_put().
CPROPS_DLL void cp_httpsocket_set_delay_usec | ( | cp_httpsocket * | socket, | |
long | usec | |||
) |
set micro sec.
to block in accept()
CPROPS_DLL int cp_socket_listen | ( | cp_socket * | sock | ) |
cp_socket_listen attempts to create a SOCK_STREAM socket with socket(), bind to a local port with bind(), and set the socket to listen for connections with listen().
bind socket
char* cp_http_request_type_lit[] [static] |
{ "OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT" }
int cp_http_server_error_code[] [static] |
{ CP_HTTP_EMPTY_REQUEST, CP_HTTP_INVALID_REQUEST_LINE, CP_HTTP_UNKNOWN_REQUEST_TYPE, CP_HTTP_INVALID_URI, CP_HTTP_VERSION_NOT_SPECIFIED, CP_HTTP_1_1_HOST_NOT_SPECIFIED, CP_HTTP_INCORRECT_REQUEST_BODY_LENGTH, -1 }
char* cp_http_server_error_lit[] [static] |
{ "EMPTY REQUEST", "INVALID REQUEST LINE", "UNKNOWN REQUEST TYPE", "INVALID URI", "VERSION NOT SPECIFIED", "HTTP/1.1 HOST NOT SPECIFIED", "INCORRECT REQUEST BODY LENGTH" }