]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
LCUP persistent search code drop
[openldap] / servers / slapd / abandon.c
1 /* abandon.c - decode and handle an ldap abandon operation */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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 #ifdef LDAP_CLIENT_UPDATE
37         int             i;
38 #endif
39
40 #ifdef NEW_LOGGING
41         LDAP_LOG( OPERATION, ENTRY, "conn: %d do_abandon\n", conn->c_connid, 0, 0);
42 #else
43         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
44 #endif
45
46         /*
47          * Parse the abandon request.  It looks like this:
48          *
49          *      AbandonRequest := MessageID
50          */
51
52         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
53 #ifdef NEW_LOGGING
54                 LDAP_LOG( OPERATION, ERR, 
55                         "conn: %d do_abandon: ber_scanf failed\n", conn->c_connid, 0, 0 );
56 #else
57                 Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 );
58 #endif
59                 send_ldap_disconnect( conn, op,
60                         LDAP_PROTOCOL_ERROR, "decoding error" );
61                 return -1;
62         }
63
64         if( (rc = get_ctrls( conn, op, 0 )) != LDAP_SUCCESS ) {
65                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
66                 return rc;
67         } 
68
69 #ifdef NEW_LOGGING
70         LDAP_LOG( OPERATION, ARGS, "do_abandon: conn: %d  id=%ld\n", 
71                 conn->c_connid, (long) id, 0 );
72 #else
73         Debug( LDAP_DEBUG_ARGS, "do_abandon: id=%ld\n", (long) id, 0 ,0 );
74 #endif
75
76         if( id <= 0 ) {
77 #ifdef NEW_LOGGING
78                 LDAP_LOG( OPERATION, ERR, 
79                         "do_abandon: conn: %d bad msgid %ld\n", 
80                         conn->c_connid, (long) id, 0 );
81 #else
82                 Debug( LDAP_DEBUG_ANY,
83                         "do_abandon: bad msgid %ld\n", (long) id, 0, 0 );
84 #endif
85                 return LDAP_SUCCESS;
86         }
87
88         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
89         /*
90          * find the operation being abandoned and set the o_abandon
91          * flag.  It's up to the backend to periodically check this
92          * flag and abort the operation at a convenient time.
93          */
94
95         LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) {
96                 if ( o->o_msgid == id ) {
97                         o->o_abandon = 1;
98                         goto done;
99                 }
100         }
101
102         LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) {
103                 if ( o->o_msgid == id ) {
104                         LDAP_STAILQ_REMOVE( &conn->c_pending_ops, o, slap_op, o_next );
105                         slap_op_free( o );
106                         goto done;
107                 }
108         }
109
110 done:
111
112 #if LDAP_CLIENT_UPDATE
113         for ( i = 0; i < nbackends; i++ ) {
114                 if ( strncmp( backends[i].be_type, "bdb", 3 ) ) continue;
115                 if ( bdb_abandon( &backends[i], conn, id ) == LDAP_SUCCESS ) {
116                         break;
117                 }
118         }
119 #endif
120
121         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
122
123 #ifdef NEW_LOGGING
124         LDAP_LOG( OPERATION, ENTRY, 
125                 "do_abandon: conn: %d op=%ld %sfound\n",
126                 conn->c_connid, (long)id, o ? "" : "not " );
127 #else
128         Debug( LDAP_DEBUG_TRACE, "do_abandon: op=%ld %sfound\n",
129                 (long) id, o ? "" : "not ", 0 );
130 #endif
131         return LDAP_SUCCESS;
132 }