1 /* syntax.c - routines to manage syntax definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
32 static Avlnode *syn_index = NULL;
33 static LDAP_SLIST_HEAD(SyntaxList, Syntax) syn_list
34 = LDAP_SLIST_HEAD_INITIALIZER(&syn_list);
42 const struct sindexrec *sir1 = v_sir1, *sir2 = v_sir2;
43 return (strcmp( sir1->sir_name, sir2->sir_name ));
52 return (strcmp( name, ((const struct sindexrec *)sir)->sir_name ));
56 syn_find( const char *synname )
58 struct sindexrec *sir = NULL;
60 if ( (sir = avl_find( syn_index, synname, syn_index_name_cmp )) != NULL ) {
61 return( sir->sir_syn );
67 syn_find_desc( const char *syndesc, int *len )
71 LDAP_SLIST_FOREACH(synp, &syn_list, ssyn_next) {
72 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{' /*'}'*/ ))) {
84 avl_free(syn_index, ldap_memfree);
85 while( !LDAP_SLIST_EMPTY(&syn_list) ) {
86 s = LDAP_SLIST_FIRST(&syn_list);
87 LDAP_SLIST_REMOVE_HEAD(&syn_list, ssyn_next);
88 ldap_syntax_free((LDAPSyntax *)s);
98 struct sindexrec *sir;
100 LDAP_SLIST_NEXT( ssyn, ssyn_next ) = NULL;
101 LDAP_SLIST_INSERT_HEAD( &syn_list, ssyn, ssyn_next );
103 if ( ssyn->ssyn_oid ) {
104 sir = (struct sindexrec *)
105 SLAP_CALLOC( 1, sizeof(struct sindexrec) );
107 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
110 sir->sir_name = ssyn->ssyn_oid;
112 if ( avl_insert( &syn_index, (caddr_t) sir,
113 syn_index_cmp, avl_dup_error ) ) {
114 *err = ssyn->ssyn_oid;
116 return SLAP_SCHERR_SYN_DUP;
118 /* FIX: temporal consistency check */
119 syn_find(sir->sir_name);
127 slap_syntax_defs_rec *def,
134 ssyn = (Syntax *) SLAP_CALLOC( 1, sizeof(Syntax) );
136 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
140 AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
142 LDAP_SLIST_NEXT(ssyn,ssyn_next) = NULL;
145 * note: ssyn_bvoid uses the same memory of ssyn_syn.syn_oid;
146 * ssyn_oidlen is #defined as ssyn_bvoid.bv_len
148 ssyn->ssyn_bvoid.bv_val = ssyn->ssyn_syn.syn_oid;
149 ssyn->ssyn_oidlen = strlen(syn->syn_oid);
150 ssyn->ssyn_flags = def->sd_flags;
151 ssyn->ssyn_validate = def->sd_validate;
152 ssyn->ssyn_pretty = def->sd_pretty;
154 #ifdef SLAPD_BINARY_CONVERSION
155 ssyn->ssyn_ber2str = def->sd_ber2str;
156 ssyn->ssyn_str2ber = def->sd_str2ber;
159 code = syn_insert(ssyn, err);
165 slap_syntax_defs_rec *def )
171 syn = ldap_str2syntax( def->sd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
173 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
174 ldap_scherr2str(code), err, def->sd_desc );
179 code = syn_add( syn, def, &err );
182 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
183 scherr2str(code), err, def->sd_desc );
184 ldap_syntax_free( syn );
195 syn_schema_info( Entry *e )
197 AttributeDescription *ad_ldapSyntaxes = slap_schema.si_ad_ldapSyntaxes;
202 LDAP_SLIST_FOREACH(syn, &syn_list, ssyn_next ) {
203 if ( ! syn->ssyn_validate ) {
204 /* skip syntaxes without validators */
207 if ( syn->ssyn_flags & SLAP_SYNTAX_HIDE ) {
212 if ( ldap_syntax2bv( &syn->ssyn_syn, &val ) == NULL ) {
216 Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
217 (long) val.bv_len, val.bv_val, 0 );
220 nval.bv_val = syn->ssyn_oid;
221 nval.bv_len = strlen(syn->ssyn_oid);
223 if( attr_merge_one( e, ad_ldapSyntaxes, &val, &nval ) )
227 ldap_memfree( val.bv_val );