]> git.sur5r.net Git - ngadmin/blob - raw/src/attr.c
c8f2fcc49848409fae3f1eb1a80c6d1c99b1ba69
[ngadmin] / raw / src / attr.c
1
2 #include <stdarg.h>
3
4 #include <nsdp/attr.h>
5 #include <nsdp/protocol.h>
6
7
8
9 struct attr* newAttr (unsigned short attr, unsigned short size, void *data)
10 {
11         struct attr *at;
12         
13         
14         at = malloc(sizeof(struct attr));
15         if (at == NULL)
16                 return NULL;
17         
18         at->attr = attr;
19         at->size = size;
20         at->data = data;
21         
22         
23         return at;
24 }
25
26
27 void freeAttr (struct attr *at)
28 {
29         if (at != NULL) {
30                 free(at->data);
31                 free(at);
32         }
33 }
34
35
36 void filterAttributes (List *attr, ...)
37 {
38         va_list ap;
39         ListNode *ln, *pr;
40         struct attr *at;
41         unsigned short attrcode;
42         bool keep;
43         
44         
45         ln = attr->first;
46         while (ln != NULL) {
47                 at = ln->data;
48                 
49                 va_start(ap, attr);
50                 keep = false;
51                 attrcode = 0;
52                 while (!keep && attrcode != ATTR_END) {
53                         attrcode = (unsigned short)va_arg(ap, unsigned int);
54                         keep = keep || (at->attr == attrcode);
55                 }
56                 va_end(ap);
57                 
58                 if (keep) {
59                         ln = ln->next;
60                 } else {
61                         pr = ln;
62                         ln = ln->next;
63                         destroyElement(attr, pr, (void(*)(void*))freeAttr);
64                 }
65         }
66         
67 }
68
69