]> git.sur5r.net Git - openldap/commitdiff
Added ldap_explode_rdn()
authorHallvard Furuseth <hallvard@openldap.org>
Wed, 4 Nov 1998 23:28:51 +0000 (23:28 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Wed, 4 Nov 1998 23:28:51 +0000 (23:28 +0000)
doc/man/man3/ldap.3
doc/man/man3/ldap_get_dn.3
include/ldap.h
libraries/libldap/getdn.c

index 53d3a68213ba25a769028b2dd4c52060787fe86b..d98f7afa550b7ae0b2d2824b2ea09400e1f09ae9 100644 (file)
@@ -326,6 +326,9 @@ extract the DN from an entry
 .SM ldap_explode_dn(3)
 convert a DN into its component parts
 .TP
+.SM ldap_explode_rdn(3)
+convert a RDN into its component parts
+.TP
 .SM ldap_explode_dns(3)
 convert a DNS-style DN into its component parts (experimental)
 .TP
index 0536578e74d3c167e557de3b2f6644c290498dd9..d6769d938822f3ef03ccd8d02ad12268111e9a5c 100644 (file)
@@ -1,6 +1,6 @@
 .TH LDAP_GET_DN 3 "22 September 1998" "OpenLDAP LDVERSION"
 .SH NAME
-ldap_get_dn, ldap_explode_dn, ldap_dn2ufn, ldap_is_dns_dn, ldap_explode_dns \- LDAP DN handling routines
+ldap_get_dn, ldap_explode_dn, ldap_explode_rdn, ldap_dn2ufn, ldap_is_dns_dn, ldap_explode_dns \- LDAP DN handling routines
 .SH SYNOPSIS
 .nf
 .ft B
@@ -20,6 +20,12 @@ char *dn;
 int notypes;
 .LP
 .ft B
+char **ldap_explode_rdn(rdn, notypes)
+.ft
+char *rdn;
+int notypes;
+.LP
+.ft B
 char *ldap_dn2ufn(dn)
 .ft
 char *dn;
@@ -68,6 +74,15 @@ c=US" would return as either { "cn=Bob", "c=US", NULL } or { "Bob",
 The result can be freed by calling
 .BR ldap_value_free (3).
 .LP
+Similarly, the
+.B ldap_explode_rdn()
+routine takes an RDN as returned by
+.B ldap_explode_dn(dn,0)
+and breaks it up into its "type=value" component parts (or just "value",
+if the \fInotypes\fP parameter is set).  The result can be freed by
+calling
+.BR ldap_value_free (3).
+.LP
 .B ldap_dn2ufn()
 is used to turn a DN as returned by
 .B ldap_get_dn()
@@ -101,6 +116,7 @@ field in the \fIld\fP parameter is set to indicate the error.  See
 .BR ldap_error (3)
 for a description of possible error codes.
 .BR ldap_explode_dn() ,
+.BR ldap_explode_rdn() ,
 .B ldap_explode_dns()
 and
 .B ldap_dn2ufn()
index a62855ce52815f036c147943ce0b55ccaea4ff40..30cad17b75d0376fab5fb34d437f70eaa395b4fa 100644 (file)
@@ -580,6 +580,7 @@ LDAP_F void ldap_add_result_entry LDAP_P(( LDAPMessage **list, LDAPMessage *e ))
 LDAP_F char *ldap_get_dn LDAP_P(( LDAP *ld, LDAPMessage *entry ));
 LDAP_F char *ldap_dn2ufn LDAP_P(( char *dn ));
 LDAP_F char **ldap_explode_dn LDAP_P(( char *dn, int notypes ));
+LDAP_F char **ldap_explode_rdn LDAP_P(( char *rdn, int notypes ));
 LDAP_F char **ldap_explode_dns LDAP_P(( char *dn ));
 LDAP_F int ldap_is_dns_dn LDAP_P(( char *dn ));
 
index 8144bb037c77c13540fe55a3d7b6a386622793a7..70c09c7933c4c534a50a634345727a604ceb2761 100644 (file)
@@ -21,6 +21,8 @@ static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of
 
 #include "ldap-int.h"
 
+static char **explode_name( char *name, int notypes, int is_dn );
+
 char *
 ldap_get_dn( LDAP *ld, LDAPMessage *entry )
 {
@@ -147,17 +149,28 @@ ldap_explode_dns( char *dn )
 char **
 ldap_explode_dn( char *dn, int notypes )
 {
-       char    *p, *q, *rdnstart, **rdns = NULL;
-       int     state, count = 0, endquote, len;
-
        Debug( LDAP_DEBUG_TRACE, "ldap_explode_dn\n", 0, 0, 0 );
 
        if ( ldap_is_dns_dn( dn ) ) {
                return( ldap_explode_dns( dn ) );
        }
+       return explode_name( dn, notypes, 1 );
+}
 
-       rdnstart = dn;
-       p = dn-1;
+char **
+ldap_explode_rdn( char *rdn, int notypes )
+{
+       Debug( LDAP_DEBUG_TRACE, "ldap_explode_rdn\n", 0, 0, 0 );
+       return explode_name( rdn, notypes, 0 );
+}
+
+static char **
+explode_name( char *name, int notypes, int is_dn )
+{
+       char    *p, *q, **parts = NULL;
+       int     state, count = 0, endquote, len;
+
+       p = name-1;
        state = OUTQUOTE;
 
        do {
@@ -174,33 +187,41 @@ ldap_explode_dn( char *dn, int notypes )
                        else
                                state = INQUOTE;
                        break;
+               case '+':
+                       if (!is_dn)
+                               goto end_part;
+                       break;
                case ';':
                case ',':
+                       if (!is_dn)
+                               break;
+                       goto end_part;
                case '\0':
+               end_part:
                        if ( state == OUTQUOTE ) {
                                ++count;
-                               if ( rdns == NULL ) {
-                                       if (( rdns = (char **)malloc( 8
+                               if ( parts == NULL ) {
+                                       if (( parts = (char **)malloc( 8
                                                 * sizeof( char *))) == NULL )
                                                return( NULL );
                                } else if ( count >= 8 ) {
-                                       if (( rdns = (char **)realloc( rdns,
+                                       if (( parts = (char **)realloc( parts,
                                                (count+1) * sizeof( char *)))
                                                == NULL )
                                                return( NULL );
                                }
-                               rdns[ count ] = NULL;
+                               parts[ count ] = NULL;
                                endquote = 0;
                                if ( notypes ) {
-                                       for ( q = rdnstart;
+                                       for ( q = name;
                                            q < p && *q != '='; ++q ) {
                                                ;
                                        }
                                        if ( q < p ) {
-                                               rdnstart = ++q;
+                                               name = ++q;
                                        }
-                                       if ( *rdnstart == '"' ) {
-                                               ++rdnstart;
+                                       if ( *name == '"' ) {
+                                               ++name;
                                        }
                                        
                                        if ( *(p-1) == '"' ) {
@@ -209,12 +230,12 @@ ldap_explode_dn( char *dn, int notypes )
                                        }
                                }
 
-                               len = p - rdnstart;
-                               if (( rdns[ count-1 ] = (char *)calloc( 1,
+                               len = p - name;
+                               if (( parts[ count-1 ] = (char *)calloc( 1,
                                    len + 1 )) != NULL ) {
-                                       SAFEMEMCPY( rdns[ count-1 ], rdnstart,
+                                       SAFEMEMCPY( parts[ count-1 ], name,
                                            len );
-                                       rdns[ count-1 ][ len ] = '\0';
+                                       parts[ count-1 ][ len ] = '\0';
                                }
 
                                /*
@@ -225,15 +246,15 @@ ldap_explode_dn( char *dn, int notypes )
                                if ( endquote == 1 )
                                        p++;
 
-                               rdnstart = *p ? p + 1 : p;
-                               while ( isspace( *rdnstart ))
-                                       ++rdnstart;
+                               name = *p ? p + 1 : p;
+                               while ( isascii( *name ) && isspace( *name ) )
+                                       ++name;
                        }
                        break;
                }
        } while ( *p );
 
-       return( rdns );
+       return( parts );
 }