1 /* syntax.c - routines to manage syntax definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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>
33 static Avlnode *syn_index = NULL;
34 static LDAP_SLIST_HEAD(SyntaxList, slap_syntax) syn_list
35 = LDAP_SLIST_HEAD_INITIALIZER(&syn_list);
43 const struct sindexrec *sir1 = v_sir1, *sir2 = v_sir2;
44 return (strcmp( sir1->sir_name, sir2->sir_name ));
53 return (strcmp( name, ((const struct sindexrec *)sir)->sir_name ));
57 syn_find( const char *synname )
59 struct sindexrec *sir = NULL;
61 if ( (sir = avl_find( syn_index, synname, syn_index_name_cmp )) != NULL ) {
62 return( sir->sir_syn );
68 syn_find_desc( const char *syndesc, int *len )
72 LDAP_SLIST_FOREACH(synp, &syn_list, ssyn_next) {
73 if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{' /*'}'*/ ))) {
85 avl_free(syn_index, ldap_memfree);
86 while( !LDAP_SLIST_EMPTY(&syn_list) ) {
87 s = LDAP_SLIST_FIRST(&syn_list);
88 LDAP_SLIST_REMOVE_HEAD(&syn_list, ssyn_next);
89 ldap_syntax_free((LDAPSyntax *)s);
99 struct sindexrec *sir;
101 LDAP_SLIST_NEXT( ssyn, ssyn_next ) = NULL;
102 LDAP_SLIST_INSERT_HEAD( &syn_list, ssyn, ssyn_next );
104 if ( ssyn->ssyn_oid ) {
105 sir = (struct sindexrec *)
106 SLAP_CALLOC( 1, sizeof(struct sindexrec) );
108 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
111 sir->sir_name = ssyn->ssyn_oid;
113 if ( avl_insert( &syn_index, (caddr_t) sir,
114 syn_index_cmp, avl_dup_error ) ) {
115 *err = ssyn->ssyn_oid;
117 return SLAP_SCHERR_SYN_DUP;
119 /* FIX: temporal consistency check */
120 syn_find(sir->sir_name);
128 slap_syntax_defs_rec *def,
135 ssyn = (Syntax *) SLAP_CALLOC( 1, sizeof(Syntax) );
137 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
141 AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
143 LDAP_SLIST_NEXT(ssyn,ssyn_next) = NULL;
146 * note: ssyn_bvoid uses the same memory of ssyn_syn.syn_oid;
147 * ssyn_oidlen is #defined as ssyn_bvoid.bv_len
149 ssyn->ssyn_bvoid.bv_val = ssyn->ssyn_syn.syn_oid;
150 ssyn->ssyn_oidlen = strlen(syn->syn_oid);
151 ssyn->ssyn_flags = def->sd_flags;
152 ssyn->ssyn_validate = def->sd_validate;
153 ssyn->ssyn_pretty = def->sd_pretty;
155 #ifdef SLAPD_BINARY_CONVERSION
156 ssyn->ssyn_ber2str = def->sd_ber2str;
157 ssyn->ssyn_str2ber = def->sd_str2ber;
160 code = syn_insert(ssyn, err);
166 slap_syntax_defs_rec *def )
172 syn = ldap_str2syntax( def->sd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
174 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
175 ldap_scherr2str(code), err, def->sd_desc );
180 code = syn_add( syn, def, &err );
185 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
186 scherr2str(code), err, def->sd_desc );
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 );