Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 1bc45d8

Browse files
author
borisz
committed
Add new methods enable_teredo, teredo, time_zone_by_country_and_region and lib_version ( Boris Zentner )
1 parent 7d0b1cd commit 1bc45d8

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove Confidence and Accuracy Database it is unsued anyway. ( Boris
2+
Zentner )
3+
* Add new methods enable_teredo, teredo, time_zone_by_country_and_region
4+
and lib_version ( Boris Zentner )
15
* Add support for Confidence and Accuracy Database.
26
* Add support for Netspeed Database. via:
37
id_by_addr

py_GeoIP.c

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static PyObject * GeoIP_region_populate_dict(GeoIPRegion * gir) {
291291
return retval;
292292
}
293293

294-
static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
294+
static PyObject * GeoIP_populate_dict(GeoIP* gi, GeoIPRecord *gir) {
295295
PyObject * retval;
296296
retval = PyDict_New();
297297
GeoIP_SetItemString(retval,"country_code",gir->country_code);
@@ -300,30 +300,39 @@ static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
300300
GeoIP_SetItemString(retval,"region",gir->region);
301301
GeoIP_SetItemString(retval,"city",gir->city);
302302
GeoIP_SetItemString(retval,"postal_code",gir->postal_code);
303-
GeoIP_SetItemFloat(retval,"latitude",gir->latitude);
304-
GeoIP_SetItemFloat(retval,"longitude",gir->longitude);
305-
/*
306-
* metro_code is a alias for the depreciated dma_code.
307-
* we use the depreciated gir->dma_code since the CAPI
308-
* wrapper might be outdated and does not supply metro_code
309-
*/
310-
GeoIP_SetItemInt(retval,"dma_code",gir->dma_code);
311-
/* we did __NOT__ use gir->metro_code here, since metro_code is
312-
* somewhat new */
313-
GeoIP_SetItemInt(retval,"metro_code",gir->dma_code);
314-
GeoIP_SetItemInt(retval,"area_code",gir->area_code);
303+
GeoIP_SetItemFloat(retval,"latitude", gir->latitude);
304+
GeoIP_SetItemFloat(retval,"longitude", gir->longitude);
315305
GeoIP_SetItemString(retval, "region_name",
316306
GeoIP_region_name_by_code(gir->country_code, gir->region));
317307
GeoIP_SetItemString(retval, "time_zone",
318308
GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region));
319-
309+
if ( gi->databaseType != GEOIP_CITY_EDITION_REV0 ){
310+
/*
311+
* metro_code is a alias for the depreciated dma_code.
312+
* we use the depreciated gir->dma_code since the CAPI
313+
* wrapper might be outdated and does not supply metro_code
314+
*/
315+
GeoIP_SetItemInt(retval,"dma_code",gir->dma_code);
316+
/* we did __NOT__ use gir->metro_code here, since metro_code is
317+
* somewhat new */
318+
GeoIP_SetItemInt(retval,"metro_code",gir->dma_code);
319+
GeoIP_SetItemInt(retval,"area_code",gir->area_code);
320+
}
321+
322+
/*
323+
* drop support for Confidence and Accuracy Database
324+
* for now
325+
326+
if ( gi->databaseType != GEOIP_CITY_EDITION_REV1 ){
320327
GeoIP_SetConfItemInt(retval, "country_conf", gir->country_conf );
321328
GeoIP_SetConfItemInt(retval, "region_conf", gir->region_conf );
322329
GeoIP_SetConfItemInt(retval, "city_conf", gir->city_conf );
323330
GeoIP_SetConfItemInt(retval, "postal_conf", gir->postal_conf );
324331
325332
GeoIP_SetAccuracyItemInt(retval, "accuracy_radius", gir->accuracy_radius );
326333
334+
*/
335+
327336
GeoIPRecord_delete(gir);
328337
return retval;
329338
}
@@ -340,7 +349,7 @@ static PyObject * GeoIP_record_by_addr_Py(PyObject *self, PyObject *args) {
340349
Py_INCREF(Py_None);
341350
return Py_None;
342351
}
343-
return GeoIP_populate_dict(gir);
352+
return GeoIP_populate_dict(GeoIP->gi, gir);
344353
}
345354

346355
static PyObject * GeoIP_record_by_name_Py(PyObject *self, PyObject *args) {
@@ -355,7 +364,7 @@ static PyObject * GeoIP_record_by_name_Py(PyObject *self, PyObject *args) {
355364
Py_INCREF(Py_None);
356365
return Py_None;
357366
}
358-
return GeoIP_populate_dict(gir);
367+
return GeoIP_populate_dict(GeoIP->gi, gir);
359368
}
360369

