]> jfr.im git - irc/quakenet/newserv.git/blame - patriciasearch/ps-nick.c
update for newsearchchanges
[irc/quakenet/newserv.git] / patriciasearch / ps-nick.c
CommitLineData
3128667f
P
1#include "patriciasearch.h"
2
3#include <stdio.h>
4#include <stdlib.h>
5
6void *ps_nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
7void ps_nick_free(searchCtx *ctx, struct searchNode *thenode);
8
9struct nick_localdata {
10 nick *np;
11};
12
13struct 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
46void *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;
3128667f
P
51 int i;
52
53 localdata = thenode->localdata;
54 node = (patricia_node_t *)theinput;
55
56 if (pnode_ext && node->exts[pnode_ext] ) {
57 pnp = node->exts[pnode_ext];
58 for (i = 0; i < PATRICIANICK_HASHSIZE; i++) {
59 for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) {
60 if (np == localdata->np)
61 return (void *)1;
62 }
63 }
64 }
65 return (void *)0;
66}
67
68void ps_nick_free(searchCtx *ctx, struct searchNode *thenode) {
69 free(thenode->localdata);
70 free(thenode);
71}