3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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;
190 * We already have the mutex in LDAP_R_COMPILE, so
191 * don't try to get it again.
192 * LDAP_NEXT_MSGID(ld, i);
194 i = ++(ld)->ld_msgid;
195 #ifdef LDAP_CONNECTIONLESS
196 if ( LDAP_IS_UDP(ld) ) {
197 err = ber_write( ber, ld->ld_options.ldo_peer,
198 sizeof(struct sockaddr), 0);
200 if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
202 char *dn = ld->ld_options.ldo_cldapdn;
204 err = ber_printf( ber, "{isti", /* '}' */
206 LDAP_REQ_ABANDON, msgid );
210 /* create a message to send */
211 err = ber_printf( ber, "{iti", /* '}' */
213 LDAP_REQ_ABANDON, msgid );
218 ld->ld_errno = LDAP_ENCODING_ERROR;
221 /* Put Server Controls */
222 if ( ldap_int_put_controls( ld, sctrls, ber )
229 err = ber_printf( ber, /*{*/ "N}" );
233 ld->ld_errno = LDAP_ENCODING_ERROR;
242 /* send the message */
244 sb = lr->lr_conn->lconn_sb;
249 if ( ber_flush( sb, ber, 1 ) != 0 ) {
250 ld->ld_errno = LDAP_SERVER_DOWN;
260 if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
261 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
263 if ( origid == msgid ) {
264 ldap_free_request( ld, lr );
269 if ( ld->ld_abandoned != NULL ) {
270 for ( ; ld->ld_abandoned[i] != -1; i++ )
274 old_abandon = ld->ld_abandoned;
276 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
277 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
279 if ( ld->ld_abandoned == NULL ) {
280 ld->ld_abandoned = old_abandon;
281 ld->ld_errno = LDAP_NO_MEMORY;
282 return( ld->ld_errno );
285 ld->ld_abandoned[i] = msgid;
286 ld->ld_abandoned[i + 1] = -1;
289 ld->ld_errno = LDAP_SUCCESS;
292 return( ld->ld_errno );