2 * Copyright (c) 1990 Regents of the University of Michigan.
9 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
15 #if !defined( MACOS ) && !defined( DOS )
16 #include <sys/types.h>
17 #include <sys/socket.h>
20 #if defined( DOS ) || defined( _WIN32 )
35 static int do_abandon( LDAP *ld, int origid, int msgid );
36 #else /* NEEDPROTOS */
37 static int do_abandon();
38 #endif /* NEEDPROTOS */
40 * ldap_abandon - perform an ldap (and X.500) abandon operation. Parameters:
43 * msgid The message id of the operation to abandon
45 * ldap_abandon returns 0 if everything went ok, -1 otherwise.
48 * ldap_abandon( ld, msgid );
51 ldap_abandon( LDAP *ld, int msgid )
53 Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
54 return( do_abandon( ld, msgid, msgid ));
59 do_abandon( LDAP *ld, int origid, int msgid )
62 int i, err, sendabandon;
66 #endif /* LDAP_REFERRALS */
69 * An abandon request looks like this:
70 * AbandonRequest ::= MessageID
73 Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
79 /* find the request that we are abandoning */
80 for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
81 if ( lr->lr_msgid == msgid ) { /* this message */
84 if ( lr->lr_origid == msgid ) { /* child: abandon it */
85 do_abandon( ld, msgid, lr->lr_msgid );
90 if ( origid == msgid && lr->lr_parent != NULL ) {
91 /* don't let caller abandon child requests! */
92 ld->ld_errno = LDAP_PARAM_ERROR;
95 if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
96 /* no need to send abandon message */
100 #endif /* LDAP_REFERRALS */
102 if ( ldap_msgdelete( ld, msgid ) == 0 ) {
103 ld->ld_errno = LDAP_SUCCESS;
109 /* create a message to send */
110 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
112 ld->ld_errno = LDAP_NO_MEMORY;
115 if ( ld->ld_sb.sb_naddr > 0 ) {
116 err = ber_printf( ber, "{isti}",
117 ++ld->ld_msgid, ld->ld_cldapdn,
118 LDAP_REQ_ABANDON, msgid );
121 err = ber_printf( ber, "{iti}", ++ld->ld_msgid,
122 LDAP_REQ_ABANDON, msgid );
128 ld->ld_errno = LDAP_ENCODING_ERROR;
131 /* send the message */
132 #ifdef LDAP_REFERRALS
134 sb = lr->lr_conn->lconn_sb;
138 #else /* LDAP_REFERRALS */
140 #endif /* LDAP_REFERRALS */
141 if ( ber_flush( sb, ber, 1 ) != 0 ) {
142 ld->ld_errno = LDAP_SERVER_DOWN;
151 #ifdef LDAP_REFERRALS
154 ldap_free_connection( ld, lr->lr_conn, 0, 1 );
156 if ( origid == msgid ) {
157 ldap_free_request( ld, lr );
160 #endif /* LDAP_REFERRALS */
163 if ( ld->ld_abandoned == NULL ) {
164 if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) ))
166 ld->ld_errno = LDAP_NO_MEMORY;
171 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
173 if ( (ld->ld_abandoned = (int *) realloc( (char *)
174 ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) {
175 ld->ld_errno = LDAP_NO_MEMORY;
179 ld->ld_abandoned[i] = msgid;
180 ld->ld_abandoned[i + 1] = -1;
183 ld->ld_errno = LDAP_SUCCESS;