repl_connext.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* repl_connext.c - replication extension to the Connection object
  42. */
  43. #include "repl.h"
  44. #include "repl5.h"
  45. /* ***** Supplier side ***** */
  46. /* NOT NEEDED YET */
  47. /* ***** Consumer side ***** */
  48. /* consumer connection extension constructor */
  49. void* consumer_connection_extension_constructor (void *object, void *parent)
  50. {
  51. consumer_connection_extension *ext = (consumer_connection_extension*) slapi_ch_malloc (sizeof (consumer_connection_extension));
  52. if (ext == NULL)
  53. {
  54. slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "unable to create replication consumer connection extension - out of memory\n" );
  55. }
  56. else
  57. {
  58. ext->is_legacy_replication_dn= 0;
  59. ext->repl_protocol_version = REPL_PROTOCOL_UNKNOWN;
  60. ext->replica_acquired = NULL;
  61. ext->isreplicationsession= 0;
  62. ext->supplier_ruv = NULL;
  63. ext->connection = NULL;
  64. }
  65. return ext;
  66. }
  67. /* consumer connection extension destructor */
  68. void consumer_connection_extension_destructor (void *ext, void *object, void *parent)
  69. {
  70. PRUint64 connid = 0;
  71. if (ext)
  72. {
  73. /* Check to see if this replication session has acquired
  74. * a replica. If so, release it here.
  75. */
  76. consumer_connection_extension *connext = (consumer_connection_extension *)ext;
  77. if (NULL != connext->replica_acquired)
  78. {
  79. Replica *r = object_get_data ((Object*)connext->replica_acquired);
  80. /* If a total update was in progress, abort it */
  81. if (REPL_PROTOCOL_50_TOTALUPDATE == connext->repl_protocol_version)
  82. {
  83. Slapi_PBlock *pb = slapi_pblock_new();
  84. const Slapi_DN *repl_root_sdn = replica_get_root(r);
  85. PR_ASSERT(NULL != repl_root_sdn);
  86. if (NULL != repl_root_sdn)
  87. {
  88. slapi_pblock_set(pb, SLAPI_CONNECTION, connext->connection);
  89. slapi_pblock_set(pb, SLAPI_TARGET_DN, (void*)slapi_sdn_get_dn(repl_root_sdn));
  90. slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
  91. slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
  92. "Aborting total update in progress for replicated "
  93. "area %s connid=%" PRIu64 "\n", slapi_sdn_get_dn(repl_root_sdn),
  94. connid);
  95. slapi_stop_bulk_import(pb);
  96. }
  97. else
  98. {
  99. slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
  100. "consumer_connection_extension_destructor: can't determine root "
  101. "of replicated area.\n");
  102. }
  103. slapi_pblock_destroy(pb);
  104. /* allow reaping again */
  105. replica_set_tombstone_reap_stop(r, PR_FALSE);
  106. }
  107. replica_relinquish_exclusive_access(r, connid, -1);
  108. object_release ((Object*)connext->replica_acquired);
  109. connext->replica_acquired = NULL;
  110. }
  111. if (connext->supplier_ruv)
  112. {
  113. ruv_destroy ((RUV **)&connext->supplier_ruv);
  114. }
  115. connext->connection = NULL;
  116. slapi_ch_free((void **)&ext);
  117. }
  118. }