]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-nick.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-nick.c
CommitLineData
c86edd1d
Q
1/*
2 * NICK functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
3adfb300
IB
10struct nick_localdata {
11 nick *np;
3adfb300
IB
12};
13
c8be5183
CP
14void *nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
15void nick_free(searchCtx *ctx, struct searchNode *thenode);
c86edd1d 16
f33f3f52 17struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv) {
3adfb300 18 struct nick_localdata *localdata;
c86edd1d
Q
19 struct searchNode *thenode;
20
3adfb300
IB
21 if (!(localdata=(struct nick_localdata *)malloc(sizeof(struct nick_localdata)))) {
22 parseError = "malloc: could not allocate memory for this search.";
23 return NULL;
24 }
25
a92bb8e1 26 if (ctx->searchcmd == reg_chansearch) {
3adfb300
IB
27 if (argc!=1) {
28 parseError="nick: usage: (nick target)";
29 free(localdata);
30 return NULL;
31 }
32 if ((localdata->np=getnickbynick(argv[0]))==NULL) {
33 parseError="nick: unknown nickname";
34 free(localdata);
35 return NULL;
36 }
a92bb8e1 37 } else if (ctx->searchcmd == reg_nicksearch) {
3adfb300
IB
38 if (argc) {
39 parseError="nick: usage: (match (nick) target)";
40 free(localdata);
41 return NULL;
42 }
3adfb300 43 localdata->np = NULL;
a92bb8e1
P
44 } else {
45 parseError="nick: invalid search command";
3adfb300 46 free(localdata);
c86edd1d
Q
47 return NULL;
48 }
49
3adfb300
IB
50 if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
51 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
9ce4f0be 52 parseError = "malloc: could not allocate memory for this search.";
3adfb300 53 free(localdata);
9ce4f0be
IB
54 return NULL;
55 }
c86edd1d 56
a92bb8e1 57 if (ctx->searchcmd == reg_chansearch)
3adfb300
IB
58 thenode->returntype = RETURNTYPE_BOOL;
59 else
60 thenode->returntype = RETURNTYPE_STRING;
61 thenode->localdata = localdata;
c86edd1d
Q
62 thenode->exe = nick_exe;
63 thenode->free = nick_free;
64
65 return thenode;
66}
67
c8be5183 68void *nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
3adfb300
IB
69 struct nick_localdata *localdata;
70 nick *np;
71 chanindex *cip;
c86edd1d 72
3adfb300
IB
73 localdata = thenode->localdata;
74
a92bb8e1 75 if (ctx->searchcmd == reg_chansearch) {
3adfb300
IB
76 cip = (chanindex *)theinput;
77
78 if (cip->channel==NULL || getnumerichandlefromchanhash(cip->channel->users, localdata->np->numeric)==NULL)
c7f7a584 79 return (void *)0;
80
81 return (void *)1;
a92bb8e1 82 } else {
3adfb300
IB
83 np = (nick *)theinput;
84
3adfb300 85 return np->nick;
3adfb300 86 }
c86edd1d
Q
87}
88
c8be5183 89void nick_free(searchCtx *ctx, struct searchNode *thenode) {
3adfb300 90 free(thenode->localdata);
c86edd1d
Q
91 free(thenode);
92}
93