]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/cache-remove.c
cleanup bind
[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 #ifdef LDAP_CACHING 
38 static int
39 remove_func (
40         Backend         *be,
41         Connection      *conn,
42         Operation       *op,
43         Entry           *entry,
44         AttributeName   *attrs,
45         int             attrsonly,
46         LDAPControl     **ctrls
47 );
48  
49 struct query_info {
50         int                     freed; 
51         int                     deleted; 
52         struct berval*          uuid; 
53         struct timeval          tv; 
54         enum type_of_result     err; 
55 }; 
56    
57 int 
58 remove_query_data (
59         Backend* be,
60         Connection* conn, 
61         struct berval* query_uuid, 
62         struct exception* result)
63 {
64         struct query_info info; 
65         char filter_str[64]; 
66         Operation op = {0};
67         Filter* filter; 
68         struct timeval time_in; 
69         struct timeval time_out; 
70         long timediff; 
71
72         slap_callback cb = {callback_null_response, 
73                         callback_null_sresult, remove_func, NULL}; 
74         sprintf(filter_str, "(queryid=%s)", query_uuid->bv_val);
75         filter = str2filter(filter_str);              
76         info.uuid = query_uuid; 
77         info.freed = 0; 
78         info.deleted = 0; 
79         info.err = SUCCESS; 
80         cb.sc_private = &info; 
81  
82         op.o_tag = LDAP_REQ_SEARCH;
83         op.o_protocol = LDAP_VERSION3;
84         op.o_ndn = conn->c_ndn;
85         op.o_callback = &cb;
86         op.o_time = slap_get_time();
87         op.o_do_not_cache = 1;
88         op.o_caching_on = 1; 
89         be->be_search( be, conn, &op, NULL, &(be->be_nsuffix[0]),
90                         LDAP_SCOPE_SUBTREE, LDAP_DEREF_NEVER, 0, 0,
91                         filter, NULL, NULL, 0 );
92         result->type = info.err;  
93         result->rc = info.deleted; 
94         return info.freed;  
95 }
96
97 static int
98 remove_func (
99         Backend         *be,
100         Connection      *conn,
101         Operation       *op,
102         Entry           *entry,
103         AttributeName   *attrs,
104         int             attrsonly,
105         LDAPControl     **ctrls
106 )
107 {
108         slap_callback   *tmp = op->o_callback;  
109         struct query_info* info = tmp->sc_private; 
110 #if 0   /* ??? pdn is not used anywhere */
111         struct berval pdn; 
112 #endif
113         int count = 0; 
114         int size; 
115         struct timeval time_in; 
116         struct timeval time_out; 
117         long timediff; 
118         Modifications* mod; 
119
120         Attribute* attr; 
121         size = get_entry_size(entry, 0, NULL);  
122
123         for (attr = entry->e_attrs; attr!= NULL; attr = attr->a_next) {
124                 if (attr->a_desc == slap_schema.si_ad_queryid) {
125                         for (count=0; attr->a_vals[count].bv_val; count++) 
126                                 ;
127                         break; 
128                 }
129         }       
130
131         if (count == 0) {
132                 info->err = REMOVE_ERR; 
133                 return 0; 
134         }
135         if (count == 1) {
136 #if 0   /* ??? pdn is not used anywhere */
137                 dnPretty2(NULL, &entry->e_nname, &pdn);         
138 #endif
139                 info->freed += size; 
140 #ifdef NEW_LOGGING
141                 LDAP_LOG( BACK_META, DETAIL1,
142                                 "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
143                                 size, attr->a_vals[0].bv_val, 0 );
144 #else
145                 Debug( LDAP_DEBUG_ANY, "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
146                                 size, attr->a_vals[0].bv_val, 0 );
147 #endif
148
149                 if (be->be_delete (be, conn, op, &entry->e_name, &entry->e_nname)) {
150                         info->err = REMOVE_ERR; 
151                 } else {
152                         info->deleted++; 
153                 }
154                 return 0; 
155         }
156
157         mod = (Modifications*)malloc(sizeof(Modifications)); 
158         mod->sml_op = LDAP_MOD_DELETE; 
159         mod->sml_type.bv_len = sizeof("queryid"); 
160         mod->sml_type.bv_val = "queryid"; 
161         mod->sml_desc = slap_schema.si_ad_queryid;   
162         mod->sml_bvalues = (struct berval*) malloc( 2 * sizeof( struct berval) );
163         ber_dupbv(mod->sml_bvalues, info->uuid); 
164         mod->sml_bvalues[1].bv_val = NULL; 
165         mod->sml_bvalues[1].bv_len = 0; 
166         mod->sml_next = NULL; 
167 #ifdef NEW_LOGGING
168         LDAP_LOG( BACK_META, DETAIL1,
169                         "REMOVING TEMP ATTR : TEMPLATE=%s\n",
170                         attr->a_vals[0].bv_val, 0, 0 );
171 #else
172         Debug( LDAP_DEBUG_ANY, "REMOVING TEMP ATTR : TEMPLATE=%s\n",
173                         attr->a_vals[0].bv_val, 0, 0 );
174 #endif
175         if (be->be_modify(be, conn, op, &(entry->e_name), &(entry->e_nname), mod)) {
176                 info->err = REMOVE_ERR;
177         }
178         info->freed += LDIF_SIZE_NEEDED(9, (strlen(info->uuid->bv_val))); 
179
180         return 0;
181 }
182
183 #endif /* LDAP_CACHING */