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
24 int cancel_extop( Operation *op, SlapReply *rs )
33 assert( ber_bvcmp( &slap_EXOP_CANCEL, &op->ore_reqoid ) == 0 );
35 if ( op->ore_reqdata == NULL ) {
36 rs->sr_text = "no message ID supplied";
37 return LDAP_PROTOCOL_ERROR;
40 ber = ber_init( op->ore_reqdata );
42 rs->sr_text = "internal error";
46 if ( ber_scanf( ber, "{i}", &opid ) == LBER_ERROR ) {
47 rs->sr_text = "message ID parse failed";
48 return LDAP_PROTOCOL_ERROR;
51 (void) ber_free( ber, 1 );
54 rs->sr_text = "message ID invalid";
55 return LDAP_PROTOCOL_ERROR;
58 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
59 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
60 if ( o->o_msgid == opid ) {
61 LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops, o, slap_op, o_next );
67 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
69 if ( found ) return LDAP_SUCCESS;
72 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
73 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
74 if ( o->o_msgid == opid ) {
81 for ( i = 0; i < nbackends; i++ ) {
82 op->o_bd = &backends[i];
83 if( !op->o_bd->be_cancel ) continue;
85 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
87 op->oq_cancel.rs_msgid = opid;
88 if ( op->o_bd->be_cancel( op, rs ) == LDAP_SUCCESS ) {
91 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
93 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
94 rs->sr_text = "message ID not found";
95 return LDAP_NO_SUCH_OPERATION;
98 if ( op->o_cancel != SLAP_CANCEL_NONE ) {
99 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
100 rs->sr_text = "message ID already being cancelled";
101 return LDAP_PROTOCOL_ERROR;
104 op->o_cancel = SLAP_CANCEL_REQ;
105 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
107 while ( op->o_cancel == SLAP_CANCEL_REQ ) {
108 ldap_pvt_thread_yield();
111 if ( op->o_cancel == SLAP_CANCEL_ACK ) {
117 op->o_cancel = SLAP_CANCEL_DONE;
122 #endif /* LDAP_EXOP_X_CANCEL */