2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 Regents of the University of Michigan.
17 #include <ac/socket.h>
18 #include <ac/string.h>
23 static int do_abandon LDAP_P((
28 LDAPControl **cctrls));
31 * ldap_abandon_ext - perform an ldap extended abandon operation.
35 * msgid The message id of the operation to abandon
36 * scntrls Server Controls
37 * ccntrls Client Controls
39 * ldap_abandon_ext returns a LDAP error code.
40 * (LDAP_SUCCESS if everything went ok)
43 * ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
50 LDAPControl **cctrls )
52 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
54 return do_abandon( ld, msgid, msgid, sctrls, cctrls );
59 * ldap_abandon - perform an ldap abandon operation. Parameters:
62 * msgid The message id of the operation to abandon
64 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
67 * ldap_abandon( ld, msgid );
70 ldap_abandon( LDAP *ld, int msgid )
72 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
73 return do_abandon( ld, msgid, msgid, NULL, NULL ) == LDAP_SUCCESS
87 int i, err, sendabandon;
88 unsigned int *old_abandon;
93 * An abandon request looks like this:
94 * AbandonRequest ::= MessageID
97 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
102 /* find the request that we are abandoning */
103 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
104 if ( lr->lr_msgid == msgid ) { /* this message */
107 if ( lr->lr_origid == msgid ) {/* child: abandon it */
108 (void) do_abandon( ld,
109 msgid, lr->lr_msgid, sctrls, cctrls );
114 if ( origid == msgid && lr->lr_parent != NULL ) {
115 /* don't let caller abandon child requests! */
116 ld->ld_errno = LDAP_PARAM_ERROR;
117 return( LDAP_PARAM_ERROR );
119 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
120 /* no need to send abandon message */
125 if ( ldap_msgdelete( ld, msgid ) == 0 ) {
126 ld->ld_errno = LDAP_SUCCESS;
132 /* create a message to send */
133 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
135 ld->ld_errno = LDAP_NO_MEMORY;
138 #ifdef LDAP_CONNECTIONLESS
139 if ( ld->ld_cldapnaddr > 0 ) {
140 err = ber_printf( ber, "{isti", /* leave open '}' */
141 ++ld->ld_msgid, ld->ld_cldapdn,
142 LDAP_REQ_ABANDON, msgid );
144 #endif /* LDAP_CONNECTIONLESS */
146 err = ber_printf( ber, "{iti", /* leave open '}' */
148 LDAP_REQ_ABANDON, msgid );
153 ld->ld_errno = LDAP_ENCODING_ERROR;
156 /* Put Server Controls */
157 if ( ldap_int_put_controls( ld, sctrls, ber )
164 err = ber_printf( ber, "}" );
168 ld->ld_errno = LDAP_ENCODING_ERROR;
177 /* send the message */
179 sb = lr->lr_conn->lconn_sb;
184 if ( ber_flush( sb, ber, 1 ) != 0 ) {
185 ld->ld_errno = LDAP_SERVER_DOWN;
196 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
198 if ( origid == msgid ) {
199 ldap_free_request( ld, lr );
204 if ( ld->ld_abandoned != NULL ) {
205 for ( ; ld->ld_abandoned[i] != -1; i++ )
209 old_abandon = ld->ld_abandoned;
211 ld->ld_abandoned = (int *) LDAP_REALLOC( (char *)
212 ld->ld_abandoned, (i + 2) * sizeof(int) );
214 if ( ld->ld_abandoned == NULL ) {
215 ld->ld_abandoned = old_abandon;
216 ld->ld_errno = LDAP_NO_MEMORY;
217 return( ld->ld_errno );
220 ld->ld_abandoned[i] = msgid;
221 ld->ld_abandoned[i + 1] = -1;
224 ld->ld_errno = LDAP_SUCCESS;
227 return( ld->ld_errno );