libdns_python.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Ok we want a lot of different parts of the DNS API in the python
  2. // module, but not one big 10000-line file.
  3. // So we split it up in several 'mini-modules'
  4. // These would be the same as a single module, except for
  5. // the init function, which has to be modified to a unique
  6. // name initModulePart_<name>, and return true/false instead of
  7. // NULL/*mod
  8. //
  9. // And of course care has to be taken that all identifiers be unique
  10. //
  11. #define PY_SSIZE_T_CLEAN
  12. #include <Python.h>
  13. #include "config.h"
  14. #include <exceptions/exceptions.h>
  15. #include <dns/buffer.h>
  16. #include <dns/exceptions.h>
  17. #include <dns/name.h>
  18. #include <dns/messagerenderer.h>
  19. #include "libdns_python_common.h"
  20. //#include "buffer_python.cc"
  21. // order is important here! (TODO: document dependencies)
  22. #include "name_python.cc"
  23. #include "messagerenderer_python.cc"
  24. #include "rrclass_python.cc"
  25. #include "rrtype_python.cc"
  26. #include "rrttl_python.cc"
  27. #include "rdata_python.cc"
  28. #include "rrset_python.cc"
  29. //
  30. // Definition of the module
  31. //
  32. static PyModuleDef libdns_python = {
  33. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
  34. "libdns_python",
  35. "Python bindings for isc.dns",
  36. -1,
  37. NULL,
  38. NULL,
  39. NULL,
  40. NULL,
  41. NULL
  42. };
  43. PyMODINIT_FUNC
  44. PyInit_libdns_python(void)
  45. {
  46. PyObject *mod = PyModule_Create(&libdns_python);
  47. if (mod == NULL) {
  48. return NULL;
  49. }
  50. // for each part included above, we call its specific initializer
  51. if (!initModulePart_Name(mod)) {
  52. return NULL;
  53. }
  54. if (!initModulePart_MessageRenderer(mod)) {
  55. return NULL;
  56. }
  57. if (!initModulePart_RRClass(mod)) {
  58. return NULL;
  59. }
  60. if (!initModulePart_RRType(mod)) {
  61. return NULL;
  62. }
  63. if (!initModulePart_RRTTL(mod)) {
  64. return NULL;
  65. }
  66. if (!initModulePart_Rdata(mod)) {
  67. return NULL;
  68. }
  69. if (!initModulePart_RRset(mod)) {
  70. return NULL;
  71. }
  72. return mod;
  73. }