|
1 | 1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
2 | 2 | /* py_GeoIP.c
|
3 | 3 | *
|
4 |
| - * Copyright (C) 2002 MaxMind.com |
| 4 | + * Copyright (C) 2003 MaxMind LLC |
5 | 5 | *
|
6 | 6 | * This library is free software; you can redistribute it and/or
|
7 | 7 | * modify it under the terms of the GNU General Public
|
|
20 | 20 |
|
21 | 21 | #include <Python.h>
|
22 | 22 | #include "GeoIP.h"
|
| 23 | +#include "GeoIPCity.h" |
23 | 24 |
|
24 | 25 | staticforward PyTypeObject GeoIP_GeoIPType;
|
25 | 26 |
|
@@ -143,13 +144,41 @@ static PyObject * GeoIP_org_by_name_Py(PyObject *self, PyObject *args) {
|
143 | 144 | return Py_BuildValue("s", retval);
|
144 | 145 | }
|
145 | 146 |
|
| 147 | +static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) { |
| 148 | + PyObject * retval; |
| 149 | + retval = PyDict_New(); |
| 150 | + PyDict_SetItem(retval,Py_BuildValue("s","country_code"),Py_BuildValue("s",gir->country_code)); |
| 151 | + PyDict_SetItem(retval,Py_BuildValue("s","country_code3"),Py_BuildValue("s",gir->country_code3)); |
| 152 | + PyDict_SetItem(retval,Py_BuildValue("s","country_name"),Py_BuildValue("s",gir->country_name)); |
| 153 | + PyDict_SetItem(retval,Py_BuildValue("s","region"),Py_BuildValue("s",gir->region)); |
| 154 | + PyDict_SetItem(retval,Py_BuildValue("s","city"),Py_BuildValue("s",gir->city)); |
| 155 | + PyDict_SetItem(retval,Py_BuildValue("s","postal_code"),Py_BuildValue("s",gir->postal_code)); |
| 156 | + PyDict_SetItem(retval,Py_BuildValue("s","latitude"),Py_BuildValue("f",gir->latitude)); |
| 157 | + PyDict_SetItem(retval,Py_BuildValue("s","longitude"),Py_BuildValue("f",gir->longitude)); |
| 158 | + PyDict_SetItem(retval,Py_BuildValue("s","dma_code"),Py_BuildValue("i",gir->dma_code)); |
| 159 | + PyDict_SetItem(retval,Py_BuildValue("s","area_code"),Py_BuildValue("i",gir->area_code)); |
| 160 | + return retval; |
| 161 | +} |
| 162 | + |
| 163 | +static PyObject * GeoIP_record_by_addr_Py(PyObject *self, PyObject *args) { |
| 164 | + char * addr; |
| 165 | + GeoIPRecord * gir; |
| 166 | + GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self; |
| 167 | + if (!PyArg_ParseTuple(args, "s", &addr)) { |
| 168 | + return NULL; |
| 169 | + } |
| 170 | + gir = GeoIP_record_by_addr(GeoIP->gi, addr); |
| 171 | + return GeoIP_populate_dict(gir); |
| 172 | +} |
| 173 | + |
146 | 174 | static PyMethodDef GeoIP_Object_methods[] = {
|
147 | 175 | {"country_code_by_name", GeoIP_country_code_by_name_Py, 1, "Lookup Country Code By Name"},
|
148 | 176 | {"country_name_by_name", GeoIP_country_name_by_name_Py, 1, "Lookup Country Name By Name"},
|
149 | 177 | {"country_code_by_addr", GeoIP_country_code_by_addr_Py, 1, "Lookup Country Code By IP Address"},
|
150 | 178 | {"country_name_by_addr", GeoIP_country_name_by_addr_Py, 1, "Lookup Country Name By IP Address"},
|
151 | 179 | {"org_by_addr", GeoIP_org_by_addr_Py, 1, "Lookup Organization or ISP By IP Address"},
|
152 | 180 | {"org_by_name", GeoIP_org_by_name_Py, 1, "Lookup Organization or ISP By Name"},
|
| 181 | + {"record_by_addr", GeoIP_record_by_addr_Py, 1, "Lookup City Region By IP Address"}, |
153 | 182 | {NULL, NULL, 0, NULL}
|
154 | 183 | };
|
155 | 184 |
|
|
0 commit comments