~ubuntu-branches/ubuntu/wily/389-ds-base/wily-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-07-08 15:50:11 UTC
  • mto: (19.1.1 experimental) (0.3.1)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20140708155011-48naeyka2x89ew8g
Tags: upstream-1.3.2.19
ImportĀ upstreamĀ versionĀ 1.3.2.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
static Slapi_RWLock *oid2asi_lock = NULL;
59
59
static PLHashTable *internalasi = NULL;
60
60
 
 
61
/* global attribute linked list */
 
62
static asyntaxinfo *global_at = NULL;
 
63
 
61
64
/*
62
65
 * This hashtable maps the name or alias of the attribute to the
63
66
 * syntax info structure for that attribute.  An attribute type has as
82
85
                PRBool remove_from_oid_table );
83
86
static struct asyntaxinfo *attr_syntax_get_by_oid_locking_optional( const
84
87
                char *oid, PRBool use_lock);
 
88
static void attr_syntax_insert( struct asyntaxinfo *asip );
 
89
static void attr_syntax_remove( struct asyntaxinfo *asip );
85
90
 
86
91
#ifdef ATTR_LDAP_DEBUG
87
92
static void attr_syntax_print();
88
93
#endif
89
94
static int attr_syntax_init(void);
90
95
 
 
96
struct asyntaxinfo *
 
97
attr_syntax_get_global_at()
 
98
{
 
99
        return global_at;
 
100
}
 
101
 
91
102
void
92
103
attr_syntax_read_lock(void)
93
104
{
202
213
        PR_ASSERT( a->asi_refcnt == 0 );
203
214
 
204
215
        cool_charray_free( a->asi_aliases );
205
 
        slapi_ch_free( (void**)&a->asi_name );
206
 
        slapi_ch_free( (void **)&a->asi_desc );
207
 
        slapi_ch_free( (void **)&a->asi_oid );
208
 
        slapi_ch_free( (void **)&a->asi_superior );
209
 
        slapi_ch_free( (void **)&a->asi_mr_equality );
210
 
        slapi_ch_free( (void **)&a->asi_mr_ordering );
211
 
        slapi_ch_free( (void **)&a->asi_mr_substring );
 
216
        slapi_ch_free_string(&a->asi_name );
 
217
        slapi_ch_free_string(&a->asi_desc );
 
218
        slapi_ch_free_string(&a->asi_oid );
 
219
        slapi_ch_free_string(&a->asi_superior );
 
220
        slapi_ch_free_string(&a->asi_mr_equality );
 
221
        slapi_ch_free_string(&a->asi_mr_ordering );
 
222
        slapi_ch_free_string(&a->asi_mr_substring );
 
223
        slapi_ch_free_string(&a->asi_syntax_oid);
212
224
        schema_free_extensions(a->asi_extensions);
213
225
        slapi_ch_free( (void **) &a );
214
226
}
380
392
                                }
381
393
                                /* ref count is 0 and it's flagged for
382
394
                                 * deletion, so it's safe to free now */
 
395
                                attr_syntax_remove(asi);
383
396
                                attr_syntax_free(asi);
384
397
                                if(use_lock) {
385
398
                                        AS_UNLOCK_WRITE(name2asi_lock);
411
424
                AS_LOCK_WRITE(name2asi_lock);
412
425
        }
413
426
 
 
427
        /* insert the attr into the global linked list */
 
428
        attr_syntax_insert(a);
 
429
 
414
430
        PL_HashTableAdd(name2asi, a->asi_name, a);
415
431
        if ( a->asi_aliases != NULL ) {
416
432
                int             i;
475
491
                         * then to call return.  The last return will then take care of
476
492
                         * the free.  The only way this free would happen here is if
477
493
                         * you return the syntax before calling delete. */
 
494
                        attr_syntax_remove(asi);
478
495
                        attr_syntax_free(asi);
479
496
                }
480
497
        }
764
781
        newas->asi_mr_eq_plugin = a->asi_mr_eq_plugin;
765
782
        newas->asi_mr_ord_plugin = a->asi_mr_ord_plugin;
766
783
        newas->asi_mr_sub_plugin = a->asi_mr_sub_plugin;
 
784
        newas->asi_syntax_oid = slapi_ch_strdup(a->asi_syntax_oid);
 
785
        newas->asi_next = NULL;
 
786
        newas->asi_prev = NULL;
767
787
 
768
788
        return( newas );
769
789
}
770
790
 
 
791
static void
 
792
attr_syntax_insert(struct asyntaxinfo *asip )
 
793
{
 
794
    /* Insert at top of list */
 
795
    asip->asi_prev = NULL;
 
796
    asip->asi_next = global_at;
 
797
    if(global_at){
 
798
        global_at->asi_prev = asip;
 
799
        global_at = asip;
 
800
    } else {
 
801
        global_at = asip;
 
802
    }
 
803
}
 
804
 
 
805
static void
 
806
attr_syntax_remove(struct asyntaxinfo *asip )
 
807
{
 
808
    struct asyntaxinfo *prev, *next;
 
809
 
 
810
    prev = asip->asi_prev;
 
811
    next = asip->asi_next;
 
812
    if(prev){
 
813
        prev->asi_next = next;
 
814
        if(next){
 
815
            next->asi_prev = prev;
 
816
        }
 
817
    } else {
 
818
        if(next){
 
819
            next->asi_prev = NULL;
 
820
        }
 
821
        global_at = next;
 
822
    }
 
823
}
771
824
 
772
825
/*
773
826
 * Add a new attribute type to the schema.
918
971
        a.asi_mr_substring = (char*)mr_substring;
919
972
        a.asi_extensions = extensions;
920
973
        a.asi_plugin = plugin_syntax_find( attr_syntax );
 
974
        a.asi_syntax_oid = (char *)attr_syntax ;
921
975
        a.asi_syntaxlength = syntaxlength;
922
976
        /* ideally, we would report an error and fail to start if there was some problem
923
977
           with the matching rule - but since this functionality is new, and we might
1503
1557
        attr_syntax_enumerate_attrs_ext(internalasi, attr_syntax_internal_asi_add, NULL);
1504
1558
        return rc;
1505
1559
}
 
1560
 
 
1561
/*
 
1562
 * See if the attribute at1 is in the list of at2.  Change by name, and oid(if necessary).
 
1563
 */
 
1564
struct asyntaxinfo *
 
1565
attr_syntax_find(struct asyntaxinfo *at1, struct asyntaxinfo *at2)
 
1566
{
 
1567
        struct asyntaxinfo *asi;
 
1568
 
 
1569
        for(asi = at2; asi != NULL; asi = asi->asi_next){
 
1570
                if(strcasecmp(at1->asi_name, asi->asi_name) == 0 || strcmp(at1->asi_oid, asi->asi_oid) == 0){
 
1571
                        /* found it */
 
1572
                        return asi;
 
1573
                }
 
1574
        }
 
1575
 
 
1576
        return NULL;
 
1577
}