basic http feature implementations. More...
#include "config.h"
#include "common.h"
#include "hashtable.h"
#include "trie.h"
#include "vector.h"
#include "socket.h"
#include "str.h"
#include <string.h>
#include <time.h>
Go to the source code of this file.
Data Structures | |
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... | |
Defines | |
#define | DEFAULT_SERVER_NAME "libcprops-0.1.8" |
#define | DEFAULT_KEEPALIVE 300 |
#define | HTTP_KEEPALIVE DEFAULT_KEEPALIVE |
#define | MAX_URL_LENGTH 0x400 |
Typedefs | |
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 | |
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 } |
Functions | |
char * | get_http_request_type_lit (cp_http_request_type type) |
int | cp_http_init () |
recommended to call before using cp_httpsocket api | |
void | cp_http_shutdown () |
call to perform cleanup after using cp_httpsocket api | |
CPROPS_DLL cp_http_request * | cp_http_request_parse (struct _cp_httpsocket *owner, char *request, int *err) |
parse an http request | |
void | cp_http_request_delete (cp_http_request *request) |
deallocate an http request descriptor | |
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 | |
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 | |
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. | |
void | cp_http_response_report_error (cp_http_response *response, cp_http_status_code code, char *message) |
set up a response reporting an error | |
void * | cp_http_thread_fn (void *prm) |
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_delete (cp_httpsocket *svc) |
deallocate a cp_httpsocket structure | |
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_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 | |
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 | |
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 | |
void * | cp_http_add_shutdown_callback (void(*cb)(void *), void *prm) |
called when shutting down http layer | |
Variables | |
__BEGIN_DECLS typedef CPROPS_DLL enum { ... } | cp_http_request_type |
HTTP request types. | |
struct CPROPS_DLL | _cp_httpsocket |
basic http feature implementations.
the intention is to offer a simple way of providing services to http based clients.