]>
Commit | Line | Data |
---|---|---|
3128667f P |
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."; | |
87826442 | 35 | free(localdata); |
3128667f P |
36 | return NULL; |
37 | } | |
38 | ||
39 | thenode->returntype = RETURNTYPE_BOOL; | |
40 | thenode->localdata = localdata; | |
41 | thenode->exe = ps_nick_exe; | |
42 | thenode->free = ps_nick_free; | |
43 | ||
44 | return thenode; | |
45 | } | |
46 | ||
47 | void *ps_nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { | |
48 | struct nick_localdata *localdata; | |
49 | patricia_node_t *node; | |
50 | nick *np; | |
51 | patricianick_t *pnp; | |
3128667f P |
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 | } |