#ifndef EVAPP_API_H #define EVAPP_API_H #define EVAPP_URIMAP_EXACT 1 #define EVAPP_URIMAP_PREFIX 2 #define EVAPP_VERSION "0.0.1" #include #include #include #include #include #include #include typedef struct evapp_context* evapp_ctx; /* This must match the evapp.h exactly */ typedef struct evapp_db_index { TAILQ_ENTRY(evapp_db_index) entries; char *field; char *file; char *type; int (*callback)(DB*, const DBT*, const DBT*, DBT*); DB *p; } evapp_db_index; TAILQ_HEAD (evapp_db_indexq, evapp_db_index); typedef struct evapp_db { TAILQ_ENTRY(evapp_db) entries; char *name; char *file; DB *p; bool (*load)(evapp_ctx *ctx, u_int64_t id, HDF **hdf); bool (*save)(evapp_ctx *ctx, u_int64_t id, HDF *hdf); bool (*del)(evapp_ctx *ctx, u_int64_t id); bool (*validate)(evapp_ctx *ctx, HDF *hdf); bool (*hdf)(evapp_ctx *ctx, void *data, size_t len, HDF **hdf); bool (*hdf_template)(evapp_ctx *ctx, HDF **hdf); bool (*cleanup)(void); struct evapp_db_indexq indices; } evapp_db; TAILQ_HEAD (evapp_dbq, evapp_db); evapp_ctx *evapp_new(const char *const name, void *app_state); bool evapp_dbenv_init(evapp_ctx *ctx, const char *const path); bool evapp_bind(evapp_ctx *ctx, const char *const bindaddr, uint16_t port); bool evapp_db_add_index(evapp_ctx *ctx, evapp_db *db, const char *field, const char *type, const char *file, int (*callback)(DB*, const DBT*, const DBT*, DBT*)); bool evapp_db_add(evapp_ctx *ctx, const char *const name, const char *const table, bool (*load)(evapp_ctx*, u_int64_t, HDF**), bool (*save)(evapp_ctx*, u_int64_t, HDF*), bool (*del)(evapp_ctx*, u_int64_t), bool (*hdf)(evapp_ctx*, void*, size_t, HDF**), bool (*hdf_template)(evapp_ctx*, HDF**), bool (*hdf_cleanup)(evapp_ctx*), bool (*validate)(evapp_ctx*, HDF*)); struct evapp_dbq *evapp_db_head(evapp_ctx *ctx); bool evapp_db_set_validate(evapp_ctx *ctx, const char *dbname, bool (*validate)(evapp_ctx*, HDF*)); struct evapp_db *evapp_db_select(evapp_ctx *ctx, const char *const name); struct evapp_db_index *evapp_db_index_first(evapp_ctx *ctx, struct evapp_db *db); struct evapp_db_index *evapp_db_index_select(evapp_ctx *ctx, struct evapp_db *db, const char *const name); int evapp_register_handler(evapp_ctx *ctx, short type, const char *const uri, void (*handler)(evapp_ctx *)); void evapp_serve(); void evapp_destroy(evapp_ctx *ctx); void *evapp_get_state(evapp_ctx *ctx); bool evapp_set_state(evapp_ctx *ctx, void *state); bool evapp_register_not_found(evapp_ctx *ctx, void *state); /* XXX: Move these to settings? */ bool evapp_set_default_domain(evapp_ctx *ctx, const char *domain); const char *evapp_get_default_domain(evapp_ctx *ctx); bool evapp_get_debug_mode(evapp_ctx *ctx); bool evapp_set_debug_mode(evapp_ctx *ctx, bool debug); bool evapp_set_default_templates(evapp_ctx *ctx, bool value); bool evapp_get_default_templates(evapp_ctx *ctx); bool evapp_get_xsrf_protection(evapp_ctx *ctx); bool evapp_set_xsrf_protection(evapp_ctx *ctx, bool value); bool evapp_get_scaffold(evapp_ctx *ctx); bool evapp_set_scaffold(evapp_ctx *ctx, bool value); bool evapp_get_readonly(evapp_ctx *ctx); bool evapp_set_readonly(evapp_ctx *ctx, bool value); struct evbuffer *evapp_response(evapp_ctx *ctx); struct evhttp_request *evapp_request(evapp_ctx *ctx); #endif