From: Luke Howard Date: Wed, 22 Jan 2003 09:35:48 +0000 (+0000) Subject: Added slapi_entry_attr_get_charptr() API X-Git-Tag: NO_SLAP_OP_BLOCKS~548 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=921d62c2ae28fc63543fa3d931c7d7860d8e6547;p=openldap Added slapi_entry_attr_get_charptr() API --- diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 125c8a62c9..b961f48a2b 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -285,6 +285,35 @@ slapi_entry_attr_find( #endif /* !defined(LDAP_SLAPI) */ } +char * +slapi_entry_attr_get_charptr( 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 NULL; + } + + attr = attr_find( e->e_attrs, ad ); + if ( attr == NULL ) { + return NULL; + } + + if ( attr->a_vals != NULL && attr->a_vals[0].bv_val != NULL ) { + return slapi_ch_strdup( attr->a_vals[0].bv_val ); + } + + return NULL; +#else + return -1; +#endif +} + /* * FIXME -- The caller must free the allocated memory. * In Netscape they do not have to. diff --git a/servers/slapd/slapi/slapi_utils.h b/servers/slapd/slapi/slapi_utils.h index 3d2c2d7eab..88487a9548 100644 --- a/servers/slapd/slapi/slapi_utils.h +++ b/servers/slapd/slapi/slapi_utils.h @@ -47,6 +47,7 @@ Slapi_Entry *slapi_str2entry( char *s, int flags ); char *slapi_entry2str( Slapi_Entry *e, int *len ); 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 ); char *slapi_entry_get_dn( Slapi_Entry *e ); int slapi_x_entry_get_id( Slapi_Entry *e );