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>
26 struct berval *reqdata,
28 struct berval **rspdata,
29 LDAPControl ***rspctrls,
39 assert( reqoid != NULL );
40 assert( strcmp( LDAP_EXOP_X_CANCEL, reqoid ) == 0 );
42 if ( reqdata == NULL ) {
43 *text = "no message ID supplied";
44 return LDAP_PROTOCOL_ERROR;
47 ber = ber_init( reqdata );
49 *text = "internal error";
53 if ( ber_scanf( ber, "{i}", &opid ) == LBER_ERROR ) {
54 *text = "message ID parse failed";
55 return LDAP_PROTOCOL_ERROR;
58 (void) ber_free( ber, 1 );
61 *text = "message ID invalid";
62 return LDAP_PROTOCOL_ERROR;
65 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
66 LDAP_STAILQ_FOREACH( op, &conn->c_pending_ops, o_next ) {
67 if ( op->o_msgid == opid ) {
68 LDAP_STAILQ_REMOVE( &conn->c_pending_ops, op, slap_op, o_next );
74 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
80 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
81 LDAP_STAILQ_FOREACH( op, &conn->c_ops, o_next ) {
82 if ( op->o_msgid == opid ) {
89 *text = "message ID not found";
90 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
91 return LDAP_NO_SUCH_OPERATION;
94 if ( op->o_cancel != LDAP_CANCEL_NONE ) {
95 *text = "message ID already being cancelled";
96 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
97 return LDAP_PROTOCOL_ERROR;
100 op->o_cancel = LDAP_CANCEL_REQ;
101 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
103 while ( op->o_cancel == LDAP_CANCEL_REQ ) {
104 ldap_pvt_thread_yield();
107 if ( op->o_cancel == LDAP_CANCEL_ACK ) {
113 op->o_cancel = LDAP_CANCEL_DONE;