pydnspp.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // We want a lot of different parts of the DNS API in the python
  15. // module, but not one big 10000-line file.
  16. // So we split it up in several 'mini-modules'
  17. // These would be the same as a single module, except for
  18. // the init function, which has to be modified to a unique
  19. // name initModulePart_<name>, and return true/false instead of
  20. // NULL/*mod
  21. //
  22. // And of course care has to be taken that all identifiers be unique
  23. #define PY_SSIZE_T_CLEAN
  24. #include <Python.h>
  25. #include <structmember.h>
  26. #include <config.h>
  27. #include "pydnspp_common.h"
  28. /* Note that we do forward declarations of the initialization functions here,
  29. * and these are not defined in headers (since they are not to be used in any
  30. * other place */
  31. namespace isc {
  32. namespace dns {
  33. namespace python {
  34. namespace internal {
  35. bool initModulePart_EDNS(PyObject* mod);
  36. bool initModulePart_Message(PyObject* mod);
  37. bool initModulePart_MessageRenderer(PyObject* mod);
  38. bool initModulePart_Name(PyObject* mod);
  39. bool initModulePart_Opcode(PyObject* mod);
  40. bool initModulePart_Question(PyObject* mod);
  41. bool initModulePart_Rcode(PyObject* mod);
  42. bool initModulePart_Rdata(PyObject* mod);
  43. bool initModulePart_RRClass(PyObject* mod);
  44. bool initModulePart_RRset(PyObject* mod);
  45. bool initModulePart_RRTTL(PyObject* mod);
  46. bool initModulePart_RRType(PyObject* mod);
  47. bool initModulePart_TSIGError(PyObject* mod);
  48. bool initModulePart_TSIGKey(PyObject* mod);
  49. bool initModulePart_TSIGKeyRing(PyObject* mod);
  50. bool initModulePart_TSIGContext(PyObject* mod);
  51. bool initModulePart_TSIG(PyObject* mod);
  52. bool initModulePart_TSIGRecord(PyObject* mod);
  53. }
  54. } // namespace python
  55. } // namespace dns
  56. } // namespace isc
  57. using namespace isc::dns::python;
  58. using namespace isc::dns::python::internal;
  59. //
  60. // Definition of the module
  61. //
  62. namespace {
  63. PyModuleDef pydnspp = {
  64. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
  65. "pydnspp",
  66. "Python bindings for the classes in the isc::dns namespace.\n\n"
  67. "These bindings match the original C++ API as closely as possible, "
  68. "but are not complete. Some classes are unnecessary (InputBuffer "
  69. "and OutputBuffer for instance), and others may be necessary, but "
  70. "were not up to now.",
  71. -1,
  72. NULL,
  73. NULL,
  74. NULL,
  75. NULL,
  76. NULL
  77. };
  78. }
  79. PyMODINIT_FUNC
  80. PyInit_pydnspp(void) {
  81. PyObject* mod = PyModule_Create(&pydnspp);
  82. if (mod == NULL) {
  83. return (NULL);
  84. }
  85. // Add the exceptions to the class
  86. po_IscException = PyErr_NewException("pydnspp.IscException", NULL, NULL);
  87. PyModule_AddObject(mod, "IscException", po_IscException);
  88. po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter",
  89. NULL, NULL);
  90. PyModule_AddObject(mod, "InvalidParameter", po_InvalidParameter);
  91. // for each part included above, we call its specific initializer
  92. if (!initModulePart_Name(mod)) {
  93. return (NULL);
  94. }
  95. if (!initModulePart_MessageRenderer(mod)) {
  96. return (NULL);
  97. }
  98. if (!initModulePart_RRClass(mod)) {
  99. return (NULL);
  100. }
  101. if (!initModulePart_RRType(mod)) {
  102. return (NULL);
  103. }
  104. if (!initModulePart_RRTTL(mod)) {
  105. return (NULL);
  106. }
  107. if (!initModulePart_Rdata(mod)) {
  108. return (NULL);
  109. }
  110. if (!initModulePart_RRset(mod)) {
  111. return (NULL);
  112. }
  113. if (!initModulePart_Question(mod)) {
  114. return (NULL);
  115. }
  116. if (!initModulePart_Opcode(mod)) {
  117. return (NULL);
  118. }
  119. if (!initModulePart_Rcode(mod)) {
  120. return (NULL);
  121. }
  122. if (!initModulePart_Message(mod)) {
  123. return (NULL);
  124. }
  125. if (!initModulePart_EDNS(mod)) {
  126. return (NULL);
  127. }
  128. if (!initModulePart_TSIGKey(mod)) {
  129. return (NULL);
  130. }
  131. if (!initModulePart_TSIGKeyRing(mod)) {
  132. return (NULL);
  133. }
  134. if (!initModulePart_TSIG(mod)) {
  135. return (NULL);
  136. }
  137. if (!initModulePart_TSIGError(mod)) {
  138. return (NULL);
  139. }
  140. if (!initModulePart_TSIGRecord(mod)) {
  141. return (NULL);
  142. }
  143. if (!initModulePart_TSIGContext(mod)) {
  144. return (NULL);
  145. }
  146. return (mod);
  147. }