]>
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 CP |
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 | } | |
6c131217 | 41 | |
fc0bf814 CP |
42 | if(numeric == -1) { |
43 | parseError = "server: server not found."; | |
44 | return NULL; | |
6c131217 | 45 | } |
6c131217 | 46 | |
fc0bf814 CP |
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; | |
6c131217 CP |
56 | } |
57 | ||
6c131217 CP |
58 | thenode->free = server_free; |
59 | ||
60 | return thenode; | |
61 | } | |
62 | ||
c8be5183 | 63 | void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
6c131217 CP |
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 | ||
c8be5183 | 73 | void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
fc0bf814 CP |
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 | ||
c8be5183 | 83 | void server_free(searchCtx *ctx, struct searchNode *thenode) { |
6c131217 CP |
84 | free(thenode); |
85 | } |