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.
19 #include <loc/libloc.h>
21 #include <loc/stringpool.h>
25 static PyObject
* AS_new(PyTypeObject
* type
, PyObject
* args
, PyObject
* kwds
) {
26 // Create libloc context
28 int r
= loc_new(&ctx
);
33 struct loc_stringpool
* pool
;
34 r
= loc_stringpool_new(ctx
, &pool
);
40 ASObject
* self
= (ASObject
*)type
->tp_alloc(type
, 0);
46 return (PyObject
*)self
;
49 static void AS_dealloc(ASObject
* self
) {
51 loc_as_unref(self
->as
);
54 loc_stringpool_unref(self
->pool
);
59 Py_TYPE(self
)->tp_free((PyObject
* )self
);
62 static int AS_init(ASObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
65 if (!PyArg_ParseTuple(args
, "i", &number
))
68 // Create the AS object
69 int r
= loc_as_new(self
->ctx
, self
->pool
, &self
->as
, number
);
76 static PyObject
* AS_get_number(ASObject
* self
) {
77 uint32_t number
= loc_as_get_number(self
->as
);
79 return PyLong_FromLong(number
);
82 static PyObject
* AS_get_name(ASObject
* self
) {
83 const char* name
= loc_as_get_name(self
->as
);
85 return PyUnicode_FromString(name
);
88 static struct PyGetSetDef AS_getsetters
[] = {
98 (getter
)AS_get_number
,
106 PyTypeObject ASType
= {
107 PyVarObject_HEAD_INIT(NULL
, 0)
108 tp_name
: "location.AS",
109 tp_basicsize
: sizeof(ASObject
),
110 tp_flags
: Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
112 tp_dealloc
: (destructor
)AS_dealloc
,
113 tp_init
: (initproc
)AS_init
,
115 tp_getset
: AS_getsetters
,