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