]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-country.c
2 * COUNTRY functionality
10 #include "../irc/irc_config.h"
11 #include "../lib/irc_string.h"
12 #include "../geoip/geoip.h"
13 #include "../core/modules.h"
15 void *country_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
16 void country_free(searchCtx
*ctx
, struct searchNode
*thenode
);
20 struct searchNode
*country_parse(searchCtx
*ctx
, int argc
, char **argv
) {
21 struct searchNode
*thenode
, *countrysn
;
27 parseError
= "country: usage: country <country 2 character ISO code>";
31 ext
= findnickext("geoip");
33 parseError
= "country: Geoip module not loaded.";
37 l
= ndlsym("geoip", "geoip_lookupcode");
39 parseError
= "unable to lookup geoip function pointer";
43 if (!(countrysn
=argtoconststr("country", ctx
, argv
[0], &p
)))
47 countrysn
->free(ctx
, countrysn
);
50 parseError
= "country: invalid country.";
54 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
55 parseError
= "malloc: could not allocate memory for this search.";
59 thenode
->returntype
= RETURNTYPE_BOOL
;
60 thenode
->localdata
= (void *)target
;
61 thenode
->exe
= country_exe
;
62 thenode
->free
= country_free
;
67 void *country_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
68 nick
*np
= (nick
*)theinput
;
69 long country
= (long)thenode
->localdata
, rc
= (long)np
->exts
[ext
];
77 void country_free(searchCtx
*ctx
, struct searchNode
*thenode
) {