]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
b8c3438576d1ed163a4f1bbd2e044b046f84da0d
[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;
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                 return LDAP_PROTOCOL_ERROR;
44         }
45
46 #ifdef GET_CTRLS
47         if( (rc = get_ctrls( conn, op, 0 )) != LDAP_SUCCESS ) {
48                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
49                 return rc;
50         } 
51 #endif
52
53         Debug( LDAP_DEBUG_ARGS, "do_abandon: id %d\n", id, 0 ,0 );
54
55         /*
56          * find the operation being abandoned and set the o_abandon
57          * flag.  It's up to the backend to periodically check this
58          * flag and abort the operation at a convenient time.
59          */
60
61         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
62
63         for ( o = conn->c_ops; o != NULL; o = o->o_next ) {
64                 if ( o->o_msgid == id ) {
65                         ldap_pvt_thread_mutex_lock( &o->o_abandonmutex );
66                         o->o_abandon = 1;
67                         ldap_pvt_thread_mutex_unlock( &o->o_abandonmutex );
68
69                         goto found_it;
70                 }
71         }
72
73         for ( oo = &conn->c_pending_ops;
74                 (*oo != NULL) && ((*oo)->o_msgid != id);
75                 oo = &(*oo)->o_next )
76         {
77                 /* EMPTY */ ;
78         }
79
80         if( *oo != NULL ) {
81                 o = *oo;
82                 *oo = (*oo)->o_next;
83                 slap_op_free( o );
84
85                 goto found_it;
86         }
87
88         Debug( LDAP_DEBUG_TRACE, "do_abandon: op not found\n", 0, 0, 0 );
89
90 found_it:
91         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
92         return LDAP_SUCCESS;
93 }