]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-country.c
added malloc checking to everything (includes error reson). updated kill/gline wallop...
[irc/quakenet/newserv.git] / newsearch / ns-country.c
1 /*
2 * COUNTRY functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "../irc/irc_config.h"
11 #include "../lib/irc_string.h"
12
13 void *country_exe(struct searchNode *thenode, int type, void *theinput);
14 void *country_exe_real(struct searchNode *thenode, int type, void *theinput);
15 void country_free(struct searchNode *thenode);
16
17 int ext;
18
19 struct searchNode *country_parse(int type, int argc, char **argv) {
20 struct searchNode *thenode;
21
22 if (type != SEARCHTYPE_NICK) {
23 parseError = "country: this function is only valid for nick searches.";
24 return NULL;
25 }
26
27 ext = findnickext("geoip");
28 if(ext == -1) {
29 parseError = "country: Geoip module not loaded.";
30 return NULL;
31 }
32
33
34 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
35 parseError = "malloc: could not allocate memory for this search.";
36 return NULL;
37 }
38
39 thenode->returntype = RETURNTYPE_INT;
40 thenode->localdata = NULL;
41 thenode->exe = country_exe;
42 thenode->free = country_free;
43
44 return thenode;
45 }
46
47 void *country_exe(struct searchNode *thenode, int type, void *theinput) {
48 nick *np = (nick *)theinput;
49
50 if (type != RETURNTYPE_INT)
51 return (void *)1;
52
53 return (void *)np->exts[ext];
54 }
55
56 void country_free(struct searchNode *thenode) {
57 free(thenode);
58 }