2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
20 #include "locationmodule.h"
27 /* Declare global context */
28 struct loc_ctx
* loc_ctx
;
30 PyMODINIT_FUNC
PyInit_location(void);
32 static void location_free(void) {
38 static PyObject
* set_log_level(PyObject
* m
, PyObject
* args
) {
39 int priority
= LOG_INFO
;
41 if (!PyArg_ParseTuple(args
, "i", &priority
))
44 loc_set_log_priority(loc_ctx
, priority
);
49 static PyMethodDef location_module_methods
[] = {
52 (PyCFunction
)set_log_level
,
59 static struct PyModuleDef location_module
= {
60 .m_base
= PyModuleDef_HEAD_INIT
,
63 .m_doc
= "Python module for libloc",
64 .m_methods
= location_module_methods
,
65 .m_free
= (freefunc
)location_free
,
68 PyMODINIT_FUNC
PyInit_location(void) {
69 // Initialise loc context
70 int r
= loc_new(&loc_ctx
);
74 PyObject
* m
= PyModule_Create(&location_module
);
79 if (PyType_Ready(&ASType
) < 0)
83 PyModule_AddObject(m
, "AS", (PyObject
*)&ASType
);
86 if (PyType_Ready(&CountryType
) < 0)
89 Py_INCREF(&CountryType
);
90 PyModule_AddObject(m
, "Country", (PyObject
*)&CountryType
);
93 if (PyType_Ready(&DatabaseType
) < 0)
96 Py_INCREF(&DatabaseType
);
97 PyModule_AddObject(m
, "Database", (PyObject
*)&DatabaseType
);
99 // Database Enumerator
100 if (PyType_Ready(&DatabaseEnumeratorType
) < 0)
103 Py_INCREF(&DatabaseEnumeratorType
);
104 //PyModule_AddObject(m, "DatabaseEnumerator", (PyObject *)&DatabaseEnumeratorType);
107 if (PyType_Ready(&NetworkType
) < 0)
110 Py_INCREF(&NetworkType
);
111 PyModule_AddObject(m
, "Network", (PyObject
*)&NetworkType
);
114 if (PyType_Ready(&WriterType
) < 0)
117 Py_INCREF(&WriterType
);
118 PyModule_AddObject(m
, "Writer", (PyObject
*)&WriterType
);
121 if (PyModule_AddStringConstant(m
, "__version__", VERSION
))
125 if (PyModule_AddIntConstant(m
, "NETWORK_FLAG_ANONYMOUS_PROXY", LOC_NETWORK_FLAG_ANONYMOUS_PROXY
))
128 if (PyModule_AddIntConstant(m
, "NETWORK_FLAG_SATELLITE_PROVIDER", LOC_NETWORK_FLAG_SATELLITE_PROVIDER
))
131 if (PyModule_AddIntConstant(m
, "NETWORK_FLAG_ANYCAST", LOC_NETWORK_FLAG_ANYCAST
))