repl_ext.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. /* repl_ext.c - manages operation extensions created by the
  13. * replication system
  14. */
  15. #include "repl5.h"
  16. /* structure with information for each extension */
  17. typedef struct repl_ext
  18. {
  19. char *object_name; /* name of the object extended */
  20. int object_type; /* handle to the extended object */
  21. int handle; /* extension handle */
  22. } repl_ext;
  23. /* ----------------------------- Supplier ----------------------------- */
  24. static repl_ext repl_sup_ext_list[REPL_EXT_ALL];
  25. /* initializes replication extensions */
  26. void
  27. repl_sup_init_ext()
  28. {
  29. int rc;
  30. /* populate the extension list */
  31. repl_sup_ext_list[REPL_SUP_EXT_OP].object_name = SLAPI_EXT_OPERATION;
  32. rc = slapi_register_object_extension(repl_plugin_name,
  33. SLAPI_EXT_OPERATION,
  34. supplier_operation_extension_constructor,
  35. supplier_operation_extension_destructor,
  36. &repl_sup_ext_list[REPL_SUP_EXT_OP].object_type,
  37. &repl_sup_ext_list[REPL_SUP_EXT_OP].handle);
  38. if (rc != 0) {
  39. PR_ASSERT(0); /* JCMREPL Argh */
  40. }
  41. }
  42. void *
  43. repl_sup_get_ext(ext_type type, void *object)
  44. {
  45. /* find the requested extension */
  46. repl_ext ext = repl_sup_ext_list[type];
  47. void *data = slapi_get_object_extension(ext.object_type, object, ext.handle);
  48. return data;
  49. }
  50. /* ----------------------------- Consumer ----------------------------- */
  51. static repl_ext repl_con_ext_list[REPL_EXT_ALL];
  52. /* initializes replication extensions */
  53. void
  54. repl_con_init_ext()
  55. {
  56. int rc;
  57. /* populate the extension list */
  58. repl_con_ext_list[REPL_CON_EXT_OP].object_name = SLAPI_EXT_OPERATION;
  59. rc = slapi_register_object_extension(repl_plugin_name,
  60. SLAPI_EXT_OPERATION,
  61. consumer_operation_extension_constructor,
  62. consumer_operation_extension_destructor,
  63. &repl_con_ext_list[REPL_CON_EXT_OP].object_type,
  64. &repl_con_ext_list[REPL_CON_EXT_OP].handle);
  65. if (rc != 0) {
  66. PR_ASSERT(0); /* JCMREPL Argh */
  67. }
  68. repl_con_ext_list[REPL_CON_EXT_CONN].object_name = SLAPI_EXT_CONNECTION;
  69. rc = slapi_register_object_extension(repl_plugin_name,
  70. SLAPI_EXT_CONNECTION,
  71. consumer_connection_extension_constructor,
  72. consumer_connection_extension_destructor,
  73. &repl_con_ext_list[REPL_CON_EXT_CONN].object_type,
  74. &repl_con_ext_list[REPL_CON_EXT_CONN].handle);
  75. if (rc != 0) {
  76. PR_ASSERT(0); /* JCMREPL Argh */
  77. }
  78. repl_con_ext_list[REPL_CON_EXT_MTNODE].object_name = SLAPI_EXT_MTNODE;
  79. rc = slapi_register_object_extension(repl_plugin_name,
  80. SLAPI_EXT_MTNODE,
  81. multimaster_mtnode_extension_constructor,
  82. multimaster_mtnode_extension_destructor,
  83. &repl_con_ext_list[REPL_CON_EXT_MTNODE].object_type,
  84. &repl_con_ext_list[REPL_CON_EXT_MTNODE].handle);
  85. if (rc != 0) {
  86. PR_ASSERT(0); /* JCMREPL Argh */
  87. }
  88. }
  89. void *
  90. repl_con_get_ext(ext_type type, void *object)
  91. {
  92. /* find the requested extension */
  93. repl_ext ext = repl_con_ext_list[type];
  94. void *data = slapi_get_object_extension(ext.object_type, object, ext.handle);
  95. return data;
  96. }