]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
ITS#2368 - fix deleting key from range IDL
[openldap] / servers / slapd / abandon.c
1 /* abandon.c - decode and handle an ldap abandon operation */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 /*
9  * Copyright (c) 1995 Regents of the University of Michigan.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms are permitted
13  * provided that this notice is preserved and that due credit is given
14  * to the University of Michigan at Ann Arbor. The name of the University
15  * may not be used to endorse or promote products derived from this
16  * software without specific prior written permission. This software
17  * is provided ``as is'' without express or implied warranty.
18  */
19
20 #include "portable.h"
21
22 #include <stdio.h>
23 #include <ac/socket.h>
24
25 #include "slap.h"
26
27 int
28 do_abandon(
29     Connection  *conn,
30     Operation   *op
31 )
32 {
33         ber_int_t       id;
34         Operation       *o;
35         int             rc;
36         int             i;
37
38 #ifdef NEW_LOGGING
39         LDAP_LOG( OPERATION, ENTRY, "conn: %d do_abandon\n", conn->c_connid, 0, 0);
40 #else
41         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
42 #endif
43
44         /*
45          * Parse the abandon request.  It looks like this:
46          *
47          *      AbandonRequest := MessageID
48          */
49
50         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
51 #ifdef NEW_LOGGING
52                 LDAP_LOG( OPERATION, ERR, 
53                         "conn: %d do_abandon: ber_scanf failed\n", conn->c_connid, 0, 0 );
54 #else
55                 Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 );
56 #endif
57                 send_ldap_disconnect( conn, op,
58                         LDAP_PROTOCOL_ERROR, "decoding error" );
59                 return -1;
60         }
61
62         if( (rc = get_ctrls( conn, op, 0 )) != LDAP_SUCCESS ) {
63                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
64                 return rc;
65         } 
66
67 #ifdef NEW_LOGGING
68         LDAP_LOG( OPERATION, ARGS, "do_abandon: conn: %d  id=%ld\n", 
69                 conn->c_connid, (long) id, 0 );
70 #else
71         Debug( LDAP_DEBUG_ARGS, "do_abandon: id=%ld\n", (long) id, 0 ,0 );
72 #endif
73
74         if( id <= 0 ) {
75 #ifdef NEW_LOGGING
76                 LDAP_LOG( OPERATION, ERR, 
77                         "do_abandon: conn: %d bad msgid %ld\n", 
78                         conn->c_connid, (long) id, 0 );
79 #else
80                 Debug( LDAP_DEBUG_ANY,
81                         "do_abandon: bad msgid %ld\n", (long) id, 0, 0 );
82 #endif
83                 return LDAP_SUCCESS;
84         }
85
86         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
87         /*
88          * find the operation being abandoned and set the o_abandon
89          * flag.  It's up to the backend to periodically check this
90          * flag and abort the operation at a convenient time.
91          */
92
93         LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) {
94                 if ( o->o_msgid == id ) {
95                         o->o_abandon = 1;
96                         goto done;
97                 }
98         }
99
100         LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) {
101                 if ( o->o_msgid == id ) {
102                         LDAP_STAILQ_REMOVE( &conn->c_pending_ops, o, slap_op, o_next );
103                         slap_op_free( o );
104                         goto done;
105                 }
106         }
107
108 done:
109
110         for ( i = 0; i < nbackends; i++ ) {
111                 Backend *be = &backends[i];
112
113                 if( be->be_abandon ) be->be_abandon( be, conn, op, id );
114         }
115
116         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
117
118 #ifdef NEW_LOGGING
119         LDAP_LOG( OPERATION, ENTRY, 
120                 "do_abandon: conn: %d op=%ld %sfound\n",
121                 conn->c_connid, (long)id, o ? "" : "not " );
122 #else
123         Debug( LDAP_DEBUG_TRACE, "do_abandon: op=%ld %sfound\n",
124                 (long) id, o ? "" : "not ", 0 );
125 #endif
126         return LDAP_SUCCESS;
127 }