]>
Commit | Line | Data |
---|---|---|
c433958f CP |
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" | |
c433958f | 11 | #include "../lib/irc_string.h" |
d1306c7a CP |
12 | #include "../geoip/geoip.h" |
13 | #include "../core/modules.h" | |
c433958f | 14 | |
c7f7a584 | 15 | void *country_exe(struct searchNode *thenode, void *theinput); |
c433958f CP |
16 | void country_free(struct searchNode *thenode); |
17 | ||
18 | int ext; | |
19 | ||
20 | struct searchNode *country_parse(int type, int argc, char **argv) { | |
21 | struct searchNode *thenode; | |
d1306c7a CP |
22 | GeoIP_LookupCode l; |
23 | int target; | |
c433958f CP |
24 | |
25 | if (type != SEARCHTYPE_NICK) { | |
26 | parseError = "country: this function is only valid for nick searches."; | |
27 | return NULL; | |
28 | } | |
29 | ||
d1306c7a CP |
30 | if (argc<1) { |
31 | parseError = "country: usage: country <country 2 character ISO code>"; | |
32 | return NULL; | |
33 | } | |
34 | ||
c433958f CP |
35 | ext = findnickext("geoip"); |
36 | if(ext == -1) { | |
37 | parseError = "country: Geoip module not loaded."; | |
38 | return NULL; | |
39 | } | |
40 | ||
d1306c7a CP |
41 | l = ndlsym("geoip", "geoip_lookupcode"); |
42 | target = l(argv[0]); | |
43 | if(target == -1) { | |
44 | parseError = "country: invalid country."; | |
45 | return NULL; | |
46 | } | |
c433958f | 47 | |
9ce4f0be IB |
48 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
49 | parseError = "malloc: could not allocate memory for this search."; | |
50 | return NULL; | |
51 | } | |
c433958f | 52 | |
d1306c7a CP |
53 | thenode->returntype = RETURNTYPE_BOOL; |
54 | thenode->localdata = (void *)target; | |
c433958f CP |
55 | thenode->exe = country_exe; |
56 | thenode->free = country_free; | |
57 | ||
58 | return thenode; | |
59 | } | |
60 | ||
c7f7a584 | 61 | void *country_exe(struct searchNode *thenode, void *theinput) { |
c433958f | 62 | nick *np = (nick *)theinput; |
d1306c7a CP |
63 | int country = (int)thenode->localdata, rc = (int)np->exts[ext]; |
64 | ||
65 | if(country == rc) | |
66 | return (void *)1; | |
c433958f | 67 | |
d1306c7a | 68 | return (void *)0; |
c433958f CP |
69 | } |
70 | ||
71 | void country_free(struct searchNode *thenode) { | |
72 | free(thenode); | |
73 | } |