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) );
109 LDAP_LOG( OPERATION, ERR,
110 "syn_insert: SLAP_CALLOC Error\n", 0, 0, 0 );
112 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
116 sir->sir_name = ssyn->ssyn_oid;
118 if ( avl_insert( &syn_index, (caddr_t) sir,
119 syn_index_cmp, avl_dup_error ) ) {
120 *err = ssyn->ssyn_oid;
122 return SLAP_SCHERR_SYN_DUP;
124 /* FIX: temporal consistency check */
125 syn_find(sir->sir_name);
133 slap_syntax_defs_rec *def,
140 ssyn = (Syntax *) SLAP_CALLOC( 1, sizeof(Syntax) );
143 LDAP_LOG( OPERATION, ERR,
144 "syn_add: SLAP_CALLOC Error\n", 0, 0, 0 );
146 Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
151 AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
153 LDAP_SLIST_NEXT(ssyn,ssyn_next) = NULL;
156 * note: ssyn_bvoid uses the same memory of ssyn_syn.syn_oid;
157 * ssyn_oidlen is #defined as ssyn_bvoid.bv_len
159 ssyn->ssyn_bvoid.bv_val = ssyn->ssyn_syn.syn_oid;
160 ssyn->ssyn_oidlen = strlen(syn->syn_oid);
161 ssyn->ssyn_flags = def->sd_flags;
162 ssyn->ssyn_validate = def->sd_validate;
163 ssyn->ssyn_pretty = def->sd_pretty;
165 #ifdef SLAPD_BINARY_CONVERSION
166 ssyn->ssyn_ber2str = def->sd_ber2str;
167 ssyn->ssyn_str2ber = def->sd_str2ber;
170 code = syn_insert(ssyn, err);
176 slap_syntax_defs_rec *def )
182 syn = ldap_str2syntax( def->sd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
185 LDAP_LOG( CONFIG, ERR,
186 "register_syntax: Error - %s before %s in %s.\n",
187 ldap_scherr2str(code), err, def->sd_desc );
189 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
190 ldap_scherr2str(code), err, def->sd_desc );
196 code = syn_add( syn, def, &err );
202 LDAP_LOG( CONFIG, ERR,
203 "register_syntax: Error - %s %s in %s\n",
204 scherr2str(code), err, def->sd_desc );
206 Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
207 scherr2str(code), err, def->sd_desc );
217 syn_schema_info( Entry *e )
219 AttributeDescription *ad_ldapSyntaxes = slap_schema.si_ad_ldapSyntaxes;
224 LDAP_SLIST_FOREACH(syn, &syn_list, ssyn_next ) {
225 if ( ! syn->ssyn_validate ) {
226 /* skip syntaxes without validators */
229 if ( syn->ssyn_flags & SLAP_SYNTAX_HIDE ) {
234 if ( ldap_syntax2bv( &syn->ssyn_syn, &val ) == NULL ) {
239 LDAP_LOG( config, ENTRY,
240 "syn_schema_info: Merging syn [%ld] %s\n",
241 (long)val.bv_len, val.bv_val, 0 );
243 Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
244 (long) val.bv_len, val.bv_val, 0 );
248 nval.bv_val = syn->ssyn_oid;
249 nval.bv_len = strlen(syn->ssyn_oid);
251 if( attr_merge_one( e, ad_ldapSyntaxes, &val, &nval ) )
255 ldap_memfree( val.bv_val );