src/nexus.c
branchmodules
changeset 55 6f7f6ae729d0
parent 53 12d806823775
child 56 942370000450
--- a/src/nexus.c	Fri Mar 13 17:38:23 2009 +0200
+++ b/src/nexus.c	Sun Mar 15 01:17:22 2009 +0200
@@ -44,7 +44,7 @@
 
 void on_sigint (evutil_socket_t sig, short what, void *arg)
 {
-    struct nexus_ctx *ctx = arg;
+    struct nexus *ctx = arg;
 
     (void) sig;
     (void) what;
@@ -73,12 +73,12 @@
 {
     int opt, option_index;
     struct signals *signals;
-    struct nexus_ctx ctx;
+    struct nexus ctx;
     struct irc_net *net;
     struct error_info err;
 
     struct irc_net_info net_info = {
-        .network                    = NULL,
+        .network                    = "default",
         .hostname                   = DEFAULT_HOST,
         .service                    = DEFAULT_PORT,
         .use_ssl                    = false,
@@ -89,15 +89,12 @@
         }
     };
 
+    // XXX: hardcode irc_log config
+    char *log_db_info = NULL;
     struct irc_chan_info log_chan_info = {
         .channel                    = NULL, 
     };
 
-    struct irc_log_info log_info = {
-        .db_info                    = NULL,
-        .channel                    = NULL,
-    };
-
     bool port_default = true;
     
     // parse options
@@ -125,7 +122,7 @@
                 break;
             
             case OPT_LOG_DATABASE:
-                log_info.db_info = optarg;
+                log_db_info = optarg;
                 break;
 
             case OPT_LOG_CHANNEL:
@@ -149,6 +146,10 @@
     // initialize sock module
     if (sock_init(ctx.ev_base, &err))
         FATAL_ERROR(&err, "sock_init");
+
+    // modules 
+    if ((ERROR_CODE(&err) = modules_create(&ctx.modules, &ctx)))
+        FATAL_ERROR(&err, "modules_create");
     
     // the IRC client
     if (irc_client_create(&ctx.client, &err))
@@ -166,14 +167,33 @@
         FATAL_ERROR(&err, "signals_add");
     
     // logging?
-    if (log_info.db_info || log_chan_info.channel) {
+    if (log_db_info || log_chan_info.channel) {
+        struct module *mod_irc_log;
+
+        struct module_info mod_irc_log_info = {
+            .name = "irc_log",
+            .path = "modules/irc_log.so"
+        };
+
+        // load the module
+        if (module_load(ctx.modules, &mod_irc_log, &mod_irc_log_info, &err))
+            FATAL_ERROR(&err, "module_load");
+
         // get the channel
-        if (log_chan_info.channel && (log_info.channel = irc_net_add_chan(net, &log_chan_info)) == NULL)
-            FATAL("irc_net_add_chan");
-        
-        // init the irc_log module
-        if ((ERROR_CODE(&err) = irc_log_init(ctx.ev_base, &log_info)))
-            FATAL_ERROR(&err, "irc_log_init");
+        if (log_chan_info.channel) {
+            // create the channel
+            if ((irc_net_add_chan(net, &log_chan_info)) == NULL)
+                FATAL("irc_net_add_chan");
+
+            // configure it
+            // XXX: hardcoded
+            if ((ERROR_CODE(&err) = module_conf(mod_irc_log, "channel", "default/#test")))
+                FATAL_ERROR(&err, "module_conf(irc_log, '%s', '%s)", "channel", "default/#test");
+        }
+
+        // configure the databse info
+        if (log_db_info && (ERROR_CODE(&err) = module_conf(mod_irc_log, "db_info", log_db_info)))
+            FATAL_ERROR(&err, "module_conf(irc_log, 'db_info', '%s')", log_db_info);
     }
 
     // run event loop