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