]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
silence warning
[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( Operation *op, SlapReply *rs )
29 {
30         ber_int_t       id;
31         Operation       *o;
32         int             i;
33
34 #ifdef NEW_LOGGING
35         LDAP_LOG( OPERATION, ENTRY, "conn: %d do_abandon\n", op->o_connid, 0, 0);
36 #else
37         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
38 #endif
39
40         /*
41          * Parse the abandon request.  It looks like this:
42          *
43          *      AbandonRequest := MessageID
44          */
45
46         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
47 #ifdef NEW_LOGGING
48                 LDAP_LOG( OPERATION, ERR, 
49                         "conn: %d do_abandon: ber_scanf failed\n", conn->c_connid, 0, 0 );
50 #else
51                 Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 );
52 #endif
53                 send_ldap_discon( op, rs,
54                         LDAP_PROTOCOL_ERROR, "decoding error" );
55                 return -1;
56         }
57
58         if( get_ctrls( op, rs, 0 ) != LDAP_SUCCESS ) {
59                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
60                 return rs->sr_err;
61         } 
62
63 #ifdef NEW_LOGGING
64         LDAP_LOG( OPERATION, ARGS, "do_abandon: conn: %d  id=%ld\n", 
65                 op->o_connid, (long) id, 0 );
66 #else
67         Debug( LDAP_DEBUG_ARGS, "do_abandon: id=%ld\n", (long) id, 0 ,0 );
68 #endif
69
70         if( id <= 0 ) {
71 #ifdef NEW_LOGGING
72                 LDAP_LOG( OPERATION, ERR, 
73                         "do_abandon: conn: %d bad msgid %ld\n", 
74                         op->o_connid, (long) id, 0 );
75 #else
76                 Debug( LDAP_DEBUG_ANY,
77                         "do_abandon: bad msgid %ld\n", (long) id, 0, 0 );
78 #endif
79                 return LDAP_SUCCESS;
80         }
81
82         ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
83         /*
84          * find the operation being abandoned and set the o_abandon
85          * flag.  It's up to the backend to periodically check this
86          * flag and abort the operation at a convenient time.
87          */
88
89         LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
90                 if ( o->o_msgid == id ) {
91                         o->o_abandon = 1;
92                         goto done;
93                 }
94         }
95
96         LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
97                 if ( o->o_msgid == id ) {
98                         LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops, o, slap_op, o_next );
99                         slap_op_free( o );
100                         goto done;
101                 }
102         }
103
104 done:
105
106         op->orn_msgid = id;
107         for ( i = 0; i < nbackends; i++ ) {
108                 op->o_bd = &backends[i];
109
110                 if( op->o_bd->be_abandon ) op->o_bd->be_abandon( op, rs );
111         }
112
113         ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
114
115 #ifdef NEW_LOGGING
116         LDAP_LOG( OPERATION, ENTRY, 
117                 "do_abandon: conn: %d op=%ld %sfound\n",
118                 op->o_connid, (long)id, o ? "" : "not " );
119 #else
120         Debug( LDAP_DEBUG_TRACE, "do_abandon: op=%ld %sfound\n",
121                 (long) id, o ? "" : "not ", 0 );
122 #endif
123         return LDAP_SUCCESS;
124 }