Branch data Line data Source code
1 : : // Copyright (C) 2011 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 <util/python/pycppwrapper_util.h>
18 : :
19 : : #include <acl/acl.h>
20 : :
21 : : using namespace isc::util::python;
22 : :
23 : : #include "acl_inc.cc"
24 : :
25 : : namespace {
26 : : // Commonly used Python exception objects. Right now the acl module consists
27 : : // of only one .cc file, so we hide them in an unnamed namespace. If and when
28 : : // we extend this module with multiple .cc files, we should move them to
29 : : // a named namespace, say isc::acl::python, and declare them in a separate
30 : : // header file.
31 : : PyObject* po_ACLError;
32 : : PyObject* po_LoaderError;
33 : : }
34 : :
35 : : namespace {
36 : : PyModuleDef acl = {
37 : : { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
38 : : "isc.acl.acl",
39 : : acl_doc,
40 : : -1,
41 : : NULL,
42 : : NULL,
43 : : NULL,
44 : : NULL,
45 : : NULL
46 : : };
47 : : } // end of unnamed namespace
48 : :
49 : : PyMODINIT_FUNC
50 : 3 : PyInit_acl(void) {
51 : 3 : PyObject* mod = PyModule_Create(&acl);
52 [ + - ]: 3 : if (mod == NULL) {
53 : : return (NULL);
54 : : }
55 : :
56 : : try {
57 [ + - ]: 3 : po_ACLError = PyErr_NewException("isc.acl.Error", NULL, NULL);
58 [ + - ][ + - ]: 3 : PyObjectContainer(po_ACLError).installToModule(mod, "Error");
[ + - ]
59 : :
60 [ + - ]: 3 : po_LoaderError = PyErr_NewException("isc.acl.LoaderError", NULL, NULL);
61 [ + - ][ + - ]: 3 : PyObjectContainer(po_LoaderError).installToModule(mod, "LoaderError");
[ + - ]
62 : :
63 : : // Install module constants. Note that we can let Py_BuildValue
64 : : // "steal" the references to these object (by specifying false to
65 : : // installToModule), because, unlike the exception cases above,
66 : : // we don't have corresponding C++ variables (see the note in
67 : : // pycppwrapper_util for more details).
68 [ + - ]: 3 : PyObjectContainer(Py_BuildValue("I", isc::acl::ACCEPT)).
69 [ + - ][ + - ]: 3 : installToModule(mod, "ACCEPT", false);
[ + - ]
70 [ + - ]: 3 : PyObjectContainer(Py_BuildValue("I", isc::acl::REJECT)).
71 [ + - ][ + - ]: 3 : installToModule(mod, "REJECT", false);
[ + - ]
72 [ + - ]: 3 : PyObjectContainer(Py_BuildValue("I", isc::acl::DROP)).
73 [ + - ][ + - ]: 3 : installToModule(mod, "DROP", false);
[ + - ]
74 : 0 : } catch (...) {
75 [ # # ][ # # ]: 0 : Py_DECREF(mod);
76 : : return (NULL);
77 : : }
78 : :
79 : : return (mod);
80 : 0 : }
|