3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 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 )
70 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
72 /* check client controls */
74 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
76 rc = ldap_int_client_controls( ld, cctrls );
77 if( rc == LDAP_SUCCESS )
78 rc = do_abandon( ld, msgid, msgid, sctrls, cctrls );
81 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
88 * ldap_abandon - perform an ldap abandon operation. Parameters:
91 * msgid The message id of the operation to abandon
93 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
96 * ldap_abandon( ld, msgid );
99 ldap_abandon( LDAP *ld, int msgid )
101 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
102 return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
112 LDAPControl **sctrls,
113 LDAPControl **cctrls)
116 int i, err, sendabandon;
117 ber_int_t *old_abandon;
121 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
126 /* find the request that we are abandoning */
127 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
128 if ( lr->lr_msgid == msgid ) { /* this message */
131 if ( lr->lr_origid == msgid ) {/* child: abandon it */
132 (void) do_abandon( ld,
133 msgid, lr->lr_msgid, sctrls, cctrls );
138 if ( origid == msgid && lr->lr_parent != NULL ) {
139 /* don't let caller abandon child requests! */
140 ld->ld_errno = LDAP_PARAM_ERROR;
141 return( LDAP_PARAM_ERROR );
143 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
144 /* no need to send abandon message */
149 /* ldap_msgdelete locks the res_mutex. Give up the req_mutex
150 * while we're in there.
152 #ifdef LDAP_R_COMPILE
153 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
155 err = ldap_msgdelete( ld, msgid );
156 #ifdef LDAP_R_COMPILE
157 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
160 ld->ld_errno = LDAP_SUCCESS;
166 if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
169 ld->ld_errno = LDAP_SERVER_DOWN;
171 } else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
172 /* BER element alocation failed */
174 ld->ld_errno = LDAP_NO_MEMORY;
178 * We already have the mutex in LDAP_R_COMPILE, so
179 * don't try to get it again.
180 * LDAP_NEXT_MSGID(ld, i);
182 i = ++(ld)->ld_msgid;
183 #ifdef LDAP_CONNECTIONLESS
184 if ( LDAP_IS_UDP(ld) ) {
185 err = ber_write( ber, ld->ld_options.ldo_peer,
186 sizeof(struct sockaddr), 0);
188 if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
190 char *dn = ld->ld_options.ldo_cldapdn;
192 err = ber_printf( ber, "{isti", /* '}' */
194 LDAP_REQ_ABANDON, msgid );
198 /* create a message to send */
199 err = ber_printf( ber, "{iti", /* '}' */
201 LDAP_REQ_ABANDON, msgid );
206 ld->ld_errno = LDAP_ENCODING_ERROR;
209 /* Put Server Controls */
210 if ( ldap_int_put_controls( ld, sctrls, ber )
217 err = ber_printf( ber, /*{*/ "N}" );
221 ld->ld_errno = LDAP_ENCODING_ERROR;
230 /* send the message */
232 sb = lr->lr_conn->lconn_sb;
237 if ( ber_flush( sb, ber, 1 ) != 0 ) {
238 ld->ld_errno = LDAP_SERVER_DOWN;
248 if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
249 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
251 if ( origid == msgid ) {
252 ldap_free_request( ld, lr );
257 if ( ld->ld_abandoned != NULL ) {
258 for ( ; ld->ld_abandoned[i] != -1; i++ )
262 old_abandon = ld->ld_abandoned;
264 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
265 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
267 if ( ld->ld_abandoned == NULL ) {
268 ld->ld_abandoned = old_abandon;
269 ld->ld_errno = LDAP_NO_MEMORY;
270 return( ld->ld_errno );
273 ld->ld_abandoned[i] = msgid;
274 ld->ld_abandoned[i + 1] = -1;
277 ld->ld_errno = LDAP_SUCCESS;
280 return( ld->ld_errno );