]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/cache-remove.c
Sync with HEAD
[openldap] / servers / slapd / back-meta / cache-remove.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2003 The OpenLDAP Foundation.
5  * Portions Copyright 2003 IBM Corporation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by the Apurva Kumar for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/socket.h>
26 #include <ac/string.h>
27 #include <ac/time.h>
28
29 #include "slap.h"
30 #include "ldif.h"
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
33 #include "ldap_pvt.h"
34 #undef ldap_debug       /* silence a warning in ldap-int.h */
35 #include "ldap_log.h"
36 #include "../../../libraries/libldap/ldap-int.h"
37 #include <sys/time.h>
38
39 static int
40 remove_func (
41         Operation       *op,
42         SlapReply       *rs
43 );
44  
45 struct query_info {
46         int                     freed; 
47         int                     deleted; 
48         struct berval*          uuid; 
49         struct timeval          tv; 
50         enum type_of_result     err; 
51 }; 
52    
53 int 
54 remove_query_data (
55         Operation       *op,
56         SlapReply       *rs,
57         struct berval* query_uuid, 
58         struct exception* result)
59 {
60         struct query_info       info; 
61         char                    filter_str[64]; 
62         Operation               op_tmp = *op;
63         Filter                  *filter; 
64         long timediff;
65         SlapReply               sreply = {REP_RESULT}; 
66         slap_callback cb = { remove_func, NULL }; 
67
68         sreply.sr_entry = NULL; 
69         sreply.sr_nentries = 0; 
70         snprintf(filter_str, sizeof(filter_str), "(queryid=%s)",
71                         query_uuid->bv_val);
72         filter = str2filter(filter_str);              
73         info.uuid = query_uuid; 
74         info.freed = 0; 
75         info.deleted = 0; 
76         info.err = SUCCESS; 
77         cb.sc_private = &info; 
78  
79         op_tmp.o_tag = LDAP_REQ_SEARCH;
80         op_tmp.o_protocol = LDAP_VERSION3;
81         op_tmp.o_callback = &cb;
82         op_tmp.o_time = slap_get_time();
83         op_tmp.o_do_not_cache = 1;
84
85         op_tmp.o_req_dn = op->o_bd->be_suffix[0];
86         op_tmp.o_req_ndn = op->o_bd->be_nsuffix[0];
87         op_tmp.ors_scope = LDAP_SCOPE_SUBTREE;
88         op_tmp.ors_deref = LDAP_DEREF_NEVER;
89         op_tmp.ors_slimit = 0;
90         op_tmp.ors_tlimit = 0;
91         op_tmp.ors_filter = filter;
92         op_tmp.ors_filterstr.bv_val = filter_str;
93         op_tmp.ors_filterstr.bv_len = strlen(filter_str);
94         op_tmp.ors_attrs = NULL;
95         op_tmp.ors_attrsonly = 0;
96
97         op->o_bd->be_search( &op_tmp, &sreply );
98
99         result->type = info.err;  
100         result->rc = info.deleted; 
101
102         return info.freed;  
103 }
104
105 static int
106 remove_func (
107         Operation       *op,
108         SlapReply       *rs
109 )
110 {
111         struct query_info       *info = op->o_callback->sc_private;
112         int                     count = 0;
113         int                     size;
114         long                    timediff;
115         Modifications           *mod;
116
117         Attribute               *attr;
118         Operation               op_tmp = *op;
119
120         SlapReply               sreply = {REP_RESULT}; 
121
122         if (rs->sr_type == REP_RESULT) 
123                 return 0; 
124
125         size = get_entry_size(rs->sr_entry, 0, NULL);
126
127         for (attr = rs->sr_entry->e_attrs; attr!= NULL; attr = attr->a_next) {
128                 if (attr->a_desc == slap_schema.si_ad_queryid) {
129                         for (count=0; attr->a_vals[count].bv_val; count++) 
130                                 ;
131                         break; 
132                 }
133         }       
134
135         if (count == 0) {
136                 info->err = REMOVE_ERR; 
137                 return 0; 
138         }
139         if (count == 1) {
140                 info->freed += size; 
141 #ifdef NEW_LOGGING
142                 LDAP_LOG( BACK_META, DETAIL1,
143                                 "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
144                                 size, attr->a_vals[0].bv_val, 0 );
145 #else
146                 Debug( LDAP_DEBUG_ANY, "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
147                                 size, attr->a_vals[0].bv_val, 0 );
148 #endif
149
150                 op_tmp.o_req_dn = rs->sr_entry->e_name;
151                 op_tmp.o_req_ndn = rs->sr_entry->e_nname;
152
153                 if (op->o_bd->be_delete(&op_tmp, rs)) {
154                         info->err = REMOVE_ERR; 
155                 } else {
156                         info->deleted++; 
157                 }
158                 return 0; 
159         }
160
161         mod = (Modifications*)malloc(sizeof(Modifications)); 
162         mod->sml_op = LDAP_MOD_DELETE; 
163         mod->sml_type.bv_len = sizeof("queryid"); 
164         mod->sml_type.bv_val = "queryid"; 
165         mod->sml_desc = slap_schema.si_ad_queryid;   
166         mod->sml_bvalues = (struct berval*) malloc( 2 * sizeof( struct berval) );
167         ber_dupbv(mod->sml_bvalues, info->uuid); 
168         mod->sml_bvalues[1].bv_val = NULL; 
169         mod->sml_bvalues[1].bv_len = 0; 
170         mod->sml_next = NULL; 
171 #ifdef NEW_LOGGING
172         LDAP_LOG( BACK_META, DETAIL1,
173                         "REMOVING TEMP ATTR : TEMPLATE=%s\n",
174                         attr->a_vals[0].bv_val, 0, 0 );
175 #else
176         Debug( LDAP_DEBUG_ANY, "REMOVING TEMP ATTR : TEMPLATE=%s\n",
177                         attr->a_vals[0].bv_val, 0, 0 );
178 #endif
179
180         op_tmp.o_req_dn = rs->sr_entry->e_name;
181         op_tmp.o_req_ndn = rs->sr_entry->e_nname;
182         op_tmp.orm_modlist = mod;
183         
184         if (op->o_bd->be_modify( &op_tmp, &sreply )) {
185                 info->err = REMOVE_ERR;
186         }
187
188         info->freed += LDIF_SIZE_NEEDED(9, (strlen(info->uuid->bv_val))); 
189
190         return 0;
191 }