src/irc_log.c
branchmodules
changeset 57 ce1accba5fc7
parent 56 942370000450
child 61 4ba21936518a
--- a/src/irc_log.c	Sun Mar 15 23:01:12 2009 +0200
+++ b/src/irc_log.c	Sun Mar 15 23:22:57 2009 +0200
@@ -1,23 +1,27 @@
-#include "irc_log.h"
+#include "module.h"
+#include "irc_chan.h"
+#include "error.h"
 #include "log.h"
 
+#include <stdlib.h>
 #include <string.h>
 
+#include <event2/event.h>
 // XXX: fix this err_t crap
 #define LIB_ERR_H
 #include <evsql.h>
 
 /**
- * The core irc_log state
+ * The irc_log module state
  */
-static struct irc_log_ctx {
+struct irc_log_ctx {
     /** The nexus this module is loaded for */
     struct nexus *nexus;
 
     /** The database connection */
     struct evsql *db;
 
-} _ctx;
+};
 
 static void on_chan_msg (struct irc_chan *chan, const struct irc_nm *source, const char *message, void *arg)
 {
@@ -33,27 +37,27 @@
     .on_msg         = on_chan_msg,
 };
 
-void* irc_log_init (struct modules *modules, struct error_info *err)
+static err_t irc_log_init (struct nexus *nexus, void **ctx_ptr, struct error_info *err)
 {
     struct irc_log_ctx *ctx;
-
-    (void) modules;
-    (void) err;
-        
-    // XXX: static pointer
-    ctx = &_ctx;
+    
+    // allocate
+    if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
+        return SET_ERROR(err, ERR_CALLOC);
 
     // initialize
     memset(ctx, 0, sizeof(*ctx));
 
     // store
-    ctx->nexus = modules->nexus;
+    ctx->nexus = nexus;
 
     // ok
-    return ctx;
+    *ctx_ptr = ctx;
+
+    return SET_ERROR(err, SUCCESS);
 }
 
-err_t irc_log_conf (void *mod_ctx, const char *name, char *value, struct error_info *err)
+static err_t irc_log_conf (void *mod_ctx, const char *name, char *value, struct error_info *err)
 {
     struct irc_log_ctx *ctx = mod_ctx;
 
@@ -90,3 +94,10 @@
     return SUCCESS;
 }
 
+/**
+ * The module function table
+ */
+struct module_funcs irc_log_funcs = {
+    .init       = &irc_log_init,
+    .conf       = &irc_log_conf,
+};