sync.h 5.6 KB

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