2008-07-17 19:39:29 +00:00
|
|
|
|
|
|
|
#include "base.h"
|
2008-07-17 21:12:52 +00:00
|
|
|
#include "config_parser.h"
|
2008-07-25 21:12:40 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LUA_H
|
2008-07-25 12:09:03 +00:00
|
|
|
#include "config_lua.h"
|
2008-07-25 21:12:40 +00:00
|
|
|
#endif
|
2008-07-17 19:39:29 +00:00
|
|
|
|
2008-07-23 20:19:23 +00:00
|
|
|
void plugin_core_init(server *srv, plugin *p);
|
2008-07-17 21:12:52 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
GError *error;
|
|
|
|
GOptionContext *context;
|
|
|
|
server *srv;
|
2008-08-02 20:56:07 +00:00
|
|
|
gboolean res;
|
2008-07-17 21:12:52 +00:00
|
|
|
|
2008-07-18 15:05:51 +00:00
|
|
|
gchar *config_path = NULL;
|
|
|
|
gboolean luaconfig = FALSE;
|
|
|
|
gboolean test_config = FALSE;
|
|
|
|
gboolean show_version = FALSE;
|
|
|
|
|
|
|
|
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 },
|
|
|
|
{ "test", 't', 0, G_OPTION_ARG_NONE, &test_config, "test config and exit", NULL },
|
|
|
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "show version and exit", NULL },
|
|
|
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
|
|
|
};
|
2008-07-17 21:12:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* parse commandline options */
|
|
|
|
context = g_option_context_new("- fast and lightweight webserver");
|
|
|
|
g_option_context_add_main_entries(context, entries, NULL);
|
2008-07-17 22:30:02 +00:00
|
|
|
|
2008-08-02 20:56:07 +00:00
|
|
|
res = g_option_context_parse(context, &argc, &argv, &error);
|
|
|
|
|
|
|
|
g_option_context_free(context);
|
|
|
|
|
|
|
|
if (!res) {
|
2008-07-17 21:12:52 +00:00
|
|
|
g_printerr("failed to parse command line arguments: %s\n", error->message);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-18 18:23:05 +00:00
|
|
|
/* -v, show version and exit */
|
|
|
|
if (show_version) {
|
2008-07-17 22:30:02 +00:00
|
|
|
g_print("%s-%s - a fast and lightweight webserver\n", PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
g_print("Build date: %s\n", PACKAGE_BUILD_DATE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-18 22:11:08 +00:00
|
|
|
/* initialize threading */
|
|
|
|
g_thread_init(NULL);
|
|
|
|
|
2008-07-17 21:12:52 +00:00
|
|
|
srv = server_new();
|
|
|
|
|
2008-07-23 20:19:23 +00:00
|
|
|
plugin_register(srv, "core", plugin_core_init);
|
|
|
|
|
2008-07-17 21:12:52 +00:00
|
|
|
/* if no path is specified for the config, read lighttpd.conf from current directory */
|
|
|
|
if (config_path == NULL)
|
|
|
|
config_path = "lighttpd.conf";
|
|
|
|
|
2008-08-02 20:56:07 +00:00
|
|
|
log_debug(srv, NULL, "config path: %s", config_path);
|
2008-07-17 21:12:52 +00:00
|
|
|
|
2008-07-17 22:30:02 +00:00
|
|
|
if (!luaconfig) {
|
2008-08-02 20:56:07 +00:00
|
|
|
GTimeVal start, end;
|
|
|
|
gulong s, millis, micros;
|
|
|
|
g_get_current_time(&start);
|
2008-08-04 21:16:49 +00:00
|
|
|
guint64 d;
|
2008-08-02 20:56:07 +00:00
|
|
|
|
2008-07-17 22:30:02 +00:00
|
|
|
/* standard config frontend */
|
2008-08-03 20:26:37 +00:00
|
|
|
GList *ctx_stack = config_parser_init(srv);
|
|
|
|
config_parser_context_t *ctx = (config_parser_context_t*) ctx_stack->data;
|
2008-08-02 20:56:07 +00:00
|
|
|
if (!config_parser_file(srv, ctx_stack, config_path)) {
|
2008-08-05 17:32:33 +00:00
|
|
|
config_parser_finish(srv, ctx_stack);
|
2008-08-02 20:56:07 +00:00
|
|
|
log_thread_start(srv);
|
|
|
|
g_atomic_int_set(&srv->exiting, TRUE);
|
|
|
|
log_thread_wakeup(srv);
|
2008-08-03 20:26:37 +00:00
|
|
|
server_free(srv);
|
2008-07-17 22:30:02 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-08-02 20:56:07 +00:00
|
|
|
|
|
|
|
g_get_current_time(&end);
|
2008-08-04 21:16:49 +00:00
|
|
|
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;
|
2008-08-08 23:55:07 +00:00
|
|
|
g_print("parsed config file in %lu seconds, %lu milliseconds, %lu microseconds\n", s, millis, micros);
|
2008-08-03 20:26:37 +00:00
|
|
|
g_print("option_stack: %u action_list_stack: %u (should be 0:1)\n", g_queue_get_length(ctx->option_stack), g_queue_get_length(ctx->action_list_stack));
|
2008-08-05 16:10:22 +00:00
|
|
|
|
2008-08-12 15:09:05 +00:00
|
|
|
/* TODO config_parser_finish(srv, ctx_stack); */
|
2008-07-17 22:30:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-07-25 21:12:40 +00:00
|
|
|
#ifdef HAVE_LUA_H
|
2008-07-24 11:25:40 +00:00
|
|
|
config_lua_load(srv, config_path);
|
2008-07-17 22:30:02 +00:00
|
|
|
/* lua config frontend */
|
2008-07-25 21:12:40 +00:00
|
|
|
#else
|
|
|
|
g_print("lua config frontend not available\n");
|
|
|
|
return 1;
|
|
|
|
#endif
|
2008-07-17 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 14:52:19 +00:00
|
|
|
/* if config should only be tested, exit here */
|
2008-07-17 21:12:52 +00:00
|
|
|
if (test_config)
|
|
|
|
return 0;
|
2008-07-17 19:39:29 +00:00
|
|
|
|
2008-07-19 10:56:44 +00:00
|
|
|
TRACE(srv, "%s", "Test!");
|
2008-07-17 19:39:29 +00:00
|
|
|
|
2008-08-07 00:25:02 +00:00
|
|
|
/* srv->log_stderr = log_new(srv, LOG_TYPE_FILE, g_string_new("lightytest.log")); */
|
2008-07-19 13:12:32 +00:00
|
|
|
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");
|
2008-07-22 16:58:27 +00:00
|
|
|
log_warning(srv, NULL, "test %s", "foo1"); /* duplicate won't be logged */
|
|
|
|
log_warning(srv, NULL, "test %s", "foo2");
|
2008-07-19 13:12:32 +00:00
|
|
|
log_debug(srv, NULL, "test %s", "message");
|
2008-08-06 18:46:42 +00:00
|
|
|
|
2008-08-15 16:21:21 +00:00
|
|
|
server_loop_init(srv);
|
2008-08-06 18:46:42 +00:00
|
|
|
server_start(srv);
|
|
|
|
|
2008-08-02 20:56:07 +00:00
|
|
|
server_free(srv);
|
|
|
|
|
2008-07-17 19:39:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|