src/irc_log.c
branchmodules
changeset 55 6f7f6ae729d0
parent 45 71e65564afd2
child 56 942370000450
--- a/src/irc_log.c	Fri Mar 13 17:38:23 2009 +0200
+++ b/src/irc_log.c	Sun Mar 15 01:17:22 2009 +0200
@@ -1,6 +1,8 @@
 #include "irc_log.h"
 #include "log.h"
 
+#include <string.h>
+
 // XXX: fix this err_t crap
 #define LIB_ERR_H
 #include <evsql.h>
@@ -28,33 +30,57 @@
     .on_msg         = on_chan_msg,
 };
 
-err_t irc_log_init (struct event_base *ev_base, const struct irc_log_info *info)
+void* irc_log_init (struct modules *modules, struct error_info *err)
 {
-    struct irc_log_ctx *ctx = &_ctx;
+    struct irc_log_ctx *ctx;
+
+    (void) modules;
+    (void) err;
+        
+    // XXX: static pointer
+    ctx = &_ctx;
+
+    // ok
+    return ctx;
+}
+
+err_t irc_log_conf (struct module *module, const char *name, char *value)
+{
+    struct irc_log_ctx *ctx = module->ctx;
+    struct nexus *nexus = module->modules->nexus;
     err_t err;
 
-    // open the database connection
-    if (info->db_info) {
-        log_info("connect to database: %s", info->db_info);
+    if (strcmp(name, "db_info") == 0) {
+        log_info("connect to database: %s", value);
 
-        if ((ctx->db = evsql_new_pq(ev_base, info->db_info, NULL, NULL)) == NULL)
+        if ((ctx->db = evsql_new_pq(nexus->ev_base, value, NULL, NULL)) == NULL)
            return ERR_EVSQL_NEW_PQ;
+
+    } else if (strcmp(name, "channel") == 0) {
+        const char *network = strsep(&value, ":");
+        const char *channel = value;
+
+        struct irc_chan *chan;
+        
+        // kill missing tokens
+        if (!network || !channel) 
+            // XXX: need to fix the error crap
+            return -1;
+
+        // get the channel?
+        if ((chan = irc_client_get_chan(nexus->client, network, channel)) == NULL)
+            return -1;
+
+        // add channel callbacks
+        if ((err = irc_chan_add_callbacks(chan, &_chan_callbacks, ctx)))
+            return err;
+
+    } else {
+        return -1;
+
     }
-    
-    if (info->channel) {
-        log_info("log channel: %s", irc_chan_name(info->channel));
-    }
-
-    // add channel callbacks
-    if ((err = irc_chan_add_callbacks(info->channel, &_chan_callbacks, ctx)))
-        goto error;
 
     // ok
     return SUCCESS;
-
-error:
-    // XXX: cleanup
-    
-    return err;
 }