3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
14 * An abandon request looks like this:
15 * AbandonRequest ::= MessageID
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
30 static int do_abandon LDAP_P((
35 LDAPControl **cctrls));
38 * ldap_abandon_ext - perform an ldap extended abandon operation.
42 * msgid The message id of the operation to abandon
43 * scntrls Server Controls
44 * ccntrls Client Controls
46 * ldap_abandon_ext returns a LDAP error code.
47 * (LDAP_SUCCESS if everything went ok)
50 * ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
57 LDAPControl **cctrls )
59 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
61 return do_abandon( ld, msgid, msgid, sctrls, cctrls );
66 * ldap_abandon - perform an ldap abandon operation. Parameters:
69 * msgid The message id of the operation to abandon
71 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
74 * ldap_abandon( ld, msgid );
77 ldap_abandon( LDAP *ld, int msgid )
79 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
80 return do_abandon( ld, msgid, msgid, NULL, NULL ) == LDAP_SUCCESS
94 int i, err, sendabandon;
95 ber_int_t *old_abandon;
99 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
104 /* find the request that we are abandoning */
105 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
106 if ( lr->lr_msgid == msgid ) { /* this message */
109 if ( lr->lr_origid == msgid ) {/* child: abandon it */
110 (void) do_abandon( ld,
111 msgid, lr->lr_msgid, sctrls, cctrls );
116 if ( origid == msgid && lr->lr_parent != NULL ) {
117 /* don't let caller abandon child requests! */
118 ld->ld_errno = LDAP_PARAM_ERROR;
119 return( LDAP_PARAM_ERROR );
121 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
122 /* no need to send abandon message */
127 if ( ldap_msgdelete( ld, msgid ) == 0 ) {
128 ld->ld_errno = LDAP_SUCCESS;
134 /* create a message to send */
135 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
137 ld->ld_errno = LDAP_NO_MEMORY;
140 err = ber_printf( ber, "{iti", /* '}' */
142 LDAP_REQ_ABANDON, msgid );
146 ld->ld_errno = LDAP_ENCODING_ERROR;
149 /* Put Server Controls */
150 if ( ldap_int_put_controls( ld, sctrls, ber )
157 err = ber_printf( ber, /*{*/ "N}" );
161 ld->ld_errno = LDAP_ENCODING_ERROR;
170 /* send the message */
172 sb = lr->lr_conn->lconn_sb;
177 if ( ber_flush( sb, ber, 1 ) != 0 ) {
178 ld->ld_errno = LDAP_SERVER_DOWN;
189 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
191 if ( origid == msgid ) {
192 ldap_free_request( ld, lr );
197 if ( ld->ld_abandoned != NULL ) {
198 for ( ; ld->ld_abandoned[i] != -1; i++ )
202 old_abandon = ld->ld_abandoned;
204 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
205 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
207 if ( ld->ld_abandoned == NULL ) {
208 ld->ld_abandoned = old_abandon;
209 ld->ld_errno = LDAP_NO_MEMORY;
210 return( ld->ld_errno );
213 ld->ld_abandoned[i] = msgid;
214 ld->ld_abandoned[i + 1] = -1;
217 ld->ld_errno = LDAP_SUCCESS;
220 return( ld->ld_errno );