1 /* idl.c - ldap id list handling routines */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
17 #define BDB_IDL_SIZE (1<<16)
18 #define BDB_IDL_MAX (BDB_IDL_SIZE-16)
19 #define BDB_IDL_ALLOC (BDB_IDL_MAX * sizeof(ID))
21 #define BDB_IS_ALLIDS(ids) ((ids)[0] == NOID)
23 static int idl_search( ID *ids, ID id )
25 /* we should replace this a binary search as ids is sorted */
29 for( i = 1; i <= n; i++ ) {
38 static int idl_insert( ID *ids, ID id )
40 int x = idl_search( ids, id );
52 } else if ( ids[0]+1 >= BDB_IDL_MAX ) {
57 AC_MEMCPY( &ids[x+1], &ids[x], (1+ids[0]-x) * sizeof(ID) );
80 data.ulen = sizeof( ids );
81 data.flags = DB_DBT_USERMEM;
83 /* fetch the key and grab a write lock */
84 rc = db->get( db, tid, key, &data, DB_RMW );
86 if( rc == DB_NOTFOUND ) {
89 data.size = 2 * sizeof( ID );
91 } else if ( rc != 0 ) {
94 } else if ( data.size == 0 || data.size % sizeof( ID ) ) {
95 /* size not multiple of ID size */
98 } else if ( BDB_IS_ALLIDS(ids) ) {
101 } else if ( data.size != (1 + ids[0]) * sizeof( ID ) ) {
106 rc = idl_insert( ids, id );
108 if( rc != 0 ) return rc;
110 data.size = (ids[0]+1) * sizeof( ID );
114 rc = db->put( db, tid, key, &data, 0 );