]> git.ipfire.org Git - people/ms/libloc.git/blame - src/python/locationmodule.c
python: Implement Network class
[people/ms/libloc.git] / src / python / locationmodule.c
CommitLineData
18e2b14c
MT
1/*
2 libloc - A library to determine the location of someone on the Internet
3
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
5
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.
10
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.
15*/
16
17#include <Python.h>
18
62ffafdd 19#include "locationmodule.h"
fadebc89 20#include "as.h"
9cdf6c53 21#include "database.h"
39967361 22#include "network.h"
d688e569 23#include "writer.h"
9cdf6c53 24
18e2b14c
MT
25PyMODINIT_FUNC PyInit_location(void);
26
62ffafdd
MT
27static void location_free(void) {
28 // Release context
29 if (loc_ctx)
30 loc_unref(loc_ctx);
31}
32
18e2b14c
MT
33static PyMethodDef location_module_methods[] = {
34 { NULL },
35};
36
37static struct PyModuleDef location_module = {
38 .m_base = PyModuleDef_HEAD_INIT,
39 .m_name = "location",
40 .m_size = -1,
41 .m_doc = "Python module for libloc",
42 .m_methods = location_module_methods,
62ffafdd 43 .m_free = (freefunc)location_free,
18e2b14c
MT
44};
45
46PyMODINIT_FUNC PyInit_location(void) {
62ffafdd
MT
47 // Initialise loc context
48 int r = loc_new(&loc_ctx);
49 if (r)
50 return NULL;
51
18e2b14c
MT
52 PyObject* m = PyModule_Create(&location_module);
53 if (!m)
54 return NULL;
55
fadebc89
MT
56 // AS
57 if (PyType_Ready(&ASType) < 0)
58 return NULL;
59
60 Py_INCREF(&ASType);
61 PyModule_AddObject(m, "AS", (PyObject *)&ASType);
62
9cdf6c53
MT
63 // Database
64 if (PyType_Ready(&DatabaseType) < 0)
65 return NULL;
66
67 Py_INCREF(&DatabaseType);
68 PyModule_AddObject(m, "Database", (PyObject *)&DatabaseType);
69
39967361
MT
70 // Network
71 if (PyType_Ready(&NetworkType) < 0)
72 return NULL;
73
74 Py_INCREF(&NetworkType);
75 PyModule_AddObject(m, "Network", (PyObject *)&NetworkType);
76
d688e569
MT
77 // Writer
78 if (PyType_Ready(&WriterType) < 0)
79 return NULL;
80
81 Py_INCREF(&WriterType);
82 PyModule_AddObject(m, "Writer", (PyObject *)&WriterType);
83
18e2b14c
MT
84 return m;
85}