1
0

repl_session_plugin.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. initfunc = (repl_session_plugin_agmt_init_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_AGMT_INIT_CB];
  68. if (initfunc) {
  69. replarea = agmt_get_replarea(ra);
  70. cookie = (*initfunc)(replarea);
  71. slapi_sdn_free(&replarea);
  72. }
  73. agmt_set_priv(ra, cookie);
  74. LDAPDebug0Args( LDAP_DEBUG_PLUGIN, "<-- repl_session_plugin_call_agmt_init_cb -- end\n");
  75. return;
  76. }
  77. int
  78. repl_session_plugin_call_pre_acquire_cb(const Repl_Agmt *ra, int is_total,
  79. char **data_guid, struct berval **data)
  80. {
  81. int rc = 0;
  82. Slapi_DN *replarea = NULL;
  83. repl_session_plugin_pre_acquire_cb thefunc =
  84. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB]) ?
  85. (repl_session_plugin_pre_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB] :
  86. NULL;
  87. if (thefunc) {
  88. replarea = agmt_get_replarea(ra);
  89. rc = (*thefunc)(agmt_get_priv(ra), replarea, is_total,
  90. data_guid, data);
  91. slapi_sdn_free(&replarea);
  92. }
  93. return rc;
  94. }
  95. int
  96. repl_session_plugin_call_post_acquire_cb(const Repl_Agmt *ra, int is_total,
  97. const char *data_guid, const struct berval *data)
  98. {
  99. int rc = 0;
  100. Slapi_DN *replarea = NULL;
  101. repl_session_plugin_post_acquire_cb thefunc =
  102. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB]) ?
  103. (repl_session_plugin_post_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB] :
  104. NULL;
  105. if (thefunc) {
  106. replarea = agmt_get_replarea(ra);
  107. rc = (*thefunc)(agmt_get_priv(ra), replarea,
  108. is_total, data_guid, data);
  109. slapi_sdn_free(&replarea);
  110. }
  111. return rc;
  112. }
  113. int
  114. repl_session_plugin_call_recv_acquire_cb(const char *repl_area, int is_total,
  115. const char *data_guid, const struct berval *data)
  116. {
  117. int rc = 0;
  118. repl_session_plugin_recv_acquire_cb thefunc =
  119. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB]) ?
  120. (repl_session_plugin_recv_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB] :
  121. NULL;
  122. if (thefunc) {
  123. rc = (*thefunc)(repl_area, is_total, data_guid, data);
  124. }
  125. return rc;
  126. }
  127. int
  128. repl_session_plugin_call_reply_acquire_cb(const char *repl_area, int is_total,
  129. char **data_guid, struct berval **data)
  130. {
  131. int rc = 0;
  132. repl_session_plugin_reply_acquire_cb thefunc =
  133. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB]) ?
  134. (repl_session_plugin_reply_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB] :
  135. NULL;
  136. if (thefunc) {
  137. rc = (*thefunc)(repl_area, is_total, data_guid, data);
  138. }
  139. return rc;
  140. }
  141. void
  142. repl_session_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra)
  143. {
  144. Slapi_DN *replarea = NULL;
  145. repl_session_plugin_destroy_agmt_cb thefunc =
  146. (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB]) ?
  147. (repl_session_plugin_destroy_agmt_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB] :
  148. NULL;
  149. if (thefunc) {
  150. replarea = agmt_get_replarea(ra);
  151. (*thefunc)(agmt_get_priv(ra), replarea);
  152. slapi_sdn_free(&replarea);
  153. }
  154. return;
  155. }