]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/newsearch.c
help changes
[irc/quakenet/newserv.git] / newsearch / newsearch.c
CommitLineData
c86edd1d 1#include <stdio.h>
0da2a4ae 2#include <stdarg.h>
b697c21c 3#include <string.h>
c86edd1d
Q
4
5#include "../irc/irc_config.h"
c86edd1d
Q
6#include "../lib/irc_string.h"
7#include "../parser/parser.h"
8#include "../control/control.h"
9#include "../lib/splitline.h"
87698d77 10#include "../lib/version.h"
ba8a65c4 11#include "../lib/stringbuf.h"
b697c21c 12#include "../lib/strlfunc.h"
a92bb8e1
P
13#include "../lib/array.h"
14#include "newsearch.h"
87698d77 15
70b0a4e5 16MODULE_VERSION("");
c86edd1d 17
a92bb8e1
P
18CommandTree *searchCmdTree;
19searchList *globalterms = NULL;
c86edd1d
Q
20
21int do_nicksearch(void *source, int cargc, char **cargv);
56a84a81 22int do_chansearch(void *source, int cargc, char **cargv);
e8ad630b 23int do_usersearch(void *source, int cargc, char **cargv);
d00af236 24
3d2bf13b
CP
25void printnick_channels(searchCtx *, nick *, nick *);
26void printchannel(searchCtx *, nick *, chanindex *);
27void printchannel_topic(searchCtx *, nick *, chanindex *);
28void printchannel_services(searchCtx *, nick *, chanindex *);
c86edd1d 29
55dd7529
CP
30UserDisplayFunc defaultuserfn = printuser;
31NickDisplayFunc defaultnickfn = printnick;
32ChanDisplayFunc defaultchanfn = printchannel;
33
a92bb8e1 34searchCmd *reg_nicksearch, *reg_chansearch, *reg_usersearch;
e8ff7b61 35void displaycommandhelp(nick *, Command *);
c86edd1d 36
a92bb8e1
P
37searchCmd *registersearchcommand(char *name, int level, CommandHandler cmd, void *defaultdisplayfunc) {
38 searchCmd *acmd;
39 searchList *sl;
73cfc302 40
e8ff7b61 41 registercontrolhelpfunccmd(name, NO_OPER,4, cmd, &displaycommandhelp);
a92bb8e1 42 acmd=(struct searchCmd *)malloc(sizeof(struct searchCmd));
e8ff7b61
P
43 if (!acmd) {
44 Error("newsearch", ERR_ERROR, "malloc failed: registersearchcommand");
45 return NULL;
46 }
a92bb8e1
P
47 acmd->handler = cmd;
48
49 acmd->name = getsstring( name, NSMAX_COMMAND_LEN);
50 acmd->outputtree = newcommandtree();
51 acmd->searchtree = newcommandtree();
73cfc302 52
a92bb8e1
P
53 addcommandtotree(searchCmdTree, name, 0, 0, (CommandHandler)acmd);
54
e8ff7b61
P
55 for (sl=globalterms; sl; sl=sl->next) {
56 registersearchterm( acmd, sl->name->content, sl->cmd, 0, sl->help);
a92bb8e1
P
57 }
58
59 return acmd;
73cfc302 60}
61
a92bb8e1
P
62void deregistersearchcommand(searchCmd *scmd) {
63 deregistercontrolcmd(scmd->name->content, (CommandHandler)scmd->handler);
64 destroycommandtree(scmd->outputtree);
65 destroycommandtree(scmd->searchtree);
66 freesstring(scmd->name);
67 free(scmd);
e8ad630b
CP
68}
69
e8ff7b61
P
70void displaycommandhelp(nick *np, Command *cmd) {
71 int i,n,j,m;
72 Command *cmdlist[100], *acmdlist[100];
73 searchCmd *acmd;
74
75 n=getcommandlist(searchCmdTree,cmdlist,100);
76 for(i=0;i<n;i++) {
77 /* note: we may want to only deregister a command if we've already registered it, for now, try de-registering new commands anyway */
78 if ( ((searchCmd *)cmdlist[i]->handler)->handler != cmd->handler )
79 continue;
80 acmd = ((searchCmd *)(cmdlist[i]->handler));
81
82 controlreply(np, "Usage: [flags] <criteria>\n");
83 controlreply(np, "Flags:\n");
84 controlreply(np, " -l int : Limit number of rows of results\n");
85 controlreply(np, " -d string : a valid output format for the results\n");
86 controlreply(np, " -s subset : ipmask subset of network to search (only for node search)\n");
87 controlreply(np, " \n");
88 controlreply(np, "Available Output Formats:\n");
89
90 m=getcommandlist(acmd->outputtree,acmdlist,100);
91 for(j=0;j<m;j++) {
92 if ( controlpermitted( acmdlist[j]->level, np) ) {
93 char *help=(char *)acmdlist[j]->ext;
94 if ( help && help[0] != '\0')
95 controlreply(np, "%-10s: %s\n", acmdlist[j]->command->content, help);
96 else
97 controlreply(np, "%s\n", acmdlist[j]->command->content );
98 }
99 }
100
101 controlreply(np, " \n");
7a8355d1 102 controlreply(np, "Available Global Commands and Operators:\n" );
e8ff7b61
P
103 m=getcommandlist(acmd->searchtree,acmdlist,100);
104 for(j=0;j<m;j++) {
105 if ( acmdlist[j]->maxparams) {
106 char *help=(char *)acmdlist[j]->ext;
107 if ( help && help[0] != '\0')
108 controlreply(np, "%-10s: %s\n", acmdlist[j]->command->content, help );
109 else
110 controlreply(np, "%s\n", acmdlist[j]->command->content );
111 }
112 }
113
114 controlreply(np, " \n");
7a8355d1 115 controlreply(np, "Available Commands and Operators for %s:\n", acmd->name->content);
e8ff7b61
P
116
117 m=getcommandlist(acmd->searchtree,acmdlist,100);
118 for(j=0;j<m;j++) {
119 if ( !acmdlist[j]->maxparams && controlpermitted( acmdlist[j]->level, np) ) {
120 char *help=(char *)acmdlist[j]->ext;
121 if ( help && help[0] != '\0')
122 controlreply(np, "%-10s: %s\n", acmdlist[j]->command->content, help );
123 else
124 controlreply(np, "%s\n", acmdlist[j]->command->content );
125 }
126 }
127 }
128}
129
130void regdisp( searchCmd *cmd, const char *name, void *handler, int level, char *help) {
131 addcommandexttotree(cmd->outputtree, name, level, 0, (CommandHandler) handler, (char *)help);
a92bb8e1
P
132}
133
134void unregdisp( searchCmd *cmd, const char *name, void *handler ) {
135 deletecommandfromtree(cmd->outputtree, name, (CommandHandler) handler);
e8ad630b
CP
136}
137
a92bb8e1 138void *findcommandinlist( searchList *sl, char *name){
e8ff7b61 139 while (sl) {
a92bb8e1
P
140 if(strcmp(sl->name->content,name) == 0 ) {
141 return sl;
142 }
e8ff7b61 143 sl=sl->next;
a92bb8e1
P
144 }
145 return NULL;
146}
147
c86edd1d 148const char *parseError;
16cc6e32
IB
149/* used for *_free functions that need to warn users of certain things
150 i.e. hitting too many users in a (kill) or (gline) */
219d27f1 151nick *senderNSExtern;
c86edd1d
Q
152
153void _init() {
a92bb8e1
P
154 searchCmdTree=newcommandtree();
155
156 reg_nicksearch = (searchCmd *)registersearchcommand("nicksearch",NO_OPER,&do_nicksearch, printnick);
157 reg_chansearch = (searchCmd *)registersearchcommand("chansearch",NO_OPER,&do_chansearch, printchannel);
158 reg_usersearch = (searchCmd *)registersearchcommand("usersearch",NO_OPER,&do_usersearch, printuser);
c86edd1d
Q
159
160 /* Boolean operations */
e8ff7b61
P
161 registerglobalsearchterm("and",and_parse, "usage: (and (X) (X))" );
162 registerglobalsearchterm("not",not_parse, "usage: (not (X))");
163 registerglobalsearchterm("or",or_parse, "usage: (or (X) (X))" );
f1903ace 164
e8ff7b61 165 registerglobalsearchterm("eq",eq_parse, "usage: (eq (X) Y)");
f1903ace 166
e8ff7b61
P
167 registerglobalsearchterm("lt",lt_parse, "usage: (lt (X) int)");
168 registerglobalsearchterm("gt",gt_parse, "usage: (gt (X) int)");
c86edd1d
Q
169
170 /* String operations */
e8ff7b61
P
171 registerglobalsearchterm("match",match_parse, "usage: (match (X) string)");
172 registerglobalsearchterm("regex",regex_parse, "usage: (regex (X) string)");
173 registerglobalsearchterm("length",length_parse, "usage: (length string)");
c7f7a584 174
c86edd1d 175 /* Nickname operations */
7a8355d1
P
176 registersearchterm(reg_nicksearch, "hostmask",hostmask_parse, 0, "The user's nick!user@host; \"hostmask real\" returns nick!user@host\rreal"); /* nick only */
177 registersearchterm(reg_nicksearch, "realname",realname_parse, 0, "User's current realname"); /* nick only */
178 registersearchterm(reg_nicksearch, "authname",authname_parse, 0, "User's current authname or false"); /* nick only */
179 registersearchterm(reg_nicksearch, "authts",authts_parse, 0, "User's Auth timestamp"); /* nick only */
180 registersearchterm(reg_nicksearch, "ident",ident_parse, 0, "User's current ident"); /* nick only */
181 registersearchterm(reg_nicksearch, "host",host_parse, 0, "User's host, allow \"host real\" to match real host"); /* nick only */
d369fba6 182 registersearchterm(reg_nicksearch, "channel",channel_parse, 0, "Valid Channel Name to match users against"); /* nick only */
7a8355d1 183 registersearchterm(reg_nicksearch, "timestamp",timestamp_parse, 0, "User's Timestamp"); /* nick only */
e8ff7b61 184 registersearchterm(reg_nicksearch, "country",country_parse, 0, "2 letter country code (data source is geoip)"); /* nick only */
7a8355d1 185 registersearchterm(reg_nicksearch, "ip",ip_parse, 0, "User's IP - ipv4 or ipv6 format as appropriate. Note: not 6to4"); /* nick only */
d369fba6
P
186 registersearchterm(reg_nicksearch, "channels",channels_parse, 0, "Channel Count"); /* nick only */
187 registersearchterm(reg_nicksearch, "server",server_parse, 0, "Server Name. Either (server string) or (match (server) string)"); /* nick only */
7a8355d1 188 registersearchterm(reg_nicksearch, "authid",authid_parse, 0, "User's Auth ID"); /* nick only */
c86edd1d 189
56a84a81 190 /* Channel operations */
d369fba6 191 registersearchterm(reg_chansearch, "exists",exists_parse, 0, "Returns if channel exists on network. Note: newserv may store data on empty channels"); /* channel only */
e8ff7b61 192 registersearchterm(reg_chansearch, "services",services_parse, 0, ""); /* channel only */
d369fba6
P
193 registersearchterm(reg_chansearch, "size",size_parse, 0, "Channel user count"); /* channel only */
194 registersearchterm(reg_chansearch, "name",name_parse, 0, "Channel Name"); /* channel only */
195 registersearchterm(reg_chansearch, "topic",topic_parse, 0, "Channel topic"); /* channel only */
196 registersearchterm(reg_chansearch, "oppct",oppct_parse, 0, "Percentage Opped"); /* channel only */
197 registersearchterm(reg_chansearch, "uniquehostpct",hostpct_parse, 0, "uniquehost percent"); /* channel only */
198 registersearchterm(reg_chansearch, "authedpct",authedpct_parse, 0, "Percentage of authed users"); /* channel only */
199 registersearchterm(reg_chansearch, "kick",kick_parse, 0, "KICK users channels in newsearch result. Note: evaluation order"); /* channel only */
56a84a81 200
c86edd1d 201 /* Nickname / channel operations */
d369fba6
P
202 registersearchterm(reg_chansearch, "modes",modes_parse, 0, "User Modes");
203 registersearchterm(reg_nicksearch, "modes",modes_parse, 0, "Channel Modes");
204 registersearchterm(reg_chansearch, "nick",nick_parse, 0, "Nickname");
205 registersearchterm(reg_nicksearch, "nick",nick_parse, 0, "Nickname");
c86edd1d 206
16cc6e32 207 /* Kill / gline parameters */
d369fba6
P
208 registersearchterm(reg_chansearch,"kill",kill_parse, 0, "KILL users in newsearch result. Note: evaluation order");
209 registersearchterm(reg_chansearch,"gline",gline_parse, 0, "GLINE users in newsearch result. Note: evaluation order");
210 registersearchterm(reg_nicksearch,"kill",kill_parse, 0, "KILL users in newsearch result. Note: evaluation order");
211 registersearchterm(reg_nicksearch,"gline",gline_parse, 0, "GLINE users in newsearch result. Note: evaluation order");
4622c762 212
b697c21c 213 /* Iteration functionality */
d369fba6
P
214 registerglobalsearchterm("any",any_parse, "usage: any (generatorfn x) (fn ... (var x) ...)");
215 registerglobalsearchterm("all",all_parse, "usage: all (generatorfn x) (fn ... (var x) ...)");
216 registerglobalsearchterm("var",var_parse, "usage: var variable");
b697c21c
CP
217
218 /* Iterable functions */
d369fba6 219 registersearchterm(reg_nicksearch, "channeliter",channeliter_parse, 0, "Channel Iterable function - usage: (any (channeliter x) (match (var x) #twilight*))"); /* nick only */
b697c21c 220
4622c762 221 /* Notice functionality */
d369fba6
P
222 registersearchterm(reg_chansearch,"notice",notice_parse, 0, "NOTICE users in newsearch result. Note: evaluation order");
223 registersearchterm(reg_nicksearch,"notice",notice_parse, 0, "NOTICE users in newsearch result. Note: evaluation order");
a92bb8e1 224
73cfc302 225 /* Nick output filters */
e8ff7b61
P
226 regdisp(reg_nicksearch,"default",printnick, 0, "");
227 regdisp(reg_nicksearch,"channels",printnick_channels, 0, "include channels in output");
d00af236 228
73cfc302 229 /* Channel output filters */
e8ff7b61
P
230 regdisp(reg_chansearch,"default",printchannel, 0, "");
231 regdisp(reg_chansearch,"topic",printchannel_topic, 0, "display channel topics");
232 regdisp(reg_chansearch,"services",printchannel_services, 0, "display services on channels");
16cc6e32 233
e8ad630b 234 /* Nick output filters */
e8ff7b61 235 regdisp(reg_usersearch,"default",printuser, 0, "");
a92bb8e1 236
c86edd1d
Q
237}
238
239void _fini() {
a92bb8e1
P
240 searchList *sl, *psl;
241 int i,n;
242 Command *cmdlist[100];
243
e8ff7b61 244 sl=globalterms;
a92bb8e1
P
245 while (sl) {
246 psl = sl;
e8ff7b61 247 sl=sl->next;
a92bb8e1
P
248
249 n=getcommandlist(searchCmdTree,cmdlist,100);
250 for(i=0;i<n;i++) {
251 deregistersearchterm( (searchCmd *)cmdlist[i]->handler, psl->name->content, psl->cmd);
252 }
253
254 freesstring(psl->name);
e8ff7b61
P
255 if (psl->help)
256 free (psl->help);
a92bb8e1 257 free(psl);
a92bb8e1
P
258 }
259
260 deregistersearchcommand( reg_nicksearch );
261 deregistersearchcommand( reg_chansearch );
262 deregistersearchcommand( reg_usersearch );
263 destroycommandtree( searchCmdTree );
264}
265
e8ff7b61 266void registerglobalsearchterm(char *term, parseFunc parsefunc, char *help) {
a92bb8e1
P
267 int i,n;
268 Command *cmdlist[100];
e8ff7b61
P
269 searchList *sl = malloc(sizeof(searchList));
270 if (!sl) {
271 Error("newsearch", ERR_ERROR, "malloc failed: registerglobalsearchterm");
272 return;
273 }
a92bb8e1
P
274
275 sl->cmd = parsefunc;
276 sl->name = getsstring(term, NSMAX_COMMAND_LEN);
277 sl->next = NULL;
e8ff7b61
P
278 if (help) {
279 int len=strlen(help);
280 sl->help=(char *)malloc(len+1);
281 if(!sl->help) {
282 Error("newsearch", ERR_ERROR, "malloc failed: registerglobalsearchterm");
283 return;
284 }
285 strncpy(sl->help, help, len);
286 sl->help[len] = '\0';
287 } else {
288 sl->help=NULL;
289 }
290
a92bb8e1
P
291
292 if ( globalterms != NULL ) {
293 sl->next = globalterms;
294 }
295 globalterms = sl;
296
297 n=getcommandlist(searchCmdTree,cmdlist,100);
298 for(i=0;i<n;i++) {
e8ff7b61
P
299 /* maxparams is set to 1 to indicate a global term */
300 /* access level is set to 0 for all global terms */
301 addcommandexttotree( ((searchCmd *)cmdlist[i]->handler)->searchtree,term, 0, 1, (CommandHandler) parsefunc, help);
a92bb8e1
P
302 }
303}
304
305void deregisterglobalsearchterm(char *term, parseFunc parsefunc) {
306 int i,n;
307 Command *cmdlist[100];
308 searchList *sl, *psl=NULL;
309
e8ff7b61 310 for (sl=globalterms; sl; sl=sl->next) {
a92bb8e1
P
311 if ( strcmp( sl->name->content, term) == 0 ) {
312 break;
313 }
314 psl = sl;
a92bb8e1
P
315 }
316
317 if (sl) {
318 if( psl ) {
319 psl->next = sl->next;
320 }
321
322 n=getcommandlist(searchCmdTree,cmdlist,100);
323 for(i=0;i<n;i++) {
e8ff7b61 324 deletecommandfromtree( ((searchCmd *)cmdlist[i]->handler)->searchtree, term, (CommandHandler) parsefunc);
a92bb8e1
P
325 }
326 freesstring(sl->name);
327 free(sl);
328 }
c86edd1d
Q
329}
330
e8ff7b61
P
331void registersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc, int level, char *help) {
332 /* NOTE: global terms are added to the tree elsewhere as we set maxparams to 1 to indicate global */
333 addcommandexttotree(cmd->searchtree, term, level, 0, (CommandHandler) parsefunc, help);
c86edd1d
Q
334}
335
a92bb8e1 336void deregistersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc) {
e8ff7b61 337 /* NOTE: global terms are removed from the tree within deregisterglobalsearchterm */
a92bb8e1 338 deletecommandfromtree(cmd->searchtree, term, (CommandHandler) parsefunc);
c86edd1d
Q
339}
340
bb4b25ee 341static void controlwallwrapper(int level, char *format, ...) __attribute__ ((format (printf, 2, 3)));
0da2a4ae
CP
342static void controlwallwrapper(int level, char *format, ...) {
343 char buf[1024];
344 va_list ap;
345
346 va_start(ap, format);
347 vsnprintf(buf, sizeof(buf), format, ap);
348 controlwall(NO_OPER, level, "%s", buf);
349 va_end(ap);
350}
351
a92bb8e1 352int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void **display, CommandTree *sl, replyFunc reply, void *sender) {
c86edd1d 353 char *ch;
a92bb8e1
P
354 Command *cmd;
355 struct irc_in_addr sin; unsigned char bits;
356
c86edd1d
Q
357 if (*cargv[0] == '-') {
358 /* options */
e8ad630b 359 (*arg)++;
c86edd1d
Q
360
361 for (ch=cargv[0]+1;*ch;ch++) {
362 switch(*ch) {
363 case 'l':
e8ad630b 364 if (cargc<*arg) {
e8ff7b61
P
365 reply(sender,"Error: -l switch requires an argument (for help, see help <searchcmd>)");
366 return CMD_ERROR;
c86edd1d 367 }
e8ad630b 368 *limit=strtoul(cargv[(*arg)++],NULL,10);
c86edd1d
Q
369 break;
370
73cfc302 371 case 'd':
e8ad630b 372 if (cargc<*arg) {
e8ff7b61
P
373 reply(sender,"Error: -d switch requires an argument (for help, see help <searchcmd>)");
374 return CMD_ERROR;
73cfc302 375 }
a92bb8e1 376 cmd=findcommandintree(sl, cargv[*arg],1);
73cfc302 377 if (!cmd) {
e8ff7b61
P
378 reply(sender,"Error: unknown output format %s (for help, see help <searchcmd>)",cargv[*arg]);
379 return CMD_ERROR;
380 }
381 if ( !controlpermitted( cmd->level, sender) ) {
382 reply(sender,"Error: Access Denied for output format %s (for help, see help <searchcmd>)", cargv[*arg]);
383 return CMD_ERROR;
73cfc302 384 }
e8ad630b
CP
385 *display=(void *)cmd->handler;
386 (*arg)++;
73cfc302 387 break;
a92bb8e1
P
388
389 case 's':
390 if (cargc<*arg) {
e8ff7b61
P
391 reply(sender,"Error: -s switch requires an argument (for help, see help <searchcmd>)");
392 return CMD_ERROR;
a92bb8e1
P
393 }
394 if (ipmask_parse(cargv[*arg], &sin, &bits) == 0) {
e8ff7b61
P
395 reply(sender, "Error: Invalid CIDR mask supplied (for help, see help <searchcmd>)");
396 return CMD_ERROR;
a92bb8e1
P
397 }
398 *subset = (void *)refnode(iptree, &sin, bits);
399 (*arg)++;
400 break;
73cfc302 401
c86edd1d 402 default:
e8ff7b61
P
403 reply(sender,"Unrecognised flag -%c. (for help, see help <searchcmd>)",*ch);
404 return CMD_ERROR;
c86edd1d
Q
405 }
406 }
407 }
408
e8ad630b
CP
409 return CMD_OK;
410}
411
e8ff7b61 412void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *np) {
b697c21c
CP
413 memset(ctx, 0, sizeof(searchCtx));
414
415 ctx->reply = replyfn;
416 ctx->wall = wallfn;
417 ctx->parser = searchfn;
418 ctx->arg = arg;
a92bb8e1 419 ctx->searchcmd = cmd;
e8ff7b61 420 ctx->sender = np;
b697c21c
CP
421}
422
e8ad630b 423int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
b697c21c 424 nick *sender = source;
e8ad630b
CP
425 struct searchNode *search;
426 int limit=500;
427 int arg=0;
55dd7529 428 NickDisplayFunc display=defaultnickfn;
e8ad630b
CP
429 searchCtx ctx;
430 int ret;
431
e8ff7b61
P
432 if (cargc<1) {
433 reply( sender, "Usage: [flags] <criteria>");
434 reply( sender, "For help, see help nicksearch");
435 return CMD_OK;
436 }
437
a92bb8e1 438 ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_nicksearch->outputtree, reply, sender);
e8ad630b
CP
439 if(ret != CMD_OK)
440 return ret;
441
c86edd1d 442 if (arg>=cargc) {
4156103f 443 reply(sender,"No search terms - aborting.");
c86edd1d
Q
444 return CMD_ERROR;
445 }
446
447 if (arg<(cargc-1)) {
448 rejoinline(cargv[arg],cargc-arg);
449 }
c8be5183 450
e8ff7b61 451 newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_nicksearch, sender);
c8be5183 452
f33f3f52 453 if (!(search = ctx.parser(&ctx, cargv[arg]))) {
0da2a4ae 454 reply(sender,"Parse error: %s",parseError);
c86edd1d
Q
455 return CMD_ERROR;
456 }
c2c414be 457
c8be5183
CP
458 nicksearch_exe(search, &ctx, sender, display, limit);
459
460 (search->free)(&ctx, search);
c2c414be
CP
461
462 return CMD_OK;
463}
464
0da2a4ae
CP
465int do_nicksearch(void *source, int cargc, char **cargv) {
466 return do_nicksearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
467}
468
c8be5183 469void nicksearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, NickDisplayFunc display, int limit) {
c2c414be
CP
470 int i, j;
471 int matches = 0;
472 unsigned int cmarker;
473 unsigned int tchans=0,uchans=0;
474 struct channel **cs;
475 nick *np;
b697c21c
CP
476 senderNSExtern = sender;
477
7c02e111 478 /* Get a marker value to mark "seen" channels for unique count */
479 cmarker=nextchanmarker();
480
c7f7a584 481 /* The top-level node needs to return a BOOL */
c8be5183 482 search=coerceNode(ctx, search, RETURNTYPE_BOOL);
c7f7a584 483
c86edd1d
Q
484 for (i=0;i<NICKHASHSIZE;i++) {
485 for (np=nicktable[i];np;np=np->next) {
c8be5183 486 if ((search->exe)(ctx, search, np)) {
7c02e111 487 /* Add total channels */
488 tchans += np->channels->cursi;
489
490 /* Check channels for uniqueness */
491 cs=(channel **)np->channels->content;
492 for (j=0;j<np->channels->cursi;j++) {
493 if (cs[j]->index->marker != cmarker) {
494 cs[j]->index->marker=cmarker;
495 uchans++;
496 }
497 }
498
c86edd1d 499 if (matches<limit)
3d2bf13b 500 display(ctx, sender, np);
7c02e111 501
c86edd1d 502 if (matches==limit)
c8be5183 503 ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
c86edd1d
Q
504 matches++;
505 }
506 }
507 }
508
c8be5183 509 ctx->reply(sender,"--- End of list: %d matches; users were on %u channels (%u unique, %.1f average clones)",
7c02e111 510 matches, tchans, uchans, (float)tchans/uchans);
c86edd1d
Q
511}
512
0da2a4ae 513int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
b697c21c 514 nick *sender = source;
56a84a81 515 struct searchNode *search;
c2c414be 516 int limit=500;
56a84a81 517 int arg=0;
55dd7529 518 ChanDisplayFunc display=defaultchanfn;
c8be5183 519 searchCtx ctx;
e8ad630b 520 int ret;
56a84a81 521
e8ff7b61
P
522 if (cargc<1) {
523 reply( sender, "Usage: [flags] <criteria>");
524 reply( sender, "For help, see help chansearch");
525 return CMD_OK;
526 }
56a84a81 527
a92bb8e1 528 ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_chansearch->outputtree, reply, sender);
e8ad630b
CP
529 if(ret != CMD_OK)
530 return ret;
56a84a81
IB
531
532 if (arg>=cargc) {
4156103f 533 reply(sender,"No search terms - aborting.");
56a84a81
IB
534 return CMD_ERROR;
535 }
536
537 if (arg<(cargc-1)) {
538 rejoinline(cargv[arg],cargc-arg);
539 }
c2c414be 540
e8ff7b61 541 newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_chansearch, sender);
f33f3f52 542 if (!(search = ctx.parser(&ctx, cargv[arg]))) {
0da2a4ae 543 reply(sender,"Parse error: %s",parseError);
56a84a81
IB
544 return CMD_ERROR;
545 }
c7f7a584 546
c8be5183 547 chansearch_exe(search, &ctx, sender, display, limit);
c2c414be 548
c8be5183 549 (search->free)(&ctx, search);
c2c414be
CP
550
551 return CMD_OK;
552}
553
0da2a4ae
CP
554int do_chansearch(void *source, int cargc, char **cargv) {
555 return do_chansearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
556}
557
c8be5183 558void chansearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, ChanDisplayFunc display, int limit) {
c2c414be
CP
559 int i;
560 chanindex *cip;
561 int matches = 0;
b697c21c 562 senderNSExtern = sender;
c2c414be 563
c8be5183 564 search=coerceNode(ctx, search, RETURNTYPE_BOOL);
56a84a81
IB
565
566 for (i=0;i<CHANNELHASHSIZE;i++) {
567 for (cip=chantable[i];cip;cip=cip->next) {
c8be5183 568 if ((search->exe)(ctx, search, cip)) {
56a84a81 569 if (matches<limit)
3d2bf13b 570 display(ctx, sender, cip);
56a84a81 571 if (matches==limit)
c8be5183 572 ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
56a84a81
IB
573 matches++;
574 }
575 }
576 }
577
c8be5183 578 ctx->reply(sender,"--- End of list: %d matches", matches);
56a84a81
IB
579}
580
e8ad630b 581int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
b697c21c 582 nick *sender = source;
e8ad630b
CP
583 struct searchNode *search;
584 int limit=500;
585 int arg=0;
55dd7529 586 UserDisplayFunc display=defaultuserfn;
e8ad630b
CP
587 searchCtx ctx;
588 int ret;
589
e8ff7b61
P
590 if (cargc<1) {
591 reply( sender, "Usage: [flags] <criteria>");
592 reply( sender, "For help, see help usersearch");
593 return CMD_OK;
594 }
595
a92bb8e1 596 ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_usersearch->outputtree, reply, sender);
e8ad630b
CP
597 if(ret != CMD_OK)
598 return ret;
599
600 if (arg>=cargc) {
4156103f 601 reply(sender,"No search terms - aborting.");
e8ad630b
CP
602 return CMD_ERROR;
603 }
604
605 if (arg<(cargc-1)) {
606 rejoinline(cargv[arg],cargc-arg);
607 }
608
e8ff7b61
P
609 newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_usersearch, sender);
610
f33f3f52 611 if (!(search = ctx.parser(&ctx, cargv[arg]))) {
e8ad630b
CP
612 reply(sender,"Parse error: %s",parseError);
613 return CMD_ERROR;
614 }
615
616 usersearch_exe(search, &ctx, sender, display, limit);
617
618 (search->free)(&ctx, search);
619
620 return CMD_OK;
621}
622
623int do_usersearch(void *source, int cargc, char **cargv) {
624 return do_usersearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
625}
626
627void usersearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, UserDisplayFunc display, int limit) {
628 int i;
629 authname *aup;
630 int matches = 0;
b697c21c 631 senderNSExtern = sender;
e8ad630b
CP
632
633 search=coerceNode(ctx, search, RETURNTYPE_BOOL);
634
635 for (i=0;i<AUTHNAMEHASHSIZE;i++) {
636 for (aup=authnametable[i];aup;aup=aup->next) {
637 if ((search->exe)(ctx, search, aup)) {
638 if (matches<limit)
639 display(ctx, sender, aup);
640 if (matches==limit)
641 ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
642 matches++;
643 }
644 }
645 }
646
647 ctx->reply(sender,"--- End of list: %d matches", matches);
648}
649
c7f7a584 650/* Free a coerce node */
c8be5183 651void free_coerce(searchCtx *ctx, struct searchNode *thenode) {
c7f7a584 652 struct coercedata *cd=thenode->localdata;
653
c8be5183 654 cd->child->free(ctx, cd->child);
c7f7a584 655 free(thenode->localdata);
656 free(thenode);
657}
c86edd1d 658
c7f7a584 659/* Free a coerce node with a stringbuf allocated */
c8be5183 660void free_coercestring(searchCtx *ctx, struct searchNode *thenode) {
c7f7a584 661 free(((struct coercedata *)thenode->localdata)->u.stringbuf);
c8be5183 662 free_coerce(ctx, thenode);
c7f7a584 663}
664
665/* exe_tostr_null: return the constant string */
c8be5183 666void *exe_tostr_null(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 667 struct coercedata *cd=thenode->localdata;
668
669 return cd->u.stringbuf;
670}
671
672/* exe_val_null: return the constant value */
c8be5183 673void *exe_val_null(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 674 struct coercedata *cd=thenode->localdata;
675
676 return (void *)cd->u.val;
677}
678
679/* Lots of very dull type conversion functions */
c8be5183 680void *exe_inttostr(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 681 struct coercedata *cd=thenode->localdata;
682
c8be5183 683 sprintf(cd->u.stringbuf, "%lu", (unsigned long)(cd->child->exe)(ctx, cd->child, theinput));
c7f7a584 684
685 return cd->u.stringbuf;
686}
687
c8be5183 688void *exe_booltostr(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 689 struct coercedata *cd=thenode->localdata;
690
c8be5183 691 if ((cd->child->exe)(ctx, cd->child, theinput)) {
c7f7a584 692 sprintf(cd->u.stringbuf,"1");
693 } else {
694 cd->u.stringbuf[0]='\0';
695 }
696
697 return cd->u.stringbuf;
698}
c86edd1d 699
c8be5183 700void *exe_strtoint(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 701 struct coercedata *cd=thenode->localdata;
702
c8be5183 703 return (void *)strtoul((cd->child->exe)(ctx,cd->child,theinput),NULL,10);
c7f7a584 704}
705
c8be5183 706void *exe_booltoint(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 707 struct coercedata *cd=thenode->localdata;
708
709 /* Don't need to do anything */
c8be5183 710 return (cd->child->exe)(ctx, cd->child, theinput);
c7f7a584 711}
712
c8be5183 713void *exe_strtobool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 714 struct coercedata *cd=thenode->localdata;
c8be5183 715 char *ch=(cd->child->exe)(ctx, cd->child, theinput);
c7f7a584 716
717 if (!ch || *ch=='\0' || (*ch=='0' && ch[1]=='\0')) {
718 return (void *)0;
719 } else {
720 return (void *)1;
721 }
722}
723
c8be5183 724void *exe_inttobool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c7f7a584 725 struct coercedata *cd=thenode->localdata;
726
c8be5183 727 if ((cd->child->exe)(ctx, cd->child, theinput)) {
c7f7a584 728 return (void *)1;
729 } else {
730 return (void *)0;
731 }
732}
733
c8be5183 734struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type) {
c7f7a584 735 struct searchNode *anode;
736 struct coercedata *cd;
737
738 /* You can't coerce a NULL */
739 if (!thenode)
740 return NULL;
741
742 /* No effort required to coerce to the same type */
743 if (type==(thenode->returntype & RETURNTYPE_TYPE))
744 return thenode;
745
746 anode=(struct searchNode *)malloc(sizeof(struct searchNode));
747 anode->localdata=cd=(struct coercedata *)malloc(sizeof(struct coercedata));
748 cd->child=thenode;
749 anode->returntype=type; /* We'll return what they want, always */
750 anode->free=free_coerce;
751
752 switch(type) {
753 case RETURNTYPE_STRING:
754 /* For a string we'll need a buffer */
755 /* A 64-bit number prints out to 20 digits, this leaves some slack */
756 cd->u.stringbuf=malloc(25);
757 anode->free=free_coercestring;
758
759 switch(thenode->returntype & RETURNTYPE_TYPE) {
760 default:
761 case RETURNTYPE_INT:
762 if (thenode->returntype & RETURNTYPE_CONST) {
763 /* Constant node: sort it out now */
c8be5183 764 sprintf(cd->u.stringbuf, "%lu", (unsigned long)thenode->exe(ctx, thenode, NULL));
c7f7a584 765 anode->exe=exe_tostr_null;
766 anode->returntype |= RETURNTYPE_CONST;
767 } else {
768 /* Variable data */
769 anode->exe=exe_inttostr;
770 }
771 break;
772
773 case RETURNTYPE_BOOL:
774 if (thenode->returntype & RETURNTYPE_CONST) {
775 /* Constant bool value */
c8be5183 776 if (thenode->exe(ctx, thenode,NULL)) {
c7f7a584 777 /* True! */
778 sprintf(cd->u.stringbuf, "1");
779 } else {
780 cd->u.stringbuf[0] = '\0';
781 }
782 anode->exe=exe_tostr_null;
783 anode->returntype |= RETURNTYPE_CONST;
784 } else {
785 /* Variable bool value */
786 anode->exe=exe_booltostr;
787 }
788 break;
789 }
790 break;
791
792 case RETURNTYPE_INT:
793 /* we want an int */
794 switch (thenode->returntype & RETURNTYPE_TYPE) {
795 case RETURNTYPE_STRING:
796 if (thenode->returntype & RETURNTYPE_CONST) {
c8be5183 797 cd->u.val=strtoul((thenode->exe)(ctx, thenode, NULL), NULL, 10);
c7f7a584 798 anode->exe=exe_val_null;
799 anode->returntype |= RETURNTYPE_CONST;
800 } else {
801 anode->exe=exe_strtoint;
802 }
803 break;
804
805 default:
806 case RETURNTYPE_BOOL:
807 if (thenode->returntype & RETURNTYPE_CONST) {
c8be5183 808 if ((thenode->exe)(ctx, thenode,NULL))
c7f7a584 809 cd->u.val=1;
810 else
811 cd->u.val=0;
812
813 anode->exe=exe_val_null;
814 anode->returntype |= RETURNTYPE_CONST;
815 } else {
816 anode->exe=exe_booltoint;
817 }
818 break;
819 }
820 break;
821
822 default:
823 case RETURNTYPE_BOOL:
824 /* we want a bool */
825 switch (thenode->returntype & RETURNTYPE_TYPE) {
826 case RETURNTYPE_STRING:
827 if (thenode->returntype & RETURNTYPE_CONST) {
c8be5183 828 char *rv=(char *)((thenode->exe)(ctx, thenode, NULL));
c7f7a584 829 if (!rv || *rv=='\0' || (*rv=='0' && rv[1]=='\0'))
830 cd->u.val=0;
831 else
832 cd->u.val=1;
833
834 anode->exe=exe_val_null;
835 anode->returntype |= RETURNTYPE_CONST;
836 } else {
837 anode->exe=exe_strtobool;
838 }
839 break;
840
841 default:
842 case RETURNTYPE_INT:
843 if (thenode->returntype & RETURNTYPE_CONST) {
c8be5183 844 if ((thenode->exe)(ctx, thenode,NULL))
c7f7a584 845 cd->u.val=1;
846 else
847 cd->u.val=0;
848
849 anode->exe=exe_val_null;
850 anode->returntype |= RETURNTYPE_CONST;
851 } else {
852 anode->exe=exe_inttobool;
853 }
854 break;
855 }
856 break;
857 }
858
859 return anode;
860}
861
862/* Literals always return constant strings... */
c8be5183 863void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
2e2a8c6a
P
864 if (thenode->localdata)
865 return ((sstring *)thenode->localdata)->content;
866 else
867 return "";
c7f7a584 868}
869
c8be5183 870void literal_free(searchCtx *ctx, struct searchNode *thenode) {
c7f7a584 871 freesstring(thenode->localdata);
872 free(thenode);
873}
c86edd1d
Q
874
875/* search_parse:
876 * Given an input string, return a searchNode.
877 */
878
f33f3f52 879struct searchNode *search_parse(searchCtx *ctx, char *input) {
c86edd1d
Q
880 /* OK, we need to split the input into chunks on spaces and brackets.. */
881 char *argvector[100];
1bf9cda6 882 char thestring[500];
c7f7a584 883 int i,j,q=0,e=0;
1bf9cda6 884 char *ch,*ch2;
c86edd1d
Q
885 struct Command *cmd;
886 struct searchNode *thenode;
c86edd1d
Q
887
888 /* If it starts with a bracket, it's a function call.. */
889 if (*input=='(') {
890 /* Skip past string */
891 for (ch=input;*ch;ch++);
892 if (*(ch-1) != ')') {
893 parseError = "Bracket mismatch!";
894 return NULL;
895 }
896 input++;
897 *(ch-1)='\0';
898
899 /* Split further args */
900 i=-1; /* i = -1 BoW, 0 = inword, 1 = bracket nest depth */
901 j=0; /* j = current arg */
1bf9cda6 902 e=0;
903 q=0;
a33e0d2b 904 argvector[0]="";
c86edd1d
Q
905 for (ch=input;*ch;ch++) {
906 if (i==-1) {
1bf9cda6 907 argvector[j]=ch;
908 if (*ch=='(') {
909 i=1;
910 } else if (*ch != ' ') {
911 i=0;
912 if (*ch=='\\') {
913 e=1;
914 } else if (*ch=='\"') {
915 q=1;
916 }
917 }
918 } else if (e==1) {
919 e=0;
920 } else if (q==1) {
921 if (*ch=='\"')
922 q=0;
c86edd1d 923 } else if (i==0) {
1bf9cda6 924 if (*ch=='\\') {
925 e=1;
926 } else if (*ch=='\"') {
927 q=1;
928 } else if (*ch==' ') {
929 *ch='\0';
930 j++;
4cd6347c
P
931 if(j >= (sizeof(argvector) / sizeof(*argvector))) {
932 parseError = "Too many arguments";
933 return NULL;
934 }
1bf9cda6 935 i=-1;
936 }
c86edd1d 937 } else {
1bf9cda6 938 if (*ch=='\\') {
939 e=1;
940 } else if (*ch=='\"') {
941 q=1;
942 } else if (*ch=='(') {
943 i++;
944 } else if (*ch==')') {
945 i--;
946 }
c86edd1d
Q
947 }
948 }
949
950 if (i>0) {
951 parseError = "Bracket mismatch!";
952 return NULL;
953 }
4cd6347c
P
954
955 if (*(ch-1) == 0) /* if the last character was a space */
956 j--; /* remove an argument */
c86edd1d 957
a92bb8e1 958 if (!(cmd=findcommandintree(ctx->searchcmd->searchtree,argvector[0],1))) {
e8ff7b61 959 parseError = "Unknown command (for valid command list, see help <searchcmd>)";
c86edd1d
Q
960 return NULL;
961 } else {
e8ff7b61
P
962 if ( !controlpermitted( cmd->level, ctx->sender) ) {
963 parseError = "Access Denied (for valid command list, see help <searchcmd>)";
964 return NULL;
965 }
f33f3f52 966 return ((parseFunc)cmd->handler)(ctx, j, argvector+1);
c86edd1d
Q
967 }
968 } else {
969 /* Literal */
1bf9cda6 970 if (*input=='\"') {
971 for (ch=input;*ch;ch++);
972
973 if (*(ch-1) != '\"') {
974 parseError="Quote mismatch";
975 return NULL;
976 }
977
978 *(ch-1)='\0';
979 input++;
980 }
981
982 ch2=thestring;
983 for (ch=input;*ch;ch++) {
984 if (e) {
985 e=0;
986 *ch2++=*ch;
987 } else if (*ch=='\\') {
988 e=1;
989 } else {
990 *ch2++=*ch;
991 }
992 }
993 *ch2='\0';
994
9ce4f0be
IB
995 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
996 parseError = "malloc: could not allocate memory for this search.";
997 return NULL;
1bf9cda6 998 }
999
c7f7a584 1000 thenode->localdata = getsstring(thestring,512);
c86edd1d
Q
1001 thenode->returntype = RETURNTYPE_CONST | RETURNTYPE_STRING;
1002 thenode->exe = literal_exe;
1003 thenode->free = literal_free;
1004
1005 return thenode;
1006 }
1007}
2ba836f2 1008
2ba836f2 1009void nssnprintf(char *buf, size_t size, const char *format, nick *np) {
ba8a65c4 1010 StringBuf b;
2ba836f2
CP
1011 const char *p;
1012 char *c;
1013 char hostbuf[512];
1014
1015 if(size == 0)
1016 return;
1017
1018 b.buf = buf;
1019 b.capacity = size;
1020 b.len = 0;
1021
1022 for(p=format;*p;p++) {
1023 if(*p != '%') {
ba8a65c4 1024 if(!sbaddchar(&b, *p))
2ba836f2
CP
1025 break;
1026 continue;
1027 }
1028 p++;
1029 if(*p == '\0')
1030 break;
1031 if(*p == '%') {
ba8a65c4 1032 if(!sbaddchar(&b, *p))
2ba836f2
CP
1033 break;
1034 continue;
1035 }
1036
1037 c = NULL;
1038 switch(*p) {
1039 case 'n':
1040 c = np->nick; break;
1041 case 'i':
1042 c = np->ident; break;
1043 case 'h':
1044 c = np->host->name->content; break;
1045 case 'I':
1046 snprintf(hostbuf, sizeof(hostbuf), "%s", IPtostr(np->p_ipaddr));
1047 c = hostbuf;
1048 break;
1049 case 'u':
1050 snprintf(hostbuf, sizeof(hostbuf), "%s!%s@%s", np->nick, np->ident, IPtostr(np->p_ipaddr));
1051 c = hostbuf;
1052 break;
1053 default:
1054 c = "(bad format specifier)";
1055 }
1056 if(c)
ba8a65c4 1057 if(!sbaddstr(&b, c))
2ba836f2
CP
1058 break;
1059 }
1060
0be0b2d0 1061 sbterminate(&b);
2ba836f2
CP
1062
1063 /* not required */
1064 /*
1065 buf[size-1] = '\0';
1066 */
1067}
1068
f33f3f52
P
1069static char *var_tochar(searchCtx *ctx, char *arg, searchNode **variable) {
1070 *variable = ctx->parser(ctx, arg);
b697c21c
CP
1071 if (!(*variable = coerceNode(ctx, *variable, RETURNTYPE_STRING)))
1072 return NULL;
1073
1074 if(!((*variable)->returntype & RETURNTYPE_CONST)) {
1075 parseError = "only constant variables allowed";
1076 ((*variable)->free)(ctx, *variable);
1077 return NULL;
1078 }
1079
1080 return (char *)((*variable)->exe)(ctx, *variable, NULL);
1081}
1082
1083void free_val_null(searchCtx *ctx, struct searchNode *thenode) {
1084}
1085
f33f3f52 1086struct searchVariable *var_register(searchCtx *ctx, char *arg, int type) {
b697c21c
CP
1087 searchNode *variable;
1088 struct searchVariable *us;
1089 char *var;
1090 int i;
1091
1092 if(ctx->lastvar >= MAX_VARIABLES) {
1093 parseError = "Maximum number of variables reached";
1094 return NULL;
1095 }
1096
1097 us = &ctx->vars[ctx->lastvar];
1098
f33f3f52 1099 var = var_tochar(ctx, arg, &variable);
b697c21c
CP
1100 if(!var)
1101 return NULL;
1102
1103 strlcpy(us->name, var, sizeof(us->name));
1104 (variable->free)(ctx, variable);
1105
1106 for(i=0;i<ctx->lastvar;i++) {
1107 if(!strcmp(us->name, ctx->vars[i].name)) {
1108 parseError = "variable name already in use";
1109 return NULL;
1110 }
1111 }
1112
1113 ctx->lastvar++;
1114 us->data.returntype = type;
1115 us->data.localdata = &us->cdata;
1116 us->data.exe = exe_val_null;
1117 us->data.free = free_val_null;
1118
1119 us->cdata.child = NULL;
1120 return us;
1121}
1122
f33f3f52 1123searchNode *var_get(searchCtx *ctx, char *arg) {
b697c21c
CP
1124 searchNode *variable, *found = NULL;
1125 int i;
f33f3f52 1126 char *var = var_tochar(ctx, arg, &variable);
b697c21c
CP
1127 if(!var)
1128 return NULL;
1129
1130 for(i=0;i<ctx->lastvar;i++) {
1131 if(!strcmp(var, ctx->vars[i].name)) {
1132 found = &ctx->vars[i].data;
1133 break;
1134 }
1135 }
1136 (variable->free)(ctx, variable);
1137
1138 if(!found)
1139 parseError = "variable not found";
1140 return found;
1141}
1142
1143void var_setstr(struct searchVariable *v, char *data) {
1144 v->cdata.u.stringbuf = data;
1145}