From 3bc425fef126a0bcdaef4e60bea6970c67bef5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 13 Dec 2009 21:35:46 +0100 Subject: [PATCH] Remove config parser code from main(), add cmake-option to disable default config parser --- include/lighttpd/config_parser.h | 2 ++ src/CMakeLists.txt | 8 ++++- src/config.h.cmake | 2 ++ src/main/config_parser.rl | 41 ++++++++++++++++++++++++++ src/main/lighttpd.c | 50 +++++++------------------------- 5 files changed, 63 insertions(+), 40 deletions(-) diff --git a/include/lighttpd/config_parser.h b/include/lighttpd/config_parser.h index 14f9fff..34b8f47 100644 --- a/include/lighttpd/config_parser.h +++ b/include/lighttpd/config_parser.h @@ -46,6 +46,8 @@ struct liConfigParserContext { gsize line; /* holds current line */ }; +LI_API gboolean li_config_parse(liServer *srv, const gchar *config_path); + /* returns a new config parser stack with the first context in it */ LI_API GList* li_config_parser_init(liServer *srv); LI_API void li_config_parser_finish(liServer *srv, GList *ctx_stack, gboolean free_all); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1be9a50..d695296 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES) # OPTION(WITH_OPENSSL "with openssl-support [default: on]" ON) OPTION(WITH_LUA "with lua 5.1 for lua-configfile [default: on]" ON) +OPTION(WITHOUT_CONFIG_PARSER "without standard config parser [default: off]" OFF) OPTION(WITH_OPENSSL "with openssl-support [default: off]") OPTION(BUILD_STATIC "build a static lighttpd with all modules added") OPTION(BUILD_EXTRA_WARNINGS "extra warnings") @@ -177,7 +178,6 @@ SET(LIGHTTPD_SHARED_SRC chunk_parser.c collect.c condition.c - config_parser.c connection.c environment.c etag.c @@ -207,6 +207,12 @@ SET(LIGHTTPD_SHARED_SRC plugin_core.c ) +IF(NOT WITHOUT_CONFIG_PARSER) +SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC} + config_parser.c +) +ENDIF(NOT WITHOUT_CONFIG_PARSER) + IF(WITH_LUA) SET(LIGHTTPD_SHARED_SRC ${LIGHTTPD_SHARED_SRC} actions_lua.c diff --git a/src/config.h.cmake b/src/config.h.cmake index 2dec29d..e51adb7 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -153,4 +153,6 @@ #cmakedefine HAVE_FASTCGI_H #cmakedefine HAVE_FASTCGI_FASTCGI_H +/* features */ +#cmakedefine WITHOUT_CONFIG_PARSER #cmakedefine LIGHTTPD_STATIC diff --git a/src/main/config_parser.rl b/src/main/config_parser.rl index a847d69..e13fdf6 100644 --- a/src/main/config_parser.rl +++ b/src/main/config_parser.rl @@ -1421,3 +1421,44 @@ static gboolean config_parser_buffer(liServer *srv, GList *ctx_stack) { return TRUE; } + +gboolean li_config_parse(liServer *srv, const gchar *config_path) { + GTimeVal start, end; + gulong s, millis, micros; + guint64 d; + liAction *a; + liConfigParserContext *ctx; + GList *ctx_stack = NULL; + + g_get_current_time(&start); + + /* standard config frontend */ + ctx_stack = li_config_parser_init(srv); + ctx = (liConfigParserContext*) ctx_stack->data; + if (!li_config_parser_file(srv, ctx_stack, config_path)) { + li_config_parser_finish(srv, ctx_stack, TRUE); + return FALSE; /* no cleanup on config error, same as config test */ + } + + /* append fallback "static" action */ + a = li_create_action(srv, "static", NULL); + g_array_append_val(srv->mainaction->data.list, a); + + g_get_current_time(&end); + d = end.tv_sec - start.tv_sec; + d *= 1000000; + d += end.tv_usec - start.tv_usec; + s = d / 1000000; + millis = (d - s) / 1000; + micros = (d - s - millis) %1000; + DEBUG(srv, "parsed config file in %lu seconds, %lu milliseconds, %lu microseconds", s, millis, micros); + + if (g_queue_get_length(ctx->option_stack) != 0 || g_queue_get_length(ctx->action_list_stack) != 1) + DEBUG(srv, "option_stack: %u action_list_stack: %u (should be 0:1)", g_queue_get_length(ctx->option_stack), g_queue_get_length(ctx->action_list_stack)); + + li_config_parser_finish(srv, ctx_stack, FALSE); + + li_config_parser_finish(srv, ctx_stack, TRUE); + + return TRUE; +} diff --git a/src/main/lighttpd.c b/src/main/lighttpd.c index 7083e49..d878ec4 100644 --- a/src/main/lighttpd.c +++ b/src/main/lighttpd.c @@ -1,6 +1,5 @@ #include -#include #include #include @@ -10,6 +9,10 @@ # include #endif +#ifndef WITHOUT_CONFIG_PARSER +# include +#endif + #ifndef DEFAULT_LIBDIR # define DEFAULT_LIBDIR "/usr/local/lib/lighttpd" #endif @@ -29,8 +32,6 @@ int main(int argc, char *argv[]) { gboolean show_version = FALSE; gboolean use_angel = FALSE; - GList *ctx_stack = NULL; - GOptionEntry entries[] = { { "config", 'c', 0, G_OPTION_ARG_FILENAME, &config_path, "filename/path of the config", "PATH" }, { "lua", 'l', 0, G_OPTION_ARG_NONE, &luaconfig, "use the lua config frontend", NULL }, @@ -96,39 +97,13 @@ int main(int argc, char *argv[]) { DEBUG(srv, "config path: %s", config_path); if (!luaconfig) { - GTimeVal start, end; - gulong s, millis, micros; - guint64 d; - liAction *a; - liConfigParserContext *ctx; - - g_get_current_time(&start); - - /* standard config frontend */ - ctx_stack = li_config_parser_init(srv); - ctx = (liConfigParserContext*) ctx_stack->data; - if (!li_config_parser_file(srv, ctx_stack, config_path)) { - li_config_parser_finish(srv, ctx_stack, TRUE); - return 1; /* no cleanup on config error, same as config test */ - } - - /* append fallback "static" action */ - a = li_create_action(srv, "static", NULL); - g_array_append_val(srv->mainaction->data.list, a); - - g_get_current_time(&end); - d = end.tv_sec - start.tv_sec; - d *= 1000000; - d += end.tv_usec - start.tv_usec; - s = d / 1000000; - millis = (d - s) / 1000; - micros = (d - s - millis) %1000; - DEBUG(srv, "parsed config file in %lu seconds, %lu milliseconds, %lu microseconds", s, millis, micros); - - if (g_queue_get_length(ctx->option_stack) != 0 || g_queue_get_length(ctx->action_list_stack) != 1) - DEBUG(srv, "option_stack: %u action_list_stack: %u (should be 0:1)", g_queue_get_length(ctx->option_stack), g_queue_get_length(ctx->action_list_stack)); - - li_config_parser_finish(srv, ctx_stack, FALSE); +#ifndef WITHOUT_CONFIG_PARSER + if (!li_config_parse(srv, config_path)) + return 1; +#else + g_print("standard config frontend not available\n"); + return 1; +#endif } else { #ifdef HAVE_LUA_H @@ -155,9 +130,6 @@ int main(int argc, char *argv[]) { li_worker_run(srv->main_worker); li_server_reached_state(srv, LI_SERVER_DOWN); - if (!luaconfig) - li_config_parser_finish(srv, ctx_stack, TRUE); - INFO(srv, "%s", "going down"); li_server_free(srv);