aboutsummaryrefslogtreecommitdiff
path: root/src/credential/plugin_gnsrecord_credential.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/credential/plugin_gnsrecord_credential.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/credential/plugin_gnsrecord_credential.c')
-rw-r--r--src/credential/plugin_gnsrecord_credential.c254
1 files changed, 128 insertions, 126 deletions
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 134153c13..269e558c2 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -43,14 +43,14 @@
43 * @return NULL on error, otherwise human-readable representation of the value 43 * @return NULL on error, otherwise human-readable representation of the value
44 */ 44 */
45static char * 45static char *
46credential_value_to_string(void *cls, uint32_t type, const void *data, 46credential_value_to_string (void *cls, uint32_t type, const void *data,
47 size_t data_size) 47 size_t data_size)
48{ 48{
49 const char *cdata; 49 const char *cdata;
50 50
51 switch (type) 51 switch (type)
52 { 52 {
53 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { 53 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
54 struct GNUNET_CREDENTIAL_DelegationRecord sets; 54 struct GNUNET_CREDENTIAL_DelegationRecord sets;
55 char *attr_str; 55 char *attr_str;
56 char *subject_pkey; 56 char *subject_pkey;
@@ -58,70 +58,70 @@ credential_value_to_string(void *cls, uint32_t type, const void *data,
58 int i; 58 int i;
59 if (data_size < sizeof(struct GNUNET_CREDENTIAL_DelegationRecord)) 59 if (data_size < sizeof(struct GNUNET_CREDENTIAL_DelegationRecord))
60 return NULL; /* malformed */ 60 return NULL; /* malformed */
61 GNUNET_memcpy(&sets, data, sizeof(sets)); 61 GNUNET_memcpy (&sets, data, sizeof(sets));
62 cdata = data; 62 cdata = data;
63 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)]; 63 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)];
64 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize( 64 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (
65 GNUNET_ntohll(sets.data_size), &cdata[sizeof(sets)], 65 GNUNET_ntohll (sets.data_size), &cdata[sizeof(sets)],
66 ntohl(sets.set_count), set)) 66 ntohl (sets.set_count), set))
67 return NULL; 67 return NULL;
68 68
69 for (i = 0; i < ntohl(sets.set_count); i++) 69 for (i = 0; i < ntohl (sets.set_count); i++)
70 {
71 subject_pkey =
72 GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n",
74 set[i].subject_attribute_len);
75 if (0 == set[i].subject_attribute_len)
70 { 76 {
71 subject_pkey = 77 if (0 == i)
72 GNUNET_CRYPTO_ecdsa_public_key_to_string(&set[i].subject_key); 78 {
73 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n", 79 GNUNET_asprintf (&attr_str, "%s", subject_pkey);
74 set[i].subject_attribute_len); 80 }
75 if (0 == set[i].subject_attribute_len)
76 {
77 if (0 == i)
78 {
79 GNUNET_asprintf(&attr_str, "%s", subject_pkey);
80 }
81 else
82 {
83 GNUNET_asprintf(&tmp_str, "%s,%s", attr_str, subject_pkey);
84 GNUNET_free(attr_str);
85 attr_str = tmp_str;
86 }
87 }
88 else 81 else
89 { 82 {
90 if (0 == i) 83 GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey);
91 { 84 GNUNET_free (attr_str);
92 GNUNET_asprintf(&attr_str, "%s %s", subject_pkey, 85 attr_str = tmp_str;
93 set[i].subject_attribute); 86 }
94 }
95 else
96 {
97 GNUNET_asprintf(&tmp_str, "%s,%s %s", attr_str, subject_pkey,
98 set[i].subject_attribute);
99 GNUNET_free(attr_str);
100 attr_str = tmp_str;
101 }
102 }
103 GNUNET_free(subject_pkey);
104 } 87 }
88 else
89 {
90 if (0 == i)
91 {
92 GNUNET_asprintf (&attr_str, "%s %s", subject_pkey,
93 set[i].subject_attribute);
94 }
95 else
96 {
97 GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey,
98 set[i].subject_attribute);
99 GNUNET_free (attr_str);
100 attr_str = tmp_str;
101 }
102 }
103 GNUNET_free (subject_pkey);
104 }
105 return attr_str; 105 return attr_str;
106 } 106 }
107 107
108 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { 108 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
109 struct GNUNET_CREDENTIAL_Credential *cred; 109 struct GNUNET_CREDENTIAL_Credential *cred;
110 char *cred_str; 110 char *cred_str;
111 111
112 cred = GNUNET_CREDENTIAL_credential_deserialize(data, data_size); 112 cred = GNUNET_CREDENTIAL_credential_deserialize (data, data_size);
113 cred_str = GNUNET_CREDENTIAL_credential_to_string(cred); 113 cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
114 GNUNET_free(cred); 114 GNUNET_free (cred);
115 return cred_str; 115 return cred_str;
116 } 116 }
117 117
118 case GNUNET_GNSRECORD_TYPE_POLICY: { 118 case GNUNET_GNSRECORD_TYPE_POLICY: {
119 return GNUNET_strndup(data, data_size); 119 return GNUNET_strndup (data, data_size);
120 } 120 }
121 121
122 default: 122 default:
123 return NULL; 123 return NULL;
124 } 124 }
125} 125}
126 126
127 127
@@ -137,14 +137,14 @@ credential_value_to_string(void *cls, uint32_t type, const void *data,
137 * @return #GNUNET_OK on success 137 * @return #GNUNET_OK on success
138 */ 138 */
139static int 139static int
140credential_string_to_value(void *cls, uint32_t type, const char *s, 140credential_string_to_value (void *cls, uint32_t type, const char *s,
141 void **data, size_t *data_size) 141 void **data, size_t *data_size)
142{ 142{
143 if (NULL == s) 143 if (NULL == s)
144 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
145 switch (type) 145 switch (type)
146 { 146 {
147 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: { 147 case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
148 struct GNUNET_CREDENTIAL_DelegationRecord *sets; 148 struct GNUNET_CREDENTIAL_DelegationRecord *sets;
149 char attr_str[253 + 1]; 149 char attr_str[253 + 1];
150 char subject_pkey[52 + 1]; 150 char subject_pkey[52 + 1];
@@ -155,96 +155,97 @@ credential_string_to_value(void *cls, uint32_t type, const char *s,
155 size_t tmp_data_size; 155 size_t tmp_data_size;
156 int i; 156 int i;
157 157
158 tmp_str = GNUNET_strdup(s); 158 tmp_str = GNUNET_strdup (s);
159 token = strtok(tmp_str, ","); 159 token = strtok (tmp_str, ",");
160 entries = 0; 160 entries = 0;
161 tmp_data_size = 0; 161 tmp_data_size = 0;
162 *data_size = sizeof(struct GNUNET_CREDENTIAL_DelegationRecord); 162 *data_size = sizeof(struct GNUNET_CREDENTIAL_DelegationRecord);
163 while (NULL != token) 163 while (NULL != token)
164 {
165 matches = sscanf (token, "%s %s", subject_pkey, attr_str);
166 if (0 == matches)
167 {
168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
169 _ ("Unable to parse ATTR record string `%s'\n"), s);
170 GNUNET_free (tmp_str);
171 return GNUNET_SYSERR;
172 }
173 if (1 == matches)
164 { 174 {
165 matches = sscanf(token, "%s %s", subject_pkey, attr_str); 175 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet);
166 if (0 == matches)
167 {
168 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
169 _("Unable to parse ATTR record string `%s'\n"), s);
170 GNUNET_free(tmp_str);
171 return GNUNET_SYSERR;
172 }
173 if (1 == matches)
174 {
175 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet);
176 }
177 else if (2 == matches)
178 {
179 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet) +
180 strlen(attr_str) + 1;
181 }
182 entries++;
183 token = strtok(NULL, ",");
184 } 176 }
185 GNUNET_free(tmp_str); 177 else if (2 == matches)
186 tmp_str = GNUNET_strdup(s);
187 token = strtok(tmp_str, ",");
188 if (NULL == token)
189 { 178 {
190 GNUNET_free(tmp_str); 179 tmp_data_size += sizeof(struct GNUNET_CREDENTIAL_DelegationRecordSet)
191 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s); 180 + strlen (attr_str) + 1;
192 return GNUNET_SYSERR;
193 } 181 }
182 entries++;
183 token = strtok (NULL, ",");
184 }
185 GNUNET_free (tmp_str);
186 tmp_str = GNUNET_strdup (s);
187 token = strtok (tmp_str, ",");
188 if (NULL == token)
189 {
190 GNUNET_free (tmp_str);
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
192 return GNUNET_SYSERR;
193 }
194 struct GNUNET_CREDENTIAL_DelegationSet set[entries]; 194 struct GNUNET_CREDENTIAL_DelegationSet set[entries];
195 memset(set, 0, sizeof(struct GNUNET_CREDENTIAL_DelegationSet) * entries); 195 memset (set, 0, sizeof(struct GNUNET_CREDENTIAL_DelegationSet) * entries);
196 for (i = 0; i < entries; i++) 196 for (i = 0; i < entries; i++)
197 {
198 matches = sscanf (token, "%s %s", subject_pkey, attr_str);
199 GNUNET_CRYPTO_ecdsa_public_key_from_string (
200 subject_pkey, strlen (subject_pkey), &set[i].subject_key);
201 if (2 == matches)
197 { 202 {
198 matches = sscanf(token, "%s %s", subject_pkey, attr_str); 203 set[i].subject_attribute_len = strlen (attr_str) + 1;
199 GNUNET_CRYPTO_ecdsa_public_key_from_string( 204 set[i].subject_attribute = GNUNET_strdup (attr_str);
200 subject_pkey, strlen(subject_pkey), &set[i].subject_key);
201 if (2 == matches)
202 {
203 set[i].subject_attribute_len = strlen(attr_str) + 1;
204 set[i].subject_attribute = GNUNET_strdup(attr_str);
205 }
206 token = strtok(NULL, ",");
207 } 205 }
208 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size(entries, set); 206 token = strtok (NULL, ",");
207 }
208 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set);
209 209
210 if (-1 == tmp_data_size) 210 if (-1 == tmp_data_size)
211 { 211 {
212 GNUNET_free(tmp_str); 212 GNUNET_free (tmp_str);
213 return GNUNET_SYSERR; 213 return GNUNET_SYSERR;
214 } 214 }
215 *data_size += tmp_data_size; 215 *data_size += tmp_data_size;
216 *data = sets = GNUNET_malloc(*data_size); 216 *data = sets = GNUNET_malloc (*data_size);
217 GNUNET_CREDENTIAL_delegation_set_serialize(entries, set, tmp_data_size, 217 GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size,
218 (char *)&sets[1]); 218 (char *) &sets[1]);
219 for (i = 0; i < entries; i++) 219 for (i = 0; i < entries; i++)
220 { 220 {
221 if (0 != set[i].subject_attribute_len) 221 if (0 != set[i].subject_attribute_len)
222 GNUNET_free((char *)set[i].subject_attribute); 222 GNUNET_free ((char *) set[i].subject_attribute);
223 } 223 }
224 sets->set_count = htonl(entries); 224 sets->set_count = htonl (entries);
225 sets->data_size = GNUNET_htonll(tmp_data_size); 225 sets->data_size = GNUNET_htonll (tmp_data_size);
226 226
227 GNUNET_free(tmp_str); 227 GNUNET_free (tmp_str);
228 return GNUNET_OK; 228 return GNUNET_OK;
229 } 229 }
230 230
231 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: { 231 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
232 struct GNUNET_CREDENTIAL_Credential *cred; 232 struct GNUNET_CREDENTIAL_Credential *cred;
233 cred = GNUNET_CREDENTIAL_credential_from_string(s); 233 cred = GNUNET_CREDENTIAL_credential_from_string (s);
234 234
235 *data_size = GNUNET_CREDENTIAL_credential_serialize(cred, (char **)data); 235 *data_size = GNUNET_CREDENTIAL_credential_serialize (cred,
236 (char **) data);
236 return GNUNET_OK; 237 return GNUNET_OK;
237 } 238 }
238 239
239 case GNUNET_GNSRECORD_TYPE_POLICY: { 240 case GNUNET_GNSRECORD_TYPE_POLICY: {
240 *data_size = strlen(s); 241 *data_size = strlen (s);
241 *data = GNUNET_strdup(s); 242 *data = GNUNET_strdup (s);
242 return GNUNET_OK; 243 return GNUNET_OK;
243 } 244 }
244 245
245 default: 246 default:
246 return GNUNET_SYSERR; 247 return GNUNET_SYSERR;
247 } 248 }
248} 249}
249 250
250 251
@@ -252,7 +253,8 @@ credential_string_to_value(void *cls, uint32_t type, const char *s,
252 * Mapping of record type numbers to human-readable 253 * Mapping of record type numbers to human-readable
253 * record type names. 254 * record type names.
254 */ 255 */
255static struct { 256static struct
257{
256 const char *name; 258 const char *name;
257 uint32_t number; 259 uint32_t number;
258} name_map[] = { { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL }, 260} name_map[] = { { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL },
@@ -269,13 +271,13 @@ static struct {
269 * @return corresponding number, UINT32_MAX on error 271 * @return corresponding number, UINT32_MAX on error
270 */ 272 */
271static uint32_t 273static uint32_t
272credential_typename_to_number(void *cls, const char *gns_typename) 274credential_typename_to_number (void *cls, const char *gns_typename)
273{ 275{
274 unsigned int i; 276 unsigned int i;
275 277
276 i = 0; 278 i = 0;
277 while ((name_map[i].name != NULL) && 279 while ((name_map[i].name != NULL) &&
278 (0 != strcasecmp(gns_typename, name_map[i].name))) 280 (0 != strcasecmp (gns_typename, name_map[i].name)))
279 i++; 281 i++;
280 return name_map[i].number; 282 return name_map[i].number;
281} 283}
@@ -289,7 +291,7 @@ credential_typename_to_number(void *cls, const char *gns_typename)
289 * @return corresponding typestring, NULL on error 291 * @return corresponding typestring, NULL on error
290 */ 292 */
291static const char * 293static const char *
292credential_number_to_typename(void *cls, uint32_t type) 294credential_number_to_typename (void *cls, uint32_t type)
293{ 295{
294 unsigned int i; 296 unsigned int i;
295 297
@@ -307,11 +309,11 @@ credential_number_to_typename(void *cls, uint32_t type)
307 * @return the exported block API 309 * @return the exported block API
308 */ 310 */
309void * 311void *
310libgnunet_plugin_gnsrecord_credential_init(void *cls) 312libgnunet_plugin_gnsrecord_credential_init (void *cls)
311{ 313{
312 struct GNUNET_GNSRECORD_PluginFunctions *api; 314 struct GNUNET_GNSRECORD_PluginFunctions *api;
313 315
314 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); 316 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
315 api->value_to_string = &credential_value_to_string; 317 api->value_to_string = &credential_value_to_string;
316 api->string_to_value = &credential_string_to_value; 318 api->string_to_value = &credential_string_to_value;
317 api->typename_to_number = &credential_typename_to_number; 319 api->typename_to_number = &credential_typename_to_number;
@@ -327,11 +329,11 @@ libgnunet_plugin_gnsrecord_credential_init(void *cls)
327 * @return NULL 329 * @return NULL
328 */ 330 */
329void * 331void *
330libgnunet_plugin_gnsrecord_credential_done(void *cls) 332libgnunet_plugin_gnsrecord_credential_done (void *cls)
331{ 333{
332 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 334 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
333 335
334 GNUNET_free(api); 336 GNUNET_free (api);
335 return NULL; 337 return NULL;
336} 338}
337 339