Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/konobi/node-geoip into ko…

…nobi-master
  • Loading branch information...
commit de6a32d3dea48375517ba1da8aecde365e4cd62d 2 parents 5dd19c8 + 8b4474b
@strange authored
View
2  examples/lookup2.js
@@ -5,7 +5,7 @@ var dbpath = '/usr/local/share/GeoIP/GeoLiteCity.dat';
var ip = '216.236.135.152';
sys.puts('Looking up ip: ' + ip + '...\n');
-var con = new geoip.Connection(dbpath, function(con) {
+var con = new geoip.Connection(dbpath, 0, function(con) {
con.query(ip, function(result) {
for (var attr in result) {
sys.puts(attr + ' : ' + result[attr]);
View
15 examples/lookup3.js
@@ -0,0 +1,15 @@
+var sys = require('sys'),
+ ceoip = require('../lib/ceoip');
+
+con = new ceoip.Connection();
+con.addListener('connected', function () {
+ con.addListener('result', function(result) {
+ for (var attr in result) {
+ sys.puts(attr + ' : ' + result[attr]);
+ }
+ });
+ var ip = '216.236.135.152';
+ sys.puts('Looking up ip: ' + ip + '...\n');
+ con.query(ip);
+});
+con.connect('/usr/local/share/GeoIP/GeoLiteCity.dat', ceoip.GEOIP_MMAP_CACHE);
View
4 lib/geoip.js
@@ -1,7 +1,7 @@
var sys = require('sys'),
ceoip = require('./ceoip');
-function Connection(dbpath, callback) {
+function Connection(dbpath, bitmask, callback) {
this.con = new ceoip.Connection();
this.queue = [];
this.connected = false;
@@ -27,7 +27,7 @@ function Connection(dbpath, callback) {
self.processQueue();
});
- this.con.connect(dbpath);
+ this.con.connect(dbpath, bitmask);
}
sys.inherits(Connection, process.EventEmitter);
View
21 src/ceoip.cc
@@ -32,13 +32,22 @@ class Connection : public EventEmitter {
NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
NODE_SET_PROTOTYPE_METHOD(t, "query", Query);
+ NODE_DEFINE_CONSTANT(target, GEOIP_STANDARD);
+ NODE_DEFINE_CONSTANT(target, GEOIP_MEMORY_CACHE);
+ NODE_DEFINE_CONSTANT(target, GEOIP_CHECK_CACHE);
+ NODE_DEFINE_CONSTANT(target, GEOIP_INDEX_CACHE);
+ NODE_DEFINE_CONSTANT(target, GEOIP_MMAP_CACHE);
+
target->Set(String::NewSymbol("Connection"), t->GetFunction());
}
- void Connect(const char *dbpath) {
+ void Connect(const char *dbpath, int db_opts_bitmask) {
HandleScope scope;
- gi = GeoIP_open(dbpath, GEOIP_INDEX_CACHE);
+ if(db_opts_bitmask == 0){
+ db_opts_bitmask = 0 | GEOIP_STANDARD;
+ }
+ gi = GeoIP_open(dbpath, db_opts_bitmask);
Emit((gi ? connected_symbol : error_symbol), 0, NULL);
}
@@ -88,11 +97,17 @@ class Connection : public EventEmitter {
Exception::TypeError(
String::New("Required argument: path to database.")));
}
+ if (args.Length() == 2 && !args[1]->IsNumber()){
+ return ThrowException(
+ Exception::TypeError(
+ String::New("Second argument must be a bitmask")));
+ }
String::Utf8Value dbpath(args[0]->ToString());
+
Connection *connection = ObjectWrap::Unwrap<Connection>(args.This());
- connection->Connect(*dbpath);
+ connection->Connect(*dbpath, args[1]->ToUint32()->Value());
return Undefined();
}
Please sign in to comment.
Something went wrong with that request. Please try again.