1 #include "../nick/nick.h"
2 #include "../parser/parser.h"
3 #include "../channel/channel.h"
4 #include "../lib/flags.h"
5 #include "../authext/authext.h"
7 #define SEARCHTYPE_CHANNEL 1
8 #define SEARCHTYPE_NICK 2
9 #define SEARCHTYPE_USER 3
12 #define NSMAX_KILL_LIMIT 500
13 #define NSMAX_GLINE_LIMIT 500
16 #define NSMAX_GLINE_CLONES 5
19 /* gline duration, in seconds */
20 #define NSGLINE_DURATION 3600
22 #define NSMAX_REASON_LEN 120
23 #define NSMAX_NOTICE_LEN 250
26 #define RETURNTYPE_BOOL 0x01
27 #define RETURNTYPE_INT 0x02
28 #define RETURNTYPE_STRING 0x03
29 #define RETURNTYPE_TYPE 0xFF
30 #define RETURNTYPE_CONST 0x100
32 #define VARIABLE_LEN 10
33 #define MAX_VARIABLES 10
39 typedef struct searchNode
*(*searchParseFunc
)(struct searchCtx
*ctx
, int type
, char *input
);
40 typedef void (*replyFunc
)(nick
*np
, char *format
, ...);
41 typedef void (*wallFunc
)(int level
, char *format
, ...);
43 typedef struct searchNode
*(*parseFunc
)(struct searchCtx
*, int, int, char **);
44 typedef void (*freeFunc
)(struct searchCtx
*, struct searchNode
*);
45 typedef void *(*exeFunc
)(struct searchCtx
*, struct searchNode
*, void *);
46 typedef void (*ChanDisplayFunc
)(struct searchCtx
*, nick
*, chanindex
*);
47 typedef void (*NickDisplayFunc
)(struct searchCtx
*, nick
*, nick
*);
48 typedef void (*UserDisplayFunc
)(struct searchCtx
*, nick
*, authname
*);
49 typedef void (*HeaderFunc
)(void *sender
, void *arg
);
52 struct searchNode
*child
;
59 typedef struct searchNode
{
66 struct searchVariable
{
67 char name
[VARIABLE_LEN
];
68 struct searchNode data
;
69 struct coercedata cdata
;
72 typedef struct searchCtx
{
73 searchParseFunc parser
;
77 struct searchVariable vars
[MAX_VARIABLES
];
82 /* Logical (BOOL -> BOOL)*/
83 struct searchNode
*and_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
84 struct searchNode
*not_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
85 struct searchNode
*or_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
87 /* Comparison (INT -> BOOL) */
88 struct searchNode
*eq_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
89 struct searchNode
*lt_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
90 struct searchNode
*gt_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
92 /* String match (STRING -> BOOL) */
93 struct searchNode
*match_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
94 struct searchNode
*regex_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
96 /* Length (STRING -> INT) */
97 struct searchNode
*length_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
99 /* kill/gline actions (BOOL) */
100 struct searchNode
*kill_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
101 struct searchNode
*gline_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
103 /* notice action (BOOL) */
104 struct searchNode
*notice_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
106 /* Nick/Channel functions (various types) */
107 struct searchNode
*nick_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
108 struct searchNode
*modes_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
110 /* Nick functions (various types) */
111 struct searchNode
*hostmask_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
112 struct searchNode
*realname_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
113 struct searchNode
*authname_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
114 struct searchNode
*authts_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
115 struct searchNode
*ident_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
116 struct searchNode
*host_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
117 struct searchNode
*channel_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
118 struct searchNode
*timestamp_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
119 struct searchNode
*country_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
120 struct searchNode
*ip_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
121 struct searchNode
*channels_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
122 struct searchNode
*server_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
123 struct searchNode
*authid_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
125 /* Channel functions (various types) */
126 struct searchNode
*exists_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
127 struct searchNode
*services_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
128 struct searchNode
*size_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
129 struct searchNode
*name_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
130 struct searchNode
*topic_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
131 struct searchNode
*oppct_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
132 struct searchNode
*hostpct_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
133 struct searchNode
*authedpct_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
134 struct searchNode
*kick_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
136 /* Interpret a string to give a node */
137 struct searchNode
*search_parse(searchCtx
*ctx
, int type
, char *input
);
139 /* Iteration functions */
140 struct searchNode
*any_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
141 struct searchNode
*all_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
142 struct searchNode
*var_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
144 /* Iteraterable functions */
145 struct searchNode
*channeliter_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
);
147 /* Force a node to return the thing you want */
148 struct searchNode
*coerceNode(searchCtx
*ctx
, struct searchNode
*thenode
, int type
);
150 /* Registration functions */
151 void registersearchterm(char *term
, parseFunc parsefunc
);
152 void deregistersearchterm(char *term
, parseFunc parsefunc
);
153 void regchandisp(const char *name
, ChanDisplayFunc handler
);
154 void unregchandisp(const char *name
, ChanDisplayFunc handler
);
155 void regnickdisp(const char *name
, NickDisplayFunc handler
);
156 void unregnickdisp(const char *name
, NickDisplayFunc handler
);
157 void reguserdisp(const char *name
, UserDisplayFunc handler
);
158 void unreguserdisp(const char *name
, UserDisplayFunc handler
);
160 /* Special nick* printf */
161 void nssnprintf(char *, size_t, const char *, nick
*);
163 extern const char *parseError
;
164 extern nick
*senderNSExtern
;
166 void printnick(searchCtx
*, nick
*, nick
*);
167 void printuser(searchCtx
*, nick
*, authname
*);
169 void nicksearch_exe(struct searchNode
*search
, searchCtx
*sctx
, nick
*sender
, NickDisplayFunc display
, int limit
);
170 void chansearch_exe(struct searchNode
*search
, searchCtx
*sctx
, nick
*sender
, ChanDisplayFunc display
, int limit
);
171 void usersearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, UserDisplayFunc display
, int limit
);
173 int do_nicksearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
174 int do_chansearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
175 int do_usersearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
177 void *literal_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
178 void literal_free(searchCtx
*ctx
, struct searchNode
*thenode
);
180 struct searchVariable
*var_register(searchCtx
*ctx
, int nstype
, char *arg
, int type
);
181 searchNode
*var_get(searchCtx
*ctx
, int nstype
, char *arg
);
182 void var_setstr(struct searchVariable
*v
, char *data
);
184 void newsearch_ctxinit(searchCtx
*ctx
, searchParseFunc searchfn
, replyFunc replyfn
, wallFunc wallfn
, void *arg
);
188 struct searchASTNode
;
190 #define AST_NODE_CHILD 1
191 #define AST_NODE_LITERAL 2
193 /* items to store in the ast lookup cache */
194 #define AST_RECENT 10
196 typedef struct searchASTExpr
{
200 struct searchASTNode
*child
;
204 typedef struct searchASTNode
{
207 struct searchASTExpr
**argv
;
212 * FEAR THE COMPOUND LITERALS
213 * MUHAHAHHAHAHAHAHAHAAH
216 #define __NSASTExpr(x, y, ...) &(searchASTExpr){.type = x, .u.y = __VA_ARGS__}
217 #define __NSASTList(...) (searchASTExpr *[]){__VA_ARGS__}
218 #define __NSASTNode(x, ...) &(searchASTNode){.fn = x, .argc = sizeof(__NSASTList(__VA_ARGS__)) / sizeof(__NSASTList(__VA_ARGS__)[0]), .argv = __NSASTList(__VA_ARGS__)}
219 #define __NSASTChild(...) __NSASTExpr(AST_NODE_CHILD, child, __VA_ARGS__)
221 #define NSASTLiteral(data) __NSASTExpr(AST_NODE_LITERAL, literal, data)
222 #define NSASTNode(fn, ...) __NSASTChild(__NSASTNode(fn, __VA_ARGS__))
224 searchNode
*search_astparse(searchCtx
*, int, char *);
226 int ast_nicksearch(searchASTExpr
*tree
, replyFunc reply
, void *sender
, wallFunc wall
, NickDisplayFunc display
, HeaderFunc header
, void *headerarg
, int limit
);
227 int ast_chansearch(searchASTExpr
*tree
, replyFunc reply
, void *sender
, wallFunc wall
, ChanDisplayFunc display
, HeaderFunc header
, void *headerarg
, int limit
);
228 int ast_usersearch(searchASTExpr
*tree
, replyFunc reply
, void *sender
, wallFunc wall
, UserDisplayFunc display
, HeaderFunc header
, void *headerarg
, int limit
);
230 char *ast_printtree(char *buf
, size_t bufsize
, searchASTExpr
*expr
);
233 extern CommandTree
*searchTree
;
235 extern UserDisplayFunc defaultuserfn
;
236 extern NickDisplayFunc defaultnickfn
;
237 extern ChanDisplayFunc defaultchanfn
;