]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add country name lookup to newsearch.
authorChris Porter <redacted>
Fri, 30 Nov 2007 18:35:30 +0000 (18:35 +0000)
committerChris Porter <redacted>
Fri, 30 Nov 2007 18:35:30 +0000 (18:35 +0000)
newsearch/ns-country.c

index d5a1a29a57c8130d97abe5c1f07c58369d12236b..ffd87813b5e0f1468cb83dc64da0d0ff3c6c8e58 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "../irc/irc_config.h"
 #include "../lib/irc_string.h"
+#include "../geoip/geoip.h"
+#include "../core/modules.h"
 
 void *country_exe(struct searchNode *thenode, void *theinput);
 void country_free(struct searchNode *thenode);
@@ -17,26 +19,39 @@ int ext;
 
 struct searchNode *country_parse(int type, int argc, char **argv) {
   struct searchNode *thenode;
+  GeoIP_LookupCode l;
+  int target;
 
   if (type != SEARCHTYPE_NICK) {
     parseError = "country: this function is only valid for nick searches.";
     return NULL;
   }
 
+  if (argc<1) {
+    parseError = "country: usage: country <country 2 character ISO code>";
+    return NULL;
+  }
+
   ext = findnickext("geoip");
   if(ext == -1) {
     parseError = "country: Geoip module not loaded.";
     return NULL;
   }
   
+  l = ndlsym("geoip", "geoip_lookupcode");
+  target = l(argv[0]);
+  if(target == -1) {
+    parseError = "country: invalid country.";
+    return NULL;
+  }
 
   if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
     parseError = "malloc: could not allocate memory for this search.";
     return NULL;
   }
 
-  thenode->returntype = RETURNTYPE_INT;
-  thenode->localdata = NULL;
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->localdata = (void *)target;
   thenode->exe = country_exe;
   thenode->free = country_free;
 
@@ -45,8 +60,12 @@ struct searchNode *country_parse(int type, int argc, char **argv) {
 
 void *country_exe(struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
+  int country = (int)thenode->localdata, rc = (int)np->exts[ext];
+
+  if(country == rc)
+    return (void *)1;
 
-  return (void *)np->exts[ext];
+  return (void *)0;
 }
 
 void country_free(struct searchNode *thenode) {