]>
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 type
, int argc
, char **argv
) {
21 struct searchNode
*thenode
;
25 if (type
!= SEARCHTYPE_NICK
) {
26 parseError
= "country: this function is only valid for nick searches.";
31 parseError
= "country: usage: country <country 2 character ISO code>";
35 ext
= findnickext("geoip");
37 parseError
= "country: Geoip module not loaded.";
41 l
= ndlsym("geoip", "geoip_lookupcode");
44 parseError
= "country: invalid country.";
48 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
49 parseError
= "malloc: could not allocate memory for this search.";
53 thenode
->returntype
= RETURNTYPE_BOOL
;
54 thenode
->localdata
= (void *)target
;
55 thenode
->exe
= country_exe
;
56 thenode
->free
= country_free
;
61 void *country_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
62 nick
*np
= (nick
*)theinput
;
63 long country
= (long)thenode
->localdata
, rc
= (long)np
->exts
[ext
];
71 void country_free(searchCtx
*ctx
, struct searchNode
*thenode
) {