Implement slapi_entry_size()

This commit is contained in:
Luke Howard 2004-05-23 12:12:43 +00:00
parent 13e657ffa8
commit f62d1aac4e
2 changed files with 30 additions and 1 deletions

View file

@ -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);

View file

@ -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.
*