skeleton of ldap_str2nd/dn2str; works with most of the simple cases, but there's much to do with unicode, I think

This commit is contained in:
Pierangelo Masarati 2001-10-18 19:00:07 +00:00
parent 850d8eba67
commit fefc29786c
8 changed files with 2228 additions and 6 deletions

View file

@ -1177,8 +1177,9 @@ typedef struct ldap_ava {
char *la_attr;
struct berval *la_value;
unsigned la_flags;
#define LDAP_AVA_STRING 0x0000U
#define LDAP_AVA_BINARY 0x0001U
#define LDAP_AVA_STRING 0x0000U
#define LDAP_AVA_BINARY 0x0001U
#define LDAP_AVA_UTF8STRING 0x0002U
} LDAPAVA;
typedef LDAPAVA** LDAPRDN;
@ -1189,10 +1190,12 @@ typedef LDAPRDN** LDAPDN;
#define LDAP_DN_FORMAT_LDAPV2 0x0001U
#define LDAP_DN_FORMAT_DCE 0x0002U
#define LDAP_DN_FORMAT_UFN 0x0003U /* dn2str only */
#define LDAP_DN_FORMAT_AD_CANONICAL 0x0004U /* dn2str only */
#define LDAP_DN_FORMAT_MASK 0x000FU
/* str2dn flags */
#define LDAP_DN_PEDANTIC 0x1000U
/* str2dn flags */
#define LDAP_DN_P_LEADTRAILSPACES 0x1000U
#define LDAP_DN_PEDANTIC 0xF000U
LDAP_F( int )
ldap_str2dn LDAP_P((

View file

@ -147,6 +147,8 @@ ber_log_sos_dump LDAP_P((
/* memory.c */
/* simple macros to realloc for now */
LBER_F (BerMemoryFunctions *) ber_int_memory_fns;
LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
LBER_F (char *) ber_strndup__( LDAP_CONST char *, size_t );
#ifdef CSRIMALLOC
#define LBER_INT_MALLOC malloc
@ -162,6 +164,7 @@ LBER_F (BerMemoryFunctions *) ber_int_memory_fns;
#define LBER_FREE free
#define LBER_VFREE ber_memvfree
#define LBER_STRDUP strdup
#define LBER_STRNDUP ber_strndup__
#else
#define LBER_INT_MALLOC(s) ber_memalloc((s))
@ -177,6 +180,7 @@ LBER_F (BerMemoryFunctions *) ber_int_memory_fns;
#define LBER_FREE(p) ber_memfree((p))
#define LBER_VFREE(v) ber_memvfree((void**)(v))
#define LBER_STRDUP(s) ber_strdup((s))
#define LBER_STRNDUP(s,l) ber_strndup((s),(l))
#endif
/* sockbuf.c */

View file

@ -563,3 +563,56 @@ ber_strdup( LDAP_CONST char *s )
AC_MEMCPY( p, s, len );
return p;
}
char *
ber_strndup( LDAP_CONST char *s, ber_len_t l )
{
char *p;
size_t len;
ber_int_options.lbo_valid = LBER_INITIALIZED;
#ifdef LDAP_MEMORY_DEBUG
assert(s != NULL); /* bv damn better point to something */
#endif
if( s == NULL ) {
ber_errno = LBER_ERROR_PARAM;
return NULL;
}
len = strlen( s );
if ( len > l ) {
len = l;
}
if ( (p = LBER_MALLOC( len + 1 )) == NULL ) {
ber_errno = LBER_ERROR_MEMORY;
return NULL;
}
AC_MEMCPY( p, s, len );
p[ len ] = '\0';
return p;
}
char *
ber_strndup__( LDAP_CONST char *s, size_t l )
{
char *p;
size_t len;
if ( s == NULL ) {
return NULL;
}
len = strlen( s );
if (( p = LBER_MALLOC( len + 1 ) ) == NULL ) {
return NULL;
}
AC_MEMCPY( p, s, len );
p[ len ] = '\0';
return p;
}

View file

@ -7,7 +7,7 @@
LIBRARY = libldap.la
XLIBRARY = ../libldap.a
PROGRAMS = apitest ltest ttest
PROGRAMS = apitest ltest ttest dntest
SRCS = bind.c open.c result.c error.c compare.c search.c \
controls.c messages.c references.c extended.c cyrus.c \
@ -60,6 +60,8 @@ ltest: $(LIBRARY) test.o $(LDAP_LIBLBER_DEPEND)
$(LTLINK) -o $@ test.o $(LIBS)
ttest: $(LIBRARY) tmpltest.o $(LDAP_LIBLBER_DEPEND)
$(LTLINK) -o $@ tmpltest.o $(LIBS)
dntest: $(LIBRARY) dntest.o $(LDAP_LIBLBER_DEPEND)
$(LTLINK) -o $@ dntest.o $(LIBS)
CFFILES=ldap.conf ldapfilter.conf ldaptemplates.conf ldapsearchprefs.conf

View file

@ -0,0 +1,98 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* OpenLDAP API Test
* Written by: Pierangelo Masarati <ando@OpenLDAP.org>
*
* This program is designed to test the ldap_str2dn/ldap_dn2str
* functions
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/string.h>
#include <stdio.h>
#include <ldap.h>
#include "ldif.h"
#include "lutil.h"
#include "lutil_ldap.h"
#include "ldap_defaults.h"
int
main(int argc, char *argv[])
{
int rc, i, debug = -1;
unsigned flags[ 2 ] = { 0U, 0U };
char *str, buf[1024];
LDAPDN *dn = NULL;
if (argc < 2) {
fprintf(stderr, "usage: dntest <dn> [flags-in[,...]] [flags-out[,...]]\n\n");
fprintf(stderr, "\tflags-in: V3,V2,DCE,PEDANTIC\n");
fprintf(stderr, "\tflags-out: V3,V2,UFN,DCE,AD,PEDANTIC\n\n");
return 0;
}
if (ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &debug) != LBER_OPT_SUCCESS) {
fprintf(stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug);
}
if (ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug) != LDAP_OPT_SUCCESS) {
fprintf(stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug);
}
if ( strcmp(argv[1], "-") == 0) {
size_t len;
fgets(buf, sizeof(buf), stdin);
len = strlen(buf)-1;
if (len >= 0 && buf[len] == '\n') {
buf[len] = '\0';
}
str = buf;
} else {
str = argv[1];
}
if (argc >= 3) {
for ( i = 0; i < argc-2; i++ ) {
char *s, *e;
for (s = argv[2+i]; s; s = e) {
e = strchr(s, ',');
if (e != NULL) {
e[0] = '\0';
e++;
}
if (!strcasecmp(s, "V3")) {
flags[i] |= LDAP_DN_FORMAT_LDAPV3;
} else if (!strcasecmp(s, "V2")) {
flags[i] |= LDAP_DN_FORMAT_LDAPV2;
} else if (!strcasecmp(s, "DCE")) {
flags[i] |= LDAP_DN_FORMAT_DCE;
} else if (!strcasecmp(s, "UFN")) {
flags[i] |= LDAP_DN_FORMAT_UFN;
} else if (!strcasecmp(s, "AD")) {
flags[i] |= LDAP_DN_FORMAT_AD_CANONICAL;
} else if (!strcasecmp(s, "PEDANTIC")) {
flags[i] |= LDAP_DN_PEDANTIC;
}
}
}
}
rc = ldap_str2dn(str, &dn, flags[0]);
if ( rc == LDAP_SUCCESS &&
ldap_dn2str( dn, &str, flags[argc > 3 ? 1 : 0] )
== LDAP_SUCCESS ) {
fprintf( stdout, "%s\n", str );
}
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -340,6 +340,7 @@ LDAP_F ( void ) ldap_int_initialize_global_options LDAP_P((
#define LDAP_FREE(p) (LBER_FREE((p)))
#define LDAP_VFREE(v) (LBER_VFREE((void **)(v)))
#define LDAP_STRDUP(s) (LBER_STRDUP((s)))
#define LDAP_STRNDUP(s,l) (LBER_STRNDUP((s),(l)))
/*
* in error.c

View file

@ -736,7 +736,7 @@ parse_whsp(const char **sp)
*/
/* Parse a sequence of dot-separated decimal strings */
static char *
char *
parse_numericoid(const char **sp, int *code, const int flags)
{
char * res;