repl_ext.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "repl.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 repl_sup_init_ext ()
  27. {
  28. int rc;
  29. /* populate the extension list */
  30. repl_sup_ext_list[REPL_SUP_EXT_OP].object_name = SLAPI_EXT_OPERATION;
  31. rc = slapi_register_object_extension(repl_plugin_name,
  32. SLAPI_EXT_OPERATION,
  33. supplier_operation_extension_constructor,
  34. supplier_operation_extension_destructor,
  35. &repl_sup_ext_list[REPL_SUP_EXT_OP].object_type,
  36. &repl_sup_ext_list[REPL_SUP_EXT_OP].handle);
  37. if(rc!=0)
  38. {
  39. PR_ASSERT(0); /* JCMREPL Argh */
  40. }
  41. }
  42. void* repl_sup_get_ext (ext_type type, void *object)
  43. {
  44. /* find the requested extension */
  45. repl_ext ext = repl_sup_ext_list [type];
  46. void* data = slapi_get_object_extension(ext.object_type, object, ext.handle);
  47. return data;
  48. }
  49. /* ----------------------------- Consumer ----------------------------- */
  50. static repl_ext repl_con_ext_list [REPL_EXT_ALL];
  51. /* initializes replication extensions */
  52. void repl_con_init_ext ()
  53. {
  54. int rc;
  55. /* populate the extension list */
  56. repl_con_ext_list[REPL_CON_EXT_OP].object_name = SLAPI_EXT_OPERATION;
  57. rc = slapi_register_object_extension(repl_plugin_name,
  58. SLAPI_EXT_OPERATION,
  59. consumer_operation_extension_constructor,
  60. consumer_operation_extension_destructor,
  61. &repl_con_ext_list[REPL_CON_EXT_OP].object_type,
  62. &repl_con_ext_list[REPL_CON_EXT_OP].handle);
  63. if(rc!=0)
  64. {
  65. PR_ASSERT(0); /* JCMREPL Argh */
  66. }
  67. repl_con_ext_list[REPL_CON_EXT_CONN].object_name = SLAPI_EXT_CONNECTION;
  68. rc = slapi_register_object_extension(repl_plugin_name,
  69. SLAPI_EXT_CONNECTION,
  70. consumer_connection_extension_constructor,
  71. consumer_connection_extension_destructor,
  72. &repl_con_ext_list[REPL_CON_EXT_CONN].object_type,
  73. &repl_con_ext_list[REPL_CON_EXT_CONN].handle);
  74. if(rc!=0)
  75. {
  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. {
  87. PR_ASSERT(0); /* JCMREPL Argh */
  88. }
  89. }
  90. void* 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. }