[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
ldap_explode_rdn()
Here is ldap_explode_rdn().
(See draft-ietf-ldapext-ldap-c-api-01.txt.)
Most of the .c patch is just a name change on the variables in
ldap_explode_dn (factored out to explode_name()). The only real change
is between the case '+': and case '\0' statements.
--- ldap/libraries/libldap/getdn.c~ Wed Sep 16 12:17:54 1998
+++ ldap/libraries/libldap/getdn.c~ Thu Sep 17 20:52:59 1998
@@ -30,4 +30,10 @@
#include "ldap.h"
+#ifndef NEEDPROTOS
+static char **explode_name();
+#else /* !NEEDPROTOS */
+static char **explode_name( char *name, int notypes, int is_dn );
+#endif /* !NEEDPROTOS */
+
char *
ldap_get_dn( LDAP *ld, LDAPMessage *entry )
@@ -157,7 +163,4 @@
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 );
@@ -165,7 +168,21 @@
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;
@@ -184,31 +201,39 @@
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;
}
@@ -219,10 +244,10 @@
}
- 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';
}
@@ -235,7 +260,7 @@
p++;
- rdnstart = *p ? p + 1 : p;
- while ( isspace( (unsigned char) *rdnstart ))
- ++rdnstart;
+ name = *p ? p + 1 : p;
+ while ( isspace( (unsigned char) *name ))
+ ++name;
}
break;
@@ -243,5 +268,5 @@
} while ( *p );
- return( rdns );
+ return( parts );
}
--- ldap/include/ldap.h~ Thu Aug 20 02:18:28 1998
+++ ldap/include/ldap.h~ Thu Sep 17 20:32:23 1998
@@ -63,16 +63,21 @@
#ifdef LDAP_SYSLOG
+/* Moved fmt out to a variable, to avoid gcc -Wformat warnings. */
#define Debug( level, fmt, arg1, arg2, arg3 ) \
{ \
+ const char *DebugFmT = fmt; \
if ( ldap_debug & level ) \
- fprintf( stderr, fmt, arg1, arg2, arg3 ); \
+ fprintf( stderr, DebugFmT, arg1, arg2, arg3 ); \
if ( ldap_syslog & level ) \
- syslog( ldap_syslog_level, fmt, arg1, arg2, arg3 ); \
+ syslog( ldap_syslog_level, DebugFmT,arg1,arg2,arg3 ); \
}
#else /* LDAP_SYSLOG */
#ifndef WINSOCK
#define Debug( level, fmt, arg1, arg2, arg3 ) \
+ { \
+ const char *DebugFmT = fmt; \
if ( ldap_debug & level ) \
- fprintf( stderr, fmt, arg1, arg2, arg3 );
+ fprintf( stderr, DebugFmT, arg1, arg2, arg3 ); \
+ }
#else /* !WINSOCK */
extern void Debug( int level, char* fmt, ... );
@@ -529,4 +534,5 @@
extern char *ldap_dn2ufn();
extern char **ldap_explode_dn();
+extern char **ldap_explode_rdn();
extern char *ldap_first_attribute();
extern char *ldap_next_attribute();
--- ldap/include/proto-ldap.h~ Sun Aug 9 00:43:13 1998
+++ ldap/include/proto-ldap.h~ Thu Sep 17 20:33:07 1998
@@ -125,4 +125,5 @@
LDAPFUNCDECL char *ldap_dn2ufn( char *dn );
LDAPFUNCDECL char **ldap_explode_dn( char *dn, int notypes );
+LDAPFUNCDECL char **ldap_explode_rdn( char *rdn, int notypes );
LDAPFUNCDECL char **ldap_explode_dns( char *dn );
LDAPFUNCDECL int ldap_is_dns_dn( char *dn );
--- ldap/doc/man/man3/ldap.3~ Sun Aug 9 00:43:13 1998
+++ ldap/doc/man/man3/ldap.3~ Thu Sep 17 21:05:14 1998
@@ -327,4 +327,7 @@
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)
--- ldap/doc/man/man3/ldap_get_dn.3~ Sun Aug 9 00:43:13 1998
+++ ldap/doc/man/man3/ldap_get_dn.3~ Thu Sep 17 21:25:31 1998
@@ -1,5 +1,5 @@
.TH LDAP_GET_DN 3 "16 June 1995" "U-M LDAP 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
@@ -21,4 +21,10 @@
.LP
.ft B
+char **ldap_explode_rdn(rdn, notypes)
+.ft
+char *rdn;
+int notypes;
+.LP
+.ft B
char *ldap_dn2ufn(dn)
.ft
@@ -69,4 +75,13 @@
.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
@@ -102,4 +117,5 @@
for a description of possible error codes.
.BR ldap_explode_dn() ,
+.BR ldap_explode_rdn() ,
.B ldap_explode_dns()
and
--- ldap/doc/man/man3/ldap_get_dn.3.links~ Sun Aug 9 00:43:13 1998
+++ ldap/doc/man/man3/ldap_get_dn.3.links~ Thu Sep 17 21:08:57 1998
@@ -1,3 +1,4 @@
ldap_explode_dn.3
+ldap_explode_rdn.3
ldap_explode_dns.3
ldap_dn2ufn.3
--
Hallvard