From aa1f2b9f039878251148c4a6a42a225aea5b9cca Mon Sep 17 00:00:00 2001 From: iratqq Date: Sat, 2 Feb 2008 14:41:16 +0000 Subject: [PATCH] add config file option. --- trunk/src/sj3proxy/sj3proxy.c | 43 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/trunk/src/sj3proxy/sj3proxy.c b/trunk/src/sj3proxy/sj3proxy.c index ef5262f..2d36ae0 100644 --- a/trunk/src/sj3proxy/sj3proxy.c +++ b/trunk/src/sj3proxy/sj3proxy.c @@ -215,26 +215,9 @@ main(int argc, char *argv[]) int daemon_disable = 0; lua_State *lua_state = NULL; int opt_inet4 = 0, opt_inet6 = 0; + char *config_file = SJ3PROXYCFG; - if ((lua_state = luaL_newstate()) == NULL) { - fprintf(stderr, "Can't setup lua"); - exit(1); - } - - luaL_openlibs(lua_state); - - /* sj3.functions */ - lua_newtable(lua_state); - set_luafunction(lua_state, "set_server", set_server); - set_luafunction(lua_state, "get_server", get_server); - lua_setglobal(lua_state, "sj3proxy"); - - if (luaL_dofile(lua_state, SJ3PROXYCFG) != 0) { - fprintf(stderr, "%s\n", lua_tostring(lua_state, -1)); - exit(255); - } - - while ((c = getopt(argc, argv, "46d")) != EOF) { + while ((c = getopt(argc, argv, "46c:d")) != EOF) { switch (c) { case '4': opt_inet4 = 1; @@ -242,6 +225,9 @@ main(int argc, char *argv[]) case '6': opt_inet6 = 1; break; + case 'c': + config_file = optarg; + break; case 'd': daemon_disable = 1; break; @@ -257,6 +243,25 @@ main(int argc, char *argv[]) exit(1); } + if ((lua_state = luaL_newstate()) == NULL) { + fprintf(stderr, "Can't setup lua"); + exit(1); + } + + luaL_openlibs(lua_state); + + /* sj3.functions */ + lua_newtable(lua_state); + set_luafunction(lua_state, "set_server", set_server); + set_luafunction(lua_state, "get_server", get_server); + lua_setglobal(lua_state, "sj3proxy"); + + if (luaL_dofile(lua_state, config_file) != 0) { + fprintf(stderr, "%s\n", lua_tostring(lua_state, -1)); + exit(255); + } + + if (strcmp(address_family_str, "unspec") == 0) address_family = AF_UNSPEC; if (opt_inet4 || strcmp(address_family_str, "inet") == 0)