pydnspp.cc 4.2 KB

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