2 * Copyright (c) 1990 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
17 #include <ac/socket.h>
18 #include <ac/string.h>
25 static int do_abandon LDAP_P(( LDAP *ld, int origid, int msgid ));
28 * ldap_abandon - perform an ldap (and X.500) abandon operation. Parameters:
31 * msgid The message id of the operation to abandon
33 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
36 * ldap_abandon( ld, msgid );
39 ldap_abandon( LDAP *ld, int msgid )
41 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
42 return( do_abandon( ld, msgid, msgid ));
47 do_abandon( LDAP *ld, int origid, int msgid )
50 int i, err, sendabandon;
54 #endif /* LDAP_REFERRALS */
57 * An abandon request looks like this:
58 * AbandonRequest ::= MessageID
61 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
67 /* find the request that we are abandoning */
68 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
69 if ( lr->lr_msgid == msgid ) { /* this message */
72 if ( lr->lr_origid == msgid ) { /* child: abandon it */
73 do_abandon( ld, msgid, lr->lr_msgid );
78 if ( origid == msgid && lr->lr_parent != NULL ) {
79 /* don't let caller abandon child requests! */
80 ld->ld_errno = LDAP_PARAM_ERROR;
83 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
84 /* no need to send abandon message */
88 #endif /* LDAP_REFERRALS */
90 if ( ldap_msgdelete( ld, msgid ) == 0 ) {
91 ld->ld_errno = LDAP_SUCCESS;
97 /* create a message to send */
98 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
100 ld->ld_errno = LDAP_NO_MEMORY;
102 #ifdef LDAP_CONNECTIONLESS
103 if ( ld->ld_sb.sb_naddr > 0 ) {
104 err = ber_printf( ber, "{isti}",
105 ++ld->ld_msgid, ld->ld_cldapdn,
106 LDAP_REQ_ABANDON, msgid );
108 #endif /* LDAP_CONNECTIONLESS */
109 err = ber_printf( ber, "{iti}", ++ld->ld_msgid,
110 LDAP_REQ_ABANDON, msgid );
111 #ifdef LDAP_CONNECTIONLESS
113 #endif /* LDAP_CONNECTIONLESS */
116 ld->ld_errno = LDAP_ENCODING_ERROR;
119 /* send the message */
120 #ifdef LDAP_REFERRALS
122 sb = lr->lr_conn->lconn_sb;
126 #else /* LDAP_REFERRALS */
128 #endif /* LDAP_REFERRALS */
129 if ( ber_flush( sb, ber, 1 ) != 0 ) {
130 ld->ld_errno = LDAP_SERVER_DOWN;
139 #ifdef LDAP_REFERRALS
142 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
144 if ( origid == msgid ) {
145 ldap_free_request( ld, lr );
148 #endif /* LDAP_REFERRALS */
151 if ( ld->ld_abandoned == NULL ) {
152 if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) ))
154 ld->ld_errno = LDAP_NO_MEMORY;
159 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
161 if ( (ld->ld_abandoned = (int *) realloc( (char *)
162 ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) {
163 ld->ld_errno = LDAP_NO_MEMORY;
167 ld->ld_abandoned[i] = msgid;
168 ld->ld_abandoned[i + 1] = -1;
171 ld->ld_errno = LDAP_SUCCESS;