]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-country.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-country.c
CommitLineData
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
c8be5183
CP
15void *country_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
16void country_free(searchCtx *ctx, struct searchNode *thenode);
c433958f
CP
17
18int ext;
19
f33f3f52 20struct searchNode *country_parse(searchCtx *ctx, int argc, char **argv) {
c433958f 21 struct searchNode *thenode;
d1306c7a 22 GeoIP_LookupCode l;
c54295ef 23 long target;
c433958f 24
d1306c7a
CP
25 if (argc<1) {
26 parseError = "country: usage: country <country 2 character ISO code>";
27 return NULL;
28 }
29
c433958f
CP
30 ext = findnickext("geoip");
31 if(ext == -1) {
32 parseError = "country: Geoip module not loaded.";
33 return NULL;
34 }
35
d1306c7a
CP
36 l = ndlsym("geoip", "geoip_lookupcode");
37 target = l(argv[0]);
38 if(target == -1) {
39 parseError = "country: invalid country.";
40 return NULL;
41 }
c433958f 42
9ce4f0be
IB
43 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
44 parseError = "malloc: could not allocate memory for this search.";
45 return NULL;
46 }
c433958f 47
d1306c7a
CP
48 thenode->returntype = RETURNTYPE_BOOL;
49 thenode->localdata = (void *)target;
c433958f
CP
50 thenode->exe = country_exe;
51 thenode->free = country_free;
52
53 return thenode;
54}
55
c8be5183 56void *country_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c433958f 57 nick *np = (nick *)theinput;
c54295ef 58 long country = (long)thenode->localdata, rc = (long)np->exts[ext];
d1306c7a
CP
59
60 if(country == rc)
61 return (void *)1;
c433958f 62
d1306c7a 63 return (void *)0;
c433958f
CP
64}
65
c8be5183 66void country_free(searchCtx *ctx, struct searchNode *thenode) {
c433958f
CP
67 free(thenode);
68}