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