]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
d6b4704d32cac7a66e3581c99f2be758749f4e91
[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 void
23 do_abandon(
24     Connection  *conn,
25     Operation   *op
26 )
27 {
28         ber_int_t               id;
29         Operation       *o;
30         Operation       **oo;
31
32         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
33
34         /*
35          * Parse the abandon request.  It looks like this:
36          *
37          *      AbandonRequest := MessageID
38          */
39
40         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
41                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0 ,0 );
42                 return;
43         }
44
45         Debug( LDAP_DEBUG_ARGS, "do_abandon: id %d\n", id, 0 ,0 );
46
47         /*
48          * find the operation being abandoned and set the o_abandon
49          * flag.  It's up to the backend to periodically check this
50          * flag and abort the operation at a convenient time.
51          */
52
53         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
54
55         for ( o = conn->c_ops; o != NULL; o = o->o_next ) {
56                 if ( o->o_msgid == id ) {
57                         ldap_pvt_thread_mutex_lock( &o->o_abandonmutex );
58                         o->o_abandon = 1;
59                         ldap_pvt_thread_mutex_unlock( &o->o_abandonmutex );
60
61                         goto found_it;
62                 }
63         }
64
65         for ( oo = &conn->c_pending_ops;
66                 (*oo != NULL) && ((*oo)->o_msgid != id);
67                 oo = &(*oo)->o_next )
68         {
69                 /* EMPTY */ ;
70         }
71
72         if( *oo != NULL ) {
73                 o = *oo;
74                 *oo = (*oo)->o_next;
75                 slap_op_free( o );
76
77                 goto found_it;
78         }
79
80         Debug( LDAP_DEBUG_TRACE, "do_abandon: op not found\n", 0, 0, 0 );
81
82 found_it:
83         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
84 }