X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=popproxy.c;h=23b17bad3a98f469146c3a88afdec17f4c651b20;hb=078b93116a46cb1a171fed292cc12669efdbb11a;hp=f6c4b57dfc37c6c6e0d75848c1170a475e90b96a;hpb=b7a69d807a1fb39c27d4ffc397d7a526ae43c0f6;p=cascardo%2Frnetproxy.git diff --git a/popproxy.c b/popproxy.c index f6c4b57..23b17ba 100644 --- a/popproxy.c +++ b/popproxy.c @@ -21,10 +21,14 @@ #include #include #include +#include #include +#include #include "log.h" #include "nethook.h" #include "null.h" +#include "ssl.h" +#include "pop.h" #define CONFFILE SYSCONFDIR "/popproxy.conf" @@ -37,7 +41,8 @@ void new_client (GServer* server, GConn* conn, gpointer data) return; } g_message ("Received connection from %s.", conn->hostname); - hook = null_hook_new (conn, data); + hook = ssl_hook_new (conn, data); + pop_hook_new (hook); gnet_conn_read (conn); } @@ -56,10 +61,12 @@ int main (int argc, char** argv) GOptionContext* opt_ctx; GKeyFile *keyfile; GInetAddr* inetaddr; + GError *error; gchar* conf_address; gint port; gchar *server_address; + gnutls_global_init (); gnet_init (); pop_log_init (); @@ -75,21 +82,60 @@ int main (int argc, char** argv) keyfile = g_key_file_new (); - 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); - server_address = g_key_file_get_string (keyfile, "global", "server", NULL); + error = NULL; + if (g_key_file_load_from_file (keyfile, configfile, + G_KEY_FILE_NONE, &error) == FALSE) + { + fprintf (stderr, "Could not load configuration file %s: %s.\n", + configfile, error->message); + g_error_free (error); + exit (1); + } - g_message ("Listen address is %s:%d.", conf_address, port); + error = NULL; + conf_address = g_key_file_get_string (keyfile, "global", "address", + &error); + if (conf_address == NULL && error != NULL) + { + conf_address = g_strdup ("0.0.0.0"); + g_error_free (error); + } + error = NULL; + port = g_key_file_get_integer (keyfile, "global", "port", &error); + if (port == 0 && error != NULL) + { + port = 110; + g_error_free (error); + } + error = NULL; + server_address = g_key_file_get_string (keyfile, "global", "server", + &error); + if (server_address == NULL && error != NULL) + { + server_address = g_strdup ("127.0.0.1"); + g_error_free (error); + } inetaddr = gnet_inetaddr_new_nonblock (conf_address, port); - gnet_server_new (inetaddr, port, new_client, server_address); + if (gnet_server_new (inetaddr, port, + new_client, server_address) == NULL) + { + fprintf (stderr, "Could not create server.\n"); + exit (1); + } + + g_message ("Listening at %s:%d.", conf_address, port); daemon (0, 0); + g_free (conf_address); + g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE)); + gnutls_global_deinit (); + + g_free (server_address); + return 0; }