WEBBY - the embedded web server with many faces / objects in plain C Snapshot
|
embedded web server facade class. More...
Classes | |
struct | tagWEBBY |
struct | tagWEBBY_CONNECTION |
Defines | |
#define | HTTP_PARSER_BUFFER_SIZE 4096 |
Typedefs | |
typedef struct tagWEBBY | WEBBY |
typedef struct tagWEBBY_CONNECTION | WEBBY_CONNECTION |
Functions | |
WEBBY * | WEBBY_init (WEBBY_CONFIG *) |
int | WEBBY_add_vhost (WEBBY *server, const char *host, int port_num, size_t *vhost_idx) |
int | WEBBY_add_filter (WEBBY *server, size_t vhost_idx, HTTP_FILTER *filter) |
int | WEBBY_add_servlet (WEBBY *server, HTTP_SERVLET *servlet) |
int | WEBBY_run (WEBBY *server) |
int | WEBBY_shutdown (WEBBY *server) |
WEBBY_CONNECTION * | WEBBY_new_connection (WEBBY *server, void *implconndata) |
int | WEBBY_connection_data_received (WEBBY_CONNECTION *connection) |
void | WEBBY_connection_close (WEBBY_CONNECTION *connection) |
embedded web server facade class.
typedef struct tagWEBBY_CONNECTION WEBBY_CONNECTION |
int WEBBY_add_filter | ( | WEBBY * | server, |
size_t | vhost_idx, | ||
HTTP_FILTER * | filter | ||
) |
Definition at line 682 of file webby.c.
{ return DATA_SINK_FILTER_add_filter_to_vhost( server->sink_filter, vhost_idx, filter ); }
int WEBBY_add_servlet | ( | WEBBY * | server, |
HTTP_SERVLET * | servlet | ||
) |
Definition at line 687 of file webby.c.
{ return SERVLET_RUNNER_FILTER_add_servlet( server->servlet_runner_filter, servlet ); }
int WEBBY_add_vhost | ( | WEBBY * | server, |
const char * | host, | ||
int | port_num, | ||
size_t * | vhost_idx | ||
) |
Definition at line 677 of file webby.c.
{ return DATA_SINK_FILTER_add_vhost( server->sink_filter, host, port_num, vhost_idx ); }
void WEBBY_connection_close | ( | WEBBY_CONNECTION * | connection | ) |
Definition at line 836 of file webby.c.
{ FILTER_CONTEXT *ctx; size_t i; if (!connection->filter_data) { return; } for( ctx = connection->filter_data, i = 0; i < connection->num_filters ; ++ctx, ++i ) { ctx->filter->on_connection_close( ctx ); } free( connection->filter_data ); connection->filter_data = 0; }
int WEBBY_connection_data_received | ( | WEBBY_CONNECTION * | connection | ) |
Definition at line 817 of file webby.c.
{ PARSER_STATUS st; st = HTTP_REQUEST_PARSER_process( &connection->request_parser, &connection->request, &connection->in_buf ); switch( st ) { case PARSER_STATUS_ERROR: MLOG_INFO( "Error during parsing of HTTP header" ); return -1; case PARSER_STATUS_COMPLETED: HTTP_REQUEST_init( &connection->request ); BF_put_mode( &connection->in_buf ); break; case PARSER_STATUS_NEED_MORE_DATA: break; } return 0; }
WEBBY* WEBBY_init | ( | WEBBY_CONFIG * | ) |
Definition at line 640 of file webby.c.
{ WEBBY *ret; DATA_SINK_FILTER *data_sink; ret = (WEBBY *) malloc( sizeof( WEBBY ) ); if (!ret) { return 0; } ret->cfg = cfg; if ( ARRAY_init( &ret->filters, sizeof( HTTP_FILTER * ), 10 ) ) { return 0; } // first filter is sink filter - receives response data. data_sink = DATA_SINK_FILTER_init( ret ); if (!data_sink) { return 0; } ARRAY_push_back( &ret->filters, &data_sink, sizeof( void * ) ); ret->sink_filter = data_sink; ret->servlet_runner_filter = SERVLET_RUNNER_FILTER_init(); if (!ret->servlet_runner_filter) { return 0; } // get the implementation object. if (WEBBY_impl_new( ret, cfg, &ret->impl ) ) { return 0; } return ret; }
WEBBY_CONNECTION* WEBBY_new_connection | ( | WEBBY * | server, |
void * | implconndata | ||
) |
Definition at line 755 of file webby.c.
{ WEBBY_CONNECTION *ret = 0; FILTER_CONTEXT *filter_data = 0; void *buff = 0; DATA_SINK_FILTER_CONNECTION_CONTEXT *sink_conn_ctx = 0; ret = (WEBBY_CONNECTION *) malloc( sizeof(WEBBY_CONNECTION) ); if (!ret) { goto err; } buff = malloc( HTTP_PARSER_BUFFER_SIZE ); if (!buff) { goto err; } BF_init( &ret->in_buf, buff, HTTP_PARSER_BUFFER_SIZE); filter_data = (FILTER_CONTEXT *) malloc( server->filter_ctx_layout_size ); if (!filter_data) { goto err; } memcpy( filter_data, server->filter_ctx_layout, server->filter_ctx_layout_size ); ret->num_filters = ARRAY_size( &server->filters ); ret->filter_data = filter_data; sink_conn_ctx = DATA_SINK_FILTER_CONNECTION_CONTEXT_init( implconndata, &ret->in_buf ); if (! sink_conn_ctx) { goto err; } filter_data->connection_ctx = sink_conn_ctx; HTTP_REQUEST_PARSER_init( &ret->request_parser, http_header_parsed, http_on_message_data, http_req_finished, filter_data); HTTP_REQUEST_init( &ret->request ); return ret; err: if (filter_data) { free(filter_data); } if (buff) { free(buff); } if (ret) { free(ret); } if (sink_conn_ctx) { DATA_SINK_FILTER_CONNECTION_CONTEXT_free( implconndata ); } return 0; }
int WEBBY_run | ( | WEBBY * | server | ) |
Definition at line 693 of file webby.c.
{ FILTER_CONTEXT *cur,*layout; HTTP_FILTER **tmp; size_t i; if (WEBBY_add_filter( server, 0, &server->servlet_runner_filter->base ) ) { return -1; } server->filter_ctx_layout_size = sizeof( FILTER_CONTEXT ) * ARRAY_size( &server->filters ); layout = (FILTER_CONTEXT *) malloc( server->filter_ctx_layout_size ); if (! layout ) { return -1; } server->filter_ctx_layout = layout; for(i = 0, cur = (FILTER_CONTEXT *) layout; i < ARRAY_size( &server->filters ); cur++, i++ ) { cur->connection_ctx = 0; tmp = (HTTP_FILTER **) ARRAY_at( &server->filters, i ); cur->filter = *tmp; cur->next_request_filter_idx = cur->filter->next_request_filter_idx - i; cur->next_response_filter_idx = i - cur->filter->next_response_filter_idx; } return WEBBY_impl_run( server->impl ); }
int WEBBY_shutdown | ( | WEBBY * | server | ) |
Definition at line 722 of file webby.c.
{ return WEBBY_impl_shutdown( server->impl ); }