2
0
Fork 0

implemented default values for options

This commit is contained in:
Thomas Porzelt 2008-08-15 20:38:28 +02:00
commit 5347dd06b3
6 changed files with 38 additions and 28 deletions

View File

@ -108,6 +108,7 @@ gboolean plugin_register(server *srv, const gchar *name, PluginInit init) {
so->index = g_hash_table_size(srv->options);
so->module_index = i;
so->p = p;
so->default_value = po->default_value;
g_hash_table_insert(srv->options, (gchar*) po->name, so);
}
}

View File

@ -75,6 +75,7 @@ struct plugin {
struct plugin_option {
const gchar *name;
option_type type;
gpointer default_value;
PluginParseOption parse_option;
PluginFreeOption free_option;
@ -105,6 +106,7 @@ struct server_option {
size_t index, module_index;
option_type type;
gpointer default_value;
};
struct server_action {

View File

@ -407,16 +407,16 @@ void core_option_log_level_free(server *srv, plugin *p, size_t ndx, gpointer val
UNUSED(value);
}
static const plugin_option options[] = {
{ "debug.log_request_handling", OPTION_BOOLEAN, NULL, NULL },
static plugin_option options[] = {
{ "debug.log_request_handling", OPTION_BOOLEAN, NULL, NULL, NULL },
{ "log.target", OPTION_STRING, core_option_log_target_parse, core_option_log_target_free },
{ "log.level", OPTION_STRING, core_option_log_level_parse, core_option_log_level_free },
{ "log.target", OPTION_STRING, NULL, core_option_log_target_parse, core_option_log_target_free },
{ "log.level", OPTION_STRING, NULL, core_option_log_level_parse, core_option_log_level_free },
{ "static-file.exclude", OPTION_LIST, NULL, NULL },
{ "static-file.exclude", OPTION_LIST, NULL, NULL, NULL },
{ "server.tag", OPTION_STRING, NULL, NULL },
{ NULL, 0, NULL, NULL }
{ "server.tag", OPTION_STRING, NULL, NULL, NULL },
{ NULL, 0, NULL, NULL, NULL }
};
static const plugin_action actions[] = {
@ -439,6 +439,10 @@ 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;

View File

@ -115,14 +115,9 @@ void response_send_headers(server *srv, connection *con) {
if (!have_server) {
GString *tag = CORE_OPTION(CORE_OPTION_SERVER_TAG);
if (!tag || tag->len) {
if (tag->len) {
g_string_append_len(head, CONST_STR_LEN("Server: "));
if (tag)
g_string_append_len(head, GSTR_LEN(tag));
else
g_string_append_len(head, CONST_STR_LEN("lighttpd-2.0~sandbox"));
g_string_append_len(head, GSTR_LEN(tag));
g_string_append_len(head, CONST_STR_LEN("\r\n"));
}
}

View File

@ -284,6 +284,8 @@ void server_listen(server *srv, int fd) {
void server_start(server *srv) {
guint i;
GHashTableIter iter;
gpointer k, v;
if (srv->state == SERVER_STOPPING || srv->state == SERVER_RUNNING) return; /* no restart after stop */
srv->state = SERVER_RUNNING;
@ -293,10 +295,16 @@ void server_start(server *srv) {
return;
}
/* TODO: get default values for options */
srv->option_count = g_hash_table_size(srv->options);
srv->option_def_values = g_slice_alloc0(srv->option_count * sizeof(*srv->option_def_values));
/* set default option values */
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;
}
plugins_prepare_callbacks(srv);
for (i = 0; i < srv->sockets->len; i++) {

View File

@ -241,12 +241,12 @@ gchar *http_status_string(guint status_code) {
gchar counter_format(guint64 *count, guint factor) {
gchar suffix = 0;
if (*count > factor) { *count /= factor; suffix = 'k';
if (*count > factor) { *count /= factor; suffix = 'm';
if (*count > factor) { *count /= factor; suffix = 'g';
if (*count > factor) { *count /= factor; suffix = 't';
if (*count > factor) { *count /= factor; suffix = 'p';
if (*count > factor) { *count /= factor; suffix = 'e'; }
if (*count >= factor) { *count /= factor; suffix = 'k';
if (*count >= factor) { *count /= factor; suffix = 'm';
if (*count >= factor) { *count /= factor; suffix = 'g';
if (*count >= factor) { *count /= factor; suffix = 't';
if (*count >= factor) { *count /= factor; suffix = 'p';
if (*count >= factor) { *count /= factor; suffix = 'e'; }
}
}
}
@ -258,13 +258,13 @@ gchar counter_format(guint64 *count, guint factor) {
gchar *ev_backend_string(guint backend) {
switch (backend) {
case EVBACKEND_SELECT: return "select";
case EVBACKEND_POLL: return "poll";
case EVBACKEND_EPOLL: return "epoll";
case EVBACKEND_KQUEUE: return "kqueue";
case EVBACKEND_DEVPOLL: return "devpoll";
case EVBACKEND_PORT: return "port";
default: return "unknown";
case EVBACKEND_SELECT: return "select";
case EVBACKEND_POLL: return "poll";
case EVBACKEND_EPOLL: return "epoll";
case EVBACKEND_KQUEUE: return "kqueue";
case EVBACKEND_DEVPOLL: return "devpoll";
case EVBACKEND_PORT: return "port";
default: return "unknown";
}
}