http framework implementation More...
#include "http.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include "hashtable.h"
#include "hashlist.h"
#include "trie.h"
#include "vector.h"
#include "log.h"
#include "util.h"
#include "socket.h"
Data Structures | |
struct | cp_http_status_code_entry |
Defines | |
#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) |
Functions | |
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) |
Variables | |
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 |
http framework implementation