source: libabac/abac_list.c @ d0efdec

mei_rt2
Last change on this file since d0efdec was 2e9455f, checked in by Mei <mei@…>, 11 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include <stdlib.h>
2
3#include "abac_util.h"
4#include "abac_list.h"
5
6/****************************************************************/
7abac_list_t *abac_list_new(void) {
8    abac_list_t *ret = abac_xmalloc(sizeof(abac_list_t));
9    ret->elts = NULL;
10    ret->size = 0;
11    return ret;
12}
13
14void abac_list_add(abac_list_t *list, void *elt) {
15    abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t));
16
17    new_element->ptr = elt;
18    DL_APPEND(list->elts, new_element);
19    ++list->size;
20}
21
22/* add only if it is not in the list already */
23int abac_list_unique_add(abac_list_t *list, void *elt) {
24    void *cur;
25    abac_list_foreach(list, cur,
26        if(cur == elt) 
27            return 0;
28    );
29
30    abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t));
31    new_element->ptr = elt;
32    DL_APPEND(list->elts, new_element);
33    ++list->size;
34    return 1;
35}
36
37void abac_list_prepend(abac_list_t *list, void *elt) {
38    abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t));
39
40    new_element->ptr = elt;
41    DL_PREPEND(list->elts, new_element);
42    ++list->size;
43}
44
45int abac_list_remove(abac_list_t *list, void *elt) {
46    abac_list_element_t *cur;
47
48    // iterate the list, remove the item if we find it
49    DL_FOREACH(list->elts, cur) {
50        if (cur->ptr == elt) {
51            DL_DELETE(list->elts, cur);
52            free(cur);
53            --list->size;
54            return 1;
55        }
56    }
57
58    // return false if we don't
59    return 0;
60}
61
62int abac_list_size(abac_list_t *list) {
63    if (list)
64        return list->size;
65    return 0;
66}
67
68void abac_list_free(abac_list_t *list) {
69    abac_list_element_t *elt, *tmp;
70
71    if (list) {
72        // free everthing in the list
73        DL_FOREACH_SAFE(list->elts, elt, tmp) {
74            DL_DELETE(list->elts, elt);
75            free(elt);
76        }
77
78        // free the list
79        free(list);
80    }
81}
Note: See TracBrowser for help on using the repository browser.