2 /* cancel.c - LDAP cancel extended operation */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
19 #ifdef LDAP_EXOP_X_CANCEL
28 struct berval *reqdata,
30 struct berval **rspdata,
31 LDAPControl ***rspctrls,
42 assert( reqoid != NULL );
43 assert( strcmp( LDAP_EXOP_X_CANCEL, reqoid ) == 0 );
45 if ( reqdata == NULL ) {
46 *text = "no message ID supplied";
47 return LDAP_PROTOCOL_ERROR;
50 ber = ber_init( reqdata );
52 *text = "internal error";
56 if ( ber_scanf( ber, "{i}", &opid ) == LBER_ERROR ) {
57 *text = "message ID parse failed";
58 return LDAP_PROTOCOL_ERROR;
61 (void) ber_free( ber, 1 );
64 *text = "message ID invalid";
65 return LDAP_PROTOCOL_ERROR;
68 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
69 LDAP_STAILQ_FOREACH( op, &conn->c_pending_ops, o_next ) {
70 if ( op->o_msgid == opid ) {
71 LDAP_STAILQ_REMOVE( &conn->c_pending_ops, op, slap_op, o_next );
77 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
79 if ( found ) return LDAP_SUCCESS;
82 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
83 LDAP_STAILQ_FOREACH( op, &conn->c_ops, o_next ) {
84 if ( op->o_msgid == opid ) {
92 for ( i = 0; i < nbackends; i++ ) {
93 Backend *be = &backends[i];
94 if( !be->be_abandon ) continue;
97 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
99 if ( be->be_cancel( be, conn, op, opid ) == LDAP_SUCCESS ) {
102 *text = "message ID not found";
103 return LDAP_NO_SUCH_OPERATION;
107 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
108 *text = "message ID not found";
109 return LDAP_NO_SUCH_OPERATION;
113 if ( op->o_cancel != SLAP_CANCEL_NONE ) {
114 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
115 *text = "message ID already being cancelled";
116 return LDAP_PROTOCOL_ERROR;
119 op->o_cancel = SLAP_CANCEL_REQ;
120 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
122 while ( op->o_cancel == SLAP_CANCEL_REQ ) {
123 ldap_pvt_thread_yield();
126 if ( op->o_cancel == SLAP_CANCEL_ACK ) {
132 op->o_cancel = SLAP_CANCEL_DONE;
137 #endif /* LDAP_EXOP_X_CANCEL */