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