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