]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-country.c
Someone figured out how to print the ip, nterfacer now shows bad IP connections.
[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
c8be5183 20struct searchNode *country_parse(searchCtx *ctx, int type, int argc, char **argv) {
c433958f 21 struct searchNode *thenode;
d1306c7a 22 GeoIP_LookupCode l;
c54295ef 23 long 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
c8be5183 61void *country_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c433958f 62 nick *np = (nick *)theinput;
c54295ef 63 long country = (long)thenode->localdata, rc = (long)np->exts[ext];
d1306c7a
CP
64
65 if(country == rc)
66 return (void *)1;
c433958f 67
d1306c7a 68 return (void *)0;
c433958f
CP
69}
70
c8be5183 71void country_free(searchCtx *ctx, struct searchNode *thenode) {
c433958f
CP
72 free(thenode);
73}