From a056542cd1e228678b458550a43f5b0076f9b726 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Mar 11 2013 19:57:53 +0000 Subject: Ticket 571 - Need attribute syntax functions from master Needed to add attr_syntax_get_by_name_with_default() and slapi_attr_init_syntax(). https://fedorahosted.org/389/ticket/571 (cherry picked from commit 1a194f0ac1a9ffe010ae2bc3869434df4031bc3f) --- diff --git a/ldap/servers/slapd/attr.c b/ldap/servers/slapd/attr.c index 87dfe1e..0dd0393 100644 --- a/ldap/servers/slapd/attr.c +++ b/ldap/servers/slapd/attr.c @@ -229,6 +229,34 @@ slapi_attr_init(Slapi_Attr *a, const char *type) return slapi_attr_init_locking_optional(a, type, PR_TRUE); } +int +slapi_attr_init_syntax(Slapi_Attr *a) +{ + int rc = 1; + struct asyntaxinfo *asi = NULL; + char *tmp = 0; + const char *basetype= NULL; + char buf[SLAPD_TYPICAL_ATTRIBUTE_NAME_MAX_LENGTH]; + + basetype = buf; + tmp = slapi_attr_basetype(a->a_type, buf, sizeof(buf)); + if (tmp) { + basetype = buf; + } + asi = attr_syntax_get_by_name_with_default (basetype); + if (asi) { + rc = 0; + a->a_plugin = asi->asi_plugin; + a->a_flags = asi->asi_flags; + a->a_mr_eq_plugin = asi->asi_mr_eq_plugin; + a->a_mr_ord_plugin = asi->asi_mr_ord_plugin; + a->a_mr_sub_plugin = asi->asi_mr_sub_plugin; + } + if (tmp) + slapi_ch_free_string(&tmp); + return rc; +} + Slapi_Attr * slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock) { diff --git a/ldap/servers/slapd/attrsyntax.c b/ldap/servers/slapd/attrsyntax.c index ff137a8..61503f3 100644 --- a/ldap/servers/slapd/attrsyntax.c +++ b/ldap/servers/slapd/attrsyntax.c @@ -302,6 +302,15 @@ attr_syntax_get_by_name(const char *name) return attr_syntax_get_by_name_locking_optional(name, PR_TRUE); } +struct asyntaxinfo * +attr_syntax_get_by_name_with_default(const char *name) +{ + struct asyntaxinfo *asi = NULL; + asi = attr_syntax_get_by_name_locking_optional(name, PR_TRUE); + if (asi == NULL) + asi = attr_syntax_get_by_name(ATTR_WITH_OCTETSTRING_SYNTAX); + return asi; +} /* * A version of attr_syntax_get_by_name() that allows you to bypass using diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h index bdcef9a..c3ac3c7 100644 --- a/ldap/servers/slapd/proto-slap.h +++ b/ldap/servers/slapd/proto-slap.h @@ -132,6 +132,7 @@ void attr_syntax_delete_all_not_flagged( unsigned long flag ); struct asyntaxinfo *attr_syntax_get_by_oid ( const char *oid ); struct asyntaxinfo *attr_syntax_get_by_name ( const char *name ); struct asyntaxinfo *attr_syntax_get_by_name_locking_optional ( const char *name, PRBool use_lock ); +struct asyntaxinfo *attr_syntax_get_by_name_with_default ( const char *name ); /* * Call attr_syntax_return() when you are done using a value returned * by attr_syntax_get_by_oid() or attr_syntax_get_by_name(). diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h index ddeac62..9648b4c 100644 --- a/ldap/servers/slapd/slapi-private.h +++ b/ldap/servers/slapd/slapi-private.h @@ -352,6 +352,7 @@ int entry_add_dncsn_ext(Slapi_Entry *entry, const CSN *csn, PRUint32 flags); Slapi_Attr *slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock); int attr_set_csn( Slapi_Attr *a, const CSN *csn); int attr_set_deletion_csn( Slapi_Attr *a, const CSN *csn); +int slapi_attr_init_syntax(Slapi_Attr *a); const CSN *attr_get_deletion_csn(const Slapi_Attr *a); int attr_first_deleted_value( Slapi_Attr *a, Slapi_Value **v ); int attr_next_deleted_value( Slapi_Attr *a, int hint, Slapi_Value **v);