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>
24 static int do_abandon LDAP_P(( LDAP *ld, int origid, int msgid ));
27 * ldap_abandon - perform an ldap (and X.500) abandon operation. Parameters:
30 * msgid The message id of the operation to abandon
32 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
35 * ldap_abandon( ld, msgid );
38 ldap_abandon( LDAP *ld, int msgid )
40 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
41 return( do_abandon( ld, msgid, msgid ));
46 do_abandon( LDAP *ld, int origid, int msgid )
49 int i, err, sendabandon;
53 #endif /* LDAP_REFERRALS */
56 * An abandon request looks like this:
57 * AbandonRequest ::= MessageID
60 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
66 /* find the request that we are abandoning */
67 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
68 if ( lr->lr_msgid == msgid ) { /* this message */
71 if ( lr->lr_origid == msgid ) { /* child: abandon it */
72 do_abandon( ld, msgid, lr->lr_msgid );
77 if ( origid == msgid && lr->lr_parent != NULL ) {
78 /* don't let caller abandon child requests! */
79 ld->ld_errno = LDAP_PARAM_ERROR;
82 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
83 /* no need to send abandon message */
87 #endif /* LDAP_REFERRALS */
89 if ( ldap_msgdelete( ld, msgid ) == 0 ) {
90 ld->ld_errno = LDAP_SUCCESS;
96 /* create a message to send */
97 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
99 ld->ld_errno = LDAP_NO_MEMORY;
102 if ( ld->ld_sb.sb_naddr > 0 ) {
103 err = ber_printf( ber, "{isti}",
104 ++ld->ld_msgid, ld->ld_cldapdn,
105 LDAP_REQ_ABANDON, msgid );
108 err = ber_printf( ber, "{iti}", ++ld->ld_msgid,
109 LDAP_REQ_ABANDON, msgid );
115 ld->ld_errno = LDAP_ENCODING_ERROR;
118 /* send the message */
119 #ifdef LDAP_REFERRALS
121 sb = lr->lr_conn->lconn_sb;
125 #else /* LDAP_REFERRALS */
127 #endif /* LDAP_REFERRALS */
128 if ( ber_flush( sb, ber, 1 ) != 0 ) {
129 ld->ld_errno = LDAP_SERVER_DOWN;
138 #ifdef LDAP_REFERRALS
141 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
143 if ( origid == msgid ) {
144 ldap_free_request( ld, lr );
147 #endif /* LDAP_REFERRALS */
150 if ( ld->ld_abandoned == NULL ) {
151 if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) ))
153 ld->ld_errno = LDAP_NO_MEMORY;
158 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
160 if ( (ld->ld_abandoned = (int *) realloc( (char *)
161 ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) {
162 ld->ld_errno = LDAP_NO_MEMORY;
166 ld->ld_abandoned[i] = msgid;
167 ld->ld_abandoned[i + 1] = -1;
170 ld->ld_errno = LDAP_SUCCESS;