361370
static PyObject * GeoIP_region_by_name_Py(PyObject *self, PyObject * args) {
@@ -428,6 +437,36 @@ static PyObject * GeoIP_last_netmask_Py(PyObject *self, PyObject * args) {
428437
return Py_BuildValue("i", GeoIP_last_netmask(GeoIP->gi) );
429438
}
430439

440+
441+
static PyObject * GeoIP_teredo_Py(PyObject *self, PyObject * args) {
442+
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
443+
return Py_BuildValue("i", GeoIP_teredo(GeoIP->gi) );
444+
}
445+
446+
static PyObject * GeoIP_enable_teredo_Py(PyObject *self, PyObject * args) {
447+
GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
448+
int teredo;
449+
if (!PyArg_ParseTuple(args, "i", &teredo)) {
450+
return NULL;
451+
}
452+
return Py_BuildValue("i", GeoIP_enable_teredo(GeoIP->gi, teredo));
453+
}
454+
455+
static PyObject*
456+
GeoIP_lib_version_Py(PyObject* self, PyObject *args) {
457+
return Py_BuildValue("s", GeoIP_lib_version());
458+
}
459+
460+
static PyObject * GeoIP_time_zone_by_country_and_region_Py(PyObject *self, PyObject * args) {
461+
char * country_code, *region;
462+
if (!PyArg_ParseTuple(args, "ss", &country_code, &region)) {
463+
return NULL;
464+
}
465+
return Py_BuildValue("s", GeoIP_time_zone_by_country_and_region(country_code, region));
466+
}
467+
468+
469+
431470
static PyMethodDef GeoIP_Object_methods[] = {
432471
{"country_code_by_name", GeoIP_country_code_by_name_Py, 1, "Lookup Country Code By Name"},
433472
{"country_name_by_name", GeoIP_country_name_by_name_Py, 1, "Lookup Country Name By Name"},
@@ -442,11 +481,13 @@ static PyMethodDef GeoIP_Object_methods[] = {
442481
{"range_by_ip", GeoIP_range_by_ip_Py, 1, "Lookup start and end IP's for a given IP"},
443482
{"charset", GeoIP_charset_Py, 1, "Return the current charset ( either GEOIP_CHARSET_ISO_8859_1 or GEOIP_CHARSET_UTF8 )"},
444483
{"set_charset", GeoIP_set_charset_Py, 1, "Set the charset for city records"},
445-
{"last_netmask", GeoIP_last_netmask_Py, 1, "return the netmask depth of the last lookup"},
484+
{"last_netmask", GeoIP_last_netmask_Py, 1, "Return the netmask depth of the last lookup"},
446485
{"country_code_by_name_v6", GeoIP_country_code_by_name_v6_Py, 1, "Lookup IPv6 Country Code By Name"},
447486
{"country_name_by_name_v6", GeoIP_country_name_by_name_v6_Py, 1, "Lookup IPv6 Country Name By Name"},
448487
{"country_code_by_addr_v6", GeoIP_country_code_by_addr_v6_Py, 1, "Lookup IPv6 Country Code By IP Address"},
449488
{"country_name_by_addr_v6", GeoIP_country_name_by_addr_v6_Py, 1, "Lookup IPv6 Country Name By IP Address"},
489+
{"enable_teredo", GeoIP_enable_teredo_Py, 1, "Enable / disable teredo"},
490+
{"teredo", GeoIP_teredo_Py, 1, "Returns true if teredo is enabled"},
450491
{"id_by_addr", GeoIP_id_by_addr_Py, 1, "Lookup Netspeed By IP Address"},
451492
{"id_by_name", GeoIP_id_by_name_Py, 1, "Lookup Netspeed By Name"},
452493
{NULL, NULL, 0, NULL}
@@ -492,6 +533,8 @@ static PyTypeObject GeoIP_GeoIPType = {
492533
static PyMethodDef GeoIP_Class_methods[] = {
493534
{"new", GeoIP_new_Py, 1, "GeoIP Constructor"},
494535
{"open", GeoIP_open_Py, 1, "GeoIP Constructor with database filename argument"},
536+
{"lib_version", GeoIP_lib_version_Py, 1, "Returns the CAPI version"},
537+
{"time_zone_by_country_and_region", GeoIP_time_zone_by_country_and_region_Py, 1, "Returns time_zone for country, region"},
495538
{NULL, NULL, 0, NULL}
496539
};
497540

test_city.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
print gir['area_code']
2121
print gir['time_zone']
2222
print gir['metro_code']
23+
print str(gir)

0 commit comments

Comments
 (0)