diff options
Diffstat (limited to 'src/lua-interface.cpp')
-rw-r--r-- | src/lua-interface.cpp | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/src/lua-interface.cpp b/src/lua-interface.cpp index dccf0d8..bab642b 100644 --- a/src/lua-interface.cpp +++ b/src/lua-interface.cpp @@ -37,6 +37,7 @@ #include <BLua.h> #include <LuaCommandLine.h> #include <HttpServ.h> +#include <MailServer.h> #include <Message.h> #include <Form.h> #include <BRegex.h> @@ -183,7 +184,7 @@ int my_getc (FILE * stream) } #endif -bool interactive = false, server = false; +bool interactive = false, hserver = false, tserver = false, mserver = false; class threaded_Lua : public Lua { public: @@ -432,9 +433,9 @@ struct option long_options[] = { {"built-in", 0, NULL, 'b'}, {"probe", 0, NULL, 'p'}, {"log", 1, NULL, 'g'}, - {"server", 0, NULL, 's'}, - {"hport", 1, NULL, 'h'}, - {"tport", 1, NULL, 't'}, + {"mail", 2, NULL, 'm'}, + {"server", 2, NULL, 's'}, + {"telnet", 2, NULL, 't'}, {"server_fname", 1, NULL, 'f'}, #ifdef HAVE_FORK {"daemonize", 1, NULL, 'z'}, @@ -548,10 +549,10 @@ void showhelp(bool longhelp = false) { " -e <cmd> to execute this single command in LUA.\n" " -b to force the use of the built-in lua-interface.lua\n" " -g <log> to log into a file.\n" -" -s start the built-in http server.\n" -" -p <hp> http port to bind to.\n" -" -t <tp> telnet port to bind to.\n" -" -f <fil> filename of http server to use (server.lua by default).\n" +" -m [mp] start the mail server on port mp (2500 by default).\n" +" -s [hp] start the built-in http server on port hp (1500 by default).\n" +" -t [tp] start the telnet server, on port tp (1550 by default).\n" +" -f <fil> filename of server code to use (server.lua by default).\n" #ifdef HAVE_FORK " -z daemonize; incompatible with -i; use with -g.\n" #endif @@ -710,7 +711,7 @@ virtual int startup() throw (GeneralException) { bool strip = true, todo = false, write = false, builtin = false, daemonize = false; char * file = 0, * output = 0, * compile = 0, * exec = 0; Lua * L = 0; - String hport = "1500", tport = "1550"; + String hport = "1500", tport = "1550", mport = "2500"; pthread_t interactive_thread; verbosity = M_WARNING; @@ -719,7 +720,7 @@ virtual int startup() throw (GeneralException) { /* Let's start parsing options */ - while ((c = getopt_long(argc, argv, "Hhva:c:dile:bg:st:p:f:z", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "Hhva:c:dile:bg:m::s::t::f:z", long_options, NULL)) != EOF) { switch (c) { case 'h': case 'H': @@ -756,14 +757,22 @@ virtual int startup() throw (GeneralException) { printer = new lua_interface_printer_t(new Output(optarg)); break; case 's': - server = true; + hserver = true; todo = true; + if (optarg) + hport = optarg; break; - case 'p': - hport = optarg; + case 'm': + mserver = true; + todo = true; + if (optarg) + mport = optarg; break; case 't': - tport = optarg; + tserver = true; + todo = true; + if (optarg) + tport = optarg; break; case 'f': server_fname = optarg; @@ -856,12 +865,8 @@ virtual int startup() throw (GeneralException) { } #endif - if (server) { - TaskMan::Init(); - } - if (interactive) { - if (server) { + if (mserver || tserver || hserver) { pthread_create(&interactive_thread, NULL, interactive_prompt, L->thread(true)); L->pop(); } else { @@ -869,18 +874,29 @@ virtual int startup() throw (GeneralException) { } } - if (server) { + if (mserver || hserver || tserver) { + TaskMan::Init(); + L->load(&Input(server_fname)); + } + + if (hserver) { HttpServ * httpserv = new HttpServ(new Message("Welcome", "Welcome.", "start"), hport.to_int(), "Lua Interface"); new Form("LUACall", "luacallform", "Enter the function name to call", LUACall_Names, LUACall_Invites, LUACall_Defaults, LUACall_Lists, LUACall_Descs, 1, new LUACall(L)); new ReloadLUA(L); + } + + if (tserver) { new LuaCommandLine(L, tport.to_int()); - L->load(&Input(server_fname)); - - StartTaskLoop(0); + } + + if (mserver) { + new MailServer(mport.to_int()); } - if (interactive && server) { - pthread_join(interactive_thread, NULL); + if (mserver || hserver || tserver) { + StartTaskLoop(0); + if (interactive) + pthread_join(interactive_thread, NULL); } return 0; |