3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* ad.c - routines for dealing with attribute descriptions */
14 #include <ac/socket.h>
15 #include <ac/string.h>
21 #ifdef SLAPD_SCHEMA_NOT_COMPAT
23 static int ad_keystring(
28 if( !AD_CHAR( bv->bv_val[0] ) ) {
32 for( i=1; i<bv->bv_len; i++ ) {
33 if( !AD_CHAR( bv->bv_val[i] ) ) {
42 AttributeDescription **ad,
46 bv.bv_val = (char *) str;
47 bv.bv_len = strlen( str );
49 return slap_bv2ad( &bv, ad, text );
54 AttributeDescription **ad,
57 int rtn = LDAP_UNDEFINED_TYPE;
59 AttributeDescription desc;
62 assert( *ad != NULL );
63 assert( *text != NULL );
65 if( bv == NULL || bv->bv_len == 0 ) {
66 *text = "empty attribute description";
67 return LDAP_UNDEFINED_TYPE;
70 /* make sure description is IA5 */
71 if( ad_keystring( bv ) ) {
72 *text = "attribute description contains inappropriate characters";
73 return LDAP_UNDEFINED_TYPE;
76 tokens = str2charray( bv->bv_val, ";");
78 if( tokens == NULL || *tokens == NULL ) {
79 *text = "no attribute type";
83 desc.ad_type = at_find( *tokens );
85 if( desc.ad_type == NULL ) {
86 *text = "attribute type undefined";
90 desc.ad_flags = SLAP_DESC_NONE;
93 for( i=1; tokens[i] != NULL; i++ ) {
94 if( strcasecmp( tokens[i], "binary" ) == 0 ) {
95 if( desc.ad_flags & SLAP_DESC_BINARY ) {
96 *text = "option \"binary\" specified multiple times";
100 if(!( desc.ad_type->sat_syntax->ssyn_flags
101 & SLAP_SYNTAX_BINARY ))
103 /* not stored in binary, disallow option */
104 *text = "option \"binary\" with type not supported";
108 desc.ad_flags |= SLAP_DESC_BINARY;
110 } else if ( strncasecmp( tokens[i], "lang-",
111 sizeof("lang-")-1 ) == 0 && tokens[i][sizeof("lang-")-1] )
113 if( desc.ad_lang != NULL ) {
114 *text = "multiple language tag options specified";
117 desc.ad_lang = tokens[i];
119 /* normalize to all lower case, it's easy */
120 ldap_pvt_str2lower( desc.ad_lang );
123 *text = "unrecognized option";
128 desc.ad_cname = ch_malloc( sizeof( struct berval ) );
130 desc.ad_cname->bv_len = strlen( desc.ad_type->sat_cname );
131 if( desc.ad_flags & SLAP_DESC_BINARY ) {
132 desc.ad_cname->bv_len += sizeof("binary");
134 if( desc.ad_lang != NULL ) {
135 desc.ad_cname->bv_len += strlen( desc.ad_lang );
138 desc.ad_cname = ch_malloc( desc.ad_cname->bv_len + 1 );
140 strcpy( desc.ad_cname->bv_val, desc.ad_type->sat_cname );
141 strcat( desc.ad_cname->bv_val, ";binary" );
142 if( desc.ad_flags & SLAP_DESC_BINARY ) {
143 strcat( desc.ad_cname->bv_val, ";binary" );
146 if( desc.ad_lang != NULL ) {
147 strcat( desc.ad_cname->bv_val, ";" );
148 strcat( desc.ad_cname->bv_val, desc.ad_lang );
151 *ad = ch_malloc( sizeof( AttributeDescription ) );
157 charray_free( tokens );
162 ad_free( AttributeDescription *ad, int freeit )
164 if( ad == NULL ) return;
166 ber_bvfree( ad->ad_cname );
169 if( freeit ) free( ad );