2
0
Fork 0
lighttpd2/src/plugin.h

150 lines
4.3 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
struct plugin;
typedef struct plugin plugin;
struct plugin_option;
typedef struct plugin_option plugin_option;
2008-06-24 19:19:20 +00:00
2008-06-28 18:37:28 +00:00
struct server_option;
typedef struct server_option server_option;
struct plugin_action;
typedef struct plugin_action plugin_action;
struct server_action;
typedef struct server_action server_action;
struct plugin_setup;
typedef struct plugin_setup plugin_setup;
struct server_setup;
typedef struct server_setup server_setup;
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
2008-06-28 18:37:28 +00:00
#include "base.h"
#include "options.h"
#include "actions.h"
#include "module.h"
2008-06-28 18:37:28 +00:00
typedef void (*PluginInit) (server *srv, plugin *p);
typedef void (*PluginFree) (server *srv, plugin *p);
typedef gboolean (*PluginParseOption) (server *srv, plugin *p, size_t ndx, option *opt, gpointer *value);
typedef void (*PluginFreeOption) (server *srv, plugin *p, size_t ndx, gpointer value);
typedef action* (*PluginCreateAction) (server *srv, plugin *p, option *opt);
typedef gboolean (*PluginSetup) (server *srv, plugin *p, option *opt);
2008-07-08 19:29:02 +00:00
typedef void (*PluginHandleContent) (server *srv, connection *con, plugin *p);
typedef void (*PluginHandleClose) (server *srv, connection *con, plugin *p);
2008-06-24 19:19:20 +00:00
struct plugin {
size_t version;
2008-07-23 16:01:19 +00:00
const gchar *name; /**< name of the plugin */
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;
PluginFree free; /**< called before plugin is unloaded */
/** called if plugin registered as indirect handler with connection_handle_indirect(srv, con, p)
* - after response headers are created:
* connection_set_state(srv, con, CON_STATE_HANDLE_RESPONSE_HEADER)
* - after content is generated close output queue:
* con->out->is_closed = TRUE
*/
PluginHandleContent handle_content;
/** 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
*/
PluginHandleClose handle_close;
2008-06-24 19:19:20 +00:00
2008-07-23 16:01:19 +00:00
const plugin_option *options;
const plugin_action *actions;
const plugin_setup *setups;
2008-06-24 19:19:20 +00:00
};
struct plugin_option {
const gchar *name;
2008-06-24 19:19:20 +00:00
option_type type;
2008-08-15 18:38:20 +00:00
gpointer default_value;
2008-07-08 19:29:02 +00:00
PluginParseOption parse_option;
PluginFreeOption free_option;
2008-06-24 19:19:20 +00:00
};
struct plugin_action {
const gchar *name;
PluginCreateAction create_action;
};
struct plugin_setup {
const gchar *name;
PluginSetup setup;
};
/* Internal structures */
2008-06-24 19:19:20 +00:00
struct server_option {
plugin *p;
2008-06-28 18:37:28 +00:00
/** the plugin must free the _content_ of the option
* opt is zero to get the global default value if nothing is specified
* save result in value
*
* Default behaviour (NULL) is to just use the option as value
*/
PluginParseOption parse_option;
PluginFreeOption free_option;
2008-06-28 18:37:28 +00:00
2008-06-24 19:19:20 +00:00
size_t index, module_index;
option_type type;
2008-08-15 18:38:20 +00:00
gpointer default_value;
2008-06-24 19:19:20 +00:00
};
struct server_action {
plugin *p;
PluginCreateAction create_action;
};
struct server_setup {
plugin *p;
PluginSetup setup;
};
2008-08-04 19:28:56 +00:00
/* Needed my modules to register their plugin(s) */
2008-07-23 16:01:19 +00:00
LI_API gboolean plugin_register(server *srv, const gchar *name, PluginInit init);
2008-07-08 19:29:02 +00:00
/* Internal needed functions */
2008-08-04 19:28:56 +00:00
LI_API void plugin_free(server *srv, plugin *p);
2008-07-23 20:33:29 +00:00
LI_API gboolean parse_option(server *srv, const char *name, option *opt, option_set *mark);
LI_API void release_option(server *srv, option_set *mark); /**< Does not free the option_set memory */
2008-06-28 18:37:28 +00:00
LI_API void plugins_prepare_callbacks(server *srv);
LI_API void plugins_handle_close(server *srv, connection *con);
2008-08-04 19:28:56 +00:00
/* Needed for config frontends */
/** For parsing 'somemod.option = "somevalue"' */
LI_API action* option_action(server *srv, const gchar *name, option *value);
/** For parsing 'somemod.action value', e.g. 'rewrite "/url" => "/destination"'
* You need to free the option after it (it should be of type NONE then)
*/
LI_API action* create_action(server *srv, const gchar *name, option *value);
2008-08-04 19:28:56 +00:00
/** For setup function, e.g. 'listen "127.0.0.1:8080"' */
2008-07-23 20:33:29 +00:00
LI_API gboolean call_setup(server *srv, const char *name, option *opt);
/* needs connection *con and plugin *p */
#define OPTION(idx) _OPTION(con, p, idx)
#define _OPTION(con, p, idx) (con->options[p->opt_base_index + idx])
#define _OPTION_ABS(con, idx) (con->options[idx])
2008-06-24 19:19:20 +00:00
#endif