/* syntax.c - routines to manage syntax definitions */
/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
static int
syn_index_name_cmp(
- char *name,
+ const char *name,
struct sindexrec *sir
)
{
struct sindexrec *sir = NULL;
if ( (sir = (struct sindexrec *) avl_find( syn_index, synname,
- (AVL_CMP) syn_index_name_cmp )) != NULL ) {
+ (AVL_CMP) syn_index_name_cmp )) != NULL ) {
return( sir->sir_syn );
}
return( NULL );
return( NULL );
}
+void
+syn_destroy( void )
+{
+ Syntax *s, *n;
+
+ avl_free(syn_index, ldap_memfree);
+ for (s=syn_list; s; s=n) {
+ n = s->ssyn_next;
+ ldap_syntax_free((LDAPSyntax *)s);
+ }
+}
+
static int
syn_insert(
Syntax *ssyn,
(AVL_DUP) avl_dup_error ) ) {
*err = ssyn->ssyn_oid;
ldap_memfree(sir);
- return SLAP_SCHERR_DUP_SYNTAX;
+ return SLAP_SCHERR_SYN_DUP;
}
/* FIX: temporal consistency check */
syn_find(sir->sir_name);
int
syn_add(
- LDAP_SYNTAX *syn,
+ LDAPSyntax *syn,
unsigned flags,
slap_syntax_validate_func *validate,
slap_syntax_transform_func *normalize,
ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
- memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX) );
+ AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
ssyn->ssyn_next = NULL;
+ ssyn->ssyn_oidlen = strlen(syn->syn_oid);
ssyn->ssyn_flags = flags;
ssyn->ssyn_validate = validate;
ssyn->ssyn_normalize = normalize;
int
register_syntax(
- char * desc,
+ const char * desc,
unsigned flags,
slap_syntax_validate_func *validate,
- slap_syntax_transform_func *ber2str,
- slap_syntax_transform_func *str2ber )
+ slap_syntax_transform_func *normalize,
+ slap_syntax_transform_func *pretty )
{
- LDAP_SYNTAX *syn;
+ LDAPSyntax *syn;
int code;
const char *err;
syn = ldap_str2syntax( desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
if ( !syn ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "schema", LDAP_LEVEL_ERR,
+ "register_syntax: Error - %s before %s in %s.\n",
+ ldap_scherr2str(code), err, desc ));
+#else
Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
ldap_scherr2str(code), err, desc );
+#endif
+
return( -1 );
}
- code = syn_add( syn, flags, validate, ber2str, str2ber, &err );
+ code = syn_add( syn, flags, validate, normalize, pretty, &err );
ldap_memfree( syn );
if ( code ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "schema", LDAP_LEVEL_ERR,
+ "register_syntax: Error - %s %s in %s\n",
+ scherr2str(code), err, desc ));
+#else
Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
scherr2str(code), err, desc );
+#endif
+
return( -1 );
}
int
syn_schema_info( Entry *e )
{
- struct berval val;
- struct berval *vals[2];
+ struct berval vals[2];
Syntax *syn;
AttributeDescription *ad_ldapSyntaxes = slap_schema.si_ad_ldapSyntaxes;
- vals[0] = &val;
- vals[1] = NULL;
+ vals[1].bv_val = NULL;
for ( syn = syn_list; syn; syn = syn->ssyn_next ) {
- val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
- if ( val.bv_val == NULL ) {
+ if ( ! syn->ssyn_validate ) {
+ /* skip syntaxes without validators */
+ continue;
+ }
+ if ( syn->ssyn_flags & SLAP_SYNTAX_HIDE ) {
+ /* hide syntaxes */
+ continue;
+ }
+
+ if ( ldap_syntax2bv( &syn->ssyn_syn, vals ) == NULL ) {
return -1;
}
- val.bv_len = strlen( val.bv_val );
#if 0
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
+ "syn_schema_info: Merging syn [%ld] %s\n",
+ (long)vals[0].bv_len, vals[0].bv_val ));
+#else
Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
- (long) val.bv_len, val.bv_val, 0 );
+ (long) vals[0].bv_len, vals[0].bv_val, 0 );
+#endif
+
#endif
attr_merge( e, ad_ldapSyntaxes, vals );
- ldap_memfree( val.bv_val );
+ ldap_memfree( vals[0].bv_val );
}
return 0;
}