X-Git-Url: http://git.cascardo.info/?a=blobdiff_plain;f=improxy.c;h=4217a517895a4093825a8e1f8ed33a7726b33fa8;hb=c8ca9622fe25f936881889e95d60a6a91126ff13;hp=987ecb05668613895b016d0eeaae423318806840;hpb=8feb6ebdc5e07e47f60c3ebee79df65f8f0c2c85;p=cascardo%2Frnetproxy.git diff --git a/improxy.c b/improxy.c index 987ecb0..4217a51 100644 --- a/improxy.c +++ b/improxy.c @@ -3,6 +3,8 @@ #include #include "log.h" +#define CONFFILE "/etc/improxy.conf" + void client_event (GConn* conn, GConnEvent* event, gpointer data) { GConn* server; @@ -48,9 +50,19 @@ void new_client (GServer* server, GConn* conn, gpointer data) gnet_conn_read (conn); } -int main () +static gchar* configfile; + +static GOptionEntry opt_entries[] = + { + { "config-file", 'c', 0, G_OPTION_ARG_FILENAME, &configfile, + "Configuration file location", "file" }, + { NULL } + }; + +int main (int argc, char** argv) { + GOptionContext* opt_ctx; GKeyFile *keyfile; GInetAddr* inetaddr; gchar* conf_address; @@ -59,9 +71,19 @@ int main () gnet_init (); im_log_init (); + configfile = CONFFILE; + opt_ctx = g_option_context_new (""); + g_option_context_add_main_entries (opt_ctx, opt_entries, NULL); + if (!g_option_context_parse (opt_ctx, &argc, &argv, NULL)) + { + g_log (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, + "Could not parse command line options."); + } + g_option_context_free (opt_ctx); + keyfile = g_key_file_new (); - g_key_file_load_from_file (keyfile, "improxy.conf", G_KEY_FILE_NONE, NULL); + g_key_file_load_from_file (keyfile, configfile, G_KEY_FILE_NONE, NULL); conf_address = g_key_file_get_string (keyfile, "global", "address", NULL); port = g_key_file_get_integer (keyfile, "global", "port", NULL);