From: Luke Howard Date: Wed, 22 Jan 2003 10:00:27 +0000 (+0000) Subject: More DS 5.x harmonisation X-Git-Tag: NO_SLAP_OP_BLOCKS~547 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c76d37313be6da7ba470b8cc292172462fdb0b3a;p=openldap More DS 5.x harmonisation --- diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index b961f48a2b..5acfdbcb62 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -314,6 +314,178 @@ slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type ) #endif } +int +slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad = NULL; + const char *text; + int rc; + Attribute *attr; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return 0; + } + + return slapi_value_get_int( attr->a_vals ); +#else + return 0; +#endif +} + +int +slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad = NULL; + const char *text; + int rc; + Attribute *attr; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return 0; + } + + return slapi_value_get_long( attr->a_vals ); +#else + return 0; +#endif +} + +int +slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad = NULL; + const char *text; + int rc; + Attribute *attr; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return 0; + } + + return slapi_value_get_uint( attr->a_vals ); +#else + return 0; +#endif +} + +int +slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad = NULL; + const char *text; + int rc; + Attribute *attr; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return 0; + } + + return slapi_value_get_ulong( attr->a_vals ); +#else + return 0; +#endif +} + +int +slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value ) +{ +#ifdef LDAP_SLAPI + struct berval bv; + AttributeDescription *ad; + const char *text; + int rc; + Attribute *attr; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return 0; + } + + bv.bv_val = (char *)value; + bv.bv_len = strlen( value ); + + return slapi_attr_value_find( attr, &bv ); +#else + return 0; +#endif +} + +int +slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals ) +{ +#ifdef LDAP_SLAPI + return slapi_entry_attr_merge( e, (char *)type, vals ); +#else + return -1; +#endif +} + +int +slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad; + const char *text; + int rc; + BerVarray bv; + + rc = slap_str2ad( type, &ad, &text ); + if ( rc != LDAP_SUCCESS ) { + return 0; + } + + attr_delete( &e->e_attrs, ad ); + + rc = bvptr2obj( vals, &bv ); + if ( rc != LDAP_SUCCESS ) { + return -1; + } + + rc = attr_merge( e, ad, bv ); + slapi_ch_free( (void **)&bv ); + if ( rc != LDAP_SUCCESS ) { + return -1; + } + + return 0; +#else + return -1; +#endif /* LDAP_SLAPI */ +} + /* * FIXME -- The caller must free the allocated memory. * In Netscape they do not have to. @@ -1966,6 +2138,7 @@ int slapi_value_get_int(const Slapi_Value *value) { #ifdef LDAP_SLAPI if ( value == NULL ) return 0; + if ( value->bv_val == NULL ) return 0; if ( !checkBVString( value ) ) return 0; return (int)strtol( value->bv_val, NULL, 10 ); @@ -1978,6 +2151,7 @@ unsigned int slapi_value_get_uint(const Slapi_Value *value) { #ifdef LDAP_SLAPI if ( value == NULL ) return 0; + if ( value->bv_val == NULL ) return 0; if ( !checkBVString( value ) ) return 0; return (unsigned int)strtoul( value->bv_val, NULL, 10 ); @@ -1990,6 +2164,7 @@ long slapi_value_get_long(const Slapi_Value *value) { #ifdef LDAP_SLAPI if ( value == NULL ) return 0; + if ( value->bv_val == NULL ) return 0; if ( !checkBVString( value ) ) return 0; return strtol( value->bv_val, NULL, 10 ); @@ -2002,6 +2177,7 @@ unsigned long slapi_value_get_ulong(const Slapi_Value *value) { #ifdef LDAP_SLAPI if ( value == NULL ) return 0; + if ( value->bv_val == NULL ) return 0; if ( !checkBVString( value ) ) return 0; return strtoul( value->bv_val, NULL, 10 ); diff --git a/servers/slapd/slapi/slapi_utils.h b/servers/slapd/slapi/slapi_utils.h index 88487a9548..05f111b089 100644 --- a/servers/slapd/slapi/slapi_utils.h +++ b/servers/slapd/slapi/slapi_utils.h @@ -49,6 +49,12 @@ int slapi_entry_attr_merge( Slapi_Entry *e, char *type, struct berval **vals ); int slapi_entry_attr_find( Slapi_Entry *e, char *type, Slapi_Attr **attr ); char *slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type ); int slapi_entry_attr_delete( Slapi_Entry *e, char *type ); +int slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type ); +int slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type ); +int slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type ); +int slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type ); +int slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value ); +int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals ); char *slapi_entry_get_dn( Slapi_Entry *e ); int slapi_x_entry_get_id( Slapi_Entry *e ); void slapi_entry_set_dn( Slapi_Entry *e, char *dn );