File: repl_session_plugin.c

package info (click to toggle)
389-ds-base 2.3.1%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 37,536 kB
  • sloc: ansic: 306,972; python: 96,937; cpp: 10,257; perl: 2,854; makefile: 2,046; sh: 925; yacc: 806; xml: 379; lex: 366; javascript: 148; java: 50
file content (164 lines) | stat: -rw-r--r-- 5,289 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/** BEGIN COPYRIGHT BLOCK
 * Copyright (C) 2010 Red Hat, Inc.
 * All rights reserved.
 *
 * License: GPL (version 3 or any later version).
 * See LICENSE for details.
 * END COPYRIGHT BLOCK **/

/* repl_session_plugin.c */

#include "repl5.h"
#include "slap.h"
#include "slapi-plugin.h"
#include "repl-session-plugin.h"

/* an array of function pointers */
static void **_ReplSessionAPI = NULL;

void
repl_session_plugin_init()
{
    /* If the function pointer array is null, get the functions.
     * We will only grab the api once. */
    if ((NULL == _ReplSessionAPI) &&
        (slapi_apib_get_interface(REPL_SESSION_v1_0_GUID, &_ReplSessionAPI) ||
         (NULL == _ReplSessionAPI))) {
        slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name,
                      "repl_session_plugin_init - No replication session"
                      " plugin API registered for GUID [%s] -- end\n",
                      REPL_SESSION_v1_0_GUID);
    }

    return;
}

void
repl_session_plugin_call_agmt_init_cb(Repl_Agmt *ra)
{
    void *cookie = NULL;
    Slapi_DN *replarea = NULL;
    repl_session_plugin_agmt_init_cb initfunc = NULL;

    slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name,
                  "repl_session_plugin_call_agmt_init_cb - Begin\n");

    if (_ReplSessionAPI) {
        initfunc = (repl_session_plugin_agmt_init_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_AGMT_INIT_CB];
    }
    if (initfunc) {
        replarea = agmt_get_replarea(ra);
        if (!replarea) {
            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
                          "repl_session_plugin_call_agmt_init_cb- Aborted - No replication area\n");
            return;
        }
        cookie = (*initfunc)(replarea);
        slapi_sdn_free(&replarea);
    }

    agmt_set_priv(ra, cookie);

    slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "repl_session_plugin_call_agmt_init_cb - End\n");

    return;
}

int
repl_session_plugin_call_pre_acquire_cb(const Repl_Agmt *ra, int is_total, char **data_guid, struct berval **data)
{
    int rc = 0;
    Slapi_DN *replarea = NULL;

    repl_session_plugin_pre_acquire_cb thefunc =
        (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB]) ? (repl_session_plugin_pre_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_PRE_ACQUIRE_CB] : NULL;

    if (thefunc) {
        replarea = agmt_get_replarea(ra);
        if (!replarea) {
            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
                          "repl_session_plugin_call_pre_acquire_cb "
                          "- Aborted - No replication area\n");
            return 1;
        }
        rc = (*thefunc)(agmt_get_priv(ra), replarea, is_total, data_guid, data);
        slapi_sdn_free(&replarea);
    }

    return rc;
}

int
repl_session_plugin_call_post_acquire_cb(const Repl_Agmt *ra, int is_total, const char *data_guid, const struct berval *data)
{
    int rc = 0;
    Slapi_DN *replarea = NULL;

    repl_session_plugin_post_acquire_cb thefunc =
        (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB]) ? (repl_session_plugin_post_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_POST_ACQUIRE_CB] : NULL;

    if (thefunc) {
        replarea = agmt_get_replarea(ra);
        if (!replarea) {
            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
                          "repl_session_plugin_call_post_acquire_cb - Aborted - No replication area\n");
            return 1;
        }
        rc = (*thefunc)(agmt_get_priv(ra), replarea, is_total, data_guid, data);
        slapi_sdn_free(&replarea);
    }

    return rc;
}

int
repl_session_plugin_call_recv_acquire_cb(const char *repl_area, int is_total, const char *data_guid, const struct berval *data)
{
    int rc = 0;

    repl_session_plugin_recv_acquire_cb thefunc =
        (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB]) ? (repl_session_plugin_recv_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_RECV_ACQUIRE_CB] : NULL;

    if (thefunc) {
        rc = (*thefunc)(repl_area, is_total, data_guid, data);
    }

    return rc;
}

int
repl_session_plugin_call_reply_acquire_cb(const char *repl_area, int is_total, char **data_guid, struct berval **data)
{
    int rc = 0;

    repl_session_plugin_reply_acquire_cb thefunc =
        (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB]) ? (repl_session_plugin_reply_acquire_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_REPLY_ACQUIRE_CB] : NULL;

    if (thefunc) {
        rc = (*thefunc)(repl_area, is_total, data_guid, data);
    }

    return rc;
}

void
repl_session_plugin_call_destroy_agmt_cb(const Repl_Agmt *ra)
{
    Slapi_DN *replarea = NULL;

    repl_session_plugin_destroy_agmt_cb thefunc =
        (_ReplSessionAPI && _ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB]) ? (repl_session_plugin_destroy_agmt_cb)_ReplSessionAPI[REPL_SESSION_PLUGIN_DESTROY_AGMT_CB] : NULL;

    if (thefunc) {
        replarea = agmt_get_replarea(ra);
        if (!replarea) {
            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
                          "repl_session_plugin_call_destroy_agmt_cb - Aborted - No replication area\n");
            return;
        }
        (*thefunc)(agmt_get_priv(ra), replarea);
        slapi_sdn_free(&replarea);
    }

    return;
}