fixed mod-watchdog.c basics
authorpk910 <philipp@zoelle1.de>
Wed, 20 Jul 2011 20:38:25 +0000 (22:38 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 20 Jul 2011 20:58:54 +0000 (22:58 +0200)
src/mod-watchdog.c

index 11d59c5f535472c8d98f83da1e7081052c012621..1d70cf6f1746d774f173a22af0ee0a63eb51eb03 100644 (file)
 #include "saxdb.h"
 #include "timeq.h"
 
-#define KEY_SENT "sent"
+#define KEY_BADWORDS "badwords"
+#define KEY_BADWORD_MASK "mask"
+#define KEY_BADWORD_TRIGGERED "count"
+#define KEY_BADWORD_ACTION "action"
 
 static const struct message_entry msgtab[] = {
     { "WDMSG_NULL", "null." },
@@ -56,14 +59,16 @@ DEFINE_LIST(shitList, struct badword*)
 #define BADACTION_GLINE  3
 
 static struct {
-    char *nick;
-    char *modes;
+    const char *nick;
+    const char *modes;
 } watchdog_conf;
 
+const char *watchdog_module_deps[] = { NULL };
 struct userNode *watchdog;
 static struct module *watchdog_module;
 static struct service *watchdog_service;
-static struct shitList *shitlist;
+static struct shitList shitlist;
+static struct log_type *MS_LOG;
 
 
 static MODCMD_FUNC(cmd_addbad)
@@ -97,7 +102,7 @@ watchdog_channel_message(struct userNode *user, struct chanNode *chan, const cha
 }
 
 static struct badword*
-add_badword(char *badword, unsigned int triggered, unsigned int action)
+add_badword(char *badword_mask, unsigned int triggered, unsigned int action)
 {
     struct badword *badword;
 
@@ -105,17 +110,17 @@ add_badword(char *badword, unsigned int triggered, unsigned int action)
     if (!badword)
         return NULL;
 
-    badword->badword_mask = strdup(badword);
+    badword->badword_mask = strdup(badword_mask);
     badword->triggered = triggered;
     badword->action = action;
-    shitlist_append(&shitlist, badword);
+    shitList_append(&shitlist, badword);
     return badword;
 }
 
 static void
 delete_badword(struct badword *badword)
 {
-    shitlist_remove(&shitlist, badword);
+    shitList_remove(&shitlist, badword);
     free(badword->badword_mask);
     free(badword);
 }
@@ -139,7 +144,7 @@ watchdog_conf_read(void)
     watchdog_conf.nick = str;
     
     str = database_get_data(conf_node, "modes", RECDB_QSTRING);
-    watchdog_conf.modes = str;
+    watchdog_conf.modes = (str ? str : NULL);
 }
 
 static int
@@ -166,8 +171,9 @@ static int
 watchdog_saxdb_read(struct dict *db)
 {
     struct dict *object;
-    if ((object = database_get_data(conf_db, KEY_BADWORDS, RECDB_OBJECT)))
+    if ((object = database_get_data(db, KEY_BADWORDS, RECDB_OBJECT)))
         dict_foreach(object, watchdog_saxdb_read_shitlist, NULL);
+    return 1;
 }
 
 static int
@@ -178,8 +184,8 @@ watchdog_saxdb_write(struct saxdb_context *ctx)
     unsigned int id = 0, ii;
 
     saxdb_start_record(ctx, KEY_BADWORDS, 1);
-    for (ii = 0; ii < ma->recvd.used; ++ii) {
-        badword = ma->recvd.list[ii];
+    for (ii = 0; ii < shitlist.used; ++ii) {
+        badword = shitlist.list[ii];
         snprintf(str, sizeof(str), "%x", id++);
         saxdb_start_record(ctx, str, 0);
         saxdb_write_string(ctx, KEY_BADWORD_MASK, badword->badword_mask);
@@ -197,23 +203,24 @@ watchdog_cleanup(void)
 {
     while (shitlist.used)
         delete_badword(shitlist.list[0]);
-    shitlist_clean(&shitlist);
+    shitList_clean(&shitlist);
 }
 
 int
 watchdog_init(void)
 {
     MS_LOG = log_register_type("Watchdog", "file:watchdog.log");
+    shitList_init(&shitlist);
     conf_register_reload(watchdog_conf_read);
     reg_exit_func(watchdog_cleanup);
     saxdb_register("Watchdog", watchdog_saxdb_read, watchdog_saxdb_write);
 
     const char *nick, *modes;
-    if(nick = conf_get_data("services/spamserv/nick", RECDB_QSTRING)) {
-        modes = conf_get_data("services/spamserv/modes", RECDB_QSTRING);
-        spamserv = AddLocalUser(nick, nick, NULL, "Watchdog Service", modes);
-        spamserv_service = service_register(spamserv);
-        reg_allchanmsg_func(spamserv, watchdog_channel_message);
+    if((nick = conf_get_data("services/watchdog/nick", RECDB_QSTRING))) {
+        modes = conf_get_data("services/watchdog/modes", RECDB_QSTRING);
+        watchdog = AddLocalUser(nick, nick, NULL, "Watchdog Service", modes);
+        watchdog_service = service_register(watchdog);
+        reg_allchanmsg_func(watchdog, watchdog_channel_message);
     }
 
     watchdog_module = module_register("Watchdog", MS_LOG, "mod-watchdog.help", NULL);