2008-06-28 18:37:28 +00:00
|
|
|
#ifndef _LIGHTTPD_PLUGIN_H_
|
|
|
|
#define _LIGHTTPD_PLUGIN_H_
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2008-10-28 21:11:50 +00:00
|
|
|
#ifndef _LIGHTTPD_BASE_H_
|
2008-11-16 20:33:53 +00:00
|
|
|
#error Please include <lighttpd/base.h> instead of this file
|
2008-10-28 21:11:50 +00:00
|
|
|
#endif
|
2008-07-23 19:34:19 +00:00
|
|
|
|
2009-12-21 11:29:14 +00:00
|
|
|
typedef void (*liPluginInitCB) (liServer *srv, liPlugin *p, gpointer userdata);
|
2009-07-08 19:06:07 +00:00
|
|
|
typedef void (*liPluginFreeCB) (liServer *srv, liPlugin *p);
|
2010-05-07 18:54:50 +00:00
|
|
|
typedef gboolean (*liPluginParseOptionCB) (liServer *srv, liWorker *wrk, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval);
|
|
|
|
typedef gboolean (*liPluginParseOptionPtrCB)(liServer *srv, liWorker *wrk, liPlugin *p, size_t ndx, liValue *val, gpointer *oval);
|
2010-01-24 20:30:41 +00:00
|
|
|
typedef void (*liPluginFreeOptionPtrCB) (liServer *srv, liPlugin *p, size_t ndx, gpointer oval);
|
2010-05-07 18:54:50 +00:00
|
|
|
typedef liAction*(*liPluginCreateActionCB) (liServer *srv, liWorker *wrk, liPlugin *p, liValue *val, gpointer userdata);
|
2009-12-21 11:29:14 +00:00
|
|
|
typedef gboolean (*liPluginSetupCB) (liServer *srv, liPlugin *p, liValue *val, gpointer userdata);
|
2009-08-30 17:25:01 +00:00
|
|
|
typedef void (*liPluginAngelCB) (liServer *srv, liPlugin *p, gint32 id, GString *data);
|
2009-07-08 19:06:07 +00:00
|
|
|
|
2010-02-13 14:41:09 +00:00
|
|
|
typedef void (*liPluginServerStateWorker)(liServer *srv, liPlugin *p, liWorker *wrk);
|
|
|
|
typedef void (*liPluginServerState)(liServer *srv, liPlugin *p);
|
2010-02-13 14:29:21 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
typedef void (*liPluginHandleCloseCB) (liConnection *con, liPlugin *p);
|
|
|
|
typedef liHandlerResult(*liPluginHandleVRequestCB)(liVRequest *vr, liPlugin *p);
|
|
|
|
typedef void (*liPluginHandleVRCloseCB) (liVRequest *vr, liPlugin *p);
|
|
|
|
|
2013-05-04 11:11:25 +00:00
|
|
|
typedef void (*liPluginInitLua)(liLuaState *LL, liServer *srv, liWorker *wrk, liPlugin *p);
|
2010-05-14 11:09:34 +00:00
|
|
|
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
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 */
|
2009-01-01 15:44:42 +00:00
|
|
|
guint id; /**< index in some plugin arrays */
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2008-08-08 17:44:54 +00:00
|
|
|
gpointer data; /**< private plugin data */
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2010-01-27 16:38:27 +00:00
|
|
|
size_t opt_base_index, optptr_base_index;
|
2008-08-08 16:49:00 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
liPluginFreeCB free; /**< called before plugin is unloaded */
|
2008-08-08 17:44:54 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
liPluginHandleVRequestCB handle_request_body;
|
2008-08-08 17:44:54 +00:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2009-07-08 19:06:07 +00:00
|
|
|
liPluginHandleCloseCB handle_close;
|
2008-06-24 19:19:20 +00:00
|
|
|
|
2009-01-01 15:44:42 +00:00
|
|
|
/** called for every plugin after vrequest got reset */
|
2009-07-08 19:06:07 +00:00
|
|
|
liPluginHandleVRCloseCB handle_vrclose;
|
2009-01-01 15:44:42 +00:00
|
|
|
|
2010-02-13 14:41:09 +00:00
|
|
|
liPluginServerStateWorker handle_prepare_worker; /**< called in the worker thread context once before running the workers */
|
2010-05-07 18:54:50 +00:00
|
|
|
liPluginServerStateWorker handle_worker_stop;
|
2010-02-13 14:41:09 +00:00
|
|
|
/* server state machine hooks */
|
|
|
|
liPluginServerState handle_prepare, handle_start_listen, handle_stop_listen, handle_start_log, handle_stop_log;
|
|
|
|
|
2010-05-14 11:09:34 +00:00
|
|
|
liPluginInitLua handle_init_lua;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
const liPluginOption *options;
|
2010-01-24 20:30:41 +00:00
|
|
|
const liPluginOptionPtr *optionptrs;
|
2009-07-08 19:06:07 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liPluginOption {
|
2008-07-23 19:34:19 +00:00
|
|
|
const gchar *name;
|
2009-07-08 19:06:07 +00:00
|
|
|
liValueType type;
|
2008-07-08 19:29:02 +00:00
|
|
|
|
2010-01-24 20:30:41 +00:00
|
|
|
gint64 default_value;
|
2009-12-21 17:19:12 +00:00
|
|
|
liPluginParseOptionCB parse_option;
|
2010-01-24 20:30:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct liPluginOptionPtr {
|
|
|
|
const gchar *name;
|
|
|
|
liValueType type;
|
|
|
|
|
|
|
|
gpointer default_value;
|
|
|
|
liPluginParseOptionPtrCB parse_option;
|
|
|
|
liPluginFreeOptionPtrCB free_option;
|
2008-06-24 19:19:20 +00:00
|
|
|
};
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
struct liPluginAction {
|
2008-07-23 19:34:19 +00:00
|
|
|
const gchar *name;
|
2009-12-21 17:19:12 +00:00
|
|
|
liPluginCreateActionCB create_action;
|
2009-12-21 11:29:14 +00:00
|
|
|
gpointer userdata;
|
2008-07-23 19:34:19 +00:00
|
|
|
};
|
|
|
|
|
2009-08-30 17:25:01 +00:00
|
|
|
struct liPluginSetup {
|
2008-07-23 19:34:19 +00:00
|
|
|
const gchar *name;
|
2009-07-08 19:06:07 +00:00
|
|
|
liPluginSetupCB setup;
|
2009-12-21 11:29:14 +00:00
|
|
|
gpointer userdata;
|
2008-07-23 19:34:19 +00:00
|
|
|
};
|
|
|
|
|
2009-08-30 17:25:01 +00:00
|
|
|
struct liPluginAngel {
|
|
|
|
const gchar *name;
|
|
|
|
liPluginAngelCB angel_cb;
|
|
|
|
};
|
|
|
|
|
2008-10-01 20:20:31 +00:00
|
|
|
/* Needed by modules to register their plugin(s) */
|
2009-12-21 11:29:14 +00:00
|
|
|
LI_API liPlugin *li_plugin_register(liServer *srv, const gchar *name, liPluginInitCB init, gpointer userdata);
|
2008-07-08 19:29:02 +00:00
|
|
|
|
2008-08-08 17:44:54 +00:00
|
|
|
/* Internal needed functions */
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_plugin_free(liServer *srv, liPlugin *p);
|
2013-08-22 16:02:50 +00:00
|
|
|
LI_API void li_server_plugins_init(liServer *srv);
|
2009-07-09 20:17:24 +00:00
|
|
|
LI_API void li_server_plugins_free(liServer *srv);
|
2008-08-04 19:28:56 +00:00
|
|
|
|
2010-01-24 20:30:41 +00:00
|
|
|
LI_API void li_release_optionptr(liServer *srv, liOptionPtrValue *value);
|
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);
|
2009-08-30 18:43:13 +00:00
|
|
|
|
|
|
|
/* server state machine callbacks */
|
2010-05-07 18:54:50 +00:00
|
|
|
LI_API void li_plugins_prepare_worker(liWorker *wrk); /* blocking callbacks */
|
2009-08-30 18:43:13 +00:00
|
|
|
LI_API void li_plugins_prepare(liServer *srv); /* "prepare", async */
|
|
|
|
|
2010-05-07 18:54:50 +00:00
|
|
|
LI_API void li_plugins_worker_stop(liWorker *wrk); /* blocking callbacks */
|
|
|
|
|
2009-08-30 18:43:13 +00:00
|
|
|
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" */
|
|
|
|
|
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-08 17:44:54 +00:00
|
|
|
|
2008-08-04 19:28:56 +00:00
|
|
|
/* Needed for config frontends */
|
2013-08-22 16:02:50 +00:00
|
|
|
/* "val" gets freed in any case */
|
|
|
|
LI_API liAction *li_plugin_config_action(liServer *srv, liWorker *wrk, const gchar *name, liValue *val);
|
|
|
|
LI_API gboolean li_plugin_config_setup(liServer *srv, const char *name, liValue *val);
|
2008-10-01 20:20:31 +00:00
|
|
|
|
2013-05-04 11:11:25 +00:00
|
|
|
LI_API void li_plugins_init_lua(liLuaState *LL, liServer *srv, liWorker *wrk);
|
2010-05-14 11:09:34 +00:00
|
|
|
|
2013-09-06 12:36:55 +00:00
|
|
|
extern const liOptionPtrValue li_option_ptr_zero;
|
2010-01-24 20:30:41 +00:00
|
|
|
|
2008-12-30 00:21:03 +00:00
|
|
|
/* needs vrequest *vr and plugin *p */
|
2008-10-25 12:53:57 +00:00
|
|
|
#define OPTION(idx) _OPTION(vr, p, idx)
|
2008-12-30 00:21:03 +00:00
|
|
|
#define _OPTION(vr, p, idx) (vr->options[p->opt_base_index + idx])
|
|
|
|
#define _OPTION_ABS(vr, idx) (vr->options[idx])
|
2010-01-24 20:30:41 +00:00
|
|
|
#define OPTIONPTR(idx) _OPTIONPTR(vr, p, idx)
|
2010-01-27 16:38:27 +00:00
|
|
|
#define _OPTIONPTR(vr, p, idx) (vr->optionptrs[p->optptr_base_index + idx] ? vr->optionptrs[p->optptr_base_index + idx]->data : li_option_ptr_zero.data)
|
2010-01-24 20:30:41 +00:00
|
|
|
#define _OPTIONPTR_ABS(vr, idx) (vr->optionptrs[idx] ? vr->optionptrs[idx]->data : li_option_ptr_zero.data)
|
2008-08-08 16:49:00 +00:00
|
|
|
|
2008-06-24 19:19:20 +00:00
|
|
|
#endif
|