]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/newsearch.h
overflow in G's welcome command
[irc/quakenet/newserv.git] / newsearch / newsearch.h
index 9950ab7da37dc6c663d7765c434cf25e4459112b..8c7f928f4fac5f515fc8e8d93779583211905f5e 100644 (file)
@@ -6,6 +6,9 @@
 #include "../authext/authext.h"
 #include "../patricia/patricia.h"
 
+#ifndef __NEWSEARCH_H
+#define __NEWSEARCH_H
+
 #define    NSMAX_KILL_LIMIT       500
 #define    NSMAX_GLINE_LIMIT      500
 #define    NSMAX_GLINE_CLONES     5
@@ -132,6 +135,7 @@ struct searchNode *ip_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *channels_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *cidr_parse(searchCtx *ctx, int argc, char **argv);
 
 /* Channel functions (various types) */
 struct searchNode *exists_parse(searchCtx *ctx, int argc, char **argv);
@@ -210,33 +214,36 @@ struct searchASTNode;
 /* items to store in the ast lookup cache */
 #define AST_RECENT 10
 
+struct searchASTExpr;
+
+typedef struct searchASTNode {
+  parseFunc fn;
+  int argc;
+  struct searchASTExpr *argv;
+} searchASTNode;
+
 typedef struct searchASTExpr {
   int type;
   union {
     char *literal;
-    struct searchASTNode *child;
+    /* this was originally a pointer, but having it as one means you can't memcpy directly */
+    struct searchASTNode child;
   } u;
 } searchASTExpr;
 
-typedef struct searchASTNode {
-  parseFunc fn;
-  int argc;
-  struct searchASTExpr **argv;
-} searchASTNode;
+#define __NSASTSizeOfArray(x) (sizeof(x) / sizeof(x[0]))
+
+#define __NSASTExpr(x, y, ...) (searchASTExpr){.type = x, .u.y = __VA_ARGS__}
+#define __NSASTRawNode(x, c, y) (searchASTNode){.fn = x, .argc = c, .argv = y}
+
+#define __NSASTSizeNode(x, y) __NSASTRawNode(x, __NSASTSizeOfArray(y), y)
+#define __NSASTNode(x, ...) __NSASTSizeNode(x, ((searchASTExpr []){__VA_ARGS__}))
 
-/*
- *
- * FEAR THE COMPOUND LITERALS
- * MUHAHAHHAHAHAHAHAHAAH
- *
- */
-#define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__}
-#define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__}
-#define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)}
 #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__)
 
-#define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data)
+#define NSASTLiteral(value) __NSASTExpr(AST_NODE_LITERAL, literal, value)
 #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__))
+#define NSASTManualNode(fn, count, children) __NSASTChild(__NSASTRawNode(fn, count, children))
 
 searchNode *search_astparse(searchCtx *, char *);
 
@@ -248,6 +255,8 @@ char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr, searchCmd *c
 
 int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void *display, CommandTree *sl, replyFunc reply, void *sender);
 
+typedef int (*ASTFunc)(searchASTExpr *, replyFunc, void *, wallFunc, void *, HeaderFunc, void *, int limit);
+
 /* erk */
 extern searchList *globalterms;
 
@@ -259,3 +268,4 @@ extern UserDisplayFunc defaultuserfn;
 extern NickDisplayFunc defaultnickfn;
 extern ChanDisplayFunc defaultchanfn;
 
+#endif