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