dns.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include <Python.h>
  15. #include <stdexcept>
  16. #include <boost/shared_ptr.hpp>
  17. #include <util/python/pycppwrapper_util.h>
  18. #include <cc/data.h>
  19. #include <acl/acl.h>
  20. #include <acl/dns.h>
  21. #include "dns_requestacl_python.h"
  22. using namespace std;
  23. using boost::shared_ptr;
  24. using namespace isc::util::python;
  25. using namespace isc::data;
  26. using namespace isc::acl::dns;
  27. using namespace isc::acl::dns::python;
  28. namespace {
  29. PyObject* po_dns_LoaderError;
  30. PyObject*
  31. loadRequestACL(PyObject*, PyObject* args) {
  32. const char* acl_config;
  33. if (PyArg_ParseTuple(args, "s", &acl_config)) {
  34. try {
  35. shared_ptr<RequestACL> acl(
  36. getRequestLoader().load(Element::fromJSON(acl_config)));
  37. s_RequestACL* py_acl = static_cast<s_RequestACL*>(
  38. requestacl_type.tp_alloc(&requestacl_type, 0));
  39. if (py_acl != NULL) {
  40. py_acl->cppobj = acl;
  41. }
  42. return (py_acl);
  43. } catch (const exception& ex) {
  44. PyErr_SetString(po_dns_LoaderError, ex.what());
  45. return (NULL);
  46. } catch (...) {
  47. PyErr_SetString(PyExc_SystemError, "Unexpected C++ exception");
  48. return (NULL);
  49. }
  50. }
  51. return (NULL);
  52. }
  53. PyMethodDef methods[] = {
  54. { "load_request_acl", loadRequestACL, METH_VARARGS, "TBD" },
  55. { NULL, NULL, 0, NULL }
  56. };
  57. PyModuleDef dnsacl = {
  58. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
  59. "isc.acl.dns",
  60. "This module provides Python bindings for the C++ classes in the "
  61. "isc::acl::dns namespace. Specifically, it defines Python interfaces of "
  62. "handling access control lists (ACLs) with DNS related contexts.\n\n"
  63. "These bindings are close match to the C++ API, but they are not complete "
  64. "(some parts are not needed) and some are done in more python-like ways.",
  65. -1,
  66. methods,
  67. NULL,
  68. NULL,
  69. NULL,
  70. NULL
  71. };
  72. } // end of unnamed namespace
  73. PyMODINIT_FUNC
  74. PyInit_dns(void) {
  75. PyObject* mod = PyModule_Create(&dnsacl);
  76. if (mod == NULL) {
  77. return (NULL);
  78. }
  79. try {
  80. po_dns_LoaderError = PyErr_NewException("isc.acl.dns.LoaderError",
  81. NULL, NULL);
  82. PyObjectContainer(po_dns_LoaderError).installToModule(mod,
  83. "LoaderError");
  84. } catch (...) {
  85. Py_DECREF(mod);
  86. return (NULL);
  87. }
  88. if (!initModulePart_RequestACL(mod)) {
  89. Py_DECREF(mod);
  90. return (NULL);
  91. }
  92. return (mod);
  93. }