123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #include <Python.h>
- #include <string>
- #include <stdexcept>
- #include <util/python/pycppwrapper_util.h>
- #include <acl/acl.h>
- #include <acl/dns.h>
- #include "dns.h"
- #include "dns_requestacl_python.h"
- #include "dns_requestcontext_python.h"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::acl;
- using namespace isc::acl::dns;
- using namespace isc::acl::dns::python;
- s_RequestACL::s_RequestACL() {}
- #include "dns_requestacl_inc.cc"
- namespace {
- int
- RequestACL_init(PyObject*, PyObject*, PyObject*) {
- PyErr_SetString(getACLException("Error"),
- "RequestACL cannot be directly constructed");
- return (-1);
- }
- void
- RequestACL_destroy(PyObject* po_self) {
- s_RequestACL* const self = static_cast<s_RequestACL*>(po_self);
- self->cppobj.reset();
- Py_TYPE(self)->tp_free(self);
- }
- PyObject*
- RequestACL_execute(PyObject* po_self, PyObject* args) {
- s_RequestACL* const self = static_cast<s_RequestACL*>(po_self);
- try {
- const s_RequestContext* po_context;
- if (PyArg_ParseTuple(args, "O!", &requestcontext_type, &po_context)) {
- const BasicAction action =
- self->cppobj->execute(*po_context->cppobj);
- return (Py_BuildValue("I", action));
- }
- } catch (const exception& ex) {
- const string ex_what = "Failed to execute ACL: " + string(ex.what());
- PyErr_SetString(getACLException("Error"), ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_RuntimeError,
- "Unexpected exception in executing ACL");
- }
- return (NULL);
- }
- PyMethodDef RequestACL_methods[] = {
- { "execute", RequestACL_execute, METH_VARARGS, RequestACL_execute_doc },
- { NULL, NULL, 0, NULL }
- };
- }
- namespace isc {
- namespace acl {
- namespace dns {
- namespace python {
- PyTypeObject requestacl_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "isc.acl.dns.RequestACL",
- sizeof(s_RequestACL),
- 0,
- RequestACL_destroy,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- RequestACL_doc,
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- RequestACL_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- RequestACL_init,
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- bool
- initModulePart_RequestACL(PyObject* mod) {
-
-
-
- if (PyType_Ready(&requestacl_type) < 0) {
- return (false);
- }
- void* p = &requestacl_type;
- if (PyModule_AddObject(mod, "RequestACL", static_cast<PyObject*>(p)) < 0) {
- return (false);
- }
- Py_INCREF(&requestacl_type);
- return (true);
- }
- }
- }
- }
- }
|