/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <ac/socket.h>
#include "slap.h"
-#include "ldap_pvt.h"
struct cindexrec {
struct berval cir_name;
};
static Avlnode *cr_index = NULL;
-static LDAP_SLIST_HEAD(CRList, slap_content_rule) cr_list
- = LDAP_SLIST_HEAD_INITIALIZER(&cr_list);
+static LDAP_STAILQ_HEAD(CRList, slap_content_rule) cr_list
+ = LDAP_STAILQ_HEAD_INITIALIZER(cr_list);
static int
cr_index_cmp(
avl_free(cr_index, ldap_memfree);
- while( !LDAP_SLIST_EMPTY(&cr_list) ) {
- c = LDAP_SLIST_FIRST(&cr_list);
- LDAP_SLIST_REMOVE_HEAD(&cr_list, scr_next);
+ while( !LDAP_STAILQ_EMPTY(&cr_list) ) {
+ c = LDAP_STAILQ_FIRST(&cr_list);
+ LDAP_STAILQ_REMOVE_HEAD(&cr_list, scr_next);
cr_destroy_one( c );
}
struct cindexrec *cir;
char **names;
- LDAP_SLIST_NEXT( scr, scr_next ) = NULL;
- LDAP_SLIST_INSERT_HEAD(&cr_list, scr, scr_next);
-
if ( scr->scr_oid ) {
cir = (struct cindexrec *)
ch_calloc( 1, sizeof(struct cindexrec) );
}
}
+ LDAP_STAILQ_INSERT_TAIL(&cr_list, scr, scr_next);
+
return 0;
}
cr_add(
LDAPContentRule *cr,
int user,
+ ContentRule **rscr,
const char **err
)
{
}
code = cr_insert(scr,err);
+ if ( code == 0 && rscr )
+ *rscr = scr;
return code;
}
+void
+cr_unparse( BerVarray *res, ContentRule *start, ContentRule *end, int sys )
+{
+ ContentRule *cr;
+ int i, num;
+ struct berval bv, *bva = NULL, idx;
+ char ibuf[32], *ptr;
+
+ if ( !start )
+ start = LDAP_STAILQ_FIRST( &cr_list );
+
+ /* count the result size */
+ i = 0;
+ for ( cr=start; cr; cr=LDAP_STAILQ_NEXT(cr, scr_next)) {
+ if ( sys && !(cr->scr_flags & SLAP_CR_HARDCODE)) continue;
+ i++;
+ if ( cr == end ) break;
+ }
+ if (!i) return;
+
+ num = i;
+ bva = ch_malloc( (num+1) * sizeof(struct berval) );
+ BER_BVZERO( bva );
+ idx.bv_val = ibuf;
+ if ( sys ) {
+ idx.bv_len = 0;
+ ibuf[0] = '\0';
+ }
+ i = 0;
+ for ( cr=start; cr; cr=LDAP_STAILQ_NEXT(cr, scr_next)) {
+ if ( sys && !(cr->scr_flags & SLAP_CR_HARDCODE)) continue;
+ if ( ldap_contentrule2bv( &cr->scr_crule, &bv ) == NULL ) {
+ ber_bvarray_free( bva );
+ }
+ if ( !sys ) {
+ idx.bv_len = sprintf(idx.bv_val, "{%02d}", i);
+ }
+ bva[i].bv_len = idx.bv_len + bv.bv_len;
+ bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
+ strcpy( bva[i].bv_val, ibuf );
+ strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
+ i++;
+ bva[i].bv_val = NULL;
+ ldap_memfree( bv.bv_val );
+ if ( cr == end ) break;
+ }
+ *res = bva;
+}
+
int
cr_schema_info( Entry *e )
{
struct berval val;
struct berval nval;
- LDAP_SLIST_FOREACH(cr, &cr_list, scr_next) {
+ LDAP_STAILQ_FOREACH(cr, &cr_list, scr_next) {
if ( ldap_contentrule2bv( &cr->scr_crule, &val ) == NULL ) {
return -1;
}