Commit a1460e74 authored by Howard Chu's avatar Howard Chu
Browse files

Added ldap_xxx2bv schema functions

parent d474789d
......@@ -198,22 +198,42 @@ LDAP_F( char * )
ldap_objectclass2str LDAP_P((
LDAPObjectClass * oc ));
LDAP_F( struct berval * )
ldap_objectclass2bv LDAP_P((
LDAPObjectClass * oc, struct berval *bv ));
LDAP_F( char * )
ldap_attributetype2str LDAP_P((
LDAPAttributeType * at ));
LDAP_F( struct berval * )
ldap_attributetype2bv LDAP_P((
LDAPAttributeType * at, struct berval *bv ));
LDAP_F( char * )
ldap_syntax2str LDAP_P((
LDAPSyntax * syn ));
LDAP_F( struct berval * )
ldap_syntax2bv LDAP_P((
LDAPSyntax * syn, struct berval *bv ));
LDAP_F( char * )
ldap_matchingrule2str LDAP_P((
LDAPMatchingRule * mr ));
LDAP_F( struct berval * )
ldap_matchingrule2bv LDAP_P((
LDAPMatchingRule * mr, struct berval *bv ));
LDAP_F( char * )
ldap_matchingruleuse2str LDAP_P((
LDAPMatchingRuleUse * mru ));
LDAP_F( struct berval * )
ldap_matchingruleuse2bv LDAP_P((
LDAPMatchingRuleUse * mru, struct berval *bv ));
LDAP_F( char * )
ldap_scherr2str LDAP_P((
int code )) LDAP_GCCATTR((const));
......
......@@ -110,6 +110,17 @@ safe_string_val(safe_string * ss)
return(ss->val);
}
static char *
safe_strdup(safe_string * ss)
{
char *ret = LDAP_MALLOC(ss->pos+1);
if (!ret)
return NULL;
AC_MEMCPY(ret, ss->val, ss->pos);
ret[ss->pos] = '\0';
return ret;
}
static int
append_to_safe_string(safe_string * ss, char * s)
{
......@@ -297,9 +308,18 @@ print_extensions(safe_string *ss, LDAPSchemaExtensionItem **extensions)
char *
ldap_syntax2str( LDAPSyntax * syn )
{
struct berval bv;
if (ldap_syntax2bv( syn, &bv ))
return(bv.bv_val);
else
return NULL;
}
struct berval *
ldap_syntax2bv( LDAPSyntax * syn, struct berval *bv )
{
safe_string * ss;
char * retstring;
ss = new_safe_string(256);
if ( !ss )
......@@ -322,16 +342,26 @@ ldap_syntax2str( LDAPSyntax * syn )
print_literal(ss,/*(*/ ")");
retstring = LDAP_STRDUP(safe_string_val(ss));
bv->bv_val = safe_strdup(ss);
bv->bv_len = ss->pos;
safe_string_free(ss);
return(retstring);
return(bv);
}
char *
ldap_matchingrule2str( LDAPMatchingRule * mr )
{
struct berval bv;
if (ldap_matchingrule2bv( mr, &bv ))
return(bv.bv_val);
else
return NULL;
}
struct berval *
ldap_matchingrule2bv( LDAPMatchingRule * mr, struct berval *bv )
{
safe_string * ss;
char * retstring;
ss = new_safe_string(256);
if ( !ss )
......@@ -371,16 +401,26 @@ ldap_matchingrule2str( LDAPMatchingRule * mr )
print_literal(ss,/*(*/")");
retstring = LDAP_STRDUP(safe_string_val(ss));
bv->bv_val = safe_strdup(ss);
bv->bv_len = ss->pos;
safe_string_free(ss);
return(retstring);
return(bv);
}
char *
ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
{
struct berval bv;
if (ldap_matchingruleuse2bv( mru, &bv ))
return(bv.bv_val);
else
return NULL;
}
struct berval *
ldap_matchingruleuse2bv( LDAPMatchingRuleUse * mru, struct berval *bv )
{
safe_string * ss;
char * retstring;
ss = new_safe_string(256);
if ( !ss )
......@@ -420,16 +460,26 @@ ldap_matchingruleuse2str( LDAPMatchingRuleUse * mru )
print_literal(ss,/*(*/")");
retstring = LDAP_STRDUP(safe_string_val(ss));
bv->bv_val = safe_strdup(ss);
bv->bv_len = ss->pos;
safe_string_free(ss);
return(retstring);
return(bv);
}
char *
ldap_objectclass2str( LDAPObjectClass * oc )
{
struct berval bv;
if (ldap_objectclass2bv( oc, &bv ))
return(bv.bv_val);
else
return NULL;
}
struct berval *
ldap_objectclass2bv( LDAPObjectClass * oc, struct berval *bv )
{
safe_string * ss;
char * retstring;
ss = new_safe_string(256);
if ( !ss )
......@@ -499,16 +549,26 @@ ldap_objectclass2str( LDAPObjectClass * oc )
print_literal(ss, /*(*/")");
retstring = LDAP_STRDUP(safe_string_val(ss));
bv->bv_val = safe_strdup(ss);
bv->bv_len = ss->pos;
safe_string_free(ss);
return(retstring);
return(bv);
}
char *
ldap_attributetype2str( LDAPAttributeType * at )
ldap_attributetype2str( LDAPAttributeType * at )
{
struct berval bv;
if (ldap_attributetype2bv( at, &bv ))
return(bv.bv_val);
else
return NULL;
}
struct berval *
ldap_attributetype2bv( LDAPAttributeType * at, struct berval *bv )
{
safe_string * ss;
char * retstring;
ss = new_safe_string(256);
if ( !ss )
......@@ -602,9 +662,10 @@ ldap_attributetype2str( LDAPAttributeType * at )
print_literal(ss,/*(*/")");
retstring = LDAP_STRDUP(safe_string_val(ss));
bv->bv_val = safe_strdup(ss);
bv->bv_len = ss->pos;
safe_string_free(ss);
return(retstring);
return(bv);
}
/*
......
......@@ -415,11 +415,9 @@ at_schema_info( Entry *e )
vals[1] = NULL;
for ( at = attr_list; at; at = at->sat_next ) {
val.bv_val = ldap_attributetype2str( &at->sat_atype );
if ( val.bv_val == NULL ) {
if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
return -1;
}
val.bv_len = strlen( val.bv_val );
#if 0
Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
(long) val.bv_len, val.bv_val, 0 );
......
......@@ -270,13 +270,9 @@ int mr_schema_info( Entry *e )
continue;
}
val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
if ( val.bv_val == NULL ) {
if ( ldap_matchingrule2bv( &mr->smr_mrule, &val ) == NULL ) {
return -1;
}
val.bv_len = strlen( val.bv_val );
#if 0
Debug( LDAP_DEBUG_TRACE, "Merging mr [%ld] %s\n",
(long) val.bv_len, val.bv_val, 0 );
......
......@@ -482,11 +482,9 @@ oc_schema_info( Entry *e )
vals[1] = NULL;
for ( oc = oc_list; oc; oc = oc->soc_next ) {
val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
if ( val.bv_val == NULL ) {
if ( ldap_objectclass2bv( &oc->soc_oclass, &val ) == NULL ) {
return -1;
}
val.bv_len = strlen( val.bv_val );
#if 0
Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
(long) val.bv_len, val.bv_val, 0 );
......
......@@ -218,11 +218,9 @@ syn_schema_info( Entry *e )
continue;
}
val.bv_val = ldap_syntax2str( &syn->ssyn_syn );
if ( val.bv_val == NULL ) {
if ( ldap_syntax2bv( &syn->ssyn_syn, &val ) == NULL ) {
return -1;
}
val.bv_len = strlen( val.bv_val );
#if 0
#ifdef NEW_LOGGING
LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment