2
0
Fork 0
lighttpd2/include/lighttpd/plugin.h

167 lines
5.6 KiB
C
Raw Normal View History

2008-06-28 18:37:28 +00:00
#ifndef _LIGHTTPD_PLUGIN_H_
#define _LIGHTTPD_PLUGIN_H_
2008-06-24 19:19:20 +00:00
#ifndef _LIGHTTPD_BASE_H_
#error Please include <lighttpd/base.h> instead of this file
#endif
2008-06-24 19:19:20 +00:00
#define INIT_FUNC(x) \
LI_EXPORT void * x(server *srv, plugin *)
#define PLUGIN_DATA \
size_t id; \
ssize_t option_base_ndx
typedef void (*liPluginInitCB) (liServer *srv, liPlugin *p);
typedef void (*liPluginFreeCB) (liServer *srv, liPlugin *p);
typedef gboolean (*liPluginParseOptionCB) (liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval);
typedef void (*liPluginFreeOptionCB) (liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval);
typedef liAction*(*liPluginCreateActionCB) (liServer *srv, liPlugin *p, liValue *val);
typedef gboolean (*liPluginSetupCB) (liServer *srv, liPlugin *p, liValue *val);
2009-08-30 17:25:01 +00:00
typedef void (*liPluginAngelCB) (liServer *srv, liPlugin *p, gint32 id, GString *data);
typedef void (*liPluginHandleCloseCB) (liConnection *con, liPlugin *p);
typedef liHandlerResult(*liPluginHandleVRequestCB)(liVRequest *vr, liPlugin *p);
typedef void (*liPluginHandleVRCloseCB) (liVRequest *vr, liPlugin *p);
struct liPlugin {
2008-06-24 19:19:20 +00:00
size_t version;
2008-07-23 16:01:19 +00:00
const gchar *name; /**< name of the plugin */
guint id; /**< index in some plugin arrays */
2008-06-24 19:19:20 +00:00
gpointer data; /**< private plugin data */
2008-06-24 19:19:20 +00:00
size_t opt_base_index;
gboolean ready_for_next_state; /**< don't modify this; use li_plugin_ready_for_state() instead */
liPluginFreeCB free; /**< called before plugin is unloaded */
liPluginHandleVRequestCB handle_request_body;
/** called for every plugin after connection got closed (response end, reset by peer, error)
* the plugins code must not depend on any order of plugins loaded
*/
liPluginHandleCloseCB handle_close;
2008-06-24 19:19:20 +00:00
/** called for every plugin after vrequest got reset */
liPluginHandleVRCloseCB handle_vrclose;
const liPluginOption *options;
const liPluginAction *actions;
2009-08-30 17:25:01 +00:00
const liPluginSetup *setups;
const liPluginAngel *angelcbs;
2008-06-24 19:19:20 +00:00
};
struct liPluginOption {
const gchar *name;
liValueType type;
2008-07-08 19:29:02 +00:00
gpointer default_value;
2009-07-09 20:17:24 +00:00
liPluginParseOptionCB li_parse_option;
liPluginFreeOptionCB free_option;
2008-06-24 19:19:20 +00:00
};
struct liPluginAction {
const gchar *name;
2009-07-09 20:17:24 +00:00
liPluginCreateActionCB li_create_action;
};
2009-08-30 17:25:01 +00:00
struct liPluginSetup {
const gchar *name;
liPluginSetupCB setup;
};
2009-08-30 17:25:01 +00:00
struct liPluginAngel {
const gchar *name;
liPluginAngelCB angel_cb;
};
/* Internal structures */
struct liServerOption {
liPlugin *p;
2008-06-28 18:37:28 +00:00
2009-07-09 20:17:24 +00:00
/** the value is freed with li_value_free after the parse call, so you
* probably want to extract the content via li_value_extract*
* val is zero to get the global default value if nothing is specified
* save result in value
*
* Default behaviour (NULL) is to extract the inner value from val
*/
2009-07-09 20:17:24 +00:00
liPluginParseOptionCB li_parse_option;
/** the free_option handler has to free all allocated resources;
* it may get called with 0 initialized options, so you have to
* check the value.
*/
liPluginFreeOptionCB free_option;
2008-06-28 18:37:28 +00:00
2009-07-09 20:17:24 +00:00
/** if li_parse_option is NULL, the default_value is used; it is only used
* for the following value types:
* - BOOLEAN, NUMBER: casted with GPOINTER_TO_INT, i.e. set it with GINT_TO_POINTER
* the numbers are limited to the 32-bit range according to the glib docs
* - STRING: used for g_string_new, i.e. a const char*
*/
gpointer default_value;
2008-06-24 19:19:20 +00:00
size_t index, module_index;
liValueType type;
2008-06-24 19:19:20 +00:00
};
struct liServerAction {
liPlugin *p;
2009-07-09 20:17:24 +00:00
liPluginCreateActionCB li_create_action;
};
struct liServerSetup {
liPlugin *p;
liPluginSetupCB setup;
};
/* Needed by modules to register their plugin(s) */
2009-07-09 20:17:24 +00:00
LI_API liPlugin *li_plugin_register(liServer *srv, const gchar *name, liPluginInitCB init);
2008-07-08 19:29:02 +00:00
/* Internal needed functions */
2009-07-09 20:17:24 +00:00
LI_API void li_plugin_free(liServer *srv, liPlugin *p);
LI_API void li_server_plugins_free(liServer *srv);
2008-08-04 19:28:56 +00:00
/** free val after call (val may be modified by parser) */
2009-07-09 20:17:24 +00:00
LI_API gboolean li_parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark);
LI_API void li_release_option(liServer *srv, liOptionSet *mark); /**< Does not free the option_set memory */
2008-06-28 18:37:28 +00:00
2009-07-09 20:17:24 +00:00
LI_API void li_plugins_prepare_callbacks(liServer *srv);
/* server state machine callbacks */
LI_API void li_plugins_prepare_worker(liWorker *srv); /* blocking callbacks */
LI_API void li_plugins_prepare(liServer *srv); /* "prepare", async */
LI_API void li_plugins_start_listen(liServer *srv); /* "warmup" */
LI_API void li_plugins_stop_listen(liServer *srv); /* "prepare suspend", async */
LI_API void li_plugins_start_log(liServer *srv); /* "run" */
LI_API void li_plugins_stop_log(liServer *srv); /* "suspend now" */
LI_API void li_plugin_ready_for_state(liServer *srv, liPlugin *p, liServerState state);
2009-07-09 20:17:24 +00:00
LI_API void li_plugins_handle_close(liConnection *con);
LI_API void li_plugins_handle_vrclose(liVRequest *vr);
2008-08-04 19:28:56 +00:00
/* Needed for config frontends */
/** For parsing 'somemod.option = "somevalue"', free value after call */
2009-07-09 20:17:24 +00:00
LI_API liAction* li_option_action(liServer *srv, const gchar *name, liValue *val);
/** For parsing 'somemod.action value', e.g. 'rewrite "/url" => "/destination"'
* free value after call
*/
2009-07-09 20:17:24 +00:00
LI_API liAction* li_create_action(liServer *srv, const gchar *name, liValue *val);
/** For setup function, e.g. 'listen "127.0.0.1:8080"'; free value after call */
2009-07-09 20:17:24 +00:00
LI_API gboolean li_call_setup(liServer *srv, const char *name, liValue *val);
2008-07-23 20:33:29 +00:00
/** free val after call */
2009-07-09 20:17:24 +00:00
LI_API gboolean li_plugin_set_default_option(liServer *srv, const gchar* name, liValue *val);
/* needs vrequest *vr and plugin *p */
#define OPTION(idx) _OPTION(vr, p, idx)
#define _OPTION(vr, p, idx) (vr->options[p->opt_base_index + idx])
#define _OPTION_ABS(vr, idx) (vr->options[idx])
2008-06-24 19:19:20 +00:00
#endif