pydnspp.cc 4.9 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 <exceptions/exceptions.h>
  28. #include <util/buffer.h>
  29. #include <dns/exceptions.h>
  30. #include <dns/name.h>
  31. #include <dns/messagerenderer.h>
  32. #include "pydnspp_common.h"
  33. namespace isc {
  34. namespace dns {
  35. namespace python {
  36. // For our 'general' isc::Exceptions
  37. PyObject* po_IscException;
  38. PyObject* po_InvalidParameter;
  39. // For our own isc::dns::Exception
  40. PyObject* po_DNSMessageBADVERS;
  41. }
  42. }
  43. }
  44. #include "rcode_python.h"
  45. #include "tsigerror_python.h"
  46. // order is important here!
  47. using namespace isc::dns::python;
  48. #include <dns/python/messagerenderer_python.cc>
  49. #include <dns/python/name_python.cc> // needs Messagerenderer
  50. #include <dns/python/rrclass_python.cc> // needs Messagerenderer
  51. #include <dns/python/rrtype_python.cc> // needs Messagerenderer
  52. #include <dns/python/rrttl_python.cc> // needs Messagerenderer
  53. #include <dns/python/rdata_python.cc> // needs Type, Class
  54. #include <dns/python/rrset_python.cc> // needs Rdata, RRTTL
  55. #include <dns/python/question_python.cc> // needs RRClass, RRType, RRTTL,
  56. // Name
  57. #include <dns/python/tsigkey_python.cc> // needs Name
  58. #include <dns/python/tsig_python.cc> // needs tsigkey
  59. #include <dns/python/opcode_python.cc>
  60. #include <dns/python/edns_python.cc> // needs Messagerenderer, Rcode
  61. #include <dns/python/message_python.cc> // needs RRset, Question
  62. //
  63. // Definition of the module
  64. //
  65. namespace {
  66. PyModuleDef pydnspp = {
  67. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
  68. "pydnspp",
  69. "Python bindings for the classes in the isc::dns namespace.\n\n"
  70. "These bindings match the original C++ API as closely as possible, "
  71. "but are not complete. Some classes are unnecessary (InputBuffer "
  72. "and OutputBuffer for instance), and others may be necessary, but "
  73. "were not up to now.",
  74. -1,
  75. NULL,
  76. NULL,
  77. NULL,
  78. NULL,
  79. NULL
  80. };
  81. }
  82. PyMODINIT_FUNC
  83. PyInit_pydnspp(void) {
  84. PyObject* mod = PyModule_Create(&pydnspp);
  85. if (mod == NULL) {
  86. return (NULL);
  87. }
  88. // Add the exceptions to the class
  89. po_IscException = PyErr_NewException("pydnspp.IscException", NULL, NULL);
  90. PyModule_AddObject(mod, "IscException", po_IscException);
  91. po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter",
  92. NULL, NULL);
  93. PyModule_AddObject(mod, "InvalidParameter", po_InvalidParameter);
  94. // for each part included above, we call its specific initializer
  95. if (!initModulePart_Name(mod)) {
  96. return (NULL);
  97. }
  98. if (!initModulePart_MessageRenderer(mod)) {
  99. return (NULL);
  100. }
  101. if (!initModulePart_RRClass(mod)) {
  102. return (NULL);
  103. }
  104. if (!initModulePart_RRType(mod)) {
  105. return (NULL);
  106. }
  107. if (!initModulePart_RRTTL(mod)) {
  108. return (NULL);
  109. }
  110. if (!initModulePart_Rdata(mod)) {
  111. return (NULL);
  112. }
  113. if (!initModulePart_RRset(mod)) {
  114. return (NULL);
  115. }
  116. if (!initModulePart_Question(mod)) {
  117. return (NULL);
  118. }
  119. if (!initModulePart_Opcode(mod)) {
  120. return (NULL);
  121. }
  122. if (!initModulePart_Rcode(mod)) {
  123. return (NULL);
  124. }
  125. if (!initModulePart_Message(mod)) {
  126. return (NULL);
  127. }
  128. if (!initModulePart_EDNS(mod)) {
  129. return (NULL);
  130. }
  131. if (!initModulePart_TSIGKey(mod)) {
  132. return (NULL);
  133. }
  134. if (!initModulePart_TSIGKeyRing(mod)) {
  135. return (NULL);
  136. }
  137. if (!initModulePart_TSIGError(mod)) {
  138. return (NULL);
  139. }
  140. if (!initModulePart_TSIGContext(mod)) {
  141. return (NULL);
  142. }
  143. return (mod);
  144. }