]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - newsearch/ns-server.c
TRUSTS: require sqlite
[irc/quakenet/newserv.git] / newsearch / ns-server.c
... / ...
CommitLineData
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
16void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput);
17void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput);
18void server_free(searchCtx *ctx, struct searchNode *thenode);
19
20int ext;
21
22struct 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 struct searchNode *servername;
34 char *p;
35
36 if (!(servername=argtoconststr("server", ctx, argv[0], &p))) {
37 free(thenode);
38 return NULL;
39 }
40
41 numeric = -1;
42 for(i=0;i<MAXSERVERS;i++) {
43 sstring *n = serverlist[i].name;
44 if(n && !strcmp(n->content, p)) {
45 numeric = i;
46 break;
47 }
48 }
49
50 (servername->free)(ctx, servername);
51
52 if(numeric == -1) {
53 parseError = "server: server not found.";
54 free(thenode);
55 return NULL;
56 }
57
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;
67 }
68
69 thenode->free = server_free;
70
71 return thenode;
72}
73
74void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
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
84void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
85 nick *np = (nick *)theinput;
86 sstring *n = serverlist[homeserver(np->numeric)].name;
87
88 if(!n)
89 return "";
90
91 return n->content;
92}
93
94void server_free(searchCtx *ctx, struct searchNode *thenode) {
95 free(thenode);
96}