sync.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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) 2013 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40. /**
  41. * LDAP content synchronization plug-in
  42. */
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include "slapi-plugin.h"
  46. #define PLUGIN_NAME "content-sync-plugin"
  47. #define SYNC_PLUGIN_SUBSYSTEM "content-sync-plugin"
  48. #define SYNC_PREOP_DESC "content-sync-preop-subplugin"
  49. #define SYNC_POSTOP_DESC "content-sync-postop-subplugin"
  50. #define OP_FLAG_SYNC_PERSIST 0x01
  51. #define E_SYNC_REFRESH_REQUIRED 0x1000
  52. #define CL_ATTR_CHANGENUMBER "changenumber"
  53. #define CL_ATTR_ENTRYDN "targetDn"
  54. #define CL_ATTR_UNIQUEID "targetUniqueId"
  55. #define CL_ATTR_CHGTYPE "changetype"
  56. #define CL_ATTR_NEWSUPERIOR "newsuperior"
  57. #define CL_SRCH_BASE "cn=changelog"
  58. #define SYNC_INVALID_CHANGENUM ((unsigned long)-1)
  59. typedef struct sync_cookie {
  60. char *cookie_client_signature;
  61. char *cookie_server_signature;
  62. unsigned long cookie_change_info;
  63. } Sync_Cookie;
  64. typedef struct sync_update {
  65. char *upd_uuid;
  66. int upd_chgtype;
  67. Slapi_Entry *upd_e;
  68. } Sync_UpdateNode;
  69. #define SYNC_CALLBACK_PREINIT (-1)
  70. typedef struct sync_callback {
  71. Slapi_PBlock *orig_pb;
  72. unsigned long changenr;
  73. unsigned long change_start;
  74. int cb_err;
  75. Sync_UpdateNode *cb_updates;
  76. } Sync_CallBackData;
  77. int sync_register_operation_extension(void);
  78. int sync_unregister_operation_entension(void);
  79. int sync_srch_refresh_pre_search(Slapi_PBlock *pb);
  80. int sync_srch_refresh_post_search(Slapi_PBlock *pb);
  81. int sync_srch_refresh_pre_entry(Slapi_PBlock *pb);
  82. int sync_srch_refresh_pre_result(Slapi_PBlock *pb);
  83. int sync_del_persist_post_op(Slapi_PBlock *pb);
  84. int sync_mod_persist_post_op(Slapi_PBlock *pb);
  85. int sync_modrdn_persist_post_op(Slapi_PBlock *pb);
  86. int sync_add_persist_post_op(Slapi_PBlock *pb);
  87. int sync_parse_control_value( struct berval *psbvp, ber_int_t *mode, int *reload, char **cookie );
  88. int sync_create_state_control( Slapi_Entry *e, LDAPControl **ctrlp, int type, Sync_Cookie *cookie);
  89. int sync_create_sync_done_control( LDAPControl **ctrlp, int refresh, char *cookie);
  90. int sync_intermediate_msg (Slapi_PBlock *pb, int tag, Sync_Cookie *cookie, char **uuids);
  91. int sync_result_msg (Slapi_PBlock *pb, Sync_Cookie *cookie);
  92. int sync_result_err (Slapi_PBlock *pb, int rc, char *msg);
  93. Sync_Cookie *sync_cookie_create (Slapi_PBlock *pb);
  94. void sync_cookie_update (Sync_Cookie *cookie, Slapi_Entry *ec);
  95. Sync_Cookie *sync_cookie_parse (char *cookie);
  96. int sync_cookie_isvalid (Sync_Cookie *testcookie, Sync_Cookie *refcookie);
  97. void sync_cookie_free (Sync_Cookie **freecookie);
  98. char * sync_cookie2str(Sync_Cookie *cookie);
  99. int sync_number2int(char *nrstr);
  100. unsigned long sync_number2ulong(char *nrstr);
  101. char *sync_nsuniqueid2uuid(const char *nsuniqueid);
  102. int sync_is_active (Slapi_Entry *e, Slapi_PBlock *pb);
  103. int sync_is_active_scope (const Slapi_DN *dn, Slapi_PBlock *pb);
  104. int sync_refresh_update_content(Slapi_PBlock *pb, Sync_Cookie *client_cookie, Sync_Cookie *session_cookie);
  105. int sync_refresh_initial_content(Slapi_PBlock *pb, int persist, PRThread *tid, Sync_Cookie *session_cookie);
  106. int sync_read_entry_from_changelog( Slapi_Entry *cl_entry, void *cb_data);
  107. int sync_send_entry_from_changelog( Slapi_PBlock *pb, int chg_req, char *uniqueid);
  108. void sync_send_deleted_entries (Slapi_PBlock *pb, Sync_UpdateNode *upd, int chg_count, Sync_Cookie *session_cookie);
  109. void sync_send_modified_entries (Slapi_PBlock *pb, Sync_UpdateNode *upd, int chg_count);
  110. int sync_persist_initialize (int argc, char **argv);
  111. PRThread *sync_persist_add (Slapi_PBlock *pb);
  112. int sync_persist_startup (PRThread *tid, Sync_Cookie *session_cookie);
  113. int sync_persist_terminate_all ();
  114. int sync_persist_terminate (PRThread *tid);
  115. Slapi_PBlock *sync_pblock_copy(Slapi_PBlock *src);
  116. /* prototype for functions not in slapi-plugin.h */
  117. Slapi_ComponentId *plugin_get_default_component_id();
  118. /*
  119. * Structures to handle the persitent phase of
  120. * Content Synchronization Requests
  121. *
  122. * A queue of entries being to be sent by a particular persistent
  123. * sync thread
  124. *
  125. * will be created in post op plugins
  126. */
  127. typedef struct sync_queue_node {
  128. Slapi_Entry *sync_entry;
  129. LDAPControl *pe_ctrls[2]; /* XXX ?? XXX */
  130. struct sync_queue_node *sync_next;
  131. int sync_chgtype;
  132. } SyncQueueNode;
  133. /*
  134. * Information about a single sync search
  135. *
  136. * will be created when a content sync control with
  137. * mode == 3 is decoded
  138. */
  139. typedef struct sync_request {
  140. Slapi_PBlock *req_pblock;
  141. Slapi_Operation *req_orig_op;
  142. PRLock *req_lock;
  143. PRThread *req_tid;
  144. char *req_orig_base;
  145. Slapi_Filter *req_filter;
  146. PRInt32 req_complete;
  147. Sync_Cookie *req_cookie;
  148. SyncQueueNode *ps_eq_head;
  149. SyncQueueNode *ps_eq_tail;
  150. int req_active;
  151. struct sync_request *req_next;
  152. } SyncRequest;
  153. /*
  154. * A list of established persistent synchronization searches.
  155. *
  156. * will be initialized at plugin initialization
  157. */
  158. #define SYNC_MAX_CONCURRENT 10
  159. typedef struct sync_request_list {
  160. Slapi_RWLock *sync_req_rwlock; /* R/W lock struct to serialize access */
  161. SyncRequest *sync_req_head; /* Head of list */
  162. PRLock *sync_req_cvarlock; /* Lock for cvar */
  163. PRCondVar *sync_req_cvar; /* ps threads sleep on this */
  164. int sync_req_max_persist;
  165. int sync_req_cur_persist;
  166. } SyncRequestList;
  167. #define SYNC_FLAG_ADD_STATE_CTRL 0x01
  168. #define SYNC_FLAG_ADD_DONE_CTRL 0x02
  169. #define SYNC_FLAG_NO_RESULT 0x04
  170. #define SYNC_FLAG_SEND_INTERMEDIATE 0x08
  171. typedef struct sync_op_info {
  172. int send_flag; /* hint for preop plugins what to send */
  173. Sync_Cookie *cookie;/* cookie to add in control */
  174. PRThread *tid; /* thread for persistent phase */
  175. } SyncOpInfo;