repl_session_plugin.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2010 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. /* repl_session_plugin.c */
  38. #include "repl.h"
  39. #include "repl5.h"
  40. #include "slap.h"
  41. #include "slapi-plugin.h"
  42. #include "repl-session-plugin.h"
  43. /* an array of function pointers */
  44. static void **_ReplSessionAPI = NULL;
  45. void
  46. repl_session_plugin_init()
  47. {
  48. /* If the function pointer array is null, get the functions.
  49. * We will only grab the api once. */
  50. if((NULL == _ReplSessionAPI) &&
  51. (slapi_apib_get_interface(REPL_SESSION_v1_0_GUID, &_ReplSessionAPI) ||
  52. (NULL == _ReplSessionAPI))) {
  53. LDAPDebug1Arg( LDAP_DEBUG_PLUGIN,
  54. "<-- repl_session_plugin_init -- no replication session"
  55. " plugin API registered for GUID [%s] -- end\n",
  56. REPL_SESSION_v1_0_GUID);
  57. }
  58. return;
  59. }
  60. void
  61. repl_session_plugin_call_agmt_init_cb(Repl_Agmt *ra)
  62. {
  63. void *cookie = NULL;
  64. Slapi_DN *replarea = NULL;
  65. repl_session_plugin_agmt_init_cb initfunc = NULL;
  66. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "--> repl_session_plugin_call_agmt_init_cb -- begin\n");
  67. if (_ReplSessionAPI) {
  68. initfunc = (repl_session_plugin_agmt_init_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_AGMT_INIT_CB];
  69. }
  70. if (initfunc) {
  71. replarea = agmt_get_replarea(ra);
  72. cookie = (*initfunc)(replarea);
  73. slapi_sdn_free(&replarea);
  74. }
  75. agmt_set_priv(ra, cookie);
  76. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- repl_session_plugin_call_agmt_init_cb -- end\n");
  77. return;
  78. }
  79. int
  80. repl_session_plugin_call_pre_acquire_cb(const Repl_Agmt *ra, int is_total,
  81. char **data_guid, struct berval **data)
  82. {
  83. int rc = 0;
  84. Slapi_DN *replarea = NULL;
  85. repl_session_plugin_pre_acquire_cb thefunc =
  86. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB]) ?
  87. (repl_session_plugin_pre_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB] :
  88. NULL;
  89. if (thefunc) {
  90. replarea = agmt_get_replarea(ra);
  91. rc = (*thefunc)(agmt_get_priv(ra), replarea, is_total,
  92. data_guid, data);
  93. slapi_sdn_free(&replarea);
  94. }
  95. return rc;
  96. }
  97. int
  98. repl_session_plugin_call_post_acquire_cb(const Repl_Agmt *ra, int is_total,
  99. const char *data_guid, const struct berval *data)
  100. {
  101. int rc = 0;
  102. Slapi_DN *replarea = NULL;
  103. repl_session_plugin_post_acquire_cb thefunc =
  104. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB]) ?
  105. (repl_session_plugin_post_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB] :
  106. NULL;
  107. if (thefunc) {
  108. replarea = agmt_get_replarea(ra);
  109. rc = (*thefunc)(agmt_get_priv(ra), replarea,
  110. is_total, data_guid, data);
  111. slapi_sdn_free(&replarea);
  112. }
  113. return rc;
  114. }
  115. int
  116. repl_session_plugin_call_recv_acquire_cb(const char *repl_area, int is_total,
  117. const char *data_guid, const struct berval *data)
  118. {
  119. int rc = 0;
  120. repl_session_plugin_recv_acquire_cb thefunc =
  121. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB]) ?
  122. (repl_session_plugin_recv_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB] :
  123. NULL;
  124. if (thefunc) {
  125. rc = (*thefunc)(repl_area, is_total, data_guid, data);
  126. }
  127. return rc;
  128. }
  129. int
  130. repl_session_plugin_call_reply_acquire_cb(const char *repl_area, int is_total,
  131. char **data_guid, struct berval **data)
  132. {
  133. int rc = 0;
  134. repl_session_plugin_reply_acquire_cb thefunc =
  135. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB]) ?
  136. (repl_session_plugin_reply_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB] :
  137. NULL;
  138. if (thefunc) {
  139. rc = (*thefunc)(repl_area, is_total, data_guid, data);
  140. }
  141. return rc;
  142. }
  143. void
  144. repl_session_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra)
  145. {
  146. Slapi_DN *replarea = NULL;
  147. repl_session_plugin_destroy_agmt_cb thefunc =
  148. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB]) ?
  149. (repl_session_plugin_destroy_agmt_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB] :
  150. NULL;
  151. if (thefunc) {
  152. replarea = agmt_get_replarea(ra);
  153. (*thefunc)(agmt_get_priv(ra), replarea);
  154. slapi_sdn_free(&replarea);
  155. }
  156. return;
  157. }