229
229
return slapi_attr_init_locking_optional(a, type, PR_TRUE);
233
slapi_attr_init_syntax(Slapi_Attr *a)
236
struct asyntaxinfo *asi = NULL;
238
const char *basetype= NULL;
239
char buf[SLAPD_TYPICAL_ATTRIBUTE_NAME_MAX_LENGTH];
242
tmp = slapi_attr_basetype(a->a_type, buf, sizeof(buf));
246
asi = attr_syntax_get_by_name_with_default (basetype);
249
a->a_plugin = asi->asi_plugin;
250
a->a_flags = asi->asi_flags;
251
a->a_mr_eq_plugin = asi->asi_mr_eq_plugin;
252
a->a_mr_ord_plugin = asi->asi_mr_ord_plugin;
253
a->a_mr_sub_plugin = asi->asi_mr_sub_plugin;
256
slapi_ch_free_string(&tmp);
233
261
slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock)
351
slapi_attr_init_nosyntax(Slapi_Attr *a, const char *type)
354
a->a_type = slapi_ch_strdup(type);
355
slapi_valueset_init(&a->a_present_values);
356
slapi_valueset_init(&a->a_deleted_values);
357
a->a_listtofree= NULL;
358
a->a_deletioncsn= NULL;
323
365
slapi_attr_dup(const Slapi_Attr *attr)
325
367
Slapi_Attr *newattr= slapi_attr_new();
326
Slapi_Value **present_va= valueset_get_valuearray(&attr->a_present_values); /* JCM Mucking about inside the value set */
327
Slapi_Value **deleted_va= valueset_get_valuearray(&attr->a_deleted_values); /* JCM Mucking about inside the value set */
328
368
slapi_attr_init(newattr, attr->a_type);
329
valueset_add_valuearray( &newattr->a_present_values, present_va );
330
valueset_add_valuearray( &newattr->a_deleted_values, deleted_va );
369
slapi_valueset_set_valueset( &newattr->a_deleted_values, &attr->a_deleted_values );
370
slapi_valueset_set_valueset( &newattr->a_present_values, &attr->a_present_values );
331
371
newattr->a_deletioncsn= csn_dup(attr->a_deletioncsn);
529
575
slapi_attr_flag_is_set( const Slapi_Attr *a, unsigned long flag )
577
if ( a->a_flags == 0 && a->a_plugin == NULL ) {
578
slapi_attr_init_syntax ((Slapi_Attr *)a);
531
580
return( a->a_flags & flag );
535
584
slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
539
if ( a->a_flags & SLAPI_ATTR_FLAG_CMP_BITBYBIT )
541
int cmplen = ( v1->bv_len <= v2->bv_len ? v1->bv_len : v2->bv_len );
542
retVal = memcmp(v1->bv_val, v2->bv_val, cmplen);
543
if ( retVal == 0 && v1->bv_len < v2->bv_len )
547
else if ( retVal == 0 && v1->bv_len > v2->bv_len )
556
Slapi_Value *cvals[2];
561
cvals[0]->v_csnset = NULL;
563
cvals[0]->v_flags = 0;
565
a2.a_present_values.va = cvals; /* JCM - PUKE */
566
ava.ava_type = a->a_type;
568
ava.ava_private = NULL;
569
retVal = plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava);
588
Slapi_Value *cvals[2];
591
if ( a->a_flags == 0 && a->a_plugin == NULL ) {
592
slapi_attr_init_syntax ((Slapi_Attr *)a);
595
cvals[0]->v_csnset = NULL;
597
cvals[0]->v_flags = 0;
599
a2.a_present_values.va = cvals; /* JCM - PUKE */
600
ava.ava_type = a->a_type;
602
ava.ava_private = NULL;
604
return( plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava));
575
608
slapi_attr_value_cmp_ext(const Slapi_Attr *a, Slapi_Value *v1, Slapi_Value *v2)
578
const struct berval *bv2 = slapi_value_get_berval(v2);
580
if ( a->a_flags & SLAPI_ATTR_FLAG_CMP_BITBYBIT )
582
const struct berval *bv1 = slapi_value_get_berval(v1);
583
return slapi_attr_value_cmp(a, bv1, bv2);
589
Slapi_Value *cvals[2];
590
unsigned long v2_flags = v2->v_flags;
595
a2.a_present_values.va = cvals; /* JCM - PUKE */
597
ava.ava_type = a->a_type;
598
ava.ava_value = *bv2;
600
ava.ava_private = &v2_flags;
602
ava.ava_private = NULL;
604
retVal = plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava);
612
Slapi_Value *cvals[2];
613
unsigned long v2_flags = v2->v_flags;
614
const struct berval *bv2 = slapi_value_get_berval(v2);
616
if ( a->a_flags == 0 && a->a_plugin == NULL ) {
617
slapi_attr_init_syntax ((Slapi_Attr *)a);
621
a2.a_present_values.va = cvals;
622
ava.ava_type = a->a_type;
623
ava.ava_value = *bv2;
625
ava.ava_private = &v2_flags;
627
ava.ava_private = NULL;
630
return (plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava));
812
* determine whether we should use an AVL tree of values or not
814
for ( i = 0; vals[i] != NULL; i++ ) ;
818
* detect duplicate values
820
if ( numofvals > 1 ) {
822
* Several values to add: use an AVL tree to detect duplicates.
824
LDAPDebug( LDAP_DEBUG_TRACE,
825
"slapi_entry_add_values: using an AVL tree to "
826
"detect duplicate values\n", 0, 0, 0 );
828
if (valueset_isempty(&a->a_present_values)) {
829
/* if the attribute contains no values yet, just check the
830
* input vals array for duplicates
832
Avlnode *vtree = NULL;
833
rc= valuetree_add_valuearray(a, vals, &vtree, &duplicate_index);
834
valuetree_free(&vtree);
835
was_present_null = 1;
837
/* the attr and vals both contain values, check intersection */
838
rc= valueset_intersectswith_valuearray(&a->a_present_values, a, vals, &duplicate_index);
841
} else if ( !valueset_isempty(&a->a_present_values) ) {
843
* One or no value to add: don't bother constructing
844
* an AVL tree, etc. since it probably isn't worth the time.
846
for ( i = 0; vals[i] != NULL; ++i ) {
847
if ( slapi_attr_value_find( a, slapi_value_get_berval(vals[i]) ) == 0 ) {
835
* add values and check for duplicate values
837
numofvals = valuearray_count(vals);
838
rc = slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, vals, numofvals, SLAPI_VALUE_FLAG_DUPCHECK, &duplicate_index);
839
if ( rc != LDAP_SUCCESS) {
849
840
#if defined(USE_OLD_UNHASHED)
850
841
if (is_type_forbidden(a->a_type)) {
851
842
/* If the attr is in the forbidden list
859
850
rc = LDAP_TYPE_OR_VALUE_EXISTS;
867
* add values if no duplicates detected
869
if(rc==LDAP_SUCCESS) {
870
valueset_add_valuearray( &a->a_present_values, vals );
873
854
/* In the case of duplicate value, rc == LDAP_TYPE_OR_VALUE_EXISTS or
874
855
* LDAP_OPERATIONS_ERROR
876
else if ( duplicate_index >= 0 ) {
857
if ( duplicate_index >= 0 ) {
877
858
char bvvalcopy[BUFSIZ];
878
859
char *duplicate_string = "null or non-ASCII";