Branch data Line data Source code
1 : : // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
2 : : //
3 : : // Permission to use, copy, modify, and/or distribute this software for any
4 : : // purpose with or without fee is hereby granted, provided that the above
5 : : // copyright notice and this permission notice appear in all copies.
6 : : //
7 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 : : // PERFORMANCE OF THIS SOFTWARE.
14 : :
15 : : #include <Python.h>
16 : :
17 : : #include <exceptions/exceptions.h>
18 : :
19 : : #include <util/buffer.h>
20 : :
21 : : #include <dns/exceptions.h>
22 : : #include <dns/name.h>
23 : : #include <dns/messagerenderer.h>
24 : :
25 : : #include "pydnspp_common.h"
26 : : #include "messagerenderer_python.h"
27 : : #include "name_python.h"
28 : : #include "rdata_python.h"
29 : : #include "rrclass_python.h"
30 : : #include "rrtype_python.h"
31 : : #include "rrttl_python.h"
32 : : #include "rrset_python.h"
33 : : #include "rcode_python.h"
34 : : #include "opcode_python.h"
35 : : #include "tsigkey_python.h"
36 : : #include "tsig_rdata_python.h"
37 : : #include "tsigerror_python.h"
38 : : #include "tsigrecord_python.h"
39 : : #include "tsig_python.h"
40 : : #include "question_python.h"
41 : : #include "message_python.h"
42 : :
43 : : using namespace isc::dns::python;
44 : :
45 : : namespace isc {
46 : : namespace dns {
47 : : namespace python {
48 : : // For our 'general' isc::Exceptions
49 : : PyObject* po_IscException;
50 : : PyObject* po_InvalidParameter;
51 : :
52 : : // For our own isc::dns::Exception
53 : : PyObject* po_DNSMessageBADVERS;
54 : :
55 : :
56 : : int
57 : 6 : readDataFromSequence(uint8_t *data, size_t len, PyObject* sequence) {
58 : 6 : PyObject* el = NULL;
59 [ + + ]: 17 : for (size_t i = 0; i < len; i++) {
60 : 12 : el = PySequence_GetItem(sequence, i);
61 [ + + ]: 12 : if (!el) {
62 : : PyErr_SetString(PyExc_TypeError,
63 : 1 : "sequence too short");
64 : 1 : return (-1);
65 : : }
66 [ + - ]: 11 : if (PyLong_Check(el)) {
67 : 11 : long l = PyLong_AsLong(el);
68 [ - + ]: 11 : if (l < 0 || l > 255) {
69 : : PyErr_SetString(PyExc_TypeError,
70 : 0 : "number in fromWire sequence not between 0 and 255");
71 : 0 : return (-1);
72 : : }
73 : 11 : data[i] = static_cast<uint8_t>(PyLong_AsLong(el));
74 : : } else {
75 : : PyErr_SetString(PyExc_TypeError,
76 : 0 : "not a number in fromWire sequence");
77 : 0 : return (-1);
78 : : }
79 : : }
80 : 5 : PySequence_DelSlice(sequence, 0, len);
81 : 6 : return (0);
82 : : }
83 : :
84 : :
85 : : int
86 : 1363 : addClassVariable(PyTypeObject& c, const char* name, PyObject* obj) {
87 [ - + ]: 1363 : if (obj == NULL) {
88 : : PyErr_SetString(PyExc_ValueError,
89 : 0 : "NULL object is specified for a class variable");
90 : 0 : return (-1);
91 : : }
92 : 1363 : return (PyDict_SetItemString(c.tp_dict, name, obj));
93 : : }
94 : : }
95 : : }
96 : 123 : }
|