@@ -291,7 +291,7 @@ static PyObject * GeoIP_region_populate_dict(GeoIPRegion * gir) {
291
291
return retval ;
292
292
}
293
293
294
- static PyObject * GeoIP_populate_dict (GeoIPRecord * gir ) {
294
+ static PyObject * GeoIP_populate_dict (GeoIP * gi , GeoIPRecord * gir ) {
295
295
PyObject * retval ;
296
296
retval = PyDict_New ();
297
297
GeoIP_SetItemString (retval ,"country_code" ,gir -> country_code );
@@ -300,30 +300,39 @@ static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
300
300
GeoIP_SetItemString (retval ,"region" ,gir -> region );
301
301
GeoIP_SetItemString (retval ,"city" ,gir -> city );
302
302
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 );
315
305
GeoIP_SetItemString (retval , "region_name" ,
316
306
GeoIP_region_name_by_code (gir -> country_code , gir -> region ));
317
307
GeoIP_SetItemString (retval , "time_zone" ,
318
308
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 ){
320
327
GeoIP_SetConfItemInt(retval, "country_conf", gir->country_conf );
321
328
GeoIP_SetConfItemInt(retval, "region_conf", gir->region_conf );
322
329
GeoIP_SetConfItemInt(retval, "city_conf", gir->city_conf );
323
330
GeoIP_SetConfItemInt(retval, "postal_conf", gir->postal_conf );
324
331
325
332
GeoIP_SetAccuracyItemInt(retval, "accuracy_radius", gir->accuracy_radius );
326
333
334
+ */
335
+
327
336
GeoIPRecord_delete (gir );
328
337
return retval ;
329
338
}
@@ -340,7 +349,7 @@ static PyObject * GeoIP_record_by_addr_Py(PyObject *self, PyObject *args) {
340
349
Py_INCREF (Py_None );
341
350
return Py_None ;
342
351
}
343
- return GeoIP_populate_dict (gir );
352
+ return GeoIP_populate_dict (GeoIP -> gi , gir );
344
353
}
345
354
346
355
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) {
355
364
Py_INCREF (Py_None );
356
365
return Py_None ;
357
366
}
358
- return GeoIP_populate_dict (gir );
367
+ return GeoIP_populate_dict (GeoIP -> gi , gir );
359
368
}
360
369
361
370
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) {
428
437
return Py_BuildValue ("i" , GeoIP_last_netmask (GeoIP -> gi ) );
429
438
}
430
439
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
+
431
470
static PyMethodDef GeoIP_Object_methods [] = {
432
471
{"country_code_by_name" , GeoIP_country_code_by_name_Py , 1 , "Lookup Country Code By Name" },
433
472
{"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[] = {
442
481
{"range_by_ip" , GeoIP_range_by_ip_Py , 1 , "Lookup start and end IP's for a given IP" },
443
482
{"charset" , GeoIP_charset_Py , 1 , "Return the current charset ( either GEOIP_CHARSET_ISO_8859_1 or GEOIP_CHARSET_UTF8 )" },
444
483
{"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" },
446
485
{"country_code_by_name_v6" , GeoIP_country_code_by_name_v6_Py , 1 , "Lookup IPv6 Country Code By Name" },
447
486
{"country_name_by_name_v6" , GeoIP_country_name_by_name_v6_Py , 1 , "Lookup IPv6 Country Name By Name" },
448
487
{"country_code_by_addr_v6" , GeoIP_country_code_by_addr_v6_Py , 1 , "Lookup IPv6 Country Code By IP Address" },
449
488
{"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" },
450
491
{"id_by_addr" , GeoIP_id_by_addr_Py , 1 , "Lookup Netspeed By IP Address" },
451
492
{"id_by_name" , GeoIP_id_by_name_Py , 1 , "Lookup Netspeed By Name" },
452
493
{NULL , NULL , 0 , NULL }
@@ -492,6 +533,8 @@ static PyTypeObject GeoIP_GeoIPType = {
492
533
static PyMethodDef GeoIP_Class_methods [] = {
493
534
{"new" , GeoIP_new_Py , 1 , "GeoIP Constructor" },
494
535
{"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" },
495
538
{NULL , NULL , 0 , NULL }
496
539
};
497
540
0 commit comments