Browse Source

Remove config parser code from main(), add cmake-option to disable default config parser

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent
commit
3bc425fef1
  1. 2
      include/lighttpd/config_parser.h
  2. 8
      src/CMakeLists.txt
  3. 2
      src/config.h.cmake
  4. 41
      src/main/config_parser.rl
  5. 50
      src/main/lighttpd.c

2
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);

8
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

2
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

41
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;
}

50
src/main/lighttpd.c

@ -1,6 +1,5 @@
#include <lighttpd/base.h>
#include <lighttpd/config_parser.h>
#include <lighttpd/profiler.h>
#include <lighttpd/plugin_core.h>
@ -10,6 +9,10 @@
# include <lighttpd/config_lua.h>
#endif
#ifndef WITHOUT_CONFIG_PARSER
# include <lighttpd/config_parser.h>
#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);

Loading…
Cancel
Save