diff options
Diffstat (limited to 'src/libfast')
-rw-r--r-- | src/libfast/context.h | 2 | ||||
-rw-r--r-- | src/libfast/controller.h | 6 | ||||
-rw-r--r-- | src/libfast/dispatcher.c | 64 | ||||
-rw-r--r-- | src/libfast/dispatcher.h | 28 | ||||
-rw-r--r-- | src/libfast/filter.h | 4 | ||||
-rw-r--r-- | src/libfast/request.c | 48 | ||||
-rw-r--r-- | src/libfast/request.h | 36 | ||||
-rw-r--r-- | src/libfast/session.c | 24 | ||||
-rw-r--r-- | src/libfast/session.h | 10 |
9 files changed, 111 insertions, 111 deletions
diff --git a/src/libfast/context.h b/src/libfast/context.h index 48b3c5e23..4f8d11d2c 100644 --- a/src/libfast/context.h +++ b/src/libfast/context.h @@ -32,7 +32,7 @@ typedef context_t *(*context_constructor_t)(void *param); * User specific session context, to extend. */ struct context_t { - + /** * Destroy the context_t. */ diff --git a/src/libfast/controller.h b/src/libfast/controller.h index 55ba6f58a..1edf72e90 100644 --- a/src/libfast/controller.h +++ b/src/libfast/controller.h @@ -42,14 +42,14 @@ typedef controller_t *(*controller_constructor_t)(context_t* context, void *para * The controller handle function is called for each incoming request. */ struct controller_t { - + /** * Get the name of the controller. * * @return name of the controller */ char* (*get_name)(controller_t *this); - + /** * Handle a HTTP request for that controller. * @@ -67,7 +67,7 @@ struct controller_t { */ void (*handle)(controller_t *this, request_t *request, char *p1, char *p2, char *p3, char *p4, char *p5); - + /** * Destroy the controller instance. */ diff --git a/src/libfast/dispatcher.c b/src/libfast/dispatcher.c index 9f4cc014a..bae6a28e8 100644 --- a/src/libfast/dispatcher.c +++ b/src/libfast/dispatcher.c @@ -37,57 +37,57 @@ struct private_dispatcher_t { * public functions */ dispatcher_t public; - + /** * fcgi socket fd */ int fd; - + /** * thread list */ pthread_t *threads; - + /** * number of threads in "threads" */ int thread_count; - + /** * session locking mutex */ pthread_mutex_t mutex; - + /** * List of sessions */ linked_list_t *sessions; - + /** * session timeout */ time_t timeout; - + /** * running in debug mode? */ bool debug; - + /** * List of controllers controller_constructor_t */ linked_list_t *controllers; - + /** * List of filters filter_constructor_t */ linked_list_t *filters; - - /** + + /** * constructor function to create session context (in controller_entry_t) */ context_constructor_t context_constructor; - + /** * user param to context constructor */ @@ -135,13 +135,13 @@ static session_t* load_session(private_dispatcher_t *this) context_t *context = NULL; controller_t *controller; filter_t *filter; - + if (this->context_constructor) { context = this->context_constructor(this->param); } session = session_create(context); - + iterator = this->controllers->create_iterator(this->controllers, TRUE); while (iterator->iterate(iterator, (void**)¢ry)) { @@ -149,7 +149,7 @@ static session_t* load_session(private_dispatcher_t *this) session->add_controller(session, controller); } iterator->destroy(iterator); - + iterator = this->filters->create_iterator(this->filters, TRUE); while (iterator->iterate(iterator, (void**)&fentry)) { @@ -157,7 +157,7 @@ static session_t* load_session(private_dispatcher_t *this) session->add_filter(session, filter); } iterator->destroy(iterator); - + return session; } @@ -168,7 +168,7 @@ static session_entry_t *session_entry_create(private_dispatcher_t *this, char *host) { session_entry_t *entry; - + entry = malloc_thing(session_entry_t); entry->in_use = FALSE; entry->closed = FALSE; @@ -176,7 +176,7 @@ static session_entry_t *session_entry_create(private_dispatcher_t *this, entry->session = load_session(this); entry->used = time_monotonic(NULL); entry->host = strdup(host); - + return entry; } @@ -194,7 +194,7 @@ static void add_controller(private_dispatcher_t *this, controller_constructor_t constructor, void *param) { controller_entry_t *entry = malloc_thing(controller_entry_t); - + entry->constructor = constructor; entry->param = param; this->controllers->insert_last(this->controllers, entry); @@ -207,14 +207,14 @@ static void add_filter(private_dispatcher_t *this, filter_constructor_t constructor, void *param) { filter_entry_t *entry = malloc_thing(filter_entry_t); - + entry->constructor = constructor; entry->param = param; this->filters->insert_last(this->filters, entry); } /** - * Actual dispatching code + * Actual dispatching code */ static void dispatch(private_dispatcher_t *this) { @@ -227,7 +227,7 @@ static void dispatch(private_dispatcher_t *this) iterator_t *iterator; time_t now; char *sid; - + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); request = request_create(this->fd, this->debug); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); @@ -238,13 +238,13 @@ static void dispatch(private_dispatcher_t *this) } sid = request->get_cookie(request, "SID"); now = time_monotonic(NULL); - + /* find session */ pthread_mutex_lock(&this->mutex); iterator = this->sessions->create_iterator(this->sessions, TRUE); while (iterator->iterate(iterator, (void**)¤t)) { - /* check all sessions for timeout or close flag + /* check all sessions for timeout or close flag * TODO: use a seperate cleanup thread */ if (!current->in_use && (current->used < now - this->timeout || current->closed)) @@ -262,7 +262,7 @@ static void dispatch(private_dispatcher_t *this) } } iterator->destroy(iterator); - + if (found) { /* wait until session is unused */ @@ -278,18 +278,18 @@ static void dispatch(private_dispatcher_t *this) } found->in_use = TRUE; pthread_mutex_unlock(&this->mutex); - + /* start processing */ found->session->process(found->session, request); found->used = time_monotonic(NULL); - + /* release session */ pthread_mutex_lock(&this->mutex); found->in_use = FALSE; found->closed = request->session_closed(request); pthread_cond_signal(&found->cond); pthread_mutex_unlock(&this->mutex); - + /* cleanup */ request->destroy(request); } @@ -319,7 +319,7 @@ static void waitsignal(private_dispatcher_t *this) { sigset_t set; int sig; - + sigemptyset(&set); sigaddset(&set, SIGINT); sigaddset(&set, SIGTERM); @@ -359,7 +359,7 @@ dispatcher_t *dispatcher_create(char *socket, bool debug, int timeout, this->public.run = (void(*)(dispatcher_t*, int threads))run; this->public.waitsignal = (void(*)(dispatcher_t*))waitsignal; this->public.destroy = (void(*)(dispatcher_t*))destroy; - + this->sessions = linked_list_create(); this->controllers = linked_list_create(); this->filters = linked_list_create(); @@ -370,9 +370,9 @@ dispatcher_t *dispatcher_create(char *socket, bool debug, int timeout, this->timeout = timeout; this->debug = debug; this->threads = NULL; - + FCGX_Init(); - + if (socket) { unlink(socket); diff --git a/src/libfast/dispatcher.h b/src/libfast/dispatcher.h index 5b4e3f947..17a288b8f 100644 --- a/src/libfast/dispatcher.h +++ b/src/libfast/dispatcher.h @@ -23,33 +23,33 @@ * the webserver. It is multithreaded and really fast. * * The application has a global context and a session context. The global - * context is accessed from all sessions simultaneously and therefore + * context is accessed from all sessions simultaneously and therefore * needs to be threadsave. Often a database wrapper is the global context. * The session context is instanciated per session. Sessions are managed * automatically through session cookies. The session context is kept alive * until the session times out. It must implement the context_t interface and - * a #context_constructor_t is needed to create instances. To each session, - * a set of controllers gets instanciated. The controller instances are per + * a #context_constructor_t is needed to create instances. To each session, + * a set of controllers gets instanciated. The controller instances are per * session, so you can hold private data for each user. - * Controllers need to implement the controller_t interface and need a + * Controllers need to implement the controller_t interface and need a * #controller_constructor_t function to create instances. * * A small example shows how to set up libfast: * @code dispatcher_t *dispatcher; your_global_context_implementation_t *global; - + global = initialize_your_global_context(); - + dispatcher = dispatcher_create(NULL, FALSE, 180, (context_constructor_t)your_session_context_create, global); dispatcher->add_controller(dispatcher, your_controller1_create, param1); dispatcher->add_controller(dispatcher, your_controller2_create, param2); - + dispatcher->run(dispatcher, 20); - + dispatcher->waitsignal(dispatcher); - + dispatcher->destroy(dispatcher); global->destroy(); @endcode @@ -76,7 +76,7 @@ typedef struct dispatcher_t dispatcher_t; * constructor added with add_controller. */ struct dispatcher_t { - + /** * Register a controller to the dispatcher. * @@ -96,8 +96,8 @@ struct dispatcher_t { * @param param param to pass to constructor */ void (*add_filter)(dispatcher_t *this, - filter_constructor_t constructor, void *param); - + filter_constructor_t constructor, void *param); + /** * Start with dispatching. * @@ -106,13 +106,13 @@ struct dispatcher_t { * @param threads number of dispatching threads */ void (*run)(dispatcher_t *this, int threads); - + /** * Wait for a relevant signal action. * */ void (*waitsignal)(dispatcher_t *this); - + /** * Destroy the dispatcher_t. */ diff --git a/src/libfast/filter.h b/src/libfast/filter.h index d2602db9d..305a8bb6e 100644 --- a/src/libfast/filter.h +++ b/src/libfast/filter.h @@ -39,7 +39,7 @@ typedef filter_t *(*filter_constructor_t)(context_t* context, void *param); * Filter interface, to be implemented by users filters. */ struct filter_t { - + /** * Called before the controller handles the request. * @@ -53,7 +53,7 @@ struct filter_t { */ bool (*run)(filter_t *this, request_t *request, char *p0, char *p1, char *p2, char *p3, char *p4, char *p5); - + /** * Destroy the filter instance. */ diff --git a/src/libfast/request.c b/src/libfast/request.c index 96dfab8e7..1e4badaeb 100644 --- a/src/libfast/request.c +++ b/src/libfast/request.c @@ -35,32 +35,32 @@ struct private_request_t { * public functions */ request_t public; - + /** * FastCGI request object */ FCGX_Request req; - + /** * length of the req.envp array */ int req_env_len; - + /** * ClearSilver CGI Kit context */ CGI *cgi; - + /** * ClearSilver HDF dataset for this request */ HDF *hdf; - - /** + + /** * close the session? */ bool closed; - + /** * reference count */ @@ -85,7 +85,7 @@ pthread_once_t once = PTHREAD_ONCE_INIT; static int read_cb(void *null, char *buf, int size) { private_request_t *this = (private_request_t*)pthread_getspecific(this_key); - + return FCGX_GetStr(buf, size, this->req.in); } @@ -95,7 +95,7 @@ static int read_cb(void *null, char *buf, int size) static int writef_cb(void *null, const char *format, va_list args) { private_request_t *this = (private_request_t*)pthread_getspecific(this_key); - + FCGX_VFPrintF(this->req.out, format, args); return 0; } @@ -105,7 +105,7 @@ static int writef_cb(void *null, const char *format, va_list args) static int write_cb(void *null, const char *buf, int size) { private_request_t *this = (private_request_t*)pthread_getspecific(this_key); - + return FCGX_PutStr(buf, size, this->req.out); } @@ -116,7 +116,7 @@ static char *getenv_cb(void *null, const char *key) { char *value; private_request_t *this = (private_request_t*)pthread_getspecific(this_key); - + value = FCGX_GetParam(key, this->req.envp); return value ? strdup(value) : NULL; } @@ -157,7 +157,7 @@ static int iterenv_cb(void *null, int num, char **key, char **value) } return 0; } - + /** * Implementation of request_t.get_cookie. */ @@ -165,7 +165,7 @@ static char* get_cookie(private_request_t *this, char *name) { return hdf_get_valuef(this->hdf, "Cookie.%s", name); } - + /** * Implementation of request_t.get_path. */ @@ -211,7 +211,7 @@ static void add_cookie(private_request_t *this, char *name, char *value) FCGX_GetParam("SCRIPT_NAME", this->req.envp), NULL, NULL, 0, 0); } - + /** * Implementation of request_t.redirect. */ @@ -246,7 +246,7 @@ static char* get_base(private_request_t *this) { return FCGX_GetParam("SCRIPT_NAME", this->req.envp); } - + /** * Implementation of request_t.session_closed. */ @@ -279,7 +279,7 @@ static void serve(private_request_t *this, char *headers, chunk_t chunk) static void render(private_request_t *this, char *template) { NEOERR* err; - + pthread_setspecific(this_key, this); err = cgi_display(this->cgi, template); if (err) @@ -327,8 +327,8 @@ static void setf(private_request_t *this, char *format, ...) va_start(args, format); hdf_set_valuevf(this->hdf, format, args); va_end(args); -} - +} + /** * Implementation of request_t.get_ref. */ @@ -371,7 +371,7 @@ request_t *request_create(int fd, bool debug) NEOERR* err; private_request_t *this = malloc_thing(private_request_t); bool failed = FALSE; - + pthread_cleanup_push(free, this); if (FCGX_InitRequest(&this->req, fd, 0) != 0 || FCGX_Accept_r(&this->req) != 0) @@ -402,18 +402,18 @@ request_t *request_create(int fd, bool debug) this->public.setf = (void(*)(request_t*, char *format, ...))setf; this->public.get_ref = (request_t*(*)(request_t*))get_ref; this->public.destroy = (void(*)(request_t*))destroy; - + pthread_once(&once, init); pthread_setspecific(this_key, this); - + this->ref = 1; this->closed = FALSE; - this->req_env_len = 0; + this->req_env_len = 0; while (this->req.envp[this->req_env_len] != NULL) { this->req_env_len++; } - + err = hdf_init(&this->hdf); if (!err) { @@ -425,7 +425,7 @@ request_t *request_create(int fd, bool debug) hdf_set_value(this->hdf, "Config.CompressionEnabled", "1"); hdf_set_value(this->hdf, "Config.WhiteSpaceStrip", "2"); } - + err = cgi_init(&this->cgi, this->hdf); if (!err) { diff --git a/src/libfast/request.h b/src/libfast/request.h index b9ea88830..61e2d59f0 100644 --- a/src/libfast/request.h +++ b/src/libfast/request.h @@ -32,7 +32,7 @@ typedef struct request_t request_t; * The response is also handled through the request object. */ struct request_t { - + /** * Add a cookie to the reply (Set-Cookie header). * @@ -40,7 +40,7 @@ struct request_t { * @param value value of the cookie */ void (*add_cookie)(request_t *this, char *name, char *value); - + /** * Get a cookie the client sent in the request. * @@ -48,35 +48,35 @@ struct request_t { * @return cookie value, NULL if no such cookie found */ char* (*get_cookie)(request_t *this, char *name); - + /** * Get the request path relative to the application. * * @return path */ char* (*get_path)(request_t *this); - + /** * Get the base path of the application. * * @return base path */ char* (*get_base)(request_t *this); - + /** * Get the remote host address of this request. * * @return host address as string */ char* (*get_host)(request_t *this); - + /** * Get the user agent string. * * @return user agent string */ char* (*get_user_agent)(request_t *this); - + /** * Get a post/get variable included in the request. * @@ -84,19 +84,19 @@ struct request_t { * @return value, NULL if not found */ char* (*get_query_data)(request_t *this, char *name); - + /** * Close the session and it's context after handling. */ void (*close_session)(request_t *this); - + /** * Has the session been closed by close_session()? * * @return TRUE if session has been closed */ bool (*session_closed)(request_t *this); - + /** * Redirect the client to another location. * @@ -104,12 +104,12 @@ struct request_t { * @param ... variable argument for fmt */ void (*redirect)(request_t *this, char *fmt, ...); - + /** * Redirect the client to the referer. */ void (*to_referer)(request_t *this); - + /** * Set a template value. * @@ -117,7 +117,7 @@ struct request_t { * @param value value to set key to */ void (*set)(request_t *this, char *key, char *value); - + /** * Set a template value using format strings. * @@ -128,7 +128,7 @@ struct request_t { * @param ... variable argument list */ void (*setf)(request_t *this, char *format, ...); - + /** * Render a template. * @@ -139,7 +139,7 @@ struct request_t { * @param template clearsilver template file location */ void (*render)(request_t *this, char *template); - + /** * Stream a format string to the client. * @@ -151,7 +151,7 @@ struct request_t { * @return number of streamed bytes, < 0 if stream closed */ int (*streamf)(request_t *this, char *format, ...); - + /** * Serve a request with headers and a body. * @@ -159,14 +159,14 @@ struct request_t { * @param chunk body to write to output */ void (*serve)(request_t *this, char *headers, chunk_t chunk); - + /** * Increase the reference count to the stream. * * @return this with increased refcount */ request_t* (*get_ref)(request_t *this); - + /** * Destroy the request_t. */ diff --git a/src/libfast/session.c b/src/libfast/session.c index 455c8d5e1..39c01c394 100644 --- a/src/libfast/session.c +++ b/src/libfast/session.c @@ -34,22 +34,22 @@ struct private_session_t { * public functions */ session_t public; - + /** * session ID */ char *sid; - + /** * list of controller instances controller_t */ linked_list_t *controllers; - + /** * list of filter instances filter_t */ linked_list_t *filters; - + /** * user defined session context */ @@ -80,7 +80,7 @@ static void create_sid(private_session_t *this, request_t *request) char buf[16]; chunk_t chunk = chunk_from_buf(buf); rng_t *rng; - + rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK); if (rng) { @@ -99,7 +99,7 @@ static bool run_filter(private_session_t *this, request_t *request, char *p0, { enumerator_t *enumerator; filter_t *filter; - + enumerator = this->filters->create_enumerator(this->filters); while (enumerator->enumerate(enumerator, &filter)) { @@ -123,12 +123,12 @@ static void process(private_session_t *this, request_t *request) bool handled = FALSE; controller_t *current; int i = 0; - + if (this->sid == NULL) { create_sid(this, request); } - + start = request->get_path(request); if (start) { @@ -142,15 +142,15 @@ static void process(private_session_t *this, request_t *request) start = pos + 1; } param[i] = strdupa(start); - - if (run_filter(this, request, param[0], param[1], param[2], param[3], + + if (run_filter(this, request, param[0], param[1], param[2], param[3], param[4], param[5])) { enumerator = this->controllers->create_enumerator(this->controllers); while (enumerator->enumerate(enumerator, ¤t)) { if (streq(current->get_name(current), param[0])) - { + { current->handle(current, request, param[1], param[2], param[3], param[4], param[5]); handled = TRUE; @@ -211,7 +211,7 @@ session_t *session_create(context_t *context) this->controllers = linked_list_create(); this->filters = linked_list_create(); this->context = context; - + return &this->public; } diff --git a/src/libfast/session.h b/src/libfast/session.h index 524e60f46..bd35de31a 100644 --- a/src/libfast/session.h +++ b/src/libfast/session.h @@ -31,35 +31,35 @@ typedef struct session_t session_t; * Session handling class, instanciated for each user session. */ struct session_t { - + /** * Get the session ID of the session. * * @return session ID */ char* (*get_sid)(session_t *this); - + /** * Add a controller instance to the session. * * @param controller controller to add */ void (*add_controller)(session_t *this, controller_t *controller); - + /** * @brief Add a filter instance to the session. * * @param filter filter to add */ void (*add_filter)(session_t *this, filter_t *filter); - + /** * Process a request in this session. * * @param request request to process */ void (*process)(session_t *this, request_t *request); - + /** * Destroy the session_t. * |