]> git.sur5r.net Git - ngadmin/blob - raw/include/attr.h
Start reorganization of low level library
[ngadmin] / raw / include / attr.h
1
2 #ifndef DEF_ATTR
3 #define DEF_ATTR
4
5
6 #include <stdlib.h>
7
8 #include <arpa/inet.h>
9
10 #include <list.h>
11
12
13
14 struct attr {
15         unsigned short attr;    /* attribute code */
16         unsigned short size;    /* attribute size */
17         void *data;             /* attribute data */
18 };
19
20
21
22 struct attr* newAttr (unsigned short attr, unsigned short size, void *data);
23
24
25 static inline struct attr* newEmptyAttr (unsigned short attr)
26 {
27         return newAttr(attr, 0, NULL);
28 }
29
30
31 static inline struct attr* newByteAttr (unsigned short attr, unsigned char value)
32 {
33         char *v = malloc(sizeof(char));
34         
35         *v = value;
36         
37         return newAttr(attr, sizeof(char), v);
38 }
39
40
41 static inline struct attr* newShortAttr (unsigned short attr, short value)
42 {
43         short *v = malloc(sizeof(short));
44         
45         *v = value;
46         
47         return newAttr(attr, sizeof(short), v);
48 }
49
50
51 static inline struct attr* newIntAttr (unsigned short attr, int value)
52 {
53         int *v = malloc(sizeof(int));
54         
55         *v = value;
56         
57         return newAttr(attr, sizeof(int), v);
58 }
59
60
61 static inline struct attr* newAddrAttr (unsigned short attr, struct in_addr value)
62 {
63         struct in_addr *v = malloc(sizeof(struct in_addr));
64         
65         *v = value;
66         
67         return newAttr(attr, sizeof(struct in_addr), v);
68 }
69
70
71 void freeAttr (struct attr *at);
72
73
74 void filterAttributes (List *attr, ...);
75
76
77 #endif
78