1 /* cancel.c - LDAP cancel extended operation */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/socket.h>
23 #include <ac/string.h>
24 #include <ac/unistd.h>
31 int cancel_extop( Operation *op, SlapReply *rs )
40 assert( ber_bvcmp( &slap_EXOP_CANCEL, &op->ore_reqoid ) == 0 );
42 if ( op->ore_reqdata == NULL ) {
43 rs->sr_text = "no message ID supplied";
44 return LDAP_PROTOCOL_ERROR;
47 ber = ber_init( op->ore_reqdata );
49 rs->sr_text = "internal error";
53 if ( ber_scanf( ber, "{i}", &opid ) == LBER_ERROR ) {
54 rs->sr_text = "message ID parse failed";
55 return LDAP_PROTOCOL_ERROR;
58 (void) ber_free( ber, 1 );
61 rs->sr_text = "message ID invalid";
62 return LDAP_PROTOCOL_ERROR;
65 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
66 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
67 if ( o->o_msgid == opid ) {
68 LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops, o, slap_op, o_next );
69 LDAP_STAILQ_NEXT(o, o_next) = NULL;
70 op->o_conn->c_n_ops_pending--;
76 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
78 if ( found ) return LDAP_SUCCESS;
81 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
82 LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
83 if ( o->o_msgid == opid ) {
90 for ( i = 0; i < nbackends; i++ ) {
91 op->o_bd = &backends[i];
92 if( !op->o_bd->be_cancel ) continue;
94 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
96 op->oq_cancel.rs_msgid = opid;
97 if ( op->o_bd->be_cancel( op, rs ) == LDAP_SUCCESS ) {
100 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
102 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
103 rs->sr_text = "message ID not found";
104 return LDAP_NO_SUCH_OPERATION;
107 if ( op->o_cancel != SLAP_CANCEL_NONE ) {
108 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
109 rs->sr_text = "message ID already being cancelled";
110 return LDAP_PROTOCOL_ERROR;
113 op->o_cancel = SLAP_CANCEL_REQ;
114 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
116 while ( op->o_cancel == SLAP_CANCEL_REQ ) {
117 ldap_pvt_thread_yield();
120 if ( op->o_cancel == SLAP_CANCEL_ACK ) {
126 op->o_cancel = SLAP_CANCEL_DONE;