~ubuntu-branches/ubuntu/trusty/389-ds-base/trusty

« back to all changes in this revision

Viewing changes to ldap/servers/slapd/attr.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-08-30 00:31:55 UTC
  • mfrom: (1.2.1)
  • Revision ID: package-import@ubuntu.com-20130830003155-oimuzdqopkvp2cd0
Tags: 1.3.1.7-0ubuntu1
Sync from unreleased debian git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
229
229
        return slapi_attr_init_locking_optional(a, type, PR_TRUE);
230
230
}
231
231
 
 
232
int
 
233
slapi_attr_init_syntax(Slapi_Attr    *a)
 
234
{
 
235
        int rc = 1;
 
236
        struct asyntaxinfo *asi = NULL;
 
237
        char *tmp = 0;
 
238
        const char *basetype= NULL;
 
239
        char buf[SLAPD_TYPICAL_ATTRIBUTE_NAME_MAX_LENGTH];
 
240
 
 
241
        basetype = buf;
 
242
        tmp = slapi_attr_basetype(a->a_type, buf, sizeof(buf));
 
243
        if (tmp) {
 
244
                basetype = buf;
 
245
        }
 
246
        asi = attr_syntax_get_by_name_with_default (basetype);
 
247
        if (asi) {
 
248
                rc = 0;
 
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;
 
254
        } 
 
255
        if (tmp)
 
256
                slapi_ch_free_string(&tmp);
 
257
        return rc;
 
258
}
 
259
 
232
260
Slapi_Attr *
233
261
slapi_attr_init_locking_optional(Slapi_Attr *a, const char *type, PRBool use_lock)
234
262
{
320
348
}
321
349
 
322
350
Slapi_Attr *
 
351
slapi_attr_init_nosyntax(Slapi_Attr *a, const char *type)
 
352
{
 
353
 
 
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;
 
359
        a->a_next= NULL;
 
360
 
 
361
        return a;
 
362
}
 
363
 
 
364
Slapi_Attr *
323
365
slapi_attr_dup(const Slapi_Attr *attr)
324
366
{
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);
332
372
        return newattr;
333
373
}
410
450
                return( -1 );
411
451
        }
412
452
 
 
453
        if ( a->a_flags == 0 && a->a_plugin == NULL ) { 
 
454
            slapi_attr_init_syntax ((Slapi_Attr *)a);
 
455
        }
413
456
        ava.ava_type = a->a_type;
414
457
        ava.ava_value = *v;
415
458
        if (a->a_flags & SLAPI_ATTR_FLAG_NORMALIZED) {
521
564
int
522
565
slapi_attr_get_flags( const Slapi_Attr *a, unsigned long *flags )
523
566
{
 
567
        if ( a->a_flags == 0 && a->a_plugin == NULL ) { 
 
568
            slapi_attr_init_syntax ((Slapi_Attr *)a);
 
569
        }
524
570
        *flags = a->a_flags;
525
571
        return( 0 );
526
572
}
528
574
int
529
575
slapi_attr_flag_is_set( const Slapi_Attr *a, unsigned long flag )
530
576
{
 
577
        if ( a->a_flags == 0 && a->a_plugin == NULL ) { 
 
578
            slapi_attr_init_syntax ((Slapi_Attr *)a);
 
579
        }
531
580
        return( a->a_flags & flag );
532
581
}
533
582
 
534
583
int
535
584
slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
536
585
{
537
 
        int retVal;
538
 
 
539
 
        if ( a->a_flags & SLAPI_ATTR_FLAG_CMP_BITBYBIT )
540
 
        {
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 )
544
 
                {
545
 
                        retVal = -1;
546
 
                }
547
 
                else if ( retVal == 0 && v1->bv_len > v2->bv_len )
548
 
                {
549
 
                        retVal = 1;
550
 
                }
551
 
        }
552
 
        else
553
 
        {
554
 
                Slapi_Attr a2;
555
 
                struct ava ava;
556
 
                Slapi_Value *cvals[2];
557
 
                Slapi_Value tmpcval;
558
 
 
559
 
                a2 = *a;
560
 
                cvals[0] = &tmpcval;
561
 
                cvals[0]->v_csnset = NULL;
562
 
                cvals[0]->bv = *v1;
563
 
                cvals[0]->v_flags = 0;
564
 
                cvals[1] = NULL;
565
 
                a2.a_present_values.va = cvals; /* JCM - PUKE */
566
 
                ava.ava_type = a->a_type;
567
 
                ava.ava_value = *v2;
568
 
                ava.ava_private = NULL;
569
 
                retVal = plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava);
570
 
        }
571
 
        return retVal;
 
586
    Slapi_Attr a2 = *a;
 
587
    struct ava ava;
 
588
    Slapi_Value *cvals[2];
 
589
    Slapi_Value tmpcval;
 
590
 
 
591
    if ( a->a_flags == 0 && a->a_plugin == NULL ) {
 
592
        slapi_attr_init_syntax ((Slapi_Attr *)a);
 
593
    }
 
594
    cvals[0] = &tmpcval;
 
595
    cvals[0]->v_csnset = NULL;
 
596
    cvals[0]->bv = *v1;
 
597
    cvals[0]->v_flags = 0;
 
598
    cvals[1] = NULL;
 
599
    a2.a_present_values.va = cvals; /* JCM - PUKE */
 
600
    ava.ava_type = a->a_type;
 
601
    ava.ava_value = *v2;
 
602
    ava.ava_private = NULL;
 
603
 
 
604
    return( plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava));
572
605
}
573
606
 
