X-Git-Url: http://git.squeep.com/?p=lemu;a=blobdiff_plain;f=main.c;fp=main.c;h=9b0d98d856356c1f5e2f175c0f4137b9c3ceeef6;hp=0000000000000000000000000000000000000000;hb=3c54afe11e890fc476cc4730226be1c45f8a04cb;hpb=29235d4c1f0b11bd2efcad262eaae70383228293 diff --git a/main.c b/main.c new file mode 100644 index 0000000..9b0d98d --- /dev/null +++ b/main.c @@ -0,0 +1,93 @@ +/* + * toy server + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "version.h" +#include "notify.h" +#include "server.h" + +#define DEFAULT_CONFIG_FILE "conf/lemu.conf" + +#define USAGE_FLAGS_LONG (1<<0) +static void +usage_(char *prog, unsigned int usage_flags) +{ + char *x; + + x = strrchr(prog, '/'); + if (x && *(x + 1)) { + prog = x + 1; + } + + printf("Usage: %s [-c config_file]\n", prog); + if (! (usage_flags & USAGE_FLAGS_LONG)) { + return; + } + printf( + "\t-h \t : this help\n" + "\t-c config_file\t : loads the specified config file [default: '" DEFAULT_CONFIG_FILE "']\n" + ); +} + +int +main(int argc, char **argv) +{ + struct server *server; + char *conf_file = DEFAULT_CONFIG_FILE; + int opt; + int r; + + /* enable threading in libevent before anything tries to use it */ + if ( (r = evthread_use_pthreads()) ) { + NOTIFY_ERROR("%s:%d", "evthread_use_pthreads", r); + } + + SSL_load_error_strings(); + SSL_library_init(); + OpenSSL_add_all_algorithms(); + + while ( (opt = getopt(argc, argv, "c:h")) != -1 ) { + switch (opt) { + case 'c': + conf_file = optarg; + break; + case 'h': + usage_(argv[0], USAGE_FLAGS_LONG); + exit(EXIT_SUCCESS); + break; + default: + usage_(argv[0], 0); + exit(EXIT_FAILURE); + } + } + + server = server_new(); + if (!server) { + NOTIFY_FATAL("server_new"); + exit(EXIT_FAILURE); + } + + if (server_init(server, conf_file)) { + NOTIFY_FATAL("error parsing config file '%s'", conf_file); + exit(EXIT_FAILURE); + } + + server_free(server); + + exit(EXIT_SUCCESS); +}