]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/dn.c
Added connection initialisation and destruction notification. Now backends can regist...
[openldap] / servers / slapd / dn.c
index 38c4bdab89921976f6b9e6226be4e387d8db8c06..4f28d164b8989490de6b653ce3aa95a3328986c9 100644 (file)
 
 #include "slap.h"
 
-typedef enum DnState {
-       B4TYPE,                 /* before attribute type */
-       INTYPE,                 /* in     attribute type */
-       B4EQUAL,                /* before '=' */
-       B4VALUE,                /* before attribute value */
-       INVALUE,                /* in     attribute value */
-       INQUOTEDVALUE,          /* in "" in attribute value */
-       B4SEPARATOR,            /* before separator ('+', ',' or ';') */
-} DnState;
+#define B4TYPE         0
+#define INTYPE         1
+#define B4EQUAL                2
+#define B4VALUE                3
+#define INVALUE                4
+#define INQUOTEDVALUE  5
+#define B4SEPARATOR    6
 
 /*
- * dn_normalize_internal - put dn into a canonical form suitable for storing
- * in a hash database.  If correct_case == 1, this involves normalizing the case
- * as well as the format.  The dn is normalized in place as well as returned.
- *
- * The dn_normalize() and dn_normalize_case() macros use this function.
+ * dn_normalize - put dn into a canonical format.  the dn is
+ * normalized in place, as well as returned.
  */
 
 char *
-dn_normalize_internal( char *dn, int correct_case )
+dn_normalize( char *dn )
 {
-       char    *s, *d;         /* source and destination pointers */
-       char    *type;          /* start of attr.type when state==INTYPE */
-       int     gotesc;         /* last char was '\\' */
-       int     ic;             /* ignore case  */
-       DnState state;
+       char    *d, *s;
+       int     state, gotesc;
 
        /* Debug( LDAP_DEBUG_TRACE, "=> dn_normalize \"%s\"\n", dn, 0, 0 ); */
 
@@ -47,28 +39,18 @@ dn_normalize_internal( char *dn, int correct_case )
                case B4TYPE:
                        if ( ! SPACE( *s ) ) {
                                state = INTYPE;
-                               ic = 1;
-                               type = d;
-                               *d++ = TOUPPER( (unsigned char) *s );
+                               *d++ = *s;
                        }
                        break;
                case INTYPE:
                        if ( *s == '=' ) {
                                state = B4VALUE;
+                               *d++ = *s;
                        } else if ( SPACE( *s ) ) {
                                state = B4EQUAL;
                        } else {
-                               *d++ = TOUPPER( (unsigned char) *s );
-                               break;
-                       }
-                       /* Check if case is ignored in this type */
-                       if ( correct_case ) {
-                               *d = '\0';
-                               if ( ! (attr_syntax( type ) | SYNTAX_CIS) )
-                                       ic = 0;
+                               *d++ = *s;
                        }
-                       if (state == B4VALUE)
-                               *d++ = '=';
                        break;
                case B4EQUAL:
                        if ( *s == '=' ) {
@@ -76,7 +58,7 @@ dn_normalize_internal( char *dn, int correct_case )
                                *d++ = *s;
                        } else if ( ! SPACE( *s ) ) {
                                /* not a valid dn - but what can we do here? */
-                               *d++ = TOUPPER( (unsigned char) *s );
+                               *d++ = *s;
                        }
                        break;
                case B4VALUE:
@@ -85,7 +67,7 @@ dn_normalize_internal( char *dn, int correct_case )
                                *d++ = *s;
                        } else if ( ! SPACE( *s ) ) { 
                                state = INVALUE;
-                               *d++ = (ic ? TOUPPER((unsigned char) *s) : *s);
+                               *d++ = *s;
                        }
                        break;
                case INVALUE:
@@ -100,10 +82,10 @@ dn_normalize_internal( char *dn, int correct_case )
                                }
                        } else if ( gotesc && !NEEDSESCAPE( *s ) &&
                            !SEPARATOR( *s ) ) {
-                               *--d = (ic ? TOUPPER((unsigned char) *s) : *s);
+                               *--d = *s;
                                d++;
                        } else {
-                               *d++ = (ic ? TOUPPER((unsigned char) *s) : *s);
+                               *d++ = *s;
                        }
                        break;
                case INQUOTEDVALUE:
@@ -111,10 +93,10 @@ dn_normalize_internal( char *dn, int correct_case )
                                state = B4SEPARATOR;
                                *d++ = *s;
                        } else if ( gotesc && !NEEDSESCAPE( *s ) ) {
-                               *--d = (ic ? TOUPPER((unsigned char) *s) : *s);
+                               *--d = *s;
                                d++;
                        } else {
-                               *d++ = (ic ? TOUPPER((unsigned char) *s) : *s);
+                               *d++ = *s;
                        }
                        break;
                case B4SEPARATOR:
@@ -140,22 +122,27 @@ dn_normalize_internal( char *dn, int correct_case )
        return( dn );
 }
 
-
 /*
- * dn_casecmp - compare two DNs after normalizing (private copies of) them
+ * dn_normalize_case - put dn into a canonical form suitable for storing
+ * in a hash database.  this involves normalizing the case as well as
+ * the format.  the dn is normalized in place as well as returned.
  */
 
-int
-dn_casecmp( const char *dn1, const char *dn2 )
+char *
+dn_normalize_case( char *dn )
 {
-       char *ndn1 = dn_normalize_case( ch_strdup( dn1 ) );
-       char *ndn2 = dn_normalize_case( ch_strdup( dn2 ) );
-       int i = strcmp( ndn1, ndn2 );
-       free( ndn1 );
-       free( ndn2 );
-       return i;
-}
+       char    *s;
 
+       /* normalize format */
+       dn_normalize( dn );
+
+       /* normalize case */
+       for ( s = dn; *s; s++ ) {
+               *s = TOUPPER( (unsigned char) *s );
+       }
+
+       return( dn );
+}
 
 /*
  * dn_parent - return a copy of the dn of dn's parent
@@ -182,7 +169,7 @@ dn_parent(
                return( NULL );
        }
 
-       if ( be_issuffix( be, dn ) ) {
+       if ( be != NULL && be_issuffix( be, dn ) ) {
                return( NULL );
        }
 
@@ -252,7 +239,7 @@ char * dn_rdn(
                return( NULL );
        }
 
-       if ( be_issuffix( be, dn ) ) {
+       if ( be != NULL && be_issuffix( be, dn ) ) {
                return( NULL );
        }