3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
17 * All rights reserved.
19 /* Portions Copyright (C) The Internet Society (1997).
20 * ASN.1 fragments are from RFC 2251; see RFC for full legal notices.
24 * An abandon request looks like this:
25 * AbandonRequest ::= MessageID
32 #include <ac/stdlib.h>
34 #include <ac/socket.h>
35 #include <ac/string.h>
40 static int do_abandon LDAP_P((
45 LDAPControl **cctrls));
48 * ldap_abandon_ext - perform an ldap extended abandon operation.
52 * msgid The message id of the operation to abandon
53 * scntrls Server Controls
54 * ccntrls Client Controls
56 * ldap_abandon_ext returns a LDAP error code.
57 * (LDAP_SUCCESS if everything went ok)
60 * ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
67 LDAPControl **cctrls )
71 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon_ext %d\n", msgid, 0, 0 );
73 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
76 /* check client controls */
78 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
80 rc = ldap_int_client_controls( ld, cctrls );
81 if( rc == LDAP_SUCCESS )
82 rc = do_abandon( ld, msgid, msgid, sctrls, cctrls );
85 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
92 * ldap_abandon - perform an ldap abandon operation. Parameters:
95 * msgid The message id of the operation to abandon
97 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
100 * ldap_abandon( ld, msgid );
103 ldap_abandon( LDAP *ld, int msgid )
106 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon %d\n", msgid, 0, 0 );
108 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
110 return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
120 LDAPControl **sctrls,
121 LDAPControl **cctrls)
124 int i, err, sendabandon;
125 ber_int_t *old_abandon;
130 LDAP_LOG ( OPERATION, ARGS, "do_abandon %d, msgid %d\n", origid, msgid, 0 );
132 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
138 /* find the request that we are abandoning */
139 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
140 if ( lr->lr_msgid == msgid ) { /* this message */
143 if ( lr->lr_origid == msgid ) {/* child: abandon it */
144 (void) do_abandon( ld,
145 msgid, lr->lr_msgid, sctrls, cctrls );
150 if ( origid == msgid && lr->lr_parent != NULL ) {
151 /* don't let caller abandon child requests! */
152 ld->ld_errno = LDAP_PARAM_ERROR;
153 return( LDAP_PARAM_ERROR );
155 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
156 /* no need to send abandon message */
161 /* ldap_msgdelete locks the res_mutex. Give up the req_mutex
162 * while we're in there.
164 #ifdef LDAP_R_COMPILE
165 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
167 err = ldap_msgdelete( ld, msgid );
168 #ifdef LDAP_R_COMPILE
169 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
172 ld->ld_errno = LDAP_SUCCESS;
178 if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
181 ld->ld_errno = LDAP_SERVER_DOWN;
183 } else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
184 /* BER element alocation failed */
186 ld->ld_errno = LDAP_NO_MEMORY;
189 LDAP_NEXT_MSGID(ld, i);
190 #ifdef LDAP_CONNECTIONLESS
191 if ( LDAP_IS_UDP(ld) ) {
192 err = ber_write( ber, ld->ld_options.ldo_peer,
193 sizeof(struct sockaddr), 0);
195 if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
197 char *dn = ld->ld_options.ldo_cldapdn;
199 err = ber_printf( ber, "{isti", /* '}' */
201 LDAP_REQ_ABANDON, msgid );
205 /* create a message to send */
206 err = ber_printf( ber, "{iti", /* '}' */
208 LDAP_REQ_ABANDON, msgid );
213 ld->ld_errno = LDAP_ENCODING_ERROR;
216 /* Put Server Controls */
217 if ( ldap_int_put_controls( ld, sctrls, ber )
224 err = ber_printf( ber, /*{*/ "N}" );
228 ld->ld_errno = LDAP_ENCODING_ERROR;
237 /* send the message */
239 sb = lr->lr_conn->lconn_sb;
244 if ( ber_flush( sb, ber, 1 ) != 0 ) {
245 ld->ld_errno = LDAP_SERVER_DOWN;
255 if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
256 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
258 if ( origid == msgid ) {
259 ldap_free_request( ld, lr );
264 if ( ld->ld_abandoned != NULL ) {
265 for ( ; ld->ld_abandoned[i] != -1; i++ )
269 old_abandon = ld->ld_abandoned;
271 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
272 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
274 if ( ld->ld_abandoned == NULL ) {
275 ld->ld_abandoned = old_abandon;
276 ld->ld_errno = LDAP_NO_MEMORY;
277 return( ld->ld_errno );
280 ld->ld_abandoned[i] = msgid;
281 ld->ld_abandoned[i + 1] = -1;
284 ld->ld_errno = LDAP_SUCCESS;
287 return( ld->ld_errno );