]> jfr.im git - solanum.git/blobdiff - extensions/filter.c
filter: correct type for modinit
[solanum.git] / extensions / filter.c
index 1cb278294748aabf9399ebacc2940f957cc29e27..c4a7f0d67048e010d4383cc5793c001b6f5c370f 100644 (file)
@@ -51,6 +51,8 @@
 
 #define FILTER_EXIT_MSG "Connection closed"
 
+static const char filter_desc[] = "Filter messages using a precompiled Hyperscan database";
+
 static void filter_msg_user(void *data);
 static void filter_msg_channel(void *data);
 static void on_client_exit(void *data);
@@ -98,12 +100,13 @@ struct Message setfilter_msgtab = {
        {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_setfilter, 2}, {mo_setfilter, 2}}
 };
 
-static void
+static int
 modinit(void)
 {
        filter_umode = user_modes['u'] = find_umode_slot();
        construct_umodebuf();
        filter_chmode = cflag_add('u', chm_simple);
+       return 0;
 }
 
 static void
@@ -126,7 +129,7 @@ moddeinit(void)
 
 mapi_clist_av1 filter_clist[] = { &setfilter_msgtab, NULL };
 
-DECLARE_MODULE_AV1(filter, modinit, moddeinit, filter_clist, NULL, filter_hfnlist, "0.3");
+DECLARE_MODULE_AV2(filter, modinit, moddeinit, filter_clist, NULL, filter_hfnlist, NULL, "0.4", filter_desc);
 
 static int
 setfilter(const char *check, const char *data, const char **error)
@@ -162,6 +165,28 @@ setfilter(const char *check, const char *data, const char **error)
                return 0;
        }
 
+       if (!strcasecmp(data, "drop")) {
+               if (!filter_db) {
+                       if (error) *error = "no database to drop";
+                       return -1;
+               }
+               hs_free_database(filter_db);
+               filter_db = 0;
+               return 0;
+       }
+
+       if (!strcasecmp(data, "abort")) {
+               if (state != FILTER_FILLING) {
+                       if (error) *error = "not filling";
+                       return -1;
+               }
+               state = filter_db ? FILTER_LOADED : FILTER_EMPTY;
+               rb_free(filter_data);
+               filter_data = 0;
+               filter_data_len = 0;
+               return 0;
+       }
+
        if (strcmp(check, check_str) != 0) {
                if (error) *error = "check strings don't match";
                return -1;
@@ -196,6 +221,13 @@ setfilter(const char *check, const char *data, const char **error)
                return 0;
        }
 
+       if (*data != '+') {
+               if (error) *error = "unknown command or data doesn't start with +";
+               return -1;
+       }
+
+       data += 1;
+
        if (state == FILTER_FILLING) {
                int dl;
                unsigned char *d = rb_base64_decode(data, strlen(data), &dl);