aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_reclaim_attribute_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_reclaim_attribute_lib.h')
-rw-r--r--src/include/gnunet_reclaim_attribute_lib.h281
1 files changed, 281 insertions, 0 deletions
diff --git a/src/include/gnunet_reclaim_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h
new file mode 100644
index 000000000..df5356d76
--- /dev/null
+++ b/src/include/gnunet_reclaim_attribute_lib.h
@@ -0,0 +1,281 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2017 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @author Martin Schanzenbach
21 *
22 * @file
23 * Identity attribute definitions
24 *
25 * @defgroup identity-provider Identity Provider service
26 * @{
27 */
28#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
29#define GNUNET_RECLAIM_ATTRIBUTE_LIB_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39#include "gnunet_util_lib.h"
40
41
42/**
43 * No value attribute.
44 */
45#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE 0
46
47/**
48 * String attribute.
49 */
50#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1
51
52
53
54/**
55 * An attribute.
56 */
57struct GNUNET_RECLAIM_ATTRIBUTE_Claim
58{
59 /**
60 * The name of the attribute. Note "name" must never be individually
61 * free'd
62 */
63 const char* name;
64
65 /**
66 * Type of Claim
67 */
68 uint32_t type;
69
70 /**
71 * Version
72 */
73 uint32_t version;
74
75 /**
76 * Number of bytes in @e data.
77 */
78 size_t data_size;
79
80 /**
81 * Binary value stored as attribute value. Note: "data" must never
82 * be individually 'malloc'ed, but instead always points into some
83 * existing data area.
84 */
85 const void *data;
86
87};
88
89struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
90{
91 /**
92 * List head
93 */
94 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head;
95
96 /**
97 * List tail
98 */
99 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail;
100};
101
102struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry
103{
104 /**
105 * DLL
106 */
107 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev;
108
109 /**
110 * DLL
111 */
112 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next;
113
114 /**
115 * The attribute claim
116 */
117 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
118};
119
120/**
121 * Create a new attribute claim.
122 *
123 * @param attr_name the attribute name
124 * @param type the attribute type
125 * @param data the attribute value
126 * @param data_size the attribute value size
127 * @return the new attribute
128 */
129struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
130GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
131 uint32_t type,
132 const void* data,
133 size_t data_size);
134
135
136/**
137 * Get required size for serialization buffer
138 *
139 * @param attrs the attribute list to serialize
140 *
141 * @return the required buffer size
142 */
143size_t
144GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
145
146void
147GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
148
149void
150GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
151 const char* attr_name,
152 uint32_t type,
153 const void* data,
154 size_t data_size);
155
156/**
157 * Serialize an attribute list
158 *
159 * @param attrs the attribute list to serialize
160 * @param result the serialized attribute
161 *
162 * @return length of serialized data
163 */
164size_t
165GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
166 char *result);
167
168/**
169 * Deserialize an attribute list
170 *
171 * @param data the serialized attribute list
172 * @param data_size the length of the serialized data
173 *
174 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
175 */
176struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
177GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
178 size_t data_size);
179
180
181/**
182 * Get required size for serialization buffer
183 *
184 * @param attr the attribute to serialize
185 *
186 * @return the required buffer size
187 */
188size_t
189GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
190
191
192
193/**
194 * Serialize an attribute
195 *
196 * @param attr the attribute to serialize
197 * @param result the serialized attribute
198 *
199 * @return length of serialized data
200 */
201size_t
202GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
203 char *result);
204
205/**
206 * Deserialize an attribute
207 *
208 * @param data the serialized attribute
209 * @param data_size the length of the serialized data
210 *
211 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
212 */
213struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
214GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
215 size_t data_size);
216
217struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList*
218GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
219
220/**
221 * Convert a type name to the corresponding number
222 *
223 * @param typename name to convert
224 * @return corresponding number, UINT32_MAX on error
225 */
226uint32_t
227GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename);
228
229/**
230 * Convert human-readable version of a 'claim' of an attribute to the binary
231 * representation
232 *
233 * @param type type of the claim
234 * @param s human-readable string
235 * @param data set to value in binary encoding (will be allocated)
236 * @param data_size set to number of bytes in @a data
237 * @return #GNUNET_OK on success
238 */
239int
240GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
241 const char *s,
242 void **data,
243 size_t *data_size);
244
245/**
246 * Convert the 'claim' of an attribute to a string
247 *
248 * @param type the type of attribute
249 * @param data claim in binary encoding
250 * @param data_size number of bytes in @a data
251 * @return NULL on error, otherwise human-readable representation of the claim
252 */
253char *
254GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
255 const void* data,
256 size_t data_size);
257
258/**
259 * Convert a type number to the corresponding type string
260 *
261 * @param type number of a type
262 * @return corresponding typestring, NULL on error
263 */
264const char*
265GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type);
266
267
268#if 0 /* keep Emacsens' auto-indent happy */
269{
270#endif
271#ifdef __cplusplus
272}
273#endif
274
275
276/* ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H */
277#endif
278
279/** @} */ /* end of group identity */
280
281/* end of gnunet_reclaim_attribute_lib.h */