]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/cache-remove.c
Berkeley DB 4.2 support (DB 4.2 required by default)
[openldap] / servers / slapd / back-meta / cache-remove.c
1 /* Copyright (c) 2003 by International Business Machines, Inc.
2  *
3  * International Business Machines, Inc. (hereinafter called IBM) grants
4  * permission under its copyrights to use, copy, modify, and distribute this
5  * Software with or without fee, provided that the above copyright notice and
6  * all paragraphs of this notice appear in all copies, and that the name of IBM
7  * not be used in connection with the marketing of any product incorporating
8  * the Software or modifications thereof, without specific, written prior
9  * permission.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
13  * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
14  * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
15  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
16  * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
17  */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22
23 #include <ac/socket.h>
24 #include <ac/string.h>
25 #include <ac/time.h>
26
27 #include "slap.h"
28 #include "ldif.h"
29 #include "../back-ldap/back-ldap.h"
30 #include "back-meta.h"
31 #include "ldap_pvt.h"
32 #undef ldap_debug       /* silence a warning in ldap-int.h */
33 #include "ldap_log.h"
34 #include "../../../libraries/libldap/ldap-int.h"
35 #include <sys/time.h>
36
37 static int
38 remove_func (
39         Operation       *op,
40         SlapReply       *rs
41 );
42  
43 struct query_info {
44         int                     freed; 
45         int                     deleted; 
46         struct berval*          uuid; 
47         struct timeval          tv; 
48         enum type_of_result     err; 
49 }; 
50    
51 int 
52 remove_query_data (
53         Operation       *op,
54         SlapReply       *rs,
55         struct berval* query_uuid, 
56         struct exception* result)
57 {
58         struct query_info       info; 
59         char                    filter_str[64]; 
60         Operation               op_tmp = *op;
61         Filter                  *filter; 
62         long timediff;
63         SlapReply               sreply = {REP_RESULT}; 
64         slap_callback cb = { remove_func, NULL }; 
65
66         sreply.sr_entry = NULL; 
67         sreply.sr_nentries = 0; 
68         snprintf(filter_str, sizeof(filter_str), "(queryid=%s)",
69                         query_uuid->bv_val);
70         filter = str2filter(filter_str);              
71         info.uuid = query_uuid; 
72         info.freed = 0; 
73         info.deleted = 0; 
74         info.err = SUCCESS; 
75         cb.sc_private = &info; 
76  
77         op_tmp.o_tag = LDAP_REQ_SEARCH;
78         op_tmp.o_protocol = LDAP_VERSION3;
79         op_tmp.o_callback = &cb;
80         op_tmp.o_time = slap_get_time();
81         op_tmp.o_do_not_cache = 1;
82
83         op_tmp.o_req_dn = op->o_bd->be_suffix[0];
84         op_tmp.o_req_ndn = op->o_bd->be_nsuffix[0];
85         op_tmp.ors_scope = LDAP_SCOPE_SUBTREE;
86         op_tmp.ors_deref = LDAP_DEREF_NEVER;
87         op_tmp.ors_slimit = 0;
88         op_tmp.ors_tlimit = 0;
89         op_tmp.ors_filter = filter;
90         op_tmp.ors_filterstr.bv_val = filter_str;
91         op_tmp.ors_filterstr.bv_len = strlen(filter_str);
92         op_tmp.ors_attrs = NULL;
93         op_tmp.ors_attrsonly = 0;
94
95         op->o_bd->be_search( &op_tmp, &sreply );
96
97         result->type = info.err;  
98         result->rc = info.deleted; 
99
100         return info.freed;  
101 }
102
103 static int
104 remove_func (
105         Operation       *op,
106         SlapReply       *rs
107 )
108 {
109         struct query_info       *info = op->o_callback->sc_private;
110         int                     count = 0;
111         int                     size;
112         long                    timediff;
113         Modifications           *mod;
114
115         Attribute               *attr;
116         Operation               op_tmp = *op;
117
118         SlapReply               sreply = {REP_RESULT}; 
119
120         if (rs->sr_type == REP_RESULT) 
121                 return 0; 
122
123         size = get_entry_size(rs->sr_entry, 0, NULL);
124
125         for (attr = rs->sr_entry->e_attrs; attr!= NULL; attr = attr->a_next) {
126                 if (attr->a_desc == slap_schema.si_ad_queryid) {
127                         for (count=0; attr->a_vals[count].bv_val; count++) 
128                                 ;
129                         break; 
130                 }
131         }       
132
133         if (count == 0) {
134                 info->err = REMOVE_ERR; 
135                 return 0; 
136         }
137         if (count == 1) {
138                 info->freed += size; 
139 #ifdef NEW_LOGGING
140                 LDAP_LOG( BACK_META, DETAIL1,
141                                 "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
142                                 size, attr->a_vals[0].bv_val, 0 );
143 #else
144                 Debug( LDAP_DEBUG_ANY, "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
145                                 size, attr->a_vals[0].bv_val, 0 );
146 #endif
147
148                 op_tmp.o_req_dn = rs->sr_entry->e_name;
149                 op_tmp.o_req_ndn = rs->sr_entry->e_nname;
150
151                 if (op->o_bd->be_delete(&op_tmp, rs)) {
152                         info->err = REMOVE_ERR; 
153                 } else {
154                         info->deleted++; 
155                 }
156                 return 0; 
157         }
158
159         mod = (Modifications*)malloc(sizeof(Modifications)); 
160         mod->sml_op = LDAP_MOD_DELETE; 
161         mod->sml_type.bv_len = sizeof("queryid"); 
162         mod->sml_type.bv_val = "queryid"; 
163         mod->sml_desc = slap_schema.si_ad_queryid;   
164         mod->sml_bvalues = (struct berval*) malloc( 2 * sizeof( struct berval) );
165         ber_dupbv(mod->sml_bvalues, info->uuid); 
166         mod->sml_bvalues[1].bv_val = NULL; 
167         mod->sml_bvalues[1].bv_len = 0; 
168         mod->sml_next = NULL; 
169 #ifdef NEW_LOGGING
170         LDAP_LOG( BACK_META, DETAIL1,
171                         "REMOVING TEMP ATTR : TEMPLATE=%s\n",
172                         attr->a_vals[0].bv_val, 0, 0 );
173 #else
174         Debug( LDAP_DEBUG_ANY, "REMOVING TEMP ATTR : TEMPLATE=%s\n",
175                         attr->a_vals[0].bv_val, 0, 0 );
176 #endif
177
178         op_tmp.o_req_dn = rs->sr_entry->e_name;
179         op_tmp.o_req_ndn = rs->sr_entry->e_nname;
180         op_tmp.orm_modlist = mod;
181         
182         if (op->o_bd->be_modify( &op_tmp, &sreply )) {
183                 info->err = REMOVE_ERR;
184         }
185
186         info->freed += LDIF_SIZE_NEEDED(9, (strlen(info->uuid->bv_val))); 
187
188         return 0;
189 }