]> git.sur5r.net Git - openldap/blob - servers/slapd/sessionlog.c
Updated notices
[openldap] / servers / slapd / sessionlog.c
1 /* sessionlog.c -- Session History Management Routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003 The OpenLDAP Foundation.
6  * Portions Copyright 2003 IBM Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "ldap_pvt.h"
26 #include "lutil.h"
27 #include "slap.h"
28 #include "lutil_ldap.h"
29
30 int
31 slap_send_session_log(
32         Operation *op,
33         Operation *sop,
34         SlapReply *rs
35 )
36 {
37         Entry e;
38         AttributeName   uuid_attr[2];
39         LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
40         int             num_ctrls = 0;
41         struct slog_entry *slog_e;
42         int             result;
43         int             match;
44         const   char    *text;
45
46         uuid_attr[0].an_desc = NULL;
47         uuid_attr[0].an_oc = NULL;
48         uuid_attr[0].an_name.bv_len = 0;
49         uuid_attr[0].an_name.bv_val = NULL;
50         e.e_attrs = NULL;
51         e.e_id = 0;
52         e.e_name.bv_val = NULL;
53         e.e_name.bv_len = 0;
54         e.e_nname.bv_val = NULL;
55         e.e_nname.bv_len = 0;
56
57         for( num_ctrls = 0;
58                  num_ctrls < SLAP_MAX_RESPONSE_CONTROLS;
59                  num_ctrls++ ) {
60                 ctrls[num_ctrls] = NULL;
61         }
62         num_ctrls = 0;
63
64         LDAP_STAILQ_FOREACH( slog_e, &sop->o_sync_slog_list, sl_link ) {
65
66                 if ( op->o_sync_state.ctxcsn->bv_val == NULL ) {
67                         match = 1;
68                 } else {
69                         value_match( &match, slap_schema.si_ad_entryCSN,
70                                                 slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
71                                                 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
72                                                 op->o_sync_state.ctxcsn, &slog_e->sl_csn, &text );
73                 }
74
75                 if ( match < 0 ) {
76                         rs->sr_err = slap_build_sync_state_ctrl_from_slog( op, rs, slog_e,
77                                                         LDAP_SYNC_DELETE, ctrls, num_ctrls++, 0, NULL );
78
79                         if ( rs->sr_err != LDAP_SUCCESS )
80                                 return rs->sr_err;
81
82                         if ( e.e_name.bv_val )
83                                 ch_free( e.e_name.bv_val );
84                         ber_dupbv( &e.e_name, &slog_e->sl_name );
85
86                         rs->sr_entry = &e;
87                         rs->sr_attrs = uuid_attr;
88                         rs->sr_ctrls = ctrls;
89                         result = send_search_entry( op, rs );
90                         sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val, op->o_tmpmemctx );
91                         sl_free( ctrls[--num_ctrls], op->o_tmpmemctx );
92                         ctrls[num_ctrls] = NULL;
93                         rs->sr_ctrls = NULL;
94                 }
95         }
96 }
97
98 int
99 slap_add_session_log(
100         Operation *op,
101         Operation *sop,
102         Entry *e
103 )
104 {
105         struct slog_entry* slog_e;
106         Attribute *a;
107
108         slog_e = (struct slog_entry *) ch_calloc (1, sizeof( struct slog_entry ));
109         a = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
110         ber_dupbv( &slog_e->sl_uuid, &a->a_nvals[0] );
111         ber_dupbv( &slog_e->sl_name, &e->e_name );
112         ber_dupbv( &slog_e->sl_csn,  &op->o_sync_csn );
113         LDAP_STAILQ_INSERT_TAIL( &sop->o_sync_slog_list, slog_e, sl_link );
114         sop->o_sync_slog_len++;
115
116         while ( sop->o_sync_slog_len > sop->o_sync_slog_size ) {
117                 slog_e = LDAP_STAILQ_FIRST( &sop->o_sync_slog_list );
118                 if ( sop->o_sync_slog_omitcsn.bv_val ) {
119                         ch_free( sop->o_sync_slog_omitcsn.bv_val );
120                 }
121                 ber_dupbv( &sop->o_sync_slog_omitcsn, &slog_e->sl_csn );
122                 LDAP_STAILQ_REMOVE_HEAD( &sop->o_sync_slog_list, sl_link );
123                 ch_free( slog_e->sl_uuid.bv_val );
124                 ch_free( slog_e->sl_name.bv_val );
125                 ch_free( slog_e->sl_csn.bv_val );
126                 ch_free( slog_e );
127                 sop->o_sync_slog_len--;
128         }
129
130         return LDAP_SUCCESS;
131 }