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.
14 * An abandon request looks like this:
15 * AbandonRequest ::= MessageID
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
30 static int do_abandon LDAP_P((
35 LDAPControl **cctrls));
38 * ldap_abandon_ext - perform an ldap extended abandon operation.
42 * msgid The message id of the operation to abandon
43 * scntrls Server Controls
44 * ccntrls Client Controls
46 * ldap_abandon_ext returns a LDAP error code.
47 * (LDAP_SUCCESS if everything went ok)
50 * ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
57 LDAPControl **cctrls )
61 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon_ext %d\n", msgid, 0, 0 );
63 Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
66 /* check client controls */
68 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
70 rc = ldap_int_client_controls( ld, cctrls );
71 if( rc == LDAP_SUCCESS )
72 rc = do_abandon( ld, msgid, msgid, sctrls, cctrls );
75 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
82 * ldap_abandon - perform an ldap abandon operation. Parameters:
85 * msgid The message id of the operation to abandon
87 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
90 * ldap_abandon( ld, msgid );
93 ldap_abandon( LDAP *ld, int msgid )
96 LDAP_LOG ( OPERATION, ARGS, "ldap_abandon %d\n", msgid, 0, 0 );
98 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
100 return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
110 LDAPControl **sctrls,
111 LDAPControl **cctrls)
114 int i, err, sendabandon;
115 ber_int_t *old_abandon;
120 LDAP_LOG ( OPERATION, ARGS, "do_abandon %d, msgid %d\n", origid, msgid, 0 );
122 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
128 /* find the request that we are abandoning */
129 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
130 if ( lr->lr_msgid == msgid ) { /* this message */
133 if ( lr->lr_origid == msgid ) {/* child: abandon it */
134 (void) do_abandon( ld,
135 msgid, lr->lr_msgid, sctrls, cctrls );
140 if ( origid == msgid && lr->lr_parent != NULL ) {
141 /* don't let caller abandon child requests! */
142 ld->ld_errno = LDAP_PARAM_ERROR;
143 return( LDAP_PARAM_ERROR );
145 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
146 /* no need to send abandon message */
151 /* ldap_msgdelete locks the res_mutex. Give up the req_mutex
152 * while we're in there.
154 #ifdef LDAP_R_COMPILE
155 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
157 err = ldap_msgdelete( ld, msgid );
158 #ifdef LDAP_R_COMPILE
159 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
162 ld->ld_errno = LDAP_SUCCESS;
168 if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
171 ld->ld_errno = LDAP_SERVER_DOWN;
173 } else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
174 /* BER element alocation failed */
176 ld->ld_errno = LDAP_NO_MEMORY;
179 LDAP_NEXT_MSGID(ld, i);
180 #ifdef LDAP_CONNECTIONLESS
181 if ( LDAP_IS_UDP(ld) ) {
182 err = ber_write( ber, ld->ld_options.ldo_peer,
183 sizeof(struct sockaddr), 0);
185 if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
187 char *dn = ld->ld_options.ldo_cldapdn;
189 err = ber_printf( ber, "{isti", /* '}' */
191 LDAP_REQ_ABANDON, msgid );
195 /* create a message to send */
196 err = ber_printf( ber, "{iti", /* '}' */
198 LDAP_REQ_ABANDON, msgid );
203 ld->ld_errno = LDAP_ENCODING_ERROR;
206 /* Put Server Controls */
207 if ( ldap_int_put_controls( ld, sctrls, ber )
214 err = ber_printf( ber, /*{*/ "N}" );
218 ld->ld_errno = LDAP_ENCODING_ERROR;
227 /* send the message */
229 sb = lr->lr_conn->lconn_sb;
234 if ( ber_flush( sb, ber, 1 ) != 0 ) {
235 ld->ld_errno = LDAP_SERVER_DOWN;
245 if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
246 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
248 if ( origid == msgid ) {
249 ldap_free_request( ld, lr );
254 if ( ld->ld_abandoned != NULL ) {
255 for ( ; ld->ld_abandoned[i] != -1; i++ )
259 old_abandon = ld->ld_abandoned;
261 ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
262 ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
264 if ( ld->ld_abandoned == NULL ) {
265 ld->ld_abandoned = old_abandon;
266 ld->ld_errno = LDAP_NO_MEMORY;
267 return( ld->ld_errno );
270 ld->ld_abandoned[i] = msgid;
271 ld->ld_abandoned[i + 1] = -1;
274 ld->ld_errno = LDAP_SUCCESS;
277 return( ld->ld_errno );