]> jfr.im git - solanum.git/blobdiff - extensions/extb_combi.c
Add `solanum.chat/oper` capablity (#217)
[solanum.git] / extensions / extb_combi.c
index fbe4b78672fe33e14c39fc6e4fc15e0dd5562317..c9f356428fafde27d454da78f9ab3e929159b448 100644 (file)
 #include "client.h"
 #include "ircd.h"
 
-// #define DEBUG(s) sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, (s))
-#define DEBUG(s)
+static const char extb_desc[] = "Combination ($&, $|) extban types";
+
+// #define MOD_DEBUG(s) sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, (s))
+#define MOD_DEBUG(s)
 #define RETURN_INVALID { recursion_depth--; return EXTBAN_INVALID; }
 
 static int _modinit(void);
 static void _moddeinit(void);
 static int eb_or(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
 static int eb_and(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type);
-static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type, int is_and);
+static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type, bool is_and);
 static int recursion_depth = 0;
 
-DECLARE_MODULE_AV1(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, "$Revision: 1 $");
+DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
 
 static int
 _modinit(void)
@@ -74,30 +76,30 @@ _moddeinit(void)
 static int eb_or(const char *data, struct Client *client_p,
                                 struct Channel *chptr, long mode_type)
 {
-       return eb_combi(data, client_p, chptr, mode_type, FALSE);
+       return eb_combi(data, client_p, chptr, mode_type, false);
 }
 
 static int eb_and(const char *data, struct Client *client_p,
                                  struct Channel *chptr, long mode_type)
 {
-       return eb_combi(data, client_p, chptr, mode_type, TRUE);
+       return eb_combi(data, client_p, chptr, mode_type, true);
 }
 
 static int eb_combi(const char *data, struct Client *client_p,
-                                       struct Channel *chptr, long mode_type, int is_and)
+                                       struct Channel *chptr, long mode_type, bool is_and)
 {
        const char *p, *banend;
-       int have_result = FALSE;
-       int allowed_nodes = 3;
+       bool have_result = false;
+       int allowed_nodes = 11;
        size_t datalen;
 
        if (recursion_depth >= 5) {
-               DEBUG("combo invalid: recursion depth too high");
+               MOD_DEBUG("combo invalid: recursion depth too high");
                return EXTBAN_INVALID;
        }
 
        if (EmptyString(data)) {
-               DEBUG("combo invalid: empty data");
+               MOD_DEBUG("combo invalid: empty data");
                return EXTBAN_INVALID;
        }
 
@@ -106,7 +108,7 @@ static int eb_combi(const char *data, struct Client *client_p,
                /* I'd be sad if this ever happened, but if it does we
                 * could overflow the buffer used below, so...
                 */
-               DEBUG("combo invalid: > BANLEN");
+               MOD_DEBUG("combo invalid: > BANLEN");
                return EXTBAN_INVALID;
        }
        banend = data + datalen;
@@ -115,7 +117,7 @@ static int eb_combi(const char *data, struct Client *client_p,
                p = data + 1;
                banend--;
                if (*banend != ')') {
-                       DEBUG("combo invalid: starting but no closing paren");
+                       MOD_DEBUG("combo invalid: starting but no closing paren");
                        return EXTBAN_INVALID;
                }
        } else {
@@ -124,7 +126,7 @@ static int eb_combi(const char *data, struct Client *client_p,
 
        /* Empty combibans are invalid. */
        if (banend == p) {
-               DEBUG("combo invalid: no data (after removing parens)");
+               MOD_DEBUG("combo invalid: no data (after removing parens)");
                return EXTBAN_INVALID;
        }
 
@@ -141,28 +143,28 @@ static int eb_combi(const char *data, struct Client *client_p,
        recursion_depth++;
 
        while (--allowed_nodes) {
-               int invert = FALSE;
+               bool invert = false;
                char *child_data, child_data_buf[BANLEN];
                ExtbanFunc f;
 
                if (*p == '~') {
-                       invert = TRUE;
+                       invert = true;
                        p++;
                        if (p == banend) {
-                               DEBUG("combo invalid: no data after ~");
+                               MOD_DEBUG("combo invalid: no data after ~");
                                RETURN_INVALID;
                        }
                }
 
                f = extban_table[(unsigned char) *p++];
                if (!f) {
-                       DEBUG("combo invalid: non-existant child extban");
+                       MOD_DEBUG("combo invalid: non-existant child extban");
                        RETURN_INVALID;
                }
 
                if (*p == ':') {
                        unsigned int parencount = 0;
-                       int escaped = FALSE, done = FALSE;
+                       bool escaped = false, done = false;
                        char *o;
 
                        p++;
@@ -171,10 +173,10 @@ static int eb_combi(const char *data, struct Client *client_p,
                         * we already have_result.
                         */
                        o = child_data = child_data_buf;
-                       while (TRUE) {
+                       while (true) {
                                if (p == banend) {
                                        if (parencount) {
-                                               DEBUG("combo invalid: EOD while in parens");
+                                               MOD_DEBUG("combo invalid: EOD while in parens");
                                                RETURN_INVALID;
                                        }
                                        break;
@@ -184,11 +186,11 @@ static int eb_combi(const char *data, struct Client *client_p,
                                        if (*p != '(' && *p != ')' && *p != '\\' && *p != ',')
                                                *o++ = '\\';
                                        *o++ = *p++;
-                                       escaped = FALSE;
+                                       escaped = false;
                                } else {
                                        switch (*p) {
                                        case '\\':
-                                               escaped = TRUE;
+                                               escaped = true;
                                                break;
                                        case '(':
                                                parencount++;
@@ -196,7 +198,7 @@ static int eb_combi(const char *data, struct Client *client_p,
                                                break;
                                        case ')':
                                                if (!parencount) {
-                                                       DEBUG("combo invalid: negative parencount");
+                                                       MOD_DEBUG("combo invalid: negative parencount");
                                                        RETURN_INVALID;
                                                }
                                                parencount--;
@@ -206,7 +208,7 @@ static int eb_combi(const char *data, struct Client *client_p,
                                                if (parencount)
                                                        *o++ = *p;
                                                else
-                                                       done = TRUE;
+                                                       done = true;
                                                break;
                                        default:
                                                *o++ = *p;
@@ -226,7 +228,7 @@ static int eb_combi(const char *data, struct Client *client_p,
                        int child_result = f(child_data, client_p, chptr, mode_type);
 
                        if (child_result == EXTBAN_INVALID) {
-                               DEBUG("combo invalid: child invalid");
+                               MOD_DEBUG("combo invalid: child invalid");
                                RETURN_INVALID;
                        }
 
@@ -237,26 +239,26 @@ static int eb_combi(const char *data, struct Client *client_p,
                                child_result = child_result == EXTBAN_MATCH;
 
                        if (is_and ? !child_result : child_result)
-                               have_result = TRUE;
+                               have_result = true;
                }
 
                if (p == banend)
                        break;
 
                if (*p++ != ',') {
-                       DEBUG("combo invalid: no ',' after ban");
+                       MOD_DEBUG("combo invalid: no ',' after ban");
                        RETURN_INVALID;
                }
 
                if (p == banend) {
-                       DEBUG("combo invalid: banend after ','");
+                       MOD_DEBUG("combo invalid: banend after ','");
                        RETURN_INVALID;
                }
        }
 
        /* at this point, *p should == banend */
        if (p != banend) {
-               DEBUG("combo invalid: more child extbans than allowed");
+               MOD_DEBUG("combo invalid: more child extbans than allowed");
                RETURN_INVALID;
        }