]> git.ipfire.org Git - location/libloc.git/blame - src/python/locationmodule.c
python: Implement setting description to the writer
[location/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"
d688e569 22#include "writer.h"
9cdf6c53 23
18e2b14c
MT
24PyMODINIT_FUNC PyInit_location(void);
25
62ffafdd
MT
26static void location_free(void) {
27 // Release context
28 if (loc_ctx)
29 loc_unref(loc_ctx);
30}
31
18e2b14c
MT
32static PyMethodDef location_module_methods[] = {
33 { NULL },
34};
35
36static struct PyModuleDef location_module = {
37 .m_base = PyModuleDef_HEAD_INIT,
38 .m_name = "location",
39 .m_size = -1,
40 .m_doc = "Python module for libloc",
41 .m_methods = location_module_methods,
62ffafdd 42 .m_free = (freefunc)location_free,
18e2b14c
MT
43};
44
45PyMODINIT_FUNC PyInit_location(void) {
62ffafdd
MT
46 // Initialise loc context
47 int r = loc_new(&loc_ctx);
48 if (r)
49 return NULL;
50
18e2b14c
MT
51 PyObject* m = PyModule_Create(&location_module);
52 if (!m)
53 return NULL;
54
fadebc89
MT
55 // AS
56 if (PyType_Ready(&ASType) < 0)
57 return NULL;
58
59 Py_INCREF(&ASType);
60 PyModule_AddObject(m, "AS", (PyObject *)&ASType);
61
9cdf6c53
MT
62 // Database
63 if (PyType_Ready(&DatabaseType) < 0)
64 return NULL;
65
66 Py_INCREF(&DatabaseType);
67 PyModule_AddObject(m, "Database", (PyObject *)&DatabaseType);
68
d688e569
MT
69 // Writer
70 if (PyType_Ready(&WriterType) < 0)
71 return NULL;
72
73 Py_INCREF(&WriterType);
74 PyModule_AddObject(m, "Writer", (PyObject *)&WriterType);
75
18e2b14c
MT
76 return m;
77}