]> git.sur5r.net Git - openldap/blob - servers/slapd/abandon.c
more new logging (finally), behind NEW_LOGGING
[openldap] / servers / slapd / abandon.c
1 /* abandon.c - decode and handle an ldap abandon operation */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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 #ifdef NEW_LOGGING
39         LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY, "conn: %d do_abandon\n", conn->c_connid));
40 #else
41         Debug( LDAP_DEBUG_TRACE, "do_abandon\n", 0, 0, 0 );
42 #endif
43
44         /*
45          * Parse the abandon request.  It looks like this:
46          *
47          *      AbandonRequest := MessageID
48          */
49
50         if ( ber_scanf( op->o_ber, "i", &id ) == LBER_ERROR ) {
51 #ifdef NEW_LOGGING
52             LDAP_LOG(( "operation", LDAP_LEVEL_ERR, 
53                        "conn: %d do_abandon: ber_scanf failed\n",
54                        conn->c_connid ));
55 #else
56                 Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 );
57 #endif
58                 send_ldap_disconnect( conn, op,
59                         LDAP_PROTOCOL_ERROR, "decoding error" );
60                 return -1;
61         }
62
63         if( (rc = get_ctrls( conn, op, 0 )) != LDAP_SUCCESS ) {
64                 Debug( LDAP_DEBUG_ANY, "do_abandon: get_ctrls failed\n", 0, 0 ,0 );
65                 return rc;
66         } 
67
68 #ifdef NEW_LOGGING
69         LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
70                    "do_abandon: conn: %d  id=%ld\n", conn->c_connid, (long) id ));
71 #else
72         Debug( LDAP_DEBUG_ARGS, "do_abandon: id=%ld\n", (long) id, 0 ,0 );
73 #endif
74
75         if( id <= 0 ) {
76 #ifdef NEW_LOGGING
77             LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
78                        "do_abandon: conn: %d bad msgid %ld\n", conn->c_connid, (long) id ));
79 #else
80                 Debug( LDAP_DEBUG_ANY,
81                         "do_abandon: bad msgid %ld\n", (long) id, 0, 0 );
82 #endif
83                 return LDAP_SUCCESS;
84         }
85
86         notfound = 1; /* not found */
87         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
88         /*
89          * find the operation being abandoned and set the o_abandon
90          * flag.  It's up to the backend to periodically check this
91          * flag and abort the operation at a convenient time.
92          */
93
94         for ( o = conn->c_ops; o != NULL; o = o->o_next ) {
95                 if ( o->o_msgid == id ) {
96                         ldap_pvt_thread_mutex_lock( &o->o_abandonmutex );
97                         o->o_abandon = 1;
98                         ldap_pvt_thread_mutex_unlock( &o->o_abandonmutex );
99
100                         notfound = 0;
101                         goto done;
102                 }
103         }
104
105         for ( oo = &conn->c_pending_ops;
106                 (*oo != NULL) && ((*oo)->o_msgid != id);
107                 oo = &(*oo)->o_next )
108         {
109                 /* EMPTY */ ;
110         }
111
112         if( *oo != NULL ) {
113                 o = *oo;
114                 *oo = (*oo)->o_next;
115                 slap_op_free( o );
116                 notfound = 0;
117         }
118
119 done:
120         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
121
122 #ifdef NEW_LOGGING
123         LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
124                    "do_abandon: conn: %d op=%ld %sfound\n",
125                    conn->c_connid, (long)id, notfound ? "not " : "" ));
126 #else
127         Debug( LDAP_DEBUG_TRACE, "do_abandon: op=%ld %sfound\n",
128                (long) id, notfound ? "not " : "", 0 );
129 #endif
130         return LDAP_SUCCESS;
131 }