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
25 AttributeDescription **ad,
28 int rtn = LDAP_UNDEFINED_TYPE;
30 AttributeDescription desc;
33 assert( *ad != NULL );
34 assert( *text != NULL );
36 if( bv == NULL || bv->bv_len == 0 ) {
37 *text = "empty attribute description";
38 return LDAP_UNDEFINED_TYPE;
41 /* make sure description is IA5 */
42 if( IA5StringValidate( NULL, bv ) != 0 ) {
43 *text = "attribute description contains non-IA5 characters";
44 return LDAP_UNDEFINED_TYPE;
47 tokens = str2charray( bv->bv_val, ";");
49 if( tokens == NULL || *tokens == NULL ) {
50 *text = "no attribute type";
54 desc.ad_type = at_find( *tokens );
56 if( desc.ad_type == NULL ) {
57 *text = "attribute type undefined";
61 desc.ad_flags = SLAP_DESC_NONE;
64 for( i=1; tokens[i] != NULL; i++ ) {
65 if( strcasecmp( tokens[i], "binary" ) == 0 ) {
66 if( desc.ad_flags & SLAP_DESC_BINARY ) {
67 *text = "option \"binary\" specified multiple times";
71 if(!( desc.ad_type->sat_syntax->ssyn_flags
72 & SLAP_SYNTAX_BINARY ))
74 /* not stored in binary, disallow option */
75 *text = "option \"binary\" with type not supported";
79 desc.ad_flags |= SLAP_DESC_BINARY;
81 } else if ( strncasecmp( tokens[i], "lang-",
82 sizeof("lang-")-1 ) == 0 && tokens[i][sizeof("lang-")-1] )
84 if( desc.ad_lang != NULL ) {
85 *text = "multiple language tag options specified";
88 desc.ad_lang = tokens[i];
90 /* normalize to all lower case, it's easy */
91 ldap_pvt_str2lower( desc.ad_lang );
94 *text = "unrecognized option";
99 desc.ad_cname = ch_malloc( sizeof( struct berval ) );
101 desc.ad_cname->bv_len = strlen( desc.ad_type->sat_cname );
102 if( desc.ad_flags & SLAP_DESC_BINARY ) {
103 desc.ad_cname->bv_len += sizeof("binary");
105 if( desc.ad_lang != NULL ) {
106 desc.ad_cname->bv_len += strlen( desc.ad_lang );
109 desc.ad_cname = ch_malloc( desc.ad_cname->bv_len + 1 );
111 strcpy( desc.ad_cname->bv_val, desc.ad_type->sat_cname );
112 strcat( desc.ad_cname->bv_val, ";binary" );
113 if( desc.ad_flags & SLAP_DESC_BINARY ) {
114 strcat( desc.ad_cname->bv_val, ";binary" );
117 if( desc.ad_lang != NULL ) {
118 strcat( desc.ad_cname->bv_val, ";" );
119 strcat( desc.ad_cname->bv_val, desc.ad_lang );
122 *ad = ch_malloc( sizeof( AttributeDescription ) );
128 charray_free( tokens );
133 ad_free( AttributeDescription *ad, int freeit )
135 if( ad == NULL ) return;
137 ber_bvfree( ad->ad_cname );
140 if( freeit ) free( ad );