]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-server.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-server.c
1 /*
2 * SERVER functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "../irc/irc_config.h"
12 #include "../lib/irc_string.h"
13 #include "../core/modules.h"
14 #include "../server/server.h"
15
16 void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput);
17 void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput);
18 void server_free(searchCtx *ctx, struct searchNode *thenode);
19
20 int ext;
21
22 struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv) {
23 struct searchNode *thenode;
24 int i;
25 long numeric;
26
27 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
28 parseError = "malloc: could not allocate memory for this search.";
29 return NULL;
30 }
31
32 if (argc>0) {
33 numeric = -1;
34 for(i=0;i<MAXSERVERS;i++) {
35 sstring *n = serverlist[i].name;
36 if(n && !strcmp(n->content, argv[0])) {
37 numeric = i;
38 break;
39 }
40 }
41
42 if(numeric == -1) {
43 parseError = "server: server not found.";
44 return NULL;
45 }
46
47 thenode->returntype = RETURNTYPE_BOOL;
48 thenode->localdata = (void *)numeric;
49
50 thenode->exe = server_exe_bool;
51 } else {
52 thenode->returntype = RETURNTYPE_STRING;
53 thenode->localdata = NULL;
54
55 thenode->exe = server_exe_str;
56 }
57
58 thenode->free = server_free;
59
60 return thenode;
61 }
62
63 void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
64 nick *np = (nick *)theinput;
65 long server = (long)thenode->localdata;
66
67 if(homeserver(np->numeric) == server)
68 return (void *)1;
69
70 return (void *)0;
71 }
72
73 void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
74 nick *np = (nick *)theinput;
75 sstring *n = serverlist[homeserver(np->numeric)].name;
76
77 if(!n)
78 return NULL;
79
80 return n->content;
81 }
82
83 void server_free(searchCtx *ctx, struct searchNode *thenode) {
84 free(thenode);
85 }