libdns_python.cc 3.7 KB

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