repl_connext.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. /* repl_connext.c - replication extension to the Connection object
  7. */
  8. #include "repl.h"
  9. #include "repl5.h"
  10. /* ***** Supplier side ***** */
  11. /* NOT NEEDED YET */
  12. /* ***** Consumer side ***** */
  13. /* consumer connection extension constructor */
  14. void* consumer_connection_extension_constructor (void *object, void *parent)
  15. {
  16. consumer_connection_extension *ext = (consumer_connection_extension*) slapi_ch_malloc (sizeof (consumer_connection_extension));
  17. if (ext == NULL)
  18. {
  19. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "unable to create replication consumer connection extension - out of memory\n" );
  20. }
  21. else
  22. {
  23. ext->is_legacy_replication_dn= 0;
  24. ext->repl_protocol_version = REPL_PROTOCOL_UNKNOWN;
  25. ext->replica_acquired = NULL;
  26. ext->isreplicationsession= 0;
  27. ext->supplier_ruv = NULL;
  28. ext->connection = NULL;
  29. }
  30. return ext;
  31. }
  32. /* consumer connection extension destructor */
  33. void consumer_connection_extension_destructor (void *ext, void *object, void *parent)
  34. {
  35. int connid = 0;
  36. if (ext)
  37. {
  38. /* Check to see if this replication session has acquired
  39. * a replica. If so, release it here.
  40. */
  41. consumer_connection_extension *connext = (consumer_connection_extension *)ext;
  42. if (NULL != connext->replica_acquired)
  43. {
  44. Replica *r = object_get_data ((Object*)connext->replica_acquired);
  45. /* If a total update was in progress, abort it */
  46. if (REPL_PROTOCOL_50_TOTALUPDATE == connext->repl_protocol_version)
  47. {
  48. Slapi_PBlock *pb = slapi_pblock_new();
  49. const Slapi_DN *repl_root_sdn = replica_get_root(r);
  50. PR_ASSERT(NULL != repl_root_sdn);
  51. if (NULL != repl_root_sdn)
  52. {
  53. slapi_pblock_set(pb, SLAPI_CONNECTION, connext->connection);
  54. slapi_pblock_set(pb, SLAPI_TARGET_DN, (void*)slapi_sdn_get_dn(repl_root_sdn));
  55. slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
  56. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  57. "Aborting total update in progress for replicated "
  58. "area %s connid=%d\n", slapi_sdn_get_dn(repl_root_sdn),
  59. connid);
  60. slapi_stop_bulk_import(pb);
  61. }
  62. else
  63. {
  64. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  65. "consumer_connection_extension_destructor: can't determine root "
  66. "of replicated area.\n");
  67. }
  68. slapi_pblock_destroy(pb);
  69. /* allow reaping again */
  70. replica_set_tombstone_reap_stop(r, PR_FALSE);
  71. }
  72. replica_relinquish_exclusive_access(r, connid, -1);
  73. object_release ((Object*)connext->replica_acquired);
  74. connext->replica_acquired = NULL;
  75. }
  76. if (connext->supplier_ruv)
  77. {
  78. ruv_destroy ((RUV **)&connext->supplier_ruv);
  79. }
  80. connext->connection = NULL;
  81. slapi_ch_free((void **)&ext);
  82. }
  83. }