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