1 /* syntax.c - routines to manage syntax definitions */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
25 static Avlnode *syn_index = NULL;
26 static Syntax *syn_list = NULL;
30 struct sindexrec *sir1,
31 struct sindexrec *sir2
34 return (strcmp( sir1->sir_name, sir2->sir_name ));
43 return (strcmp( name, sir->sir_name ));
47 syn_find( const char *synname )
49 struct sindexrec *sir = NULL;
51 if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
52 (AVL_CMP) syn_index_name_cmp )) != NULL ) {
53 return( sir->sir_syn );
59 syn_find_desc( const char *syndesc, int *len )
63 for (synp = syn_list; synp; synp = synp->ssyn_next)
64 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{')))
74 avl_free(syn_index, ldap_memfree);
75 for (s=syn_list; s; s=n) {
77 ldap_syntax_free((LDAPSyntax *)s);
88 struct sindexrec *sir;
91 while ( *synp != NULL ) {
92 synp = &(*synp)->ssyn_next;
96 if ( ssyn->ssyn_oid ) {
97 sir = (struct sindexrec *)
98 ch_calloc( 1, sizeof(struct sindexrec) );
99 sir->sir_name = ssyn->ssyn_oid;
101 if ( avl_insert( &syn_index, (caddr_t) sir,
102 (AVL_CMP) syn_index_cmp,
103 (AVL_DUP) avl_dup_error ) ) {
104 *err = ssyn->ssyn_oid;
106 return SLAP_SCHERR_DUP_SYNTAX;
108 /* FIX: temporal consistency check */
109 syn_find(sir->sir_name);
118 slap_syntax_validate_func *validate,
119 slap_syntax_transform_func *normalize,
120 slap_syntax_transform_func *pretty,
121 #ifdef SLAPD_BINARY_CONVERSION
122 slap_syntax_transform_func *ber2str,
123 slap_syntax_transform_func *str2ber,
131 ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
133 AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
135 ssyn->ssyn_next = NULL;
137 ssyn->ssyn_flags = flags;
138 ssyn->ssyn_validate = validate;
139 ssyn->ssyn_normalize = normalize;
140 ssyn->ssyn_pretty = pretty;
142 #ifdef SLAPD_BINARY_CONVERSION
143 ssyn->ssyn_ber2str = ber2str;
144 ssyn->ssyn_str2ber = str2ber;
147 code = syn_insert(ssyn, err);
155 slap_syntax_validate_func *validate,
156 slap_syntax_transform_func *normalize,
157 slap_syntax_transform_func *pretty )
163 syn = ldap_str2syntax( desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
166 LDAP_LOG(( "schema", LDAP_LEVEL_ERR,
167 "register_syntax: Error - %s before %s in %s.\n",
168 ldap_scherr2str(code), err, desc ));
170 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
171 ldap_scherr2str(code), err, desc );
177 code = syn_add( syn, flags, validate, normalize, pretty, &err );
183 LDAP_LOG(( "schema", LDAP_LEVEL_ERR,
184 "register_syntax: Error - %s %s in %s\n",
185 scherr2str(code), err, desc ));
187 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
188 scherr2str(code), err, desc );
197 #if defined( SLAPD_SCHEMA_DN )
200 syn_schema_info( Entry *e )
203 struct berval *vals[2];
206 AttributeDescription *ad_ldapSyntaxes = slap_schema.si_ad_ldapSyntaxes;
211 for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
212 if ( ! syn->ssyn_validate ) {
213 /* skip syntaxes without validators */
216 if ( syn->ssyn_flags & SLAP_SYNTAX_HIDE ) {
221 if ( ldap_syntax2bv( &syn->ssyn_syn, &val ) == NULL ) {
226 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
227 "syn_schema_info: Merging syn [%ld] %s\n",
228 (long)val.bv_len, val.bv_val ));
230 Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
231 (long) val.bv_len, val.bv_val, 0 );
235 attr_merge( e, ad_ldapSyntaxes, vals );
236 ldap_memfree( val.bv_val );