From 6147119dc8526a758a7c576940fe8483e2b93915 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Mon, 16 Aug 1999 02:59:11 +0000 Subject: [PATCH] Add ldap_*2name() in /schema, use them in slapd/schema --- include/ldap_schema.h | 16 ++++++++++++++++ libraries/libldap/schema.c | 32 ++++++++++++++++++++++++++++++++ servers/slapd/schema.c | 23 ++++++++++------------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/include/ldap_schema.h b/include/ldap_schema.h index f1f9dae831..64de1b08d6 100644 --- a/include/ldap_schema.h +++ b/include/ldap_schema.h @@ -86,6 +86,22 @@ typedef struct ldap_objectclass { #define LDAP_SCHEMA_STRUCTURAL 1 #define LDAP_SCHEMA_AUXILIARY 2 +LDAP_F( LDAP_CONST char * ) +ldap_syntax2name LDAP_P(( + LDAP_SYNTAX * syn )); + +LDAP_F( LDAP_CONST char * ) +ldap_matchingrule2name LDAP_P(( + LDAP_MATCHING_RULE * mr )); + +LDAP_F( LDAP_CONST char * ) +ldap_attributetype2name LDAP_P(( + LDAP_ATTRIBUTE_TYPE * at )); + +LDAP_F( LDAP_CONST char * ) +ldap_objectclass2name LDAP_P(( + LDAP_OBJECT_CLASS * oc )); + LDAP_F( void ) ldap_syntax_free LDAP_P(( LDAP_SYNTAX * syn )); diff --git a/libraries/libldap/schema.c b/libraries/libldap/schema.c index e3ae6318f0..33f8f2674a 100644 --- a/libraries/libldap/schema.c +++ b/libraries/libldap/schema.c @@ -20,6 +20,38 @@ #include + +static LDAP_CONST char * +choose_name( char *names[], LDAP_CONST char *fallback ) +{ + return( (names != NULL && names[0] != NULL) ? names[0] : fallback ); +} + +LDAP_CONST char * +ldap_syntax2name( LDAP_SYNTAX * syn ) +{ + return( syn->syn_oid ); +} + +LDAP_CONST char * +ldap_matchingrule2name( LDAP_MATCHING_RULE * mr ) +{ + return( choose_name( mr->mr_names, mr->mr_oid ) ); +} + +LDAP_CONST char * +ldap_attributetype2name( LDAP_ATTRIBUTE_TYPE * at ) +{ + return( choose_name( at->at_names, at->at_oid ) ); +} + +LDAP_CONST char * +ldap_objectclass2name( LDAP_OBJECT_CLASS * oc ) +{ + return( choose_name( oc->oc_names, oc->oc_oid ) ); +} + + /* * When pretty printing the entities we will be appending to a buffer. * Since checking for overflow, realloc'ing and checking if no error diff --git a/servers/slapd/schema.c b/servers/slapd/schema.c index 6abcacac99..ad022a60bb 100644 --- a/servers/slapd/schema.c +++ b/servers/slapd/schema.c @@ -1190,24 +1190,21 @@ static void oc_print( ObjectClass *oc ) { int i; + const char *mid; - if ( oc->soc_names && oc->soc_names[0] ) { - printf( "objectclass %s\n", oc->soc_names[0] ); - } else { - printf( "objectclass %s\n", oc->soc_oid ); - } + printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) ); if ( oc->soc_required != NULL ) { - printf( "\trequires %s", oc->soc_required[0] ); - for ( i = 1; oc->soc_required[i] != NULL; i++ ) { - printf( ",%s", oc->soc_required[i] ); - } + mid = "\trequires "; + for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," ) + printf( "%s%s", mid, + ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) ); printf( "\n" ); } if ( oc->soc_allowed != NULL ) { - printf( "\tallows %s", oc->soc_allowed[0] ); - for ( i = 1; oc->soc_allowed[i] != NULL; i++ ) { - printf( ",%s", oc->soc_allowed[i] ); - } + mid = "\tallows "; + for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," ) + printf( "%s%s", mid, + ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) ); printf( "\n" ); } } -- 2.39.5