2003-11-26 15:16:36 +08:00
|
|
|
/* abandon.c */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 1998-2007 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* All rights reserved.
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
2003-11-26 15:16:36 +08:00
|
|
|
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
1999-06-04 03:22:33 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
2006-10-28 03:37:04 +08:00
|
|
|
/*
|
|
|
|
* An abandon request looks like this:
|
|
|
|
* AbandonRequest ::= [APPLICATION 16] MessageID
|
|
|
|
* and has no response. (Source: RFC 4511)
|
|
|
|
*/
|
2006-12-04 04:56:25 +08:00
|
|
|
#include "lutil.h"
|
2006-10-28 03:37:04 +08:00
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
static int
|
|
|
|
do_abandon(
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP *ld,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_int_t origid,
|
|
|
|
ber_int_t msgid,
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAPControl **sctrls,
|
2006-10-23 04:31:41 +08:00
|
|
|
int sendabandon );
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1999-05-19 09:12:33 +08:00
|
|
|
* ldap_abandon_ext - perform an ldap extended abandon operation.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* msgid The message id of the operation to abandon
|
|
|
|
* scntrls Server Controls
|
|
|
|
* ccntrls Client Controls
|
|
|
|
*
|
|
|
|
* ldap_abandon_ext returns a LDAP error code.
|
|
|
|
* (LDAP_SUCCESS if everything went ok)
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_abandon_ext(
|
|
|
|
LDAP *ld,
|
|
|
|
int msgid,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
|
|
|
{
|
2006-10-23 04:31:41 +08:00
|
|
|
int rc;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
|
|
|
|
|
2001-07-06 11:13:42 +08:00
|
|
|
/* check client controls */
|
2003-02-14 07:02:31 +08:00
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
2006-10-23 04:31:41 +08:00
|
|
|
|
2001-07-06 11:13:42 +08:00
|
|
|
rc = ldap_int_client_controls( ld, cctrls );
|
2006-10-23 04:31:41 +08:00
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
rc = do_abandon( ld, msgid, msgid, sctrls, 1 );
|
|
|
|
}
|
2001-07-06 11:13:42 +08:00
|
|
|
|
2003-02-14 07:02:31 +08:00
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
2006-10-23 04:31:41 +08:00
|
|
|
|
2003-02-14 07:02:31 +08:00
|
|
|
return rc;
|
1999-05-19 09:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_abandon - perform an ldap abandon operation. Parameters:
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* msgid The message id of the operation to abandon
|
|
|
|
*
|
|
|
|
* ldap_abandon returns 0 if everything went ok, -1 otherwise.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_abandon( ld, msgid );
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_abandon( LDAP *ld, int msgid )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
|
2001-07-06 11:13:42 +08:00
|
|
|
return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
|
1999-05-19 09:12:33 +08:00
|
|
|
? 0 : -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
int
|
2006-10-29 02:13:12 +08:00
|
|
|
ldap_pvt_discard(
|
2006-10-23 04:31:41 +08:00
|
|
|
LDAP *ld,
|
|
|
|
ber_int_t msgid )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc = do_abandon( ld, msgid, msgid, NULL, 0 );
|
|
|
|
|
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
static int
|
1999-05-19 09:12:33 +08:00
|
|
|
do_abandon(
|
|
|
|
LDAP *ld,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_int_t origid,
|
|
|
|
ber_int_t msgid,
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAPControl **sctrls,
|
2006-10-23 04:31:41 +08:00
|
|
|
int sendabandon )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement *ber;
|
2006-10-23 04:31:41 +08:00
|
|
|
int i, err;
|
1998-08-09 08:43:13 +08:00
|
|
|
Sockbuf *sb;
|
|
|
|
LDAPRequest *lr;
|
|
|
|
|
2006-11-03 03:11:18 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
origid, msgid, 0 );
|
|
|
|
|
|
|
|
/* find the request that we are abandoning */
|
2006-09-01 21:59:55 +08:00
|
|
|
start_again:;
|
|
|
|
lr = ld->ld_requests;
|
|
|
|
while ( lr != NULL ) {
|
2006-11-12 22:22:24 +08:00
|
|
|
/* this message */
|
|
|
|
if ( lr->lr_msgid == msgid ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-09-01 21:59:55 +08:00
|
|
|
|
2006-11-12 22:22:24 +08:00
|
|
|
/* child: abandon it */
|
2006-12-04 04:56:25 +08:00
|
|
|
if ( lr->lr_origid == msgid && !lr->lr_abandoned ) {
|
2006-10-23 04:31:41 +08:00
|
|
|
(void)do_abandon( ld, lr->lr_origid, lr->lr_msgid,
|
|
|
|
sctrls, sendabandon );
|
2006-09-01 21:59:55 +08:00
|
|
|
|
|
|
|
/* restart, as lr may now be dangling... */
|
|
|
|
goto start_again;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2006-09-01 21:59:55 +08:00
|
|
|
|
|
|
|
lr = lr->lr_next;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
if ( origid == msgid && lr->lr_parent != NULL ) {
|
|
|
|
/* don't let caller abandon child requests! */
|
|
|
|
ld->ld_errno = LDAP_PARAM_ERROR;
|
1999-05-19 09:12:33 +08:00
|
|
|
return( LDAP_PARAM_ERROR );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
|
|
|
|
/* no need to send abandon message */
|
|
|
|
sendabandon = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
/* ldap_msgdelete locks the res_mutex. Give up the req_mutex
|
|
|
|
* while we're in there.
|
|
|
|
*/
|
2003-02-14 07:02:31 +08:00
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
|
|
|
err = ldap_msgdelete( ld, msgid );
|
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
|
|
|
if ( err == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
1999-05-19 09:12:33 +08:00
|
|
|
return LDAP_SUCCESS;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2005-06-30 10:36:55 +08:00
|
|
|
/* fetch again the request that we are abandoning */
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
|
2006-10-23 04:31:41 +08:00
|
|
|
/* this message */
|
|
|
|
if ( lr->lr_msgid == msgid ) {
|
2005-06-30 10:36:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
err = 0;
|
|
|
|
if ( sendabandon ) {
|
2006-10-23 04:31:41 +08:00
|
|
|
if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
|
2000-10-17 07:11:41 +08:00
|
|
|
/* not connected */
|
|
|
|
err = -1;
|
|
|
|
ld->ld_errno = LDAP_SERVER_DOWN;
|
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
} else if ( ( ber = ldap_alloc_ber_with_options( ld ) ) == NULL ) {
|
|
|
|
/* BER element allocation failed */
|
1998-08-09 08:43:13 +08:00
|
|
|
err = -1;
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
2006-10-23 04:31:41 +08:00
|
|
|
/*
|
|
|
|
* We already have the mutex in LDAP_R_COMPILE, so
|
|
|
|
* don't try to get it again.
|
|
|
|
* LDAP_NEXT_MSGID(ld, i);
|
|
|
|
*/
|
|
|
|
|
2004-02-13 10:47:53 +08:00
|
|
|
i = ++(ld)->ld_msgid;
|
2001-09-28 08:18:40 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
|
|
|
if ( LDAP_IS_UDP(ld) ) {
|
2006-05-18 08:37:56 +08:00
|
|
|
err = ber_write( ber, ld->ld_options.ldo_peer,
|
|
|
|
sizeof(struct sockaddr), 0);
|
2001-10-02 09:02:23 +08:00
|
|
|
}
|
|
|
|
if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
|
2006-05-18 08:37:56 +08:00
|
|
|
LDAP_VERSION2 )
|
|
|
|
{
|
|
|
|
char *dn = ld->ld_options.ldo_cldapdn;
|
|
|
|
if (!dn) dn = "";
|
|
|
|
err = ber_printf( ber, "{isti", /* '}' */
|
|
|
|
i, dn,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
2001-09-28 08:18:40 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2006-05-18 08:37:56 +08:00
|
|
|
/* create a message to send */
|
|
|
|
err = ber_printf( ber, "{iti", /* '}' */
|
|
|
|
i,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
2001-09-28 08:18:40 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
if ( err == -1 ) {
|
1999-05-19 09:12:33 +08:00
|
|
|
/* encoding error */
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Put Server Controls */
|
|
|
|
if ( ldap_int_put_controls( ld, sctrls, ber )
|
|
|
|
!= LDAP_SUCCESS )
|
|
|
|
{
|
|
|
|
err = -1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* close '{' */
|
2000-06-24 09:40:39 +08:00
|
|
|
err = ber_printf( ber, /*{*/ "N}" );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2006-10-23 04:31:41 +08:00
|
|
|
if ( err == -1 ) {
|
1999-05-19 09:12:33 +08:00
|
|
|
/* encoding error */
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err == -1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ber_free( ber, 1 );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
|
|
|
/* send the message */
|
|
|
|
if ( lr != NULL ) {
|
2005-08-02 07:35:44 +08:00
|
|
|
assert( lr->lr_conn != NULL );
|
1998-08-09 08:43:13 +08:00
|
|
|
sb = lr->lr_conn->lconn_sb;
|
1999-05-22 14:11:48 +08:00
|
|
|
} else {
|
2000-06-02 04:59:21 +08:00
|
|
|
sb = ld->ld_sb;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2006-04-10 06:29:42 +08:00
|
|
|
if ( ber_flush2( sb, ber, LBER_FLUSH_FREE_ALWAYS ) != 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_SERVER_DOWN;
|
|
|
|
err = -1;
|
|
|
|
} else {
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lr != NULL ) {
|
2002-08-29 20:12:36 +08:00
|
|
|
if ( sendabandon || lr->lr_status == LDAP_REQST_WRITING ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_connection( ld, lr->lr_conn, 0, 1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2006-10-23 04:31:41 +08:00
|
|
|
|
2006-12-04 04:56:25 +08:00
|
|
|
if ( origid == msgid ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_request( ld, lr );
|
2006-12-04 04:56:25 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
lr->lr_abandoned = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-01 00:49:00 +08:00
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
/* ld_abandoned is actually protected by the ld_res_mutex;
|
|
|
|
* give up the ld_req_mutex and get the other */
|
|
|
|
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
|
|
|
|
ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
|
|
|
|
#endif
|
2006-10-23 04:31:41 +08:00
|
|
|
|
|
|
|
/* use bisection */
|
1999-05-29 09:19:14 +08:00
|
|
|
i = 0;
|
2006-12-04 04:56:25 +08:00
|
|
|
if ( ld->ld_nabandoned == 0 ||
|
2006-12-18 06:04:25 +08:00
|
|
|
ldap_int_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, &i ) == 0 )
|
2006-12-04 04:56:25 +08:00
|
|
|
{
|
2006-12-18 06:04:25 +08:00
|
|
|
ldap_int_bisect_insert( &ld->ld_abandoned, &ld->ld_nabandoned, msgid, i );
|
2006-10-23 04:31:41 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( err != -1 ) {
|
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2005-07-01 00:49:00 +08:00
|
|
|
#ifdef LDAP_R_COMPILE
|
|
|
|
ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
|
|
|
|
ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
|
|
|
|
#endif
|
1999-05-19 09:12:33 +08:00
|
|
|
return( ld->ld_errno );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2006-12-18 06:04:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_int_bisect_find
|
|
|
|
*
|
|
|
|
* args:
|
|
|
|
* v: array of length n (in)
|
|
|
|
* n: length of array v (in)
|
|
|
|
* id: value to look for (in)
|
|
|
|
* idxp: pointer to location of value/insert point
|
|
|
|
*
|
|
|
|
* return:
|
|
|
|
* 0: not found
|
|
|
|
* 1: found
|
|
|
|
* -1: error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
|
|
|
|
{
|
|
|
|
int begin,
|
|
|
|
end,
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
assert( n >= 0 );
|
|
|
|
assert( id >= 0 );
|
|
|
|
|
|
|
|
begin = 0;
|
|
|
|
end = n - 1;
|
|
|
|
|
|
|
|
if ( n > 0 ) {
|
|
|
|
if ( id < v[ begin ] ) {
|
|
|
|
*idxp = 0;
|
|
|
|
|
|
|
|
} else if ( id > v[ end ] ) {
|
|
|
|
*idxp = n;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
int pos;
|
|
|
|
ber_int_t curid;
|
|
|
|
|
|
|
|
while ( end >= begin ) {
|
|
|
|
pos = (begin + end)/2;
|
|
|
|
curid = v[ pos ];
|
|
|
|
|
|
|
|
if ( id < curid ) {
|
|
|
|
end = pos - 1;
|
|
|
|
|
|
|
|
} else if ( id > curid ) {
|
|
|
|
begin = pos + 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* already abandoned? */
|
|
|
|
*idxp = pos;
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc == 0 ) {
|
|
|
|
*idxp = pos + ( id > curid ? 1 : 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
*idxp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_int_bisect_insert
|
|
|
|
*
|
|
|
|
* args:
|
|
|
|
* vp: pointer to array of length *np (in/out)
|
|
|
|
* np: pointer to length of array *vp (in/out)
|
|
|
|
* id: value to insert (in)
|
|
|
|
* idx: location of insert point (as computed by ldap_int_bisect_find())
|
|
|
|
*
|
|
|
|
* return:
|
|
|
|
* 0: inserted
|
|
|
|
* -1: error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
|
|
|
|
{
|
|
|
|
ber_int_t *v;
|
|
|
|
ber_len_t n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert( vp != NULL );
|
|
|
|
assert( np != NULL );
|
|
|
|
assert( *np >= 0 );
|
|
|
|
assert( idx >= 0 );
|
|
|
|
assert( idx <= *np );
|
|
|
|
|
|
|
|
n = *np;
|
|
|
|
|
|
|
|
v = ber_memrealloc( *vp, sizeof( ber_int_t ) * ( n + 1 ) );
|
|
|
|
if ( v == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*vp = v;
|
|
|
|
|
|
|
|
for ( i = n; i > idx; i-- ) {
|
|
|
|
v[ i ] = v[ i - 1 ];
|
|
|
|
}
|
|
|
|
v[ idx ] = id;
|
|
|
|
++(*np);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_int_bisect_delete
|
|
|
|
*
|
|
|
|
* args:
|
|
|
|
* vp: pointer to array of length *np (in/out)
|
|
|
|
* np: pointer to length of array *vp (in/out)
|
|
|
|
* id: value to delete (in)
|
|
|
|
* idx: location of value to delete (as computed by ldap_int_bisect_find())
|
|
|
|
*
|
|
|
|
* return:
|
|
|
|
* 0: deleted
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
|
|
|
|
{
|
|
|
|
ber_int_t *v;
|
|
|
|
ber_len_t n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert( vp != NULL );
|
|
|
|
assert( np != NULL );
|
|
|
|
assert( *np >= 0 );
|
|
|
|
assert( idx >= 0 );
|
|
|
|
assert( idx < *np );
|
|
|
|
|
|
|
|
v = *vp;
|
|
|
|
|
|
|
|
assert( v[ idx ] == id );
|
|
|
|
|
|
|
|
--(*np);
|
|
|
|
n = *np;
|
|
|
|
|
|
|
|
for ( i = idx; i < n; i++ ) {
|
|
|
|
v[ i ] = v[ i + 1 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|