changed option default value assignment to callbacks

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent 93618313e1
commit 8649ce6cfe
  1. 5
      src/plugin.h
  2. 26
      src/plugin_core.c
  3. 3
      src/server.c

@ -38,6 +38,7 @@ 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 gpointer (*PluginDefaultValue) (server *srv, plugin *p, gsize ndx);
typedef action* (*PluginCreateAction) (server *srv, plugin *p, option *opt);
typedef gboolean (*PluginSetup) (server *srv, plugin *p, option *opt);
@ -75,8 +76,8 @@ struct plugin {
struct plugin_option {
const gchar *name;
option_type type;
gpointer default_value;
PluginDefaultValue default_value;
PluginParseOption parse_option;
PluginFreeOption free_option;
};
@ -101,12 +102,12 @@ struct server_option {
*
* Default behaviour (NULL) is to just use the option as value
*/
PluginDefaultValue default_value; /* default value callback - if no callback is provided, default value will be NULL, 0 or FALSE */
PluginParseOption parse_option;
PluginFreeOption free_option;
size_t index, module_index;
option_type type;
gpointer default_value;
};
struct server_action {

@ -424,7 +424,23 @@ void core_option_log_level_free(server *srv, plugin *p, size_t ndx, gpointer val
UNUSED(value);
}
static plugin_option options[] = {
gpointer core_option_max_keep_alive_idle_default(server *srv, plugin *p, gsize ndx) {
UNUSED(srv);
UNUSED(p);
UNUSED(ndx);
return GINT_TO_POINTER(5);
}
gpointer core_option_server_tag_default(server *srv, plugin *p, gsize ndx) {
UNUSED(srv);
UNUSED(p);
UNUSED(ndx);
return g_string_new_len(CONST_STR_LEN("lighttpd-2.0~sandbox"));
}
static const plugin_option options[] = {
{ "debug.log_request_handling", OPTION_BOOLEAN, NULL, NULL, NULL },
{ "log.target", OPTION_STRING, NULL, core_option_log_target_parse, core_option_log_target_free },
@ -432,8 +448,8 @@ static plugin_option options[] = {
{ "static-file.exclude", OPTION_LIST, NULL, NULL, NULL },
{ "server.tag", OPTION_STRING, NULL, NULL, NULL },
{ "server.max_keep_alive_idle", OPTION_INT, GINT_TO_POINTER(5), NULL, NULL },
{ "server.tag", OPTION_STRING, core_option_server_tag_default, NULL, NULL },
{ "server.max_keep_alive_idle", OPTION_INT, core_option_max_keep_alive_idle_default, NULL, NULL },
{ NULL, 0, NULL, NULL, NULL }
};
@ -458,10 +474,6 @@ static const plugin_setup setups[] = {
void plugin_core_init(server *srv, plugin *p) {
UNUSED(srv);
/* default values - if not initialized here, will default to NULL, 0 or FALSE */
options[CORE_OPTION_DEBUG_REQUEST_HANDLING].default_value = FALSE;
options[CORE_OPTION_SERVER_TAG].default_value = g_string_new_len(CONST_STR_LEN("lighttpd-2.0~sandbox"));
p->options = options;
p->actions = actions;
p->setups = setups;

@ -354,7 +354,8 @@ void server_start(server *srv) {
g_hash_table_iter_init(&iter, srv->options);
while (g_hash_table_iter_next(&iter, &k, &v)) {
server_option *so = v;
srv->option_def_values[so->index] = so->default_value;
if (so->default_value)
srv->option_def_values[so->index] = so->default_value(srv, so->p, so->index);
}
plugins_prepare_callbacks(srv);

Loading…
Cancel
Save