]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syntax.c
use ldap_charray_free() instead of slapd's charray_free()
[openldap] / servers / slapd / syntax.c
index e26fe835c53d529993172aab8fc1da936444bdca..21fef110ea09d58f0a9e4567a4f591a692ec79a2 100644 (file)
@@ -1,7 +1,7 @@
 /* syntax.c - routines to manage syntax definitions */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -16,7 +16,6 @@
 #include "slap.h"
 #include "ldap_pvt.h"
 
-
 struct sindexrec {
        char            *sir_name;
        Syntax          *sir_syn;
@@ -36,7 +35,7 @@ syn_index_cmp(
 
 static int
 syn_index_name_cmp(
-    char               *name,
+    const char         *name,
     struct sindexrec   *sir
 )
 {
@@ -49,7 +48,7 @@ syn_find( const char *synname )
        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 );
@@ -66,6 +65,18 @@ syn_find_desc( const char *syndesc, int *len )
        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,
@@ -91,7 +102,7 @@ syn_insert(
                                 (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);
@@ -101,11 +112,8 @@ syn_insert(
 
 int
 syn_add(
-    LDAP_SYNTAX                *syn,
-       int flags,
-    slap_syntax_validate_func  *validate,
-    slap_syntax_transform_func *ber2str,
-    slap_syntax_transform_func *str2ber,
+    LDAPSyntax         *syn,
+    slap_syntax_defs_rec *def,
     const char         **err
 )
 {
@@ -113,39 +121,62 @@ syn_add(
        int             code;
 
        ssyn = (Syntax *) ch_calloc( 1, sizeof(Syntax) );
-       memcpy( &ssyn->ssyn_syn, syn, sizeof(LDAP_SYNTAX));
 
-       ssyn->ssyn_flags = flags;
-       ssyn->ssyn_validate = validate;
-       ssyn->ssyn_ber2str = ber2str;
-       ssyn->ssyn_str2ber = str2ber;
+       AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
 
-       code = syn_insert(ssyn,err);
+       ssyn->ssyn_next = NULL;
+
+       ssyn->ssyn_oidlen = strlen(syn->syn_oid);
+       ssyn->ssyn_flags = def->sd_flags;
+       ssyn->ssyn_validate = def->sd_validate;
+       ssyn->ssyn_normalize = def->sd_normalize;
+       ssyn->ssyn_pretty = def->sd_pretty;
+
+#ifdef SLAPD_BINARY_CONVERSION
+       ssyn->ssyn_ber2str = def->sd_ber2str;
+       ssyn->ssyn_str2ber = def->sd_str2ber;
+#endif
+
+       code = syn_insert(ssyn, err);
        return code;
 }
 
 int
 register_syntax(
-       char * desc, int flags,
-       slap_syntax_validate_func *validate,
-       slap_syntax_transform_func *ber2str,
-       slap_syntax_transform_func *str2ber )
+       slap_syntax_defs_rec *def )
 {
-       LDAP_SYNTAX     *syn;
+       LDAPSyntax      *syn;
        int             code;
        const char      *err;
 
-       syn = ldap_str2syntax( desc, &code, &err);
+       syn = ldap_str2syntax( def->sd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
        if ( !syn ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( CONFIG, ERR, 
+                       "register_syntax: Error - %s before %s in %s.\n",
+                       ldap_scherr2str(code), err, def->sd_desc );
+#else
                Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n",
-                   ldap_scherr2str(code), err, desc );
+                   ldap_scherr2str(code), err, def->sd_desc );
+#endif
+
                return( -1 );
        }
 
-       code = syn_add( syn, flags, validate, ber2str, str2ber, &err );
+       code = syn_add( syn, def, &err );
+
+       ldap_memfree( syn );
+
        if ( code ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( CONFIG, ERR, 
+                       "register_syntax: Error - %s %s in %s\n", 
+                       scherr2str(code), err, def->sd_desc );
+#else
                Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
-                   scherr2str(code), err, desc );
+                   scherr2str(code), err, def->sd_desc );
+#endif
+
                return( -1 );
        }
 
@@ -157,24 +188,39 @@ register_syntax(
 int
 syn_schema_info( Entry *e )
 {
-       struct berval   val;
-       struct berval   *vals[2];
+       struct berval   vals[2];
        Syntax          *syn;
 
-       vals[0] = &val;
-       vals[1] = NULL;
+       AttributeDescription *ad_ldapSyntaxes = slap_schema.si_ad_ldapSyntaxes;
+
+       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 ) {
-                       val.bv_len = strlen( val.bv_val );
-                       Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
-                              (long) val.bv_len, val.bv_val, 0 );
-                       attr_merge( e, "ldapSyntaxes", vals );
-                       ldap_memfree( val.bv_val );
-               } else {
+               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;
                }
+#if 0
+#ifdef NEW_LOGGING
+               LDAP_LOG( config, ENTRY,
+                          "syn_schema_info: Merging syn [%ld] %s\n",
+                          (long)vals[0].bv_len, vals[0].bv_val, 0 );
+#else
+               Debug( LDAP_DEBUG_TRACE, "Merging syn [%ld] %s\n",
+              (long) vals[0].bv_len, vals[0].bv_val, 0 );
+#endif
+
+#endif
+               attr_merge( e, ad_ldapSyntaxes, vals );
+               ldap_memfree( vals[0].bv_val );
        }
        return 0;
 }