From: Kurt Zeilenga Date: Tue, 29 Oct 2002 02:18:10 +0000 (+0000) Subject: HasSubordinate stuff X-Git-Tag: OPENLDAP_REL_ENG_2_1_9~50 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3451144dc5c972be06626abedef8293f50cb300d;p=openldap HasSubordinate stuff --- diff --git a/servers/slapd/back-ldbm/external.h b/servers/slapd/back-ldbm/external.h new file mode 100644 index 0000000000..93b40b1dd4 --- /dev/null +++ b/servers/slapd/back-ldbm/external.h @@ -0,0 +1,65 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#ifndef _LDBM_EXTERNAL_H +#define _LDBM_EXTERNAL_H + +LDAP_BEGIN_DECL + +extern BI_init ldbm_back_initialize; +extern BI_open ldbm_back_open; +extern BI_close ldbm_back_close; +extern BI_destroy ldbm_back_destroy; + +extern BI_db_init ldbm_back_db_init; +extern BI_db_open ldbm_back_db_open; +extern BI_db_close ldbm_back_db_close; +extern BI_db_destroy ldbm_back_db_destroy; + +extern BI_db_config ldbm_back_db_config; + +extern BI_op_extended ldbm_back_extended; + +extern BI_op_bind ldbm_back_bind; + +extern BI_op_search ldbm_back_search; + +extern BI_op_compare ldbm_back_compare; + +extern BI_op_modify ldbm_back_modify; + +extern BI_op_modrdn ldbm_back_modrdn; + +extern BI_op_add ldbm_back_add; + +extern BI_op_delete ldbm_back_delete; + +extern BI_acl_group ldbm_back_group; + +extern BI_acl_attribute ldbm_back_attribute; + +extern BI_operational ldbm_back_operational; + +#ifdef SLAP_X_FILTER_HASSUBORDINATES +extern BI_has_subordinates ldbm_back_hasSubordinates; +#endif /* SLAP_X_FILTER_HASSUBORDINATES */ + +/* hooks for slap tools */ +extern BI_tool_entry_open ldbm_tool_entry_open; +extern BI_tool_entry_close ldbm_tool_entry_close; +extern BI_tool_entry_first ldbm_tool_entry_first; +extern BI_tool_entry_next ldbm_tool_entry_next; +extern BI_tool_entry_get ldbm_tool_entry_get; +extern BI_tool_entry_put ldbm_tool_entry_put; + +extern BI_tool_entry_reindex ldbm_tool_entry_reindex; +extern BI_tool_sync ldbm_tool_sync; + +extern BI_chk_referrals ldbm_back_referrals; + +LDAP_END_DECL + +#endif /* _LDBM_EXTERNAL_H */ diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index be55fac73c..327b0b79a9 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -71,6 +71,9 @@ ldbm_back_initialize( bi->bi_acl_attribute = ldbm_back_attribute; bi->bi_chk_referrals = ldbm_back_referrals; bi->bi_operational = ldbm_back_operational; +#ifdef SLAP_X_FILTER_HASSUBORDINATES + bi->bi_has_subordinates = ldbm_back_hasSubordinates; +#endif /* SLAP_X_FILTER_HASSUBORDINATES */ /* * hooks for slap tools diff --git a/servers/slapd/back-ldbm/operational.c b/servers/slapd/back-ldbm/operational.c new file mode 100644 index 0000000000..bc68116c28 --- /dev/null +++ b/servers/slapd/back-ldbm/operational.c @@ -0,0 +1,69 @@ +/* operational.c - ldbm backend operational attributes function */ +/* + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include + +#include +#include + +#include "slap.h" +#include "back-ldbm.h" +#include "proto-back-ldbm.h" + +/* + * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE + * if the entry has children or not. + */ +int +ldbm_back_hasSubordinates( + BackendDB *be, + Connection *conn, + Operation *op, + Entry *e, + int *hasSubordinates ) +{ + if ( has_children( be, e ) ) { + *hasSubordinates = LDAP_COMPARE_TRUE; + + } else { + *hasSubordinates = LDAP_COMPARE_FALSE; + } + + return 0; +} + +/* + * sets the supported operational attributes (if required) + */ +int +ldbm_back_operational( + BackendDB *be, + Connection *conn, + Operation *op, + Entry *e, + AttributeName *attrs, + int opattrs, + Attribute **a ) +{ + Attribute **aa = a; + + assert( e ); + + if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, attrs ) ) { + int hs; + + hs = has_children( be, e ); + *aa = slap_operational_hasSubordinate( hs ); + if ( *aa != NULL ) { + aa = &(*aa)->a_next; + } + } + + return 0; +} + diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index eac5f831e9..1d41140078 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -57,10 +57,6 @@ ldbm_back_search( struct slap_limits_set *limit = NULL; int isroot = 0; -#ifdef SLAP_X_FILTER_HASSUBORDINATES - int filter_hasSubordinates = 0; -#endif /* SLAP_X_FILTER_HASSUBORDINATES */ - #ifdef NEW_LOGGING LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_search: enter\n", 0, 0, 0 ); #else @@ -292,22 +288,11 @@ searchit: /* compute it anyway; root does not use it */ stoptime = op->o_time + tlimit; -#ifdef SLAP_X_FILTER_HASSUBORDINATES - /* - * is hasSubordinates used in the filter ? - * FIXME: we may compute this directly when parsing the filter - */ - filter_hasSubordinates = filter_has_subordinates( filter ); -#endif /* SLAP_X_FILTER_HASSUBORDINATES */ - for ( id = idl_firstid( candidates, &cursor ); id != NOID; id = idl_nextid( candidates, &cursor ) ) { int scopeok = 0; int result = 0; -#ifdef SLAP_X_FILTER_HASSUBORDINATES - Attribute *hasSubordinates = NULL; -#endif /* SLAP_X_FILTER_HASSUBORDINATES */ /* check for abandon */ if ( op->o_abandon ) { @@ -436,43 +421,9 @@ searchit: goto loop_continue; } -#ifdef SLAP_X_FILTER_HASSUBORDINATES - /* - * if hasSubordinates is used in the filter, - * append it to the entry's attributes - */ - if ( filter_hasSubordinates ) { - int hs; - - hs = has_children( be, e ); - hasSubordinates = slap_operational_hasSubordinate( hs ); - if ( hasSubordinates == NULL ) { - goto loop_continue; - } - - hasSubordinates->a_next = e->e_attrs; - e->e_attrs = hasSubordinates; - } -#endif /* SLAP_X_FILTER_HASSUBORDINATES */ - /* if it matches the filter and scope, send it */ result = test_filter( be, conn, op, e, filter ); -#ifdef SLAP_X_FILTER_HASSUBORDINATES - if ( hasSubordinates ) { - /* - * FIXME: this is fairly inefficient, because - * if hasSubordinates is among the required - * attrs, it will be added again later; - * maybe we should leave it and check - * check later if it's already present, - * if required - */ - e->e_attrs = e->e_attrs->a_next; - attr_free( hasSubordinates ); - } -#endif /* SLAP_X_FILTER_HASSUBORDINATES */ - if ( result == LDAP_COMPARE_TRUE ) { struct berval dn;