574
607
int
575
608
slapi_attr_value_cmp_ext(const Slapi_Attr *a, Slapi_Value *v1, Slapi_Value *v2)
576
609
{
577
 
        int retVal;
578
 
        const struct berval *bv2 = slapi_value_get_berval(v2);
579
 
 
580
 
        if ( a->a_flags & SLAPI_ATTR_FLAG_CMP_BITBYBIT )
581
 
        {
582
 
                const struct berval *bv1 = slapi_value_get_berval(v1);
583
 
                return slapi_attr_value_cmp(a, bv1, bv2);
584
 
        }
585
 
        else
586
 
        {
587
 
                Slapi_Attr a2;
588
 
                struct ava ava;
589
 
                Slapi_Value *cvals[2];
590
 
                unsigned long v2_flags = v2->v_flags;
591
 
 
592
 
                a2 = *a;
593
 
                cvals[0] = v1;
594
 
                cvals[1] = NULL;
595
 
                a2.a_present_values.va = cvals; /* JCM - PUKE */
596
 
 
597
 
                ava.ava_type = a->a_type;
598
 
                ava.ava_value = *bv2;
599
 
                if (v2_flags) {
600
 
                        ava.ava_private = &v2_flags;
601
 
                } else {
602
 
                        ava.ava_private = NULL;
603
 
                }
604
 
                retVal = plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava);
605
 
        }
606
 
        return retVal;
 
610
    struct ava ava;
 
611
    Slapi_Attr a2 = *a;
 
612
    Slapi_Value *cvals[2];
 
613
    unsigned long v2_flags = v2->v_flags;
 
614
    const struct berval *bv2 = slapi_value_get_berval(v2);
 
615
 
 
616
    if ( a->a_flags == 0 && a->a_plugin == NULL ) {
 
617
       slapi_attr_init_syntax ((Slapi_Attr *)a);
 
618
    }
 
619
    cvals[0] = v1;
 
620
    cvals[1] = NULL;
 
621
    a2.a_present_values.va = cvals;
 
622
    ava.ava_type = a->a_type;
 
623
    ava.ava_value = *bv2;
 
624
    if (v2_flags) {
 
625
        ava.ava_private = &v2_flags;
 
626
    } else {
 
627
        ava.ava_private = NULL;
 
628
    }
 
629
 
 
630
    return (plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava));
607
631
}
608
632
 
609
633
/*
798
822
    int i = 0;
799
823
    int numofvals = 0;
800
824
    int duplicate_index = -1;
801
 
    int was_present_null = 0;
802
825
    int rc = LDAP_SUCCESS;
803
826
 
804
827
    if (valuearray_isempty(vals)) {
809
832
    }
810
833
 
811
834
    /*
812
 
     * determine whether we should use an AVL tree of values or not
813
 
     */
814
 
    for ( i = 0; vals[i] != NULL; i++ ) ;
815
 
    numofvals = i;
816
 
 
817
 
    /*
818
 
     * detect duplicate values
819
 
     */
820
 
    if ( numofvals > 1 ) {
821
 
        /*
822
 
         * Several values to add: use an AVL tree to detect duplicates.
823
 
         */
824
 
        LDAPDebug( LDAP_DEBUG_TRACE,
825
 
                   "slapi_entry_add_values: using an AVL tree to "
826
 
                   "detect duplicate values\n", 0, 0, 0 );
827
 
 
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
831
 
             */
832
 
            Avlnode *vtree = NULL;
833
 
            rc= valuetree_add_valuearray(a, vals, &vtree, &duplicate_index);
834
 
            valuetree_free(&vtree);
835
 
            was_present_null = 1;
836
 
        } else {
837
 
            /* the attr and vals both contain values, check intersection */
838
 
            rc= valueset_intersectswith_valuearray(&a->a_present_values, a, vals, &duplicate_index);
839
 
        }
840
 
 
841
 
    } else if ( !valueset_isempty(&a->a_present_values) ) {
842
 
        /*
843
 
         * One or no value to add: don't bother constructing
844
 
         * an AVL tree, etc. since it probably isn't worth the time.
845
 
         */
846
 
        for ( i = 0; vals[i] != NULL; ++i ) {
847
 
            if ( slapi_attr_value_find( a, slapi_value_get_berval(vals[i]) ) == 0 ) {
848
 
                duplicate_index = i;
 
835
     * add values and check for duplicate values
 
836
     */
 
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
858
849
#else
859
850
                rc = LDAP_TYPE_OR_VALUE_EXISTS;
860
851
#endif
861
 
                break;
862
852
            }
863
 
        }
864
 
    }
865
 
 
866
 
    /*
867
 
     * add values if no duplicates detected
868
 
     */
869
 
    if(rc==LDAP_SUCCESS) {
870
 
        valueset_add_valuearray( &a->a_present_values, vals );
871
 
    }
872
853
 
873
854
    /* In the case of duplicate value, rc == LDAP_TYPE_OR_VALUE_EXISTS or
874
855
     * LDAP_OPERATIONS_ERROR
875
856
     */
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";
879
860
 
901
882
                duplicate_string,
902
883
                a->a_type,
903
884
                dn ? dn : "<null>", 
904
 
                (was_present_null ? "duplicate new value" : "value exists"));
 
885
                "value exists");
905
886
    }
906
887
    return( rc );
907
888
}
914
895
 */
915
896
int attr_replace(Slapi_Attr *a, Slapi_Value **vals)
916
897
{
917
 
    return valueset_replace(a, &a->a_present_values, vals);
 
898
    return valueset_replace_valuearray(a, &a->a_present_values, vals);
918
899
}
919
900
 
920
901
int