132
* Function: handle_getchangerecord_result
132
* Function: handle_getchangetime_result
133
133
* Arguments: op - pointer to Operation struct for this operation
134
134
* err - error code returned from search
135
135
* Returns: nothing
136
* Description: result handler for get_changerecord(). Sets the crt_err
136
* Description: result handler for get_changetime(). Sets the crt_err
137
137
* field of the cnum_result_t struct to the error returned
138
138
* from the backend.
141
handle_getchangerecord_result( int err, void *callback_data )
141
handle_getchangetime_result( int err, void *callback_data )
143
143
cnum_result_t *crt = callback_data;
145
145
if ( crt == NULL ) {
146
146
slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
147
"handle_getchangerecord_result: callback_data NULL\n" );
147
"handle_getchangetime_result: callback_data NULL\n" );
149
149
crt->crt_err = err;
154
* Function: handle_getchangerecord_search
154
* Function: handle_getchangetime_search
155
155
* Arguments: op - pointer to Operation struct for this operation
156
156
* e - entry returned by backend
157
157
* Returns: 0 in all cases
158
* Description: Search result operation handler for get_changerecord().
158
* Description: Search result operation handler for get_changetime().
159
159
* Sets fields in the cnum_result_t struct pointed to by
160
160
* op->o_handler_data.
163
handle_getchangerecord_search( Slapi_Entry *e, void *callback_data)
163
handle_getchangetime_search( Slapi_Entry *e, void *callback_data)
165
165
cnum_result_t *crt = callback_data;
168
slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
169
"handle_getchangerecord_search: op->o_handler_data NULL\n" );
170
} else if ( crt->crt_nentries > 0 ) {
171
/* only return the first entry, I guess */
172
slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
173
"handle_getchangerecord_search: multiple entries returned\n" );
170
slapi_log_error(SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
171
"handle_getchangetime_search: op->o_handler_data NULL\n");
172
} else if (crt->crt_nentries > 0) {
173
/* only return the first entry, I guess */
174
slapi_log_error(SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
175
"handle_getchangetime_search: multiple entries returned\n");
181
Slapi_Value *sval = NULL;
182
const struct berval *val = NULL;
183
rc = slapi_entry_attr_find(e, attr_changetime, &attr);
184
/* Bug 624442: Logic checking for lack of timestamp was
186
if (0 != rc || slapi_attr_first_value(attr, &sval) == -1 ||
187
(val = slapi_value_get_berval(sval)) == NULL ||
188
NULL == val->bv_val) {
191
crt->crt_time = parse_localTime(val->bv_val);
184
* Function: get_changerecord
201
* Function: get_changetime
185
202
* Arguments: cnum - number of change record to retrieve
186
* Returns: Pointer to an entry structure. The caller must free the entry.
187
* If "err" is non-NULL, an error code is returned in the memory
188
* location it points to.
189
* Description: Retrieve the change record entry whose number is "cnum".
203
* Returns: Taking the attr_changetime of the 'cnum' entry,
204
* it converts it into time_t (parse_localTime) and returns this time value.
205
* It returns 0 in the following cases:
206
* - changerecord entry has not attr_changetime
207
* - attr_changetime attribute has no value
208
* - attr_changetime attribute value is empty
210
* Description: Retrieve attr_changetime ("changetime") from a changerecord whose number is "cnum".
191
static Slapi_Entry *get_changerecord( changeNumber cnum, int *err )
212
static time_t get_changetime( changeNumber cnum, int *err )
193
cnum_result_t crt, *crtp = &crt;
194
char fstr[ 16 + CNUMSTR_LEN + 2 ];
214
cnum_result_t crt, *crtp = &crt;
215
char fstr[ 16 + CNUMSTR_LEN + 2 ];
195
216
Slapi_PBlock *pb;
199
*err = LDAP_PARAM_ERROR;
203
crtp->crt_nentries = crtp->crt_err = 0; crtp->crt_entry = NULL;
204
PR_snprintf( fstr, sizeof(fstr), "%s=%ld", attr_changenumber, cnum );
206
pb = slapi_pblock_new ();
207
slapi_search_internal_set_pb (pb, RETROCL_CHANGELOG_DN,
208
LDAP_SCOPE_SUBTREE, fstr,
209
(char **)get_cleattrs(), /* cast const */
211
NULL /* controls */, NULL /* uniqueid */,
212
g_plg_identity[PLUGIN_RETROCL],
215
slapi_search_internal_callback_pb (pb, crtp,
216
handle_getchangerecord_result,
217
handle_getchangerecord_search, NULL );
219
*err = crtp->crt_err;
222
slapi_pblock_destroy (pb);
224
return( crtp->crt_entry );
220
*err = LDAP_PARAM_ERROR;
224
crtp->crt_nentries = crtp->crt_err = 0;
226
PR_snprintf(fstr, sizeof (fstr), "%s=%ld", attr_changenumber, cnum);
228
pb = slapi_pblock_new();
229
slapi_search_internal_set_pb(pb, RETROCL_CHANGELOG_DN,
230
LDAP_SCOPE_SUBTREE, fstr,
231
(char **) get_cleattrs(), /* cast const */
233
NULL /* controls */, NULL /* uniqueid */,
234
g_plg_identity[PLUGIN_RETROCL],
237
slapi_search_internal_callback_pb(pb, crtp,
238
handle_getchangetime_result,
239
handle_getchangetime_search, NULL);
241
*err = crtp->crt_err;
244
slapi_pblock_destroy(pb);
246
return ( crtp->crt_time);
283
e = get_changerecord( first_in_log, &ldrc );
285
Slapi_Value *sval = NULL;
286
const struct berval *val = NULL;
287
rc = slapi_entry_attr_find( e, attr_changetime, &attr );
288
/* Bug 624442: Logic checking for lack of timestamp was
290
if ( 0 != rc || slapi_attr_first_value( attr,&sval ) == -1 ||
291
(val = slapi_value_get_berval ( sval )) == NULL ||
292
NULL == val->bv_val ) {
293
/* What to do if there's no timestamp? Just delete it. */
294
retrocl_set_first_changenumber( first_in_log + 1 );
295
ldrc = delete_changerecord( first_in_log );
299
time_t change_time = parse_localTime( val->bv_val );
300
if ( change_time + me < now ) {
301
retrocl_set_first_changenumber( first_in_log + 1 );
302
ldrc = delete_changerecord( first_in_log );
306
/* slapi_entry_free( e ); */ /* XXXggood should we be freeing this? */
303
time_t change_time = get_changetime(first_in_log, &ldrc);
305
if ((change_time + me) < now) {
306
retrocl_set_first_changenumber(first_in_log + 1);
307
ldrc = delete_changerecord(first_in_log);
312
/* What to do if there's no timestamp? Just delete it. */
313
retrocl_set_first_changenumber(first_in_log + 1);
314
ldrc = delete_changerecord(first_in_log);
310
319
if ( !did_delete ) {