]> jfr.im git - irc/quakenet/newserv.git/blob - patriciasearch/ps-nick.c
551bd0a77eddc3c49874738cde34746f316df8cf
[irc/quakenet/newserv.git] / patriciasearch / ps-nick.c
1 #include "patriciasearch.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 void *ps_nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
7 void ps_nick_free(searchCtx *ctx, struct searchNode *thenode);
8
9 struct nick_localdata {
10 nick *np;
11 };
12
13 struct searchNode *ps_nick_parse(searchCtx *ctx, int argc, char **argv) {
14 struct searchNode *thenode;
15 struct nick_localdata *localdata;
16
17 if (!(localdata=(struct nick_localdata *)malloc(sizeof(struct nick_localdata)))) {
18 parseError = "malloc: could not allocate memory for this search.";
19 return NULL;
20 }
21
22 if (argc!=1) {
23 parseError="nick: usage: (nick target)";
24 free(localdata);
25 return NULL;
26 }
27 if ((localdata->np=getnickbynick(argv[0]))==NULL) {
28 parseError="nick: unknown nickname";
29 free(localdata);
30 return NULL;
31 }
32
33 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
34 parseError = "malloc: could not allocate memory for this search.";
35 return NULL;
36 }
37
38 thenode->returntype = RETURNTYPE_BOOL;
39 thenode->localdata = localdata;
40 thenode->exe = ps_nick_exe;
41 thenode->free = ps_nick_free;
42
43 return thenode;
44 }
45
46 void *ps_nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
47 struct nick_localdata *localdata;
48 patricia_node_t *node;
49 nick *np;
50 patricianick_t *pnp;
51 patricia_node_t *pn;
52 int i;
53
54 localdata = thenode->localdata;
55 node = (patricia_node_t *)theinput;
56
57 if (pnode_ext && node->exts[pnode_ext] ) {
58 pnp = node->exts[pnode_ext];
59 for (i = 0; i < PATRICIANICK_HASHSIZE; i++) {
60 for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) {
61 if (np == localdata->np)
62 return (void *)1;
63 }
64 }
65 }
66 return (void *)0;
67 }
68
69 void ps_nick_free(searchCtx *ctx, struct searchNode *thenode) {
70 free(thenode->localdata);
71 free(thenode);
72 }