]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
update for new backend types
[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-2005 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
40         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
41
42         /*
43          * Parse the abandon request.  It looks like this:
44          *
45          *      AbandonRequest := MessageID
46          */
47
48         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
49                 Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 );
50                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
51                 return SLAPD_DISCONNECT;
52         }
53
54         if( get_ctrls( op, rs, 0 ) != LDAP_SUCCESS ) {
55                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
56                 return rs->sr_err;
57         } 
58
59         Debug( LDAP_DEBUG_ARGS, "do_abandon: id=%ld\n", (long) id, 0 ,0 );
60
61         if( id <= 0 ) {
62                 Debug( LDAP_DEBUG_ANY,
63                         "do_abandon: bad msgid %ld\n", (long) id, 0, 0 );
64                 return LDAP_SUCCESS;
65         }
66
67         ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
68         /*
69          * find the operation being abandoned and set the o_abandon
70          * flag.  It's up to the backend to periodically check this
71          * flag and abort the operation at a convenient time.
72          */
73
74         LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
75                 if ( o->o_msgid == id ) {
76                         o->o_abandon = 1;
77                         break;
78                 }
79         }
80
81         if ( o ) {
82                 op->orn_msgid = id;
83
84                 op->o_bd = frontendDB;
85                 rs->sr_err = frontendDB->be_abandon( op, rs );
86
87         } else {
88                 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
89                         if ( o->o_msgid == id ) {
90                                 LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops,
91                                         o, slap_op, o_next );
92                                 LDAP_STAILQ_NEXT(o, o_next) = NULL;
93                                 op->o_conn->c_n_ops_pending--;
94                                 slap_op_free( o );
95                                 break;
96                         }
97                 }
98         }
99
100         ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
101
102         Debug( LDAP_DEBUG_TRACE, "do_abandon: op=%ld %sfound\n",
103                 (long) id, o ? "" : "not ", 0 );
104         return rs->sr_err;
105 }
106
107 int
108 fe_op_abandon( Operation *op, SlapReply *rs )
109 {
110         LDAP_STAILQ_FOREACH( op->o_bd, &backendDB, be_next ) {
111                 if ( op->o_bd->be_abandon ) {
112                         (void)op->o_bd->be_abandon( op, rs );
113                 }
114         }
115
116         return LDAP_SUCCESS;
117 }