3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
13 * Portions Copyright (C) The Internet Society (1997)
14 * ASN.1 fragments are from RFC 2251; see RFC for full legal notices.
18 * An abandon request looks like this:
19 * AbandonRequest ::= MessageID
26 #include <ac/stdlib.h>
28 #include <ac/socket.h>
29 #include <ac/string.h>
34 static int do_abandon LDAP_P((
39 LDAPControl **cctrls));
42 * ldap_abandon_ext - perform an ldap extended abandon operation.
46 * msgid The message id of the operation to abandon
47 * scntrls Server Controls
48 * ccntrls Client Controls
50 * ldap_abandon_ext returns a LDAP error code.
51 * (LDAP_SUCCESS if everything went ok)
54 * ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
61 LDAPControl **cctrls )
65 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon_ext %d\n", msgid, 0, 0 );
67 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
70 /* check client controls */
72 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
74 rc = ldap_int_client_controls( ld, cctrls );
75 if( rc == LDAP_SUCCESS )
76 rc = do_abandon( ld, msgid, msgid, sctrls, cctrls );
79 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
86 * ldap_abandon - perform an ldap abandon operation. Parameters:
89 * msgid The message id of the operation to abandon
91 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
94 * ldap_abandon( ld, msgid );
97 ldap_abandon( LDAP *ld, int msgid )
100 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon %d\n", msgid, 0, 0 );
102 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
104 return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
114 LDAPControl **sctrls,
115 LDAPControl **cctrls)
118 int i, err, sendabandon;
119 ber_int_t *old_abandon;
124 LDAP_LOG ( OPERATION, ARGS, "do_abandon %d, msgid %d\n", origid, msgid, 0 );
126 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
132 /* find the request that we are abandoning */
133 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
134 if ( lr->lr_msgid == msgid ) { /* this message */
137 if ( lr->lr_origid == msgid ) {/* child: abandon it */
138 (void) do_abandon( ld,
139 msgid, lr->lr_msgid, sctrls, cctrls );
144 if ( origid == msgid && lr->lr_parent != NULL ) {
145 /* don't let caller abandon child requests! */
146 ld->ld_errno = LDAP_PARAM_ERROR;
147 return( LDAP_PARAM_ERROR );
149 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
150 /* no need to send abandon message */
155 /* ldap_msgdelete locks the res_mutex. Give up the req_mutex
156 * while we're in there.
158 #ifdef LDAP_R_COMPILE
159 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
161 err = ldap_msgdelete( ld, msgid );
162 #ifdef LDAP_R_COMPILE
163 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
166 ld->ld_errno = LDAP_SUCCESS;
172 if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
175 ld->ld_errno = LDAP_SERVER_DOWN;
177 } else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
178 /* BER element alocation failed */
180 ld->ld_errno = LDAP_NO_MEMORY;
183 LDAP_NEXT_MSGID(ld, i);
184 #ifdef LDAP_CONNECTIONLESS
185 if ( LDAP_IS_UDP(ld) ) {
186 err = ber_write( ber, ld->ld_options.ldo_peer,
187 sizeof(struct sockaddr), 0);
189 if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
191 char *dn = ld->ld_options.ldo_cldapdn;
193 err = ber_printf( ber, "{isti", /* '}' */
195 LDAP_REQ_ABANDON, msgid );
199 /* create a message to send */
200 err = ber_printf( ber, "{iti", /* '}' */
202 LDAP_REQ_ABANDON, msgid );
207 ld->ld_errno = LDAP_ENCODING_ERROR;
210 /* Put Server Controls */
211 if ( ldap_int_put_controls( ld, sctrls, ber )
218 err = ber_printf( ber, /*{*/ "N}" );
222 ld->ld_errno = LDAP_ENCODING_ERROR;
231 /* send the message */
233 sb = lr->lr_conn->lconn_sb;
238 if ( ber_flush( sb, ber, 1 ) != 0 ) {
239 ld->ld_errno = LDAP_SERVER_DOWN;
249 if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
250 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
252 if ( origid == msgid ) {
253 ldap_free_request( ld, lr );
258 if ( ld->ld_abandoned != NULL ) {
259 for ( ; ld->ld_abandoned[i] != -1; i++ )
263 old_abandon = ld->ld_abandoned;
265 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
266 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
268 if ( ld->ld_abandoned == NULL ) {
269 ld->ld_abandoned = old_abandon;
270 ld->ld_errno = LDAP_NO_MEMORY;
271 return( ld->ld_errno );
274 ld->ld_abandoned[i] = msgid;
275 ld->ld_abandoned[i + 1] = -1;
278 ld->ld_errno = LDAP_SUCCESS;
281 return( ld->ld_errno );