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