From: Luke Howard Date: Sun, 23 May 2004 12:12:43 +0000 (+0000) Subject: Implement slapi_entry_size() X-Git-Tag: OPENDLAP_REL_ENG_2_2_MP~341 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f62d1aac4e7bc315dcde729ee6b5c276b4b5c0ff;p=openldap Implement slapi_entry_size() --- diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index a4412be146..7e256aab5a 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -49,7 +49,7 @@ extern void slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l); extern void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l); extern int slapi_is_rootdse( const char *dn ); extern int slapi_entry_has_children(const Slapi_Entry *e); - +size_t slapi_entry_size(Slapi_Entry *e); extern int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals ); extern int slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals ); extern int slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs); diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 735f81a651..c68f48d651 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -558,6 +558,35 @@ slapi_entry_has_children(const Slapi_Entry *e) #endif } +/* + * Return approximate size of the entry rounded to the nearest + * 1K. Only the size of the attribute values are counted in the + * Sun implementation. + * + * http://docs.sun.com/source/816-6701-10/funcref.html#1017388 + */ +size_t slapi_entry_size(Slapi_Entry *e) +{ +#ifdef LDAP_SLAPI + size_t size; + Attribute *a; + int i; + + for ( size = 0, a = e->e_attrs; a != NULL; a->a_next ) { + for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) { + size += a->a_vals[i].bv_len + 1; + } + } + + size += 1023; + size -= (size % 1024); + + return size; +#else + return 0; +#endif /* LDAP_SLAPI */ +} + /* * Add values to entry. *