]>
Commit | Line | Data |
---|---|---|
6c131217 CP |
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 | ||
c8be5183 CP |
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); | |
6c131217 CP |
19 | |
20 | int ext; | |
21 | ||
f33f3f52 | 22 | struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv) { |
6c131217 CP |
23 | struct searchNode *thenode; |
24 | int i; | |
25 | long numeric; | |
26 | ||
03c2998e P |
27 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
28 | parseError = "malloc: could not allocate memory for this search."; | |
29 | return NULL; | |
30 | } | |
31 | ||
fc0bf814 | 32 | if (argc>0) { |
31686847 CP |
33 | struct searchNode *servername; |
34 | char *p; | |
35 | ||
36 | if (!(servername=argtoconststr("server", ctx, argv[0], &p))) { | |
37 | free(thenode); | |
38 | return NULL; | |
39 | } | |
40 | ||
fc0bf814 CP |
41 | numeric = -1; |
42 | for(i=0;i<MAXSERVERS;i++) { | |
43 | sstring *n = serverlist[i].name; | |
31686847 | 44 | if(n && !strcmp(n->content, p)) { |
fc0bf814 CP |
45 | numeric = i; |
46 | break; | |
47 | } | |
48 | } | |
6c131217 | 49 | |
31686847 CP |
50 | (servername->free)(ctx, servername); |
51 | ||
fc0bf814 CP |
52 | if(numeric == -1) { |
53 | parseError = "server: server not found."; | |
31686847 | 54 | free(thenode); |
fc0bf814 | 55 | return NULL; |
6c131217 | 56 | } |
6c131217 | 57 | |
fc0bf814 CP |
58 | thenode->returntype = RETURNTYPE_BOOL; |
59 | thenode->localdata = (void *)numeric; | |
60 | ||
61 | thenode->exe = server_exe_bool; | |
62 | } else { | |
63 | thenode->returntype = RETURNTYPE_STRING; | |
64 | thenode->localdata = NULL; | |
65 | ||
66 | thenode->exe = server_exe_str; | |
6c131217 CP |
67 | } |
68 | ||
6c131217 CP |
69 | thenode->free = server_free; |
70 | ||
71 | return thenode; | |
72 | } | |
73 | ||
c8be5183 | 74 | void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
6c131217 CP |
75 | nick *np = (nick *)theinput; |
76 | long server = (long)thenode->localdata; | |
77 | ||
78 | if(homeserver(np->numeric) == server) | |
79 | return (void *)1; | |
80 | ||
81 | return (void *)0; | |
82 | } | |
83 | ||
c8be5183 | 84 | void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
fc0bf814 CP |
85 | nick *np = (nick *)theinput; |
86 | sstring *n = serverlist[homeserver(np->numeric)].name; | |
87 | ||
88 | if(!n) | |
89 | return NULL; | |
90 | ||
91 | return n->content; | |
92 | } | |
93 | ||
c8be5183 | 94 | void server_free(searchCtx *ctx, struct searchNode *thenode) { |
6c131217 CP |
95 | free(thenode); |
96 | } |