1 /* sessionlog.c -- Session History Management Routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2003 IBM Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
27 #include "lutil_ldap.h"
31 slap_send_session_log(
38 AttributeName uuid_attr[2];
39 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
41 struct slog_entry *slog_e;
46 uuid_attr[0].an_desc = NULL;
47 uuid_attr[0].an_oc = NULL;
48 uuid_attr[0].an_oc_exclude = 0;
49 uuid_attr[0].an_name.bv_len = 0;
50 uuid_attr[0].an_name.bv_val = NULL;
53 e.e_name.bv_val = NULL;
55 e.e_nname.bv_val = NULL;
59 num_ctrls < SLAP_MAX_RESPONSE_CONTROLS;
61 ctrls[num_ctrls] = NULL;
65 LDAP_STAILQ_FOREACH( slog_e, &sop->o_sync_slog_list, sl_link ) {
67 if ( op->o_sync_state.ctxcsn->bv_val == NULL ) {
70 value_match( &match, slap_schema.si_ad_entryCSN,
71 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
72 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
73 op->o_sync_state.ctxcsn, &slog_e->sl_csn, &text );
77 rs->sr_err = slap_build_sync_state_ctrl_from_slog( op, rs, slog_e,
78 LDAP_SYNC_DELETE, ctrls, num_ctrls++, 0, NULL );
80 if ( rs->sr_err != LDAP_SUCCESS )
83 if ( e.e_name.bv_val )
84 ch_free( e.e_name.bv_val );
85 ber_dupbv( &e.e_name, &slog_e->sl_name );
88 rs->sr_attrs = uuid_attr;
91 result = send_search_entry( op, rs );
92 slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val, op->o_tmpmemctx );
93 slap_sl_free( ctrls[--num_ctrls], op->o_tmpmemctx );
94 ctrls[num_ctrls] = NULL;
102 slap_add_session_log(
108 struct slog_entry* slog_e;
111 slog_e = (struct slog_entry *) ch_calloc (1, sizeof( struct slog_entry ));
112 a = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
113 ber_dupbv( &slog_e->sl_uuid, &a->a_nvals[0] );
114 ber_dupbv( &slog_e->sl_name, &e->e_name );
115 ber_dupbv( &slog_e->sl_csn, &op->o_sync_csn );
116 LDAP_STAILQ_INSERT_TAIL( &sop->o_sync_slog_list, slog_e, sl_link );
117 sop->o_sync_slog_len++;
119 while ( sop->o_sync_slog_len > sop->o_sync_slog_size ) {
120 slog_e = LDAP_STAILQ_FIRST( &sop->o_sync_slog_list );
121 if ( sop->o_sync_slog_omitcsn.bv_val ) {
122 ch_free( sop->o_sync_slog_omitcsn.bv_val );
124 ber_dupbv( &sop->o_sync_slog_omitcsn, &slog_e->sl_csn );
125 LDAP_STAILQ_REMOVE_HEAD( &sop->o_sync_slog_list, sl_link );
126 ch_free( slog_e->sl_uuid.bv_val );
127 ch_free( slog_e->sl_name.bv_val );
128 ch_free( slog_e->sl_csn.bv_val );
130 sop->o_sync_slog_len--;