1 /* cancel.c - LDAP cancel extended operation */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
13 #include <ac/string.h>
14 #include <ac/unistd.h>
25 struct berval *reqdata,
27 struct berval **rspdata,
28 LDAPControl ***rspctrls,
38 assert( reqoid != NULL );
39 assert( strcmp( LDAP_EXOP_X_CANCEL, reqoid ) == 0 );
41 if ( reqdata == NULL ) {
42 *text = "no message ID supplied";
43 return LDAP_PROTOCOL_ERROR;
46 ber = ber_init( reqdata );
48 *text = "internal error";
52 if ( ber_scanf( ber, "{i}", &opid ) == LBER_ERROR ) {
53 *text = "message ID parse failed";
54 return LDAP_PROTOCOL_ERROR;
57 (void) ber_free( ber, 1 );
60 *text = "message ID invalid";
61 return LDAP_PROTOCOL_ERROR;
64 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
65 LDAP_STAILQ_FOREACH( op, &conn->c_pending_ops, o_next ) {
66 if ( op->o_msgid == opid ) {
67 LDAP_STAILQ_REMOVE( &conn->c_pending_ops, op, slap_op, o_next );
73 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
79 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
80 LDAP_STAILQ_FOREACH( op, &conn->c_ops, o_next ) {
81 if ( op->o_msgid == opid ) {
88 *text = "message ID not found";
89 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
90 return LDAP_NO_SUCH_OPERATION;
93 if ( op->o_cancel != LDAP_CANCEL_NONE ) {
94 *text = "message ID already being cancelled";
95 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
96 return LDAP_PROTOCOL_ERROR;
99 op->o_cancel = LDAP_CANCEL_REQ;
100 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
102 while ( op->o_cancel == LDAP_CANCEL_REQ ) {
103 ldap_pvt_thread_yield();
106 if ( op->o_cancel == LDAP_CANCEL_ACK ) {
110 op->o_cancel = LDAP_CANCEL_NOTDONE;