6 #include "proto_detect.h"
8 #define CONFFILE SYSCONFDIR "/improxy.conf"
10 void client_event (GConn* conn, GConnEvent* event, gpointer data)
13 hook = (net_hook_t*) data;
16 case GNET_CONN_CONNECT:
20 hook->read (hook, event->buffer, event->length);
29 g_warning ("Received an unexpected client event.");
34 void new_client (GServer* server, GConn* conn, gpointer data)
39 g_critical ("Server has received an error event.");
42 g_message ("Received connection from %s.", conn->hostname);
43 hook = proto_detect_new (conn);
44 gnet_conn_set_callback (conn, client_event, hook);
45 gnet_conn_read (conn);
48 static gchar* configfile;
50 static GOptionEntry opt_entries[] =
52 { "config-file", 'c', 0, G_OPTION_ARG_FILENAME, &configfile,
53 "Configuration file location", "file" },
57 int main (int argc, char** argv)
60 GOptionContext* opt_ctx;
69 configfile = CONFFILE;
70 opt_ctx = g_option_context_new ("");
71 g_option_context_add_main_entries (opt_ctx, opt_entries, NULL);
72 if (!g_option_context_parse (opt_ctx, &argc, &argv, NULL))
74 g_log (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL,
75 "Could not parse command line options.");
77 g_option_context_free (opt_ctx);
79 keyfile = g_key_file_new ();
81 g_key_file_load_from_file (keyfile, configfile, G_KEY_FILE_NONE, NULL);
83 conf_address = g_key_file_get_string (keyfile, "global", "address", NULL);
84 port = g_key_file_get_integer (keyfile, "global", "port", NULL);
86 g_message ("Listen address is %s:%d.", conf_address, port);
88 inetaddr = gnet_inetaddr_new_nonblock (conf_address, port);
89 gnet_server_new (inetaddr, port, new_client, NULL);
91 g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));