lander/lnm/src/_include/lnm/http/loop_internal.h

70 lines
1.7 KiB
C

#ifndef LNM_HTTP_LOOP_INTERNAL
#define LNM_HTTP_LOOP_INTERNAL
#include <regex.h>
#include "lnm/http/loop.h"
typedef struct lnm_http_step {
lnm_http_step_fn fn;
struct lnm_http_step *next;
} lnm_http_step;
typedef enum lnm_http_route_type {
lnm_http_route_type_literal = 0,
lnm_http_route_type_regex,
} lnm_http_route_type;
typedef struct lnm_http_route {
union {
regex_t *regex;
const char *s;
} route;
lnm_http_method method;
lnm_http_route_type type;
int regex_group_count;
lnm_http_step *step;
} lnm_http_route;
/**
* Initialize a new empty route.
*
* @param out where to store pointer to new `lnm_http_route`
*/
lnm_err lnm_http_route_init(lnm_http_route **out);
/**
* Initialize a first step.
*
* @param out where to store pointer to new `lnm_http_step`
* @param fn step function associated with the step
*/
lnm_err lnm_http_step_init(lnm_http_step **out, lnm_http_step_fn fn);
/**
* Initialize a new global context object.
*
* @param out where to store pointer to new `lnm_http_loop_gctx`
*/
lnm_err lnm_http_loop_gctx_init(lnm_http_loop_gctx **out, void *c_gctx,
lnm_http_ctx_init_fn ctx_init,
lnm_http_ctx_reset_fn ctx_reset,
lnm_http_ctx_free_fn ctx_free);
/**
* Initialize a new context.
*
* @param out where to store pointer to new object
* @param gctx global context for the loop
*/
lnm_err lnm_http_loop_ctx_init(lnm_http_loop_ctx **out,
lnm_http_loop_gctx *gctx);
void lnm_http_loop_ctx_reset(lnm_http_loop_ctx *ctx);
void lnm_http_loop_ctx_free(lnm_http_loop_ctx *ctx);
void lnm_http_loop_process(lnm_http_conn *conn);
#endif