diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/reclaim | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 715 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 1273 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 1154 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.h | 45 | ||||
-rw-r--r-- | src/reclaim/json_reclaim.c | 244 | ||||
-rw-r--r-- | src/reclaim/json_reclaim.h | 6 | ||||
-rw-r--r-- | src/reclaim/oidc_helper.h | 46 | ||||
-rw-r--r-- | src/reclaim/plugin_gnsrecord_reclaim.c | 101 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_openid_connect.c | 2084 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 941 | ||||
-rw-r--r-- | src/reclaim/reclaim.h | 50 | ||||
-rw-r--r-- | src/reclaim/reclaim_api.c | 576 |
12 files changed, 3643 insertions, 3592 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index b2f6b4c3c..5160aef7f 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @file src/reclaim/gnunet-reclaim.c | 22 | * @file src/reclaim/gnunet-reclaim.c |
@@ -168,175 +168,176 @@ static char *attr_delete; | |||
168 | static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; | 168 | static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; |
169 | 169 | ||
170 | static void | 170 | static void |
171 | do_cleanup (void *cls) | 171 | do_cleanup(void *cls) |
172 | { | 172 | { |
173 | cleanup_task = NULL; | 173 | cleanup_task = NULL; |
174 | if (NULL != timeout) | 174 | if (NULL != timeout) |
175 | GNUNET_SCHEDULER_cancel (timeout); | 175 | GNUNET_SCHEDULER_cancel(timeout); |
176 | if (NULL != reclaim_op) | 176 | if (NULL != reclaim_op) |
177 | GNUNET_RECLAIM_cancel (reclaim_op); | 177 | GNUNET_RECLAIM_cancel(reclaim_op); |
178 | if (NULL != attr_iterator) | 178 | if (NULL != attr_iterator) |
179 | GNUNET_RECLAIM_get_attributes_stop (attr_iterator); | 179 | GNUNET_RECLAIM_get_attributes_stop(attr_iterator); |
180 | if (NULL != ticket_iterator) | 180 | if (NULL != ticket_iterator) |
181 | GNUNET_RECLAIM_ticket_iteration_stop (ticket_iterator); | 181 | GNUNET_RECLAIM_ticket_iteration_stop(ticket_iterator); |
182 | if (NULL != reclaim_handle) | 182 | if (NULL != reclaim_handle) |
183 | GNUNET_RECLAIM_disconnect (reclaim_handle); | 183 | GNUNET_RECLAIM_disconnect(reclaim_handle); |
184 | if (NULL != identity_handle) | 184 | if (NULL != identity_handle) |
185 | GNUNET_IDENTITY_disconnect (identity_handle); | 185 | GNUNET_IDENTITY_disconnect(identity_handle); |
186 | if (NULL != abe_key) | 186 | if (NULL != abe_key) |
187 | GNUNET_free (abe_key); | 187 | GNUNET_free(abe_key); |
188 | if (NULL != attr_list) | 188 | if (NULL != attr_list) |
189 | GNUNET_free (attr_list); | 189 | GNUNET_free(attr_list); |
190 | if (NULL != attr_to_delete) | 190 | if (NULL != attr_to_delete) |
191 | GNUNET_free (attr_to_delete); | 191 | GNUNET_free(attr_to_delete); |
192 | } | 192 | } |
193 | 193 | ||
194 | static void | 194 | static void |
195 | ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 195 | ticket_issue_cb(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
196 | { | 196 | { |
197 | char *ticket_str; | 197 | char *ticket_str; |
198 | |||
198 | reclaim_op = NULL; | 199 | reclaim_op = NULL; |
199 | if (NULL != ticket) | 200 | if (NULL != ticket) |
200 | { | 201 | { |
201 | ticket_str = | 202 | ticket_str = |
202 | GNUNET_STRINGS_data_to_string_alloc (ticket, | 203 | GNUNET_STRINGS_data_to_string_alloc(ticket, |
203 | sizeof ( | 204 | sizeof( |
204 | struct GNUNET_RECLAIM_Ticket)); | 205 | struct GNUNET_RECLAIM_Ticket)); |
205 | printf ("%s\n", ticket_str); | 206 | printf("%s\n", ticket_str); |
206 | GNUNET_free (ticket_str); | 207 | GNUNET_free(ticket_str); |
207 | } | 208 | } |
208 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 209 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
209 | } | 210 | } |
210 | 211 | ||
211 | static void | 212 | static void |
212 | store_attr_cont (void *cls, int32_t success, const char *emsg) | 213 | store_attr_cont(void *cls, int32_t success, const char *emsg) |
213 | { | 214 | { |
214 | reclaim_op = NULL; | 215 | reclaim_op = NULL; |
215 | if (GNUNET_SYSERR == success) | 216 | if (GNUNET_SYSERR == success) |
216 | { | 217 | { |
217 | fprintf (stderr, "%s\n", emsg); | 218 | fprintf(stderr, "%s\n", emsg); |
218 | } | 219 | } |
219 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 220 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
220 | } | 221 | } |
221 | 222 | ||
222 | static void | 223 | static void |
223 | process_attrs (void *cls, | 224 | process_attrs(void *cls, |
224 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 225 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
225 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 226 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
226 | { | 227 | { |
227 | char *value_str; | 228 | char *value_str; |
228 | char *id; | 229 | char *id; |
229 | const char *attr_type; | 230 | const char *attr_type; |
230 | 231 | ||
231 | if (NULL == identity) | 232 | if (NULL == identity) |
232 | { | 233 | { |
233 | reclaim_op = NULL; | 234 | reclaim_op = NULL; |
234 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 235 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
235 | return; | 236 | return; |
236 | } | 237 | } |
237 | if (NULL == attr) | 238 | if (NULL == attr) |
238 | { | 239 | { |
239 | ret = 1; | 240 | ret = 1; |
240 | return; | 241 | return; |
241 | } | 242 | } |
242 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 243 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
243 | attr->data, | 244 | attr->data, |
244 | attr->data_size); | 245 | attr->data_size); |
245 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 246 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); |
246 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | 247 | id = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); |
247 | fprintf (stdout, | 248 | fprintf(stdout, |
248 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 249 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
249 | attr->name, | 250 | attr->name, |
250 | value_str, | 251 | value_str, |
251 | attr_type, | 252 | attr_type, |
252 | attr->version, | 253 | attr->version, |
253 | id); | 254 | id); |
254 | GNUNET_free (id); | 255 | GNUNET_free(id); |
255 | } | 256 | } |
256 | 257 | ||
257 | static void | 258 | static void |
258 | ticket_iter_err (void *cls) | 259 | ticket_iter_err(void *cls) |
259 | { | 260 | { |
260 | ticket_iterator = NULL; | 261 | ticket_iterator = NULL; |
261 | fprintf (stderr, "Failed to iterate over tickets\n"); | 262 | fprintf(stderr, "Failed to iterate over tickets\n"); |
262 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 263 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
263 | } | 264 | } |
264 | 265 | ||
265 | static void | 266 | static void |
266 | ticket_iter_fin (void *cls) | 267 | ticket_iter_fin(void *cls) |
267 | { | 268 | { |
268 | ticket_iterator = NULL; | 269 | ticket_iterator = NULL; |
269 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 270 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
270 | } | 271 | } |
271 | 272 | ||
272 | static void | 273 | static void |
273 | ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 274 | ticket_iter(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
274 | { | 275 | { |
275 | char *aud; | 276 | char *aud; |
276 | char *ref; | 277 | char *ref; |
277 | char *tkt; | 278 | char *tkt; |
278 | 279 | ||
279 | aud = | 280 | aud = |
280 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 281 | GNUNET_STRINGS_data_to_string_alloc(&ticket->audience, |
281 | sizeof (struct | 282 | sizeof(struct |
282 | GNUNET_CRYPTO_EcdsaPublicKey)); | 283 | GNUNET_CRYPTO_EcdsaPublicKey)); |
283 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 284 | ref = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t)); |
284 | tkt = | 285 | tkt = |
285 | GNUNET_STRINGS_data_to_string_alloc (ticket, | 286 | GNUNET_STRINGS_data_to_string_alloc(ticket, |
286 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 287 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
287 | fprintf (stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud); | 288 | fprintf(stdout, "Ticket: %s | ID: %s | Audience: %s\n", tkt, ref, aud); |
288 | GNUNET_free (aud); | 289 | GNUNET_free(aud); |
289 | GNUNET_free (ref); | 290 | GNUNET_free(ref); |
290 | GNUNET_free (tkt); | 291 | GNUNET_free(tkt); |
291 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); | 292 | GNUNET_RECLAIM_ticket_iteration_next(ticket_iterator); |
292 | } | 293 | } |
293 | 294 | ||
294 | static void | 295 | static void |
295 | iter_error (void *cls) | 296 | iter_error(void *cls) |
296 | { | 297 | { |
297 | attr_iterator = NULL; | 298 | attr_iterator = NULL; |
298 | fprintf (stderr, "Failed to iterate over attributes\n"); | 299 | fprintf(stderr, "Failed to iterate over attributes\n"); |
299 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 300 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
300 | } | 301 | } |
301 | 302 | ||
302 | static void | 303 | static void |
303 | timeout_task (void *cls) | 304 | timeout_task(void *cls) |
304 | { | 305 | { |
305 | timeout = NULL; | 306 | timeout = NULL; |
306 | ret = 1; | 307 | ret = 1; |
307 | fprintf (stderr, "Timeout\n"); | 308 | fprintf(stderr, "Timeout\n"); |
308 | if (NULL == cleanup_task) | 309 | if (NULL == cleanup_task) |
309 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 310 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
310 | } | 311 | } |
311 | 312 | ||
312 | static void | 313 | static void |
313 | process_rvk (void *cls, int success, const char *msg) | 314 | process_rvk(void *cls, int success, const char *msg) |
314 | { | 315 | { |
315 | reclaim_op = NULL; | 316 | reclaim_op = NULL; |
316 | if (GNUNET_OK != success) | 317 | if (GNUNET_OK != success) |
317 | { | 318 | { |
318 | fprintf (stderr, "Revocation failed.\n"); | 319 | fprintf(stderr, "Revocation failed.\n"); |
319 | ret = 1; | 320 | ret = 1; |
320 | } | 321 | } |
321 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 322 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
322 | } | 323 | } |
323 | 324 | ||
324 | 325 | ||
325 | static void | 326 | static void |
326 | process_delete (void *cls, int success, const char *msg) | 327 | process_delete(void *cls, int success, const char *msg) |
327 | { | 328 | { |
328 | reclaim_op = NULL; | 329 | reclaim_op = NULL; |
329 | if (GNUNET_OK != success) | 330 | if (GNUNET_OK != success) |
330 | { | 331 | { |
331 | fprintf (stderr, "Deletion failed.\n"); | 332 | fprintf(stderr, "Deletion failed.\n"); |
332 | ret = 1; | 333 | ret = 1; |
333 | } | 334 | } |
334 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 335 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
335 | } | 336 | } |
336 | 337 | ||
337 | 338 | ||
338 | static void | 339 | static void |
339 | iter_finished (void *cls) | 340 | iter_finished(void *cls) |
340 | { | 341 | { |
341 | char *data; | 342 | char *data; |
342 | size_t data_size; | 343 | size_t data_size; |
@@ -344,97 +345,97 @@ iter_finished (void *cls) | |||
344 | 345 | ||
345 | attr_iterator = NULL; | 346 | attr_iterator = NULL; |
346 | if (list) | 347 | if (list) |
347 | { | 348 | { |
348 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 349 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
349 | return; | 350 | return; |
350 | } | 351 | } |
351 | 352 | ||
352 | if (issue_attrs) | 353 | if (issue_attrs) |
353 | { | 354 | { |
354 | reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle, | 355 | reclaim_op = GNUNET_RECLAIM_ticket_issue(reclaim_handle, |
355 | pkey, | 356 | pkey, |
356 | &rp_key, | 357 | &rp_key, |
357 | attr_list, | 358 | attr_list, |
358 | &ticket_issue_cb, | 359 | &ticket_issue_cb, |
359 | NULL); | 360 | NULL); |
360 | return; | 361 | return; |
361 | } | 362 | } |
362 | if (consume_ticket) | 363 | if (consume_ticket) |
363 | { | 364 | { |
364 | reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle, | 365 | reclaim_op = GNUNET_RECLAIM_ticket_consume(reclaim_handle, |
366 | pkey, | ||
367 | &ticket, | ||
368 | &process_attrs, | ||
369 | NULL); | ||
370 | timeout = GNUNET_SCHEDULER_add_delayed( | ||
371 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
372 | &timeout_task, | ||
373 | NULL); | ||
374 | return; | ||
375 | } | ||
376 | if (revoke_ticket) | ||
377 | { | ||
378 | reclaim_op = GNUNET_RECLAIM_ticket_revoke(reclaim_handle, | ||
365 | pkey, | 379 | pkey, |
366 | &ticket, | 380 | &ticket, |
367 | &process_attrs, | 381 | &process_rvk, |
368 | NULL); | 382 | NULL); |
369 | timeout = GNUNET_SCHEDULER_add_delayed ( | 383 | return; |
370 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 384 | } |
371 | &timeout_task, | ||
372 | NULL); | ||
373 | return; | ||
374 | } | ||
375 | if (revoke_ticket) | ||
376 | { | ||
377 | reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle, | ||
378 | pkey, | ||
379 | &ticket, | ||
380 | &process_rvk, | ||
381 | NULL); | ||
382 | return; | ||
383 | } | ||
384 | if (attr_delete) | 385 | if (attr_delete) |
385 | { | ||
386 | if (NULL == attr_to_delete) | ||
387 | { | 386 | { |
388 | fprintf (stdout, "No such attribute ``%s''\n", attr_delete); | 387 | if (NULL == attr_to_delete) |
388 | { | ||
389 | fprintf(stdout, "No such attribute ``%s''\n", attr_delete); | ||
390 | return; | ||
391 | } | ||
392 | reclaim_op = GNUNET_RECLAIM_attribute_delete(reclaim_handle, | ||
393 | pkey, | ||
394 | attr_to_delete, | ||
395 | &process_delete, | ||
396 | NULL); | ||
389 | return; | 397 | return; |
390 | } | 398 | } |
391 | reclaim_op = GNUNET_RECLAIM_attribute_delete (reclaim_handle, | ||
392 | pkey, | ||
393 | attr_to_delete, | ||
394 | &process_delete, | ||
395 | NULL); | ||
396 | return; | ||
397 | } | ||
398 | if (attr_name) | 399 | if (attr_name) |
399 | { | 400 | { |
400 | if (NULL == type_str) | 401 | if (NULL == type_str) |
401 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; | 402 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; |
402 | else | 403 | else |
403 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 404 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); |
404 | 405 | ||
405 | GNUNET_assert (GNUNET_SYSERR != | 406 | GNUNET_assert(GNUNET_SYSERR != |
406 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 407 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, |
407 | attr_value, | 408 | attr_value, |
408 | (void **) &data, | 409 | (void **)&data, |
409 | &data_size)); | 410 | &data_size)); |
410 | if (NULL != claim) | 411 | if (NULL != claim) |
411 | { | 412 | { |
412 | claim->type = type; | 413 | claim->type = type; |
413 | claim->data = data; | 414 | claim->data = data; |
414 | claim->data_size = data_size; | 415 | claim->data_size = data_size; |
415 | } | 416 | } |
416 | else | 417 | else |
417 | { | 418 | { |
418 | claim = | 419 | claim = |
419 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | 420 | GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr_name, type, data, data_size); |
421 | } | ||
422 | reclaim_op = GNUNET_RECLAIM_attribute_store(reclaim_handle, | ||
423 | pkey, | ||
424 | claim, | ||
425 | &exp_interval, | ||
426 | &store_attr_cont, | ||
427 | NULL); | ||
428 | GNUNET_free(data); | ||
429 | GNUNET_free(claim); | ||
430 | return; | ||
420 | } | 431 | } |
421 | reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle, | 432 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
422 | pkey, | ||
423 | claim, | ||
424 | &exp_interval, | ||
425 | &store_attr_cont, | ||
426 | NULL); | ||
427 | GNUNET_free (data); | ||
428 | GNUNET_free (claim); | ||
429 | return; | ||
430 | } | ||
431 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
432 | } | 433 | } |
433 | 434 | ||
434 | static void | 435 | static void |
435 | iter_cb (void *cls, | 436 | iter_cb(void *cls, |
436 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 437 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
437 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 438 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
438 | { | 439 | { |
439 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 440 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
440 | char *attrs_tmp; | 441 | char *attrs_tmp; |
@@ -444,260 +445,260 @@ iter_cb (void *cls, | |||
444 | const char *attr_type; | 445 | const char *attr_type; |
445 | 446 | ||
446 | if ((NULL != attr_name) && (NULL != claim)) | 447 | if ((NULL != attr_name) && (NULL != claim)) |
447 | { | ||
448 | if (0 == strcasecmp (attr_name, attr->name)) | ||
449 | { | 448 | { |
450 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 449 | if (0 == strcasecmp(attr_name, attr->name)) |
451 | attr->type, | 450 | { |
452 | attr->data, | 451 | claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
453 | attr->data_size); | 452 | attr->type, |
453 | attr->data, | ||
454 | attr->data_size); | ||
455 | } | ||
454 | } | 456 | } |
455 | } | ||
456 | else if (issue_attrs) | 457 | else if (issue_attrs) |
457 | { | ||
458 | attrs_tmp = GNUNET_strdup (issue_attrs); | ||
459 | attr_str = strtok (attrs_tmp, ","); | ||
460 | while (NULL != attr_str) | ||
461 | { | 458 | { |
462 | if (0 != strcasecmp (attr_str, attr->name)) | 459 | attrs_tmp = GNUNET_strdup(issue_attrs); |
463 | { | 460 | attr_str = strtok(attrs_tmp, ","); |
464 | attr_str = strtok (NULL, ","); | 461 | while (NULL != attr_str) |
465 | continue; | 462 | { |
466 | } | 463 | if (0 != strcasecmp(attr_str, attr->name)) |
467 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 464 | { |
468 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 465 | attr_str = strtok(NULL, ","); |
469 | attr->type, | 466 | continue; |
470 | attr->data, | 467 | } |
471 | attr->data_size); | 468 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
472 | le->claim->version = attr->version; | 469 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
473 | le->claim->id = attr->id; | 470 | attr->type, |
474 | GNUNET_CONTAINER_DLL_insert (attr_list->list_head, | 471 | attr->data, |
475 | attr_list->list_tail, | 472 | attr->data_size); |
476 | le); | 473 | le->claim->version = attr->version; |
477 | break; | 474 | le->claim->id = attr->id; |
475 | GNUNET_CONTAINER_DLL_insert(attr_list->list_head, | ||
476 | attr_list->list_tail, | ||
477 | le); | ||
478 | break; | ||
479 | } | ||
480 | GNUNET_free(attrs_tmp); | ||
478 | } | 481 | } |
479 | GNUNET_free (attrs_tmp); | ||
480 | } | ||
481 | else if (attr_delete && (NULL == attr_to_delete)) | 482 | else if (attr_delete && (NULL == attr_to_delete)) |
482 | { | ||
483 | label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | ||
484 | if (0 == strcasecmp (attr_delete, label)) | ||
485 | { | 483 | { |
486 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 484 | label = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); |
487 | attr->type, | 485 | if (0 == strcasecmp(attr_delete, label)) |
488 | attr->data, | 486 | { |
489 | attr->data_size); | 487 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
490 | attr_to_delete->id = attr->id; | 488 | attr->type, |
489 | attr->data, | ||
490 | attr->data_size); | ||
491 | attr_to_delete->id = attr->id; | ||
492 | } | ||
493 | GNUNET_free(label); | ||
491 | } | 494 | } |
492 | GNUNET_free (label); | ||
493 | } | ||
494 | else if (list) | 495 | else if (list) |
495 | { | 496 | { |
496 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 497 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
497 | attr->data, | 498 | attr->data, |
498 | attr->data_size); | 499 | attr->data_size); |
499 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 500 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); |
500 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | 501 | id = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); |
501 | fprintf (stdout, | 502 | fprintf(stdout, |
502 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", | 503 | "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
503 | attr->name, | 504 | attr->name, |
504 | attr_str, | 505 | attr_str, |
505 | attr_type, | 506 | attr_type, |
506 | attr->version, | 507 | attr->version, |
507 | id); | 508 | id); |
508 | GNUNET_free (id); | 509 | GNUNET_free(id); |
509 | } | 510 | } |
510 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); | 511 | GNUNET_RECLAIM_get_attributes_next(attr_iterator); |
511 | } | 512 | } |
512 | 513 | ||
513 | static void | 514 | static void |
514 | start_process () | 515 | start_process() |
515 | { | 516 | { |
516 | if (NULL == pkey) | 517 | if (NULL == pkey) |
517 | { | 518 | { |
518 | fprintf (stderr, "Ego %s not found\n", ego_name); | 519 | fprintf(stderr, "Ego %s not found\n", ego_name); |
519 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 520 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
520 | return; | 521 | return; |
521 | } | 522 | } |
522 | 523 | ||
523 | if (list_tickets) | 524 | if (list_tickets) |
524 | { | 525 | { |
525 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start (reclaim_handle, | 526 | ticket_iterator = GNUNET_RECLAIM_ticket_iteration_start(reclaim_handle, |
526 | pkey, | 527 | pkey, |
527 | &ticket_iter_err, | 528 | &ticket_iter_err, |
528 | NULL, | 529 | NULL, |
529 | &ticket_iter, | 530 | &ticket_iter, |
530 | NULL, | 531 | NULL, |
531 | &ticket_iter_fin, | 532 | &ticket_iter_fin, |
532 | NULL); | 533 | NULL); |
533 | return; | 534 | return; |
534 | } | 535 | } |
535 | 536 | ||
536 | if ((NULL != rp) && | 537 | if ((NULL != rp) && |
537 | GNUNET_OK != | 538 | GNUNET_OK != |
538 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key)) | 539 | GNUNET_CRYPTO_ecdsa_public_key_from_string(rp, strlen(rp), &rp_key)) |
539 | { | 540 | { |
540 | fprintf (stderr, "%s is not a public key!\n", rp); | 541 | fprintf(stderr, "%s is not a public key!\n", rp); |
541 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 542 | cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup, NULL); |
542 | return; | 543 | return; |
543 | } | 544 | } |
544 | if (NULL != consume_ticket) | 545 | if (NULL != consume_ticket) |
545 | GNUNET_STRINGS_string_to_data (consume_ticket, | 546 | GNUNET_STRINGS_string_to_data(consume_ticket, |
546 | strlen (consume_ticket), | 547 | strlen(consume_ticket), |
547 | &ticket, | 548 | &ticket, |
548 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 549 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
549 | if (NULL != revoke_ticket) | 550 | if (NULL != revoke_ticket) |
550 | GNUNET_STRINGS_string_to_data (revoke_ticket, | 551 | GNUNET_STRINGS_string_to_data(revoke_ticket, |
551 | strlen (revoke_ticket), | 552 | strlen(revoke_ticket), |
552 | &ticket, | 553 | &ticket, |
553 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 554 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
554 | 555 | ||
555 | attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 556 | attr_list = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
556 | claim = NULL; | 557 | claim = NULL; |
557 | attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle, | 558 | attr_iterator = GNUNET_RECLAIM_get_attributes_start(reclaim_handle, |
558 | pkey, | 559 | pkey, |
559 | &iter_error, | 560 | &iter_error, |
560 | NULL, | 561 | NULL, |
561 | &iter_cb, | 562 | &iter_cb, |
562 | NULL, | 563 | NULL, |
563 | &iter_finished, | 564 | &iter_finished, |
564 | NULL); | 565 | NULL); |
565 | } | 566 | } |
566 | 567 | ||
567 | static int init = GNUNET_YES; | 568 | static int init = GNUNET_YES; |
568 | 569 | ||
569 | static void | 570 | static void |
570 | ego_cb (void *cls, | 571 | ego_cb(void *cls, |
571 | struct GNUNET_IDENTITY_Ego *ego, | 572 | struct GNUNET_IDENTITY_Ego *ego, |
572 | void **ctx, | 573 | void **ctx, |
573 | const char *name) | 574 | const char *name) |
574 | { | 575 | { |
575 | if (NULL == name) | 576 | if (NULL == name) |
576 | { | ||
577 | if (GNUNET_YES == init) | ||
578 | { | 577 | { |
579 | init = GNUNET_NO; | 578 | if (GNUNET_YES == init) |
580 | start_process (); | 579 | { |
580 | init = GNUNET_NO; | ||
581 | start_process(); | ||
582 | } | ||
583 | return; | ||
581 | } | 584 | } |
585 | if (0 != strcmp(name, ego_name)) | ||
582 | return; | 586 | return; |
583 | } | 587 | pkey = GNUNET_IDENTITY_ego_get_private_key(ego); |
584 | if (0 != strcmp (name, ego_name)) | ||
585 | return; | ||
586 | pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
587 | } | 588 | } |
588 | 589 | ||
589 | 590 | ||
590 | static void | 591 | static void |
591 | run (void *cls, | 592 | run(void *cls, |
592 | char *const *args, | 593 | char *const *args, |
593 | const char *cfgfile, | 594 | const char *cfgfile, |
594 | const struct GNUNET_CONFIGURATION_Handle *c) | 595 | const struct GNUNET_CONFIGURATION_Handle *c) |
595 | { | 596 | { |
596 | ret = 0; | 597 | ret = 0; |
597 | if (NULL == ego_name) | 598 | if (NULL == ego_name) |
598 | { | 599 | { |
599 | ret = 1; | 600 | ret = 1; |
600 | fprintf (stderr, _ ("Ego is required\n")); | 601 | fprintf(stderr, _("Ego is required\n")); |
601 | return; | 602 | return; |
602 | } | 603 | } |
603 | 604 | ||
604 | if ((NULL == attr_value) && (NULL != attr_name)) | 605 | if ((NULL == attr_value) && (NULL != attr_name)) |
605 | { | 606 | { |
606 | ret = 1; | 607 | ret = 1; |
607 | fprintf (stderr, _ ("Attribute value missing!\n")); | 608 | fprintf(stderr, _("Attribute value missing!\n")); |
608 | return; | 609 | return; |
609 | } | 610 | } |
610 | 611 | ||
611 | if ((NULL == rp) && (NULL != issue_attrs)) | 612 | if ((NULL == rp) && (NULL != issue_attrs)) |
612 | { | 613 | { |
613 | ret = 1; | 614 | ret = 1; |
614 | fprintf (stderr, _ ("Requesting party key is required!\n")); | 615 | fprintf(stderr, _("Requesting party key is required!\n")); |
615 | return; | 616 | return; |
616 | } | 617 | } |
617 | 618 | ||
618 | reclaim_handle = GNUNET_RECLAIM_connect (c); | 619 | reclaim_handle = GNUNET_RECLAIM_connect(c); |
619 | // Get Ego | 620 | // Get Ego |
620 | identity_handle = GNUNET_IDENTITY_connect (c, &ego_cb, NULL); | 621 | identity_handle = GNUNET_IDENTITY_connect(c, &ego_cb, NULL); |
621 | } | 622 | } |
622 | 623 | ||
623 | 624 | ||
624 | int | 625 | int |
625 | main (int argc, char *const argv[]) | 626 | main(int argc, char *const argv[]) |
626 | { | 627 | { |
627 | exp_interval = GNUNET_TIME_UNIT_HOURS; | 628 | exp_interval = GNUNET_TIME_UNIT_HOURS; |
628 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 629 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
629 | 630 | GNUNET_GETOPT_option_string('a', | |
630 | GNUNET_GETOPT_option_string ('a', | 631 | "add", |
631 | "add", | 632 | "NAME", |
632 | "NAME", | 633 | gettext_noop("Add an attribute NAME"), |
633 | gettext_noop ("Add an attribute NAME"), | 634 | &attr_name), |
634 | &attr_name), | 635 | GNUNET_GETOPT_option_string('d', |
635 | GNUNET_GETOPT_option_string ('d', | 636 | "delete", |
636 | "delete", | 637 | "ID", |
637 | "ID", | 638 | gettext_noop("Delete the attribute with ID"), |
638 | gettext_noop ("Delete the attribute with ID"), | 639 | &attr_delete), |
639 | &attr_delete), | 640 | GNUNET_GETOPT_option_string('V', |
640 | GNUNET_GETOPT_option_string ('V', | 641 | "value", |
641 | "value", | 642 | "VALUE", |
642 | "VALUE", | 643 | gettext_noop("The attribute VALUE"), |
643 | gettext_noop ("The attribute VALUE"), | 644 | &attr_value), |
644 | &attr_value), | 645 | GNUNET_GETOPT_option_string('e', |
645 | GNUNET_GETOPT_option_string ('e', | 646 | "ego", |
646 | "ego", | 647 | "EGO", |
647 | "EGO", | 648 | gettext_noop("The EGO to use"), |
648 | gettext_noop ("The EGO to use"), | 649 | &ego_name), |
649 | &ego_name), | 650 | GNUNET_GETOPT_option_string('r', |
650 | GNUNET_GETOPT_option_string ('r', | 651 | "rp", |
651 | "rp", | 652 | "RP", |
652 | "RP", | 653 | gettext_noop( |
653 | gettext_noop ( | 654 | "Specify the relying party for issue"), |
654 | "Specify the relying party for issue"), | 655 | &rp), |
655 | &rp), | 656 | GNUNET_GETOPT_option_flag('D', |
656 | GNUNET_GETOPT_option_flag ('D', | 657 | "dump", |
657 | "dump", | 658 | gettext_noop("List attributes for EGO"), |
658 | gettext_noop ("List attributes for EGO"), | 659 | &list), |
659 | &list), | 660 | GNUNET_GETOPT_option_string( |
660 | GNUNET_GETOPT_option_string ( | ||
661 | 'i', | 661 | 'i', |
662 | "issue", | 662 | "issue", |
663 | "A1,A2,...", | 663 | "A1,A2,...", |
664 | gettext_noop ( | 664 | gettext_noop( |
665 | "Issue a ticket for a set of attributes separated by comma"), | 665 | "Issue a ticket for a set of attributes separated by comma"), |
666 | &issue_attrs), | 666 | &issue_attrs), |
667 | GNUNET_GETOPT_option_string ('C', | 667 | GNUNET_GETOPT_option_string('C', |
668 | "consume", | 668 | "consume", |
669 | "TICKET", | 669 | "TICKET", |
670 | gettext_noop ("Consume a ticket"), | 670 | gettext_noop("Consume a ticket"), |
671 | &consume_ticket), | 671 | &consume_ticket), |
672 | GNUNET_GETOPT_option_string ('R', | 672 | GNUNET_GETOPT_option_string('R', |
673 | "revoke", | 673 | "revoke", |
674 | "TICKET", | 674 | "TICKET", |
675 | gettext_noop ("Revoke a ticket"), | 675 | gettext_noop("Revoke a ticket"), |
676 | &revoke_ticket), | 676 | &revoke_ticket), |
677 | GNUNET_GETOPT_option_string ('t', | 677 | GNUNET_GETOPT_option_string('t', |
678 | "type", | 678 | "type", |
679 | "TYPE", | 679 | "TYPE", |
680 | gettext_noop ("Type of attribute"), | 680 | gettext_noop("Type of attribute"), |
681 | &type_str), | 681 | &type_str), |
682 | GNUNET_GETOPT_option_flag ('T', | 682 | GNUNET_GETOPT_option_flag('T', |
683 | "tickets", | 683 | "tickets", |
684 | gettext_noop ("List tickets of ego"), | 684 | gettext_noop("List tickets of ego"), |
685 | &list_tickets), | 685 | &list_tickets), |
686 | GNUNET_GETOPT_option_relative_time ('E', | 686 | GNUNET_GETOPT_option_relative_time('E', |
687 | "expiration", | 687 | "expiration", |
688 | "INTERVAL", | 688 | "INTERVAL", |
689 | gettext_noop ( | 689 | gettext_noop( |
690 | "Expiration interval of the attribute"), | 690 | "Expiration interval of the attribute"), |
691 | &exp_interval), | 691 | &exp_interval), |
692 | 692 | ||
693 | GNUNET_GETOPT_OPTION_END}; | 693 | GNUNET_GETOPT_OPTION_END |
694 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 694 | }; |
695 | argv, | 695 | if (GNUNET_OK != GNUNET_PROGRAM_run(argc, |
696 | "gnunet-reclaim", | 696 | argv, |
697 | _ ("re:claimID command line tool"), | 697 | "gnunet-reclaim", |
698 | options, | 698 | _("re:claimID command line tool"), |
699 | &run, | 699 | options, |
700 | NULL)) | 700 | &run, |
701 | NULL)) | ||
701 | return 1; | 702 | return 1; |
702 | else | 703 | else |
703 | return ret; | 704 | return ret; |
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 57bff8ed4..23a5db1ed 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @file src/reclaim/gnunet-service-reclaim.c | 22 | * @file src/reclaim/gnunet-service-reclaim.c |
@@ -58,8 +58,7 @@ struct IdpClient; | |||
58 | /** | 58 | /** |
59 | * A ticket iteration operation. | 59 | * A ticket iteration operation. |
60 | */ | 60 | */ |
61 | struct TicketIteration | 61 | struct TicketIteration { |
62 | { | ||
63 | /** | 62 | /** |
64 | * DLL | 63 | * DLL |
65 | */ | 64 | */ |
@@ -90,8 +89,7 @@ struct TicketIteration | |||
90 | /** | 89 | /** |
91 | * An attribute iteration operation. | 90 | * An attribute iteration operation. |
92 | */ | 91 | */ |
93 | struct AttributeIterator | 92 | struct AttributeIterator { |
94 | { | ||
95 | /** | 93 | /** |
96 | * Next element in the DLL | 94 | * Next element in the DLL |
97 | */ | 95 | */ |
@@ -127,8 +125,7 @@ struct AttributeIterator | |||
127 | /** | 125 | /** |
128 | * An idp client | 126 | * An idp client |
129 | */ | 127 | */ |
130 | struct IdpClient | 128 | struct IdpClient { |
131 | { | ||
132 | /** | 129 | /** |
133 | * DLL | 130 | * DLL |
134 | */ | 131 | */ |
@@ -227,8 +224,7 @@ struct IdpClient | |||
227 | /** | 224 | /** |
228 | * Handle for attribute deletion request | 225 | * Handle for attribute deletion request |
229 | */ | 226 | */ |
230 | struct AttributeDeleteHandle | 227 | struct AttributeDeleteHandle { |
231 | { | ||
232 | /** | 228 | /** |
233 | * DLL | 229 | * DLL |
234 | */ | 230 | */ |
@@ -290,8 +286,7 @@ struct AttributeDeleteHandle | |||
290 | /** | 286 | /** |
291 | * Handle for attribute store request | 287 | * Handle for attribute store request |
292 | */ | 288 | */ |
293 | struct AttributeStoreHandle | 289 | struct AttributeStoreHandle { |
294 | { | ||
295 | /** | 290 | /** |
296 | * DLL | 291 | * DLL |
297 | */ | 292 | */ |
@@ -342,8 +337,7 @@ struct AttributeStoreHandle | |||
342 | /** | 337 | /** |
343 | * Handle for ticket consume request | 338 | * Handle for ticket consume request |
344 | */ | 339 | */ |
345 | struct ConsumeTicketOperation | 340 | struct ConsumeTicketOperation { |
346 | { | ||
347 | /** | 341 | /** |
348 | * DLL | 342 | * DLL |
349 | */ | 343 | */ |
@@ -374,8 +368,7 @@ struct ConsumeTicketOperation | |||
374 | /** | 368 | /** |
375 | * Ticket revocation request handle | 369 | * Ticket revocation request handle |
376 | */ | 370 | */ |
377 | struct TicketRevocationOperation | 371 | struct TicketRevocationOperation { |
378 | { | ||
379 | /** | 372 | /** |
380 | * DLL | 373 | * DLL |
381 | */ | 374 | */ |
@@ -406,8 +399,7 @@ struct TicketRevocationOperation | |||
406 | /** | 399 | /** |
407 | * Ticket issue operation handle | 400 | * Ticket issue operation handle |
408 | */ | 401 | */ |
409 | struct TicketIssueOperation | 402 | struct TicketIssueOperation { |
410 | { | ||
411 | /** | 403 | /** |
412 | * DLL | 404 | * DLL |
413 | */ | 405 | */ |
@@ -447,28 +439,30 @@ static struct IdpClient *client_list_tail = NULL; | |||
447 | * @param adh the attribute to cleanup | 439 | * @param adh the attribute to cleanup |
448 | */ | 440 | */ |
449 | static void | 441 | static void |
450 | cleanup_adh (struct AttributeDeleteHandle *adh) | 442 | cleanup_adh(struct AttributeDeleteHandle *adh) |
451 | { | 443 | { |
452 | struct TicketRecordsEntry *le; | 444 | struct TicketRecordsEntry *le; |
445 | |||
453 | if (NULL != adh->ns_it) | 446 | if (NULL != adh->ns_it) |
454 | GNUNET_NAMESTORE_zone_iteration_stop (adh->ns_it); | 447 | GNUNET_NAMESTORE_zone_iteration_stop(adh->ns_it); |
455 | if (NULL != adh->ns_qe) | 448 | if (NULL != adh->ns_qe) |
456 | GNUNET_NAMESTORE_cancel (adh->ns_qe); | 449 | GNUNET_NAMESTORE_cancel(adh->ns_qe); |
457 | if (NULL != adh->label) | 450 | if (NULL != adh->label) |
458 | GNUNET_free (adh->label); | 451 | GNUNET_free(adh->label); |
459 | if (NULL != adh->claim) | 452 | if (NULL != adh->claim) |
460 | GNUNET_free (adh->claim); | 453 | GNUNET_free(adh->claim); |
461 | while (NULL != (le = adh->tickets_to_update_head)) { | 454 | while (NULL != (le = adh->tickets_to_update_head)) |
462 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | 455 | { |
463 | adh->tickets_to_update_tail, | 456 | GNUNET_CONTAINER_DLL_remove(adh->tickets_to_update_head, |
464 | le); | 457 | adh->tickets_to_update_tail, |
465 | if (NULL != le->label) | 458 | le); |
466 | GNUNET_free (le->label); | 459 | if (NULL != le->label) |
467 | if (NULL != le->data) | 460 | GNUNET_free(le->label); |
468 | GNUNET_free (le->data); | 461 | if (NULL != le->data) |
469 | GNUNET_free (le); | 462 | GNUNET_free(le->data); |
470 | } | 463 | GNUNET_free(le); |
471 | GNUNET_free (adh); | 464 | } |
465 | GNUNET_free(adh); | ||
472 | } | 466 | } |
473 | 467 | ||
474 | 468 | ||
@@ -478,13 +472,13 @@ cleanup_adh (struct AttributeDeleteHandle *adh) | |||
478 | * @param handle handle to clean up | 472 | * @param handle handle to clean up |
479 | */ | 473 | */ |
480 | static void | 474 | static void |
481 | cleanup_as_handle (struct AttributeStoreHandle *ash) | 475 | cleanup_as_handle(struct AttributeStoreHandle *ash) |
482 | { | 476 | { |
483 | if (NULL != ash->ns_qe) | 477 | if (NULL != ash->ns_qe) |
484 | GNUNET_NAMESTORE_cancel (ash->ns_qe); | 478 | GNUNET_NAMESTORE_cancel(ash->ns_qe); |
485 | if (NULL != ash->claim) | 479 | if (NULL != ash->claim) |
486 | GNUNET_free (ash->claim); | 480 | GNUNET_free(ash->claim); |
487 | GNUNET_free (ash); | 481 | GNUNET_free(ash); |
488 | } | 482 | } |
489 | 483 | ||
490 | 484 | ||
@@ -494,7 +488,7 @@ cleanup_as_handle (struct AttributeStoreHandle *ash) | |||
494 | * @param idp the client to clean up | 488 | * @param idp the client to clean up |
495 | */ | 489 | */ |
496 | static void | 490 | static void |
497 | cleanup_client (struct IdpClient *idp) | 491 | cleanup_client(struct IdpClient *idp) |
498 | { | 492 | { |
499 | struct AttributeIterator *ai; | 493 | struct AttributeIterator *ai; |
500 | struct TicketIteration *ti; | 494 | struct TicketIteration *ti; |
@@ -504,46 +498,53 @@ cleanup_client (struct IdpClient *idp) | |||
504 | struct AttributeStoreHandle *as; | 498 | struct AttributeStoreHandle *as; |
505 | struct AttributeDeleteHandle *adh; | 499 | struct AttributeDeleteHandle *adh; |
506 | 500 | ||
507 | while (NULL != (iss = idp->issue_op_head)) { | 501 | while (NULL != (iss = idp->issue_op_head)) |
508 | GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, idp->issue_op_tail, iss); | 502 | { |
509 | GNUNET_free (iss); | 503 | GNUNET_CONTAINER_DLL_remove(idp->issue_op_head, idp->issue_op_tail, iss); |
510 | } | 504 | GNUNET_free(iss); |
511 | while (NULL != (ct = idp->consume_op_head)) { | 505 | } |
512 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, | 506 | while (NULL != (ct = idp->consume_op_head)) |
513 | idp->consume_op_tail, | 507 | { |
514 | ct); | 508 | GNUNET_CONTAINER_DLL_remove(idp->consume_op_head, |
515 | if (NULL != ct->ch) | 509 | idp->consume_op_tail, |
516 | RECLAIM_TICKETS_consume_cancel (ct->ch); | 510 | ct); |
517 | GNUNET_free (ct); | 511 | if (NULL != ct->ch) |
518 | } | 512 | RECLAIM_TICKETS_consume_cancel(ct->ch); |
519 | while (NULL != (as = idp->store_op_head)) { | 513 | GNUNET_free(ct); |
520 | GNUNET_CONTAINER_DLL_remove (idp->store_op_head, idp->store_op_tail, as); | 514 | } |
521 | cleanup_as_handle (as); | 515 | while (NULL != (as = idp->store_op_head)) |
522 | } | 516 | { |
523 | while (NULL != (adh = idp->delete_op_head)) { | 517 | GNUNET_CONTAINER_DLL_remove(idp->store_op_head, idp->store_op_tail, as); |
524 | GNUNET_CONTAINER_DLL_remove (idp->delete_op_head, idp->delete_op_tail, adh); | 518 | cleanup_as_handle(as); |
525 | cleanup_adh (adh); | 519 | } |
526 | } | 520 | while (NULL != (adh = idp->delete_op_head)) |
527 | 521 | { | |
528 | while (NULL != (ai = idp->attr_iter_head)) { | 522 | GNUNET_CONTAINER_DLL_remove(idp->delete_op_head, idp->delete_op_tail, adh); |
529 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); | 523 | cleanup_adh(adh); |
530 | GNUNET_free (ai); | 524 | } |
531 | } | 525 | |
532 | while (NULL != (rop = idp->revoke_op_head)) { | 526 | while (NULL != (ai = idp->attr_iter_head)) |
533 | GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, idp->revoke_op_tail, rop); | 527 | { |
534 | if (NULL != rop->rh) | 528 | GNUNET_CONTAINER_DLL_remove(idp->attr_iter_head, idp->attr_iter_tail, ai); |
535 | RECLAIM_TICKETS_revoke_cancel (rop->rh); | 529 | GNUNET_free(ai); |
536 | GNUNET_free (rop); | 530 | } |
537 | } | 531 | while (NULL != (rop = idp->revoke_op_head)) |
538 | while (NULL != (ti = idp->ticket_iter_head)) { | 532 | { |
539 | GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, | 533 | GNUNET_CONTAINER_DLL_remove(idp->revoke_op_head, idp->revoke_op_tail, rop); |
540 | idp->ticket_iter_tail, | 534 | if (NULL != rop->rh) |
541 | ti); | 535 | RECLAIM_TICKETS_revoke_cancel(rop->rh); |
542 | if (NULL != ti->iter) | 536 | GNUNET_free(rop); |
543 | RECLAIM_TICKETS_iteration_stop (ti->iter); | 537 | } |
544 | GNUNET_free (ti); | 538 | while (NULL != (ti = idp->ticket_iter_head)) |
545 | } | 539 | { |
546 | GNUNET_free (idp); | 540 | GNUNET_CONTAINER_DLL_remove(idp->ticket_iter_head, |
541 | idp->ticket_iter_tail, | ||
542 | ti); | ||
543 | if (NULL != ti->iter) | ||
544 | RECLAIM_TICKETS_iteration_stop(ti->iter); | ||
545 | GNUNET_free(ti); | ||
546 | } | ||
547 | GNUNET_free(idp); | ||
547 | } | 548 | } |
548 | 549 | ||
549 | 550 | ||
@@ -551,23 +552,24 @@ cleanup_client (struct IdpClient *idp) | |||
551 | * Cleanup task | 552 | * Cleanup task |
552 | */ | 553 | */ |
553 | static void | 554 | static void |
554 | cleanup () | 555 | cleanup() |
555 | { | 556 | { |
556 | struct IdpClient *cl; | 557 | struct IdpClient *cl; |
557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 558 | |
559 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | ||
558 | 560 | ||
559 | while (NULL != (cl = client_list_head)) | 561 | while (NULL != (cl = client_list_head)) |
560 | { | 562 | { |
561 | GNUNET_CONTAINER_DLL_remove (client_list_head, | 563 | GNUNET_CONTAINER_DLL_remove(client_list_head, |
562 | client_list_tail, | 564 | client_list_tail, |
563 | cl); | 565 | cl); |
564 | cleanup_client (cl); | 566 | cleanup_client(cl); |
565 | } | 567 | } |
566 | RECLAIM_TICKETS_deinit (); | 568 | RECLAIM_TICKETS_deinit(); |
567 | if (NULL != timeout_task) | 569 | if (NULL != timeout_task) |
568 | GNUNET_SCHEDULER_cancel (timeout_task); | 570 | GNUNET_SCHEDULER_cancel(timeout_task); |
569 | if (NULL != nsh) | 571 | if (NULL != nsh) |
570 | GNUNET_NAMESTORE_disconnect (nsh); | 572 | GNUNET_NAMESTORE_disconnect(nsh); |
571 | } | 573 | } |
572 | 574 | ||
573 | 575 | ||
@@ -577,10 +579,10 @@ cleanup () | |||
577 | * @param cls NULL | 579 | * @param cls NULL |
578 | */ | 580 | */ |
579 | static void | 581 | static void |
580 | do_shutdown (void *cls) | 582 | do_shutdown(void *cls) |
581 | { | 583 | { |
582 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); | 584 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); |
583 | cleanup (); | 585 | cleanup(); |
584 | } | 586 | } |
585 | 587 | ||
586 | 588 | ||
@@ -593,23 +595,24 @@ do_shutdown (void *cls) | |||
593 | * @param success the success status of the request | 595 | * @param success the success status of the request |
594 | */ | 596 | */ |
595 | static void | 597 | static void |
596 | send_ticket_result (const struct IdpClient *client, | 598 | send_ticket_result(const struct IdpClient *client, |
597 | uint32_t r_id, | 599 | uint32_t r_id, |
598 | const struct GNUNET_RECLAIM_Ticket *ticket, | 600 | const struct GNUNET_RECLAIM_Ticket *ticket, |
599 | uint32_t success) | 601 | uint32_t success) |
600 | { | 602 | { |
601 | struct TicketResultMessage *irm; | 603 | struct TicketResultMessage *irm; |
602 | struct GNUNET_MQ_Envelope *env; | 604 | struct GNUNET_MQ_Envelope *env; |
603 | 605 | ||
604 | env = GNUNET_MQ_msg (irm, | 606 | env = GNUNET_MQ_msg(irm, |
605 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | 607 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
606 | if (NULL != ticket) { | 608 | if (NULL != ticket) |
607 | irm->ticket = *ticket; | 609 | { |
608 | } | 610 | irm->ticket = *ticket; |
611 | } | ||
609 | // TODO add success member | 612 | // TODO add success member |
610 | irm->id = htonl (r_id); | 613 | irm->id = htonl(r_id); |
611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); | 614 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); |
612 | GNUNET_MQ_send (client->mq, env); | 615 | GNUNET_MQ_send(client->mq, env); |
613 | } | 616 | } |
614 | 617 | ||
615 | 618 | ||
@@ -622,26 +625,28 @@ send_ticket_result (const struct IdpClient *client, | |||
622 | * @param emsg error message (NULL of success is GNUNET_OK) | 625 | * @param emsg error message (NULL of success is GNUNET_OK) |
623 | */ | 626 | */ |
624 | static void | 627 | static void |
625 | issue_ticket_result_cb (void *cls, | 628 | issue_ticket_result_cb(void *cls, |
626 | struct GNUNET_RECLAIM_Ticket *ticket, | 629 | struct GNUNET_RECLAIM_Ticket *ticket, |
627 | int32_t success, | 630 | int32_t success, |
628 | const char *emsg) | 631 | const char *emsg) |
629 | { | 632 | { |
630 | struct TicketIssueOperation *tio = cls; | 633 | struct TicketIssueOperation *tio = cls; |
631 | if (GNUNET_OK != success) { | 634 | |
632 | send_ticket_result (tio->client, tio->r_id, NULL, GNUNET_SYSERR); | 635 | if (GNUNET_OK != success) |
633 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, | 636 | { |
634 | tio->client->issue_op_tail, | 637 | send_ticket_result(tio->client, tio->r_id, NULL, GNUNET_SYSERR); |
635 | tio); | 638 | GNUNET_CONTAINER_DLL_remove(tio->client->issue_op_head, |
636 | GNUNET_free (tio); | 639 | tio->client->issue_op_tail, |
637 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg); | 640 | tio); |
638 | return; | 641 | GNUNET_free(tio); |
639 | } | 642 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg); |
640 | send_ticket_result (tio->client, tio->r_id, ticket, GNUNET_SYSERR); | 643 | return; |
641 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, | 644 | } |
642 | tio->client->issue_op_tail, | 645 | send_ticket_result(tio->client, tio->r_id, ticket, GNUNET_SYSERR); |
643 | tio); | 646 | GNUNET_CONTAINER_DLL_remove(tio->client->issue_op_head, |
644 | GNUNET_free (tio); | 647 | tio->client->issue_op_tail, |
648 | tio); | ||
649 | GNUNET_free(tio); | ||
645 | } | 650 | } |
646 | 651 | ||
647 | 652 | ||
@@ -653,15 +658,16 @@ issue_ticket_result_cb (void *cls, | |||
653 | * @return GNUNET_OK if message is ok | 658 | * @return GNUNET_OK if message is ok |
654 | */ | 659 | */ |
655 | static int | 660 | static int |
656 | check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) | 661 | check_issue_ticket_message(void *cls, const struct IssueTicketMessage *im) |
657 | { | 662 | { |
658 | uint16_t size; | 663 | uint16_t size; |
659 | 664 | ||
660 | size = ntohs (im->header.size); | 665 | size = ntohs(im->header.size); |
661 | if (size <= sizeof (struct IssueTicketMessage)) { | 666 | if (size <= sizeof(struct IssueTicketMessage)) |
662 | GNUNET_break (0); | 667 | { |
663 | return GNUNET_SYSERR; | 668 | GNUNET_break(0); |
664 | } | 669 | return GNUNET_SYSERR; |
670 | } | ||
665 | return GNUNET_OK; | 671 | return GNUNET_OK; |
666 | } | 672 | } |
667 | 673 | ||
@@ -673,34 +679,34 @@ check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) | |||
673 | * @param im the message | 679 | * @param im the message |
674 | */ | 680 | */ |
675 | static void | 681 | static void |
676 | handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) | 682 | handle_issue_ticket_message(void *cls, const struct IssueTicketMessage *im) |
677 | { | 683 | { |
678 | struct TicketIssueOperation *tio; | 684 | struct TicketIssueOperation *tio; |
679 | struct IdpClient *idp = cls; | 685 | struct IdpClient *idp = cls; |
680 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 686 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; |
681 | size_t attrs_len; | 687 | size_t attrs_len; |
682 | 688 | ||
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); | 689 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); |
684 | tio = GNUNET_new (struct TicketIssueOperation); | 690 | tio = GNUNET_new(struct TicketIssueOperation); |
685 | attrs_len = ntohs (im->attr_len); | 691 | attrs_len = ntohs(im->attr_len); |
686 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&im[1], attrs_len); | 692 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize((char *)&im[1], attrs_len); |
687 | tio->r_id = ntohl (im->id); | 693 | tio->r_id = ntohl(im->id); |
688 | tio->client = idp; | 694 | tio->client = idp; |
689 | GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio); | 695 | GNUNET_CONTAINER_DLL_insert(idp->issue_op_head, idp->issue_op_tail, tio); |
690 | RECLAIM_TICKETS_issue (&im->identity, | 696 | RECLAIM_TICKETS_issue(&im->identity, |
691 | attrs, | 697 | attrs, |
692 | &im->rp, | 698 | &im->rp, |
693 | &issue_ticket_result_cb, | 699 | &issue_ticket_result_cb, |
694 | tio); | 700 | tio); |
695 | GNUNET_SERVICE_client_continue (idp->client); | 701 | GNUNET_SERVICE_client_continue(idp->client); |
696 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | 702 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy(attrs); |
697 | } | 703 | } |
698 | 704 | ||
699 | 705 | ||
700 | 706 | ||
701 | /********************************************************** | 707 | /********************************************************** |
702 | * Revocation | 708 | * Revocation |
703 | **********************************************************/ | 709 | **********************************************************/ |
704 | 710 | ||
705 | /** | 711 | /** |
706 | * Handles revocation result | 712 | * Handles revocation result |
@@ -709,22 +715,22 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) | |||
709 | * @param success revocation result (GNUNET_OK if successful) | 715 | * @param success revocation result (GNUNET_OK if successful) |
710 | */ | 716 | */ |
711 | static void | 717 | static void |
712 | revoke_result_cb (void *cls, int32_t success) | 718 | revoke_result_cb(void *cls, int32_t success) |
713 | { | 719 | { |
714 | struct TicketRevocationOperation *rop = cls; | 720 | struct TicketRevocationOperation *rop = cls; |
715 | struct GNUNET_MQ_Envelope *env; | 721 | struct GNUNET_MQ_Envelope *env; |
716 | struct RevokeTicketResultMessage *trm; | 722 | struct RevokeTicketResultMessage *trm; |
717 | 723 | ||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending REVOKE_TICKET_RESULT message\n"); | 724 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending REVOKE_TICKET_RESULT message\n"); |
719 | rop->rh = NULL; | 725 | rop->rh = NULL; |
720 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT); | 726 | env = GNUNET_MQ_msg(trm, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT); |
721 | trm->id = htonl (rop->r_id); | 727 | trm->id = htonl(rop->r_id); |
722 | trm->success = htonl (success); | 728 | trm->success = htonl(success); |
723 | GNUNET_MQ_send (rop->client->mq, env); | 729 | GNUNET_MQ_send(rop->client->mq, env); |
724 | GNUNET_CONTAINER_DLL_remove (rop->client->revoke_op_head, | 730 | GNUNET_CONTAINER_DLL_remove(rop->client->revoke_op_head, |
725 | rop->client->revoke_op_tail, | 731 | rop->client->revoke_op_tail, |
726 | rop); | 732 | rop); |
727 | GNUNET_free (rop); | 733 | GNUNET_free(rop); |
728 | } | 734 | } |
729 | 735 | ||
730 | 736 | ||
@@ -736,15 +742,16 @@ revoke_result_cb (void *cls, int32_t success) | |||
736 | * @return GNUNET_OK if message is ok | 742 | * @return GNUNET_OK if message is ok |
737 | */ | 743 | */ |
738 | static int | 744 | static int |
739 | check_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *im) | 745 | check_revoke_ticket_message(void *cls, const struct RevokeTicketMessage *im) |
740 | { | 746 | { |
741 | uint16_t size; | 747 | uint16_t size; |
742 | 748 | ||
743 | size = ntohs (im->header.size); | 749 | size = ntohs(im->header.size); |
744 | if (size != sizeof (struct RevokeTicketMessage)) { | 750 | if (size != sizeof(struct RevokeTicketMessage)) |
745 | GNUNET_break (0); | 751 | { |
746 | return GNUNET_SYSERR; | 752 | GNUNET_break(0); |
747 | } | 753 | return GNUNET_SYSERR; |
754 | } | ||
748 | return GNUNET_OK; | 755 | return GNUNET_OK; |
749 | } | 756 | } |
750 | 757 | ||
@@ -756,19 +763,19 @@ check_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *im) | |||
756 | * @param rm the message to handle | 763 | * @param rm the message to handle |
757 | */ | 764 | */ |
758 | static void | 765 | static void |
759 | handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) | 766 | handle_revoke_ticket_message(void *cls, const struct RevokeTicketMessage *rm) |
760 | { | 767 | { |
761 | struct TicketRevocationOperation *rop; | 768 | struct TicketRevocationOperation *rop; |
762 | struct IdpClient *idp = cls; | 769 | struct IdpClient *idp = cls; |
763 | 770 | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); | 771 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); |
765 | rop = GNUNET_new (struct TicketRevocationOperation); | 772 | rop = GNUNET_new(struct TicketRevocationOperation); |
766 | rop->r_id = ntohl (rm->id); | 773 | rop->r_id = ntohl(rm->id); |
767 | rop->client = idp; | 774 | rop->client = idp; |
768 | GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop); | 775 | GNUNET_CONTAINER_DLL_insert(idp->revoke_op_head, idp->revoke_op_tail, rop); |
769 | rop->rh | 776 | rop->rh |
770 | = RECLAIM_TICKETS_revoke (&rm->ticket, &rm->identity, &revoke_result_cb, rop); | 777 | = RECLAIM_TICKETS_revoke(&rm->ticket, &rm->identity, &revoke_result_cb, rop); |
771 | GNUNET_SERVICE_client_continue (idp->client); | 778 | GNUNET_SERVICE_client_continue(idp->client); |
772 | } | 779 | } |
773 | 780 | ||
774 | 781 | ||
@@ -782,36 +789,38 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) | |||
782 | * @param emsg error message (NULL if success=GNUNET_OK) | 789 | * @param emsg error message (NULL if success=GNUNET_OK) |
783 | */ | 790 | */ |
784 | static void | 791 | static void |
785 | consume_result_cb (void *cls, | 792 | consume_result_cb(void *cls, |
786 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 793 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
787 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 794 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
788 | int32_t success, | 795 | int32_t success, |
789 | const char *emsg) | 796 | const char *emsg) |
790 | { | 797 | { |
791 | struct ConsumeTicketOperation *cop = cls; | 798 | struct ConsumeTicketOperation *cop = cls; |
792 | struct ConsumeTicketResultMessage *crm; | 799 | struct ConsumeTicketResultMessage *crm; |
793 | struct GNUNET_MQ_Envelope *env; | 800 | struct GNUNET_MQ_Envelope *env; |
794 | char *data_tmp; | 801 | char *data_tmp; |
795 | size_t attrs_len; | 802 | size_t attrs_len; |
796 | if (GNUNET_OK != success) { | 803 | |
797 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); | 804 | if (GNUNET_OK != success) |
798 | } | 805 | { |
799 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | 806 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); |
800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending CONSUME_TICKET_RESULT message\n"); | 807 | } |
801 | env = GNUNET_MQ_msg_extra (crm, | 808 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size(attrs); |
802 | attrs_len, | 809 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending CONSUME_TICKET_RESULT message\n"); |
803 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); | 810 | env = GNUNET_MQ_msg_extra(crm, |
804 | crm->id = htonl (cop->r_id); | 811 | attrs_len, |
805 | crm->attrs_len = htons (attrs_len); | 812 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); |
813 | crm->id = htonl(cop->r_id); | ||
814 | crm->attrs_len = htons(attrs_len); | ||
806 | crm->identity = *identity; | 815 | crm->identity = *identity; |
807 | crm->result = htonl (success); | 816 | crm->result = htonl(success); |
808 | data_tmp = (char *)&crm[1]; | 817 | data_tmp = (char *)&crm[1]; |
809 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, data_tmp); | 818 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize(attrs, data_tmp); |
810 | GNUNET_MQ_send (cop->client->mq, env); | 819 | GNUNET_MQ_send(cop->client->mq, env); |
811 | GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, | 820 | GNUNET_CONTAINER_DLL_remove(cop->client->consume_op_head, |
812 | cop->client->consume_op_tail, | 821 | cop->client->consume_op_tail, |
813 | cop); | 822 | cop); |
814 | GNUNET_free (cop); | 823 | GNUNET_free(cop); |
815 | } | 824 | } |
816 | 825 | ||
817 | 826 | ||
@@ -822,15 +831,16 @@ consume_result_cb (void *cls, | |||
822 | * @param cm the message to handle | 831 | * @param cm the message to handle |
823 | */ | 832 | */ |
824 | static int | 833 | static int |
825 | check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | 834 | check_consume_ticket_message(void *cls, const struct ConsumeTicketMessage *cm) |
826 | { | 835 | { |
827 | uint16_t size; | 836 | uint16_t size; |
828 | 837 | ||
829 | size = ntohs (cm->header.size); | 838 | size = ntohs(cm->header.size); |
830 | if (size != sizeof (struct ConsumeTicketMessage)) { | 839 | if (size != sizeof(struct ConsumeTicketMessage)) |
831 | GNUNET_break (0); | 840 | { |
832 | return GNUNET_SYSERR; | 841 | GNUNET_break(0); |
833 | } | 842 | return GNUNET_SYSERR; |
843 | } | ||
834 | return GNUNET_OK; | 844 | return GNUNET_OK; |
835 | } | 845 | } |
836 | 846 | ||
@@ -842,24 +852,24 @@ check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | |||
842 | * @cm the message to handle | 852 | * @cm the message to handle |
843 | */ | 853 | */ |
844 | static void | 854 | static void |
845 | handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | 855 | handle_consume_ticket_message(void *cls, const struct ConsumeTicketMessage *cm) |
846 | { | 856 | { |
847 | struct ConsumeTicketOperation *cop; | 857 | struct ConsumeTicketOperation *cop; |
848 | struct IdpClient *idp = cls; | 858 | struct IdpClient *idp = cls; |
849 | 859 | ||
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); | 860 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); |
851 | cop = GNUNET_new (struct ConsumeTicketOperation); | 861 | cop = GNUNET_new(struct ConsumeTicketOperation); |
852 | cop->r_id = ntohl (cm->id); | 862 | cop->r_id = ntohl(cm->id); |
853 | cop->client = idp; | 863 | cop->client = idp; |
854 | cop->ch | 864 | cop->ch |
855 | = RECLAIM_TICKETS_consume (&cm->identity, &cm->ticket, &consume_result_cb, cop); | 865 | = RECLAIM_TICKETS_consume(&cm->identity, &cm->ticket, &consume_result_cb, cop); |
856 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); | 866 | GNUNET_CONTAINER_DLL_insert(idp->consume_op_head, idp->consume_op_tail, cop); |
857 | GNUNET_SERVICE_client_continue (idp->client); | 867 | GNUNET_SERVICE_client_continue(idp->client); |
858 | } | 868 | } |
859 | 869 | ||
860 | /***************************************** | 870 | /***************************************** |
861 | * Attribute store | 871 | * Attribute store |
862 | *****************************************/ | 872 | *****************************************/ |
863 | 873 | ||
864 | 874 | ||
865 | /** | 875 | /** |
@@ -870,32 +880,33 @@ handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | |||
870 | * @param emsg error message (NULL if success=GNUNET_OK) | 880 | * @param emsg error message (NULL if success=GNUNET_OK) |
871 | */ | 881 | */ |
872 | static void | 882 | static void |
873 | attr_store_cont (void *cls, int32_t success, const char *emsg) | 883 | attr_store_cont(void *cls, int32_t success, const char *emsg) |
874 | { | 884 | { |
875 | struct AttributeStoreHandle *ash = cls; | 885 | struct AttributeStoreHandle *ash = cls; |
876 | struct GNUNET_MQ_Envelope *env; | 886 | struct GNUNET_MQ_Envelope *env; |
877 | struct SuccessResultMessage *acr_msg; | 887 | struct SuccessResultMessage *acr_msg; |
878 | 888 | ||
879 | ash->ns_qe = NULL; | 889 | ash->ns_qe = NULL; |
880 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, | 890 | GNUNET_CONTAINER_DLL_remove(ash->client->store_op_head, |
881 | ash->client->store_op_tail, | 891 | ash->client->store_op_tail, |
882 | ash); | 892 | ash); |
883 | 893 | ||
884 | if (GNUNET_SYSERR == success) { | 894 | if (GNUNET_SYSERR == success) |
885 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 895 | { |
886 | "Failed to store attribute %s\n", | 896 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
887 | emsg); | 897 | "Failed to store attribute %s\n", |
888 | cleanup_as_handle (ash); | 898 | emsg); |
889 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 899 | cleanup_as_handle(ash); |
890 | return; | 900 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
891 | } | 901 | return; |
892 | 902 | } | |
893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); | 903 | |
894 | env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); | 904 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); |
895 | acr_msg->id = htonl (ash->r_id); | 905 | env = GNUNET_MQ_msg(acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); |
896 | acr_msg->op_result = htonl (GNUNET_OK); | 906 | acr_msg->id = htonl(ash->r_id); |
897 | GNUNET_MQ_send (ash->client->mq, env); | 907 | acr_msg->op_result = htonl(GNUNET_OK); |
898 | cleanup_as_handle (ash); | 908 | GNUNET_MQ_send(ash->client->mq, env); |
909 | cleanup_as_handle(ash); | ||
899 | } | 910 | } |
900 | 911 | ||
901 | 912 | ||
@@ -905,7 +916,7 @@ attr_store_cont (void *cls, int32_t success, const char *emsg) | |||
905 | * @param cls the AttributeStoreHandle | 916 | * @param cls the AttributeStoreHandle |
906 | */ | 917 | */ |
907 | static void | 918 | static void |
908 | attr_store_task (void *cls) | 919 | attr_store_task(void *cls) |
909 | { | 920 | { |
910 | struct AttributeStoreHandle *ash = cls; | 921 | struct AttributeStoreHandle *ash = cls; |
911 | struct GNUNET_GNSRECORD_Data rd[1]; | 922 | struct GNUNET_GNSRECORD_Data rd[1]; |
@@ -913,32 +924,32 @@ attr_store_task (void *cls) | |||
913 | char *label; | 924 | char *label; |
914 | size_t buf_size; | 925 | size_t buf_size; |
915 | 926 | ||
916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); | 927 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); |
917 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); | 928 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(ash->claim); |
918 | buf = GNUNET_malloc (buf_size); | 929 | buf = GNUNET_malloc(buf_size); |
919 | // Give the ash a new id if unset | 930 | // Give the ash a new id if unset |
920 | if (0 == ash->claim->id) | 931 | if (0 == ash->claim->id) |
921 | ash->claim->id | 932 | ash->claim->id |
922 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 933 | = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
923 | GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); | 934 | GNUNET_RECLAIM_ATTRIBUTE_serialize(ash->claim, buf); |
924 | label | 935 | label |
925 | = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, sizeof (uint64_t)); | 936 | = GNUNET_STRINGS_data_to_string_alloc(&ash->claim->id, sizeof(uint64_t)); |
926 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | 937 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); |
927 | 938 | ||
928 | rd[0].data_size = buf_size; | 939 | rd[0].data_size = buf_size; |
929 | rd[0].data = buf; | 940 | rd[0].data = buf; |
930 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; | 941 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; |
931 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 942 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
932 | rd[0].expiration_time = ash->exp.rel_value_us; | 943 | rd[0].expiration_time = ash->exp.rel_value_us; |
933 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 944 | ash->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
934 | &ash->identity, | 945 | &ash->identity, |
935 | label, | 946 | label, |
936 | 1, | 947 | 1, |
937 | rd, | 948 | rd, |
938 | &attr_store_cont, | 949 | &attr_store_cont, |
939 | ash); | 950 | ash); |
940 | GNUNET_free (buf); | 951 | GNUNET_free(buf); |
941 | GNUNET_free (label); | 952 | GNUNET_free(label); |
942 | } | 953 | } |
943 | 954 | ||
944 | 955 | ||
@@ -949,16 +960,17 @@ attr_store_task (void *cls) | |||
949 | * @param sam the message to check | 960 | * @param sam the message to check |
950 | */ | 961 | */ |
951 | static int | 962 | static int |
952 | check_attribute_store_message (void *cls, | 963 | check_attribute_store_message(void *cls, |
953 | const struct AttributeStoreMessage *sam) | 964 | const struct AttributeStoreMessage *sam) |
954 | { | 965 | { |
955 | uint16_t size; | 966 | uint16_t size; |
956 | 967 | ||
957 | size = ntohs (sam->header.size); | 968 | size = ntohs(sam->header.size); |
958 | if (size <= sizeof (struct AttributeStoreMessage)) { | 969 | if (size <= sizeof(struct AttributeStoreMessage)) |
959 | GNUNET_break (0); | 970 | { |
960 | return GNUNET_SYSERR; | 971 | GNUNET_break(0); |
961 | } | 972 | return GNUNET_SYSERR; |
973 | } | ||
962 | return GNUNET_OK; | 974 | return GNUNET_OK; |
963 | } | 975 | } |
964 | 976 | ||
@@ -970,28 +982,29 @@ check_attribute_store_message (void *cls, | |||
970 | * @param sam the message to handle | 982 | * @param sam the message to handle |
971 | */ | 983 | */ |
972 | static void | 984 | static void |
973 | handle_attribute_store_message (void *cls, | 985 | handle_attribute_store_message(void *cls, |
974 | const struct AttributeStoreMessage *sam) | 986 | const struct AttributeStoreMessage *sam) |
975 | { | 987 | { |
976 | struct AttributeStoreHandle *ash; | 988 | struct AttributeStoreHandle *ash; |
977 | struct IdpClient *idp = cls; | 989 | struct IdpClient *idp = cls; |
978 | size_t data_len; | 990 | size_t data_len; |
979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n"); | ||
980 | 991 | ||
981 | data_len = ntohs (sam->attr_len); | 992 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n"); |
993 | |||
994 | data_len = ntohs(sam->attr_len); | ||
982 | 995 | ||
983 | ash = GNUNET_new (struct AttributeStoreHandle); | 996 | ash = GNUNET_new(struct AttributeStoreHandle); |
984 | ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&sam[1], data_len); | 997 | ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize((char *)&sam[1], data_len); |
985 | 998 | ||
986 | ash->r_id = ntohl (sam->id); | 999 | ash->r_id = ntohl(sam->id); |
987 | ash->identity = sam->identity; | 1000 | ash->identity = sam->identity; |
988 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); | 1001 | ash->exp.rel_value_us = GNUNET_ntohll(sam->exp); |
989 | GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); | 1002 | GNUNET_CRYPTO_ecdsa_key_get_public(&sam->identity, &ash->identity_pkey); |
990 | 1003 | ||
991 | GNUNET_SERVICE_client_continue (idp->client); | 1004 | GNUNET_SERVICE_client_continue(idp->client); |
992 | ash->client = idp; | 1005 | ash->client = idp; |
993 | GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash); | 1006 | GNUNET_CONTAINER_DLL_insert(idp->store_op_head, idp->store_op_tail, ash); |
994 | GNUNET_SCHEDULER_add_now (&attr_store_task, ash); | 1007 | GNUNET_SCHEDULER_add_now(&attr_store_task, ash); |
995 | } | 1008 | } |
996 | 1009 | ||
997 | 1010 | ||
@@ -1002,20 +1015,20 @@ handle_attribute_store_message (void *cls, | |||
1002 | * @param success the success status | 1015 | * @param success the success status |
1003 | */ | 1016 | */ |
1004 | static void | 1017 | static void |
1005 | send_delete_response (struct AttributeDeleteHandle *adh, int32_t success) | 1018 | send_delete_response(struct AttributeDeleteHandle *adh, int32_t success) |
1006 | { | 1019 | { |
1007 | struct GNUNET_MQ_Envelope *env; | 1020 | struct GNUNET_MQ_Envelope *env; |
1008 | struct SuccessResultMessage *acr_msg; | 1021 | struct SuccessResultMessage *acr_msg; |
1009 | 1022 | ||
1010 | GNUNET_CONTAINER_DLL_remove (adh->client->delete_op_head, | 1023 | GNUNET_CONTAINER_DLL_remove(adh->client->delete_op_head, |
1011 | adh->client->delete_op_tail, | 1024 | adh->client->delete_op_tail, |
1012 | adh); | 1025 | adh); |
1013 | 1026 | ||
1014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); | 1027 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); |
1015 | env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); | 1028 | env = GNUNET_MQ_msg(acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); |
1016 | acr_msg->id = htonl (adh->r_id); | 1029 | acr_msg->id = htonl(adh->r_id); |
1017 | acr_msg->op_result = htonl (success); | 1030 | acr_msg->op_result = htonl(success); |
1018 | GNUNET_MQ_send (adh->client->mq, env); | 1031 | GNUNET_MQ_send(adh->client->mq, env); |
1019 | } | 1032 | } |
1020 | 1033 | ||
1021 | 1034 | ||
@@ -1030,39 +1043,41 @@ send_delete_response (struct AttributeDeleteHandle *adh, int32_t success) | |||
1030 | * @param rd record data | 1043 | * @param rd record data |
1031 | */ | 1044 | */ |
1032 | static void | 1045 | static void |
1033 | ticket_iter (void *cls, | 1046 | ticket_iter(void *cls, |
1034 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1047 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1035 | const char *label, | 1048 | const char *label, |
1036 | unsigned int rd_count, | 1049 | unsigned int rd_count, |
1037 | const struct GNUNET_GNSRECORD_Data *rd) | 1050 | const struct GNUNET_GNSRECORD_Data *rd) |
1038 | { | 1051 | { |
1039 | struct AttributeDeleteHandle *adh = cls; | 1052 | struct AttributeDeleteHandle *adh = cls; |
1040 | struct TicketRecordsEntry *le; | 1053 | struct TicketRecordsEntry *le; |
1041 | int has_changed = GNUNET_NO; | 1054 | int has_changed = GNUNET_NO; |
1042 | 1055 | ||
1043 | for (int i = 0; i < rd_count; i++) { | 1056 | for (int i = 0; i < rd_count; i++) |
1044 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 1057 | { |
1045 | continue; | 1058 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
1046 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof (uint64_t))) | 1059 | continue; |
1047 | continue; | 1060 | if (0 != memcmp(rd[i].data, &adh->claim->id, sizeof(uint64_t))) |
1048 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1061 | continue; |
1049 | "Attribute to delete found (%s)\n", | 1062 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1050 | adh->label); | 1063 | "Attribute to delete found (%s)\n", |
1051 | has_changed = GNUNET_YES; | 1064 | adh->label); |
1052 | break; | 1065 | has_changed = GNUNET_YES; |
1053 | } | 1066 | break; |
1054 | if (GNUNET_YES == has_changed) { | 1067 | } |
1055 | le = GNUNET_new (struct TicketRecordsEntry); | 1068 | if (GNUNET_YES == has_changed) |
1056 | le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 1069 | { |
1057 | le->data = GNUNET_malloc (le->data_size); | 1070 | le = GNUNET_new(struct TicketRecordsEntry); |
1058 | le->rd_count = rd_count; | 1071 | le->data_size = GNUNET_GNSRECORD_records_get_size(rd_count, rd); |
1059 | le->label = GNUNET_strdup (label); | 1072 | le->data = GNUNET_malloc(le->data_size); |
1060 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data); | 1073 | le->rd_count = rd_count; |
1061 | GNUNET_CONTAINER_DLL_insert (adh->tickets_to_update_head, | 1074 | le->label = GNUNET_strdup(label); |
1062 | adh->tickets_to_update_tail, | 1075 | GNUNET_GNSRECORD_records_serialize(rd_count, rd, le->data_size, le->data); |
1063 | le); | 1076 | GNUNET_CONTAINER_DLL_insert(adh->tickets_to_update_head, |
1064 | } | 1077 | adh->tickets_to_update_tail, |
1065 | GNUNET_NAMESTORE_zone_iterator_next (adh->ns_it, 1); | 1078 | le); |
1079 | } | ||
1080 | GNUNET_NAMESTORE_zone_iterator_next(adh->ns_it, 1); | ||
1066 | } | 1081 | } |
1067 | 1082 | ||
1068 | 1083 | ||
@@ -1071,7 +1086,7 @@ ticket_iter (void *cls, | |||
1071 | * @param cls our deletion handle | 1086 | * @param cls our deletion handle |
1072 | */ | 1087 | */ |
1073 | static void | 1088 | static void |
1074 | update_tickets (void *cls); | 1089 | update_tickets(void *cls); |
1075 | 1090 | ||
1076 | 1091 | ||
1077 | /** | 1092 | /** |
@@ -1082,11 +1097,12 @@ update_tickets (void *cls); | |||
1082 | * @param emsg error message (NULL if success=GNUNET_OK) | 1097 | * @param emsg error message (NULL if success=GNUNET_OK) |
1083 | */ | 1098 | */ |
1084 | static void | 1099 | static void |
1085 | ticket_updated (void *cls, int32_t success, const char *emsg) | 1100 | ticket_updated(void *cls, int32_t success, const char *emsg) |
1086 | { | 1101 | { |
1087 | struct AttributeDeleteHandle *adh = cls; | 1102 | struct AttributeDeleteHandle *adh = cls; |
1103 | |||
1088 | adh->ns_qe = NULL; | 1104 | adh->ns_qe = NULL; |
1089 | GNUNET_SCHEDULER_add_now (&update_tickets, adh); | 1105 | GNUNET_SCHEDULER_add_now(&update_tickets, adh); |
1090 | } | 1106 | } |
1091 | 1107 | ||
1092 | 1108 | ||
@@ -1098,55 +1114,58 @@ ticket_updated (void *cls, int32_t success, const char *emsg) | |||
1098 | * @param cls our attribute deletion handle | 1114 | * @param cls our attribute deletion handle |
1099 | */ | 1115 | */ |
1100 | static void | 1116 | static void |
1101 | update_tickets (void *cls) | 1117 | update_tickets(void *cls) |
1102 | { | 1118 | { |
1103 | struct AttributeDeleteHandle *adh = cls; | 1119 | struct AttributeDeleteHandle *adh = cls; |
1104 | struct TicketRecordsEntry *le; | 1120 | struct TicketRecordsEntry *le; |
1105 | if (NULL == adh->tickets_to_update_head) { | 1121 | |
1106 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1122 | if (NULL == adh->tickets_to_update_head) |
1107 | "Finished updatding tickets, success\n"); | 1123 | { |
1108 | send_delete_response (adh, GNUNET_OK); | 1124 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1109 | cleanup_adh (adh); | 1125 | "Finished updatding tickets, success\n"); |
1110 | return; | 1126 | send_delete_response(adh, GNUNET_OK); |
1111 | } | 1127 | cleanup_adh(adh); |
1112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1128 | return; |
1113 | "Updating %s\n", | 1129 | } |
1114 | adh->tickets_to_update_head->label); | 1130 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1131 | "Updating %s\n", | ||
1132 | adh->tickets_to_update_head->label); | ||
1115 | le = adh->tickets_to_update_head; | 1133 | le = adh->tickets_to_update_head; |
1116 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | 1134 | GNUNET_CONTAINER_DLL_remove(adh->tickets_to_update_head, |
1117 | adh->tickets_to_update_tail, | 1135 | adh->tickets_to_update_tail, |
1118 | le); | 1136 | le); |
1119 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | 1137 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; |
1120 | struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1]; | 1138 | struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1]; |
1121 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, | 1139 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize(le->data_size, |
1122 | le->data, | 1140 | le->data, |
1123 | le->rd_count, | 1141 | le->rd_count, |
1124 | rd)) | 1142 | rd)) |
1125 | { | 1143 | { |
1126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1144 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1127 | "Unable to deserialize record data!\n"); | 1145 | "Unable to deserialize record data!\n"); |
1128 | send_delete_response (adh, GNUNET_SYSERR); | 1146 | send_delete_response(adh, GNUNET_SYSERR); |
1129 | cleanup_adh (adh); | 1147 | cleanup_adh(adh); |
1130 | return; | 1148 | return; |
1131 | } | 1149 | } |
1132 | int j = 0; | 1150 | int j = 0; |
1133 | for (int i = 0; i < le->rd_count; i++) { | 1151 | for (int i = 0; i < le->rd_count; i++) |
1134 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) | 1152 | { |
1135 | && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof (uint64_t)))) | 1153 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
1136 | continue; | 1154 | && (0 == memcmp(rd[i].data, &adh->claim->id, sizeof(uint64_t)))) |
1137 | rd_new[j] = rd[i]; | 1155 | continue; |
1138 | j++; | 1156 | rd_new[j] = rd[i]; |
1139 | } | 1157 | j++; |
1140 | adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1158 | } |
1141 | &adh->identity, | 1159 | adh->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
1142 | le->label, | 1160 | &adh->identity, |
1143 | j, | 1161 | le->label, |
1144 | rd_new, | 1162 | j, |
1145 | &ticket_updated, | 1163 | rd_new, |
1146 | adh); | 1164 | &ticket_updated, |
1147 | GNUNET_free (le->label); | 1165 | adh); |
1148 | GNUNET_free (le->data); | 1166 | GNUNET_free(le->label); |
1149 | GNUNET_free (le); | 1167 | GNUNET_free(le->data); |
1168 | GNUNET_free(le); | ||
1150 | } | 1169 | } |
1151 | 1170 | ||
1152 | 1171 | ||
@@ -1156,11 +1175,12 @@ update_tickets (void *cls) | |||
1156 | * @param cls our attribute deletion handle | 1175 | * @param cls our attribute deletion handle |
1157 | */ | 1176 | */ |
1158 | static void | 1177 | static void |
1159 | ticket_iter_fin (void *cls) | 1178 | ticket_iter_fin(void *cls) |
1160 | { | 1179 | { |
1161 | struct AttributeDeleteHandle *adh = cls; | 1180 | struct AttributeDeleteHandle *adh = cls; |
1181 | |||
1162 | adh->ns_it = NULL; | 1182 | adh->ns_it = NULL; |
1163 | GNUNET_SCHEDULER_add_now (&update_tickets, adh); | 1183 | GNUNET_SCHEDULER_add_now(&update_tickets, adh); |
1164 | } | 1184 | } |
1165 | 1185 | ||
1166 | 1186 | ||
@@ -1170,15 +1190,16 @@ ticket_iter_fin (void *cls) | |||
1170 | * @param cls our attribute deletion handle | 1190 | * @param cls our attribute deletion handle |
1171 | */ | 1191 | */ |
1172 | static void | 1192 | static void |
1173 | ticket_iter_err (void *cls) | 1193 | ticket_iter_err(void *cls) |
1174 | { | 1194 | { |
1175 | struct AttributeDeleteHandle *adh = cls; | 1195 | struct AttributeDeleteHandle *adh = cls; |
1196 | |||
1176 | adh->ns_it = NULL; | 1197 | adh->ns_it = NULL; |
1177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1198 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1178 | "Namestore error on delete %s\n", | 1199 | "Namestore error on delete %s\n", |
1179 | adh->label); | 1200 | adh->label); |
1180 | send_delete_response (adh, GNUNET_SYSERR); | 1201 | send_delete_response(adh, GNUNET_SYSERR); |
1181 | cleanup_adh (adh); | 1202 | cleanup_adh(adh); |
1182 | } | 1203 | } |
1183 | 1204 | ||
1184 | 1205 | ||
@@ -1189,17 +1210,18 @@ ticket_iter_err (void *cls) | |||
1189 | * @param cls attribute deletion handle | 1210 | * @param cls attribute deletion handle |
1190 | */ | 1211 | */ |
1191 | static void | 1212 | static void |
1192 | start_ticket_update (void *cls) | 1213 | start_ticket_update(void *cls) |
1193 | { | 1214 | { |
1194 | struct AttributeDeleteHandle *adh = cls; | 1215 | struct AttributeDeleteHandle *adh = cls; |
1195 | adh->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1216 | |
1196 | &adh->identity, | 1217 | adh->ns_it = GNUNET_NAMESTORE_zone_iteration_start(nsh, |
1197 | &ticket_iter_err, | 1218 | &adh->identity, |
1198 | adh, | 1219 | &ticket_iter_err, |
1199 | &ticket_iter, | 1220 | adh, |
1200 | adh, | 1221 | &ticket_iter, |
1201 | &ticket_iter_fin, | 1222 | adh, |
1202 | adh); | 1223 | &ticket_iter_fin, |
1224 | adh); | ||
1203 | } | 1225 | } |
1204 | 1226 | ||
1205 | 1227 | ||
@@ -1211,20 +1233,22 @@ start_ticket_update (void *cls) | |||
1211 | * @param emsg error message (NULL if success=GNUNET_OK) | 1233 | * @param emsg error message (NULL if success=GNUNET_OK) |
1212 | */ | 1234 | */ |
1213 | static void | 1235 | static void |
1214 | attr_delete_cont (void *cls, int32_t success, const char *emsg) | 1236 | attr_delete_cont(void *cls, int32_t success, const char *emsg) |
1215 | { | 1237 | { |
1216 | struct AttributeDeleteHandle *adh = cls; | 1238 | struct AttributeDeleteHandle *adh = cls; |
1239 | |||
1217 | adh->ns_qe = NULL; | 1240 | adh->ns_qe = NULL; |
1218 | if (GNUNET_SYSERR == success) { | 1241 | if (GNUNET_SYSERR == success) |
1219 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1242 | { |
1220 | "Error deleting attribute %s\n", | 1243 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1221 | adh->label); | 1244 | "Error deleting attribute %s\n", |
1222 | send_delete_response (adh, GNUNET_SYSERR); | 1245 | adh->label); |
1223 | cleanup_adh (adh); | 1246 | send_delete_response(adh, GNUNET_SYSERR); |
1224 | return; | 1247 | cleanup_adh(adh); |
1225 | } | 1248 | return; |
1226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); | 1249 | } |
1227 | GNUNET_SCHEDULER_add_now (&start_ticket_update, adh); | 1250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); |
1251 | GNUNET_SCHEDULER_add_now(&start_ticket_update, adh); | ||
1228 | } | 1252 | } |
1229 | 1253 | ||
1230 | 1254 | ||
@@ -1235,16 +1259,17 @@ attr_delete_cont (void *cls, int32_t success, const char *emsg) | |||
1235 | * @dam message to check | 1259 | * @dam message to check |
1236 | */ | 1260 | */ |
1237 | static int | 1261 | static int |
1238 | check_attribute_delete_message (void *cls, | 1262 | check_attribute_delete_message(void *cls, |
1239 | const struct AttributeDeleteMessage *dam) | 1263 | const struct AttributeDeleteMessage *dam) |
1240 | { | 1264 | { |
1241 | uint16_t size; | 1265 | uint16_t size; |
1242 | 1266 | ||
1243 | size = ntohs (dam->header.size); | 1267 | size = ntohs(dam->header.size); |
1244 | if (size <= sizeof (struct AttributeDeleteMessage)) { | 1268 | if (size <= sizeof(struct AttributeDeleteMessage)) |
1245 | GNUNET_break (0); | 1269 | { |
1246 | return GNUNET_SYSERR; | 1270 | GNUNET_break(0); |
1247 | } | 1271 | return GNUNET_SYSERR; |
1272 | } | ||
1248 | return GNUNET_OK; | 1273 | return GNUNET_OK; |
1249 | } | 1274 | } |
1250 | 1275 | ||
@@ -1256,39 +1281,40 @@ check_attribute_delete_message (void *cls, | |||
1256 | * @param dam deletion message | 1281 | * @param dam deletion message |
1257 | */ | 1282 | */ |
1258 | static void | 1283 | static void |
1259 | handle_attribute_delete_message (void *cls, | 1284 | handle_attribute_delete_message(void *cls, |
1260 | const struct AttributeDeleteMessage *dam) | 1285 | const struct AttributeDeleteMessage *dam) |
1261 | { | 1286 | { |
1262 | struct AttributeDeleteHandle *adh; | 1287 | struct AttributeDeleteHandle *adh; |
1263 | struct IdpClient *idp = cls; | 1288 | struct IdpClient *idp = cls; |
1264 | size_t data_len; | 1289 | size_t data_len; |
1265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n"); | ||
1266 | 1290 | ||
1267 | data_len = ntohs (dam->attr_len); | 1291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n"); |
1268 | 1292 | ||
1269 | adh = GNUNET_new (struct AttributeDeleteHandle); | 1293 | data_len = ntohs(dam->attr_len); |
1270 | adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&dam[1], data_len); | ||
1271 | 1294 | ||
1272 | adh->r_id = ntohl (dam->id); | 1295 | adh = GNUNET_new(struct AttributeDeleteHandle); |
1296 | adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize((char *)&dam[1], data_len); | ||
1297 | |||
1298 | adh->r_id = ntohl(dam->id); | ||
1273 | adh->identity = dam->identity; | 1299 | adh->identity = dam->identity; |
1274 | adh->label | 1300 | adh->label |
1275 | = GNUNET_STRINGS_data_to_string_alloc (&adh->claim->id, sizeof (uint64_t)); | 1301 | = GNUNET_STRINGS_data_to_string_alloc(&adh->claim->id, sizeof(uint64_t)); |
1276 | GNUNET_SERVICE_client_continue (idp->client); | 1302 | GNUNET_SERVICE_client_continue(idp->client); |
1277 | adh->client = idp; | 1303 | adh->client = idp; |
1278 | GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh); | 1304 | GNUNET_CONTAINER_DLL_insert(idp->delete_op_head, idp->delete_op_tail, adh); |
1279 | adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1305 | adh->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
1280 | &adh->identity, | 1306 | &adh->identity, |
1281 | adh->label, | 1307 | adh->label, |
1282 | 0, | 1308 | 0, |
1283 | NULL, | 1309 | NULL, |
1284 | &attr_delete_cont, | 1310 | &attr_delete_cont, |
1285 | adh); | 1311 | adh); |
1286 | } | 1312 | } |
1287 | 1313 | ||
1288 | 1314 | ||
1289 | /************************************************* | 1315 | /************************************************* |
1290 | * Attrubute iteration | 1316 | * Attrubute iteration |
1291 | *************************************************/ | 1317 | *************************************************/ |
1292 | 1318 | ||
1293 | 1319 | ||
1294 | /** | 1320 | /** |
@@ -1297,21 +1323,21 @@ handle_attribute_delete_message (void *cls, | |||
1297 | * @param cls our iterator handle | 1323 | * @param cls our iterator handle |
1298 | */ | 1324 | */ |
1299 | static void | 1325 | static void |
1300 | attr_iter_finished (void *cls) | 1326 | attr_iter_finished(void *cls) |
1301 | { | 1327 | { |
1302 | struct AttributeIterator *ai = cls; | 1328 | struct AttributeIterator *ai = cls; |
1303 | struct GNUNET_MQ_Envelope *env; | 1329 | struct GNUNET_MQ_Envelope *env; |
1304 | struct AttributeResultMessage *arm; | 1330 | struct AttributeResultMessage *arm; |
1305 | 1331 | ||
1306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); | 1332 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); |
1307 | env = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | 1333 | env = GNUNET_MQ_msg(arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); |
1308 | arm->id = htonl (ai->request_id); | 1334 | arm->id = htonl(ai->request_id); |
1309 | arm->attr_len = htons (0); | 1335 | arm->attr_len = htons(0); |
1310 | GNUNET_MQ_send (ai->client->mq, env); | 1336 | GNUNET_MQ_send(ai->client->mq, env); |
1311 | GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, | 1337 | GNUNET_CONTAINER_DLL_remove(ai->client->attr_iter_head, |
1312 | ai->client->attr_iter_tail, | 1338 | ai->client->attr_iter_tail, |
1313 | ai); | 1339 | ai); |
1314 | GNUNET_free (ai); | 1340 | GNUNET_free(ai); |
1315 | } | 1341 | } |
1316 | 1342 | ||
1317 | /** | 1343 | /** |
@@ -1320,12 +1346,12 @@ attr_iter_finished (void *cls) | |||
1320 | * @param cls our attribute iteration handle | 1346 | * @param cls our attribute iteration handle |
1321 | */ | 1347 | */ |
1322 | static void | 1348 | static void |
1323 | attr_iter_error (void *cls) | 1349 | attr_iter_error(void *cls) |
1324 | { | 1350 | { |
1325 | struct AttributeIterator *ai = cls; | 1351 | struct AttributeIterator *ai = cls; |
1326 | 1352 | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n"); | 1353 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n"); |
1328 | attr_iter_finished (ai); | 1354 | attr_iter_finished(ai); |
1329 | } | 1355 | } |
1330 | 1356 | ||
1331 | 1357 | ||
@@ -1339,37 +1365,39 @@ attr_iter_error (void *cls) | |||
1339 | * @param rd records | 1365 | * @param rd records |
1340 | */ | 1366 | */ |
1341 | static void | 1367 | static void |
1342 | attr_iter_cb (void *cls, | 1368 | attr_iter_cb(void *cls, |
1343 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1369 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1344 | const char *label, | 1370 | const char *label, |
1345 | unsigned int rd_count, | 1371 | unsigned int rd_count, |
1346 | const struct GNUNET_GNSRECORD_Data *rd) | 1372 | const struct GNUNET_GNSRECORD_Data *rd) |
1347 | { | 1373 | { |
1348 | struct AttributeIterator *ai = cls; | 1374 | struct AttributeIterator *ai = cls; |
1349 | struct AttributeResultMessage *arm; | 1375 | struct AttributeResultMessage *arm; |
1350 | struct GNUNET_MQ_Envelope *env; | 1376 | struct GNUNET_MQ_Envelope *env; |
1351 | char *data_tmp; | 1377 | char *data_tmp; |
1352 | 1378 | ||
1353 | if (rd_count != 1) { | 1379 | if (rd_count != 1) |
1354 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); | 1380 | { |
1355 | return; | 1381 | GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1); |
1356 | } | 1382 | return; |
1357 | 1383 | } | |
1358 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) { | 1384 | |
1359 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); | 1385 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) |
1360 | return; | 1386 | { |
1361 | } | 1387 | GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1); |
1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); | 1388 | return; |
1363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); | 1389 | } |
1364 | env = GNUNET_MQ_msg_extra (arm, | 1390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); |
1365 | rd->data_size, | 1391 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); |
1366 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | 1392 | env = GNUNET_MQ_msg_extra(arm, |
1367 | arm->id = htonl (ai->request_id); | 1393 | rd->data_size, |
1368 | arm->attr_len = htons (rd->data_size); | 1394 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); |
1369 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); | 1395 | arm->id = htonl(ai->request_id); |
1396 | arm->attr_len = htons(rd->data_size); | ||
1397 | GNUNET_CRYPTO_ecdsa_key_get_public(zone, &arm->identity); | ||
1370 | data_tmp = (char *)&arm[1]; | 1398 | data_tmp = (char *)&arm[1]; |
1371 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); | 1399 | GNUNET_memcpy(data_tmp, rd->data, rd->data_size); |
1372 | GNUNET_MQ_send (ai->client->mq, env); | 1400 | GNUNET_MQ_send(ai->client->mq, env); |
1373 | } | 1401 | } |
1374 | 1402 | ||
1375 | 1403 | ||
@@ -1380,29 +1408,29 @@ attr_iter_cb (void *cls, | |||
1380 | * @param ais_msg the iteration message to start | 1408 | * @param ais_msg the iteration message to start |
1381 | */ | 1409 | */ |
1382 | static void | 1410 | static void |
1383 | handle_iteration_start (void *cls, | 1411 | handle_iteration_start(void *cls, |
1384 | const struct AttributeIterationStartMessage *ais_msg) | 1412 | const struct AttributeIterationStartMessage *ais_msg) |
1385 | { | 1413 | { |
1386 | struct IdpClient *idp = cls; | 1414 | struct IdpClient *idp = cls; |
1387 | struct AttributeIterator *ai; | 1415 | struct AttributeIterator *ai; |
1388 | 1416 | ||
1389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1417 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1390 | "Received ATTRIBUTE_ITERATION_START message\n"); | 1418 | "Received ATTRIBUTE_ITERATION_START message\n"); |
1391 | ai = GNUNET_new (struct AttributeIterator); | 1419 | ai = GNUNET_new(struct AttributeIterator); |
1392 | ai->request_id = ntohl (ais_msg->id); | 1420 | ai->request_id = ntohl(ais_msg->id); |
1393 | ai->client = idp; | 1421 | ai->client = idp; |
1394 | ai->identity = ais_msg->identity; | 1422 | ai->identity = ais_msg->identity; |
1395 | 1423 | ||
1396 | GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, idp->attr_iter_tail, ai); | 1424 | GNUNET_CONTAINER_DLL_insert(idp->attr_iter_head, idp->attr_iter_tail, ai); |
1397 | ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1425 | ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start(nsh, |
1398 | &ai->identity, | 1426 | &ai->identity, |
1399 | &attr_iter_error, | 1427 | &attr_iter_error, |
1400 | ai, | 1428 | ai, |
1401 | &attr_iter_cb, | 1429 | &attr_iter_cb, |
1402 | ai, | 1430 | ai, |
1403 | &attr_iter_finished, | 1431 | &attr_iter_finished, |
1404 | ai); | 1432 | ai); |
1405 | GNUNET_SERVICE_client_continue (idp->client); | 1433 | GNUNET_SERVICE_client_continue(idp->client); |
1406 | } | 1434 | } |
1407 | 1435 | ||
1408 | 1436 | ||
@@ -1413,28 +1441,29 @@ handle_iteration_start (void *cls, | |||
1413 | * @param ais_msg the stop message | 1441 | * @param ais_msg the stop message |
1414 | */ | 1442 | */ |
1415 | static void | 1443 | static void |
1416 | handle_iteration_stop (void *cls, | 1444 | handle_iteration_stop(void *cls, |
1417 | const struct AttributeIterationStopMessage *ais_msg) | 1445 | const struct AttributeIterationStopMessage *ais_msg) |
1418 | { | 1446 | { |
1419 | struct IdpClient *idp = cls; | 1447 | struct IdpClient *idp = cls; |
1420 | struct AttributeIterator *ai; | 1448 | struct AttributeIterator *ai; |
1421 | uint32_t rid; | 1449 | uint32_t rid; |
1422 | 1450 | ||
1423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1424 | "Received `%s' message\n", | 1452 | "Received `%s' message\n", |
1425 | "ATTRIBUTE_ITERATION_STOP"); | 1453 | "ATTRIBUTE_ITERATION_STOP"); |
1426 | rid = ntohl (ais_msg->id); | 1454 | rid = ntohl(ais_msg->id); |
1427 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) | 1455 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) |
1428 | if (ai->request_id == rid) | 1456 | if (ai->request_id == rid) |
1429 | break; | 1457 | break; |
1430 | if (NULL == ai) { | 1458 | if (NULL == ai) |
1431 | GNUNET_break (0); | 1459 | { |
1432 | GNUNET_SERVICE_client_drop (idp->client); | 1460 | GNUNET_break(0); |
1433 | return; | 1461 | GNUNET_SERVICE_client_drop(idp->client); |
1434 | } | 1462 | return; |
1435 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); | 1463 | } |
1436 | GNUNET_free (ai); | 1464 | GNUNET_CONTAINER_DLL_remove(idp->attr_iter_head, idp->attr_iter_tail, ai); |
1437 | GNUNET_SERVICE_client_continue (idp->client); | 1465 | GNUNET_free(ai); |
1466 | GNUNET_SERVICE_client_continue(idp->client); | ||
1438 | } | 1467 | } |
1439 | 1468 | ||
1440 | 1469 | ||
@@ -1445,31 +1474,32 @@ handle_iteration_stop (void *cls, | |||
1445 | * @param ais_msg the message | 1474 | * @param ais_msg the message |
1446 | */ | 1475 | */ |
1447 | static void | 1476 | static void |
1448 | handle_iteration_next (void *cls, | 1477 | handle_iteration_next(void *cls, |
1449 | const struct AttributeIterationNextMessage *ais_msg) | 1478 | const struct AttributeIterationNextMessage *ais_msg) |
1450 | { | 1479 | { |
1451 | struct IdpClient *idp = cls; | 1480 | struct IdpClient *idp = cls; |
1452 | struct AttributeIterator *ai; | 1481 | struct AttributeIterator *ai; |
1453 | uint32_t rid; | 1482 | uint32_t rid; |
1454 | 1483 | ||
1455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1484 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1456 | "Received ATTRIBUTE_ITERATION_NEXT message\n"); | 1485 | "Received ATTRIBUTE_ITERATION_NEXT message\n"); |
1457 | rid = ntohl (ais_msg->id); | 1486 | rid = ntohl(ais_msg->id); |
1458 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) | 1487 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) |
1459 | if (ai->request_id == rid) | 1488 | if (ai->request_id == rid) |
1460 | break; | 1489 | break; |
1461 | if (NULL == ai) { | 1490 | if (NULL == ai) |
1462 | GNUNET_break (0); | 1491 | { |
1463 | GNUNET_SERVICE_client_drop (idp->client); | 1492 | GNUNET_break(0); |
1464 | return; | 1493 | GNUNET_SERVICE_client_drop(idp->client); |
1465 | } | 1494 | return; |
1466 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); | 1495 | } |
1467 | GNUNET_SERVICE_client_continue (idp->client); | 1496 | GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1); |
1497 | GNUNET_SERVICE_client_continue(idp->client); | ||
1468 | } | 1498 | } |
1469 | 1499 | ||
1470 | /****************************************************** | 1500 | /****************************************************** |
1471 | * Ticket iteration | 1501 | * Ticket iteration |
1472 | ******************************************************/ | 1502 | ******************************************************/ |
1473 | 1503 | ||
1474 | /** | 1504 | /** |
1475 | * Got a ticket. Return to client | 1505 | * Got a ticket. Return to client |
@@ -1478,26 +1508,29 @@ handle_iteration_next (void *cls, | |||
1478 | * @param ticket the ticket | 1508 | * @param ticket the ticket |
1479 | */ | 1509 | */ |
1480 | static void | 1510 | static void |
1481 | ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket) | 1511 | ticket_iter_cb(void *cls, struct GNUNET_RECLAIM_Ticket *ticket) |
1482 | { | 1512 | { |
1483 | struct TicketIteration *ti = cls; | 1513 | struct TicketIteration *ti = cls; |
1484 | struct GNUNET_MQ_Envelope *env; | 1514 | struct GNUNET_MQ_Envelope *env; |
1485 | struct TicketResultMessage *trm; | 1515 | struct TicketResultMessage *trm; |
1486 | 1516 | ||
1487 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | 1517 | env = GNUNET_MQ_msg(trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
1488 | if (NULL == ticket) { | ||
1489 | /* send empty response to indicate end of list */ | ||
1490 | GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, | ||
1491 | ti->client->ticket_iter_tail, | ||
1492 | ti); | ||
1493 | } else { | ||
1494 | trm->ticket = *ticket; | ||
1495 | } | ||
1496 | trm->id = htonl (ti->r_id); | ||
1497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); | ||
1498 | GNUNET_MQ_send (ti->client->mq, env); | ||
1499 | if (NULL == ticket) | 1518 | if (NULL == ticket) |
1500 | GNUNET_free (ti); | 1519 | { |
1520 | /* send empty response to indicate end of list */ | ||
1521 | GNUNET_CONTAINER_DLL_remove(ti->client->ticket_iter_head, | ||
1522 | ti->client->ticket_iter_tail, | ||
1523 | ti); | ||
1524 | } | ||
1525 | else | ||
1526 | { | ||
1527 | trm->ticket = *ticket; | ||
1528 | } | ||
1529 | trm->id = htonl(ti->r_id); | ||
1530 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); | ||
1531 | GNUNET_MQ_send(ti->client->mq, env); | ||
1532 | if (NULL == ticket) | ||
1533 | GNUNET_free(ti); | ||
1501 | } | 1534 | } |
1502 | 1535 | ||
1503 | 1536 | ||
@@ -1508,25 +1541,25 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket) | |||
1508 | * @param tis_msg the iteration request message | 1541 | * @param tis_msg the iteration request message |
1509 | */ | 1542 | */ |
1510 | static void | 1543 | static void |
1511 | handle_ticket_iteration_start ( | 1544 | handle_ticket_iteration_start( |
1512 | void *cls, | 1545 | void *cls, |
1513 | const struct TicketIterationStartMessage *tis_msg) | 1546 | const struct TicketIterationStartMessage *tis_msg) |
1514 | { | 1547 | { |
1515 | struct IdpClient *client = cls; | 1548 | struct IdpClient *client = cls; |
1516 | struct TicketIteration *ti; | 1549 | struct TicketIteration *ti; |
1517 | 1550 | ||
1518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1551 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1519 | "Received TICKET_ITERATION_START message\n"); | 1552 | "Received TICKET_ITERATION_START message\n"); |
1520 | ti = GNUNET_new (struct TicketIteration); | 1553 | ti = GNUNET_new(struct TicketIteration); |
1521 | ti->r_id = ntohl (tis_msg->id); | 1554 | ti->r_id = ntohl(tis_msg->id); |
1522 | ti->client = client; | 1555 | ti->client = client; |
1523 | 1556 | ||
1524 | GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, | 1557 | GNUNET_CONTAINER_DLL_insert(client->ticket_iter_head, |
1525 | client->ticket_iter_tail, | 1558 | client->ticket_iter_tail, |
1526 | ti); | 1559 | ti); |
1527 | ti->iter | 1560 | ti->iter |
1528 | = RECLAIM_TICKETS_iteration_start (&tis_msg->identity, &ticket_iter_cb, ti); | 1561 | = RECLAIM_TICKETS_iteration_start(&tis_msg->identity, &ticket_iter_cb, ti); |
1529 | GNUNET_SERVICE_client_continue (client->client); | 1562 | GNUNET_SERVICE_client_continue(client->client); |
1530 | } | 1563 | } |
1531 | 1564 | ||
1532 | 1565 | ||
@@ -1537,31 +1570,32 @@ handle_ticket_iteration_start ( | |||
1537 | * @param tis_msg the stop message | 1570 | * @param tis_msg the stop message |
1538 | */ | 1571 | */ |
1539 | static void | 1572 | static void |
1540 | handle_ticket_iteration_stop (void *cls, | 1573 | handle_ticket_iteration_stop(void *cls, |
1541 | const struct TicketIterationStopMessage *tis_msg) | 1574 | const struct TicketIterationStopMessage *tis_msg) |
1542 | { | 1575 | { |
1543 | struct IdpClient *client = cls; | 1576 | struct IdpClient *client = cls; |
1544 | struct TicketIteration *ti; | 1577 | struct TicketIteration *ti; |
1545 | uint32_t rid; | 1578 | uint32_t rid; |
1546 | 1579 | ||
1547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1580 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1548 | "Received `%s' message\n", | 1581 | "Received `%s' message\n", |
1549 | "TICKET_ITERATION_STOP"); | 1582 | "TICKET_ITERATION_STOP"); |
1550 | rid = ntohl (tis_msg->id); | 1583 | rid = ntohl(tis_msg->id); |
1551 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) | 1584 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) |
1552 | if (ti->r_id == rid) | 1585 | if (ti->r_id == rid) |
1553 | break; | 1586 | break; |
1554 | if (NULL == ti) { | 1587 | if (NULL == ti) |
1555 | GNUNET_break (0); | 1588 | { |
1556 | GNUNET_SERVICE_client_drop (client->client); | 1589 | GNUNET_break(0); |
1557 | return; | 1590 | GNUNET_SERVICE_client_drop(client->client); |
1558 | } | 1591 | return; |
1559 | RECLAIM_TICKETS_iteration_stop (ti->iter); | 1592 | } |
1560 | GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, | 1593 | RECLAIM_TICKETS_iteration_stop(ti->iter); |
1561 | client->ticket_iter_tail, | 1594 | GNUNET_CONTAINER_DLL_remove(client->ticket_iter_head, |
1562 | ti); | 1595 | client->ticket_iter_tail, |
1563 | GNUNET_free (ti); | 1596 | ti); |
1564 | GNUNET_SERVICE_client_continue (client->client); | 1597 | GNUNET_free(ti); |
1598 | GNUNET_SERVICE_client_continue(client->client); | ||
1565 | } | 1599 | } |
1566 | 1600 | ||
1567 | 1601 | ||
@@ -1572,26 +1606,27 @@ handle_ticket_iteration_stop (void *cls, | |||
1572 | * @param tis_msg the message | 1606 | * @param tis_msg the message |
1573 | */ | 1607 | */ |
1574 | static void | 1608 | static void |
1575 | handle_ticket_iteration_next (void *cls, | 1609 | handle_ticket_iteration_next(void *cls, |
1576 | const struct TicketIterationNextMessage *tis_msg) | 1610 | const struct TicketIterationNextMessage *tis_msg) |
1577 | { | 1611 | { |
1578 | struct IdpClient *client = cls; | 1612 | struct IdpClient *client = cls; |
1579 | struct TicketIteration *ti; | 1613 | struct TicketIteration *ti; |
1580 | uint32_t rid; | 1614 | uint32_t rid; |
1581 | 1615 | ||
1582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1616 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1583 | "Received TICKET_ITERATION_NEXT message\n"); | 1617 | "Received TICKET_ITERATION_NEXT message\n"); |
1584 | rid = ntohl (tis_msg->id); | 1618 | rid = ntohl(tis_msg->id); |
1585 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) | 1619 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) |
1586 | if (ti->r_id == rid) | 1620 | if (ti->r_id == rid) |
1587 | break; | 1621 | break; |
1588 | if (NULL == ti) { | 1622 | if (NULL == ti) |
1589 | GNUNET_break (0); | 1623 | { |
1590 | GNUNET_SERVICE_client_drop (client->client); | 1624 | GNUNET_break(0); |
1591 | return; | 1625 | GNUNET_SERVICE_client_drop(client->client); |
1592 | } | 1626 | return; |
1593 | RECLAIM_TICKETS_iteration_next (ti->iter); | 1627 | } |
1594 | GNUNET_SERVICE_client_continue (client->client); | 1628 | RECLAIM_TICKETS_iteration_next(ti->iter); |
1629 | GNUNET_SERVICE_client_continue(client->client); | ||
1595 | } | 1630 | } |
1596 | 1631 | ||
1597 | 1632 | ||
@@ -1603,26 +1638,28 @@ handle_ticket_iteration_next (void *cls, | |||
1603 | * @param server the service handle | 1638 | * @param server the service handle |
1604 | */ | 1639 | */ |
1605 | static void | 1640 | static void |
1606 | run (void *cls, | 1641 | run(void *cls, |
1607 | const struct GNUNET_CONFIGURATION_Handle *c, | 1642 | const struct GNUNET_CONFIGURATION_Handle *c, |
1608 | struct GNUNET_SERVICE_Handle *server) | 1643 | struct GNUNET_SERVICE_Handle *server) |
1609 | { | 1644 | { |
1610 | cfg = c; | 1645 | cfg = c; |
1611 | 1646 | ||
1612 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) { | 1647 | if (GNUNET_OK != RECLAIM_TICKETS_init(cfg)) |
1613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1648 | { |
1614 | "Unable to initialize TICKETS subsystem.\n"); | 1649 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1615 | GNUNET_SCHEDULER_shutdown (); | 1650 | "Unable to initialize TICKETS subsystem.\n"); |
1616 | return; | 1651 | GNUNET_SCHEDULER_shutdown(); |
1617 | } | 1652 | return; |
1653 | } | ||
1618 | // Connect to identity and namestore services | 1654 | // Connect to identity and namestore services |
1619 | nsh = GNUNET_NAMESTORE_connect (cfg); | 1655 | nsh = GNUNET_NAMESTORE_connect(cfg); |
1620 | if (NULL == nsh) { | 1656 | if (NULL == nsh) |
1621 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 1657 | { |
1622 | "error connecting to namestore"); | 1658 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
1623 | } | 1659 | "error connecting to namestore"); |
1624 | 1660 | } | |
1625 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1661 | |
1662 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
1626 | } | 1663 | } |
1627 | 1664 | ||
1628 | 1665 | ||
@@ -1634,16 +1671,17 @@ run (void *cls, | |||
1634 | * @param app_ctx @a client | 1671 | * @param app_ctx @a client |
1635 | */ | 1672 | */ |
1636 | static void | 1673 | static void |
1637 | client_disconnect_cb (void *cls, | 1674 | client_disconnect_cb(void *cls, |
1638 | struct GNUNET_SERVICE_Client *client, | 1675 | struct GNUNET_SERVICE_Client *client, |
1639 | void *app_ctx) | 1676 | void *app_ctx) |
1640 | { | 1677 | { |
1641 | struct IdpClient *idp = app_ctx; | 1678 | struct IdpClient *idp = app_ctx; |
1642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 1679 | |
1643 | GNUNET_CONTAINER_DLL_remove (client_list_head, | 1680 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1644 | client_list_tail, | 1681 | GNUNET_CONTAINER_DLL_remove(client_list_head, |
1645 | idp); | 1682 | client_list_tail, |
1646 | cleanup_client (idp); | 1683 | idp); |
1684 | cleanup_client(idp); | ||
1647 | } | 1685 | } |
1648 | 1686 | ||
1649 | 1687 | ||
@@ -1656,18 +1694,19 @@ client_disconnect_cb (void *cls, | |||
1656 | * @return internal namestore client structure for this client | 1694 | * @return internal namestore client structure for this client |
1657 | */ | 1695 | */ |
1658 | static void * | 1696 | static void * |
1659 | client_connect_cb (void *cls, | 1697 | client_connect_cb(void *cls, |
1660 | struct GNUNET_SERVICE_Client *client, | 1698 | struct GNUNET_SERVICE_Client *client, |
1661 | struct GNUNET_MQ_Handle *mq) | 1699 | struct GNUNET_MQ_Handle *mq) |
1662 | { | 1700 | { |
1663 | struct IdpClient *idp; | 1701 | struct IdpClient *idp; |
1664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); | 1702 | |
1665 | idp = GNUNET_new (struct IdpClient); | 1703 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
1704 | idp = GNUNET_new(struct IdpClient); | ||
1666 | idp->client = client; | 1705 | idp->client = client; |
1667 | idp->mq = mq; | 1706 | idp->mq = mq; |
1668 | GNUNET_CONTAINER_DLL_insert (client_list_head, | 1707 | GNUNET_CONTAINER_DLL_insert(client_list_head, |
1669 | client_list_tail, | 1708 | client_list_tail, |
1670 | idp); | 1709 | idp); |
1671 | return idp; | 1710 | return idp; |
1672 | } | 1711 | } |
1673 | 1712 | ||
@@ -1675,57 +1714,57 @@ client_connect_cb (void *cls, | |||
1675 | /** | 1714 | /** |
1676 | * Define "main" method using service macro. | 1715 | * Define "main" method using service macro. |
1677 | */ | 1716 | */ |
1678 | GNUNET_SERVICE_MAIN ( | 1717 | GNUNET_SERVICE_MAIN( |
1679 | "reclaim", | 1718 | "reclaim", |
1680 | GNUNET_SERVICE_OPTION_NONE, | 1719 | GNUNET_SERVICE_OPTION_NONE, |
1681 | &run, | 1720 | &run, |
1682 | &client_connect_cb, | 1721 | &client_connect_cb, |
1683 | &client_disconnect_cb, | 1722 | &client_disconnect_cb, |
1684 | NULL, | 1723 | NULL, |
1685 | GNUNET_MQ_hd_var_size (attribute_store_message, | 1724 | GNUNET_MQ_hd_var_size(attribute_store_message, |
1686 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, | 1725 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, |
1687 | struct AttributeStoreMessage, | 1726 | struct AttributeStoreMessage, |
1688 | NULL), | 1727 | NULL), |
1689 | GNUNET_MQ_hd_var_size (attribute_delete_message, | 1728 | GNUNET_MQ_hd_var_size(attribute_delete_message, |
1690 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, | 1729 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, |
1691 | struct AttributeDeleteMessage, | 1730 | struct AttributeDeleteMessage, |
1692 | NULL), | 1731 | NULL), |
1693 | GNUNET_MQ_hd_fixed_size ( | 1732 | GNUNET_MQ_hd_fixed_size( |
1694 | iteration_start, | 1733 | iteration_start, |
1695 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, | 1734 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, |
1696 | struct AttributeIterationStartMessage, | 1735 | struct AttributeIterationStartMessage, |
1697 | NULL), | 1736 | NULL), |
1698 | GNUNET_MQ_hd_fixed_size (iteration_next, | 1737 | GNUNET_MQ_hd_fixed_size(iteration_next, |
1699 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, | 1738 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, |
1700 | struct AttributeIterationNextMessage, | 1739 | struct AttributeIterationNextMessage, |
1701 | NULL), | 1740 | NULL), |
1702 | GNUNET_MQ_hd_fixed_size (iteration_stop, | 1741 | GNUNET_MQ_hd_fixed_size(iteration_stop, |
1703 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, | 1742 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, |
1704 | struct AttributeIterationStopMessage, | 1743 | struct AttributeIterationStopMessage, |
1705 | NULL), | 1744 | NULL), |
1706 | GNUNET_MQ_hd_var_size (issue_ticket_message, | 1745 | GNUNET_MQ_hd_var_size(issue_ticket_message, |
1707 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET, | 1746 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET, |
1708 | struct IssueTicketMessage, | 1747 | struct IssueTicketMessage, |
1709 | NULL), | 1748 | NULL), |
1710 | GNUNET_MQ_hd_var_size (consume_ticket_message, | 1749 | GNUNET_MQ_hd_var_size(consume_ticket_message, |
1711 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, | 1750 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, |
1712 | struct ConsumeTicketMessage, | 1751 | struct ConsumeTicketMessage, |
1713 | NULL), | 1752 | NULL), |
1714 | GNUNET_MQ_hd_fixed_size (ticket_iteration_start, | 1753 | GNUNET_MQ_hd_fixed_size(ticket_iteration_start, |
1715 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, | 1754 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, |
1716 | struct TicketIterationStartMessage, | 1755 | struct TicketIterationStartMessage, |
1717 | NULL), | 1756 | NULL), |
1718 | GNUNET_MQ_hd_fixed_size (ticket_iteration_next, | 1757 | GNUNET_MQ_hd_fixed_size(ticket_iteration_next, |
1719 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, | 1758 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, |
1720 | struct TicketIterationNextMessage, | 1759 | struct TicketIterationNextMessage, |
1721 | NULL), | 1760 | NULL), |
1722 | GNUNET_MQ_hd_fixed_size (ticket_iteration_stop, | 1761 | GNUNET_MQ_hd_fixed_size(ticket_iteration_stop, |
1723 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP, | 1762 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP, |
1724 | struct TicketIterationStopMessage, | 1763 | struct TicketIterationStopMessage, |
1725 | NULL), | 1764 | NULL), |
1726 | GNUNET_MQ_hd_var_size (revoke_ticket_message, | 1765 | GNUNET_MQ_hd_var_size(revoke_ticket_message, |
1727 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET, | 1766 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET, |
1728 | struct RevokeTicketMessage, | 1767 | struct RevokeTicketMessage, |
1729 | NULL), | 1768 | NULL), |
1730 | GNUNET_MQ_handler_end ()); | 1769 | GNUNET_MQ_handler_end()); |
1731 | /* end of gnunet-service-reclaim.c */ | 1770 | /* end of gnunet-service-reclaim.c */ |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index fcfb2267d..b38a5eb25 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Martin Schanzenbach | 22 | * @author Martin Schanzenbach |
@@ -44,8 +44,7 @@ struct ParallelLookup; | |||
44 | /** | 44 | /** |
45 | * A reference to a ticket stored in GNS | 45 | * A reference to a ticket stored in GNS |
46 | */ | 46 | */ |
47 | struct TicketReference | 47 | struct TicketReference { |
48 | { | ||
49 | /** | 48 | /** |
50 | * DLL | 49 | * DLL |
51 | */ | 50 | */ |
@@ -71,8 +70,7 @@ struct TicketReference | |||
71 | /** | 70 | /** |
72 | * Handle to a consume operation | 71 | * Handle to a consume operation |
73 | */ | 72 | */ |
74 | struct RECLAIM_TICKETS_ConsumeHandle | 73 | struct RECLAIM_TICKETS_ConsumeHandle { |
75 | { | ||
76 | /** | 74 | /** |
77 | * Ticket | 75 | * Ticket |
78 | */ | 76 | */ |
@@ -133,8 +131,7 @@ struct RECLAIM_TICKETS_ConsumeHandle | |||
133 | /** | 131 | /** |
134 | * Handle for a parallel GNS lookup job | 132 | * Handle for a parallel GNS lookup job |
135 | */ | 133 | */ |
136 | struct ParallelLookup | 134 | struct ParallelLookup { |
137 | { | ||
138 | /* DLL */ | 135 | /* DLL */ |
139 | struct ParallelLookup *next; | 136 | struct ParallelLookup *next; |
140 | 137 | ||
@@ -160,8 +157,7 @@ struct ParallelLookup | |||
160 | /** | 157 | /** |
161 | * Ticket issue request handle | 158 | * Ticket issue request handle |
162 | */ | 159 | */ |
163 | struct TicketIssueHandle | 160 | struct TicketIssueHandle { |
164 | { | ||
165 | /** | 161 | /** |
166 | * Attributes to issue | 162 | * Attributes to issue |
167 | */ | 163 | */ |
@@ -202,8 +198,7 @@ struct TicketIssueHandle | |||
202 | /** | 198 | /** |
203 | * Ticket iterator | 199 | * Ticket iterator |
204 | */ | 200 | */ |
205 | struct RECLAIM_TICKETS_Iterator | 201 | struct RECLAIM_TICKETS_Iterator { |
206 | { | ||
207 | /** | 202 | /** |
208 | * Namestore queue entry | 203 | * Namestore queue entry |
209 | */ | 204 | */ |
@@ -221,8 +216,7 @@ struct RECLAIM_TICKETS_Iterator | |||
221 | }; | 216 | }; |
222 | 217 | ||
223 | 218 | ||
224 | struct RevokedAttributeEntry | 219 | struct RevokedAttributeEntry { |
225 | { | ||
226 | /** | 220 | /** |
227 | * DLL | 221 | * DLL |
228 | */ | 222 | */ |
@@ -248,8 +242,7 @@ struct RevokedAttributeEntry | |||
248 | /** | 242 | /** |
249 | * Ticket revocation request handle | 243 | * Ticket revocation request handle |
250 | */ | 244 | */ |
251 | struct RECLAIM_TICKETS_RevokeHandle | 245 | struct RECLAIM_TICKETS_RevokeHandle { |
252 | { | ||
253 | /** | 246 | /** |
254 | * Issuer Key | 247 | * Issuer Key |
255 | */ | 248 | */ |
@@ -337,31 +330,32 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
337 | * @param rh the ticket revocation handle | 330 | * @param rh the ticket revocation handle |
338 | */ | 331 | */ |
339 | static void | 332 | static void |
340 | cleanup_rvk (struct RECLAIM_TICKETS_RevokeHandle *rh) | 333 | cleanup_rvk(struct RECLAIM_TICKETS_RevokeHandle *rh) |
341 | { | 334 | { |
342 | struct RevokedAttributeEntry *ae; | 335 | struct RevokedAttributeEntry *ae; |
343 | struct TicketRecordsEntry *le; | 336 | struct TicketRecordsEntry *le; |
337 | |||
344 | if (NULL != rh->ns_qe) | 338 | if (NULL != rh->ns_qe) |
345 | GNUNET_NAMESTORE_cancel (rh->ns_qe); | 339 | GNUNET_NAMESTORE_cancel(rh->ns_qe); |
346 | if (NULL != rh->ns_it) | 340 | if (NULL != rh->ns_it) |
347 | GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it); | 341 | GNUNET_NAMESTORE_zone_iteration_stop(rh->ns_it); |
348 | while (NULL != (ae = rh->attrs_head)) | 342 | while (NULL != (ae = rh->attrs_head)) |
349 | { | 343 | { |
350 | GNUNET_CONTAINER_DLL_remove (rh->attrs_head, rh->attrs_tail, ae); | 344 | GNUNET_CONTAINER_DLL_remove(rh->attrs_head, rh->attrs_tail, ae); |
351 | GNUNET_free (ae); | 345 | GNUNET_free(ae); |
352 | } | 346 | } |
353 | while (NULL != (le = rh->tickets_to_update_head)) | 347 | while (NULL != (le = rh->tickets_to_update_head)) |
354 | { | 348 | { |
355 | GNUNET_CONTAINER_DLL_remove (rh->tickets_to_update_head, | 349 | GNUNET_CONTAINER_DLL_remove(rh->tickets_to_update_head, |
356 | rh->tickets_to_update_head, | 350 | rh->tickets_to_update_head, |
357 | le); | 351 | le); |
358 | if (NULL != le->data) | 352 | if (NULL != le->data) |
359 | GNUNET_free (le->data); | 353 | GNUNET_free(le->data); |
360 | if (NULL != le->label) | 354 | if (NULL != le->label) |
361 | GNUNET_free (le->label); | 355 | GNUNET_free(le->label); |
362 | GNUNET_free (le); | 356 | GNUNET_free(le); |
363 | } | 357 | } |
364 | GNUNET_free (rh); | 358 | GNUNET_free(rh); |
365 | } | 359 | } |
366 | 360 | ||
367 | 361 | ||
@@ -372,7 +366,7 @@ cleanup_rvk (struct RECLAIM_TICKETS_RevokeHandle *rh) | |||
372 | * @param cls handle to the operation | 366 | * @param cls handle to the operation |
373 | */ | 367 | */ |
374 | static void | 368 | static void |
375 | process_tickets (void *cls); | 369 | process_tickets(void *cls); |
376 | 370 | ||
377 | 371 | ||
378 | /** | 372 | /** |
@@ -384,11 +378,12 @@ process_tickets (void *cls); | |||
384 | * @param emsg (NULL on success) | 378 | * @param emsg (NULL on success) |
385 | */ | 379 | */ |
386 | static void | 380 | static void |
387 | ticket_processed (void *cls, int32_t success, const char *emsg) | 381 | ticket_processed(void *cls, int32_t success, const char *emsg) |
388 | { | 382 | { |
389 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 383 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
384 | |||
390 | rvk->ns_qe = NULL; | 385 | rvk->ns_qe = NULL; |
391 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); | 386 | GNUNET_SCHEDULER_add_now(&process_tickets, rvk); |
392 | } | 387 | } |
393 | 388 | ||
394 | 389 | ||
@@ -398,56 +393,57 @@ ticket_processed (void *cls, int32_t success, const char *emsg) | |||
398 | * @param cls handle to the operation | 393 | * @param cls handle to the operation |
399 | */ | 394 | */ |
400 | static void | 395 | static void |
401 | process_tickets (void *cls) | 396 | process_tickets(void *cls) |
402 | { | 397 | { |
403 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 398 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
404 | struct TicketRecordsEntry *le; | 399 | struct TicketRecordsEntry *le; |
405 | struct RevokedAttributeEntry *ae; | 400 | struct RevokedAttributeEntry *ae; |
401 | |||
406 | if (NULL == rvk->tickets_to_update_head) | 402 | if (NULL == rvk->tickets_to_update_head) |
407 | { | 403 | { |
408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 404 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
409 | "Finished updatding tickets, success\n"); | 405 | "Finished updatding tickets, success\n"); |
410 | rvk->cb (rvk->cb_cls, GNUNET_OK); | 406 | rvk->cb(rvk->cb_cls, GNUNET_OK); |
411 | cleanup_rvk (rvk); | 407 | cleanup_rvk(rvk); |
412 | return; | 408 | return; |
413 | } | 409 | } |
414 | le = rvk->tickets_to_update_head; | 410 | le = rvk->tickets_to_update_head; |
415 | GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head, | 411 | GNUNET_CONTAINER_DLL_remove(rvk->tickets_to_update_head, |
416 | rvk->tickets_to_update_tail, | 412 | rvk->tickets_to_update_tail, |
417 | le); | 413 | le); |
418 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | 414 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; |
419 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, | 415 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize(le->data_size, |
420 | le->data, | 416 | le->data, |
421 | le->rd_count, | 417 | le->rd_count, |
422 | rd)) | 418 | rd)) |
423 | { | 419 | { |
424 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 420 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
425 | "Unable to deserialize ticket record(s)\n"); | 421 | "Unable to deserialize ticket record(s)\n"); |
426 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 422 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
427 | cleanup_rvk (rvk); | 423 | cleanup_rvk(rvk); |
428 | return; | 424 | return; |
429 | } | 425 | } |
430 | for (int i = 0; i < le->rd_count; i++) | 426 | for (int i = 0; i < le->rd_count; i++) |
431 | { | ||
432 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | ||
433 | continue; | ||
434 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) | ||
435 | { | 427 | { |
436 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | 428 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
437 | continue; | 429 | continue; |
438 | rd[i].data = &ae->new_id; | 430 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) |
431 | { | ||
432 | if (0 != memcmp(rd[i].data, &ae->old_id, sizeof(uint64_t))) | ||
433 | continue; | ||
434 | rd[i].data = &ae->new_id; | ||
435 | } | ||
439 | } | 436 | } |
440 | } | 437 | rvk->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
441 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 438 | &rvk->identity, |
442 | &rvk->identity, | 439 | le->label, |
443 | le->label, | 440 | le->rd_count, |
444 | le->rd_count, | 441 | rd, |
445 | rd, | 442 | &ticket_processed, |
446 | &ticket_processed, | 443 | rvk); |
447 | rvk); | 444 | GNUNET_free(le->label); |
448 | GNUNET_free (le->label); | 445 | GNUNET_free(le->data); |
449 | GNUNET_free (le->data); | 446 | GNUNET_free(le); |
450 | GNUNET_free (le); | ||
451 | } | 447 | } |
452 | 448 | ||
453 | 449 | ||
@@ -457,11 +453,12 @@ process_tickets (void *cls) | |||
457 | * @param cls handle to the operation | 453 | * @param cls handle to the operation |
458 | */ | 454 | */ |
459 | static void | 455 | static void |
460 | rvk_ticket_update_finished (void *cls) | 456 | rvk_ticket_update_finished(void *cls) |
461 | { | 457 | { |
462 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 458 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
459 | |||
463 | rvk->ns_it = NULL; | 460 | rvk->ns_it = NULL; |
464 | GNUNET_SCHEDULER_add_now (&process_tickets, rvk); | 461 | GNUNET_SCHEDULER_add_now(&process_tickets, rvk); |
465 | } | 462 | } |
466 | 463 | ||
467 | 464 | ||
@@ -476,11 +473,11 @@ rvk_ticket_update_finished (void *cls) | |||
476 | * @param rd record set | 473 | * @param rd record set |
477 | */ | 474 | */ |
478 | static void | 475 | static void |
479 | rvk_ticket_update (void *cls, | 476 | rvk_ticket_update(void *cls, |
480 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
481 | const char *label, | 478 | const char *label, |
482 | unsigned int rd_count, | 479 | unsigned int rd_count, |
483 | const struct GNUNET_GNSRECORD_Data *rd) | 480 | const struct GNUNET_GNSRECORD_Data *rd) |
484 | { | 481 | { |
485 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 482 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
486 | struct TicketRecordsEntry *le; | 483 | struct TicketRecordsEntry *le; |
@@ -489,32 +486,32 @@ rvk_ticket_update (void *cls, | |||
489 | 486 | ||
490 | /** Let everything point to the old record **/ | 487 | /** Let everything point to the old record **/ |
491 | for (int i = 0; i < rd_count; i++) | 488 | for (int i = 0; i < rd_count; i++) |
492 | { | ||
493 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | ||
494 | continue; | ||
495 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) | ||
496 | { | 489 | { |
497 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | 490 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
498 | continue; | 491 | continue; |
499 | has_changed = GNUNET_YES; | 492 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) |
500 | break; | 493 | { |
494 | if (0 != memcmp(rd[i].data, &ae->old_id, sizeof(uint64_t))) | ||
495 | continue; | ||
496 | has_changed = GNUNET_YES; | ||
497 | break; | ||
498 | } | ||
499 | if (GNUNET_YES == has_changed) | ||
500 | break; | ||
501 | } | 501 | } |
502 | if (GNUNET_YES == has_changed) | ||
503 | break; | ||
504 | } | ||
505 | if (GNUNET_YES == has_changed) | 502 | if (GNUNET_YES == has_changed) |
506 | { | 503 | { |
507 | le = GNUNET_new (struct TicketRecordsEntry); | 504 | le = GNUNET_new(struct TicketRecordsEntry); |
508 | le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 505 | le->data_size = GNUNET_GNSRECORD_records_get_size(rd_count, rd); |
509 | le->data = GNUNET_malloc (le->data_size); | 506 | le->data = GNUNET_malloc(le->data_size); |
510 | le->rd_count = rd_count; | 507 | le->rd_count = rd_count; |
511 | le->label = GNUNET_strdup (label); | 508 | le->label = GNUNET_strdup(label); |
512 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data); | 509 | GNUNET_GNSRECORD_records_serialize(rd_count, rd, le->data_size, le->data); |
513 | GNUNET_CONTAINER_DLL_insert (rvk->tickets_to_update_head, | 510 | GNUNET_CONTAINER_DLL_insert(rvk->tickets_to_update_head, |
514 | rvk->tickets_to_update_tail, | 511 | rvk->tickets_to_update_tail, |
515 | le); | 512 | le); |
516 | } | 513 | } |
517 | GNUNET_NAMESTORE_zone_iterator_next (rvk->ns_it, 1); | 514 | GNUNET_NAMESTORE_zone_iterator_next(rvk->ns_it, 1); |
518 | } | 515 | } |
519 | 516 | ||
520 | 517 | ||
@@ -524,15 +521,16 @@ rvk_ticket_update (void *cls, | |||
524 | * @param cls handle to the operation | 521 | * @param cls handle to the operation |
525 | */ | 522 | */ |
526 | static void | 523 | static void |
527 | rvk_ns_iter_err (void *cls) | 524 | rvk_ns_iter_err(void *cls) |
528 | { | 525 | { |
529 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 526 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
527 | |||
530 | rvk->ns_it = NULL; | 528 | rvk->ns_it = NULL; |
531 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 529 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
532 | "Namestore error on revocation (id=%" PRIu64 "\n", | 530 | "Namestore error on revocation (id=%" PRIu64 "\n", |
533 | rvk->move_attr->old_id); | 531 | rvk->move_attr->old_id); |
534 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 532 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
535 | cleanup_rvk (rvk); | 533 | cleanup_rvk(rvk); |
536 | } | 534 | } |
537 | 535 | ||
538 | 536 | ||
@@ -542,15 +540,16 @@ rvk_ns_iter_err (void *cls) | |||
542 | * @param cls handle to the operation | 540 | * @param cls handle to the operation |
543 | */ | 541 | */ |
544 | static void | 542 | static void |
545 | rvk_ns_err (void *cls) | 543 | rvk_ns_err(void *cls) |
546 | { | 544 | { |
547 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 545 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
546 | |||
548 | rvk->ns_qe = NULL; | 547 | rvk->ns_qe = NULL; |
549 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 548 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
550 | "Namestore error on revocation (id=%" PRIu64 "\n", | 549 | "Namestore error on revocation (id=%" PRIu64 "\n", |
551 | rvk->move_attr->old_id); | 550 | rvk->move_attr->old_id); |
552 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 551 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
553 | cleanup_rvk (rvk); | 552 | cleanup_rvk(rvk); |
554 | } | 553 | } |
555 | 554 | ||
556 | 555 | ||
@@ -564,7 +563,7 @@ rvk_ns_err (void *cls) | |||
564 | * @param rvk handle to the operation | 563 | * @param rvk handle to the operation |
565 | */ | 564 | */ |
566 | static void | 565 | static void |
567 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh); | 566 | move_attrs(struct RECLAIM_TICKETS_RevokeHandle *rh); |
568 | 567 | ||
569 | 568 | ||
570 | /** | 569 | /** |
@@ -573,9 +572,9 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh); | |||
573 | * @param cls handle to the operation. | 572 | * @param cls handle to the operation. |
574 | */ | 573 | */ |
575 | static void | 574 | static void |
576 | move_attrs_cont (void *cls) | 575 | move_attrs_cont(void *cls) |
577 | { | 576 | { |
578 | move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls); | 577 | move_attrs((struct RECLAIM_TICKETS_RevokeHandle *)cls); |
579 | } | 578 | } |
580 | 579 | ||
581 | 580 | ||
@@ -588,21 +587,22 @@ move_attrs_cont (void *cls) | |||
588 | * @param emsg error message (NULL on success) | 587 | * @param emsg error message (NULL on success) |
589 | */ | 588 | */ |
590 | static void | 589 | static void |
591 | del_attr_finished (void *cls, int32_t success, const char *emsg) | 590 | del_attr_finished(void *cls, int32_t success, const char *emsg) |
592 | { | 591 | { |
593 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 592 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
593 | |||
594 | rvk->ns_qe = NULL; | 594 | rvk->ns_qe = NULL; |
595 | if (GNUNET_SYSERR == success) | 595 | if (GNUNET_SYSERR == success) |
596 | { | 596 | { |
597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 597 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
598 | "Error removing attribute: %s\n", | 598 | "Error removing attribute: %s\n", |
599 | emsg); | 599 | emsg); |
600 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 600 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
601 | cleanup_rvk (rvk); | 601 | cleanup_rvk(rvk); |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | rvk->move_attr = rvk->move_attr->next; | 604 | rvk->move_attr = rvk->move_attr->next; |
605 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); | 605 | GNUNET_SCHEDULER_add_now(&move_attrs_cont, rvk); |
606 | } | 606 | } |
607 | 607 | ||
608 | 608 | ||
@@ -616,30 +616,31 @@ del_attr_finished (void *cls, int32_t success, const char *emsg) | |||
616 | * @param emsg error message (NULL on success) | 616 | * @param emsg error message (NULL on success) |
617 | */ | 617 | */ |
618 | static void | 618 | static void |
619 | move_attr_finished (void *cls, int32_t success, const char *emsg) | 619 | move_attr_finished(void *cls, int32_t success, const char *emsg) |
620 | { | 620 | { |
621 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 621 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
622 | char *label; | 622 | char *label; |
623 | |||
623 | rvk->ns_qe = NULL; | 624 | rvk->ns_qe = NULL; |
624 | if (GNUNET_SYSERR == success) | 625 | if (GNUNET_SYSERR == success) |
625 | { | 626 | { |
626 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); | 627 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); |
627 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 628 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
628 | cleanup_rvk (rvk); | 629 | cleanup_rvk(rvk); |
629 | return; | 630 | return; |
630 | } | 631 | } |
631 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | 632 | label = GNUNET_STRINGS_data_to_string_alloc(&rvk->move_attr->old_id, |
632 | sizeof (uint64_t)); | 633 | sizeof(uint64_t)); |
633 | GNUNET_assert (NULL != label); | 634 | GNUNET_assert(NULL != label); |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); | 635 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); |
635 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 636 | rvk->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
636 | &rvk->identity, | 637 | &rvk->identity, |
637 | label, | 638 | label, |
638 | 0, | 639 | 0, |
639 | NULL, | 640 | NULL, |
640 | &del_attr_finished, | 641 | &del_attr_finished, |
641 | rvk); | 642 | rvk); |
642 | GNUNET_free (label); | 643 | GNUNET_free(label); |
643 | } | 644 | } |
644 | 645 | ||
645 | 646 | ||
@@ -653,11 +654,11 @@ move_attr_finished (void *cls, int32_t success, const char *emsg) | |||
653 | * @param rd record set (the attribute) | 654 | * @param rd record set (the attribute) |
654 | */ | 655 | */ |
655 | static void | 656 | static void |
656 | rvk_move_attr_cb (void *cls, | 657 | rvk_move_attr_cb(void *cls, |
657 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 658 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
658 | const char *label, | 659 | const char *label, |
659 | unsigned int rd_count, | 660 | unsigned int rd_count, |
660 | const struct GNUNET_GNSRECORD_Data *rd) | 661 | const struct GNUNET_GNSRECORD_Data *rd) |
661 | { | 662 | { |
662 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 663 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
663 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 664 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; |
@@ -665,46 +666,47 @@ rvk_move_attr_cb (void *cls, | |||
665 | struct RevokedAttributeEntry *le; | 666 | struct RevokedAttributeEntry *le; |
666 | char *new_label; | 667 | char *new_label; |
667 | char *attr_data; | 668 | char *attr_data; |
669 | |||
668 | rvk->ns_qe = NULL; | 670 | rvk->ns_qe = NULL; |
669 | if (0 == rd_count) | 671 | if (0 == rd_count) |
670 | { | 672 | { |
671 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 673 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
672 | "The attribute %s no longer exists!\n", | 674 | "The attribute %s no longer exists!\n", |
673 | label); | 675 | label); |
674 | le = rvk->move_attr; | 676 | le = rvk->move_attr; |
675 | rvk->move_attr = le->next; | 677 | rvk->move_attr = le->next; |
676 | GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le); | 678 | GNUNET_CONTAINER_DLL_remove(rvk->attrs_head, rvk->attrs_tail, le); |
677 | GNUNET_free (le); | 679 | GNUNET_free(le); |
678 | GNUNET_SCHEDULER_add_now (&move_attrs_cont, rvk); | 680 | GNUNET_SCHEDULER_add_now(&move_attrs_cont, rvk); |
679 | return; | 681 | return; |
680 | } | 682 | } |
681 | /** find a new place for this attribute **/ | 683 | /** find a new place for this attribute **/ |
682 | rvk->move_attr->new_id = | 684 | rvk->move_attr->new_id = |
683 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 685 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
684 | new_rd = *rd; | 686 | new_rd = *rd; |
685 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | 687 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize(rd->data, rd->data_size); |
686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 688 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
687 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", | 689 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", |
688 | claim->name, | 690 | claim->name, |
689 | claim->id); | 691 | claim->id); |
690 | claim->id = rvk->move_attr->new_id; | 692 | claim->id = rvk->move_attr->new_id; |
691 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); | 693 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(claim); |
692 | attr_data = GNUNET_malloc (rd->data_size); | 694 | attr_data = GNUNET_malloc(rd->data_size); |
693 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize (claim, attr_data); | 695 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize(claim, attr_data); |
694 | new_rd.data = attr_data; | 696 | new_rd.data = attr_data; |
695 | new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, | 697 | new_label = GNUNET_STRINGS_data_to_string_alloc(&rvk->move_attr->new_id, |
696 | sizeof (uint64_t)); | 698 | sizeof(uint64_t)); |
697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); | 699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); |
698 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 700 | rvk->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
699 | &rvk->identity, | 701 | &rvk->identity, |
700 | new_label, | 702 | new_label, |
701 | 1, | 703 | 1, |
702 | &new_rd, | 704 | &new_rd, |
703 | &move_attr_finished, | 705 | &move_attr_finished, |
704 | rvk); | 706 | rvk); |
705 | GNUNET_free (new_label); | 707 | GNUNET_free(new_label); |
706 | GNUNET_free (claim); | 708 | GNUNET_free(claim); |
707 | GNUNET_free (attr_data); | 709 | GNUNET_free(attr_data); |
708 | } | 710 | } |
709 | 711 | ||
710 | 712 | ||
@@ -717,36 +719,36 @@ rvk_move_attr_cb (void *cls, | |||
717 | * @param rvk handle to the operation | 719 | * @param rvk handle to the operation |
718 | */ | 720 | */ |
719 | static void | 721 | static void |
720 | move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) | 722 | move_attrs(struct RECLAIM_TICKETS_RevokeHandle *rvk) |
721 | { | 723 | { |
722 | char *label; | 724 | char *label; |
723 | 725 | ||
724 | if (NULL == rvk->move_attr) | 726 | if (NULL == rvk->move_attr) |
725 | { | 727 | { |
726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n"); | 728 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n"); |
727 | rvk->ns_it = | 729 | rvk->ns_it = |
728 | GNUNET_NAMESTORE_zone_iteration_start (nsh, | 730 | GNUNET_NAMESTORE_zone_iteration_start(nsh, |
729 | &rvk->identity, | 731 | &rvk->identity, |
730 | &rvk_ns_iter_err, | 732 | &rvk_ns_iter_err, |
731 | rvk, | 733 | rvk, |
732 | &rvk_ticket_update, | 734 | &rvk_ticket_update, |
733 | rvk, | 735 | rvk, |
734 | &rvk_ticket_update_finished, | 736 | &rvk_ticket_update_finished, |
735 | rvk); | 737 | rvk); |
736 | return; | 738 | return; |
737 | } | 739 | } |
738 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | 740 | label = GNUNET_STRINGS_data_to_string_alloc(&rvk->move_attr->old_id, |
739 | sizeof (uint64_t)); | 741 | sizeof(uint64_t)); |
740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label); | 742 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label); |
741 | 743 | ||
742 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 744 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup(nsh, |
743 | &rvk->identity, | 745 | &rvk->identity, |
744 | label, | 746 | label, |
745 | &rvk_ns_err, | 747 | &rvk_ns_err, |
746 | rvk, | 748 | rvk, |
747 | &rvk_move_attr_cb, | 749 | &rvk_move_attr_cb, |
748 | rvk); | 750 | rvk); |
749 | GNUNET_free (label); | 751 | GNUNET_free(label); |
750 | } | 752 | } |
751 | 753 | ||
752 | 754 | ||
@@ -762,28 +764,29 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) | |||
762 | * @param emsg error message (NULL on success) | 764 | * @param emsg error message (NULL on success) |
763 | */ | 765 | */ |
764 | static void | 766 | static void |
765 | remove_ticket_cont (void *cls, int32_t success, const char *emsg) | 767 | remove_ticket_cont(void *cls, int32_t success, const char *emsg) |
766 | { | 768 | { |
767 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 769 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
770 | |||
768 | rvk->ns_qe = NULL; | 771 | rvk->ns_qe = NULL; |
769 | if (GNUNET_SYSERR == success) | 772 | if (GNUNET_SYSERR == success) |
770 | { | 773 | { |
771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 774 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); |
772 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 775 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
773 | cleanup_rvk (rvk); | 776 | cleanup_rvk(rvk); |
774 | return; | 777 | return; |
775 | } | 778 | } |
776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n"); | 779 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n"); |
777 | if (0 == rvk->ticket_attrs) | 780 | if (0 == rvk->ticket_attrs) |
778 | { | 781 | { |
779 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 782 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
780 | "No attributes to move... strange\n"); | 783 | "No attributes to move... strange\n"); |
781 | rvk->cb (rvk->cb_cls, GNUNET_OK); | 784 | rvk->cb(rvk->cb_cls, GNUNET_OK); |
782 | cleanup_rvk (rvk); | 785 | cleanup_rvk(rvk); |
783 | return; | 786 | return; |
784 | } | 787 | } |
785 | rvk->move_attr = rvk->attrs_head; | 788 | rvk->move_attr = rvk->attrs_head; |
786 | move_attrs (rvk); | 789 | move_attrs(rvk); |
787 | } | 790 | } |
788 | 791 | ||
789 | 792 | ||
@@ -798,38 +801,39 @@ remove_ticket_cont (void *cls, int32_t success, const char *emsg) | |||
798 | * @param rd record set | 801 | * @param rd record set |
799 | */ | 802 | */ |
800 | static void | 803 | static void |
801 | revoke_attrs_cb (void *cls, | 804 | revoke_attrs_cb(void *cls, |
802 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 805 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
803 | const char *label, | 806 | const char *label, |
804 | unsigned int rd_count, | 807 | unsigned int rd_count, |
805 | const struct GNUNET_GNSRECORD_Data *rd) | 808 | const struct GNUNET_GNSRECORD_Data *rd) |
806 | 809 | ||
807 | { | 810 | { |
808 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 811 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
809 | struct RevokedAttributeEntry *le; | 812 | struct RevokedAttributeEntry *le; |
813 | |||
810 | rvk->ns_qe = NULL; | 814 | rvk->ns_qe = NULL; |
811 | /** | 815 | /** |
812 | * Temporarily store attribute references. | 816 | * Temporarily store attribute references. |
813 | * We need it later. | 817 | * We need it later. |
814 | */ | 818 | */ |
815 | for (int i = 0; i < rd_count; i++) | 819 | for (int i = 0; i < rd_count; i++) |
816 | { | 820 | { |
817 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 821 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
818 | continue; | 822 | continue; |
819 | le = GNUNET_new (struct RevokedAttributeEntry); | 823 | le = GNUNET_new(struct RevokedAttributeEntry); |
820 | le->old_id = *((uint64_t *) rd[i].data); | 824 | le->old_id = *((uint64_t *)rd[i].data); |
821 | GNUNET_CONTAINER_DLL_insert (rvk->attrs_head, rvk->attrs_tail, le); | 825 | GNUNET_CONTAINER_DLL_insert(rvk->attrs_head, rvk->attrs_tail, le); |
822 | rvk->ticket_attrs++; | 826 | rvk->ticket_attrs++; |
823 | } | 827 | } |
824 | 828 | ||
825 | /** Remove attribute references **/ | 829 | /** Remove attribute references **/ |
826 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 830 | rvk->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
827 | &rvk->identity, | 831 | &rvk->identity, |
828 | label, | 832 | label, |
829 | 0, | 833 | 0, |
830 | NULL, | 834 | NULL, |
831 | &remove_ticket_cont, | 835 | &remove_ticket_cont, |
832 | rvk); | 836 | rvk); |
833 | } | 837 | } |
834 | 838 | ||
835 | 839 | ||
@@ -839,11 +843,12 @@ revoke_attrs_cb (void *cls, | |||
839 | * @param cls handle to the operation | 843 | * @param cls handle to the operation |
840 | */ | 844 | */ |
841 | static void | 845 | static void |
842 | rvk_attrs_err_cb (void *cls) | 846 | rvk_attrs_err_cb(void *cls) |
843 | { | 847 | { |
844 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 848 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
845 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 849 | |
846 | cleanup_rvk (rvk); | 850 | rvk->cb(rvk->cb_cls, GNUNET_SYSERR); |
851 | cleanup_rvk(rvk); | ||
847 | } | 852 | } |
848 | 853 | ||
849 | 854 | ||
@@ -859,31 +864,31 @@ rvk_attrs_err_cb (void *cls) | |||
859 | * @return handle to the operation | 864 | * @return handle to the operation |
860 | */ | 865 | */ |
861 | struct RECLAIM_TICKETS_RevokeHandle * | 866 | struct RECLAIM_TICKETS_RevokeHandle * |
862 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 867 | RECLAIM_TICKETS_revoke(const struct GNUNET_RECLAIM_Ticket *ticket, |
863 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 868 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
864 | RECLAIM_TICKETS_RevokeCallback cb, | 869 | RECLAIM_TICKETS_RevokeCallback cb, |
865 | void *cb_cls) | 870 | void *cb_cls) |
866 | { | 871 | { |
867 | struct RECLAIM_TICKETS_RevokeHandle *rvk; | 872 | struct RECLAIM_TICKETS_RevokeHandle *rvk; |
868 | char *label; | 873 | char *label; |
869 | 874 | ||
870 | rvk = GNUNET_new (struct RECLAIM_TICKETS_RevokeHandle); | 875 | rvk = GNUNET_new(struct RECLAIM_TICKETS_RevokeHandle); |
871 | rvk->cb = cb; | 876 | rvk->cb = cb; |
872 | rvk->cb_cls = cb_cls; | 877 | rvk->cb_cls = cb_cls; |
873 | rvk->identity = *identity; | 878 | rvk->identity = *identity; |
874 | rvk->ticket = *ticket; | 879 | rvk->ticket = *ticket; |
875 | GNUNET_CRYPTO_ecdsa_key_get_public (&rvk->identity, &rvk->ticket.identity); | 880 | GNUNET_CRYPTO_ecdsa_key_get_public(&rvk->identity, &rvk->ticket.identity); |
876 | /** Get shared attributes **/ | 881 | /** Get shared attributes **/ |
877 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 882 | label = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t)); |
878 | GNUNET_assert (NULL != label); | 883 | GNUNET_assert(NULL != label); |
879 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 884 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup(nsh, |
880 | identity, | 885 | identity, |
881 | label, | 886 | label, |
882 | &rvk_attrs_err_cb, | 887 | &rvk_attrs_err_cb, |
883 | rvk, | 888 | rvk, |
884 | &revoke_attrs_cb, | 889 | &revoke_attrs_cb, |
885 | rvk); | 890 | rvk); |
886 | GNUNET_free (label); | 891 | GNUNET_free(label); |
887 | return rvk; | 892 | return rvk; |
888 | } | 893 | } |
889 | 894 | ||
@@ -894,16 +899,16 @@ RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
894 | * @param rh handle to the operation | 899 | * @param rh handle to the operation |
895 | */ | 900 | */ |
896 | void | 901 | void |
897 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh) | 902 | RECLAIM_TICKETS_revoke_cancel(struct RECLAIM_TICKETS_RevokeHandle *rh) |
898 | { | 903 | { |
899 | GNUNET_assert (NULL != rh); | 904 | GNUNET_assert(NULL != rh); |
900 | cleanup_rvk (rh); | 905 | cleanup_rvk(rh); |
901 | } | 906 | } |
902 | 907 | ||
903 | 908 | ||
904 | /******************************* | 909 | /******************************* |
905 | * Ticket consume | 910 | * Ticket consume |
906 | *******************************/ | 911 | *******************************/ |
907 | 912 | ||
908 | /** | 913 | /** |
909 | * Cleanup ticket consume handle | 914 | * Cleanup ticket consume handle |
@@ -911,27 +916,28 @@ RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh) | |||
911 | * @param cth the handle to clean up | 916 | * @param cth the handle to clean up |
912 | */ | 917 | */ |
913 | static void | 918 | static void |
914 | cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | 919 | cleanup_cth(struct RECLAIM_TICKETS_ConsumeHandle *cth) |
915 | { | 920 | { |
916 | struct ParallelLookup *lu; | 921 | struct ParallelLookup *lu; |
922 | |||
917 | if (NULL != cth->lookup_request) | 923 | if (NULL != cth->lookup_request) |
918 | GNUNET_GNS_lookup_cancel (cth->lookup_request); | 924 | GNUNET_GNS_lookup_cancel(cth->lookup_request); |
919 | if (NULL != cth->kill_task) | 925 | if (NULL != cth->kill_task) |
920 | GNUNET_SCHEDULER_cancel (cth->kill_task); | 926 | GNUNET_SCHEDULER_cancel(cth->kill_task); |
921 | while (NULL != (lu = cth->parallel_lookups_head)) | 927 | while (NULL != (lu = cth->parallel_lookups_head)) |
922 | { | 928 | { |
923 | if (NULL != lu->lookup_request) | 929 | if (NULL != lu->lookup_request) |
924 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 930 | GNUNET_GNS_lookup_cancel(lu->lookup_request); |
925 | GNUNET_free_non_null (lu->label); | 931 | GNUNET_free_non_null(lu->label); |
926 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 932 | GNUNET_CONTAINER_DLL_remove(cth->parallel_lookups_head, |
927 | cth->parallel_lookups_tail, | 933 | cth->parallel_lookups_tail, |
928 | lu); | 934 | lu); |
929 | GNUNET_free (lu); | 935 | GNUNET_free(lu); |
930 | } | 936 | } |
931 | 937 | ||
932 | if (NULL != cth->attrs) | 938 | if (NULL != cth->attrs) |
933 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cth->attrs); | 939 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy(cth->attrs); |
934 | GNUNET_free (cth); | 940 | GNUNET_free(cth); |
935 | } | 941 | } |
936 | 942 | ||
937 | 943 | ||
@@ -943,50 +949,51 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
943 | * @param rd record set | 949 | * @param rd record set |
944 | */ | 950 | */ |
945 | static void | 951 | static void |
946 | process_parallel_lookup_result (void *cls, | 952 | process_parallel_lookup_result(void *cls, |
947 | uint32_t rd_count, | 953 | uint32_t rd_count, |
948 | const struct GNUNET_GNSRECORD_Data *rd) | 954 | const struct GNUNET_GNSRECORD_Data *rd) |
949 | { | 955 | { |
950 | struct ParallelLookup *parallel_lookup = cls; | 956 | struct ParallelLookup *parallel_lookup = cls; |
951 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; | 957 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; |
952 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; | 958 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; |
953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
954 | "Parallel lookup finished (count=%u)\n", | ||
955 | rd_count); | ||
956 | 959 | ||
957 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 960 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
958 | cth->parallel_lookups_tail, | 961 | "Parallel lookup finished (count=%u)\n", |
959 | parallel_lookup); | 962 | rd_count); |
960 | GNUNET_free (parallel_lookup->label); | 963 | |
964 | GNUNET_CONTAINER_DLL_remove(cth->parallel_lookups_head, | ||
965 | cth->parallel_lookups_tail, | ||
966 | parallel_lookup); | ||
967 | GNUNET_free(parallel_lookup->label); | ||
961 | 968 | ||
962 | GNUNET_STATISTICS_update (stats, | 969 | GNUNET_STATISTICS_update(stats, |
963 | "attribute_lookup_time_total", | 970 | "attribute_lookup_time_total", |
964 | GNUNET_TIME_absolute_get_duration ( | 971 | GNUNET_TIME_absolute_get_duration( |
965 | parallel_lookup->lookup_start_time) | 972 | parallel_lookup->lookup_start_time) |
966 | .rel_value_us, | 973 | .rel_value_us, |
967 | GNUNET_YES); | 974 | GNUNET_YES); |
968 | GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES); | 975 | GNUNET_STATISTICS_update(stats, "attribute_lookups_count", 1, GNUNET_YES); |
969 | 976 | ||
970 | 977 | ||
971 | GNUNET_free (parallel_lookup); | 978 | GNUNET_free(parallel_lookup); |
972 | if (1 != rd_count) | 979 | if (1 != rd_count) |
973 | GNUNET_break (0); // FIXME: We should never find this. | 980 | GNUNET_break(0); // FIXME: We should never find this. |
974 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) | 981 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) |
975 | { | 982 | { |
976 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 983 | attr_le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
977 | attr_le->claim = | 984 | attr_le->claim = |
978 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | 985 | GNUNET_RECLAIM_ATTRIBUTE_deserialize(rd->data, rd->data_size); |
979 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, | 986 | GNUNET_CONTAINER_DLL_insert(cth->attrs->list_head, |
980 | cth->attrs->list_tail, | 987 | cth->attrs->list_tail, |
981 | attr_le); | 988 | attr_le); |
982 | } | 989 | } |
983 | 990 | ||
984 | if (NULL != cth->parallel_lookups_head) | 991 | if (NULL != cth->parallel_lookups_head) |
985 | return; // Wait for more | 992 | return; // Wait for more |
986 | 993 | ||
987 | /* Else we are done */ | 994 | /* Else we are done */ |
988 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); | 995 | cth->cb(cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
989 | cleanup_cth (cth); | 996 | cleanup_cth(cth); |
990 | } | 997 | } |
991 | 998 | ||
992 | 999 | ||
@@ -996,7 +1003,7 @@ process_parallel_lookup_result (void *cls, | |||
996 | * @param cls handle to the operation | 1003 | * @param cls handle to the operation |
997 | */ | 1004 | */ |
998 | static void | 1005 | static void |
999 | abort_parallel_lookups (void *cls) | 1006 | abort_parallel_lookups(void *cls) |
1000 | { | 1007 | { |
1001 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 1008 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
1002 | struct ParallelLookup *lu; | 1009 | struct ParallelLookup *lu; |
@@ -1004,17 +1011,17 @@ abort_parallel_lookups (void *cls) | |||
1004 | 1011 | ||
1005 | cth->kill_task = NULL; | 1012 | cth->kill_task = NULL; |
1006 | for (lu = cth->parallel_lookups_head; NULL != lu;) | 1013 | for (lu = cth->parallel_lookups_head; NULL != lu;) |
1007 | { | 1014 | { |
1008 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 1015 | GNUNET_GNS_lookup_cancel(lu->lookup_request); |
1009 | GNUNET_free (lu->label); | 1016 | GNUNET_free(lu->label); |
1010 | tmp = lu->next; | 1017 | tmp = lu->next; |
1011 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 1018 | GNUNET_CONTAINER_DLL_remove(cth->parallel_lookups_head, |
1012 | cth->parallel_lookups_tail, | 1019 | cth->parallel_lookups_tail, |
1013 | lu); | 1020 | lu); |
1014 | GNUNET_free (lu); | 1021 | GNUNET_free(lu); |
1015 | lu = tmp; | 1022 | lu = tmp; |
1016 | } | 1023 | } |
1017 | cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted"); | 1024 | cth->cb(cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted"); |
1018 | } | 1025 | } |
1019 | 1026 | ||
1020 | 1027 | ||
@@ -1028,9 +1035,9 @@ abort_parallel_lookups (void *cls) | |||
1028 | * @param rd record set | 1035 | * @param rd record set |
1029 | */ | 1036 | */ |
1030 | static void | 1037 | static void |
1031 | lookup_authz_cb (void *cls, | 1038 | lookup_authz_cb(void *cls, |
1032 | uint32_t rd_count, | 1039 | uint32_t rd_count, |
1033 | const struct GNUNET_GNSRECORD_Data *rd) | 1040 | const struct GNUNET_GNSRECORD_Data *rd) |
1034 | { | 1041 | { |
1035 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 1042 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
1036 | struct ParallelLookup *parallel_lookup; | 1043 | struct ParallelLookup *parallel_lookup; |
@@ -1038,56 +1045,56 @@ lookup_authz_cb (void *cls, | |||
1038 | 1045 | ||
1039 | cth->lookup_request = NULL; | 1046 | cth->lookup_request = NULL; |
1040 | 1047 | ||
1041 | GNUNET_STATISTICS_update (stats, | 1048 | GNUNET_STATISTICS_update(stats, |
1042 | "reclaim_authz_lookup_time_total", | 1049 | "reclaim_authz_lookup_time_total", |
1043 | GNUNET_TIME_absolute_get_duration ( | 1050 | GNUNET_TIME_absolute_get_duration( |
1044 | cth->lookup_start_time) | 1051 | cth->lookup_start_time) |
1045 | .rel_value_us, | 1052 | .rel_value_us, |
1046 | GNUNET_YES); | 1053 | GNUNET_YES); |
1047 | GNUNET_STATISTICS_update (stats, | 1054 | GNUNET_STATISTICS_update(stats, |
1048 | "reclaim_authz_lookups_count", | 1055 | "reclaim_authz_lookups_count", |
1049 | 1, | 1056 | 1, |
1050 | GNUNET_YES); | 1057 | GNUNET_YES); |
1051 | 1058 | ||
1052 | for (int i = 0; i < rd_count; i++) | 1059 | for (int i = 0; i < rd_count; i++) |
1053 | { | 1060 | { |
1054 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 1061 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
1055 | continue; | 1062 | continue; |
1056 | lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); | 1063 | lbl = GNUNET_STRINGS_data_to_string_alloc(rd[i].data, rd[i].data_size); |
1057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl); | 1064 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attribute ref found %s\n", lbl); |
1058 | parallel_lookup = GNUNET_new (struct ParallelLookup); | 1065 | parallel_lookup = GNUNET_new(struct ParallelLookup); |
1059 | parallel_lookup->handle = cth; | 1066 | parallel_lookup->handle = cth; |
1060 | parallel_lookup->label = lbl; | 1067 | parallel_lookup->label = lbl; |
1061 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); | 1068 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get(); |
1062 | parallel_lookup->lookup_request = | 1069 | parallel_lookup->lookup_request = |
1063 | GNUNET_GNS_lookup (gns, | 1070 | GNUNET_GNS_lookup(gns, |
1064 | lbl, | 1071 | lbl, |
1065 | &cth->ticket.identity, | 1072 | &cth->ticket.identity, |
1066 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | 1073 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, |
1067 | GNUNET_GNS_LO_DEFAULT, | 1074 | GNUNET_GNS_LO_DEFAULT, |
1068 | &process_parallel_lookup_result, | 1075 | &process_parallel_lookup_result, |
1069 | parallel_lookup); | 1076 | parallel_lookup); |
1070 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, | 1077 | GNUNET_CONTAINER_DLL_insert(cth->parallel_lookups_head, |
1071 | cth->parallel_lookups_tail, | 1078 | cth->parallel_lookups_tail, |
1072 | parallel_lookup); | 1079 | parallel_lookup); |
1073 | } | 1080 | } |
1074 | /** | 1081 | /** |
1075 | * We started lookups. Add a timeout task. | 1082 | * We started lookups. Add a timeout task. |
1076 | * FIXME: Really needed here? | 1083 | * FIXME: Really needed here? |
1077 | */ | 1084 | */ |
1078 | if (NULL != cth->parallel_lookups_head) | 1085 | if (NULL != cth->parallel_lookups_head) |
1079 | { | 1086 | { |
1080 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | 1087 | cth->kill_task = GNUNET_SCHEDULER_add_delayed( |
1081 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), | 1088 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 3), |
1082 | &abort_parallel_lookups, | 1089 | &abort_parallel_lookups, |
1083 | cth); | 1090 | cth); |
1084 | return; | 1091 | return; |
1085 | } | 1092 | } |
1086 | /** | 1093 | /** |
1087 | * No references found, return empty attribute list | 1094 | * No references found, return empty attribute list |
1088 | */ | 1095 | */ |
1089 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); | 1096 | cth->cb(cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
1090 | cleanup_cth (cth); | 1097 | cleanup_cth(cth); |
1091 | } | 1098 | } |
1092 | 1099 | ||
1093 | 1100 | ||
@@ -1103,36 +1110,37 @@ lookup_authz_cb (void *cls, | |||
1103 | * @return handle to the operation | 1110 | * @return handle to the operation |
1104 | */ | 1111 | */ |
1105 | struct RECLAIM_TICKETS_ConsumeHandle * | 1112 | struct RECLAIM_TICKETS_ConsumeHandle * |
1106 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 1113 | RECLAIM_TICKETS_consume(const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
1107 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1114 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1108 | RECLAIM_TICKETS_ConsumeCallback cb, | 1115 | RECLAIM_TICKETS_ConsumeCallback cb, |
1109 | void *cb_cls) | 1116 | void *cb_cls) |
1110 | { | 1117 | { |
1111 | struct RECLAIM_TICKETS_ConsumeHandle *cth; | 1118 | struct RECLAIM_TICKETS_ConsumeHandle *cth; |
1112 | char *label; | 1119 | char *label; |
1113 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); | 1120 | |
1121 | cth = GNUNET_new(struct RECLAIM_TICKETS_ConsumeHandle); | ||
1114 | 1122 | ||
1115 | cth->identity = *id; | 1123 | cth->identity = *id; |
1116 | GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); | 1124 | GNUNET_CRYPTO_ecdsa_key_get_public(&cth->identity, &cth->identity_pub); |
1117 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 1125 | cth->attrs = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
1118 | cth->ticket = *ticket; | 1126 | cth->ticket = *ticket; |
1119 | cth->cb = cb; | 1127 | cth->cb = cb; |
1120 | cth->cb_cls = cb_cls; | 1128 | cth->cb_cls = cb_cls; |
1121 | label = | 1129 | label = |
1122 | GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t)); | 1130 | GNUNET_STRINGS_data_to_string_alloc(&cth->ticket.rnd, sizeof(uint64_t)); |
1123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1124 | "Looking for AuthZ info under %s\n", | 1132 | "Looking for AuthZ info under %s\n", |
1125 | label); | 1133 | label); |
1126 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); | 1134 | cth->lookup_start_time = GNUNET_TIME_absolute_get(); |
1127 | cth->lookup_request = | 1135 | cth->lookup_request = |
1128 | GNUNET_GNS_lookup (gns, | 1136 | GNUNET_GNS_lookup(gns, |
1129 | label, | 1137 | label, |
1130 | &cth->ticket.identity, | 1138 | &cth->ticket.identity, |
1131 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, | 1139 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, |
1132 | GNUNET_GNS_LO_DEFAULT, | 1140 | GNUNET_GNS_LO_DEFAULT, |
1133 | &lookup_authz_cb, | 1141 | &lookup_authz_cb, |
1134 | cth); | 1142 | cth); |
1135 | GNUNET_free (label); | 1143 | GNUNET_free(label); |
1136 | return cth; | 1144 | return cth; |
1137 | } | 1145 | } |
1138 | 1146 | ||
@@ -1143,27 +1151,27 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
1143 | * @param cth the operation to cancel | 1151 | * @param cth the operation to cancel |
1144 | */ | 1152 | */ |
1145 | void | 1153 | void |
1146 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) | 1154 | RECLAIM_TICKETS_consume_cancel(struct RECLAIM_TICKETS_ConsumeHandle *cth) |
1147 | { | 1155 | { |
1148 | cleanup_cth (cth); | 1156 | cleanup_cth(cth); |
1149 | return; | 1157 | return; |
1150 | } | 1158 | } |
1151 | 1159 | ||
1152 | 1160 | ||
1153 | /******************************* | 1161 | /******************************* |
1154 | * Ticket issue | 1162 | * Ticket issue |
1155 | *******************************/ | 1163 | *******************************/ |
1156 | 1164 | ||
1157 | /** | 1165 | /** |
1158 | * Cleanup ticket consume handle | 1166 | * Cleanup ticket consume handle |
1159 | * @param handle the handle to clean up | 1167 | * @param handle the handle to clean up |
1160 | */ | 1168 | */ |
1161 | static void | 1169 | static void |
1162 | cleanup_issue_handle (struct TicketIssueHandle *handle) | 1170 | cleanup_issue_handle(struct TicketIssueHandle *handle) |
1163 | { | 1171 | { |
1164 | if (NULL != handle->ns_qe) | 1172 | if (NULL != handle->ns_qe) |
1165 | GNUNET_NAMESTORE_cancel (handle->ns_qe); | 1173 | GNUNET_NAMESTORE_cancel(handle->ns_qe); |
1166 | GNUNET_free (handle); | 1174 | GNUNET_free(handle); |
1167 | } | 1175 | } |
1168 | 1176 | ||
1169 | 1177 | ||
@@ -1176,21 +1184,21 @@ cleanup_issue_handle (struct TicketIssueHandle *handle) | |||
1176 | * @param emsg error message (or NULL on success) | 1184 | * @param emsg error message (or NULL on success) |
1177 | */ | 1185 | */ |
1178 | static void | 1186 | static void |
1179 | store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) | 1187 | store_ticket_issue_cont(void *cls, int32_t success, const char *emsg) |
1180 | { | 1188 | { |
1181 | struct TicketIssueHandle *handle = cls; | 1189 | struct TicketIssueHandle *handle = cls; |
1182 | 1190 | ||
1183 | handle->ns_qe = NULL; | 1191 | handle->ns_qe = NULL; |
1184 | if (GNUNET_SYSERR == success) | 1192 | if (GNUNET_SYSERR == success) |
1185 | { | 1193 | { |
1186 | handle->cb (handle->cb_cls, | 1194 | handle->cb(handle->cb_cls, |
1187 | &handle->ticket, | 1195 | &handle->ticket, |
1188 | GNUNET_SYSERR, | 1196 | GNUNET_SYSERR, |
1189 | "Error storing AuthZ ticket in GNS"); | 1197 | "Error storing AuthZ ticket in GNS"); |
1190 | return; | 1198 | return; |
1191 | } | 1199 | } |
1192 | handle->cb (handle->cb_cls, &handle->ticket, GNUNET_OK, NULL); | 1200 | handle->cb(handle->cb_cls, &handle->ticket, GNUNET_OK, NULL); |
1193 | cleanup_issue_handle (handle); | 1201 | cleanup_issue_handle(handle); |
1194 | } | 1202 | } |
1195 | 1203 | ||
1196 | 1204 | ||
@@ -1202,7 +1210,7 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) | |||
1202 | * @param ih handle to the operation containing relevant metadata | 1210 | * @param ih handle to the operation containing relevant metadata |
1203 | */ | 1211 | */ |
1204 | static void | 1212 | static void |
1205 | issue_ticket (struct TicketIssueHandle *ih) | 1213 | issue_ticket(struct TicketIssueHandle *ih) |
1206 | { | 1214 | { |
1207 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 1215 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
1208 | struct GNUNET_GNSRECORD_Data *attrs_record; | 1216 | struct GNUNET_GNSRECORD_Data *attrs_record; |
@@ -1214,45 +1222,45 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
1214 | list_len++; | 1222 | list_len++; |
1215 | 1223 | ||
1216 | attrs_record = | 1224 | attrs_record = |
1217 | GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data)); | 1225 | GNUNET_malloc(list_len * sizeof(struct GNUNET_GNSRECORD_Data)); |
1218 | i = 0; | 1226 | i = 0; |
1219 | for (le = ih->attrs->list_head; NULL != le; le = le->next) | 1227 | for (le = ih->attrs->list_head; NULL != le; le = le->next) |
1220 | { | 1228 | { |
1221 | attrs_record[i].data = &le->claim->id; | 1229 | attrs_record[i].data = &le->claim->id; |
1222 | attrs_record[i].data_size = sizeof (le->claim->id); | 1230 | attrs_record[i].data_size = sizeof(le->claim->id); |
1223 | /** | 1231 | /** |
1224 | * FIXME: Should this be the attribute expiration time or ticket | 1232 | * FIXME: Should this be the attribute expiration time or ticket |
1225 | * refresh interval? Probably min(attrs.expiration) | 1233 | * refresh interval? Probably min(attrs.expiration) |
1226 | */ | 1234 | */ |
1227 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; | 1235 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; |
1228 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; | 1236 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF; |
1229 | attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1237 | attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1230 | i++; | 1238 | i++; |
1231 | } | 1239 | } |
1232 | attrs_record[i].data = &ih->ticket; | 1240 | attrs_record[i].data = &ih->ticket; |
1233 | attrs_record[i].data_size = sizeof (struct GNUNET_RECLAIM_Ticket); | 1241 | attrs_record[i].data_size = sizeof(struct GNUNET_RECLAIM_Ticket); |
1234 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; | 1242 | attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; |
1235 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET; | 1243 | attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET; |
1236 | attrs_record[i].flags = | 1244 | attrs_record[i].flags = |
1237 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | GNUNET_GNSRECORD_RF_PRIVATE; | 1245 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | GNUNET_GNSRECORD_RF_PRIVATE; |
1238 | 1246 | ||
1239 | label = | 1247 | label = |
1240 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); | 1248 | GNUNET_STRINGS_data_to_string_alloc(&ih->ticket.rnd, sizeof(uint64_t)); |
1241 | // Publish record | 1249 | // Publish record |
1242 | ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1250 | ih->ns_qe = GNUNET_NAMESTORE_records_store(nsh, |
1243 | &ih->identity, | 1251 | &ih->identity, |
1244 | label, | 1252 | label, |
1245 | list_len, | 1253 | list_len, |
1246 | attrs_record, | 1254 | attrs_record, |
1247 | &store_ticket_issue_cont, | 1255 | &store_ticket_issue_cont, |
1248 | ih); | 1256 | ih); |
1249 | GNUNET_free (attrs_record); | 1257 | GNUNET_free(attrs_record); |
1250 | GNUNET_free (label); | 1258 | GNUNET_free(label); |
1251 | } | 1259 | } |
1252 | 1260 | ||
1253 | /************************************************* | 1261 | /************************************************* |
1254 | * Ticket iteration (finding a specific ticket) | 1262 | * Ticket iteration (finding a specific ticket) |
1255 | *************************************************/ | 1263 | *************************************************/ |
1256 | 1264 | ||
1257 | 1265 | ||
1258 | /** | 1266 | /** |
@@ -1261,15 +1269,16 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
1261 | * @param cls handle to the operation | 1269 | * @param cls handle to the operation |
1262 | */ | 1270 | */ |
1263 | static void | 1271 | static void |
1264 | filter_tickets_error_cb (void *cls) | 1272 | filter_tickets_error_cb(void *cls) |
1265 | { | 1273 | { |
1266 | struct TicketIssueHandle *tih = cls; | 1274 | struct TicketIssueHandle *tih = cls; |
1275 | |||
1267 | tih->ns_it = NULL; | 1276 | tih->ns_it = NULL; |
1268 | tih->cb (tih->cb_cls, | 1277 | tih->cb(tih->cb_cls, |
1269 | &tih->ticket, | 1278 | &tih->ticket, |
1270 | GNUNET_SYSERR, | 1279 | GNUNET_SYSERR, |
1271 | "Error storing AuthZ ticket in GNS"); | 1280 | "Error storing AuthZ ticket in GNS"); |
1272 | cleanup_issue_handle (tih); | 1281 | cleanup_issue_handle(tih); |
1273 | } | 1282 | } |
1274 | 1283 | ||
1275 | 1284 | ||
@@ -1286,11 +1295,11 @@ filter_tickets_error_cb (void *cls) | |||
1286 | * @param rd record set | 1295 | * @param rd record set |
1287 | */ | 1296 | */ |
1288 | static void | 1297 | static void |
1289 | filter_tickets_cb (void *cls, | 1298 | filter_tickets_cb(void *cls, |
1290 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1299 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1291 | const char *label, | 1300 | const char *label, |
1292 | unsigned int rd_count, | 1301 | unsigned int rd_count, |
1293 | const struct GNUNET_GNSRECORD_Data *rd) | 1302 | const struct GNUNET_GNSRECORD_Data *rd) |
1294 | { | 1303 | { |
1295 | struct TicketIssueHandle *tih = cls; | 1304 | struct TicketIssueHandle *tih = cls; |
1296 | struct GNUNET_RECLAIM_Ticket *ticket = NULL; | 1305 | struct GNUNET_RECLAIM_Ticket *ticket = NULL; |
@@ -1298,6 +1307,7 @@ filter_tickets_cb (void *cls, | |||
1298 | // figure out the number of requested attributes | 1307 | // figure out the number of requested attributes |
1299 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 1308 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
1300 | unsigned int attr_cnt = 0; | 1309 | unsigned int attr_cnt = 0; |
1310 | |||
1301 | for (le = tih->attrs->list_head; NULL != le; le = le->next) | 1311 | for (le = tih->attrs->list_head; NULL != le; le = le->next) |
1302 | attr_cnt++; | 1312 | attr_cnt++; |
1303 | 1313 | ||
@@ -1305,53 +1315,53 @@ filter_tickets_cb (void *cls, | |||
1305 | unsigned int found_attrs_cnt = 0; | 1315 | unsigned int found_attrs_cnt = 0; |
1306 | 1316 | ||
1307 | for (int i = 0; i < rd_count; i++) | 1317 | for (int i = 0; i < rd_count; i++) |
1308 | { | ||
1309 | // found ticket | ||
1310 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type) | ||
1311 | { | 1318 | { |
1312 | ticket = (struct GNUNET_RECLAIM_Ticket *) rd[i].data; | 1319 | // found ticket |
1313 | // cmp audience | 1320 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type) |
1314 | if (0 == memcmp (&tih->ticket.audience, | 1321 | { |
1315 | &ticket->audience, | 1322 | ticket = (struct GNUNET_RECLAIM_Ticket *)rd[i].data; |
1316 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 1323 | // cmp audience |
1317 | { | 1324 | if (0 == memcmp(&tih->ticket.audience, |
1318 | tih->ticket = *ticket; | 1325 | &ticket->audience, |
1326 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
1327 | { | ||
1328 | tih->ticket = *ticket; | ||
1329 | continue; | ||
1330 | } | ||
1331 | ticket = NULL; | ||
1332 | } | ||
1333 | |||
1334 | // cmp requested attributes with ticket attributes | ||
1335 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | ||
1319 | continue; | 1336 | continue; |
1320 | } | 1337 | for (le = tih->attrs->list_head; NULL != le; le = le->next) |
1321 | ticket = NULL; | 1338 | { |
1322 | } | 1339 | // cmp attr_ref id with requested attr id |
1323 | 1340 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
1324 | // cmp requested attributes with ticket attributes | 1341 | " %" PRIu64 "\n %" PRIu64 "\n", |
1325 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 1342 | *((uint64_t *)rd[i].data), |
1326 | continue; | 1343 | le->claim->id); |
1327 | for (le = tih->attrs->list_head; NULL != le; le = le->next) | 1344 | |
1328 | { | 1345 | |
1329 | // cmp attr_ref id with requested attr id | 1346 | if (0 == memcmp(rd[i].data, &le->claim->id, sizeof(uint64_t))) |
1330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1347 | found_attrs_cnt++; |
1331 | " %" PRIu64 "\n %" PRIu64 "\n", | 1348 | } |
1332 | *((uint64_t *) rd[i].data), | ||
1333 | le->claim->id); | ||
1334 | |||
1335 | |||
1336 | if (0 == memcmp (rd[i].data, &le->claim->id, sizeof (uint64_t))) | ||
1337 | found_attrs_cnt++; | ||
1338 | } | 1349 | } |
1339 | } | ||
1340 | 1350 | ||
1341 | /** | 1351 | /** |
1342 | * If we found a matching ticket, return that to the caller and | 1352 | * If we found a matching ticket, return that to the caller and |
1343 | * we are done. | 1353 | * we are done. |
1344 | */ | 1354 | */ |
1345 | if (attr_cnt == found_attrs_cnt && NULL != ticket) | 1355 | if (attr_cnt == found_attrs_cnt && NULL != ticket) |
1346 | { | 1356 | { |
1347 | GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); | 1357 | GNUNET_NAMESTORE_zone_iteration_stop(tih->ns_it); |
1348 | tih->cb (tih->cb_cls, &tih->ticket, GNUNET_OK, NULL); | 1358 | tih->cb(tih->cb_cls, &tih->ticket, GNUNET_OK, NULL); |
1349 | cleanup_issue_handle (tih); | 1359 | cleanup_issue_handle(tih); |
1350 | return; | 1360 | return; |
1351 | } | 1361 | } |
1352 | 1362 | ||
1353 | // ticket not found in current record, checking next record set | 1363 | // ticket not found in current record, checking next record set |
1354 | GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1); | 1364 | GNUNET_NAMESTORE_zone_iterator_next(tih->ns_it, 1); |
1355 | } | 1365 | } |
1356 | 1366 | ||
1357 | 1367 | ||
@@ -1363,13 +1373,14 @@ filter_tickets_cb (void *cls, | |||
1363 | * @param cls handle to the operation | 1373 | * @param cls handle to the operation |
1364 | */ | 1374 | */ |
1365 | static void | 1375 | static void |
1366 | filter_tickets_finished_cb (void *cls) | 1376 | filter_tickets_finished_cb(void *cls) |
1367 | { | 1377 | { |
1368 | struct TicketIssueHandle *tih = cls; | 1378 | struct TicketIssueHandle *tih = cls; |
1369 | GNUNET_CRYPTO_ecdsa_key_get_public (&tih->identity, &tih->ticket.identity); | 1379 | |
1380 | GNUNET_CRYPTO_ecdsa_key_get_public(&tih->identity, &tih->ticket.identity); | ||
1370 | tih->ticket.rnd = | 1381 | tih->ticket.rnd = |
1371 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 1382 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
1372 | issue_ticket (tih); | 1383 | issue_ticket(tih); |
1373 | } | 1384 | } |
1374 | 1385 | ||
1375 | 1386 | ||
@@ -1385,36 +1396,37 @@ filter_tickets_finished_cb (void *cls) | |||
1385 | * FIXME: Return handle?? | 1396 | * FIXME: Return handle?? |
1386 | */ | 1397 | */ |
1387 | void | 1398 | void |
1388 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1399 | RECLAIM_TICKETS_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1389 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 1400 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
1390 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 1401 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
1391 | RECLAIM_TICKETS_TicketResult cb, | 1402 | RECLAIM_TICKETS_TicketResult cb, |
1392 | void *cb_cls) | 1403 | void *cb_cls) |
1393 | { | 1404 | { |
1394 | struct TicketIssueHandle *tih; | 1405 | struct TicketIssueHandle *tih; |
1395 | tih = GNUNET_new (struct TicketIssueHandle); | 1406 | |
1407 | tih = GNUNET_new(struct TicketIssueHandle); | ||
1396 | tih->cb = cb; | 1408 | tih->cb = cb; |
1397 | tih->cb_cls = cb_cls; | 1409 | tih->cb_cls = cb_cls; |
1398 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); | 1410 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup(attrs); |
1399 | tih->identity = *identity; | 1411 | tih->identity = *identity; |
1400 | tih->ticket.audience = *audience; | 1412 | tih->ticket.audience = *audience; |
1401 | 1413 | ||
1402 | // First check whether the ticket has already been issued | 1414 | // First check whether the ticket has already been issued |
1403 | tih->ns_it = | 1415 | tih->ns_it = |
1404 | GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1416 | GNUNET_NAMESTORE_zone_iteration_start(nsh, |
1405 | &tih->identity, | 1417 | &tih->identity, |
1406 | &filter_tickets_error_cb, | 1418 | &filter_tickets_error_cb, |
1407 | tih, | 1419 | tih, |
1408 | &filter_tickets_cb, | 1420 | &filter_tickets_cb, |
1409 | tih, | 1421 | tih, |
1410 | &filter_tickets_finished_cb, | 1422 | &filter_tickets_finished_cb, |
1411 | tih); | 1423 | tih); |
1412 | } | 1424 | } |
1413 | 1425 | ||
1414 | 1426 | ||
1415 | /************************************ | 1427 | /************************************ |
1416 | * Ticket iteration | 1428 | * Ticket iteration |
1417 | ************************************/ | 1429 | ************************************/ |
1418 | 1430 | ||
1419 | /** | 1431 | /** |
1420 | * Cleanup ticket iterator | 1432 | * Cleanup ticket iterator |
@@ -1422,11 +1434,11 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
1422 | * @param iter handle to the iteration | 1434 | * @param iter handle to the iteration |
1423 | */ | 1435 | */ |
1424 | static void | 1436 | static void |
1425 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | 1437 | cleanup_iter(struct RECLAIM_TICKETS_Iterator *iter) |
1426 | { | 1438 | { |
1427 | if (NULL != iter->ns_it) | 1439 | if (NULL != iter->ns_it) |
1428 | GNUNET_NAMESTORE_zone_iteration_stop (iter->ns_it); | 1440 | GNUNET_NAMESTORE_zone_iteration_stop(iter->ns_it); |
1429 | GNUNET_free (iter); | 1441 | GNUNET_free(iter); |
1430 | } | 1442 | } |
1431 | 1443 | ||
1432 | 1444 | ||
@@ -1442,22 +1454,22 @@ cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | |||
1442 | * @param rd record set containing a ticket | 1454 | * @param rd record set containing a ticket |
1443 | */ | 1455 | */ |
1444 | static void | 1456 | static void |
1445 | collect_tickets_cb (void *cls, | 1457 | collect_tickets_cb(void *cls, |
1446 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1458 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1447 | const char *label, | 1459 | const char *label, |
1448 | unsigned int rd_count, | 1460 | unsigned int rd_count, |
1449 | const struct GNUNET_GNSRECORD_Data *rd) | 1461 | const struct GNUNET_GNSRECORD_Data *rd) |
1450 | { | 1462 | { |
1451 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 1463 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
1452 | 1464 | ||
1453 | for (int i = 0; i < rd_count; i++) | 1465 | for (int i = 0; i < rd_count; i++) |
1454 | { | 1466 | { |
1455 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type) | 1467 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type) |
1456 | continue; | 1468 | continue; |
1457 | iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *) rd[i].data); | 1469 | iter->cb(iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *)rd[i].data); |
1458 | return; | 1470 | return; |
1459 | } | 1471 | } |
1460 | GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1); | 1472 | GNUNET_NAMESTORE_zone_iterator_next(iter->ns_it, 1); |
1461 | } | 1473 | } |
1462 | 1474 | ||
1463 | 1475 | ||
@@ -1467,12 +1479,13 @@ collect_tickets_cb (void *cls, | |||
1467 | * @param cls handle to the iteration | 1479 | * @param cls handle to the iteration |
1468 | */ | 1480 | */ |
1469 | static void | 1481 | static void |
1470 | collect_tickets_finished_cb (void *cls) | 1482 | collect_tickets_finished_cb(void *cls) |
1471 | { | 1483 | { |
1472 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 1484 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
1485 | |||
1473 | iter->ns_it = NULL; | 1486 | iter->ns_it = NULL; |
1474 | iter->cb (iter->cb_cls, NULL); | 1487 | iter->cb(iter->cb_cls, NULL); |
1475 | cleanup_iter (iter); | 1488 | cleanup_iter(iter); |
1476 | } | 1489 | } |
1477 | 1490 | ||
1478 | 1491 | ||
@@ -1482,12 +1495,13 @@ collect_tickets_finished_cb (void *cls) | |||
1482 | * @param cls the iteration handle | 1495 | * @param cls the iteration handle |
1483 | */ | 1496 | */ |
1484 | static void | 1497 | static void |
1485 | collect_tickets_error_cb (void *cls) | 1498 | collect_tickets_error_cb(void *cls) |
1486 | { | 1499 | { |
1487 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 1500 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
1501 | |||
1488 | iter->ns_it = NULL; | 1502 | iter->ns_it = NULL; |
1489 | iter->cb (iter->cb_cls, NULL); | 1503 | iter->cb(iter->cb_cls, NULL); |
1490 | cleanup_iter (iter); | 1504 | cleanup_iter(iter); |
1491 | } | 1505 | } |
1492 | 1506 | ||
1493 | 1507 | ||
@@ -1497,9 +1511,9 @@ collect_tickets_error_cb (void *cls) | |||
1497 | * @param iter the iteration to continue | 1511 | * @param iter the iteration to continue |
1498 | */ | 1512 | */ |
1499 | void | 1513 | void |
1500 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) | 1514 | RECLAIM_TICKETS_iteration_next(struct RECLAIM_TICKETS_Iterator *iter) |
1501 | { | 1515 | { |
1502 | GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1); | 1516 | GNUNET_NAMESTORE_zone_iterator_next(iter->ns_it, 1); |
1503 | } | 1517 | } |
1504 | 1518 | ||
1505 | 1519 | ||
@@ -1509,10 +1523,10 @@ RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) | |||
1509 | * @param iter iteration to cancel | 1523 | * @param iter iteration to cancel |
1510 | */ | 1524 | */ |
1511 | void | 1525 | void |
1512 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | 1526 | RECLAIM_TICKETS_iteration_stop(struct RECLAIM_TICKETS_Iterator *iter) |
1513 | { | 1527 | { |
1514 | GNUNET_NAMESTORE_zone_iteration_stop (iter->ns_it); | 1528 | GNUNET_NAMESTORE_zone_iteration_stop(iter->ns_it); |
1515 | cleanup_iter (iter); | 1529 | cleanup_iter(iter); |
1516 | } | 1530 | } |
1517 | 1531 | ||
1518 | 1532 | ||
@@ -1525,25 +1539,25 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | |||
1525 | * @return a handle to the iteration | 1539 | * @return a handle to the iteration |
1526 | */ | 1540 | */ |
1527 | struct RECLAIM_TICKETS_Iterator * | 1541 | struct RECLAIM_TICKETS_Iterator * |
1528 | RECLAIM_TICKETS_iteration_start ( | 1542 | RECLAIM_TICKETS_iteration_start( |
1529 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1543 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1530 | RECLAIM_TICKETS_TicketIter cb, | 1544 | RECLAIM_TICKETS_TicketIter cb, |
1531 | void *cb_cls) | 1545 | void *cb_cls) |
1532 | { | 1546 | { |
1533 | struct RECLAIM_TICKETS_Iterator *iter; | 1547 | struct RECLAIM_TICKETS_Iterator *iter; |
1534 | 1548 | ||
1535 | iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator); | 1549 | iter = GNUNET_new(struct RECLAIM_TICKETS_Iterator); |
1536 | iter->cb = cb; | 1550 | iter->cb = cb; |
1537 | iter->cb_cls = cb_cls; | 1551 | iter->cb_cls = cb_cls; |
1538 | iter->ns_it = | 1552 | iter->ns_it = |
1539 | GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1553 | GNUNET_NAMESTORE_zone_iteration_start(nsh, |
1540 | identity, | 1554 | identity, |
1541 | &collect_tickets_error_cb, | 1555 | &collect_tickets_error_cb, |
1542 | iter, | 1556 | iter, |
1543 | &collect_tickets_cb, | 1557 | &collect_tickets_cb, |
1544 | iter, | 1558 | iter, |
1545 | &collect_tickets_finished_cb, | 1559 | &collect_tickets_finished_cb, |
1546 | iter); | 1560 | iter); |
1547 | return iter; | 1561 | return iter; |
1548 | } | 1562 | } |
1549 | 1563 | ||
@@ -1555,39 +1569,39 @@ RECLAIM_TICKETS_iteration_start ( | |||
1555 | * @return GNUNET_SYSERR on error | 1569 | * @return GNUNET_SYSERR on error |
1556 | */ | 1570 | */ |
1557 | int | 1571 | int |
1558 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | 1572 | RECLAIM_TICKETS_init(const struct GNUNET_CONFIGURATION_Handle *c) |
1559 | { | 1573 | { |
1560 | // Get ticket expiration time (relative) from config | 1574 | // Get ticket expiration time (relative) from config |
1561 | if (GNUNET_OK == | 1575 | if (GNUNET_OK == |
1562 | GNUNET_CONFIGURATION_get_value_time (c, | 1576 | GNUNET_CONFIGURATION_get_value_time(c, |
1563 | "reclaim", | 1577 | "reclaim", |
1564 | "TICKET_REFRESH_INTERVAL", | 1578 | "TICKET_REFRESH_INTERVAL", |
1565 | &ticket_refresh_interval)) | 1579 | &ticket_refresh_interval)) |
1566 | { | 1580 | { |
1567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1581 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1568 | "Configured refresh interval for tickets: %s\n", | 1582 | "Configured refresh interval for tickets: %s\n", |
1569 | GNUNET_STRINGS_relative_time_to_string (ticket_refresh_interval, | 1583 | GNUNET_STRINGS_relative_time_to_string(ticket_refresh_interval, |
1570 | GNUNET_YES)); | 1584 | GNUNET_YES)); |
1571 | } | 1585 | } |
1572 | else | 1586 | else |
1573 | { | 1587 | { |
1574 | ticket_refresh_interval = DEFAULT_TICKET_REFRESH_INTERVAL; | 1588 | ticket_refresh_interval = DEFAULT_TICKET_REFRESH_INTERVAL; |
1575 | } | 1589 | } |
1576 | // Connect to identity and namestore services | 1590 | // Connect to identity and namestore services |
1577 | nsh = GNUNET_NAMESTORE_connect (c); | 1591 | nsh = GNUNET_NAMESTORE_connect(c); |
1578 | if (NULL == nsh) | 1592 | if (NULL == nsh) |
1579 | { | 1593 | { |
1580 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 1594 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
1581 | "error connecting to namestore"); | 1595 | "error connecting to namestore"); |
1582 | return GNUNET_SYSERR; | 1596 | return GNUNET_SYSERR; |
1583 | } | 1597 | } |
1584 | gns = GNUNET_GNS_connect (c); | 1598 | gns = GNUNET_GNS_connect(c); |
1585 | if (NULL == gns) | 1599 | if (NULL == gns) |
1586 | { | 1600 | { |
1587 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); | 1601 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); |
1588 | return GNUNET_SYSERR; | 1602 | return GNUNET_SYSERR; |
1589 | } | 1603 | } |
1590 | stats = GNUNET_STATISTICS_create ("reclaim", c); | 1604 | stats = GNUNET_STATISTICS_create("reclaim", c); |
1591 | return GNUNET_OK; | 1605 | return GNUNET_OK; |
1592 | } | 1606 | } |
1593 | 1607 | ||
@@ -1597,17 +1611,17 @@ RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1597 | * FIXME: cancel all pending operations (gns, ns etc) | 1611 | * FIXME: cancel all pending operations (gns, ns etc) |
1598 | */ | 1612 | */ |
1599 | void | 1613 | void |
1600 | RECLAIM_TICKETS_deinit (void) | 1614 | RECLAIM_TICKETS_deinit(void) |
1601 | { | 1615 | { |
1602 | if (NULL != nsh) | 1616 | if (NULL != nsh) |
1603 | GNUNET_NAMESTORE_disconnect (nsh); | 1617 | GNUNET_NAMESTORE_disconnect(nsh); |
1604 | nsh = NULL; | 1618 | nsh = NULL; |
1605 | if (NULL != gns) | 1619 | if (NULL != gns) |
1606 | GNUNET_GNS_disconnect (gns); | 1620 | GNUNET_GNS_disconnect(gns); |
1607 | gns = NULL; | 1621 | gns = NULL; |
1608 | if (NULL != stats) | 1622 | if (NULL != stats) |
1609 | { | 1623 | { |
1610 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1624 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
1611 | stats = NULL; | 1625 | stats = NULL; |
1612 | } | 1626 | } |
1613 | } | 1627 | } |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 05f834b1e..20a7a8e6f 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Martin Schanzenbach | 22 | * @author Martin Schanzenbach |
@@ -63,8 +63,7 @@ struct RECLAIM_TICKETS_RevokeHandle; | |||
63 | /** | 63 | /** |
64 | * List of tickets | 64 | * List of tickets |
65 | */ | 65 | */ |
66 | struct TicketRecordsEntry | 66 | struct TicketRecordsEntry { |
67 | { | ||
68 | /** | 67 | /** |
69 | * DLL | 68 | * DLL |
70 | */ | 69 | */ |
@@ -162,10 +161,10 @@ typedef void (*RECLAIM_TICKETS_RevokeCallback) (void *cls, int32_t success); | |||
162 | * @return handle to the operation | 161 | * @return handle to the operation |
163 | */ | 162 | */ |
164 | struct RECLAIM_TICKETS_RevokeHandle * | 163 | struct RECLAIM_TICKETS_RevokeHandle * |
165 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 164 | RECLAIM_TICKETS_revoke(const struct GNUNET_RECLAIM_Ticket *ticket, |
166 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 165 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
167 | RECLAIM_TICKETS_RevokeCallback cb, | 166 | RECLAIM_TICKETS_RevokeCallback cb, |
168 | void *cb_cls); | 167 | void *cb_cls); |
169 | 168 | ||
170 | 169 | ||
171 | /** | 170 | /** |
@@ -174,7 +173,7 @@ RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
174 | * @param rh handle to the operation | 173 | * @param rh handle to the operation |
175 | */ | 174 | */ |
176 | void | 175 | void |
177 | RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh); | 176 | RECLAIM_TICKETS_revoke_cancel(struct RECLAIM_TICKETS_RevokeHandle *rh); |
178 | 177 | ||
179 | 178 | ||
180 | /** | 179 | /** |
@@ -189,10 +188,10 @@ RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh); | |||
189 | * @return handle to the operation | 188 | * @return handle to the operation |
190 | */ | 189 | */ |
191 | struct RECLAIM_TICKETS_ConsumeHandle * | 190 | struct RECLAIM_TICKETS_ConsumeHandle * |
192 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 191 | RECLAIM_TICKETS_consume(const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
193 | const struct GNUNET_RECLAIM_Ticket *ticket, | 192 | const struct GNUNET_RECLAIM_Ticket *ticket, |
194 | RECLAIM_TICKETS_ConsumeCallback cb, | 193 | RECLAIM_TICKETS_ConsumeCallback cb, |
195 | void *cb_cls); | 194 | void *cb_cls); |
196 | 195 | ||
197 | 196 | ||
198 | /** | 197 | /** |
@@ -201,7 +200,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
201 | * @param cth the operation to cancel | 200 | * @param cth the operation to cancel |
202 | */ | 201 | */ |
203 | void | 202 | void |
204 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); | 203 | RECLAIM_TICKETS_consume_cancel(struct RECLAIM_TICKETS_ConsumeHandle *cth); |
205 | 204 | ||
206 | 205 | ||
207 | /** | 206 | /** |
@@ -216,11 +215,11 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); | |||
216 | * FIXME: Return handle?? | 215 | * FIXME: Return handle?? |
217 | */ | 216 | */ |
218 | void | 217 | void |
219 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 218 | RECLAIM_TICKETS_issue(const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
220 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 219 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
221 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 220 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
222 | RECLAIM_TICKETS_TicketResult cb, | 221 | RECLAIM_TICKETS_TicketResult cb, |
223 | void *cb_cls); | 222 | void *cb_cls); |
224 | 223 | ||
225 | 224 | ||
226 | /** | 225 | /** |
@@ -229,7 +228,7 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
229 | * @param iter the iteration to continue | 228 | * @param iter the iteration to continue |
230 | */ | 229 | */ |
231 | void | 230 | void |
232 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); | 231 | RECLAIM_TICKETS_iteration_next(struct RECLAIM_TICKETS_Iterator *iter); |
233 | 232 | ||
234 | 233 | ||
235 | /** | 234 | /** |
@@ -238,7 +237,7 @@ RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter); | |||
238 | * @param iter iteration to cancel | 237 | * @param iter iteration to cancel |
239 | */ | 238 | */ |
240 | void | 239 | void |
241 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); | 240 | RECLAIM_TICKETS_iteration_stop(struct RECLAIM_TICKETS_Iterator *iter); |
242 | 241 | ||
243 | 242 | ||
244 | /** | 243 | /** |
@@ -250,7 +249,7 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); | |||
250 | * @return a handle to the iteration | 249 | * @return a handle to the iteration |
251 | */ | 250 | */ |
252 | struct RECLAIM_TICKETS_Iterator * | 251 | struct RECLAIM_TICKETS_Iterator * |
253 | RECLAIM_TICKETS_iteration_start ( | 252 | RECLAIM_TICKETS_iteration_start( |
254 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 253 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
255 | RECLAIM_TICKETS_TicketIter cb, | 254 | RECLAIM_TICKETS_TicketIter cb, |
256 | void *cb_cls); | 255 | void *cb_cls); |
@@ -263,7 +262,7 @@ RECLAIM_TICKETS_iteration_start ( | |||
263 | * @return GNUNET_SYSERR on error | 262 | * @return GNUNET_SYSERR on error |
264 | */ | 263 | */ |
265 | int | 264 | int |
266 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); | 265 | RECLAIM_TICKETS_init(const struct GNUNET_CONFIGURATION_Handle *c); |
267 | 266 | ||
268 | 267 | ||
269 | /** | 268 | /** |
@@ -271,6 +270,6 @@ RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c); | |||
271 | * FIXME: cancel all pending operations (gns, ns etc) | 270 | * FIXME: cancel all pending operations (gns, ns etc) |
272 | */ | 271 | */ |
273 | void | 272 | void |
274 | RECLAIM_TICKETS_deinit (void); | 273 | RECLAIM_TICKETS_deinit(void); |
275 | 274 | ||
276 | #endif | 275 | #endif |
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 557caafe2..a98dec717 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rest-plugins/json_reclaim.c | 22 | * @file rest-plugins/json_reclaim.c |
@@ -41,7 +41,7 @@ | |||
41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
42 | */ | 42 | */ |
43 | static int | 43 | static int |
44 | parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 44 | parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
45 | { | 45 | { |
46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
47 | const char *name_str = NULL; | 47 | const char *name_str = NULL; |
@@ -53,52 +53,52 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
53 | uint32_t type; | 53 | uint32_t type; |
54 | size_t data_size; | 54 | size_t data_size; |
55 | 55 | ||
56 | GNUNET_assert (NULL != root); | 56 | GNUNET_assert(NULL != root); |
57 | 57 | ||
58 | if (! json_is_object (root)) | 58 | if (!json_is_object(root)) |
59 | { | 59 | { |
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 60 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
61 | "Error json is not array nor object!\n"); | 61 | "Error json is not array nor object!\n"); |
62 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
63 | } | 63 | } |
64 | // interpret single attribute | 64 | // interpret single attribute |
65 | unpack_state = json_unpack (root, | 65 | unpack_state = json_unpack(root, |
66 | "{s:s, s?s, s:s, s:s!}", | 66 | "{s:s, s?s, s:s, s:s!}", |
67 | "name", | 67 | "name", |
68 | &name_str, | 68 | &name_str, |
69 | "id", | 69 | "id", |
70 | &id_str, | 70 | &id_str, |
71 | "type", | 71 | "type", |
72 | &type_str, | 72 | &type_str, |
73 | "value", | 73 | "value", |
74 | &val_str); | 74 | &val_str); |
75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || |
76 | (NULL == type_str)) | 76 | (NULL == type_str)) |
77 | { | 77 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
79 | "Error json object has a wrong format!\n"); | 79 | "Error json object has a wrong format!\n"); |
80 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
81 | } | 81 | } |
82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); |
83 | if (GNUNET_SYSERR == | 83 | if (GNUNET_SYSERR == |
84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, |
85 | val_str, | 85 | val_str, |
86 | (void **) &data, | 86 | (void **)&data, |
87 | &data_size))) | 87 | &data_size))) |
88 | { | 88 | { |
89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
90 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
91 | } | 91 | } |
92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); | 92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new(name_str, type, data, data_size); |
93 | if ((NULL == id_str) || (0 == strlen (id_str))) | 93 | if ((NULL == id_str) || (0 == strlen(id_str))) |
94 | attr->id = 0; | 94 | attr->id = 0; |
95 | else | 95 | else |
96 | GNUNET_STRINGS_string_to_data (id_str, | 96 | GNUNET_STRINGS_string_to_data(id_str, |
97 | strlen (id_str), | 97 | strlen(id_str), |
98 | &attr->id, | 98 | &attr->id, |
99 | sizeof (uint64_t)); | 99 | sizeof(uint64_t)); |
100 | 100 | ||
101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; | 101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr; |
102 | return GNUNET_OK; | 102 | return GNUNET_OK; |
103 | } | 103 | } |
104 | 104 | ||
@@ -109,15 +109,16 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
109 | * @param[out] spec where to free the data | 109 | * @param[out] spec where to free the data |
110 | */ | 110 | */ |
111 | static void | 111 | static void |
112 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | 112 | clean_attr(void *cls, struct GNUNET_JSON_Specification *spec) |
113 | { | 113 | { |
114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; |
115 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; | 115 | |
116 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr; | ||
116 | if (NULL != *attr) | 117 | if (NULL != *attr) |
117 | { | 118 | { |
118 | GNUNET_free (*attr); | 119 | GNUNET_free(*attr); |
119 | *attr = NULL; | 120 | *attr = NULL; |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | /** | 124 | /** |
@@ -127,15 +128,16 @@ clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | |||
127 | * @return JSON Specification | 128 | * @return JSON Specification |
128 | */ | 129 | */ |
129 | struct GNUNET_JSON_Specification | 130 | struct GNUNET_JSON_Specification |
130 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 131 | GNUNET_RECLAIM_JSON_spec_claim(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) |
131 | { | 132 | { |
132 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, | 133 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, |
133 | .cleaner = &clean_attr, | 134 | .cleaner = &clean_attr, |
134 | .cls = NULL, | 135 | .cls = NULL, |
135 | .field = NULL, | 136 | .field = NULL, |
136 | .ptr = attr, | 137 | .ptr = attr, |
137 | .ptr_size = 0, | 138 | .ptr_size = 0, |
138 | .size_ptr = NULL}; | 139 | .size_ptr = NULL }; |
140 | |||
139 | *attr = NULL; | 141 | *attr = NULL; |
140 | return ret; | 142 | return ret; |
141 | } | 143 | } |
@@ -148,7 +150,7 @@ GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | |||
148 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 150 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
149 | */ | 151 | */ |
150 | static int | 152 | static int |
151 | parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 153 | parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
152 | { | 154 | { |
153 | struct GNUNET_RECLAIM_Ticket *ticket; | 155 | struct GNUNET_RECLAIM_Ticket *ticket; |
154 | const char *rnd_str; | 156 | const char *rnd_str; |
@@ -156,63 +158,63 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
156 | const char *id_str; | 158 | const char *id_str; |
157 | int unpack_state; | 159 | int unpack_state; |
158 | 160 | ||
159 | GNUNET_assert (NULL != root); | 161 | GNUNET_assert(NULL != root); |
160 | 162 | ||
161 | if (! json_is_object (root)) | 163 | if (!json_is_object(root)) |
162 | { | 164 | { |
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 165 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
164 | "Error json is not array nor object!\n"); | 166 | "Error json is not array nor object!\n"); |
165 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
166 | } | 168 | } |
167 | // interpret single ticket | 169 | // interpret single ticket |
168 | unpack_state = json_unpack (root, | 170 | unpack_state = json_unpack(root, |
169 | "{s:s, s:s, s:s!}", | 171 | "{s:s, s:s, s:s!}", |
170 | "rnd", | 172 | "rnd", |
171 | &rnd_str, | 173 | &rnd_str, |
172 | "audience", | 174 | "audience", |
173 | &aud_str, | 175 | &aud_str, |
174 | "issuer", | 176 | "issuer", |
175 | &id_str); | 177 | &id_str); |
176 | if (0 != unpack_state) | 178 | if (0 != unpack_state) |
177 | { | 179 | { |
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
179 | "Error json object has a wrong format!\n"); | 181 | "Error json object has a wrong format!\n"); |
180 | return GNUNET_SYSERR; | 182 | return GNUNET_SYSERR; |
181 | } | 183 | } |
182 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 184 | ticket = GNUNET_new(struct GNUNET_RECLAIM_Ticket); |
183 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, | 185 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data(rnd_str, |
184 | strlen (rnd_str), | 186 | strlen(rnd_str), |
185 | &ticket->rnd, | 187 | &ticket->rnd, |
186 | sizeof (uint64_t))) | 188 | sizeof(uint64_t))) |
187 | { | 189 | { |
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); | 190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); |
189 | GNUNET_free (ticket); | 191 | GNUNET_free(ticket); |
190 | return GNUNET_SYSERR; | 192 | return GNUNET_SYSERR; |
191 | } | 193 | } |
192 | if (GNUNET_OK != | 194 | if (GNUNET_OK != |
193 | GNUNET_STRINGS_string_to_data (id_str, | 195 | GNUNET_STRINGS_string_to_data(id_str, |
194 | strlen (id_str), | 196 | strlen(id_str), |
195 | &ticket->identity, | 197 | &ticket->identity, |
196 | sizeof ( | 198 | sizeof( |
197 | struct GNUNET_CRYPTO_EcdsaPublicKey))) | 199 | struct GNUNET_CRYPTO_EcdsaPublicKey))) |
198 | { | 200 | { |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); | 201 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); |
200 | GNUNET_free (ticket); | 202 | GNUNET_free(ticket); |
201 | return GNUNET_SYSERR; | 203 | return GNUNET_SYSERR; |
202 | } | 204 | } |
203 | 205 | ||
204 | if (GNUNET_OK != | 206 | if (GNUNET_OK != |
205 | GNUNET_STRINGS_string_to_data (aud_str, | 207 | GNUNET_STRINGS_string_to_data(aud_str, |
206 | strlen (aud_str), | 208 | strlen(aud_str), |
207 | &ticket->audience, | 209 | &ticket->audience, |
208 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 210 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
209 | { | 211 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); | 212 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); |
211 | GNUNET_free (ticket); | 213 | GNUNET_free(ticket); |
212 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
213 | } | 215 | } |
214 | 216 | ||
215 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; | 217 | *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket; |
216 | return GNUNET_OK; | 218 | return GNUNET_OK; |
217 | } | 219 | } |
218 | 220 | ||
@@ -223,15 +225,16 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
223 | * @param[out] spec where to free the data | 225 | * @param[out] spec where to free the data |
224 | */ | 226 | */ |
225 | static void | 227 | static void |
226 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | 228 | clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec) |
227 | { | 229 | { |
228 | struct GNUNET_RECLAIM_Ticket **ticket; | 230 | struct GNUNET_RECLAIM_Ticket **ticket; |
229 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; | 231 | |
232 | ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr; | ||
230 | if (NULL != *ticket) | 233 | if (NULL != *ticket) |
231 | { | 234 | { |
232 | GNUNET_free (*ticket); | 235 | GNUNET_free(*ticket); |
233 | *ticket = NULL; | 236 | *ticket = NULL; |
234 | } | 237 | } |
235 | } | 238 | } |
236 | 239 | ||
237 | /** | 240 | /** |
@@ -241,15 +244,16 @@ clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | |||
241 | * @return JSON Specification | 244 | * @return JSON Specification |
242 | */ | 245 | */ |
243 | struct GNUNET_JSON_Specification | 246 | struct GNUNET_JSON_Specification |
244 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | 247 | GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket) |
245 | { | 248 | { |
246 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, | 249 | struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket, |
247 | .cleaner = &clean_ticket, | 250 | .cleaner = &clean_ticket, |
248 | .cls = NULL, | 251 | .cls = NULL, |
249 | .field = NULL, | 252 | .field = NULL, |
250 | .ptr = ticket, | 253 | .ptr = ticket, |
251 | .ptr_size = 0, | 254 | .ptr_size = 0, |
252 | .size_ptr = NULL}; | 255 | .size_ptr = NULL }; |
256 | |||
253 | *ticket = NULL; | 257 | *ticket = NULL; |
254 | return ret; | 258 | return ret; |
255 | } | 259 | } |
diff --git a/src/reclaim/json_reclaim.h b/src/reclaim/json_reclaim.h index 36221ccb4..28db6937e 100644 --- a/src/reclaim/json_reclaim.h +++ b/src/reclaim/json_reclaim.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rest-plugins/json_reclaim.h | 22 | * @file rest-plugins/json_reclaim.h |
@@ -36,7 +36,7 @@ | |||
36 | * @return JSON Specification | 36 | * @return JSON Specification |
37 | */ | 37 | */ |
38 | struct GNUNET_JSON_Specification | 38 | struct GNUNET_JSON_Specification |
39 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr); | 39 | GNUNET_RECLAIM_JSON_spec_claim(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * JSON Specification for Reclaim tickets. | 42 | * JSON Specification for Reclaim tickets. |
@@ -45,4 +45,4 @@ GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr); | |||
45 | * @return JSON Specification | 45 | * @return JSON Specification |
46 | */ | 46 | */ |
47 | struct GNUNET_JSON_Specification | 47 | struct GNUNET_JSON_Specification |
48 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket); | 48 | GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket); |
diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h index 10e43ea27..46bd804e7 100644 --- a/src/reclaim/oidc_helper.h +++ b/src/reclaim/oidc_helper.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file reclaim/oidc_helper.h | 22 | * @file reclaim/oidc_helper.h |
@@ -49,12 +49,12 @@ | |||
49 | * @return a new base64-encoded JWT string. | 49 | * @return a new base64-encoded JWT string. |
50 | */ | 50 | */ |
51 | char* | 51 | char* |
52 | OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | 52 | OIDC_id_token_new(const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, |
53 | const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 53 | const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, |
54 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 54 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
55 | const struct GNUNET_TIME_Relative *expiration_time, | 55 | const struct GNUNET_TIME_Relative *expiration_time, |
56 | const char *nonce, | 56 | const char *nonce, |
57 | const char *secret_key); | 57 | const char *secret_key); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Builds an OIDC authorization code including | 60 | * Builds an OIDC authorization code including |
@@ -68,11 +68,11 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | |||
68 | * @return a new authorization code (caller must free) | 68 | * @return a new authorization code (caller must free) |
69 | */ | 69 | */ |
70 | char* | 70 | char* |
71 | OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 71 | OIDC_build_authz_code(const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, |
72 | const struct GNUNET_RECLAIM_Ticket *ticket, | 72 | const struct GNUNET_RECLAIM_Ticket *ticket, |
73 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 73 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
74 | const char *nonce, | 74 | const char *nonce, |
75 | const char *code_challenge); | 75 | const char *code_challenge); |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Parse reclaim ticket and nonce from | 78 | * Parse reclaim ticket and nonce from |
@@ -88,12 +88,12 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
88 | * @return GNUNET_OK if successful, else GNUNET_SYSERR | 88 | * @return GNUNET_OK if successful, else GNUNET_SYSERR |
89 | */ | 89 | */ |
90 | int | 90 | int |
91 | OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, | 91 | OIDC_parse_authz_code(const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, |
92 | const char *code, | 92 | const char *code, |
93 | const char *code_verifier, | 93 | const char *code_verifier, |
94 | struct GNUNET_RECLAIM_Ticket *ticket, | 94 | struct GNUNET_RECLAIM_Ticket *ticket, |
95 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList **attrs, | 95 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList **attrs, |
96 | char **nonce); | 96 | char **nonce); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Build a token response for a token request | 99 | * Build a token response for a token request |
@@ -105,15 +105,15 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv, | |||
105 | * @param token_response where to store the response | 105 | * @param token_response where to store the response |
106 | */ | 106 | */ |
107 | void | 107 | void |
108 | OIDC_build_token_response (const char *access_token, | 108 | OIDC_build_token_response(const char *access_token, |
109 | const char *id_token, | 109 | const char *id_token, |
110 | const struct GNUNET_TIME_Relative *expiration_time, | 110 | const struct GNUNET_TIME_Relative *expiration_time, |
111 | char **token_response); | 111 | char **token_response); |
112 | /** | 112 | /** |
113 | * Generate a new access token | 113 | * Generate a new access token |
114 | */ | 114 | */ |
115 | char* | 115 | char* |
116 | OIDC_access_token_new (); | 116 | OIDC_access_token_new(); |
117 | 117 | ||
118 | 118 | ||
119 | #endif | 119 | #endif |
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 48cdd9811..708142774 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file reclaim/plugin_gnsrecord_reclaim.c | 22 | * @file reclaim/plugin_gnsrecord_reclaim.c |
@@ -40,21 +40,25 @@ | |||
40 | * @return NULL on error, otherwise human-readable representation of the value | 40 | * @return NULL on error, otherwise human-readable representation of the value |
41 | */ | 41 | */ |
42 | static char * | 42 | static char * |
43 | value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) | 43 | value_to_string(void *cls, uint32_t type, const void *data, size_t data_size) |
44 | { | 44 | { |
45 | switch (type) { | 45 | switch (type) |
46 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 46 | { |
47 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 47 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
48 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 48 | return GNUNET_STRINGS_data_to_string_alloc(data, data_size); |
49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 49 | |
50 | return GNUNET_strndup (data, data_size); | 50 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: | 51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 52 | return GNUNET_strndup(data, data_size); |
53 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 53 | |
54 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 54 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
55 | default: | 55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
56 | return NULL; | 56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
57 | } | 57 | return GNUNET_STRINGS_data_to_string_alloc(data, data_size); |
58 | |||
59 | default: | ||
60 | return NULL; | ||
61 | } | ||
58 | } | 62 | } |
59 | 63 | ||
60 | 64 | ||
@@ -70,26 +74,30 @@ value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) | |||
70 | * @return #GNUNET_OK on success | 74 | * @return #GNUNET_OK on success |
71 | */ | 75 | */ |
72 | static int | 76 | static int |
73 | string_to_value (void *cls, uint32_t type, const char *s, void **data, | 77 | string_to_value(void *cls, uint32_t type, const char *s, void **data, |
74 | size_t *data_size) | 78 | size_t *data_size) |
75 | { | 79 | { |
76 | if (NULL == s) | 80 | if (NULL == s) |
77 | return GNUNET_SYSERR; | 81 | return GNUNET_SYSERR; |
78 | switch (type) { | 82 | switch (type) |
79 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 83 | { |
80 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); | 84 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
81 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 85 | return GNUNET_STRINGS_string_to_data(s, strlen(s), *data, *data_size); |
82 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 86 | |
83 | *data = GNUNET_strdup (s); | 87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
84 | *data_size = strlen (s); | 88 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
85 | return GNUNET_OK; | 89 | *data = GNUNET_strdup(s); |
86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: | 90 | *data_size = strlen(s); |
87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 91 | return GNUNET_OK; |
88 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 92 | |
89 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); | 93 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
90 | default: | 94 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
91 | return GNUNET_SYSERR; | 95 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
92 | } | 96 | return GNUNET_STRINGS_string_to_data(s, strlen(s), *data, *data_size); |
97 | |||
98 | default: | ||
99 | return GNUNET_SYSERR; | ||
100 | } | ||
93 | } | 101 | } |
94 | 102 | ||
95 | 103 | ||
@@ -101,13 +109,14 @@ static struct { | |||
101 | const char *name; | 109 | const char *name; |
102 | uint32_t number; | 110 | uint32_t number; |
103 | } name_map[] = { | 111 | } name_map[] = { |
104 | {"RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR}, | 112 | { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, |
105 | {"RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF}, | 113 | { "RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF }, |
106 | {"RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER}, | 114 | { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, |
107 | {"RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT}, | 115 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, |
108 | {"RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT}, | 116 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, |
109 | {"RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET}, | 117 | { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET }, |
110 | {NULL, UINT32_MAX}}; | 118 | { NULL, UINT32_MAX } |
119 | }; | ||
111 | 120 | ||
112 | 121 | ||
113 | /** | 122 | /** |
@@ -118,13 +127,13 @@ static struct { | |||
118 | * @return corresponding number, UINT32_MAX on error | 127 | * @return corresponding number, UINT32_MAX on error |
119 | */ | 128 | */ |
120 | static uint32_t | 129 | static uint32_t |
121 | typename_to_number (void *cls, const char *dns_typename) | 130 | typename_to_number(void *cls, const char *dns_typename) |
122 | { | 131 | { |
123 | unsigned int i; | 132 | unsigned int i; |
124 | 133 | ||
125 | i = 0; | 134 | i = 0; |
126 | while ((NULL != name_map[i].name) && | 135 | while ((NULL != name_map[i].name) && |
127 | (0 != strcasecmp (dns_typename, name_map[i].name))) | 136 | (0 != strcasecmp(dns_typename, name_map[i].name))) |
128 | i++; | 137 | i++; |
129 | return name_map[i].number; | 138 | return name_map[i].number; |
130 | } | 139 | } |
@@ -138,7 +147,7 @@ typename_to_number (void *cls, const char *dns_typename) | |||
138 | * @return corresponding typestring, NULL on error | 147 | * @return corresponding typestring, NULL on error |
139 | */ | 148 | */ |
140 | static const char * | 149 | static const char * |
141 | number_to_typename (void *cls, uint32_t type) | 150 | number_to_typename(void *cls, uint32_t type) |
142 | { | 151 | { |
143 | unsigned int i; | 152 | unsigned int i; |
144 | 153 | ||
@@ -156,11 +165,11 @@ number_to_typename (void *cls, uint32_t type) | |||
156 | * @return the exported block API | 165 | * @return the exported block API |
157 | */ | 166 | */ |
158 | void * | 167 | void * |
159 | libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | 168 | libgnunet_plugin_gnsrecord_reclaim_init(void *cls) |
160 | { | 169 | { |
161 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 170 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
162 | 171 | ||
163 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); | 172 | api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); |
164 | api->value_to_string = &value_to_string; | 173 | api->value_to_string = &value_to_string; |
165 | api->string_to_value = &string_to_value; | 174 | api->string_to_value = &string_to_value; |
166 | api->typename_to_number = &typename_to_number; | 175 | api->typename_to_number = &typename_to_number; |
@@ -176,11 +185,11 @@ libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | |||
176 | * @return NULL | 185 | * @return NULL |
177 | */ | 186 | */ |
178 | void * | 187 | void * |
179 | libgnunet_plugin_gnsrecord_reclaim_done (void *cls) | 188 | libgnunet_plugin_gnsrecord_reclaim_done(void *cls) |
180 | { | 189 | { |
181 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 190 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
182 | 191 | ||
183 | GNUNET_free (api); | 192 | GNUNET_free(api); |
184 | return NULL; | 193 | return NULL; |
185 | } | 194 | } |
186 | 195 | ||
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index bf1e950da..3f1dba254 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @author Philippe Buschmann | 22 | * @author Philippe Buschmann |
@@ -218,13 +218,13 @@ | |||
218 | /** | 218 | /** |
219 | * OIDC ignored parameter array | 219 | * OIDC ignored parameter array |
220 | */ | 220 | */ |
221 | static char *OIDC_ignored_parameter_array[] = {"display", | 221 | static char *OIDC_ignored_parameter_array[] = { "display", |
222 | "prompt", | 222 | "prompt", |
223 | "ui_locales", | 223 | "ui_locales", |
224 | "response_mode", | 224 | "response_mode", |
225 | "id_token_hint", | 225 | "id_token_hint", |
226 | "login_hint", | 226 | "login_hint", |
227 | "acr_values"}; | 227 | "acr_values" }; |
228 | 228 | ||
229 | /** | 229 | /** |
230 | * OIDC Hash map that keeps track of issued cookies | 230 | * OIDC Hash map that keeps track of issued cookies |
@@ -250,16 +250,14 @@ static char *allow_methods; | |||
250 | /** | 250 | /** |
251 | * @brief struct returned by the initialization function of the plugin | 251 | * @brief struct returned by the initialization function of the plugin |
252 | */ | 252 | */ |
253 | struct Plugin | 253 | struct Plugin { |
254 | { | ||
255 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 254 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
256 | }; | 255 | }; |
257 | 256 | ||
258 | /** | 257 | /** |
259 | * OIDC needed variables | 258 | * OIDC needed variables |
260 | */ | 259 | */ |
261 | struct OIDC_Variables | 260 | struct OIDC_Variables { |
262 | { | ||
263 | /** | 261 | /** |
264 | * The RP client public key | 262 | * The RP client public key |
265 | */ | 263 | */ |
@@ -324,8 +322,7 @@ struct OIDC_Variables | |||
324 | /** | 322 | /** |
325 | * The ego list | 323 | * The ego list |
326 | */ | 324 | */ |
327 | struct EgoEntry | 325 | struct EgoEntry { |
328 | { | ||
329 | /** | 326 | /** |
330 | * DLL | 327 | * DLL |
331 | */ | 328 | */ |
@@ -353,8 +350,7 @@ struct EgoEntry | |||
353 | }; | 350 | }; |
354 | 351 | ||
355 | 352 | ||
356 | struct RequestHandle | 353 | struct RequestHandle { |
357 | { | ||
358 | /** | 354 | /** |
359 | * Ego list | 355 | * Ego list |
360 | */ | 356 | */ |
@@ -511,74 +507,75 @@ struct RequestHandle | |||
511 | * @param handle Handle to clean up | 507 | * @param handle Handle to clean up |
512 | */ | 508 | */ |
513 | static void | 509 | static void |
514 | cleanup_handle (struct RequestHandle *handle) | 510 | cleanup_handle(struct RequestHandle *handle) |
515 | { | 511 | { |
516 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; | 512 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; |
517 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; | 513 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; |
518 | struct EgoEntry *ego_entry; | 514 | struct EgoEntry *ego_entry; |
519 | struct EgoEntry *ego_tmp; | 515 | struct EgoEntry *ego_tmp; |
520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 516 | |
517 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | ||
521 | if (NULL != handle->timeout_task) | 518 | if (NULL != handle->timeout_task) |
522 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 519 | GNUNET_SCHEDULER_cancel(handle->timeout_task); |
523 | if (NULL != handle->identity_handle) | 520 | if (NULL != handle->identity_handle) |
524 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | 521 | GNUNET_IDENTITY_disconnect(handle->identity_handle); |
525 | if (NULL != handle->attr_it) | 522 | if (NULL != handle->attr_it) |
526 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); | 523 | GNUNET_RECLAIM_get_attributes_stop(handle->attr_it); |
527 | if (NULL != handle->ticket_it) | 524 | if (NULL != handle->ticket_it) |
528 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); | 525 | GNUNET_RECLAIM_ticket_iteration_stop(handle->ticket_it); |
529 | if (NULL != handle->idp) | 526 | if (NULL != handle->idp) |
530 | GNUNET_RECLAIM_disconnect (handle->idp); | 527 | GNUNET_RECLAIM_disconnect(handle->idp); |
531 | GNUNET_free_non_null (handle->url); | 528 | GNUNET_free_non_null(handle->url); |
532 | GNUNET_free_non_null (handle->tld); | 529 | GNUNET_free_non_null(handle->tld); |
533 | GNUNET_free_non_null (handle->redirect_prefix); | 530 | GNUNET_free_non_null(handle->redirect_prefix); |
534 | GNUNET_free_non_null (handle->redirect_suffix); | 531 | GNUNET_free_non_null(handle->redirect_suffix); |
535 | GNUNET_free_non_null (handle->emsg); | 532 | GNUNET_free_non_null(handle->emsg); |
536 | GNUNET_free_non_null (handle->edesc); | 533 | GNUNET_free_non_null(handle->edesc); |
537 | if (NULL != handle->gns_op) | 534 | if (NULL != handle->gns_op) |
538 | GNUNET_GNS_lookup_cancel (handle->gns_op); | 535 | GNUNET_GNS_lookup_cancel(handle->gns_op); |
539 | if (NULL != handle->gns_handle) | 536 | if (NULL != handle->gns_handle) |
540 | GNUNET_GNS_disconnect (handle->gns_handle); | 537 | GNUNET_GNS_disconnect(handle->gns_handle); |
541 | 538 | ||
542 | if (NULL != handle->namestore_handle) | 539 | if (NULL != handle->namestore_handle) |
543 | GNUNET_NAMESTORE_disconnect (handle->namestore_handle); | 540 | GNUNET_NAMESTORE_disconnect(handle->namestore_handle); |
544 | if (NULL != handle->oidc) | 541 | if (NULL != handle->oidc) |
545 | { | 542 | { |
546 | GNUNET_free_non_null (handle->oidc->client_id); | 543 | GNUNET_free_non_null(handle->oidc->client_id); |
547 | GNUNET_free_non_null (handle->oidc->login_identity); | 544 | GNUNET_free_non_null(handle->oidc->login_identity); |
548 | GNUNET_free_non_null (handle->oidc->nonce); | 545 | GNUNET_free_non_null(handle->oidc->nonce); |
549 | GNUNET_free_non_null (handle->oidc->redirect_uri); | 546 | GNUNET_free_non_null(handle->oidc->redirect_uri); |
550 | GNUNET_free_non_null (handle->oidc->response_type); | 547 | GNUNET_free_non_null(handle->oidc->response_type); |
551 | GNUNET_free_non_null (handle->oidc->scope); | 548 | GNUNET_free_non_null(handle->oidc->scope); |
552 | GNUNET_free_non_null (handle->oidc->state); | 549 | GNUNET_free_non_null(handle->oidc->state); |
553 | json_decref (handle->oidc->response); | 550 | json_decref(handle->oidc->response); |
554 | GNUNET_free (handle->oidc); | 551 | GNUNET_free(handle->oidc); |
555 | } | 552 | } |
556 | if (NULL != handle->attr_list) | 553 | if (NULL != handle->attr_list) |
557 | { | ||
558 | for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) | ||
559 | { | 554 | { |
560 | claim_tmp = claim_entry; | 555 | for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) |
561 | claim_entry = claim_entry->next; | 556 | { |
562 | GNUNET_free (claim_tmp->claim); | 557 | claim_tmp = claim_entry; |
563 | GNUNET_free (claim_tmp); | 558 | claim_entry = claim_entry->next; |
559 | GNUNET_free(claim_tmp->claim); | ||
560 | GNUNET_free(claim_tmp); | ||
561 | } | ||
562 | GNUNET_free(handle->attr_list); | ||
564 | } | 563 | } |
565 | GNUNET_free (handle->attr_list); | ||
566 | } | ||
567 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 564 | for (ego_entry = handle->ego_head; NULL != ego_entry;) |
568 | { | 565 | { |
569 | ego_tmp = ego_entry; | 566 | ego_tmp = ego_entry; |
570 | ego_entry = ego_entry->next; | 567 | ego_entry = ego_entry->next; |
571 | GNUNET_free (ego_tmp->identifier); | 568 | GNUNET_free(ego_tmp->identifier); |
572 | GNUNET_free (ego_tmp->keystring); | 569 | GNUNET_free(ego_tmp->keystring); |
573 | GNUNET_free (ego_tmp); | 570 | GNUNET_free(ego_tmp); |
574 | } | 571 | } |
575 | GNUNET_free (handle); | 572 | GNUNET_free(handle); |
576 | } | 573 | } |
577 | 574 | ||
578 | static void | 575 | static void |
579 | cleanup_handle_delayed (void *cls) | 576 | cleanup_handle_delayed(void *cls) |
580 | { | 577 | { |
581 | cleanup_handle (cls); | 578 | cleanup_handle(cls); |
582 | } | 579 | } |
583 | 580 | ||
584 | 581 | ||
@@ -588,30 +585,30 @@ cleanup_handle_delayed (void *cls) | |||
588 | * @param cls the `struct RequestHandle` | 585 | * @param cls the `struct RequestHandle` |
589 | */ | 586 | */ |
590 | static void | 587 | static void |
591 | do_error (void *cls) | 588 | do_error(void *cls) |
592 | { | 589 | { |
593 | struct RequestHandle *handle = cls; | 590 | struct RequestHandle *handle = cls; |
594 | struct MHD_Response *resp; | 591 | struct MHD_Response *resp; |
595 | char *json_error; | 592 | char *json_error; |
596 | 593 | ||
597 | GNUNET_asprintf (&json_error, | 594 | GNUNET_asprintf(&json_error, |
598 | "{ \"error\" : \"%s\", \"error_description\" : \"%s\"%s%s%s}", | 595 | "{ \"error\" : \"%s\", \"error_description\" : \"%s\"%s%s%s}", |
599 | handle->emsg, | 596 | handle->emsg, |
600 | (NULL != handle->edesc) ? handle->edesc : "", | 597 | (NULL != handle->edesc) ? handle->edesc : "", |
601 | (NULL != handle->oidc->state) ? ", \"state\":\"" : "", | 598 | (NULL != handle->oidc->state) ? ", \"state\":\"" : "", |
602 | (NULL != handle->oidc->state) ? handle->oidc->state : "", | 599 | (NULL != handle->oidc->state) ? handle->oidc->state : "", |
603 | (NULL != handle->oidc->state) ? "\"" : ""); | 600 | (NULL != handle->oidc->state) ? "\"" : ""); |
604 | if (0 == handle->response_code) | 601 | if (0 == handle->response_code) |
605 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 602 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
606 | resp = GNUNET_REST_create_response (json_error); | 603 | resp = GNUNET_REST_create_response(json_error); |
607 | if (MHD_HTTP_UNAUTHORIZED == handle->response_code) | 604 | if (MHD_HTTP_UNAUTHORIZED == handle->response_code) |
608 | MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic"); | 605 | MHD_add_response_header(resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Basic"); |
609 | MHD_add_response_header (resp, | 606 | MHD_add_response_header(resp, |
610 | MHD_HTTP_HEADER_CONTENT_TYPE, | 607 | MHD_HTTP_HEADER_CONTENT_TYPE, |
611 | "application/json"); | 608 | "application/json"); |
612 | handle->proc (handle->proc_cls, resp, handle->response_code); | 609 | handle->proc(handle->proc_cls, resp, handle->response_code); |
613 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 610 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
614 | GNUNET_free (json_error); | 611 | GNUNET_free(json_error); |
615 | } | 612 | } |
616 | 613 | ||
617 | 614 | ||
@@ -622,21 +619,21 @@ do_error (void *cls) | |||
622 | * @param cls the `struct RequestHandle` | 619 | * @param cls the `struct RequestHandle` |
623 | */ | 620 | */ |
624 | static void | 621 | static void |
625 | do_userinfo_error (void *cls) | 622 | do_userinfo_error(void *cls) |
626 | { | 623 | { |
627 | struct RequestHandle *handle = cls; | 624 | struct RequestHandle *handle = cls; |
628 | struct MHD_Response *resp; | 625 | struct MHD_Response *resp; |
629 | char *error; | 626 | char *error; |
630 | 627 | ||
631 | GNUNET_asprintf (&error, | 628 | GNUNET_asprintf(&error, |
632 | "error=\"%s\", error_description=\"%s\"", | 629 | "error=\"%s\", error_description=\"%s\"", |
633 | handle->emsg, | 630 | handle->emsg, |
634 | (NULL != handle->edesc) ? handle->edesc : ""); | 631 | (NULL != handle->edesc) ? handle->edesc : ""); |
635 | resp = GNUNET_REST_create_response (""); | 632 | resp = GNUNET_REST_create_response(""); |
636 | MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer"); | 633 | MHD_add_response_header(resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer"); |
637 | handle->proc (handle->proc_cls, resp, handle->response_code); | 634 | handle->proc(handle->proc_cls, resp, handle->response_code); |
638 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 635 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
639 | GNUNET_free (error); | 636 | GNUNET_free(error); |
640 | } | 637 | } |
641 | 638 | ||
642 | 639 | ||
@@ -646,23 +643,24 @@ do_userinfo_error (void *cls) | |||
646 | * @param cls the `struct RequestHandle` | 643 | * @param cls the `struct RequestHandle` |
647 | */ | 644 | */ |
648 | static void | 645 | static void |
649 | do_redirect_error (void *cls) | 646 | do_redirect_error(void *cls) |
650 | { | 647 | { |
651 | struct RequestHandle *handle = cls; | 648 | struct RequestHandle *handle = cls; |
652 | struct MHD_Response *resp; | 649 | struct MHD_Response *resp; |
653 | char *redirect; | 650 | char *redirect; |
654 | GNUNET_asprintf (&redirect, | 651 | |
655 | "%s?error=%s&error_description=%s%s%s", | 652 | GNUNET_asprintf(&redirect, |
656 | handle->oidc->redirect_uri, | 653 | "%s?error=%s&error_description=%s%s%s", |
657 | handle->emsg, | 654 | handle->oidc->redirect_uri, |
658 | handle->edesc, | 655 | handle->emsg, |
659 | (NULL != handle->oidc->state) ? "&state=" : "", | 656 | handle->edesc, |
660 | (NULL != handle->oidc->state) ? handle->oidc->state : ""); | 657 | (NULL != handle->oidc->state) ? "&state=" : "", |
661 | resp = GNUNET_REST_create_response (""); | 658 | (NULL != handle->oidc->state) ? handle->oidc->state : ""); |
662 | MHD_add_response_header (resp, "Location", redirect); | 659 | resp = GNUNET_REST_create_response(""); |
663 | handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); | 660 | MHD_add_response_header(resp, "Location", redirect); |
664 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 661 | handle->proc(handle->proc_cls, resp, MHD_HTTP_FOUND); |
665 | GNUNET_free (redirect); | 662 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
663 | GNUNET_free(redirect); | ||
666 | } | 664 | } |
667 | 665 | ||
668 | /** | 666 | /** |
@@ -671,12 +669,12 @@ do_redirect_error (void *cls) | |||
671 | * @param cls the `struct RequestHandle` | 669 | * @param cls the `struct RequestHandle` |
672 | */ | 670 | */ |
673 | static void | 671 | static void |
674 | do_timeout (void *cls) | 672 | do_timeout(void *cls) |
675 | { | 673 | { |
676 | struct RequestHandle *handle = cls; | 674 | struct RequestHandle *handle = cls; |
677 | 675 | ||
678 | handle->timeout_task = NULL; | 676 | handle->timeout_task = NULL; |
679 | do_error (handle); | 677 | do_error(handle); |
680 | } | 678 | } |
681 | 679 | ||
682 | /** | 680 | /** |
@@ -685,18 +683,18 @@ do_timeout (void *cls) | |||
685 | * @param cls the request handle | 683 | * @param cls the request handle |
686 | */ | 684 | */ |
687 | static void | 685 | static void |
688 | return_userinfo_response (void *cls) | 686 | return_userinfo_response(void *cls) |
689 | { | 687 | { |
690 | char *result_str; | 688 | char *result_str; |
691 | struct RequestHandle *handle = cls; | 689 | struct RequestHandle *handle = cls; |
692 | struct MHD_Response *resp; | 690 | struct MHD_Response *resp; |
693 | 691 | ||
694 | result_str = json_dumps (handle->oidc->response, 0); | 692 | result_str = json_dumps(handle->oidc->response, 0); |
695 | 693 | ||
696 | resp = GNUNET_REST_create_response (result_str); | 694 | resp = GNUNET_REST_create_response(result_str); |
697 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 695 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
698 | GNUNET_free (result_str); | 696 | GNUNET_free(result_str); |
699 | cleanup_handle (handle); | 697 | cleanup_handle(handle); |
700 | } | 698 | } |
701 | 699 | ||
702 | 700 | ||
@@ -708,18 +706,18 @@ return_userinfo_response (void *cls) | |||
708 | * @param cls the RequestHandle | 706 | * @param cls the RequestHandle |
709 | */ | 707 | */ |
710 | static void | 708 | static void |
711 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 709 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, |
712 | const char *url, | 710 | const char *url, |
713 | void *cls) | 711 | void *cls) |
714 | { | 712 | { |
715 | struct MHD_Response *resp; | 713 | struct MHD_Response *resp; |
716 | struct RequestHandle *handle = cls; | 714 | struct RequestHandle *handle = cls; |
717 | 715 | ||
718 | // For now, independent of path return all options | 716 | // For now, independent of path return all options |
719 | resp = GNUNET_REST_create_response (NULL); | 717 | resp = GNUNET_REST_create_response(NULL); |
720 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 718 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); |
721 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 719 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
722 | cleanup_handle (handle); | 720 | cleanup_handle(handle); |
723 | return; | 721 | return; |
724 | } | 722 | } |
725 | 723 | ||
@@ -728,7 +726,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
728 | * Interprets cookie header and pass its identity keystring to handle | 726 | * Interprets cookie header and pass its identity keystring to handle |
729 | */ | 727 | */ |
730 | static void | 728 | static void |
731 | cookie_identity_interpretation (struct RequestHandle *handle) | 729 | cookie_identity_interpretation(struct RequestHandle *handle) |
732 | { | 730 | { |
733 | struct GNUNET_HashCode cache_key; | 731 | struct GNUNET_HashCode cache_key; |
734 | char *cookies; | 732 | char *cookies; |
@@ -739,142 +737,143 @@ cookie_identity_interpretation (struct RequestHandle *handle) | |||
739 | char *value; | 737 | char *value; |
740 | 738 | ||
741 | // gets identity of login try with cookie | 739 | // gets identity of login try with cookie |
742 | GNUNET_CRYPTO_hash (OIDC_COOKIE_HEADER_KEY, | 740 | GNUNET_CRYPTO_hash(OIDC_COOKIE_HEADER_KEY, |
743 | strlen (OIDC_COOKIE_HEADER_KEY), | 741 | strlen(OIDC_COOKIE_HEADER_KEY), |
744 | &cache_key); | 742 | &cache_key); |
745 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 743 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle |
746 | ->header_param_map, | 744 | ->header_param_map, |
747 | &cache_key)) | 745 | &cache_key)) |
748 | { | 746 | { |
749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n"); | 747 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n"); |
750 | return; | 748 | return; |
751 | } | 749 | } |
752 | // splits cookies and find 'Identity' cookie | 750 | // splits cookies and find 'Identity' cookie |
753 | tmp_cookies = | 751 | tmp_cookies = |
754 | GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map, | 752 | GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->header_param_map, |
755 | &cache_key); | 753 | &cache_key); |
756 | cookies = GNUNET_strdup (tmp_cookies); | 754 | cookies = GNUNET_strdup(tmp_cookies); |
757 | token = strtok (cookies, delimiter); | 755 | token = strtok(cookies, delimiter); |
758 | handle->oidc->user_cancelled = GNUNET_NO; | 756 | handle->oidc->user_cancelled = GNUNET_NO; |
759 | handle->oidc->login_identity = NULL; | 757 | handle->oidc->login_identity = NULL; |
760 | if (NULL == token) | 758 | if (NULL == token) |
761 | { | 759 | { |
762 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 760 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
763 | "Unable to parse cookie: %s\n", | 761 | "Unable to parse cookie: %s\n", |
764 | cookies); | 762 | cookies); |
765 | GNUNET_free (cookies); | 763 | GNUNET_free(cookies); |
766 | return; | 764 | return; |
767 | } | 765 | } |
768 | 766 | ||
769 | while (NULL != token) | 767 | while (NULL != token) |
770 | { | ||
771 | if (0 == strcmp (token, OIDC_COOKIE_HEADER_ACCESS_DENIED)) | ||
772 | { | 768 | { |
773 | handle->oidc->user_cancelled = GNUNET_YES; | 769 | if (0 == strcmp(token, OIDC_COOKIE_HEADER_ACCESS_DENIED)) |
774 | GNUNET_free (cookies); | 770 | { |
775 | return; | 771 | handle->oidc->user_cancelled = GNUNET_YES; |
772 | GNUNET_free(cookies); | ||
773 | return; | ||
774 | } | ||
775 | if (NULL != strstr(token, OIDC_COOKIE_HEADER_INFORMATION_KEY)) | ||
776 | break; | ||
777 | token = strtok(NULL, delimiter); | ||
776 | } | 778 | } |
777 | if (NULL != strstr (token, OIDC_COOKIE_HEADER_INFORMATION_KEY)) | ||
778 | break; | ||
779 | token = strtok (NULL, delimiter); | ||
780 | } | ||
781 | if (NULL == token) | 779 | if (NULL == token) |
782 | { | 780 | { |
783 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 781 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
784 | "No cookie value to process: %s\n", | 782 | "No cookie value to process: %s\n", |
785 | cookies); | 783 | cookies); |
786 | GNUNET_free (cookies); | 784 | GNUNET_free(cookies); |
787 | return; | 785 | return; |
788 | } | 786 | } |
789 | GNUNET_CRYPTO_hash (token, strlen (token), &cache_key); | 787 | GNUNET_CRYPTO_hash(token, strlen(token), &cache_key); |
790 | if (GNUNET_NO == | 788 | if (GNUNET_NO == |
791 | GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key)) | 789 | GNUNET_CONTAINER_multihashmap_contains(OIDC_cookie_jar_map, &cache_key)) |
792 | { | 790 | { |
793 | GNUNET_log ( | 791 | GNUNET_log( |
794 | GNUNET_ERROR_TYPE_WARNING, | 792 | GNUNET_ERROR_TYPE_WARNING, |
795 | "Found cookie `%s', but no corresponding expiration entry present...\n", | 793 | "Found cookie `%s', but no corresponding expiration entry present...\n", |
796 | token); | 794 | token); |
797 | GNUNET_free (cookies); | 795 | GNUNET_free(cookies); |
798 | return; | 796 | return; |
799 | } | 797 | } |
800 | relog_time = | 798 | relog_time = |
801 | GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key); | 799 | GNUNET_CONTAINER_multihashmap_get(OIDC_cookie_jar_map, &cache_key); |
802 | current_time = GNUNET_TIME_absolute_get (); | 800 | current_time = GNUNET_TIME_absolute_get(); |
803 | // 30 min after old login -> redirect to login | 801 | // 30 min after old login -> redirect to login |
804 | if (current_time.abs_value_us > relog_time->abs_value_us) | 802 | if (current_time.abs_value_us > relog_time->abs_value_us) |
805 | { | 803 | { |
806 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 804 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
807 | "Found cookie `%s', but it is expired.\n", | 805 | "Found cookie `%s', but it is expired.\n", |
808 | token); | 806 | token); |
809 | GNUNET_free (cookies); | 807 | GNUNET_free(cookies); |
810 | return; | 808 | return; |
811 | } | 809 | } |
812 | value = strtok (token, OIDC_COOKIE_HEADER_INFORMATION_KEY); | 810 | value = strtok(token, OIDC_COOKIE_HEADER_INFORMATION_KEY); |
813 | GNUNET_assert (NULL != value); | 811 | GNUNET_assert(NULL != value); |
814 | handle->oidc->login_identity = GNUNET_strdup (value); | 812 | handle->oidc->login_identity = GNUNET_strdup(value); |
815 | GNUNET_free (cookies); | 813 | GNUNET_free(cookies); |
816 | } | 814 | } |
817 | 815 | ||
818 | /** | 816 | /** |
819 | * Redirects to login page stored in configuration file | 817 | * Redirects to login page stored in configuration file |
820 | */ | 818 | */ |
821 | static void | 819 | static void |
822 | login_redirect (void *cls) | 820 | login_redirect(void *cls) |
823 | { | 821 | { |
824 | char *login_base_url; | 822 | char *login_base_url; |
825 | char *new_redirect; | 823 | char *new_redirect; |
826 | struct MHD_Response *resp; | 824 | struct MHD_Response *resp; |
827 | struct RequestHandle *handle = cls; | 825 | struct RequestHandle *handle = cls; |
828 | 826 | ||
829 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | 827 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, |
830 | "reclaim-rest-plugin", | 828 | "reclaim-rest-plugin", |
831 | "address", | 829 | "address", |
832 | &login_base_url)) | 830 | &login_base_url)) |
833 | { | 831 | { |
834 | GNUNET_asprintf (&new_redirect, | 832 | GNUNET_asprintf(&new_redirect, |
835 | "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", | 833 | "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", |
836 | login_base_url, | 834 | login_base_url, |
837 | OIDC_RESPONSE_TYPE_KEY, | 835 | OIDC_RESPONSE_TYPE_KEY, |
838 | handle->oidc->response_type, | 836 | handle->oidc->response_type, |
839 | OIDC_CLIENT_ID_KEY, | 837 | OIDC_CLIENT_ID_KEY, |
840 | handle->oidc->client_id, | 838 | handle->oidc->client_id, |
841 | OIDC_REDIRECT_URI_KEY, | 839 | OIDC_REDIRECT_URI_KEY, |
842 | handle->oidc->redirect_uri, | 840 | handle->oidc->redirect_uri, |
843 | OIDC_SCOPE_KEY, | 841 | OIDC_SCOPE_KEY, |
844 | handle->oidc->scope, | 842 | handle->oidc->scope, |
845 | OIDC_STATE_KEY, | 843 | OIDC_STATE_KEY, |
846 | (NULL != handle->oidc->state) ? handle->oidc->state : "", | 844 | (NULL != handle->oidc->state) ? handle->oidc->state : "", |
847 | OIDC_CODE_CHALLENGE_KEY, | 845 | OIDC_CODE_CHALLENGE_KEY, |
848 | (NULL != handle->oidc->code_challenge) ? handle->oidc->code_challenge : "", | 846 | (NULL != handle->oidc->code_challenge) ? handle->oidc->code_challenge : "", |
849 | OIDC_NONCE_KEY, | 847 | OIDC_NONCE_KEY, |
850 | (NULL != handle->oidc->nonce) ? handle->oidc->nonce : ""); | 848 | (NULL != handle->oidc->nonce) ? handle->oidc->nonce : ""); |
851 | resp = GNUNET_REST_create_response (""); | 849 | resp = GNUNET_REST_create_response(""); |
852 | MHD_add_response_header (resp, "Location", new_redirect); | 850 | MHD_add_response_header(resp, "Location", new_redirect); |
853 | GNUNET_free (login_base_url); | 851 | GNUNET_free(login_base_url); |
854 | } | 852 | } |
855 | else | 853 | else |
856 | { | 854 | { |
857 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 855 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); |
858 | handle->edesc = GNUNET_strdup ("gnunet configuration failed"); | 856 | handle->edesc = GNUNET_strdup("gnunet configuration failed"); |
859 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 857 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
860 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 858 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
861 | return; | 859 | return; |
862 | } | 860 | } |
863 | handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); | 861 | handle->proc(handle->proc_cls, resp, MHD_HTTP_FOUND); |
864 | GNUNET_free (new_redirect); | 862 | GNUNET_free(new_redirect); |
865 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 863 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
866 | } | 864 | } |
867 | 865 | ||
868 | /** | 866 | /** |
869 | * Does internal server error when iteration failed. | 867 | * Does internal server error when iteration failed. |
870 | */ | 868 | */ |
871 | static void | 869 | static void |
872 | oidc_iteration_error (void *cls) | 870 | oidc_iteration_error(void *cls) |
873 | { | 871 | { |
874 | struct RequestHandle *handle = cls; | 872 | struct RequestHandle *handle = cls; |
875 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 873 | |
874 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); | ||
876 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 875 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
877 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 876 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
878 | } | 877 | } |
879 | 878 | ||
880 | 879 | ||
@@ -883,7 +882,7 @@ oidc_iteration_error (void *cls) | |||
883 | * parameter. Otherwise redirects with error | 882 | * parameter. Otherwise redirects with error |
884 | */ | 883 | */ |
885 | static void | 884 | static void |
886 | oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 885 | oidc_ticket_issue_cb(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
887 | { | 886 | { |
888 | struct RequestHandle *handle = cls; | 887 | struct RequestHandle *handle = cls; |
889 | struct MHD_Response *resp; | 888 | struct MHD_Response *resp; |
@@ -893,72 +892,72 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
893 | 892 | ||
894 | handle->idp_op = NULL; | 893 | handle->idp_op = NULL; |
895 | if (NULL == ticket) | 894 | if (NULL == ticket) |
896 | { | 895 | { |
897 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 896 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); |
898 | handle->edesc = GNUNET_strdup ("Server cannot generate ticket."); | 897 | handle->edesc = GNUNET_strdup("Server cannot generate ticket."); |
899 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 898 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
900 | return; | 899 | return; |
901 | } | 900 | } |
902 | handle->ticket = *ticket; | 901 | handle->ticket = *ticket; |
903 | ticket_str = | 902 | ticket_str = |
904 | GNUNET_STRINGS_data_to_string_alloc (&handle->ticket, | 903 | GNUNET_STRINGS_data_to_string_alloc(&handle->ticket, |
905 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 904 | sizeof(struct GNUNET_RECLAIM_Ticket)); |
906 | // TODO change if more attributes are needed (see max_age) | 905 | // TODO change if more attributes are needed (see max_age) |
907 | code_string = OIDC_build_authz_code (&handle->priv_key, | 906 | code_string = OIDC_build_authz_code(&handle->priv_key, |
908 | &handle->ticket, | 907 | &handle->ticket, |
909 | handle->attr_list, | 908 | handle->attr_list, |
910 | handle->oidc->nonce, | 909 | handle->oidc->nonce, |
911 | handle->oidc->code_challenge); | 910 | handle->oidc->code_challenge); |
912 | if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) && | 911 | if ((NULL != handle->redirect_prefix) && (NULL != handle->redirect_suffix) && |
913 | (NULL != handle->tld)) | 912 | (NULL != handle->tld)) |
914 | { | 913 | { |
915 | 914 | GNUNET_asprintf(&redirect_uri, | |
916 | GNUNET_asprintf (&redirect_uri, | 915 | "%s.%s/%s?%s=%s&state=%s", |
917 | "%s.%s/%s?%s=%s&state=%s", | 916 | handle->redirect_prefix, |
918 | handle->redirect_prefix, | 917 | handle->tld, |
919 | handle->tld, | 918 | handle->redirect_suffix, |
920 | handle->redirect_suffix, | 919 | handle->oidc->response_type, |
921 | handle->oidc->response_type, | 920 | code_string, |
922 | code_string, | 921 | handle->oidc->state); |
923 | handle->oidc->state); | 922 | } |
924 | } | ||
925 | else | 923 | else |
926 | { | 924 | { |
927 | GNUNET_asprintf (&redirect_uri, | 925 | GNUNET_asprintf(&redirect_uri, |
928 | "%s?%s=%s&state=%s", | 926 | "%s?%s=%s&state=%s", |
929 | handle->oidc->redirect_uri, | 927 | handle->oidc->redirect_uri, |
930 | handle->oidc->response_type, | 928 | handle->oidc->response_type, |
931 | code_string, | 929 | code_string, |
932 | handle->oidc->state); | 930 | handle->oidc->state); |
933 | } | 931 | } |
934 | resp = GNUNET_REST_create_response (""); | 932 | resp = GNUNET_REST_create_response(""); |
935 | MHD_add_response_header (resp, "Location", redirect_uri); | 933 | MHD_add_response_header(resp, "Location", redirect_uri); |
936 | handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); | 934 | handle->proc(handle->proc_cls, resp, MHD_HTTP_FOUND); |
937 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 935 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
938 | GNUNET_free (redirect_uri); | 936 | GNUNET_free(redirect_uri); |
939 | GNUNET_free (ticket_str); | 937 | GNUNET_free(ticket_str); |
940 | GNUNET_free (code_string); | 938 | GNUNET_free(code_string); |
941 | } | 939 | } |
942 | 940 | ||
943 | static void | 941 | static void |
944 | oidc_collect_finished_cb (void *cls) | 942 | oidc_collect_finished_cb(void *cls) |
945 | { | 943 | { |
946 | struct RequestHandle *handle = cls; | 944 | struct RequestHandle *handle = cls; |
945 | |||
947 | handle->attr_it = NULL; | 946 | handle->attr_it = NULL; |
948 | handle->ticket_it = NULL; | 947 | handle->ticket_it = NULL; |
949 | if (NULL == handle->attr_list->list_head) | 948 | if (NULL == handle->attr_list->list_head) |
950 | { | 949 | { |
951 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE); | 950 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_SCOPE); |
952 | handle->edesc = GNUNET_strdup ("The requested scope is not available."); | 951 | handle->edesc = GNUNET_strdup("The requested scope is not available."); |
953 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 952 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
954 | return; | 953 | return; |
955 | } | 954 | } |
956 | handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp, | 955 | handle->idp_op = GNUNET_RECLAIM_ticket_issue(handle->idp, |
957 | &handle->priv_key, | 956 | &handle->priv_key, |
958 | &handle->oidc->client_pkey, | 957 | &handle->oidc->client_pkey, |
959 | handle->attr_list, | 958 | handle->attr_list, |
960 | &oidc_ticket_issue_cb, | 959 | &oidc_ticket_issue_cb, |
961 | handle); | 960 | handle); |
962 | } | 961 | } |
963 | 962 | ||
964 | 963 | ||
@@ -966,9 +965,9 @@ oidc_collect_finished_cb (void *cls) | |||
966 | * Collects all attributes for an ego if in scope parameter | 965 | * Collects all attributes for an ego if in scope parameter |
967 | */ | 966 | */ |
968 | static void | 967 | static void |
969 | oidc_attr_collect (void *cls, | 968 | oidc_attr_collect(void *cls, |
970 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 969 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
971 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 970 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
972 | { | 971 | { |
973 | struct RequestHandle *handle = cls; | 972 | struct RequestHandle *handle = cls; |
974 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 973 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
@@ -977,38 +976,38 @@ oidc_attr_collect (void *cls, | |||
977 | char delimiter[] = " "; | 976 | char delimiter[] = " "; |
978 | 977 | ||
979 | if ((NULL == attr->name) || (NULL == attr->data)) | 978 | if ((NULL == attr->name) || (NULL == attr->data)) |
980 | { | 979 | { |
981 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 980 | GNUNET_RECLAIM_get_attributes_next(handle->attr_it); |
982 | return; | 981 | return; |
983 | } | 982 | } |
984 | 983 | ||
985 | scope_variables = GNUNET_strdup (handle->oidc->scope); | 984 | scope_variables = GNUNET_strdup(handle->oidc->scope); |
986 | scope_variable = strtok (scope_variables, delimiter); | 985 | scope_variable = strtok(scope_variables, delimiter); |
987 | while (NULL != scope_variable) | 986 | while (NULL != scope_variable) |
988 | { | 987 | { |
989 | if (0 == strcmp (attr->name, scope_variable)) | 988 | if (0 == strcmp(attr->name, scope_variable)) |
990 | break; | 989 | break; |
991 | scope_variable = strtok (NULL, delimiter); | 990 | scope_variable = strtok(NULL, delimiter); |
992 | } | 991 | } |
993 | if (NULL == scope_variable) | 992 | if (NULL == scope_variable) |
994 | { | 993 | { |
995 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 994 | GNUNET_RECLAIM_get_attributes_next(handle->attr_it); |
996 | GNUNET_free (scope_variables); | 995 | GNUNET_free(scope_variables); |
997 | return; | 996 | return; |
998 | } | 997 | } |
999 | GNUNET_free (scope_variables); | 998 | GNUNET_free(scope_variables); |
1000 | 999 | ||
1001 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 1000 | le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
1002 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, | 1001 | le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr->name, |
1003 | attr->type, | 1002 | attr->type, |
1004 | attr->data, | 1003 | attr->data, |
1005 | attr->data_size); | 1004 | attr->data_size); |
1006 | le->claim->id = attr->id; | 1005 | le->claim->id = attr->id; |
1007 | le->claim->version = attr->version; | 1006 | le->claim->version = attr->version; |
1008 | GNUNET_CONTAINER_DLL_insert (handle->attr_list->list_head, | 1007 | GNUNET_CONTAINER_DLL_insert(handle->attr_list->list_head, |
1009 | handle->attr_list->list_tail, | 1008 | handle->attr_list->list_tail, |
1010 | le); | 1009 | le); |
1011 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 1010 | GNUNET_RECLAIM_get_attributes_next(handle->attr_it); |
1012 | } | 1011 | } |
1013 | 1012 | ||
1014 | 1013 | ||
@@ -1016,7 +1015,7 @@ oidc_attr_collect (void *cls, | |||
1016 | * Checks time and cookie and redirects accordingly | 1015 | * Checks time and cookie and redirects accordingly |
1017 | */ | 1016 | */ |
1018 | static void | 1017 | static void |
1019 | code_redirect (void *cls) | 1018 | code_redirect(void *cls) |
1020 | { | 1019 | { |
1021 | struct RequestHandle *handle = cls; | 1020 | struct RequestHandle *handle = cls; |
1022 | struct GNUNET_TIME_Absolute current_time; | 1021 | struct GNUNET_TIME_Absolute current_time; |
@@ -1026,111 +1025,111 @@ code_redirect (void *cls) | |||
1026 | struct GNUNET_HashCode cache_key; | 1025 | struct GNUNET_HashCode cache_key; |
1027 | char *identity_cookie; | 1026 | char *identity_cookie; |
1028 | 1027 | ||
1029 | GNUNET_asprintf (&identity_cookie, | 1028 | GNUNET_asprintf(&identity_cookie, |
1030 | "Identity=%s", | 1029 | "Identity=%s", |
1031 | handle->oidc->login_identity); | 1030 | handle->oidc->login_identity); |
1032 | GNUNET_CRYPTO_hash (identity_cookie, strlen (identity_cookie), &cache_key); | 1031 | GNUNET_CRYPTO_hash(identity_cookie, strlen(identity_cookie), &cache_key); |
1033 | GNUNET_free (identity_cookie); | 1032 | GNUNET_free(identity_cookie); |
1034 | // No login time for identity -> redirect to login | 1033 | // No login time for identity -> redirect to login |
1035 | if (GNUNET_YES == | 1034 | if (GNUNET_YES == |
1036 | GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key)) | 1035 | GNUNET_CONTAINER_multihashmap_contains(OIDC_cookie_jar_map, &cache_key)) |
1037 | { | 1036 | { |
1038 | relog_time = | 1037 | relog_time = |
1039 | GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key); | 1038 | GNUNET_CONTAINER_multihashmap_get(OIDC_cookie_jar_map, &cache_key); |
1040 | current_time = GNUNET_TIME_absolute_get (); | 1039 | current_time = GNUNET_TIME_absolute_get(); |
1041 | // 30 min after old login -> redirect to login | 1040 | // 30 min after old login -> redirect to login |
1042 | if (current_time.abs_value_us <= relog_time->abs_value_us) | 1041 | if (current_time.abs_value_us <= relog_time->abs_value_us) |
1043 | { | ||
1044 | if (GNUNET_OK != | ||
1045 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc | ||
1046 | ->login_identity, | ||
1047 | strlen ( | ||
1048 | handle->oidc | ||
1049 | ->login_identity), | ||
1050 | &pubkey)) | ||
1051 | { | ||
1052 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); | ||
1053 | handle->edesc = | ||
1054 | GNUNET_strdup ("The cookie of a login identity is not valid"); | ||
1055 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | ||
1056 | return; | ||
1057 | } | ||
1058 | // iterate over egos and compare their public key | ||
1059 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; | ||
1060 | handle->ego_entry = handle->ego_entry->next) | ||
1061 | { | ||
1062 | GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey); | ||
1063 | if (0 == GNUNET_memcmp (&ego_pkey, &pubkey)) | ||
1064 | { | 1042 | { |
1065 | handle->priv_key = | 1043 | if (GNUNET_OK != |
1066 | *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego); | 1044 | GNUNET_CRYPTO_ecdsa_public_key_from_string(handle->oidc |
1067 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 1045 | ->login_identity, |
1068 | handle->attr_list = | 1046 | strlen( |
1069 | GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 1047 | handle->oidc |
1070 | handle->attr_it = | 1048 | ->login_identity), |
1071 | GNUNET_RECLAIM_get_attributes_start (handle->idp, | 1049 | &pubkey)) |
1072 | &handle->priv_key, | 1050 | { |
1073 | &oidc_iteration_error, | 1051 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_COOKIE); |
1074 | handle, | 1052 | handle->edesc = |
1075 | &oidc_attr_collect, | 1053 | GNUNET_strdup("The cookie of a login identity is not valid"); |
1076 | handle, | 1054 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1077 | &oidc_collect_finished_cb, | 1055 | return; |
1078 | handle); | 1056 | } |
1057 | // iterate over egos and compare their public key | ||
1058 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; | ||
1059 | handle->ego_entry = handle->ego_entry->next) | ||
1060 | { | ||
1061 | GNUNET_IDENTITY_ego_get_public_key(handle->ego_entry->ego, &ego_pkey); | ||
1062 | if (0 == GNUNET_memcmp(&ego_pkey, &pubkey)) | ||
1063 | { | ||
1064 | handle->priv_key = | ||
1065 | *GNUNET_IDENTITY_ego_get_private_key(handle->ego_entry->ego); | ||
1066 | handle->idp = GNUNET_RECLAIM_connect(cfg); | ||
1067 | handle->attr_list = | ||
1068 | GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | ||
1069 | handle->attr_it = | ||
1070 | GNUNET_RECLAIM_get_attributes_start(handle->idp, | ||
1071 | &handle->priv_key, | ||
1072 | &oidc_iteration_error, | ||
1073 | handle, | ||
1074 | &oidc_attr_collect, | ||
1075 | handle, | ||
1076 | &oidc_collect_finished_cb, | ||
1077 | handle); | ||
1078 | return; | ||
1079 | } | ||
1080 | } | ||
1081 | GNUNET_SCHEDULER_add_now(&login_redirect, handle); | ||
1079 | return; | 1082 | return; |
1080 | } | 1083 | } |
1081 | } | ||
1082 | GNUNET_SCHEDULER_add_now (&login_redirect, handle); | ||
1083 | return; | ||
1084 | } | 1084 | } |
1085 | } | ||
1086 | } | 1085 | } |
1087 | 1086 | ||
1088 | 1087 | ||
1089 | static void | 1088 | static void |
1090 | build_redirect (void *cls) | 1089 | build_redirect(void *cls) |
1091 | { | 1090 | { |
1092 | struct RequestHandle *handle = cls; | 1091 | struct RequestHandle *handle = cls; |
1093 | struct MHD_Response *resp; | 1092 | struct MHD_Response *resp; |
1094 | char *redirect_uri; | 1093 | char *redirect_uri; |
1095 | 1094 | ||
1096 | if (GNUNET_YES == handle->oidc->user_cancelled) | 1095 | if (GNUNET_YES == handle->oidc->user_cancelled) |
1097 | { | 1096 | { |
1098 | if ((NULL != handle->redirect_prefix) && | 1097 | if ((NULL != handle->redirect_prefix) && |
1099 | (NULL != handle->redirect_suffix) && (NULL != handle->tld)) | 1098 | (NULL != handle->redirect_suffix) && (NULL != handle->tld)) |
1100 | { | 1099 | { |
1101 | GNUNET_asprintf (&redirect_uri, | 1100 | GNUNET_asprintf(&redirect_uri, |
1102 | "%s.%s/%s?error=%s&error_description=%s&state=%s", | 1101 | "%s.%s/%s?error=%s&error_description=%s&state=%s", |
1103 | handle->redirect_prefix, | 1102 | handle->redirect_prefix, |
1104 | handle->tld, | 1103 | handle->tld, |
1105 | handle->redirect_suffix, | 1104 | handle->redirect_suffix, |
1106 | "access_denied", | 1105 | "access_denied", |
1107 | "User denied access", | 1106 | "User denied access", |
1108 | handle->oidc->state); | 1107 | handle->oidc->state); |
1109 | } | 1108 | } |
1110 | else | 1109 | else |
1111 | { | 1110 | { |
1112 | GNUNET_asprintf (&redirect_uri, | 1111 | GNUNET_asprintf(&redirect_uri, |
1113 | "%s?error=%s&error_description=%s&state=%s", | 1112 | "%s?error=%s&error_description=%s&state=%s", |
1114 | handle->oidc->redirect_uri, | 1113 | handle->oidc->redirect_uri, |
1115 | "access_denied", | 1114 | "access_denied", |
1116 | "User denied access", | 1115 | "User denied access", |
1117 | handle->oidc->state); | 1116 | handle->oidc->state); |
1118 | } | 1117 | } |
1119 | resp = GNUNET_REST_create_response (""); | 1118 | resp = GNUNET_REST_create_response(""); |
1120 | MHD_add_response_header (resp, "Location", redirect_uri); | 1119 | MHD_add_response_header(resp, "Location", redirect_uri); |
1121 | handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); | 1120 | handle->proc(handle->proc_cls, resp, MHD_HTTP_FOUND); |
1122 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 1121 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
1123 | GNUNET_free (redirect_uri); | 1122 | GNUNET_free(redirect_uri); |
1124 | return; | 1123 | return; |
1125 | } | 1124 | } |
1126 | GNUNET_SCHEDULER_add_now (&code_redirect, handle); | 1125 | GNUNET_SCHEDULER_add_now(&code_redirect, handle); |
1127 | } | 1126 | } |
1128 | 1127 | ||
1129 | 1128 | ||
1130 | static void | 1129 | static void |
1131 | lookup_redirect_uri_result (void *cls, | 1130 | lookup_redirect_uri_result(void *cls, |
1132 | uint32_t rd_count, | 1131 | uint32_t rd_count, |
1133 | const struct GNUNET_GNSRECORD_Data *rd) | 1132 | const struct GNUNET_GNSRECORD_Data *rd) |
1134 | { | 1133 | { |
1135 | struct RequestHandle *handle = cls; | 1134 | struct RequestHandle *handle = cls; |
1136 | char *tmp; | 1135 | char *tmp; |
@@ -1140,66 +1139,66 @@ lookup_redirect_uri_result (void *cls, | |||
1140 | 1139 | ||
1141 | handle->gns_op = NULL; | 1140 | handle->gns_op = NULL; |
1142 | if (0 == rd_count) | 1141 | if (0 == rd_count) |
1143 | { | 1142 | { |
1144 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 1143 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); |
1145 | handle->edesc = | 1144 | handle->edesc = |
1146 | GNUNET_strdup ("Server cannot generate ticket, redirect uri not found."); | 1145 | GNUNET_strdup("Server cannot generate ticket, redirect uri not found."); |
1147 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1146 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1148 | return; | 1147 | return; |
1149 | } | 1148 | } |
1150 | for (int i = 0; i < rd_count; i++) | 1149 | for (int i = 0; i < rd_count; i++) |
1151 | { | 1150 | { |
1152 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT != rd[i].record_type) | 1151 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT != rd[i].record_type) |
1153 | continue; | ||
1154 | if (0 != strncmp (rd[i].data, handle->oidc->redirect_uri, rd[i].data_size)) | ||
1155 | continue; | ||
1156 | tmp = GNUNET_strndup (rd[i].data, rd[i].data_size); | ||
1157 | if (NULL == strstr (tmp, handle->oidc->client_id)) | ||
1158 | { | ||
1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1160 | "Redirect uri %s does not contain client_id %s\n", | ||
1161 | tmp, | ||
1162 | handle->oidc->client_id); | ||
1163 | } | ||
1164 | else | ||
1165 | { | ||
1166 | pos = strrchr (tmp, (unsigned char) '.'); | ||
1167 | if (NULL == pos) | ||
1168 | { | ||
1169 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1170 | "Redirect uri %s contains client_id but is malformed\n", | ||
1171 | tmp); | ||
1172 | GNUNET_free (tmp); | ||
1173 | continue; | 1152 | continue; |
1174 | } | 1153 | if (0 != strncmp(rd[i].data, handle->oidc->redirect_uri, rd[i].data_size)) |
1175 | *pos = '\0'; | ||
1176 | handle->redirect_prefix = GNUNET_strdup (tmp); | ||
1177 | tmp_key_str = pos + 1; | ||
1178 | pos = strchr (tmp_key_str, (unsigned char) '/'); | ||
1179 | if (NULL == pos) | ||
1180 | { | ||
1181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1182 | "Redirect uri %s contains client_id but is malformed\n", | ||
1183 | tmp); | ||
1184 | GNUNET_free (tmp); | ||
1185 | continue; | 1154 | continue; |
1186 | } | 1155 | tmp = GNUNET_strndup(rd[i].data, rd[i].data_size); |
1187 | *pos = '\0'; | 1156 | if (NULL == strstr(tmp, handle->oidc->client_id)) |
1188 | handle->redirect_suffix = GNUNET_strdup (pos + 1); | 1157 | { |
1189 | 1158 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
1190 | GNUNET_STRINGS_string_to_data (tmp_key_str, | 1159 | "Redirect uri %s does not contain client_id %s\n", |
1191 | strlen (tmp_key_str), | 1160 | tmp, |
1192 | &redirect_zone, | 1161 | handle->oidc->client_id); |
1193 | sizeof (redirect_zone)); | 1162 | } |
1194 | } | 1163 | else |
1195 | GNUNET_SCHEDULER_add_now (&build_redirect, handle); | 1164 | { |
1196 | GNUNET_free (tmp); | 1165 | pos = strrchr(tmp, (unsigned char)'.'); |
1197 | return; | 1166 | if (NULL == pos) |
1198 | } | 1167 | { |
1199 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 1168 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1169 | "Redirect uri %s contains client_id but is malformed\n", | ||
1170 | tmp); | ||
1171 | GNUNET_free(tmp); | ||
1172 | continue; | ||
1173 | } | ||
1174 | *pos = '\0'; | ||
1175 | handle->redirect_prefix = GNUNET_strdup(tmp); | ||
1176 | tmp_key_str = pos + 1; | ||
1177 | pos = strchr(tmp_key_str, (unsigned char)'/'); | ||
1178 | if (NULL == pos) | ||
1179 | { | ||
1180 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1181 | "Redirect uri %s contains client_id but is malformed\n", | ||
1182 | tmp); | ||
1183 | GNUNET_free(tmp); | ||
1184 | continue; | ||
1185 | } | ||
1186 | *pos = '\0'; | ||
1187 | handle->redirect_suffix = GNUNET_strdup(pos + 1); | ||
1188 | |||
1189 | GNUNET_STRINGS_string_to_data(tmp_key_str, | ||
1190 | strlen(tmp_key_str), | ||
1191 | &redirect_zone, | ||
1192 | sizeof(redirect_zone)); | ||
1193 | } | ||
1194 | GNUNET_SCHEDULER_add_now(&build_redirect, handle); | ||
1195 | GNUNET_free(tmp); | ||
1196 | return; | ||
1197 | } | ||
1198 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); | ||
1200 | handle->edesc = | 1199 | handle->edesc = |
1201 | GNUNET_strdup ("Server cannot generate ticket, redirect uri not found."); | 1200 | GNUNET_strdup("Server cannot generate ticket, redirect uri not found."); |
1202 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1201 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1203 | } | 1202 | } |
1204 | 1203 | ||
1205 | 1204 | ||
@@ -1207,36 +1206,37 @@ lookup_redirect_uri_result (void *cls, | |||
1207 | * Initiate redirect back to client. | 1206 | * Initiate redirect back to client. |
1208 | */ | 1207 | */ |
1209 | static void | 1208 | static void |
1210 | client_redirect (void *cls) | 1209 | client_redirect(void *cls) |
1211 | { | 1210 | { |
1212 | struct RequestHandle *handle = cls; | 1211 | struct RequestHandle *handle = cls; |
1213 | 1212 | ||
1214 | /* Lookup client redirect uri to verify request */ | 1213 | /* Lookup client redirect uri to verify request */ |
1215 | handle->gns_op = | 1214 | handle->gns_op = |
1216 | GNUNET_GNS_lookup (handle->gns_handle, | 1215 | GNUNET_GNS_lookup(handle->gns_handle, |
1217 | GNUNET_GNS_EMPTY_LABEL_AT, | 1216 | GNUNET_GNS_EMPTY_LABEL_AT, |
1218 | &handle->oidc->client_pkey, | 1217 | &handle->oidc->client_pkey, |
1219 | GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, | 1218 | GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, |
1220 | GNUNET_GNS_LO_DEFAULT, | 1219 | GNUNET_GNS_LO_DEFAULT, |
1221 | &lookup_redirect_uri_result, | 1220 | &lookup_redirect_uri_result, |
1222 | handle); | 1221 | handle); |
1223 | } | 1222 | } |
1224 | 1223 | ||
1225 | static char * | 1224 | static char * |
1226 | get_url_parameter_copy (const struct RequestHandle *handle, const char *key) | 1225 | get_url_parameter_copy(const struct RequestHandle *handle, const char *key) |
1227 | { | 1226 | { |
1228 | struct GNUNET_HashCode hc; | 1227 | struct GNUNET_HashCode hc; |
1229 | char *value; | 1228 | char *value; |
1230 | GNUNET_CRYPTO_hash (key, strlen (key), &hc); | 1229 | |
1231 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1230 | GNUNET_CRYPTO_hash(key, strlen(key), &hc); |
1232 | ->url_param_map, | 1231 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle |
1233 | &hc)) | 1232 | ->url_param_map, |
1233 | &hc)) | ||
1234 | return NULL; | 1234 | return NULL; |
1235 | value = | 1235 | value = |
1236 | GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, &hc); | 1236 | GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map, &hc); |
1237 | if (NULL == value) | 1237 | if (NULL == value) |
1238 | return NULL; | 1238 | return NULL; |
1239 | return GNUNET_strdup (value); | 1239 | return GNUNET_strdup(value); |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | 1242 | ||
@@ -1247,7 +1247,7 @@ get_url_parameter_copy (const struct RequestHandle *handle, const char *key) | |||
1247 | * @param cls the `struct RequestHandle` | 1247 | * @param cls the `struct RequestHandle` |
1248 | */ | 1248 | */ |
1249 | static void | 1249 | static void |
1250 | build_authz_response (void *cls) | 1250 | build_authz_response(void *cls) |
1251 | { | 1251 | { |
1252 | struct RequestHandle *handle = cls; | 1252 | struct RequestHandle *handle = cls; |
1253 | struct GNUNET_HashCode cache_key; | 1253 | struct GNUNET_HashCode cache_key; |
@@ -1259,117 +1259,117 @@ build_authz_response (void *cls) | |||
1259 | 1259 | ||
1260 | // REQUIRED value: redirect_uri | 1260 | // REQUIRED value: redirect_uri |
1261 | handle->oidc->redirect_uri = | 1261 | handle->oidc->redirect_uri = |
1262 | get_url_parameter_copy (handle, OIDC_REDIRECT_URI_KEY); | 1262 | get_url_parameter_copy(handle, OIDC_REDIRECT_URI_KEY); |
1263 | if (NULL == handle->oidc->redirect_uri) | 1263 | if (NULL == handle->oidc->redirect_uri) |
1264 | { | 1264 | { |
1265 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1265 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1266 | handle->edesc = GNUNET_strdup ("missing parameter redirect_uri"); | 1266 | handle->edesc = GNUNET_strdup("missing parameter redirect_uri"); |
1267 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1267 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1268 | return; | 1268 | return; |
1269 | } | 1269 | } |
1270 | 1270 | ||
1271 | // REQUIRED value: response_type | 1271 | // REQUIRED value: response_type |
1272 | handle->oidc->response_type = | 1272 | handle->oidc->response_type = |
1273 | get_url_parameter_copy (handle, OIDC_RESPONSE_TYPE_KEY); | 1273 | get_url_parameter_copy(handle, OIDC_RESPONSE_TYPE_KEY); |
1274 | if (NULL == handle->oidc->response_type) | 1274 | if (NULL == handle->oidc->response_type) |
1275 | { | 1275 | { |
1276 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1276 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1277 | handle->edesc = GNUNET_strdup ("missing parameter response_type"); | 1277 | handle->edesc = GNUNET_strdup("missing parameter response_type"); |
1278 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1278 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1279 | return; | 1279 | return; |
1280 | } | 1280 | } |
1281 | 1281 | ||
1282 | // REQUIRED value: scope | 1282 | // REQUIRED value: scope |
1283 | handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY); | 1283 | handle->oidc->scope = get_url_parameter_copy(handle, OIDC_SCOPE_KEY); |
1284 | if (NULL == handle->oidc->scope) | 1284 | if (NULL == handle->oidc->scope) |
1285 | { | 1285 | { |
1286 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE); | 1286 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_SCOPE); |
1287 | handle->edesc = GNUNET_strdup ("missing parameter scope"); | 1287 | handle->edesc = GNUNET_strdup("missing parameter scope"); |
1288 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1288 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1289 | return; | 1289 | return; |
1290 | } | 1290 | } |
1291 | 1291 | ||
1292 | // OPTIONAL value: nonce | 1292 | // OPTIONAL value: nonce |
1293 | handle->oidc->nonce = get_url_parameter_copy (handle, OIDC_NONCE_KEY); | 1293 | handle->oidc->nonce = get_url_parameter_copy(handle, OIDC_NONCE_KEY); |
1294 | 1294 | ||
1295 | // TODO check other values if needed | 1295 | // TODO check other values if needed |
1296 | number_of_ignored_parameter = | 1296 | number_of_ignored_parameter = |
1297 | sizeof (OIDC_ignored_parameter_array) / sizeof (char *); | 1297 | sizeof(OIDC_ignored_parameter_array) / sizeof(char *); |
1298 | for (iterator = 0; iterator < number_of_ignored_parameter; iterator++) | 1298 | for (iterator = 0; iterator < number_of_ignored_parameter; iterator++) |
1299 | { | 1299 | { |
1300 | GNUNET_CRYPTO_hash (OIDC_ignored_parameter_array[iterator], | 1300 | GNUNET_CRYPTO_hash(OIDC_ignored_parameter_array[iterator], |
1301 | strlen (OIDC_ignored_parameter_array[iterator]), | 1301 | strlen(OIDC_ignored_parameter_array[iterator]), |
1302 | &cache_key); | 1302 | &cache_key); |
1303 | if (GNUNET_YES == | 1303 | if (GNUNET_YES == |
1304 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1304 | GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle |
1305 | ->url_param_map, | 1305 | ->url_param_map, |
1306 | &cache_key)) | 1306 | &cache_key)) |
1307 | { | 1307 | { |
1308 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED); | 1308 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_ACCESS_DENIED); |
1309 | GNUNET_asprintf (&handle->edesc, | 1309 | GNUNET_asprintf(&handle->edesc, |
1310 | "Server will not handle parameter: %s", | 1310 | "Server will not handle parameter: %s", |
1311 | OIDC_ignored_parameter_array[iterator]); | 1311 | OIDC_ignored_parameter_array[iterator]); |
1312 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1312 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1313 | return; | 1313 | return; |
1314 | } | ||
1314 | } | 1315 | } |
1315 | } | ||
1316 | 1316 | ||
1317 | // We only support authorization code flows. | 1317 | // We only support authorization code flows. |
1318 | if (0 != strcmp (handle->oidc->response_type, | 1318 | if (0 != strcmp(handle->oidc->response_type, |
1319 | OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE)) | 1319 | OIDC_EXPECTED_AUTHORIZATION_RESPONSE_TYPE)) |
1320 | { | 1320 | { |
1321 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE); | 1321 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_UNSUPPORTED_RESPONSE_TYPE); |
1322 | handle->edesc = GNUNET_strdup ("The authorization server does not support " | 1322 | handle->edesc = GNUNET_strdup("The authorization server does not support " |
1323 | "obtaining this authorization code."); | 1323 | "obtaining this authorization code."); |
1324 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1324 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1325 | return; | 1325 | return; |
1326 | } | 1326 | } |
1327 | 1327 | ||
1328 | // Checks if scope contains 'openid' | 1328 | // Checks if scope contains 'openid' |
1329 | expected_scope = GNUNET_strdup (handle->oidc->scope); | 1329 | expected_scope = GNUNET_strdup(handle->oidc->scope); |
1330 | char *test; | 1330 | char *test; |
1331 | test = strtok (expected_scope, delimiter); | 1331 | test = strtok(expected_scope, delimiter); |
1332 | while (NULL != test) | 1332 | while (NULL != test) |
1333 | { | 1333 | { |
1334 | if (0 == strcmp (OIDC_EXPECTED_AUTHORIZATION_SCOPE, expected_scope)) | 1334 | if (0 == strcmp(OIDC_EXPECTED_AUTHORIZATION_SCOPE, expected_scope)) |
1335 | break; | 1335 | break; |
1336 | test = strtok (NULL, delimiter); | 1336 | test = strtok(NULL, delimiter); |
1337 | } | 1337 | } |
1338 | if (NULL == test) | 1338 | if (NULL == test) |
1339 | { | 1339 | { |
1340 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_SCOPE); | 1340 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_SCOPE); |
1341 | handle->edesc = | 1341 | handle->edesc = |
1342 | GNUNET_strdup ("The requested scope is invalid, unknown, or malformed."); | 1342 | GNUNET_strdup("The requested scope is invalid, unknown, or malformed."); |
1343 | GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); | 1343 | GNUNET_SCHEDULER_add_now(&do_redirect_error, handle); |
1344 | GNUNET_free (expected_scope); | 1344 | GNUNET_free(expected_scope); |
1345 | return; | 1345 | return; |
1346 | } | 1346 | } |
1347 | 1347 | ||
1348 | GNUNET_free (expected_scope); | 1348 | GNUNET_free(expected_scope); |
1349 | if ((NULL == handle->oidc->login_identity) && | 1349 | if ((NULL == handle->oidc->login_identity) && |
1350 | (GNUNET_NO == handle->oidc->user_cancelled)) | 1350 | (GNUNET_NO == handle->oidc->user_cancelled)) |
1351 | GNUNET_SCHEDULER_add_now (&login_redirect, handle); | 1351 | GNUNET_SCHEDULER_add_now(&login_redirect, handle); |
1352 | else | 1352 | else |
1353 | GNUNET_SCHEDULER_add_now (&client_redirect, handle); | 1353 | GNUNET_SCHEDULER_add_now(&client_redirect, handle); |
1354 | } | 1354 | } |
1355 | 1355 | ||
1356 | /** | 1356 | /** |
1357 | * Iterate over tlds in config | 1357 | * Iterate over tlds in config |
1358 | */ | 1358 | */ |
1359 | static void | 1359 | static void |
1360 | tld_iter (void *cls, const char *section, const char *option, const char *value) | 1360 | tld_iter(void *cls, const char *section, const char *option, const char *value) |
1361 | { | 1361 | { |
1362 | struct RequestHandle *handle = cls; | 1362 | struct RequestHandle *handle = cls; |
1363 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1363 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
1364 | 1364 | ||
1365 | if (GNUNET_OK != | 1365 | if (GNUNET_OK != |
1366 | GNUNET_CRYPTO_ecdsa_public_key_from_string (value, strlen (value), &pkey)) | 1366 | GNUNET_CRYPTO_ecdsa_public_key_from_string(value, strlen(value), &pkey)) |
1367 | { | 1367 | { |
1368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value); | 1368 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value); |
1369 | return; | 1369 | return; |
1370 | } | 1370 | } |
1371 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) | 1371 | if (0 == GNUNET_memcmp(&pkey, &handle->oidc->client_pkey)) |
1372 | handle->tld = GNUNET_strdup (option + 1); | 1372 | handle->tld = GNUNET_strdup(option + 1); |
1373 | } | 1373 | } |
1374 | 1374 | ||
1375 | /** | 1375 | /** |
@@ -1380,70 +1380,70 @@ tld_iter (void *cls, const char *section, const char *option, const char *value) | |||
1380 | * @param cls the RequestHandle | 1380 | * @param cls the RequestHandle |
1381 | */ | 1381 | */ |
1382 | static void | 1382 | static void |
1383 | authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | 1383 | authorize_endpoint(struct GNUNET_REST_RequestHandle *con_handle, |
1384 | const char *url, | 1384 | const char *url, |
1385 | void *cls) | 1385 | void *cls) |
1386 | { | 1386 | { |
1387 | struct RequestHandle *handle = cls; | 1387 | struct RequestHandle *handle = cls; |
1388 | struct EgoEntry *tmp_ego; | 1388 | struct EgoEntry *tmp_ego; |
1389 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 1389 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
1390 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1390 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
1391 | 1391 | ||
1392 | cookie_identity_interpretation (handle); | 1392 | cookie_identity_interpretation(handle); |
1393 | 1393 | ||
1394 | // RECOMMENDED value: state - REQUIRED for answers | 1394 | // RECOMMENDED value: state - REQUIRED for answers |
1395 | handle->oidc->state = get_url_parameter_copy (handle, OIDC_STATE_KEY); | 1395 | handle->oidc->state = get_url_parameter_copy(handle, OIDC_STATE_KEY); |
1396 | 1396 | ||
1397 | // REQUIRED value: client_id | 1397 | // REQUIRED value: client_id |
1398 | handle->oidc->client_id = get_url_parameter_copy (handle, OIDC_CLIENT_ID_KEY); | 1398 | handle->oidc->client_id = get_url_parameter_copy(handle, OIDC_CLIENT_ID_KEY); |
1399 | if (NULL == handle->oidc->client_id) | 1399 | if (NULL == handle->oidc->client_id) |
1400 | { | 1400 | { |
1401 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1401 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1402 | handle->edesc = GNUNET_strdup ("missing parameter client_id"); | 1402 | handle->edesc = GNUNET_strdup("missing parameter client_id"); |
1403 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 1403 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
1404 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1404 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1405 | return; | 1405 | return; |
1406 | } | 1406 | } |
1407 | 1407 | ||
1408 | // OPTIONAL value: code_challenge | 1408 | // OPTIONAL value: code_challenge |
1409 | handle->oidc->code_challenge = get_url_parameter_copy (handle, OIDC_CODE_CHALLENGE_KEY); | 1409 | handle->oidc->code_challenge = get_url_parameter_copy(handle, OIDC_CODE_CHALLENGE_KEY); |
1410 | if (NULL == handle->oidc->code_challenge) | 1410 | if (NULL == handle->oidc->code_challenge) |
1411 | { | 1411 | { |
1412 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1412 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1413 | "OAuth authorization request does not contain PKCE parameters!\n"); | 1413 | "OAuth authorization request does not contain PKCE parameters!\n"); |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | if (GNUNET_OK != | 1416 | if (GNUNET_OK != |
1417 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id, | 1417 | GNUNET_CRYPTO_ecdsa_public_key_from_string(handle->oidc->client_id, |
1418 | strlen ( | 1418 | strlen( |
1419 | handle->oidc->client_id), | 1419 | handle->oidc->client_id), |
1420 | &handle->oidc->client_pkey)) | 1420 | &handle->oidc->client_pkey)) |
1421 | { | 1421 | { |
1422 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); | 1422 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); |
1423 | handle->edesc = GNUNET_strdup ("The client is not authorized to request an " | 1423 | handle->edesc = GNUNET_strdup("The client is not authorized to request an " |
1424 | "authorization code using this method."); | 1424 | "authorization code using this method."); |
1425 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 1425 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
1426 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1426 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1427 | return; | 1427 | return; |
1428 | } | 1428 | } |
1429 | 1429 | ||
1430 | // If we know this identity, translated the corresponding TLD | 1430 | // If we know this identity, translated the corresponding TLD |
1431 | // TODO: We might want to have a reverse lookup functionality for TLDs? | 1431 | // TODO: We might want to have a reverse lookup functionality for TLDs? |
1432 | for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) | 1432 | for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) |
1433 | { | ||
1434 | priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); | ||
1435 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey); | ||
1436 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) | ||
1437 | { | 1433 | { |
1438 | handle->tld = GNUNET_strdup (tmp_ego->identifier); | 1434 | priv_key = GNUNET_IDENTITY_ego_get_private_key(tmp_ego->ego); |
1439 | handle->ego_entry = handle->ego_tail; | 1435 | GNUNET_CRYPTO_ecdsa_key_get_public(priv_key, &pkey); |
1436 | if (0 == GNUNET_memcmp(&pkey, &handle->oidc->client_pkey)) | ||
1437 | { | ||
1438 | handle->tld = GNUNET_strdup(tmp_ego->identifier); | ||
1439 | handle->ego_entry = handle->ego_tail; | ||
1440 | } | ||
1440 | } | 1441 | } |
1441 | } | ||
1442 | if (NULL == handle->tld) | 1442 | if (NULL == handle->tld) |
1443 | GNUNET_CONFIGURATION_iterate_section_values (cfg, "gns", tld_iter, handle); | 1443 | GNUNET_CONFIGURATION_iterate_section_values(cfg, "gns", tld_iter, handle); |
1444 | if (NULL == handle->tld) | 1444 | if (NULL == handle->tld) |
1445 | handle->tld = GNUNET_strdup (handle->oidc->client_id); | 1445 | handle->tld = GNUNET_strdup(handle->oidc->client_id); |
1446 | GNUNET_SCHEDULER_add_now (&build_authz_response, handle); | 1446 | GNUNET_SCHEDULER_add_now(&build_authz_response, handle); |
1447 | } | 1447 | } |
1448 | 1448 | ||
1449 | /** | 1449 | /** |
@@ -1454,11 +1454,11 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1454 | * @param cls the RequestHandle | 1454 | * @param cls the RequestHandle |
1455 | */ | 1455 | */ |
1456 | static void | 1456 | static void |
1457 | login_cont (struct GNUNET_REST_RequestHandle *con_handle, | 1457 | login_cont(struct GNUNET_REST_RequestHandle *con_handle, |
1458 | const char *url, | 1458 | const char *url, |
1459 | void *cls) | 1459 | void *cls) |
1460 | { | 1460 | { |
1461 | struct MHD_Response *resp = GNUNET_REST_create_response (""); | 1461 | struct MHD_Response *resp = GNUNET_REST_create_response(""); |
1462 | struct RequestHandle *handle = cls; | 1462 | struct RequestHandle *handle = cls; |
1463 | struct GNUNET_HashCode cache_key; | 1463 | struct GNUNET_HashCode cache_key; |
1464 | struct GNUNET_TIME_Absolute *current_time; | 1464 | struct GNUNET_TIME_Absolute *current_time; |
@@ -1469,55 +1469,56 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1469 | json_error_t error; | 1469 | json_error_t error; |
1470 | json_t *identity; | 1470 | json_t *identity; |
1471 | char term_data[handle->rest_handle->data_size + 1]; | 1471 | char term_data[handle->rest_handle->data_size + 1]; |
1472 | |||
1472 | term_data[handle->rest_handle->data_size] = '\0'; | 1473 | term_data[handle->rest_handle->data_size] = '\0'; |
1473 | GNUNET_memcpy (term_data, | 1474 | GNUNET_memcpy(term_data, |
1474 | handle->rest_handle->data, | 1475 | handle->rest_handle->data, |
1475 | handle->rest_handle->data_size); | 1476 | handle->rest_handle->data_size); |
1476 | root = json_loads (term_data, JSON_DECODE_ANY, &error); | 1477 | root = json_loads(term_data, JSON_DECODE_ANY, &error); |
1477 | identity = json_object_get (root, "identity"); | 1478 | identity = json_object_get(root, "identity"); |
1478 | if (! json_is_string (identity)) | 1479 | if (!json_is_string(identity)) |
1479 | { | 1480 | { |
1480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1481 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1481 | "Error parsing json string from %s\n", | 1482 | "Error parsing json string from %s\n", |
1482 | term_data); | 1483 | term_data); |
1483 | handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); | 1484 | handle->proc(handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); |
1484 | json_decref (root); | 1485 | json_decref(root); |
1485 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 1486 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
1486 | return; | 1487 | return; |
1487 | } | 1488 | } |
1488 | GNUNET_asprintf (&cookie, "Identity=%s", json_string_value (identity)); | 1489 | GNUNET_asprintf(&cookie, "Identity=%s", json_string_value(identity)); |
1489 | GNUNET_asprintf (&header_val, | 1490 | GNUNET_asprintf(&header_val, |
1490 | "%s;Max-Age=%d", | 1491 | "%s;Max-Age=%d", |
1491 | cookie, | 1492 | cookie, |
1492 | OIDC_COOKIE_EXPIRATION); | 1493 | OIDC_COOKIE_EXPIRATION); |
1493 | MHD_add_response_header (resp, "Set-Cookie", header_val); | 1494 | MHD_add_response_header(resp, "Set-Cookie", header_val); |
1494 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", "POST"); | 1495 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", "POST"); |
1495 | GNUNET_CRYPTO_hash (cookie, strlen (cookie), &cache_key); | 1496 | GNUNET_CRYPTO_hash(cookie, strlen(cookie), &cache_key); |
1496 | 1497 | ||
1497 | if (0 != strcmp (json_string_value (identity), "Denied")) | 1498 | if (0 != strcmp(json_string_value(identity), "Denied")) |
1498 | { | 1499 | { |
1499 | current_time = GNUNET_new (struct GNUNET_TIME_Absolute); | 1500 | current_time = GNUNET_new(struct GNUNET_TIME_Absolute); |
1500 | *current_time = GNUNET_TIME_relative_to_absolute ( | 1501 | *current_time = GNUNET_TIME_relative_to_absolute( |
1501 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (), | 1502 | GNUNET_TIME_relative_multiply(GNUNET_TIME_relative_get_second_(), |
1502 | OIDC_COOKIE_EXPIRATION)); | 1503 | OIDC_COOKIE_EXPIRATION)); |
1503 | last_time = | 1504 | last_time = |
1504 | GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key); | 1505 | GNUNET_CONTAINER_multihashmap_get(OIDC_cookie_jar_map, &cache_key); |
1505 | GNUNET_free_non_null (last_time); | 1506 | GNUNET_free_non_null(last_time); |
1506 | GNUNET_CONTAINER_multihashmap_put (OIDC_cookie_jar_map, | 1507 | GNUNET_CONTAINER_multihashmap_put(OIDC_cookie_jar_map, |
1507 | &cache_key, | 1508 | &cache_key, |
1508 | current_time, | 1509 | current_time, |
1509 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 1510 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
1510 | } | 1511 | } |
1511 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 1512 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
1512 | GNUNET_free (cookie); | 1513 | GNUNET_free(cookie); |
1513 | GNUNET_free (header_val); | 1514 | GNUNET_free(header_val); |
1514 | json_decref (root); | 1515 | json_decref(root); |
1515 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 1516 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
1516 | } | 1517 | } |
1517 | 1518 | ||
1518 | static int | 1519 | static int |
1519 | check_authorization (struct RequestHandle *handle, | 1520 | check_authorization(struct RequestHandle *handle, |
1520 | struct GNUNET_CRYPTO_EcdsaPublicKey *cid) | 1521 | struct GNUNET_CRYPTO_EcdsaPublicKey *cid) |
1521 | { | 1522 | { |
1522 | struct GNUNET_HashCode cache_key; | 1523 | struct GNUNET_HashCode cache_key; |
1523 | char *authorization; | 1524 | char *authorization; |
@@ -1527,146 +1528,146 @@ check_authorization (struct RequestHandle *handle, | |||
1527 | char *pass; | 1528 | char *pass; |
1528 | char *expected_pass; | 1529 | char *expected_pass; |
1529 | 1530 | ||
1530 | GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, | 1531 | GNUNET_CRYPTO_hash(OIDC_AUTHORIZATION_HEADER_KEY, |
1531 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), | 1532 | strlen(OIDC_AUTHORIZATION_HEADER_KEY), |
1532 | &cache_key); | 1533 | &cache_key); |
1533 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1534 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle |
1534 | ->header_param_map, | 1535 | ->header_param_map, |
1535 | &cache_key)) | 1536 | &cache_key)) |
1536 | { | 1537 | { |
1537 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1538 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1538 | handle->edesc = GNUNET_strdup ("missing authorization"); | 1539 | handle->edesc = GNUNET_strdup("missing authorization"); |
1539 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1540 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1540 | return GNUNET_SYSERR; | 1541 | return GNUNET_SYSERR; |
1541 | } | 1542 | } |
1542 | authorization = | 1543 | authorization = |
1543 | GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map, | 1544 | GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->header_param_map, |
1544 | &cache_key); | 1545 | &cache_key); |
1545 | 1546 | ||
1546 | // split header in "Basic" and [content] | 1547 | // split header in "Basic" and [content] |
1547 | credentials = strtok (authorization, " "); | 1548 | credentials = strtok(authorization, " "); |
1548 | if ((NULL == credentials) || (0 != strcmp ("Basic", credentials))) | 1549 | if ((NULL == credentials) || (0 != strcmp("Basic", credentials))) |
1549 | { | 1550 | { |
1550 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1551 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1551 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1552 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1552 | return GNUNET_SYSERR; | 1553 | return GNUNET_SYSERR; |
1553 | } | 1554 | } |
1554 | credentials = strtok (NULL, " "); | 1555 | credentials = strtok(NULL, " "); |
1555 | if (NULL == credentials) | 1556 | if (NULL == credentials) |
1556 | { | 1557 | { |
1557 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1558 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1558 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1559 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1559 | return GNUNET_SYSERR; | 1560 | return GNUNET_SYSERR; |
1560 | } | 1561 | } |
1561 | GNUNET_STRINGS_base64_decode (credentials, | 1562 | GNUNET_STRINGS_base64_decode(credentials, |
1562 | strlen (credentials), | 1563 | strlen(credentials), |
1563 | (void **) &basic_authorization); | 1564 | (void **)&basic_authorization); |
1564 | 1565 | ||
1565 | if (NULL == basic_authorization) | 1566 | if (NULL == basic_authorization) |
1566 | { | 1567 | { |
1567 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1568 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1568 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1569 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1569 | return GNUNET_SYSERR; | 1570 | return GNUNET_SYSERR; |
1570 | } | 1571 | } |
1571 | client_id = strtok (basic_authorization, ":"); | 1572 | client_id = strtok(basic_authorization, ":"); |
1572 | if (NULL == client_id) | 1573 | if (NULL == client_id) |
1573 | { | 1574 | { |
1574 | GNUNET_free_non_null (basic_authorization); | 1575 | GNUNET_free_non_null(basic_authorization); |
1575 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1576 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1576 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1577 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1577 | return GNUNET_SYSERR; | 1578 | return GNUNET_SYSERR; |
1578 | } | 1579 | } |
1579 | pass = strtok (NULL, ":"); | 1580 | pass = strtok(NULL, ":"); |
1580 | if (NULL == pass) | 1581 | if (NULL == pass) |
1581 | { | 1582 | { |
1582 | GNUNET_free_non_null (basic_authorization); | 1583 | GNUNET_free_non_null(basic_authorization); |
1583 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1584 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1584 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | ||
1585 | return GNUNET_SYSERR; | ||
1586 | } | ||
1587 | |||
1588 | // check client password | ||
1589 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1590 | "reclaim-rest-plugin", | ||
1591 | "OIDC_CLIENT_SECRET", | ||
1592 | &expected_pass)) | ||
1593 | { | ||
1594 | if (0 != strcmp (expected_pass, pass)) | ||
1595 | { | ||
1596 | GNUNET_free_non_null (basic_authorization); | ||
1597 | GNUNET_free (expected_pass); | ||
1598 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | ||
1599 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1585 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1600 | return GNUNET_SYSERR; | 1586 | return GNUNET_SYSERR; |
1601 | } | 1587 | } |
1602 | GNUNET_free (expected_pass); | 1588 | |
1603 | } | 1589 | // check client password |
1590 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, | ||
1591 | "reclaim-rest-plugin", | ||
1592 | "OIDC_CLIENT_SECRET", | ||
1593 | &expected_pass)) | ||
1594 | { | ||
1595 | if (0 != strcmp(expected_pass, pass)) | ||
1596 | { | ||
1597 | GNUNET_free_non_null(basic_authorization); | ||
1598 | GNUNET_free(expected_pass); | ||
1599 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); | ||
1600 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | ||
1601 | return GNUNET_SYSERR; | ||
1602 | } | ||
1603 | GNUNET_free(expected_pass); | ||
1604 | } | ||
1604 | else | 1605 | else |
1605 | { | 1606 | { |
1606 | GNUNET_free_non_null (basic_authorization); | 1607 | GNUNET_free_non_null(basic_authorization); |
1607 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 1608 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); |
1608 | handle->edesc = GNUNET_strdup ("gnunet configuration failed"); | 1609 | handle->edesc = GNUNET_strdup("gnunet configuration failed"); |
1609 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 1610 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
1610 | return GNUNET_SYSERR; | 1611 | return GNUNET_SYSERR; |
1611 | } | 1612 | } |
1612 | 1613 | ||
1613 | // check client_id | 1614 | // check client_id |
1614 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; | 1615 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; |
1615 | handle->ego_entry = handle->ego_entry->next) | 1616 | handle->ego_entry = handle->ego_entry->next) |
1616 | { | 1617 | { |
1617 | if (0 == strcmp (handle->ego_entry->keystring, client_id)) | 1618 | if (0 == strcmp(handle->ego_entry->keystring, client_id)) |
1618 | break; | 1619 | break; |
1619 | } | 1620 | } |
1620 | if (NULL == handle->ego_entry) | 1621 | if (NULL == handle->ego_entry) |
1621 | { | 1622 | { |
1622 | GNUNET_free_non_null (basic_authorization); | 1623 | GNUNET_free_non_null(basic_authorization); |
1623 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1624 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_CLIENT); |
1624 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1625 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1625 | return GNUNET_SYSERR; | 1626 | return GNUNET_SYSERR; |
1626 | } | 1627 | } |
1627 | GNUNET_STRINGS_string_to_data (client_id, | 1628 | GNUNET_STRINGS_string_to_data(client_id, |
1628 | strlen (client_id), | 1629 | strlen(client_id), |
1629 | cid, | 1630 | cid, |
1630 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1631 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
1631 | 1632 | ||
1632 | GNUNET_free (basic_authorization); | 1633 | GNUNET_free(basic_authorization); |
1633 | return GNUNET_OK; | 1634 | return GNUNET_OK; |
1634 | } | 1635 | } |
1635 | 1636 | ||
1636 | const struct EgoEntry * | 1637 | const struct EgoEntry * |
1637 | find_ego (struct RequestHandle *handle, | 1638 | find_ego(struct RequestHandle *handle, |
1638 | struct GNUNET_CRYPTO_EcdsaPublicKey *test_key) | 1639 | struct GNUNET_CRYPTO_EcdsaPublicKey *test_key) |
1639 | { | 1640 | { |
1640 | struct EgoEntry *ego_entry; | 1641 | struct EgoEntry *ego_entry; |
1641 | struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; | 1642 | struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; |
1642 | 1643 | ||
1643 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1644 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
1644 | ego_entry = ego_entry->next) | 1645 | ego_entry = ego_entry->next) |
1645 | { | 1646 | { |
1646 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key); | 1647 | GNUNET_IDENTITY_ego_get_public_key(ego_entry->ego, &pub_key); |
1647 | if (0 == GNUNET_memcmp (&pub_key, test_key)) | 1648 | if (0 == GNUNET_memcmp(&pub_key, test_key)) |
1648 | return ego_entry; | 1649 | return ego_entry; |
1649 | } | 1650 | } |
1650 | return NULL; | 1651 | return NULL; |
1651 | } | 1652 | } |
1652 | 1653 | ||
1653 | static void | 1654 | static void |
1654 | persist_access_token (const struct RequestHandle *handle, | 1655 | persist_access_token(const struct RequestHandle *handle, |
1655 | const char *access_token, | 1656 | const char *access_token, |
1656 | const struct GNUNET_RECLAIM_Ticket *ticket) | 1657 | const struct GNUNET_RECLAIM_Ticket *ticket) |
1657 | { | 1658 | { |
1658 | struct GNUNET_HashCode hc; | 1659 | struct GNUNET_HashCode hc; |
1659 | struct GNUNET_RECLAIM_Ticket *ticketbuf; | 1660 | struct GNUNET_RECLAIM_Ticket *ticketbuf; |
1660 | 1661 | ||
1661 | GNUNET_CRYPTO_hash (access_token, strlen (access_token), &hc); | 1662 | GNUNET_CRYPTO_hash(access_token, strlen(access_token), &hc); |
1662 | ticketbuf = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 1663 | ticketbuf = GNUNET_new(struct GNUNET_RECLAIM_Ticket); |
1663 | *ticketbuf = *ticket; | 1664 | *ticketbuf = *ticket; |
1664 | GNUNET_assert (GNUNET_SYSERR != | 1665 | GNUNET_assert(GNUNET_SYSERR != |
1665 | GNUNET_CONTAINER_multihashmap_put ( | 1666 | GNUNET_CONTAINER_multihashmap_put( |
1666 | OIDC_access_token_map, | 1667 | OIDC_access_token_map, |
1667 | &hc, | 1668 | &hc, |
1668 | ticketbuf, | 1669 | ticketbuf, |
1669 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1670 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1670 | } | 1671 | } |
1671 | 1672 | ||
1672 | /** | 1673 | /** |
@@ -1677,9 +1678,9 @@ persist_access_token (const struct RequestHandle *handle, | |||
1677 | * @param cls the RequestHandle | 1678 | * @param cls the RequestHandle |
1678 | */ | 1679 | */ |
1679 | static void | 1680 | static void |
1680 | token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | 1681 | token_endpoint(struct GNUNET_REST_RequestHandle *con_handle, |
1681 | const char *url, | 1682 | const char *url, |
1682 | void *cls) | 1683 | void *cls) |
1683 | { | 1684 | { |
1684 | struct RequestHandle *handle = cls; | 1685 | struct RequestHandle *handle = cls; |
1685 | const struct EgoEntry *ego_entry; | 1686 | const struct EgoEntry *ego_entry; |
@@ -1698,16 +1699,17 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1698 | char *jwt_secret; | 1699 | char *jwt_secret; |
1699 | char *nonce; | 1700 | char *nonce; |
1700 | char *code_verifier; | 1701 | char *code_verifier; |
1702 | |||
1701 | /* | 1703 | /* |
1702 | * Check Authorization | 1704 | * Check Authorization |
1703 | */ | 1705 | */ |
1704 | if (GNUNET_SYSERR == check_authorization (handle, &cid)) | 1706 | if (GNUNET_SYSERR == check_authorization(handle, &cid)) |
1705 | { | 1707 | { |
1706 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1708 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1707 | "OIDC authorization for token endpoint failed\n"); | 1709 | "OIDC authorization for token endpoint failed\n"); |
1708 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1710 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1709 | return; | 1711 | return; |
1710 | } | 1712 | } |
1711 | 1713 | ||
1712 | /* | 1714 | /* |
1713 | * Check parameter | 1715 | * Check parameter |
@@ -1715,148 +1717,148 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1715 | 1717 | ||
1716 | // TODO Do not allow multiple equal parameter names | 1718 | // TODO Do not allow multiple equal parameter names |
1717 | // REQUIRED grant_type | 1719 | // REQUIRED grant_type |
1718 | GNUNET_CRYPTO_hash (OIDC_GRANT_TYPE_KEY, | 1720 | GNUNET_CRYPTO_hash(OIDC_GRANT_TYPE_KEY, |
1719 | strlen (OIDC_GRANT_TYPE_KEY), | 1721 | strlen(OIDC_GRANT_TYPE_KEY), |
1720 | &cache_key); | 1722 | &cache_key); |
1721 | grant_type = get_url_parameter_copy (handle, OIDC_GRANT_TYPE_KEY); | 1723 | grant_type = get_url_parameter_copy(handle, OIDC_GRANT_TYPE_KEY); |
1722 | if (NULL == grant_type) | 1724 | if (NULL == grant_type) |
1723 | { | 1725 | { |
1724 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1726 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1725 | handle->edesc = GNUNET_strdup ("missing parameter grant_type"); | 1727 | handle->edesc = GNUNET_strdup("missing parameter grant_type"); |
1726 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1728 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1727 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1729 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1728 | return; | 1730 | return; |
1729 | } | 1731 | } |
1730 | 1732 | ||
1731 | // Check parameter grant_type == "authorization_code" | 1733 | // Check parameter grant_type == "authorization_code" |
1732 | if (0 != strcmp (OIDC_GRANT_TYPE_VALUE, grant_type)) | 1734 | if (0 != strcmp(OIDC_GRANT_TYPE_VALUE, grant_type)) |
1733 | { | 1735 | { |
1734 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE); | 1736 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE); |
1735 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1737 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1736 | GNUNET_free (grant_type); | 1738 | GNUNET_free(grant_type); |
1737 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1739 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1738 | return; | 1740 | return; |
1739 | } | 1741 | } |
1740 | GNUNET_free (grant_type); | 1742 | GNUNET_free(grant_type); |
1741 | // REQUIRED code | 1743 | // REQUIRED code |
1742 | code = get_url_parameter_copy (handle, OIDC_CODE_KEY); | 1744 | code = get_url_parameter_copy(handle, OIDC_CODE_KEY); |
1743 | if (NULL == code) | 1745 | if (NULL == code) |
1744 | { | 1746 | { |
1745 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1747 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1746 | handle->edesc = GNUNET_strdup ("missing parameter code"); | 1748 | handle->edesc = GNUNET_strdup("missing parameter code"); |
1747 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1749 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1748 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1750 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1749 | return; | 1751 | return; |
1750 | } | 1752 | } |
1751 | ego_entry = find_ego (handle, &cid); | 1753 | ego_entry = find_ego(handle, &cid); |
1752 | if (NULL == ego_entry) | 1754 | if (NULL == ego_entry) |
1753 | { | 1755 | { |
1754 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1756 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1755 | handle->edesc = GNUNET_strdup ("Unknown client"); | 1757 | handle->edesc = GNUNET_strdup("Unknown client"); |
1756 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1758 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1757 | GNUNET_free (code); | 1759 | GNUNET_free(code); |
1758 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1760 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1759 | return; | 1761 | return; |
1760 | } | 1762 | } |
1761 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1763 | privkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
1762 | 1764 | ||
1763 | // REQUIRED code verifier | 1765 | // REQUIRED code verifier |
1764 | code_verifier = get_url_parameter_copy (handle, OIDC_CODE_VERIFIER_KEY); | 1766 | code_verifier = get_url_parameter_copy(handle, OIDC_CODE_VERIFIER_KEY); |
1765 | if (NULL == code_verifier) | 1767 | if (NULL == code_verifier) |
1766 | { | 1768 | { |
1767 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1769 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1768 | handle->edesc = GNUNET_strdup ("missing parameter code_verifier"); | 1770 | handle->edesc = GNUNET_strdup("missing parameter code_verifier"); |
1769 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1771 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1770 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1772 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1771 | return; | 1773 | return; |
1772 | } | 1774 | } |
1773 | 1775 | ||
1774 | // decode code | 1776 | // decode code |
1775 | if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket, &cl, &nonce)) | 1777 | if (GNUNET_OK != OIDC_parse_authz_code(privkey, code, code_verifier, &ticket, &cl, &nonce)) |
1776 | { | 1778 | { |
1777 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1779 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1778 | handle->edesc = GNUNET_strdup ("invalid code"); | 1780 | handle->edesc = GNUNET_strdup("invalid code"); |
1779 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1781 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1780 | GNUNET_free (code); | 1782 | GNUNET_free(code); |
1781 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1783 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1782 | return; | 1784 | return; |
1783 | } | 1785 | } |
1784 | GNUNET_free (code); | 1786 | GNUNET_free(code); |
1785 | 1787 | ||
1786 | // create jwt | 1788 | // create jwt |
1787 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | 1789 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, |
1788 | "reclaim-rest-plugin", | 1790 | "reclaim-rest-plugin", |
1789 | "expiration_time", | 1791 | "expiration_time", |
1790 | &expiration_time)) | 1792 | &expiration_time)) |
1791 | { | 1793 | { |
1792 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR); | 1794 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_SERVER_ERROR); |
1793 | handle->edesc = GNUNET_strdup ("gnunet configuration failed"); | 1795 | handle->edesc = GNUNET_strdup("gnunet configuration failed"); |
1794 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 1796 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
1795 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1797 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1796 | return; | 1798 | return; |
1797 | } | 1799 | } |
1798 | 1800 | ||
1799 | 1801 | ||
1800 | // TODO OPTIONAL acr,amr,azp | 1802 | // TODO OPTIONAL acr,amr,azp |
1801 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | 1803 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, |
1802 | "reclaim-rest-plugin", | 1804 | "reclaim-rest-plugin", |
1803 | "jwt_secret", | 1805 | "jwt_secret", |
1804 | &jwt_secret)) | 1806 | &jwt_secret)) |
1805 | { | 1807 | { |
1806 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1808 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_REQUEST); |
1807 | handle->edesc = GNUNET_strdup ("No signing secret configured!"); | 1809 | handle->edesc = GNUNET_strdup("No signing secret configured!"); |
1808 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 1810 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
1809 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1811 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1810 | return; | 1812 | return; |
1811 | } | 1813 | } |
1812 | id_token = OIDC_id_token_new (&ticket.audience, | 1814 | id_token = OIDC_id_token_new(&ticket.audience, |
1813 | &ticket.identity, | 1815 | &ticket.identity, |
1814 | cl, | 1816 | cl, |
1815 | &expiration_time, | 1817 | &expiration_time, |
1816 | (NULL != nonce) ? nonce : NULL, | 1818 | (NULL != nonce) ? nonce : NULL, |
1817 | jwt_secret); | 1819 | jwt_secret); |
1818 | access_token = OIDC_access_token_new (); | 1820 | access_token = OIDC_access_token_new(); |
1819 | OIDC_build_token_response (access_token, | 1821 | OIDC_build_token_response(access_token, |
1820 | id_token, | 1822 | id_token, |
1821 | &expiration_time, | 1823 | &expiration_time, |
1822 | &json_response); | 1824 | &json_response); |
1823 | 1825 | ||
1824 | persist_access_token (handle, access_token, &ticket); | 1826 | persist_access_token(handle, access_token, &ticket); |
1825 | resp = GNUNET_REST_create_response (json_response); | 1827 | resp = GNUNET_REST_create_response(json_response); |
1826 | MHD_add_response_header (resp, "Cache-Control", "no-store"); | 1828 | MHD_add_response_header(resp, "Cache-Control", "no-store"); |
1827 | MHD_add_response_header (resp, "Pragma", "no-cache"); | 1829 | MHD_add_response_header(resp, "Pragma", "no-cache"); |
1828 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 1830 | MHD_add_response_header(resp, "Content-Type", "application/json"); |
1829 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 1831 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
1830 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (cl); | 1832 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy(cl); |
1831 | GNUNET_free (access_token); | 1833 | GNUNET_free(access_token); |
1832 | GNUNET_free (json_response); | 1834 | GNUNET_free(json_response); |
1833 | GNUNET_free (id_token); | 1835 | GNUNET_free(id_token); |
1834 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 1836 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
1835 | } | 1837 | } |
1836 | 1838 | ||
1837 | /** | 1839 | /** |
1838 | * Collects claims and stores them in handle | 1840 | * Collects claims and stores them in handle |
1839 | */ | 1841 | */ |
1840 | static void | 1842 | static void |
1841 | consume_ticket (void *cls, | 1843 | consume_ticket(void *cls, |
1842 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1844 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
1843 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 1845 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
1844 | { | 1846 | { |
1845 | struct RequestHandle *handle = cls; | 1847 | struct RequestHandle *handle = cls; |
1846 | char *tmp_value; | 1848 | char *tmp_value; |
1847 | json_t *value; | 1849 | json_t *value; |
1848 | 1850 | ||
1849 | if (NULL == identity) | 1851 | if (NULL == identity) |
1850 | { | 1852 | { |
1851 | GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle); | 1853 | GNUNET_SCHEDULER_add_now(&return_userinfo_response, handle); |
1852 | return; | 1854 | return; |
1853 | } | 1855 | } |
1854 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 1856 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
1855 | attr->data, | 1857 | attr->data, |
1856 | attr->data_size); | 1858 | attr->data_size); |
1857 | value = json_string (tmp_value); | 1859 | value = json_string(tmp_value); |
1858 | json_object_set_new (handle->oidc->response, attr->name, value); | 1860 | json_object_set_new(handle->oidc->response, attr->name, value); |
1859 | GNUNET_free (tmp_value); | 1861 | GNUNET_free(tmp_value); |
1860 | } | 1862 | } |
1861 | 1863 | ||
1862 | /** | 1864 | /** |
@@ -1867,9 +1869,9 @@ consume_ticket (void *cls, | |||
1867 | * @param cls the RequestHandle | 1869 | * @param cls the RequestHandle |
1868 | */ | 1870 | */ |
1869 | static void | 1871 | static void |
1870 | userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | 1872 | userinfo_endpoint(struct GNUNET_REST_RequestHandle *con_handle, |
1871 | const char *url, | 1873 | const char *url, |
1872 | void *cls) | 1874 | void *cls) |
1873 | { | 1875 | { |
1874 | // TODO expiration time | 1876 | // TODO expiration time |
1875 | struct RequestHandle *handle = cls; | 1877 | struct RequestHandle *handle = cls; |
@@ -1882,87 +1884,87 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1882 | const struct EgoEntry *ego_entry; | 1884 | const struct EgoEntry *ego_entry; |
1883 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 1885 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; |
1884 | 1886 | ||
1885 | GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, | 1887 | GNUNET_CRYPTO_hash(OIDC_AUTHORIZATION_HEADER_KEY, |
1886 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), | 1888 | strlen(OIDC_AUTHORIZATION_HEADER_KEY), |
1887 | &cache_key); | 1889 | &cache_key); |
1888 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1890 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle |
1889 | ->header_param_map, | 1891 | ->header_param_map, |
1890 | &cache_key)) | 1892 | &cache_key)) |
1891 | { | 1893 | { |
1892 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1894 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_TOKEN); |
1893 | handle->edesc = GNUNET_strdup ("No Access Token"); | 1895 | handle->edesc = GNUNET_strdup("No Access Token"); |
1894 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1896 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1895 | GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle); | 1897 | GNUNET_SCHEDULER_add_now(&do_userinfo_error, handle); |
1896 | return; | 1898 | return; |
1897 | } | 1899 | } |
1898 | authorization = | 1900 | authorization = |
1899 | GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map, | 1901 | GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->header_param_map, |
1900 | &cache_key); | 1902 | &cache_key); |
1901 | 1903 | ||
1902 | // split header in "Bearer" and access_token | 1904 | // split header in "Bearer" and access_token |
1903 | authorization = GNUNET_strdup (authorization); | 1905 | authorization = GNUNET_strdup(authorization); |
1904 | authorization_type = strtok (authorization, delimiter); | 1906 | authorization_type = strtok(authorization, delimiter); |
1905 | if ((NULL == authorization_type) || | 1907 | if ((NULL == authorization_type) || |
1906 | (0 != strcmp ("Bearer", authorization_type))) | 1908 | (0 != strcmp("Bearer", authorization_type))) |
1907 | { | 1909 | { |
1908 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1910 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_TOKEN); |
1909 | handle->edesc = GNUNET_strdup ("No Access Token"); | 1911 | handle->edesc = GNUNET_strdup("No Access Token"); |
1910 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1912 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1911 | GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle); | 1913 | GNUNET_SCHEDULER_add_now(&do_userinfo_error, handle); |
1912 | GNUNET_free (authorization); | 1914 | GNUNET_free(authorization); |
1913 | return; | 1915 | return; |
1914 | } | 1916 | } |
1915 | authorization_access_token = strtok (NULL, delimiter); | 1917 | authorization_access_token = strtok(NULL, delimiter); |
1916 | if (NULL == authorization_access_token) | 1918 | if (NULL == authorization_access_token) |
1917 | { | 1919 | { |
1918 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1920 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_TOKEN); |
1919 | handle->edesc = GNUNET_strdup ("Access token missing"); | 1921 | handle->edesc = GNUNET_strdup("Access token missing"); |
1920 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1922 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1921 | GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle); | 1923 | GNUNET_SCHEDULER_add_now(&do_userinfo_error, handle); |
1922 | GNUNET_free (authorization); | 1924 | GNUNET_free(authorization); |
1923 | return; | 1925 | return; |
1924 | } | 1926 | } |
1925 | 1927 | ||
1926 | GNUNET_CRYPTO_hash (authorization_access_token, | 1928 | GNUNET_CRYPTO_hash(authorization_access_token, |
1927 | strlen (authorization_access_token), | 1929 | strlen(authorization_access_token), |
1928 | &cache_key); | 1930 | &cache_key); |
1929 | if (GNUNET_NO == | 1931 | if (GNUNET_NO == |
1930 | GNUNET_CONTAINER_multihashmap_contains (OIDC_access_token_map, | 1932 | GNUNET_CONTAINER_multihashmap_contains(OIDC_access_token_map, |
1931 | &cache_key)) | 1933 | &cache_key)) |
1932 | { | 1934 | { |
1933 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1935 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_TOKEN); |
1934 | handle->edesc = GNUNET_strdup ("The access token expired"); | 1936 | handle->edesc = GNUNET_strdup("The access token expired"); |
1935 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1937 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1936 | GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle); | 1938 | GNUNET_SCHEDULER_add_now(&do_userinfo_error, handle); |
1937 | GNUNET_free (authorization); | 1939 | GNUNET_free(authorization); |
1938 | return; | 1940 | return; |
1939 | } | 1941 | } |
1940 | ticket = | 1942 | ticket = |
1941 | GNUNET_CONTAINER_multihashmap_get (OIDC_access_token_map, &cache_key); | 1943 | GNUNET_CONTAINER_multihashmap_get(OIDC_access_token_map, &cache_key); |
1942 | GNUNET_assert (NULL != ticket); | 1944 | GNUNET_assert(NULL != ticket); |
1943 | ego_entry = find_ego (handle, &ticket->audience); | 1945 | ego_entry = find_ego(handle, &ticket->audience); |
1944 | if (NULL == ego_entry) | 1946 | if (NULL == ego_entry) |
1945 | { | 1947 | { |
1946 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1948 | handle->emsg = GNUNET_strdup(OIDC_ERROR_KEY_INVALID_TOKEN); |
1947 | handle->edesc = GNUNET_strdup ("The access token expired"); | 1949 | handle->edesc = GNUNET_strdup("The access token expired"); |
1948 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1950 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1949 | GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle); | 1951 | GNUNET_SCHEDULER_add_now(&do_userinfo_error, handle); |
1950 | GNUNET_free (authorization); | 1952 | GNUNET_free(authorization); |
1951 | return; | 1953 | return; |
1952 | } | 1954 | } |
1953 | 1955 | ||
1954 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 1956 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
1955 | handle->oidc->response = json_object (); | 1957 | handle->oidc->response = json_object(); |
1956 | json_object_set_new (handle->oidc->response, | 1958 | json_object_set_new(handle->oidc->response, |
1957 | "sub", | 1959 | "sub", |
1958 | json_string (ego_entry->keystring)); | 1960 | json_string(ego_entry->keystring)); |
1959 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1961 | privkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
1960 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, | 1962 | handle->idp_op = GNUNET_RECLAIM_ticket_consume(handle->idp, |
1961 | privkey, | 1963 | privkey, |
1962 | ticket, | 1964 | ticket, |
1963 | consume_ticket, | 1965 | consume_ticket, |
1964 | handle); | 1966 | handle); |
1965 | GNUNET_free (authorization); | 1967 | GNUNET_free(authorization); |
1966 | } | 1968 | } |
1967 | 1969 | ||
1968 | 1970 | ||
@@ -1972,27 +1974,27 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1972 | * @param handle the request handle | 1974 | * @param handle the request handle |
1973 | */ | 1975 | */ |
1974 | static void | 1976 | static void |
1975 | init_cont (struct RequestHandle *handle) | 1977 | init_cont(struct RequestHandle *handle) |
1976 | { | 1978 | { |
1977 | struct GNUNET_REST_RequestHandlerError err; | 1979 | struct GNUNET_REST_RequestHandlerError err; |
1978 | static const struct GNUNET_REST_RequestHandler handlers[] = | 1980 | static const struct GNUNET_REST_RequestHandler handlers[] = |
1979 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint}, | 1981 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, |
1980 | {MHD_HTTP_METHOD_POST, | 1982 | { MHD_HTTP_METHOD_POST, |
1981 | GNUNET_REST_API_NS_AUTHORIZE, | 1983 | GNUNET_REST_API_NS_AUTHORIZE, |
1982 | &authorize_endpoint}, // url-encoded | 1984 | &authorize_endpoint }, // url-encoded |
1983 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont}, | 1985 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont }, |
1984 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint}, | 1986 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint }, |
1985 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, | 1987 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, |
1986 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, | 1988 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, |
1987 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont}, | 1989 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont }, |
1988 | GNUNET_REST_HANDLER_END}; | 1990 | GNUNET_REST_HANDLER_END }; |
1989 | 1991 | ||
1990 | if (GNUNET_NO == | 1992 | if (GNUNET_NO == |
1991 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 1993 | GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) |
1992 | { | 1994 | { |
1993 | handle->response_code = err.error_code; | 1995 | handle->response_code = err.error_code; |
1994 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1996 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1995 | } | 1997 | } |
1996 | } | 1998 | } |
1997 | 1999 | ||
1998 | /** | 2000 | /** |
@@ -2029,90 +2031,91 @@ init_cont (struct RequestHandle *handle) | |||
2029 | * must thus no longer be used | 2031 | * must thus no longer be used |
2030 | */ | 2032 | */ |
2031 | static void | 2033 | static void |
2032 | list_ego (void *cls, | 2034 | list_ego(void *cls, |
2033 | struct GNUNET_IDENTITY_Ego *ego, | 2035 | struct GNUNET_IDENTITY_Ego *ego, |
2034 | void **ctx, | 2036 | void **ctx, |
2035 | const char *identifier) | 2037 | const char *identifier) |
2036 | { | 2038 | { |
2037 | struct RequestHandle *handle = cls; | 2039 | struct RequestHandle *handle = cls; |
2038 | struct EgoEntry *ego_entry; | 2040 | struct EgoEntry *ego_entry; |
2039 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 2041 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
2040 | 2042 | ||
2041 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 2043 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
2042 | { | 2044 | { |
2043 | handle->state = ID_REST_STATE_POST_INIT; | 2045 | handle->state = ID_REST_STATE_POST_INIT; |
2044 | init_cont (handle); | 2046 | init_cont(handle); |
2045 | return; | 2047 | return; |
2046 | } | 2048 | } |
2047 | GNUNET_assert (NULL != ego); | 2049 | GNUNET_assert(NULL != ego); |
2048 | if (ID_REST_STATE_INIT == handle->state) | 2050 | if (ID_REST_STATE_INIT == handle->state) |
2049 | 2051 | ||
2050 | { | 2052 | { |
2051 | ego_entry = GNUNET_new (struct EgoEntry); | 2053 | ego_entry = GNUNET_new(struct EgoEntry); |
2052 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 2054 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); |
2053 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2055 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); |
2054 | ego_entry->ego = ego; | 2056 | ego_entry->ego = ego; |
2055 | ego_entry->identifier = GNUNET_strdup (identifier); | 2057 | ego_entry->identifier = GNUNET_strdup(identifier); |
2056 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 2058 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, |
2057 | handle->ego_tail, | 2059 | handle->ego_tail, |
2058 | ego_entry); | 2060 | ego_entry); |
2059 | return; | 2061 | return; |
2060 | } | 2062 | } |
2061 | /* Ego renamed or added */ | 2063 | /* Ego renamed or added */ |
2062 | if (identifier != NULL) | 2064 | if (identifier != NULL) |
2063 | { | ||
2064 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
2065 | ego_entry = ego_entry->next) | ||
2066 | { | ||
2067 | if (ego_entry->ego == ego) | ||
2068 | { | ||
2069 | /* Rename */ | ||
2070 | GNUNET_free (ego_entry->identifier); | ||
2071 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
2072 | break; | ||
2073 | } | ||
2074 | } | ||
2075 | if (NULL == ego_entry) | ||
2076 | { | 2065 | { |
2077 | /* Add */ | 2066 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
2078 | ego_entry = GNUNET_new (struct EgoEntry); | 2067 | ego_entry = ego_entry->next) |
2079 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 2068 | { |
2080 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2069 | if (ego_entry->ego == ego) |
2081 | ego_entry->ego = ego; | 2070 | { |
2082 | ego_entry->identifier = GNUNET_strdup (identifier); | 2071 | /* Rename */ |
2083 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 2072 | GNUNET_free(ego_entry->identifier); |
2084 | handle->ego_tail, | 2073 | ego_entry->identifier = GNUNET_strdup(identifier); |
2085 | ego_entry); | 2074 | break; |
2075 | } | ||
2076 | } | ||
2077 | if (NULL == ego_entry) | ||
2078 | { | ||
2079 | /* Add */ | ||
2080 | ego_entry = GNUNET_new(struct EgoEntry); | ||
2081 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); | ||
2082 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); | ||
2083 | ego_entry->ego = ego; | ||
2084 | ego_entry->identifier = GNUNET_strdup(identifier); | ||
2085 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, | ||
2086 | handle->ego_tail, | ||
2087 | ego_entry); | ||
2088 | } | ||
2086 | } | 2089 | } |
2087 | } | ||
2088 | else | 2090 | else |
2089 | { | ||
2090 | /* Delete */ | ||
2091 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
2092 | ego_entry = ego_entry->next) | ||
2093 | { | 2091 | { |
2094 | if (ego_entry->ego == ego) | 2092 | /* Delete */ |
2095 | break; | 2093 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
2094 | ego_entry = ego_entry->next) | ||
2095 | { | ||
2096 | if (ego_entry->ego == ego) | ||
2097 | break; | ||
2098 | } | ||
2099 | if (NULL != ego_entry) | ||
2100 | GNUNET_CONTAINER_DLL_remove(handle->ego_head, | ||
2101 | handle->ego_tail, | ||
2102 | ego_entry); | ||
2096 | } | 2103 | } |
2097 | if (NULL != ego_entry) | ||
2098 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | ||
2099 | handle->ego_tail, | ||
2100 | ego_entry); | ||
2101 | } | ||
2102 | } | 2104 | } |
2103 | 2105 | ||
2104 | static void | 2106 | static void |
2105 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 2107 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
2106 | GNUNET_REST_ResultProcessor proc, | 2108 | GNUNET_REST_ResultProcessor proc, |
2107 | void *proc_cls) | 2109 | void *proc_cls) |
2108 | { | 2110 | { |
2109 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 2111 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); |
2110 | handle->oidc = GNUNET_new (struct OIDC_Variables); | 2112 | |
2113 | handle->oidc = GNUNET_new(struct OIDC_Variables); | ||
2111 | if (NULL == OIDC_cookie_jar_map) | 2114 | if (NULL == OIDC_cookie_jar_map) |
2112 | OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 2115 | OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); |
2113 | if (NULL == OIDC_access_token_map) | 2116 | if (NULL == OIDC_access_token_map) |
2114 | OIDC_access_token_map = | 2117 | OIDC_access_token_map = |
2115 | GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 2118 | GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); |
2116 | handle->response_code = 0; | 2119 | handle->response_code = 0; |
2117 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 2120 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
2118 | handle->proc_cls = proc_cls; | 2121 | handle->proc_cls = proc_cls; |
@@ -2120,16 +2123,16 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
2120 | handle->state = ID_REST_STATE_INIT; | 2123 | handle->state = ID_REST_STATE_INIT; |
2121 | handle->rest_handle = rest_handle; | 2124 | handle->rest_handle = rest_handle; |
2122 | 2125 | ||
2123 | handle->url = GNUNET_strdup (rest_handle->url); | 2126 | handle->url = GNUNET_strdup(rest_handle->url); |
2124 | if (handle->url[strlen (handle->url) - 1] == '/') | 2127 | if (handle->url[strlen(handle->url) - 1] == '/') |
2125 | handle->url[strlen (handle->url) - 1] = '\0'; | 2128 | handle->url[strlen(handle->url) - 1] = '\0'; |
2126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 2129 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
2127 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); | 2130 | handle->identity_handle = GNUNET_IDENTITY_connect(cfg, &list_ego, handle); |
2128 | handle->gns_handle = GNUNET_GNS_connect (cfg); | 2131 | handle->gns_handle = GNUNET_GNS_connect(cfg); |
2129 | handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg); | 2132 | handle->namestore_handle = GNUNET_NAMESTORE_connect(cfg); |
2130 | handle->timeout_task = | 2133 | handle->timeout_task = |
2131 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 2134 | GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_timeout, handle); |
2132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 2135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
2133 | } | 2136 | } |
2134 | 2137 | ||
2135 | /** | 2138 | /** |
@@ -2139,7 +2142,7 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
2139 | * @return NULL on error, otherwise the plugin context | 2142 | * @return NULL on error, otherwise the plugin context |
2140 | */ | 2143 | */ |
2141 | void * | 2144 | void * |
2142 | libgnunet_plugin_rest_openid_connect_init (void *cls) | 2145 | libgnunet_plugin_rest_openid_connect_init(void *cls) |
2143 | { | 2146 | { |
2144 | static struct Plugin plugin; | 2147 | static struct Plugin plugin; |
2145 | struct GNUNET_REST_Plugin *api; | 2148 | struct GNUNET_REST_Plugin *api; |
@@ -2147,22 +2150,22 @@ libgnunet_plugin_rest_openid_connect_init (void *cls) | |||
2147 | cfg = cls; | 2150 | cfg = cls; |
2148 | if (NULL != plugin.cfg) | 2151 | if (NULL != plugin.cfg) |
2149 | return NULL; /* can only initialize once! */ | 2152 | return NULL; /* can only initialize once! */ |
2150 | memset (&plugin, 0, sizeof (struct Plugin)); | 2153 | memset(&plugin, 0, sizeof(struct Plugin)); |
2151 | plugin.cfg = cfg; | 2154 | plugin.cfg = cfg; |
2152 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 2155 | api = GNUNET_new(struct GNUNET_REST_Plugin); |
2153 | api->cls = &plugin; | 2156 | api->cls = &plugin; |
2154 | api->name = GNUNET_REST_API_NS_OIDC; | 2157 | api->name = GNUNET_REST_API_NS_OIDC; |
2155 | api->process_request = &rest_identity_process_request; | 2158 | api->process_request = &rest_identity_process_request; |
2156 | GNUNET_asprintf (&allow_methods, | 2159 | GNUNET_asprintf(&allow_methods, |
2157 | "%s, %s, %s, %s, %s", | 2160 | "%s, %s, %s, %s, %s", |
2158 | MHD_HTTP_METHOD_GET, | 2161 | MHD_HTTP_METHOD_GET, |
2159 | MHD_HTTP_METHOD_POST, | 2162 | MHD_HTTP_METHOD_POST, |
2160 | MHD_HTTP_METHOD_PUT, | 2163 | MHD_HTTP_METHOD_PUT, |
2161 | MHD_HTTP_METHOD_DELETE, | 2164 | MHD_HTTP_METHOD_DELETE, |
2162 | MHD_HTTP_METHOD_OPTIONS); | 2165 | MHD_HTTP_METHOD_OPTIONS); |
2163 | 2166 | ||
2164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2167 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2165 | _ ("OpenID Connect REST API initialized\n")); | 2168 | _("OpenID Connect REST API initialized\n")); |
2166 | return api; | 2169 | return api; |
2167 | } | 2170 | } |
2168 | 2171 | ||
@@ -2174,33 +2177,34 @@ libgnunet_plugin_rest_openid_connect_init (void *cls) | |||
2174 | * @return always NULL | 2177 | * @return always NULL |
2175 | */ | 2178 | */ |
2176 | void * | 2179 | void * |
2177 | libgnunet_plugin_rest_openid_connect_done (void *cls) | 2180 | libgnunet_plugin_rest_openid_connect_done(void *cls) |
2178 | { | 2181 | { |
2179 | struct GNUNET_REST_Plugin *api = cls; | 2182 | struct GNUNET_REST_Plugin *api = cls; |
2180 | struct Plugin *plugin = api->cls; | 2183 | struct Plugin *plugin = api->cls; |
2184 | |||
2181 | plugin->cfg = NULL; | 2185 | plugin->cfg = NULL; |
2182 | 2186 | ||
2183 | struct GNUNET_CONTAINER_MultiHashMapIterator *hashmap_it; | 2187 | struct GNUNET_CONTAINER_MultiHashMapIterator *hashmap_it; |
2184 | void *value = NULL; | 2188 | void *value = NULL; |
2185 | hashmap_it = | 2189 | hashmap_it = |
2186 | GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_cookie_jar_map); | 2190 | GNUNET_CONTAINER_multihashmap_iterator_create(OIDC_cookie_jar_map); |
2187 | while (GNUNET_YES == | 2191 | while (GNUNET_YES == |
2188 | GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value)) | 2192 | GNUNET_CONTAINER_multihashmap_iterator_next(hashmap_it, NULL, value)) |
2189 | GNUNET_free_non_null (value); | 2193 | GNUNET_free_non_null(value); |
2190 | GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it); | 2194 | GNUNET_CONTAINER_multihashmap_iterator_destroy(hashmap_it); |
2191 | GNUNET_CONTAINER_multihashmap_destroy (OIDC_cookie_jar_map); | 2195 | GNUNET_CONTAINER_multihashmap_destroy(OIDC_cookie_jar_map); |
2192 | 2196 | ||
2193 | hashmap_it = | 2197 | hashmap_it = |
2194 | GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_access_token_map); | 2198 | GNUNET_CONTAINER_multihashmap_iterator_create(OIDC_access_token_map); |
2195 | while (GNUNET_YES == | 2199 | while (GNUNET_YES == |
2196 | GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL, value)) | 2200 | GNUNET_CONTAINER_multihashmap_iterator_next(hashmap_it, NULL, value)) |
2197 | GNUNET_free_non_null (value); | 2201 | GNUNET_free_non_null(value); |
2198 | GNUNET_CONTAINER_multihashmap_destroy (OIDC_access_token_map); | 2202 | GNUNET_CONTAINER_multihashmap_destroy(OIDC_access_token_map); |
2199 | GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it); | 2203 | GNUNET_CONTAINER_multihashmap_iterator_destroy(hashmap_it); |
2200 | GNUNET_free_non_null (allow_methods); | 2204 | GNUNET_free_non_null(allow_methods); |
2201 | GNUNET_free (api); | 2205 | GNUNET_free(api); |
2202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2203 | "OpenID Connect REST plugin is finished\n"); | 2207 | "OpenID Connect REST plugin is finished\n"); |
2204 | return NULL; | 2208 | return NULL; |
2205 | } | 2209 | } |
2206 | 2210 | ||
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 3f2577802..176f46ffc 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @author Philippe Buschmann | 22 | * @author Philippe Buschmann |
@@ -86,16 +86,14 @@ static char *allow_methods; | |||
86 | /** | 86 | /** |
87 | * @brief struct returned by the initialization function of the plugin | 87 | * @brief struct returned by the initialization function of the plugin |
88 | */ | 88 | */ |
89 | struct Plugin | 89 | struct Plugin { |
90 | { | ||
91 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 90 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
92 | }; | 91 | }; |
93 | 92 | ||
94 | /** | 93 | /** |
95 | * The ego list | 94 | * The ego list |
96 | */ | 95 | */ |
97 | struct EgoEntry | 96 | struct EgoEntry { |
98 | { | ||
99 | /** | 97 | /** |
100 | * DLL | 98 | * DLL |
101 | */ | 99 | */ |
@@ -123,8 +121,7 @@ struct EgoEntry | |||
123 | }; | 121 | }; |
124 | 122 | ||
125 | 123 | ||
126 | struct RequestHandle | 124 | struct RequestHandle { |
127 | { | ||
128 | /** | 125 | /** |
129 | * Ego list | 126 | * Ego list |
130 | */ | 127 | */ |
@@ -241,55 +238,56 @@ struct RequestHandle | |||
241 | * @param handle Handle to clean up | 238 | * @param handle Handle to clean up |
242 | */ | 239 | */ |
243 | static void | 240 | static void |
244 | cleanup_handle (struct RequestHandle *handle) | 241 | cleanup_handle(struct RequestHandle *handle) |
245 | { | 242 | { |
246 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; | 243 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; |
247 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; | 244 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; |
248 | struct EgoEntry *ego_entry; | 245 | struct EgoEntry *ego_entry; |
249 | struct EgoEntry *ego_tmp; | 246 | struct EgoEntry *ego_tmp; |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 247 | |
248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | ||
251 | if (NULL != handle->resp_object) | 249 | if (NULL != handle->resp_object) |
252 | json_decref (handle->resp_object); | 250 | json_decref(handle->resp_object); |
253 | if (NULL != handle->timeout_task) | 251 | if (NULL != handle->timeout_task) |
254 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 252 | GNUNET_SCHEDULER_cancel(handle->timeout_task); |
255 | if (NULL != handle->identity_handle) | 253 | if (NULL != handle->identity_handle) |
256 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | 254 | GNUNET_IDENTITY_disconnect(handle->identity_handle); |
257 | if (NULL != handle->attr_it) | 255 | if (NULL != handle->attr_it) |
258 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); | 256 | GNUNET_RECLAIM_get_attributes_stop(handle->attr_it); |
259 | if (NULL != handle->ticket_it) | 257 | if (NULL != handle->ticket_it) |
260 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); | 258 | GNUNET_RECLAIM_ticket_iteration_stop(handle->ticket_it); |
261 | if (NULL != handle->idp) | 259 | if (NULL != handle->idp) |
262 | GNUNET_RECLAIM_disconnect (handle->idp); | 260 | GNUNET_RECLAIM_disconnect(handle->idp); |
263 | if (NULL != handle->url) | 261 | if (NULL != handle->url) |
264 | GNUNET_free (handle->url); | 262 | GNUNET_free(handle->url); |
265 | if (NULL != handle->emsg) | 263 | if (NULL != handle->emsg) |
266 | GNUNET_free (handle->emsg); | 264 | GNUNET_free(handle->emsg); |
267 | if (NULL != handle->attr_list) | 265 | if (NULL != handle->attr_list) |
268 | { | ||
269 | for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) | ||
270 | { | 266 | { |
271 | claim_tmp = claim_entry; | 267 | for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) |
272 | claim_entry = claim_entry->next; | 268 | { |
273 | GNUNET_free (claim_tmp->claim); | 269 | claim_tmp = claim_entry; |
274 | GNUNET_free (claim_tmp); | 270 | claim_entry = claim_entry->next; |
271 | GNUNET_free(claim_tmp->claim); | ||
272 | GNUNET_free(claim_tmp); | ||
273 | } | ||
274 | GNUNET_free(handle->attr_list); | ||
275 | } | 275 | } |
276 | GNUNET_free (handle->attr_list); | ||
277 | } | ||
278 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 276 | for (ego_entry = handle->ego_head; NULL != ego_entry;) |
279 | { | 277 | { |
280 | ego_tmp = ego_entry; | 278 | ego_tmp = ego_entry; |
281 | ego_entry = ego_entry->next; | 279 | ego_entry = ego_entry->next; |
282 | GNUNET_free (ego_tmp->identifier); | 280 | GNUNET_free(ego_tmp->identifier); |
283 | GNUNET_free (ego_tmp->keystring); | 281 | GNUNET_free(ego_tmp->keystring); |
284 | GNUNET_free (ego_tmp); | 282 | GNUNET_free(ego_tmp); |
285 | } | 283 | } |
286 | GNUNET_free (handle); | 284 | GNUNET_free(handle); |
287 | } | 285 | } |
288 | 286 | ||
289 | static void | 287 | static void |
290 | cleanup_handle_delayed (void *cls) | 288 | cleanup_handle_delayed(void *cls) |
291 | { | 289 | { |
292 | cleanup_handle (cls); | 290 | cleanup_handle(cls); |
293 | } | 291 | } |
294 | 292 | ||
295 | 293 | ||
@@ -299,22 +297,22 @@ cleanup_handle_delayed (void *cls) | |||
299 | * @param cls the `struct RequestHandle` | 297 | * @param cls the `struct RequestHandle` |
300 | */ | 298 | */ |
301 | static void | 299 | static void |
302 | do_error (void *cls) | 300 | do_error(void *cls) |
303 | { | 301 | { |
304 | struct RequestHandle *handle = cls; | 302 | struct RequestHandle *handle = cls; |
305 | struct MHD_Response *resp; | 303 | struct MHD_Response *resp; |
306 | char *json_error; | 304 | char *json_error; |
307 | 305 | ||
308 | GNUNET_asprintf (&json_error, "{ \"error\" : \"%s\" }", handle->emsg); | 306 | GNUNET_asprintf(&json_error, "{ \"error\" : \"%s\" }", handle->emsg); |
309 | if (0 == handle->response_code) | 307 | if (0 == handle->response_code) |
310 | { | 308 | { |
311 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 309 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
312 | } | 310 | } |
313 | resp = GNUNET_REST_create_response (json_error); | 311 | resp = GNUNET_REST_create_response(json_error); |
314 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 312 | MHD_add_response_header(resp, "Content-Type", "application/json"); |
315 | handle->proc (handle->proc_cls, resp, handle->response_code); | 313 | handle->proc(handle->proc_cls, resp, handle->response_code); |
316 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 314 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
317 | GNUNET_free (json_error); | 315 | GNUNET_free(json_error); |
318 | } | 316 | } |
319 | 317 | ||
320 | 318 | ||
@@ -324,37 +322,37 @@ do_error (void *cls) | |||
324 | * @param cls the `struct RequestHandle` | 322 | * @param cls the `struct RequestHandle` |
325 | */ | 323 | */ |
326 | static void | 324 | static void |
327 | do_timeout (void *cls) | 325 | do_timeout(void *cls) |
328 | { | 326 | { |
329 | struct RequestHandle *handle = cls; | 327 | struct RequestHandle *handle = cls; |
330 | 328 | ||
331 | handle->timeout_task = NULL; | 329 | handle->timeout_task = NULL; |
332 | do_error (handle); | 330 | do_error(handle); |
333 | } | 331 | } |
334 | 332 | ||
335 | 333 | ||
336 | static void | 334 | static void |
337 | collect_error_cb (void *cls) | 335 | collect_error_cb(void *cls) |
338 | { | 336 | { |
339 | struct RequestHandle *handle = cls; | 337 | struct RequestHandle *handle = cls; |
340 | 338 | ||
341 | do_error (handle); | 339 | do_error(handle); |
342 | } | 340 | } |
343 | 341 | ||
344 | static void | 342 | static void |
345 | finished_cont (void *cls, int32_t success, const char *emsg) | 343 | finished_cont(void *cls, int32_t success, const char *emsg) |
346 | { | 344 | { |
347 | struct RequestHandle *handle = cls; | 345 | struct RequestHandle *handle = cls; |
348 | struct MHD_Response *resp; | 346 | struct MHD_Response *resp; |
349 | 347 | ||
350 | resp = GNUNET_REST_create_response (emsg); | 348 | resp = GNUNET_REST_create_response(emsg); |
351 | if (GNUNET_OK != success) | 349 | if (GNUNET_OK != success) |
352 | { | 350 | { |
353 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 351 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
354 | return; | 352 | return; |
355 | } | 353 | } |
356 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 354 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
357 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 355 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
358 | } | 356 | } |
359 | 357 | ||
360 | 358 | ||
@@ -364,28 +362,29 @@ finished_cont (void *cls, int32_t success, const char *emsg) | |||
364 | * @param cls the request handle | 362 | * @param cls the request handle |
365 | */ | 363 | */ |
366 | static void | 364 | static void |
367 | return_response (void *cls) | 365 | return_response(void *cls) |
368 | { | 366 | { |
369 | char *result_str; | 367 | char *result_str; |
370 | struct RequestHandle *handle = cls; | 368 | struct RequestHandle *handle = cls; |
371 | struct MHD_Response *resp; | 369 | struct MHD_Response *resp; |
372 | 370 | ||
373 | result_str = json_dumps (handle->resp_object, 0); | 371 | result_str = json_dumps(handle->resp_object, 0); |
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 372 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
375 | resp = GNUNET_REST_create_response (result_str); | 373 | resp = GNUNET_REST_create_response(result_str); |
376 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 374 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
377 | GNUNET_free (result_str); | 375 | GNUNET_free(result_str); |
378 | cleanup_handle (handle); | 376 | cleanup_handle(handle); |
379 | } | 377 | } |
380 | 378 | ||
381 | static void | 379 | static void |
382 | collect_finished_cb (void *cls) | 380 | collect_finished_cb(void *cls) |
383 | { | 381 | { |
384 | struct RequestHandle *handle = cls; | 382 | struct RequestHandle *handle = cls; |
383 | |||
385 | // Done | 384 | // Done |
386 | handle->attr_it = NULL; | 385 | handle->attr_it = NULL; |
387 | handle->ticket_it = NULL; | 386 | handle->ticket_it = NULL; |
388 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 387 | GNUNET_SCHEDULER_add_now(&return_response, handle); |
389 | } | 388 | } |
390 | 389 | ||
391 | 390 | ||
@@ -394,38 +393,38 @@ collect_finished_cb (void *cls) | |||
394 | * | 393 | * |
395 | */ | 394 | */ |
396 | static void | 395 | static void |
397 | ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | 396 | ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) |
398 | { | 397 | { |
399 | json_t *json_resource; | 398 | json_t *json_resource; |
400 | struct RequestHandle *handle = cls; | 399 | struct RequestHandle *handle = cls; |
401 | json_t *value; | 400 | json_t *value; |
402 | char *tmp; | 401 | char *tmp; |
403 | 402 | ||
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); | 403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); |
405 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 404 | tmp = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t)); |
406 | json_resource = json_object (); | 405 | json_resource = json_object(); |
407 | GNUNET_free (tmp); | 406 | GNUNET_free(tmp); |
408 | json_array_append (handle->resp_object, json_resource); | 407 | json_array_append(handle->resp_object, json_resource); |
409 | 408 | ||
410 | tmp = | 409 | tmp = |
411 | GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, | 410 | GNUNET_STRINGS_data_to_string_alloc(&ticket->identity, |
412 | sizeof (struct | 411 | sizeof(struct |
413 | GNUNET_CRYPTO_EcdsaPublicKey)); | 412 | GNUNET_CRYPTO_EcdsaPublicKey)); |
414 | value = json_string (tmp); | 413 | value = json_string(tmp); |
415 | json_object_set_new (json_resource, "issuer", value); | 414 | json_object_set_new(json_resource, "issuer", value); |
416 | GNUNET_free (tmp); | 415 | GNUNET_free(tmp); |
417 | tmp = | 416 | tmp = |
418 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 417 | GNUNET_STRINGS_data_to_string_alloc(&ticket->audience, |
419 | sizeof (struct | 418 | sizeof(struct |
420 | GNUNET_CRYPTO_EcdsaPublicKey)); | 419 | GNUNET_CRYPTO_EcdsaPublicKey)); |
421 | value = json_string (tmp); | 420 | value = json_string(tmp); |
422 | json_object_set_new (json_resource, "audience", value); | 421 | json_object_set_new(json_resource, "audience", value); |
423 | GNUNET_free (tmp); | 422 | GNUNET_free(tmp); |
424 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 423 | tmp = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t)); |
425 | value = json_string (tmp); | 424 | value = json_string(tmp); |
426 | json_object_set_new (json_resource, "rnd", value); | 425 | json_object_set_new(json_resource, "rnd", value); |
427 | GNUNET_free (tmp); | 426 | GNUNET_free(tmp); |
428 | GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); | 427 | GNUNET_RECLAIM_ticket_iteration_next(handle->ticket_it); |
429 | } | 428 | } |
430 | 429 | ||
431 | 430 | ||
@@ -437,57 +436,57 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
437 | * @param cls the RequestHandle | 436 | * @param cls the RequestHandle |
438 | */ | 437 | */ |
439 | static void | 438 | static void |
440 | list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | 439 | list_tickets_cont(struct GNUNET_REST_RequestHandle *con_handle, |
441 | const char *url, | 440 | const char *url, |
442 | void *cls) | 441 | void *cls) |
443 | { | 442 | { |
444 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 443 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
445 | struct RequestHandle *handle = cls; | 444 | struct RequestHandle *handle = cls; |
446 | struct EgoEntry *ego_entry; | 445 | struct EgoEntry *ego_entry; |
447 | char *identity; | 446 | char *identity; |
448 | 447 | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 448 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
450 | "Getting tickets for %s.\n", | 449 | "Getting tickets for %s.\n", |
451 | handle->url); | 450 | handle->url); |
452 | if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url)) | 451 | if (strlen(GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen(handle->url)) |
453 | { | 452 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 453 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
455 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 454 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
456 | return; | 455 | return; |
457 | } | 456 | } |
458 | identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; | 457 | identity = handle->url + strlen(GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; |
459 | 458 | ||
460 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 459 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
461 | ego_entry = ego_entry->next) | 460 | ego_entry = ego_entry->next) |
462 | if (0 == strcmp (identity, ego_entry->identifier)) | 461 | if (0 == strcmp(identity, ego_entry->identifier)) |
463 | break; | 462 | break; |
464 | handle->resp_object = json_array (); | 463 | handle->resp_object = json_array(); |
465 | 464 | ||
466 | if (NULL == ego_entry) | 465 | if (NULL == ego_entry) |
467 | { | 466 | { |
468 | // Done | 467 | // Done |
469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); |
470 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 469 | GNUNET_SCHEDULER_add_now(&return_response, handle); |
471 | return; | 470 | return; |
472 | } | 471 | } |
473 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 472 | priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
474 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 473 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
475 | handle->ticket_it = | 474 | handle->ticket_it = |
476 | GNUNET_RECLAIM_ticket_iteration_start (handle->idp, | 475 | GNUNET_RECLAIM_ticket_iteration_start(handle->idp, |
477 | priv_key, | 476 | priv_key, |
478 | &collect_error_cb, | 477 | &collect_error_cb, |
479 | handle, | 478 | handle, |
480 | &ticket_collect, | 479 | &ticket_collect, |
481 | handle, | 480 | handle, |
482 | &collect_finished_cb, | 481 | &collect_finished_cb, |
483 | handle); | 482 | handle); |
484 | } | 483 | } |
485 | 484 | ||
486 | 485 | ||
487 | static void | 486 | static void |
488 | add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | 487 | add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, |
489 | const char *url, | 488 | const char *url, |
490 | void *cls) | 489 | void *cls) |
491 | { | 490 | { |
492 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 491 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
493 | const char *identity; | 492 | const char *identity; |
@@ -499,68 +498,68 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
499 | json_t *data_json; | 498 | json_t *data_json; |
500 | json_error_t err; | 499 | json_error_t err; |
501 | struct GNUNET_JSON_Specification attrspec[] = | 500 | struct GNUNET_JSON_Specification attrspec[] = |
502 | {GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end ()}; | 501 | { GNUNET_RECLAIM_JSON_spec_claim(&attribute), GNUNET_JSON_spec_end() }; |
503 | 502 | ||
504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
505 | "Adding an attribute for %s.\n", | 504 | "Adding an attribute for %s.\n", |
506 | handle->url); | 505 | handle->url); |
507 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) | 506 | if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url)) |
508 | { | 507 | { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 508 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
510 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 509 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
511 | return; | 510 | return; |
512 | } | 511 | } |
513 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; | 512 | identity = handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; |
514 | 513 | ||
515 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 514 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
516 | ego_entry = ego_entry->next) | 515 | ego_entry = ego_entry->next) |
517 | if (0 == strcmp (identity, ego_entry->identifier)) | 516 | if (0 == strcmp(identity, ego_entry->identifier)) |
518 | break; | 517 | break; |
519 | 518 | ||
520 | if (NULL == ego_entry) | 519 | if (NULL == ego_entry) |
521 | { | 520 | { |
522 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); | 521 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); |
523 | return; | 522 | return; |
524 | } | 523 | } |
525 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 524 | identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
526 | 525 | ||
527 | if (0 >= handle->rest_handle->data_size) | 526 | if (0 >= handle->rest_handle->data_size) |
528 | { | 527 | { |
529 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 528 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
530 | return; | 529 | return; |
531 | } | 530 | } |
532 | 531 | ||
533 | term_data[handle->rest_handle->data_size] = '\0'; | 532 | term_data[handle->rest_handle->data_size] = '\0'; |
534 | GNUNET_memcpy (term_data, | 533 | GNUNET_memcpy(term_data, |
535 | handle->rest_handle->data, | 534 | handle->rest_handle->data, |
536 | handle->rest_handle->data_size); | 535 | handle->rest_handle->data_size); |
537 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | 536 | data_json = json_loads(term_data, JSON_DECODE_ANY, &err); |
538 | GNUNET_assert (GNUNET_OK == | 537 | GNUNET_assert(GNUNET_OK == |
539 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); | 538 | GNUNET_JSON_parse(data_json, attrspec, NULL, NULL)); |
540 | json_decref (data_json); | 539 | json_decref(data_json); |
541 | if (NULL == attribute) | 540 | if (NULL == attribute) |
542 | { | 541 | { |
543 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 542 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
544 | "Unable to parse attribute from %s\n", | 543 | "Unable to parse attribute from %s\n", |
545 | term_data); | 544 | term_data); |
546 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 545 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
547 | return; | 546 | return; |
548 | } | 547 | } |
549 | /** | 548 | /** |
550 | * New ID for attribute | 549 | * New ID for attribute |
551 | */ | 550 | */ |
552 | if (0 == attribute->id) | 551 | if (0 == attribute->id) |
553 | attribute->id = | 552 | attribute->id = |
554 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | 553 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
555 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 554 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
556 | exp = GNUNET_TIME_UNIT_HOURS; | 555 | exp = GNUNET_TIME_UNIT_HOURS; |
557 | handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, | 556 | handle->idp_op = GNUNET_RECLAIM_attribute_store(handle->idp, |
558 | identity_priv, | 557 | identity_priv, |
559 | attribute, | 558 | attribute, |
560 | &exp, | 559 | &exp, |
561 | &finished_cont, | 560 | &finished_cont, |
562 | handle); | 561 | handle); |
563 | GNUNET_JSON_parse_free (attrspec); | 562 | GNUNET_JSON_parse_free(attrspec); |
564 | } | 563 | } |
565 | 564 | ||
566 | 565 | ||
@@ -569,9 +568,9 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
569 | * | 568 | * |
570 | */ | 569 | */ |
571 | static void | 570 | static void |
572 | attr_collect (void *cls, | 571 | attr_collect(void *cls, |
573 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 572 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
574 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 573 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
575 | { | 574 | { |
576 | struct RequestHandle *handle = cls; | 575 | struct RequestHandle *handle = cls; |
577 | json_t *attr_obj; | 576 | json_t *attr_obj; |
@@ -580,28 +579,28 @@ attr_collect (void *cls, | |||
580 | char *id_str; | 579 | char *id_str; |
581 | 580 | ||
582 | if ((NULL == attr->name) || (NULL == attr->data)) | 581 | if ((NULL == attr->name) || (NULL == attr->data)) |
583 | { | 582 | { |
584 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 583 | GNUNET_RECLAIM_get_attributes_next(handle->attr_it); |
585 | return; | 584 | return; |
586 | } | 585 | } |
587 | 586 | ||
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); | 587 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); |
589 | 588 | ||
590 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 589 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
591 | attr->data, | 590 | attr->data, |
592 | attr->data_size); | 591 | attr->data_size); |
593 | 592 | ||
594 | attr_obj = json_object (); | 593 | attr_obj = json_object(); |
595 | json_object_set_new (attr_obj, "value", json_string (tmp_value)); | 594 | json_object_set_new(attr_obj, "value", json_string(tmp_value)); |
596 | json_object_set_new (attr_obj, "name", json_string (attr->name)); | 595 | json_object_set_new(attr_obj, "name", json_string(attr->name)); |
597 | type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 596 | type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type); |
598 | json_object_set_new (attr_obj, "type", json_string (type)); | 597 | json_object_set_new(attr_obj, "type", json_string(type)); |
599 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | 598 | id_str = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t)); |
600 | json_object_set_new (attr_obj, "id", json_string (id_str)); | 599 | json_object_set_new(attr_obj, "id", json_string(id_str)); |
601 | json_array_append (handle->resp_object, attr_obj); | 600 | json_array_append(handle->resp_object, attr_obj); |
602 | json_decref (attr_obj); | 601 | json_decref(attr_obj); |
603 | GNUNET_free (tmp_value); | 602 | GNUNET_free(tmp_value); |
604 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 603 | GNUNET_RECLAIM_get_attributes_next(handle->attr_it); |
605 | } | 604 | } |
606 | 605 | ||
607 | 606 | ||
@@ -613,67 +612,67 @@ attr_collect (void *cls, | |||
613 | * @param cls the RequestHandle | 612 | * @param cls the RequestHandle |
614 | */ | 613 | */ |
615 | static void | 614 | static void |
616 | list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | 615 | list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, |
617 | const char *url, | 616 | const char *url, |
618 | void *cls) | 617 | void *cls) |
619 | { | 618 | { |
620 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 619 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
621 | struct RequestHandle *handle = cls; | 620 | struct RequestHandle *handle = cls; |
622 | struct EgoEntry *ego_entry; | 621 | struct EgoEntry *ego_entry; |
623 | char *identity; | 622 | char *identity; |
624 | 623 | ||
625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 624 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
626 | "Getting attributes for %s.\n", | 625 | "Getting attributes for %s.\n", |
627 | handle->url); | 626 | handle->url); |
628 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) | 627 | if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url)) |
629 | { | 628 | { |
630 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 629 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
631 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 630 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
632 | return; | 631 | return; |
633 | } | 632 | } |
634 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; | 633 | identity = handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; |
635 | 634 | ||
636 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 635 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
637 | ego_entry = ego_entry->next) | 636 | ego_entry = ego_entry->next) |
638 | if (0 == strcmp (identity, ego_entry->identifier)) | 637 | if (0 == strcmp(identity, ego_entry->identifier)) |
639 | break; | 638 | break; |
640 | handle->resp_object = json_array (); | 639 | handle->resp_object = json_array(); |
641 | 640 | ||
642 | 641 | ||
643 | if (NULL == ego_entry) | 642 | if (NULL == ego_entry) |
644 | { | 643 | { |
645 | // Done | 644 | // Done |
646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | 645 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); |
647 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 646 | GNUNET_SCHEDULER_add_now(&return_response, handle); |
648 | return; | 647 | return; |
649 | } | 648 | } |
650 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 649 | priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
651 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 650 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
652 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, | 651 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start(handle->idp, |
653 | priv_key, | 652 | priv_key, |
654 | &collect_error_cb, | 653 | &collect_error_cb, |
655 | handle, | 654 | handle, |
656 | &attr_collect, | 655 | &attr_collect, |
657 | handle, | 656 | handle, |
658 | &collect_finished_cb, | 657 | &collect_finished_cb, |
659 | handle); | 658 | handle); |
660 | } | 659 | } |
661 | 660 | ||
662 | 661 | ||
663 | static void | 662 | static void |
664 | delete_finished_cb (void *cls, int32_t success, const char *emsg) | 663 | delete_finished_cb(void *cls, int32_t success, const char *emsg) |
665 | { | 664 | { |
666 | struct RequestHandle *handle = cls; | 665 | struct RequestHandle *handle = cls; |
667 | struct MHD_Response *resp; | 666 | struct MHD_Response *resp; |
668 | 667 | ||
669 | resp = GNUNET_REST_create_response (emsg); | 668 | resp = GNUNET_REST_create_response(emsg); |
670 | if (GNUNET_OK != success) | 669 | if (GNUNET_OK != success) |
671 | { | 670 | { |
672 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 671 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
673 | return; | 672 | return; |
674 | } | 673 | } |
675 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 674 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
676 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 675 | GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); |
677 | } | 676 | } |
678 | 677 | ||
679 | 678 | ||
@@ -685,9 +684,9 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg) | |||
685 | * @param cls the RequestHandle | 684 | * @param cls the RequestHandle |
686 | */ | 685 | */ |
687 | static void | 686 | static void |
688 | delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | 687 | delete_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle, |
689 | const char *url, | 688 | const char *url, |
690 | void *cls) | 689 | void *cls) |
691 | { | 690 | { |
692 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 691 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
693 | struct RequestHandle *handle = cls; | 692 | struct RequestHandle *handle = cls; |
@@ -697,56 +696,56 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
697 | char *identity; | 696 | char *identity; |
698 | char *id; | 697 | char *id; |
699 | 698 | ||
700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n"); | 699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n"); |
701 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) | 700 | if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url)) |
702 | { | 701 | { |
703 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | 702 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); |
704 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 703 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
705 | return; | 704 | return; |
706 | } | 705 | } |
707 | identity_id_str = | 706 | identity_id_str = |
708 | strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1); | 707 | strdup(handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1); |
709 | identity = strtok (identity_id_str, "/"); | 708 | identity = strtok(identity_id_str, "/"); |
710 | id = strtok (NULL, "/"); | 709 | id = strtok(NULL, "/"); |
711 | if ((NULL == identity) || (NULL == id)) | 710 | if ((NULL == identity) || (NULL == id)) |
712 | { | 711 | { |
713 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); | 712 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); |
714 | GNUNET_free (identity_id_str); | 713 | GNUNET_free(identity_id_str); |
715 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 714 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
716 | return; | 715 | return; |
717 | } | 716 | } |
718 | 717 | ||
719 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 718 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
720 | ego_entry = ego_entry->next) | 719 | ego_entry = ego_entry->next) |
721 | if (0 == strcmp (identity, ego_entry->identifier)) | 720 | if (0 == strcmp(identity, ego_entry->identifier)) |
722 | break; | 721 | break; |
723 | handle->resp_object = json_array (); | 722 | handle->resp_object = json_array(); |
724 | if (NULL == ego_entry) | 723 | if (NULL == ego_entry) |
725 | { | 724 | { |
726 | // Done | 725 | // Done |
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | 726 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); |
728 | GNUNET_free (identity_id_str); | 727 | GNUNET_free(identity_id_str); |
729 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 728 | GNUNET_SCHEDULER_add_now(&return_response, handle); |
730 | return; | 729 | return; |
731 | } | 730 | } |
732 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 731 | priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
733 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 732 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
734 | memset (&attr, 0, sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim)); | 733 | memset(&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim)); |
735 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t)); | 734 | GNUNET_STRINGS_string_to_data(id, strlen(id), &attr.id, sizeof(uint64_t)); |
736 | attr.name = ""; | 735 | attr.name = ""; |
737 | handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, | 736 | handle->idp_op = GNUNET_RECLAIM_attribute_delete(handle->idp, |
738 | priv_key, | 737 | priv_key, |
739 | &attr, | 738 | &attr, |
740 | &delete_finished_cb, | 739 | &delete_finished_cb, |
741 | handle); | 740 | handle); |
742 | GNUNET_free (identity_id_str); | 741 | GNUNET_free(identity_id_str); |
743 | } | 742 | } |
744 | 743 | ||
745 | 744 | ||
746 | static void | 745 | static void |
747 | revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | 746 | revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, |
748 | const char *url, | 747 | const char *url, |
749 | void *cls) | 748 | void *cls) |
750 | { | 749 | { |
751 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 750 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
752 | struct RequestHandle *handle = cls; | 751 | struct RequestHandle *handle = cls; |
@@ -757,101 +756,101 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
757 | json_t *data_json; | 756 | json_t *data_json; |
758 | json_error_t err; | 757 | json_error_t err; |
759 | struct GNUNET_JSON_Specification tktspec[] = | 758 | struct GNUNET_JSON_Specification tktspec[] = |
760 | {GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; | 759 | { GNUNET_RECLAIM_JSON_spec_ticket(&ticket), GNUNET_JSON_spec_end() }; |
761 | 760 | ||
762 | if (0 >= handle->rest_handle->data_size) | 761 | if (0 >= handle->rest_handle->data_size) |
763 | { | 762 | { |
764 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 763 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
765 | return; | 764 | return; |
766 | } | 765 | } |
767 | 766 | ||
768 | term_data[handle->rest_handle->data_size] = '\0'; | 767 | term_data[handle->rest_handle->data_size] = '\0'; |
769 | GNUNET_memcpy (term_data, | 768 | GNUNET_memcpy(term_data, |
770 | handle->rest_handle->data, | 769 | handle->rest_handle->data, |
771 | handle->rest_handle->data_size); | 770 | handle->rest_handle->data_size); |
772 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | 771 | data_json = json_loads(term_data, JSON_DECODE_ANY, &err); |
773 | if ((NULL == data_json) || | 772 | if ((NULL == data_json) || |
774 | (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))) | 773 | (GNUNET_OK != GNUNET_JSON_parse(data_json, tktspec, NULL, NULL))) |
775 | { | 774 | { |
776 | handle->emsg = GNUNET_strdup ("Not a ticket!\n"); | 775 | handle->emsg = GNUNET_strdup("Not a ticket!\n"); |
777 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 776 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
778 | GNUNET_JSON_parse_free (tktspec); | 777 | GNUNET_JSON_parse_free(tktspec); |
779 | if (NULL != data_json) | 778 | if (NULL != data_json) |
780 | json_decref (data_json); | 779 | json_decref(data_json); |
781 | return; | 780 | return; |
782 | } | 781 | } |
783 | json_decref (data_json); | 782 | json_decref(data_json); |
784 | if (NULL == ticket) | 783 | if (NULL == ticket) |
785 | { | 784 | { |
786 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 785 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
787 | "Unable to parse ticket from %s\n", | 786 | "Unable to parse ticket from %s\n", |
788 | term_data); | 787 | term_data); |
789 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 788 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
790 | return; | 789 | return; |
791 | } | 790 | } |
792 | 791 | ||
793 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 792 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
794 | ego_entry = ego_entry->next) | 793 | ego_entry = ego_entry->next) |
795 | { | 794 | { |
796 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 795 | GNUNET_IDENTITY_ego_get_public_key(ego_entry->ego, &tmp_pk); |
797 | if (0 == memcmp (&ticket->identity, | 796 | if (0 == memcmp(&ticket->identity, |
798 | &tmp_pk, | 797 | &tmp_pk, |
799 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 798 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
800 | break; | 799 | break; |
801 | } | 800 | } |
802 | if (NULL == ego_entry) | 801 | if (NULL == ego_entry) |
803 | { | 802 | { |
804 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); | 803 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); |
805 | GNUNET_JSON_parse_free (tktspec); | 804 | GNUNET_JSON_parse_free(tktspec); |
806 | return; | 805 | return; |
807 | } | 806 | } |
808 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 807 | identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
809 | 808 | ||
810 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 809 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
811 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, | 810 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke(handle->idp, |
812 | identity_priv, | 811 | identity_priv, |
813 | ticket, | 812 | ticket, |
814 | &finished_cont, | 813 | &finished_cont, |
815 | handle); | 814 | handle); |
816 | GNUNET_JSON_parse_free (tktspec); | 815 | GNUNET_JSON_parse_free(tktspec); |
817 | } | 816 | } |
818 | 817 | ||
819 | static void | 818 | static void |
820 | consume_cont (void *cls, | 819 | consume_cont(void *cls, |
821 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 820 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
822 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 821 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
823 | { | 822 | { |
824 | struct RequestHandle *handle = cls; | 823 | struct RequestHandle *handle = cls; |
825 | char *val_str; | 824 | char *val_str; |
826 | json_t *value; | 825 | json_t *value; |
827 | 826 | ||
828 | if (NULL == identity) | 827 | if (NULL == identity) |
829 | { | 828 | { |
830 | GNUNET_SCHEDULER_add_now (&return_response, handle); | 829 | GNUNET_SCHEDULER_add_now(&return_response, handle); |
831 | return; | 830 | return; |
832 | } | 831 | } |
833 | 832 | ||
834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); | 833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); |
835 | val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 834 | val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type, |
836 | attr->data, | 835 | attr->data, |
837 | attr->data_size); | 836 | attr->data_size); |
838 | if (NULL == val_str) | 837 | if (NULL == val_str) |
839 | { | 838 | { |
840 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 839 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
841 | "Failed to parse value for: %s\n", | 840 | "Failed to parse value for: %s\n", |
842 | attr->name); | 841 | attr->name); |
843 | return; | 842 | return; |
844 | } | 843 | } |
845 | value = json_string (val_str); | 844 | value = json_string(val_str); |
846 | json_object_set_new (handle->resp_object, attr->name, value); | 845 | json_object_set_new(handle->resp_object, attr->name, value); |
847 | json_decref (value); | 846 | json_decref(value); |
848 | GNUNET_free (val_str); | 847 | GNUNET_free(val_str); |
849 | } | 848 | } |
850 | 849 | ||
851 | static void | 850 | static void |
852 | consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | 851 | consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle, |
853 | const char *url, | 852 | const char *url, |
854 | void *cls) | 853 | void *cls) |
855 | { | 854 | { |
856 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 855 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
857 | struct RequestHandle *handle = cls; | 856 | struct RequestHandle *handle = cls; |
@@ -862,59 +861,59 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
862 | json_t *data_json; | 861 | json_t *data_json; |
863 | json_error_t err; | 862 | json_error_t err; |
864 | struct GNUNET_JSON_Specification tktspec[] = | 863 | struct GNUNET_JSON_Specification tktspec[] = |
865 | {GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; | 864 | { GNUNET_RECLAIM_JSON_spec_ticket(&ticket), GNUNET_JSON_spec_end() }; |
866 | 865 | ||
867 | if (0 >= handle->rest_handle->data_size) | 866 | if (0 >= handle->rest_handle->data_size) |
868 | { | 867 | { |
869 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 868 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
870 | return; | 869 | return; |
871 | } | 870 | } |
872 | 871 | ||
873 | term_data[handle->rest_handle->data_size] = '\0'; | 872 | term_data[handle->rest_handle->data_size] = '\0'; |
874 | GNUNET_memcpy (term_data, | 873 | GNUNET_memcpy(term_data, |
875 | handle->rest_handle->data, | 874 | handle->rest_handle->data, |
876 | handle->rest_handle->data_size); | 875 | handle->rest_handle->data_size); |
877 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | 876 | data_json = json_loads(term_data, JSON_DECODE_ANY, &err); |
878 | if (NULL == data_json) | 877 | if (NULL == data_json) |
879 | { | 878 | { |
880 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 879 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
881 | "Unable to parse JSON Object from %s\n", | 880 | "Unable to parse JSON Object from %s\n", |
882 | term_data); | 881 | term_data); |
883 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 882 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
884 | return; | 883 | return; |
885 | } | 884 | } |
886 | if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)) | 885 | if (GNUNET_OK != GNUNET_JSON_parse(data_json, tktspec, NULL, NULL)) |
887 | { | 886 | { |
888 | handle->emsg = GNUNET_strdup ("Not a ticket!\n"); | 887 | handle->emsg = GNUNET_strdup("Not a ticket!\n"); |
889 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 888 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
890 | GNUNET_JSON_parse_free (tktspec); | 889 | GNUNET_JSON_parse_free(tktspec); |
891 | json_decref (data_json); | 890 | json_decref(data_json); |
892 | return; | 891 | return; |
893 | } | 892 | } |
894 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 893 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
895 | ego_entry = ego_entry->next) | 894 | ego_entry = ego_entry->next) |
896 | { | 895 | { |
897 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 896 | GNUNET_IDENTITY_ego_get_public_key(ego_entry->ego, &tmp_pk); |
898 | if (0 == memcmp (&ticket->audience, | 897 | if (0 == memcmp(&ticket->audience, |
899 | &tmp_pk, | 898 | &tmp_pk, |
900 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 899 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
901 | break; | 900 | break; |
902 | } | 901 | } |
903 | if (NULL == ego_entry) | 902 | if (NULL == ego_entry) |
904 | { | 903 | { |
905 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); | 904 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); |
906 | GNUNET_JSON_parse_free (tktspec); | 905 | GNUNET_JSON_parse_free(tktspec); |
907 | return; | 906 | return; |
908 | } | 907 | } |
909 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 908 | identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
910 | handle->resp_object = json_object (); | 909 | handle->resp_object = json_object(); |
911 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 910 | handle->idp = GNUNET_RECLAIM_connect(cfg); |
912 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, | 911 | handle->idp_op = GNUNET_RECLAIM_ticket_consume(handle->idp, |
913 | identity_priv, | 912 | identity_priv, |
914 | ticket, | 913 | ticket, |
915 | &consume_cont, | 914 | &consume_cont, |
916 | handle); | 915 | handle); |
917 | GNUNET_JSON_parse_free (tktspec); | 916 | GNUNET_JSON_parse_free(tktspec); |
918 | } | 917 | } |
919 | 918 | ||
920 | 919 | ||
@@ -926,18 +925,18 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
926 | * @param cls the RequestHandle | 925 | * @param cls the RequestHandle |
927 | */ | 926 | */ |
928 | static void | 927 | static void |
929 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 928 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, |
930 | const char *url, | 929 | const char *url, |
931 | void *cls) | 930 | void *cls) |
932 | { | 931 | { |
933 | struct MHD_Response *resp; | 932 | struct MHD_Response *resp; |
934 | struct RequestHandle *handle = cls; | 933 | struct RequestHandle *handle = cls; |
935 | 934 | ||
936 | // For now, independent of path return all options | 935 | // For now, independent of path return all options |
937 | resp = GNUNET_REST_create_response (NULL); | 936 | resp = GNUNET_REST_create_response(NULL); |
938 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 937 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); |
939 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 938 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
940 | cleanup_handle (handle); | 939 | cleanup_handle(handle); |
941 | return; | 940 | return; |
942 | } | 941 | } |
943 | 942 | ||
@@ -947,37 +946,37 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
947 | * @param handle the request handle | 946 | * @param handle the request handle |
948 | */ | 947 | */ |
949 | static void | 948 | static void |
950 | init_cont (struct RequestHandle *handle) | 949 | init_cont(struct RequestHandle *handle) |
951 | { | 950 | { |
952 | struct GNUNET_REST_RequestHandlerError err; | 951 | struct GNUNET_REST_RequestHandlerError err; |
953 | static const struct GNUNET_REST_RequestHandler handlers[] = | 952 | static const struct GNUNET_REST_RequestHandler handlers[] = |
954 | {{MHD_HTTP_METHOD_GET, | 953 | { { MHD_HTTP_METHOD_GET, |
955 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | ||
956 | &list_attribute_cont}, | ||
957 | {MHD_HTTP_METHOD_POST, | ||
958 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | 954 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, |
959 | &add_attribute_cont}, | 955 | &list_attribute_cont }, |
960 | {MHD_HTTP_METHOD_DELETE, | 956 | { MHD_HTTP_METHOD_POST, |
961 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | 957 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, |
962 | &delete_attribute_cont}, | 958 | &add_attribute_cont }, |
963 | {MHD_HTTP_METHOD_GET, | 959 | { MHD_HTTP_METHOD_DELETE, |
964 | GNUNET_REST_API_NS_IDENTITY_TICKETS, | 960 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, |
965 | &list_tickets_cont}, | 961 | &delete_attribute_cont }, |
966 | {MHD_HTTP_METHOD_POST, | 962 | { MHD_HTTP_METHOD_GET, |
967 | GNUNET_REST_API_NS_IDENTITY_REVOKE, | 963 | GNUNET_REST_API_NS_IDENTITY_TICKETS, |
968 | &revoke_ticket_cont}, | 964 | &list_tickets_cont }, |
969 | {MHD_HTTP_METHOD_POST, | 965 | { MHD_HTTP_METHOD_POST, |
970 | GNUNET_REST_API_NS_IDENTITY_CONSUME, | 966 | GNUNET_REST_API_NS_IDENTITY_REVOKE, |
971 | &consume_ticket_cont}, | 967 | &revoke_ticket_cont }, |
972 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont}, | 968 | { MHD_HTTP_METHOD_POST, |
973 | GNUNET_REST_HANDLER_END}; | 969 | GNUNET_REST_API_NS_IDENTITY_CONSUME, |
970 | &consume_ticket_cont }, | ||
971 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, | ||
972 | GNUNET_REST_HANDLER_END }; | ||
974 | 973 | ||
975 | if (GNUNET_NO == | 974 | if (GNUNET_NO == |
976 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 975 | GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) |
977 | { | 976 | { |
978 | handle->response_code = err.error_code; | 977 | handle->response_code = err.error_code; |
979 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 978 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
980 | } | 979 | } |
981 | } | 980 | } |
982 | 981 | ||
983 | /** | 982 | /** |
@@ -1014,40 +1013,41 @@ init_cont (struct RequestHandle *handle) | |||
1014 | * must thus no longer be used | 1013 | * must thus no longer be used |
1015 | */ | 1014 | */ |
1016 | static void | 1015 | static void |
1017 | list_ego (void *cls, | 1016 | list_ego(void *cls, |
1018 | struct GNUNET_IDENTITY_Ego *ego, | 1017 | struct GNUNET_IDENTITY_Ego *ego, |
1019 | void **ctx, | 1018 | void **ctx, |
1020 | const char *identifier) | 1019 | const char *identifier) |
1021 | { | 1020 | { |
1022 | struct RequestHandle *handle = cls; | 1021 | struct RequestHandle *handle = cls; |
1023 | struct EgoEntry *ego_entry; | 1022 | struct EgoEntry *ego_entry; |
1024 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1023 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1025 | 1024 | ||
1026 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1025 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
1027 | { | 1026 | { |
1028 | handle->state = ID_REST_STATE_POST_INIT; | 1027 | handle->state = ID_REST_STATE_POST_INIT; |
1029 | init_cont (handle); | 1028 | init_cont(handle); |
1030 | return; | 1029 | return; |
1031 | } | 1030 | } |
1032 | if (ID_REST_STATE_INIT == handle->state) | 1031 | if (ID_REST_STATE_INIT == handle->state) |
1033 | { | 1032 | { |
1034 | ego_entry = GNUNET_new (struct EgoEntry); | 1033 | ego_entry = GNUNET_new(struct EgoEntry); |
1035 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1034 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); |
1036 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1035 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); |
1037 | ego_entry->ego = ego; | 1036 | ego_entry->ego = ego; |
1038 | ego_entry->identifier = GNUNET_strdup (identifier); | 1037 | ego_entry->identifier = GNUNET_strdup(identifier); |
1039 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 1038 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, |
1040 | handle->ego_tail, | 1039 | handle->ego_tail, |
1041 | ego_entry); | 1040 | ego_entry); |
1042 | } | 1041 | } |
1043 | } | 1042 | } |
1044 | 1043 | ||
1045 | static void | 1044 | static void |
1046 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1045 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
1047 | GNUNET_REST_ResultProcessor proc, | 1046 | GNUNET_REST_ResultProcessor proc, |
1048 | void *proc_cls) | 1047 | void *proc_cls) |
1049 | { | 1048 | { |
1050 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1049 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); |
1050 | |||
1051 | handle->response_code = 0; | 1051 | handle->response_code = 0; |
1052 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1052 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1053 | handle->proc_cls = proc_cls; | 1053 | handle->proc_cls = proc_cls; |
@@ -1055,14 +1055,14 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1055 | handle->state = ID_REST_STATE_INIT; | 1055 | handle->state = ID_REST_STATE_INIT; |
1056 | handle->rest_handle = rest_handle; | 1056 | handle->rest_handle = rest_handle; |
1057 | 1057 | ||
1058 | handle->url = GNUNET_strdup (rest_handle->url); | 1058 | handle->url = GNUNET_strdup(rest_handle->url); |
1059 | if (handle->url[strlen (handle->url) - 1] == '/') | 1059 | if (handle->url[strlen(handle->url) - 1] == '/') |
1060 | handle->url[strlen (handle->url) - 1] = '\0'; | 1060 | handle->url[strlen(handle->url) - 1] = '\0'; |
1061 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1061 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1062 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); | 1062 | handle->identity_handle = GNUNET_IDENTITY_connect(cfg, &list_ego, handle); |
1063 | handle->timeout_task = | 1063 | handle->timeout_task = |
1064 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 1064 | GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_timeout, handle); |
1065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | /** | 1068 | /** |
@@ -1072,7 +1072,7 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1072 | * @return NULL on error, otherwise the plugin context | 1072 | * @return NULL on error, otherwise the plugin context |
1073 | */ | 1073 | */ |
1074 | void * | 1074 | void * |
1075 | libgnunet_plugin_rest_reclaim_init (void *cls) | 1075 | libgnunet_plugin_rest_reclaim_init(void *cls) |
1076 | { | 1076 | { |
1077 | static struct Plugin plugin; | 1077 | static struct Plugin plugin; |
1078 | struct GNUNET_REST_Plugin *api; | 1078 | struct GNUNET_REST_Plugin *api; |
@@ -1080,22 +1080,22 @@ libgnunet_plugin_rest_reclaim_init (void *cls) | |||
1080 | cfg = cls; | 1080 | cfg = cls; |
1081 | if (NULL != plugin.cfg) | 1081 | if (NULL != plugin.cfg) |
1082 | return NULL; /* can only initialize once! */ | 1082 | return NULL; /* can only initialize once! */ |
1083 | memset (&plugin, 0, sizeof (struct Plugin)); | 1083 | memset(&plugin, 0, sizeof(struct Plugin)); |
1084 | plugin.cfg = cfg; | 1084 | plugin.cfg = cfg; |
1085 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 1085 | api = GNUNET_new(struct GNUNET_REST_Plugin); |
1086 | api->cls = &plugin; | 1086 | api->cls = &plugin; |
1087 | api->name = GNUNET_REST_API_NS_RECLAIM; | 1087 | api->name = GNUNET_REST_API_NS_RECLAIM; |
1088 | api->process_request = &rest_identity_process_request; | 1088 | api->process_request = &rest_identity_process_request; |
1089 | GNUNET_asprintf (&allow_methods, | 1089 | GNUNET_asprintf(&allow_methods, |
1090 | "%s, %s, %s, %s, %s", | 1090 | "%s, %s, %s, %s, %s", |
1091 | MHD_HTTP_METHOD_GET, | 1091 | MHD_HTTP_METHOD_GET, |
1092 | MHD_HTTP_METHOD_POST, | 1092 | MHD_HTTP_METHOD_POST, |
1093 | MHD_HTTP_METHOD_PUT, | 1093 | MHD_HTTP_METHOD_PUT, |
1094 | MHD_HTTP_METHOD_DELETE, | 1094 | MHD_HTTP_METHOD_DELETE, |
1095 | MHD_HTTP_METHOD_OPTIONS); | 1095 | MHD_HTTP_METHOD_OPTIONS); |
1096 | 1096 | ||
1097 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1097 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1098 | _ ("Identity Provider REST API initialized\n")); | 1098 | _("Identity Provider REST API initialized\n")); |
1099 | return api; | 1099 | return api; |
1100 | } | 1100 | } |
1101 | 1101 | ||
@@ -1107,16 +1107,17 @@ libgnunet_plugin_rest_reclaim_init (void *cls) | |||
1107 | * @return always NULL | 1107 | * @return always NULL |
1108 | */ | 1108 | */ |
1109 | void * | 1109 | void * |
1110 | libgnunet_plugin_rest_reclaim_done (void *cls) | 1110 | libgnunet_plugin_rest_reclaim_done(void *cls) |
1111 | { | 1111 | { |
1112 | struct GNUNET_REST_Plugin *api = cls; | 1112 | struct GNUNET_REST_Plugin *api = cls; |
1113 | struct Plugin *plugin = api->cls; | 1113 | struct Plugin *plugin = api->cls; |
1114 | |||
1114 | plugin->cfg = NULL; | 1115 | plugin->cfg = NULL; |
1115 | 1116 | ||
1116 | GNUNET_free_non_null (allow_methods); | 1117 | GNUNET_free_non_null(allow_methods); |
1117 | GNUNET_free (api); | 1118 | GNUNET_free(api); |
1118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1119 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1119 | "Identity Provider REST plugin is finished\n"); | 1120 | "Identity Provider REST plugin is finished\n"); |
1120 | return NULL; | 1121 | return NULL; |
1121 | } | 1122 | } |
1122 | 1123 | ||
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h index 3c7c05a10..87e343b51 100644 --- a/src/reclaim/reclaim.h +++ b/src/reclaim/reclaim.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Martin Schanzenbach | 22 | * @author Martin Schanzenbach |
@@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | /** | 37 | /** |
38 | * Use to store an identity attribute | 38 | * Use to store an identity attribute |
39 | */ | 39 | */ |
40 | struct AttributeStoreMessage | 40 | struct AttributeStoreMessage { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT | 42 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT |
44 | */ | 43 | */ |
@@ -71,8 +70,7 @@ struct AttributeStoreMessage | |||
71 | /** | 70 | /** |
72 | * Use to delete an identity attribute | 71 | * Use to delete an identity attribute |
73 | */ | 72 | */ |
74 | struct AttributeDeleteMessage | 73 | struct AttributeDeleteMessage { |
75 | { | ||
76 | /** | 74 | /** |
77 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT | 75 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT |
78 | */ | 76 | */ |
@@ -100,8 +98,7 @@ struct AttributeDeleteMessage | |||
100 | /** | 98 | /** |
101 | * Attribute store/delete response message | 99 | * Attribute store/delete response message |
102 | */ | 100 | */ |
103 | struct SuccessResultMessage | 101 | struct SuccessResultMessage { |
104 | { | ||
105 | /** | 102 | /** |
106 | * Message header | 103 | * Message header |
107 | */ | 104 | */ |
@@ -121,8 +118,7 @@ struct SuccessResultMessage | |||
121 | /** | 118 | /** |
122 | * Attribute is returned from the idp. | 119 | * Attribute is returned from the idp. |
123 | */ | 120 | */ |
124 | struct AttributeResultMessage | 121 | struct AttributeResultMessage { |
125 | { | ||
126 | /** | 122 | /** |
127 | * Message header | 123 | * Message header |
128 | */ | 124 | */ |
@@ -157,8 +153,7 @@ struct AttributeResultMessage | |||
157 | /** | 153 | /** |
158 | * Start a attribute iteration for the given identity | 154 | * Start a attribute iteration for the given identity |
159 | */ | 155 | */ |
160 | struct AttributeIterationStartMessage | 156 | struct AttributeIterationStartMessage { |
161 | { | ||
162 | /** | 157 | /** |
163 | * Message | 158 | * Message |
164 | */ | 159 | */ |
@@ -179,8 +174,7 @@ struct AttributeIterationStartMessage | |||
179 | /** | 174 | /** |
180 | * Ask for next result of attribute iteration for the given operation | 175 | * Ask for next result of attribute iteration for the given operation |
181 | */ | 176 | */ |
182 | struct AttributeIterationNextMessage | 177 | struct AttributeIterationNextMessage { |
183 | { | ||
184 | /** | 178 | /** |
185 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT | 179 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT |
186 | */ | 180 | */ |
@@ -196,8 +190,7 @@ struct AttributeIterationNextMessage | |||
196 | /** | 190 | /** |
197 | * Stop attribute iteration for the given operation | 191 | * Stop attribute iteration for the given operation |
198 | */ | 192 | */ |
199 | struct AttributeIterationStopMessage | 193 | struct AttributeIterationStopMessage { |
200 | { | ||
201 | /** | 194 | /** |
202 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP | 195 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP |
203 | */ | 196 | */ |
@@ -212,8 +205,7 @@ struct AttributeIterationStopMessage | |||
212 | /** | 205 | /** |
213 | * Start a ticket iteration for the given identity | 206 | * Start a ticket iteration for the given identity |
214 | */ | 207 | */ |
215 | struct TicketIterationStartMessage | 208 | struct TicketIterationStartMessage { |
216 | { | ||
217 | /** | 209 | /** |
218 | * Message | 210 | * Message |
219 | */ | 211 | */ |
@@ -234,8 +226,7 @@ struct TicketIterationStartMessage | |||
234 | /** | 226 | /** |
235 | * Ask for next result of ticket iteration for the given operation | 227 | * Ask for next result of ticket iteration for the given operation |
236 | */ | 228 | */ |
237 | struct TicketIterationNextMessage | 229 | struct TicketIterationNextMessage { |
238 | { | ||
239 | /** | 230 | /** |
240 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT | 231 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT |
241 | */ | 232 | */ |
@@ -251,8 +242,7 @@ struct TicketIterationNextMessage | |||
251 | /** | 242 | /** |
252 | * Stop ticket iteration for the given operation | 243 | * Stop ticket iteration for the given operation |
253 | */ | 244 | */ |
254 | struct TicketIterationStopMessage | 245 | struct TicketIterationStopMessage { |
255 | { | ||
256 | /** | 246 | /** |
257 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP | 247 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP |
258 | */ | 248 | */ |
@@ -268,8 +258,7 @@ struct TicketIterationStopMessage | |||
268 | /** | 258 | /** |
269 | * Ticket issue message | 259 | * Ticket issue message |
270 | */ | 260 | */ |
271 | struct IssueTicketMessage | 261 | struct IssueTicketMessage { |
272 | { | ||
273 | /** | 262 | /** |
274 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET | 263 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET |
275 | */ | 264 | */ |
@@ -301,8 +290,7 @@ struct IssueTicketMessage | |||
301 | /** | 290 | /** |
302 | * Ticket revoke message | 291 | * Ticket revoke message |
303 | */ | 292 | */ |
304 | struct RevokeTicketMessage | 293 | struct RevokeTicketMessage { |
305 | { | ||
306 | /** | 294 | /** |
307 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET | 295 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET |
308 | */ | 296 | */ |
@@ -332,8 +320,7 @@ struct RevokeTicketMessage | |||
332 | /** | 320 | /** |
333 | * Ticket revoke message | 321 | * Ticket revoke message |
334 | */ | 322 | */ |
335 | struct RevokeTicketResultMessage | 323 | struct RevokeTicketResultMessage { |
336 | { | ||
337 | /** | 324 | /** |
338 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT | 325 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT |
339 | */ | 326 | */ |
@@ -354,8 +341,7 @@ struct RevokeTicketResultMessage | |||
354 | /** | 341 | /** |
355 | * Ticket result message | 342 | * Ticket result message |
356 | */ | 343 | */ |
357 | struct TicketResultMessage | 344 | struct TicketResultMessage { |
358 | { | ||
359 | /** | 345 | /** |
360 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT | 346 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT |
361 | */ | 347 | */ |
@@ -375,8 +361,7 @@ struct TicketResultMessage | |||
375 | /** | 361 | /** |
376 | * Ticket consume message | 362 | * Ticket consume message |
377 | */ | 363 | */ |
378 | struct ConsumeTicketMessage | 364 | struct ConsumeTicketMessage { |
379 | { | ||
380 | /** | 365 | /** |
381 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET | 366 | * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET |
382 | */ | 367 | */ |
@@ -401,8 +386,7 @@ struct ConsumeTicketMessage | |||
401 | /** | 386 | /** |
402 | * Attribute list is returned from the idp. | 387 | * Attribute list is returned from the idp. |
403 | */ | 388 | */ |
404 | struct ConsumeTicketResultMessage | 389 | struct ConsumeTicketResultMessage { |
405 | { | ||
406 | /** | 390 | /** |
407 | * Message header | 391 | * Message header |
408 | */ | 392 | */ |
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 725b2b876..a8790cd8e 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file reclaim/reclaim_api.c | 22 | * @file reclaim/reclaim_api.c |
@@ -32,15 +32,13 @@ | |||
32 | #include "gnunet_reclaim_service.h" | 32 | #include "gnunet_reclaim_service.h" |
33 | #include "reclaim.h" | 33 | #include "reclaim.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from (kind, "reclaim-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "reclaim-api", __VA_ARGS__) |
36 | 36 | ||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Handle for an operation with the service. | 39 | * Handle for an operation with the service. |
40 | */ | 40 | */ |
41 | struct GNUNET_RECLAIM_Operation | 41 | struct GNUNET_RECLAIM_Operation { |
42 | { | ||
43 | |||
44 | /** | 42 | /** |
45 | * Main handle. | 43 | * Main handle. |
46 | */ | 44 | */ |
@@ -102,9 +100,7 @@ struct GNUNET_RECLAIM_Operation | |||
102 | /** | 100 | /** |
103 | * Handle for a ticket iterator operation | 101 | * Handle for a ticket iterator operation |
104 | */ | 102 | */ |
105 | struct GNUNET_RECLAIM_TicketIterator | 103 | struct GNUNET_RECLAIM_TicketIterator { |
106 | { | ||
107 | |||
108 | /** | 104 | /** |
109 | * Kept in a DLL. | 105 | * Kept in a DLL. |
110 | */ | 106 | */ |
@@ -166,9 +162,7 @@ struct GNUNET_RECLAIM_TicketIterator | |||
166 | /** | 162 | /** |
167 | * Handle for a attribute iterator operation | 163 | * Handle for a attribute iterator operation |
168 | */ | 164 | */ |
169 | struct GNUNET_RECLAIM_AttributeIterator | 165 | struct GNUNET_RECLAIM_AttributeIterator { |
170 | { | ||
171 | |||
172 | /** | 166 | /** |
173 | * Kept in a DLL. | 167 | * Kept in a DLL. |
174 | */ | 168 | */ |
@@ -235,8 +229,7 @@ struct GNUNET_RECLAIM_AttributeIterator | |||
235 | /** | 229 | /** |
236 | * Handle to the service. | 230 | * Handle to the service. |
237 | */ | 231 | */ |
238 | struct GNUNET_RECLAIM_Handle | 232 | struct GNUNET_RECLAIM_Handle { |
239 | { | ||
240 | /** | 233 | /** |
241 | * Configuration to use. | 234 | * Configuration to use. |
242 | */ | 235 | */ |
@@ -320,7 +313,7 @@ struct GNUNET_RECLAIM_Handle | |||
320 | * @param h handle to the reclaim service. | 313 | * @param h handle to the reclaim service. |
321 | */ | 314 | */ |
322 | static void | 315 | static void |
323 | reconnect (struct GNUNET_RECLAIM_Handle *h); | 316 | reconnect(struct GNUNET_RECLAIM_Handle *h); |
324 | 317 | ||
325 | 318 | ||
326 | /** | 319 | /** |
@@ -329,12 +322,12 @@ reconnect (struct GNUNET_RECLAIM_Handle *h); | |||
329 | * @param cls the handle | 322 | * @param cls the handle |
330 | */ | 323 | */ |
331 | static void | 324 | static void |
332 | reconnect_task (void *cls) | 325 | reconnect_task(void *cls) |
333 | { | 326 | { |
334 | struct GNUNET_RECLAIM_Handle *handle = cls; | 327 | struct GNUNET_RECLAIM_Handle *handle = cls; |
335 | 328 | ||
336 | handle->reconnect_task = NULL; | 329 | handle->reconnect_task = NULL; |
337 | reconnect (handle); | 330 | reconnect(handle); |
338 | } | 331 | } |
339 | 332 | ||
340 | 333 | ||
@@ -344,16 +337,16 @@ reconnect_task (void *cls) | |||
344 | * @param handle our service | 337 | * @param handle our service |
345 | */ | 338 | */ |
346 | static void | 339 | static void |
347 | force_reconnect (struct GNUNET_RECLAIM_Handle *handle) | 340 | force_reconnect(struct GNUNET_RECLAIM_Handle *handle) |
348 | { | 341 | { |
349 | GNUNET_MQ_destroy (handle->mq); | 342 | GNUNET_MQ_destroy(handle->mq); |
350 | handle->mq = NULL; | 343 | handle->mq = NULL; |
351 | handle->reconnect_backoff = | 344 | handle->reconnect_backoff = |
352 | GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | 345 | GNUNET_TIME_STD_BACKOFF(handle->reconnect_backoff); |
353 | handle->reconnect_task = | 346 | handle->reconnect_task = |
354 | GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, | 347 | GNUNET_SCHEDULER_add_delayed(handle->reconnect_backoff, |
355 | &reconnect_task, | 348 | &reconnect_task, |
356 | handle); | 349 | handle); |
357 | } | 350 | } |
358 | 351 | ||
359 | 352 | ||
@@ -363,14 +356,14 @@ force_reconnect (struct GNUNET_RECLAIM_Handle *handle) | |||
363 | * @param it entry to free | 356 | * @param it entry to free |
364 | */ | 357 | */ |
365 | static void | 358 | static void |
366 | free_it (struct GNUNET_RECLAIM_AttributeIterator *it) | 359 | free_it(struct GNUNET_RECLAIM_AttributeIterator *it) |
367 | { | 360 | { |
368 | struct GNUNET_RECLAIM_Handle *h = it->h; | 361 | struct GNUNET_RECLAIM_Handle *h = it->h; |
369 | 362 | ||
370 | GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); | 363 | GNUNET_CONTAINER_DLL_remove(h->it_head, h->it_tail, it); |
371 | if (NULL != it->env) | 364 | if (NULL != it->env) |
372 | GNUNET_MQ_discard (it->env); | 365 | GNUNET_MQ_discard(it->env); |
373 | GNUNET_free (it); | 366 | GNUNET_free(it); |
374 | } | 367 | } |
375 | 368 | ||
376 | /** | 369 | /** |
@@ -379,13 +372,13 @@ free_it (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
379 | * @param op the operation to free | 372 | * @param op the operation to free |
380 | */ | 373 | */ |
381 | static void | 374 | static void |
382 | free_op (struct GNUNET_RECLAIM_Operation *op) | 375 | free_op(struct GNUNET_RECLAIM_Operation *op) |
383 | { | 376 | { |
384 | if (NULL == op) | 377 | if (NULL == op) |
385 | return; | 378 | return; |
386 | if (NULL != op->env) | 379 | if (NULL != op->env) |
387 | GNUNET_MQ_discard (op->env); | 380 | GNUNET_MQ_discard(op->env); |
388 | GNUNET_free (op); | 381 | GNUNET_free(op); |
389 | } | 382 | } |
390 | 383 | ||
391 | 384 | ||
@@ -398,10 +391,11 @@ free_op (struct GNUNET_RECLAIM_Operation *op) | |||
398 | * @param error error code | 391 | * @param error error code |
399 | */ | 392 | */ |
400 | static void | 393 | static void |
401 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 394 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
402 | { | 395 | { |
403 | struct GNUNET_RECLAIM_Handle *handle = cls; | 396 | struct GNUNET_RECLAIM_Handle *handle = cls; |
404 | force_reconnect (handle); | 397 | |
398 | force_reconnect(handle); | ||
405 | } | 399 | } |
406 | 400 | ||
407 | 401 | ||
@@ -413,11 +407,11 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
413 | * @param msg the message we received | 407 | * @param msg the message we received |
414 | */ | 408 | */ |
415 | static void | 409 | static void |
416 | handle_success_response (void *cls, const struct SuccessResultMessage *msg) | 410 | handle_success_response(void *cls, const struct SuccessResultMessage *msg) |
417 | { | 411 | { |
418 | struct GNUNET_RECLAIM_Handle *h = cls; | 412 | struct GNUNET_RECLAIM_Handle *h = cls; |
419 | struct GNUNET_RECLAIM_Operation *op; | 413 | struct GNUNET_RECLAIM_Operation *op; |
420 | uint32_t r_id = ntohl (msg->id); | 414 | uint32_t r_id = ntohl(msg->id); |
421 | int res; | 415 | int res; |
422 | const char *emsg; | 416 | const char *emsg; |
423 | 417 | ||
@@ -427,20 +421,20 @@ handle_success_response (void *cls, const struct SuccessResultMessage *msg) | |||
427 | if (NULL == op) | 421 | if (NULL == op) |
428 | return; | 422 | return; |
429 | 423 | ||
430 | res = ntohl (msg->op_result); | 424 | res = ntohl(msg->op_result); |
431 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 425 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
432 | "Received SUCCESS_RESPONSE with result %d\n", | 426 | "Received SUCCESS_RESPONSE with result %d\n", |
433 | res); | 427 | res); |
434 | 428 | ||
435 | /* TODO: add actual error message to response... */ | 429 | /* TODO: add actual error message to response... */ |
436 | if (GNUNET_SYSERR == res) | 430 | if (GNUNET_SYSERR == res) |
437 | emsg = _ ("failed to store record\n"); | 431 | emsg = _("failed to store record\n"); |
438 | else | 432 | else |
439 | emsg = NULL; | 433 | emsg = NULL; |
440 | if (NULL != op->as_cb) | 434 | if (NULL != op->as_cb) |
441 | op->as_cb (op->cls, res, emsg); | 435 | op->as_cb(op->cls, res, emsg); |
442 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 436 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
443 | free_op (op); | 437 | free_op(op); |
444 | } | 438 | } |
445 | 439 | ||
446 | 440 | ||
@@ -453,19 +447,19 @@ handle_success_response (void *cls, const struct SuccessResultMessage *msg) | |||
453 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 447 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
454 | */ | 448 | */ |
455 | static int | 449 | static int |
456 | check_consume_ticket_result (void *cls, | 450 | check_consume_ticket_result(void *cls, |
457 | const struct ConsumeTicketResultMessage *msg) | 451 | const struct ConsumeTicketResultMessage *msg) |
458 | { | 452 | { |
459 | size_t msg_len; | 453 | size_t msg_len; |
460 | size_t attrs_len; | 454 | size_t attrs_len; |
461 | 455 | ||
462 | msg_len = ntohs (msg->header.size); | 456 | msg_len = ntohs(msg->header.size); |
463 | attrs_len = ntohs (msg->attrs_len); | 457 | attrs_len = ntohs(msg->attrs_len); |
464 | if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) | 458 | if (msg_len != sizeof(struct ConsumeTicketResultMessage) + attrs_len) |
465 | { | 459 | { |
466 | GNUNET_break (0); | 460 | GNUNET_break(0); |
467 | return GNUNET_SYSERR; | 461 | return GNUNET_SYSERR; |
468 | } | 462 | } |
469 | return GNUNET_OK; | 463 | return GNUNET_OK; |
470 | } | 464 | } |
471 | 465 | ||
@@ -478,16 +472,16 @@ check_consume_ticket_result (void *cls, | |||
478 | * @param msg the message we received | 472 | * @param msg the message we received |
479 | */ | 473 | */ |
480 | static void | 474 | static void |
481 | handle_consume_ticket_result (void *cls, | 475 | handle_consume_ticket_result(void *cls, |
482 | const struct ConsumeTicketResultMessage *msg) | 476 | const struct ConsumeTicketResultMessage *msg) |
483 | { | 477 | { |
484 | struct GNUNET_RECLAIM_Handle *h = cls; | 478 | struct GNUNET_RECLAIM_Handle *h = cls; |
485 | struct GNUNET_RECLAIM_Operation *op; | 479 | struct GNUNET_RECLAIM_Operation *op; |
486 | size_t attrs_len; | 480 | size_t attrs_len; |
487 | uint32_t r_id = ntohl (msg->id); | 481 | uint32_t r_id = ntohl(msg->id); |
488 | 482 | ||
489 | attrs_len = ntohs (msg->attrs_len); | 483 | attrs_len = ntohs(msg->attrs_len); |
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); | 484 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
491 | 485 | ||
492 | 486 | ||
493 | for (op = h->op_head; NULL != op; op = op->next) | 487 | for (op = h->op_head; NULL != op; op = op->next) |
@@ -500,28 +494,28 @@ handle_consume_ticket_result (void *cls, | |||
500 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 494 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; |
501 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 495 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
502 | attrs = | 496 | attrs = |
503 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len); | 497 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize((char *)&msg[1], attrs_len); |
504 | if (NULL != op->ar_cb) | 498 | if (NULL != op->ar_cb) |
505 | { | ||
506 | if (NULL == attrs) | ||
507 | { | 499 | { |
508 | op->ar_cb (op->cls, &msg->identity, NULL); | 500 | if (NULL == attrs) |
501 | { | ||
502 | op->ar_cb(op->cls, &msg->identity, NULL); | ||
503 | } | ||
504 | else | ||
505 | { | ||
506 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
507 | op->ar_cb(op->cls, &msg->identity, le->claim); | ||
508 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy(attrs); | ||
509 | attrs = NULL; | ||
510 | } | ||
511 | op->ar_cb(op->cls, NULL, NULL); | ||
509 | } | 512 | } |
510 | else | 513 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
511 | { | 514 | free_op(op); |
512 | for (le = attrs->list_head; NULL != le; le = le->next) | 515 | GNUNET_free_non_null(attrs); |
513 | op->ar_cb (op->cls, &msg->identity, le->claim); | ||
514 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | ||
515 | attrs = NULL; | ||
516 | } | ||
517 | op->ar_cb (op->cls, NULL, NULL); | ||
518 | } | ||
519 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
520 | free_op (op); | ||
521 | GNUNET_free_non_null (attrs); | ||
522 | return; | 516 | return; |
523 | } | 517 | } |
524 | GNUNET_assert (0); | 518 | GNUNET_assert(0); |
525 | } | 519 | } |
526 | 520 | ||
527 | 521 | ||
@@ -534,18 +528,18 @@ handle_consume_ticket_result (void *cls, | |||
534 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 528 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
535 | */ | 529 | */ |
536 | static int | 530 | static int |
537 | check_attribute_result (void *cls, const struct AttributeResultMessage *msg) | 531 | check_attribute_result(void *cls, const struct AttributeResultMessage *msg) |
538 | { | 532 | { |
539 | size_t msg_len; | 533 | size_t msg_len; |
540 | size_t attr_len; | 534 | size_t attr_len; |
541 | 535 | ||
542 | msg_len = ntohs (msg->header.size); | 536 | msg_len = ntohs(msg->header.size); |
543 | attr_len = ntohs (msg->attr_len); | 537 | attr_len = ntohs(msg->attr_len); |
544 | if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) | 538 | if (msg_len != sizeof(struct AttributeResultMessage) + attr_len) |
545 | { | 539 | { |
546 | GNUNET_break (0); | 540 | GNUNET_break(0); |
547 | return GNUNET_SYSERR; | 541 | return GNUNET_SYSERR; |
548 | } | 542 | } |
549 | return GNUNET_OK; | 543 | return GNUNET_OK; |
550 | } | 544 | } |
551 | 545 | ||
@@ -558,17 +552,17 @@ check_attribute_result (void *cls, const struct AttributeResultMessage *msg) | |||
558 | * @param msg the message we received | 552 | * @param msg the message we received |
559 | */ | 553 | */ |
560 | static void | 554 | static void |
561 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) | 555 | handle_attribute_result(void *cls, const struct AttributeResultMessage *msg) |
562 | { | 556 | { |
563 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; | 557 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; |
564 | struct GNUNET_RECLAIM_Handle *h = cls; | 558 | struct GNUNET_RECLAIM_Handle *h = cls; |
565 | struct GNUNET_RECLAIM_AttributeIterator *it; | 559 | struct GNUNET_RECLAIM_AttributeIterator *it; |
566 | struct GNUNET_RECLAIM_Operation *op; | 560 | struct GNUNET_RECLAIM_Operation *op; |
567 | size_t attr_len; | 561 | size_t attr_len; |
568 | uint32_t r_id = ntohl (msg->id); | 562 | uint32_t r_id = ntohl(msg->id); |
569 | 563 | ||
570 | attr_len = ntohs (msg->attr_len); | 564 | attr_len = ntohs(msg->attr_len); |
571 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); | 565 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
572 | 566 | ||
573 | 567 | ||
574 | for (it = h->it_head; NULL != it; it = it->next) | 568 | for (it = h->it_head; NULL != it; it = it->next) |
@@ -581,47 +575,47 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) | |||
581 | return; | 575 | return; |
582 | 576 | ||
583 | if ((0 == | 577 | if ((0 == |
584 | (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) | 578 | (memcmp(&msg->identity, &identity_dummy, sizeof(identity_dummy))))) |
585 | { | ||
586 | if ((NULL == it) && (NULL == op)) | ||
587 | { | 579 | { |
588 | GNUNET_break (0); | 580 | if ((NULL == it) && (NULL == op)) |
589 | force_reconnect (h); | 581 | { |
582 | GNUNET_break(0); | ||
583 | force_reconnect(h); | ||
584 | return; | ||
585 | } | ||
586 | if (NULL != it) | ||
587 | { | ||
588 | if (NULL != it->finish_cb) | ||
589 | it->finish_cb(it->finish_cb_cls); | ||
590 | free_it(it); | ||
591 | } | ||
592 | if (NULL != op) | ||
593 | { | ||
594 | if (NULL != op->ar_cb) | ||
595 | op->ar_cb(op->cls, NULL, NULL); | ||
596 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); | ||
597 | free_op(op); | ||
598 | } | ||
590 | return; | 599 | return; |
591 | } | 600 | } |
592 | if (NULL != it) | ||
593 | { | ||
594 | if (NULL != it->finish_cb) | ||
595 | it->finish_cb (it->finish_cb_cls); | ||
596 | free_it (it); | ||
597 | } | ||
598 | if (NULL != op) | ||
599 | { | ||
600 | if (NULL != op->ar_cb) | ||
601 | op->ar_cb (op->cls, NULL, NULL); | ||
602 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
603 | free_op (op); | ||
604 | } | ||
605 | return; | ||
606 | } | ||
607 | 601 | ||
608 | { | 602 | { |
609 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 603 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
610 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len); | 604 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize((char *)&msg[1], attr_len); |
611 | if (NULL != it) | 605 | if (NULL != it) |
612 | { | 606 | { |
613 | if (NULL != it->proc) | 607 | if (NULL != it->proc) |
614 | it->proc (it->proc_cls, &msg->identity, attr); | 608 | it->proc(it->proc_cls, &msg->identity, attr); |
615 | } | 609 | } |
616 | else if (NULL != op) | 610 | else if (NULL != op) |
617 | { | 611 | { |
618 | if (NULL != op->ar_cb) | 612 | if (NULL != op->ar_cb) |
619 | op->ar_cb (op->cls, &msg->identity, attr); | 613 | op->ar_cb(op->cls, &msg->identity, attr); |
620 | } | 614 | } |
621 | GNUNET_free (attr); | 615 | GNUNET_free(attr); |
622 | return; | 616 | return; |
623 | } | 617 | } |
624 | GNUNET_assert (0); | 618 | GNUNET_assert(0); |
625 | } | 619 | } |
626 | 620 | ||
627 | 621 | ||
@@ -633,13 +627,14 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) | |||
633 | * @param msg the message we received | 627 | * @param msg the message we received |
634 | */ | 628 | */ |
635 | static void | 629 | static void |
636 | handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | 630 | handle_ticket_result(void *cls, const struct TicketResultMessage *msg) |
637 | { | 631 | { |
638 | struct GNUNET_RECLAIM_Handle *handle = cls; | 632 | struct GNUNET_RECLAIM_Handle *handle = cls; |
639 | struct GNUNET_RECLAIM_Operation *op; | 633 | struct GNUNET_RECLAIM_Operation *op; |
640 | struct GNUNET_RECLAIM_TicketIterator *it; | 634 | struct GNUNET_RECLAIM_TicketIterator *it; |
641 | uint32_t r_id = ntohl (msg->id); | 635 | uint32_t r_id = ntohl(msg->id); |
642 | static const struct GNUNET_RECLAIM_Ticket ticket; | 636 | static const struct GNUNET_RECLAIM_Ticket ticket; |
637 | |||
643 | for (op = handle->op_head; NULL != op; op = op->next) | 638 | for (op = handle->op_head; NULL != op; op = op->next) |
644 | if (op->r_id == r_id) | 639 | if (op->r_id == r_id) |
645 | break; | 640 | break; |
@@ -649,41 +644,41 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | |||
649 | if ((NULL == op) && (NULL == it)) | 644 | if ((NULL == op) && (NULL == it)) |
650 | return; | 645 | return; |
651 | if (NULL != op) | 646 | if (NULL != op) |
652 | { | ||
653 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); | ||
654 | if (0 == | ||
655 | memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) | ||
656 | { | 647 | { |
657 | if (NULL != op->tr_cb) | 648 | GNUNET_CONTAINER_DLL_remove(handle->op_head, handle->op_tail, op); |
658 | op->tr_cb (op->cls, NULL); | 649 | if (0 == |
659 | } | 650 | memcmp(&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket))) |
660 | else | 651 | { |
661 | { | 652 | if (NULL != op->tr_cb) |
662 | if (NULL != op->tr_cb) | 653 | op->tr_cb(op->cls, NULL); |
663 | op->tr_cb (op->cls, &msg->ticket); | 654 | } |
655 | else | ||
656 | { | ||
657 | if (NULL != op->tr_cb) | ||
658 | op->tr_cb(op->cls, &msg->ticket); | ||
659 | } | ||
660 | free_op(op); | ||
661 | return; | ||
664 | } | 662 | } |
665 | free_op (op); | ||
666 | return; | ||
667 | } | ||
668 | else if (NULL != it) | 663 | else if (NULL != it) |
669 | { | ||
670 | if (0 == | ||
671 | memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) | ||
672 | { | ||
673 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | ||
674 | handle->ticket_it_tail, | ||
675 | it); | ||
676 | it->finish_cb (it->finish_cb_cls); | ||
677 | GNUNET_free (it); | ||
678 | } | ||
679 | else | ||
680 | { | 664 | { |
681 | if (NULL != it->tr_cb) | 665 | if (0 == |
682 | it->tr_cb (it->cls, &msg->ticket); | 666 | memcmp(&msg->ticket, &ticket, sizeof(struct GNUNET_RECLAIM_Ticket))) |
667 | { | ||
668 | GNUNET_CONTAINER_DLL_remove(handle->ticket_it_head, | ||
669 | handle->ticket_it_tail, | ||
670 | it); | ||
671 | it->finish_cb(it->finish_cb_cls); | ||
672 | GNUNET_free(it); | ||
673 | } | ||
674 | else | ||
675 | { | ||
676 | if (NULL != it->tr_cb) | ||
677 | it->tr_cb(it->cls, &msg->ticket); | ||
678 | } | ||
679 | return; | ||
683 | } | 680 | } |
684 | return; | 681 | GNUNET_break(0); |
685 | } | ||
686 | GNUNET_break (0); | ||
687 | } | 682 | } |
688 | 683 | ||
689 | 684 | ||
@@ -695,15 +690,15 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | |||
695 | * @param msg the message we received | 690 | * @param msg the message we received |
696 | */ | 691 | */ |
697 | static void | 692 | static void |
698 | handle_revoke_ticket_result (void *cls, | 693 | handle_revoke_ticket_result(void *cls, |
699 | const struct RevokeTicketResultMessage *msg) | 694 | const struct RevokeTicketResultMessage *msg) |
700 | { | 695 | { |
701 | struct GNUNET_RECLAIM_Handle *h = cls; | 696 | struct GNUNET_RECLAIM_Handle *h = cls; |
702 | struct GNUNET_RECLAIM_Operation *op; | 697 | struct GNUNET_RECLAIM_Operation *op; |
703 | uint32_t r_id = ntohl (msg->id); | 698 | uint32_t r_id = ntohl(msg->id); |
704 | int32_t success; | 699 | int32_t success; |
705 | 700 | ||
706 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); | 701 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); |
707 | 702 | ||
708 | 703 | ||
709 | for (op = h->op_head; NULL != op; op = op->next) | 704 | for (op = h->op_head; NULL != op; op = op->next) |
@@ -711,17 +706,17 @@ handle_revoke_ticket_result (void *cls, | |||
711 | break; | 706 | break; |
712 | if (NULL == op) | 707 | if (NULL == op) |
713 | return; | 708 | return; |
714 | success = ntohl (msg->success); | 709 | success = ntohl(msg->success); |
715 | { | 710 | { |
716 | if (NULL != op->rvk_cb) | 711 | if (NULL != op->rvk_cb) |
717 | { | 712 | { |
718 | op->rvk_cb (op->cls, success, NULL); | 713 | op->rvk_cb(op->cls, success, NULL); |
719 | } | 714 | } |
720 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 715 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
721 | free_op (op); | 716 | free_op(op); |
722 | return; | 717 | return; |
723 | } | 718 | } |
724 | GNUNET_assert (0); | 719 | GNUNET_assert(0); |
725 | } | 720 | } |
726 | 721 | ||
727 | 722 | ||
@@ -731,41 +726,41 @@ handle_revoke_ticket_result (void *cls, | |||
731 | * @param h handle to the reclaim service. | 726 | * @param h handle to the reclaim service. |
732 | */ | 727 | */ |
733 | static void | 728 | static void |
734 | reconnect (struct GNUNET_RECLAIM_Handle *h) | 729 | reconnect(struct GNUNET_RECLAIM_Handle *h) |
735 | { | 730 | { |
736 | struct GNUNET_MQ_MessageHandler handlers[] = | 731 | struct GNUNET_MQ_MessageHandler handlers[] = |
737 | {GNUNET_MQ_hd_fixed_size (success_response, | 732 | { GNUNET_MQ_hd_fixed_size(success_response, |
738 | GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, | 733 | GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, |
739 | struct SuccessResultMessage, | 734 | struct SuccessResultMessage, |
740 | h), | ||
741 | GNUNET_MQ_hd_var_size (attribute_result, | ||
742 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, | ||
743 | struct AttributeResultMessage, | ||
744 | h), | 735 | h), |
745 | GNUNET_MQ_hd_fixed_size (ticket_result, | 736 | GNUNET_MQ_hd_var_size(attribute_result, |
746 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, | 737 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, |
747 | struct TicketResultMessage, | 738 | struct AttributeResultMessage, |
748 | h), | 739 | h), |
749 | GNUNET_MQ_hd_var_size (consume_ticket_result, | 740 | GNUNET_MQ_hd_fixed_size(ticket_result, |
750 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, | 741 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, |
751 | struct ConsumeTicketResultMessage, | 742 | struct TicketResultMessage, |
752 | h), | 743 | h), |
753 | GNUNET_MQ_hd_fixed_size (revoke_ticket_result, | 744 | GNUNET_MQ_hd_var_size(consume_ticket_result, |
754 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, | 745 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, |
755 | struct RevokeTicketResultMessage, | 746 | struct ConsumeTicketResultMessage, |
756 | h), | 747 | h), |
757 | GNUNET_MQ_handler_end ()}; | 748 | GNUNET_MQ_hd_fixed_size(revoke_ticket_result, |
749 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, | ||
750 | struct RevokeTicketResultMessage, | ||
751 | h), | ||
752 | GNUNET_MQ_handler_end() }; | ||
758 | struct GNUNET_RECLAIM_Operation *op; | 753 | struct GNUNET_RECLAIM_Operation *op; |
759 | 754 | ||
760 | GNUNET_assert (NULL == h->mq); | 755 | GNUNET_assert(NULL == h->mq); |
761 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); | 756 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); |
762 | 757 | ||
763 | h->mq = | 758 | h->mq = |
764 | GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); | 759 | GNUNET_CLIENT_connect(h->cfg, "reclaim", handlers, &mq_error_handler, h); |
765 | if (NULL == h->mq) | 760 | if (NULL == h->mq) |
766 | return; | 761 | return; |
767 | for (op = h->op_head; NULL != op; op = op->next) | 762 | for (op = h->op_head; NULL != op; op = op->next) |
768 | GNUNET_MQ_send_copy (h->mq, op->env); | 763 | GNUNET_MQ_send_copy(h->mq, op->env); |
769 | } | 764 | } |
770 | 765 | ||
771 | 766 | ||
@@ -776,18 +771,18 @@ reconnect (struct GNUNET_RECLAIM_Handle *h) | |||
776 | * @return handle to use | 771 | * @return handle to use |
777 | */ | 772 | */ |
778 | struct GNUNET_RECLAIM_Handle * | 773 | struct GNUNET_RECLAIM_Handle * |
779 | GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 774 | GNUNET_RECLAIM_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
780 | { | 775 | { |
781 | struct GNUNET_RECLAIM_Handle *h; | 776 | struct GNUNET_RECLAIM_Handle *h; |
782 | 777 | ||
783 | h = GNUNET_new (struct GNUNET_RECLAIM_Handle); | 778 | h = GNUNET_new(struct GNUNET_RECLAIM_Handle); |
784 | h->cfg = cfg; | 779 | h->cfg = cfg; |
785 | reconnect (h); | 780 | reconnect(h); |
786 | if (NULL == h->mq) | 781 | if (NULL == h->mq) |
787 | { | 782 | { |
788 | GNUNET_free (h); | 783 | GNUNET_free(h); |
789 | return NULL; | 784 | return NULL; |
790 | } | 785 | } |
791 | return h; | 786 | return h; |
792 | } | 787 | } |
793 | 788 | ||
@@ -801,12 +796,12 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
801 | * @param op operation to cancel | 796 | * @param op operation to cancel |
802 | */ | 797 | */ |
803 | void | 798 | void |
804 | GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) | 799 | GNUNET_RECLAIM_cancel(struct GNUNET_RECLAIM_Operation *op) |
805 | { | 800 | { |
806 | struct GNUNET_RECLAIM_Handle *h = op->h; | 801 | struct GNUNET_RECLAIM_Handle *h = op->h; |
807 | 802 | ||
808 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 803 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
809 | free_op (op); | 804 | free_op(op); |
810 | } | 805 | } |
811 | 806 | ||
812 | 807 | ||
@@ -816,21 +811,21 @@ GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) | |||
816 | * @param h handle to destroy | 811 | * @param h handle to destroy |
817 | */ | 812 | */ |
818 | void | 813 | void |
819 | GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | 814 | GNUNET_RECLAIM_disconnect(struct GNUNET_RECLAIM_Handle *h) |
820 | { | 815 | { |
821 | GNUNET_assert (NULL != h); | 816 | GNUNET_assert(NULL != h); |
822 | if (NULL != h->mq) | 817 | if (NULL != h->mq) |
823 | { | 818 | { |
824 | GNUNET_MQ_destroy (h->mq); | 819 | GNUNET_MQ_destroy(h->mq); |
825 | h->mq = NULL; | 820 | h->mq = NULL; |
826 | } | 821 | } |
827 | if (NULL != h->reconnect_task) | 822 | if (NULL != h->reconnect_task) |
828 | { | 823 | { |
829 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 824 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
830 | h->reconnect_task = NULL; | 825 | h->reconnect_task = NULL; |
831 | } | 826 | } |
832 | GNUNET_assert (NULL == h->op_head); | 827 | GNUNET_assert(NULL == h->op_head); |
833 | GNUNET_free (h); | 828 | GNUNET_free(h); |
834 | } | 829 | } |
835 | 830 | ||
836 | /** | 831 | /** |
@@ -846,7 +841,7 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | |||
846 | * @return handle to abort the request | 841 | * @return handle to abort the request |
847 | */ | 842 | */ |
848 | struct GNUNET_RECLAIM_Operation * | 843 | struct GNUNET_RECLAIM_Operation * |
849 | GNUNET_RECLAIM_attribute_store ( | 844 | GNUNET_RECLAIM_attribute_store( |
850 | struct GNUNET_RECLAIM_Handle *h, | 845 | struct GNUNET_RECLAIM_Handle *h, |
851 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 846 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
852 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 847 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
@@ -858,25 +853,25 @@ GNUNET_RECLAIM_attribute_store ( | |||
858 | struct AttributeStoreMessage *sam; | 853 | struct AttributeStoreMessage *sam; |
859 | size_t attr_len; | 854 | size_t attr_len; |
860 | 855 | ||
861 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 856 | op = GNUNET_new(struct GNUNET_RECLAIM_Operation); |
862 | op->h = h; | 857 | op->h = h; |
863 | op->as_cb = cont; | 858 | op->as_cb = cont; |
864 | op->cls = cont_cls; | 859 | op->cls = cont_cls; |
865 | op->r_id = h->r_id_gen++; | 860 | op->r_id = h->r_id_gen++; |
866 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 861 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
867 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); | 862 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(attr); |
868 | op->env = GNUNET_MQ_msg_extra (sam, | 863 | op->env = GNUNET_MQ_msg_extra(sam, |
869 | attr_len, | 864 | attr_len, |
870 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); | 865 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); |
871 | sam->identity = *pkey; | 866 | sam->identity = *pkey; |
872 | sam->id = htonl (op->r_id); | 867 | sam->id = htonl(op->r_id); |
873 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); | 868 | sam->exp = GNUNET_htonll(exp_interval->rel_value_us); |
874 | 869 | ||
875 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]); | 870 | GNUNET_RECLAIM_ATTRIBUTE_serialize(attr, (char *)&sam[1]); |
876 | 871 | ||
877 | sam->attr_len = htons (attr_len); | 872 | sam->attr_len = htons(attr_len); |
878 | if (NULL != h->mq) | 873 | if (NULL != h->mq) |
879 | GNUNET_MQ_send_copy (h->mq, op->env); | 874 | GNUNET_MQ_send_copy(h->mq, op->env); |
880 | return op; | 875 | return op; |
881 | } | 876 | } |
882 | 877 | ||
@@ -893,7 +888,7 @@ GNUNET_RECLAIM_attribute_store ( | |||
893 | * @return handle Used to to abort the request | 888 | * @return handle Used to to abort the request |
894 | */ | 889 | */ |
895 | struct GNUNET_RECLAIM_Operation * | 890 | struct GNUNET_RECLAIM_Operation * |
896 | GNUNET_RECLAIM_attribute_delete ( | 891 | GNUNET_RECLAIM_attribute_delete( |
897 | struct GNUNET_RECLAIM_Handle *h, | 892 | struct GNUNET_RECLAIM_Handle *h, |
898 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 893 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
899 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 894 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
@@ -904,23 +899,23 @@ GNUNET_RECLAIM_attribute_delete ( | |||
904 | struct AttributeDeleteMessage *dam; | 899 | struct AttributeDeleteMessage *dam; |
905 | size_t attr_len; | 900 | size_t attr_len; |
906 | 901 | ||
907 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 902 | op = GNUNET_new(struct GNUNET_RECLAIM_Operation); |
908 | op->h = h; | 903 | op->h = h; |
909 | op->as_cb = cont; | 904 | op->as_cb = cont; |
910 | op->cls = cont_cls; | 905 | op->cls = cont_cls; |
911 | op->r_id = h->r_id_gen++; | 906 | op->r_id = h->r_id_gen++; |
912 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 907 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
913 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); | 908 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(attr); |
914 | op->env = GNUNET_MQ_msg_extra (dam, | 909 | op->env = GNUNET_MQ_msg_extra(dam, |
915 | attr_len, | 910 | attr_len, |
916 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); | 911 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); |
917 | dam->identity = *pkey; | 912 | dam->identity = *pkey; |
918 | dam->id = htonl (op->r_id); | 913 | dam->id = htonl(op->r_id); |
919 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]); | 914 | GNUNET_RECLAIM_ATTRIBUTE_serialize(attr, (char *)&dam[1]); |
920 | 915 | ||
921 | dam->attr_len = htons (attr_len); | 916 | dam->attr_len = htons(attr_len); |
922 | if (NULL != h->mq) | 917 | if (NULL != h->mq) |
923 | GNUNET_MQ_send_copy (h->mq, op->env); | 918 | GNUNET_MQ_send_copy(h->mq, op->env); |
924 | return op; | 919 | return op; |
925 | } | 920 | } |
926 | 921 | ||
@@ -950,7 +945,7 @@ GNUNET_RECLAIM_attribute_delete ( | |||
950 | * @return an iterator Handle to use for iteration | 945 | * @return an iterator Handle to use for iteration |
951 | */ | 946 | */ |
952 | struct GNUNET_RECLAIM_AttributeIterator * | 947 | struct GNUNET_RECLAIM_AttributeIterator * |
953 | GNUNET_RECLAIM_get_attributes_start ( | 948 | GNUNET_RECLAIM_get_attributes_start( |
954 | struct GNUNET_RECLAIM_Handle *h, | 949 | struct GNUNET_RECLAIM_Handle *h, |
955 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 950 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
956 | GNUNET_SCHEDULER_TaskCallback error_cb, | 951 | GNUNET_SCHEDULER_TaskCallback error_cb, |
@@ -966,7 +961,7 @@ GNUNET_RECLAIM_get_attributes_start ( | |||
966 | uint32_t rid; | 961 | uint32_t rid; |
967 | 962 | ||
968 | rid = h->r_id_gen++; | 963 | rid = h->r_id_gen++; |
969 | it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator); | 964 | it = GNUNET_new(struct GNUNET_RECLAIM_AttributeIterator); |
970 | it->h = h; | 965 | it->h = h; |
971 | it->error_cb = error_cb; | 966 | it->error_cb = error_cb; |
972 | it->error_cb_cls = error_cb_cls; | 967 | it->error_cb_cls = error_cb_cls; |
@@ -976,15 +971,15 @@ GNUNET_RECLAIM_get_attributes_start ( | |||
976 | it->proc_cls = proc_cls; | 971 | it->proc_cls = proc_cls; |
977 | it->r_id = rid; | 972 | it->r_id = rid; |
978 | it->identity = *identity; | 973 | it->identity = *identity; |
979 | GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); | 974 | GNUNET_CONTAINER_DLL_insert_tail(h->it_head, h->it_tail, it); |
980 | env = | 975 | env = |
981 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); | 976 | GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); |
982 | msg->id = htonl (rid); | 977 | msg->id = htonl(rid); |
983 | msg->identity = *identity; | 978 | msg->identity = *identity; |
984 | if (NULL == h->mq) | 979 | if (NULL == h->mq) |
985 | it->env = env; | 980 | it->env = env; |
986 | else | 981 | else |
987 | GNUNET_MQ_send (h->mq, env); | 982 | GNUNET_MQ_send(h->mq, env); |
988 | return it; | 983 | return it; |
989 | } | 984 | } |
990 | 985 | ||
@@ -996,16 +991,16 @@ GNUNET_RECLAIM_get_attributes_start ( | |||
996 | * @param it the iterator | 991 | * @param it the iterator |
997 | */ | 992 | */ |
998 | void | 993 | void |
999 | GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it) | 994 | GNUNET_RECLAIM_get_attributes_next(struct GNUNET_RECLAIM_AttributeIterator *it) |
1000 | { | 995 | { |
1001 | struct GNUNET_RECLAIM_Handle *h = it->h; | 996 | struct GNUNET_RECLAIM_Handle *h = it->h; |
1002 | struct AttributeIterationNextMessage *msg; | 997 | struct AttributeIterationNextMessage *msg; |
1003 | struct GNUNET_MQ_Envelope *env; | 998 | struct GNUNET_MQ_Envelope *env; |
1004 | 999 | ||
1005 | env = | 1000 | env = |
1006 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT); | 1001 | GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT); |
1007 | msg->id = htonl (it->r_id); | 1002 | msg->id = htonl(it->r_id); |
1008 | GNUNET_MQ_send (h->mq, env); | 1003 | GNUNET_MQ_send(h->mq, env); |
1009 | } | 1004 | } |
1010 | 1005 | ||
1011 | 1006 | ||
@@ -1017,20 +1012,20 @@ GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1017 | * @param it the iterator | 1012 | * @param it the iterator |
1018 | */ | 1013 | */ |
1019 | void | 1014 | void |
1020 | GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | 1015 | GNUNET_RECLAIM_get_attributes_stop(struct GNUNET_RECLAIM_AttributeIterator *it) |
1021 | { | 1016 | { |
1022 | struct GNUNET_RECLAIM_Handle *h = it->h; | 1017 | struct GNUNET_RECLAIM_Handle *h = it->h; |
1023 | struct GNUNET_MQ_Envelope *env; | 1018 | struct GNUNET_MQ_Envelope *env; |
1024 | struct AttributeIterationStopMessage *msg; | 1019 | struct AttributeIterationStopMessage *msg; |
1025 | 1020 | ||
1026 | if (NULL != h->mq) | 1021 | if (NULL != h->mq) |
1027 | { | 1022 | { |
1028 | env = | 1023 | env = |
1029 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); | 1024 | GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); |
1030 | msg->id = htonl (it->r_id); | 1025 | msg->id = htonl(it->r_id); |
1031 | GNUNET_MQ_send (h->mq, env); | 1026 | GNUNET_MQ_send(h->mq, env); |
1032 | } | 1027 | } |
1033 | free_it (it); | 1028 | free_it(it); |
1034 | } | 1029 | } |
1035 | 1030 | ||
1036 | 1031 | ||
@@ -1048,7 +1043,7 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1048 | * @return handle to abort the operation | 1043 | * @return handle to abort the operation |
1049 | */ | 1044 | */ |
1050 | struct GNUNET_RECLAIM_Operation * | 1045 | struct GNUNET_RECLAIM_Operation * |
1051 | GNUNET_RECLAIM_ticket_issue ( | 1046 | GNUNET_RECLAIM_ticket_issue( |
1052 | struct GNUNET_RECLAIM_Handle *h, | 1047 | struct GNUNET_RECLAIM_Handle *h, |
1053 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, | 1048 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, |
1054 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, | 1049 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, |
@@ -1059,26 +1054,27 @@ GNUNET_RECLAIM_ticket_issue ( | |||
1059 | struct GNUNET_RECLAIM_Operation *op; | 1054 | struct GNUNET_RECLAIM_Operation *op; |
1060 | struct IssueTicketMessage *tim; | 1055 | struct IssueTicketMessage *tim; |
1061 | size_t attr_len; | 1056 | size_t attr_len; |
1062 | fprintf (stderr, "Issuing ticket\n"); | 1057 | |
1063 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 1058 | fprintf(stderr, "Issuing ticket\n"); |
1059 | op = GNUNET_new(struct GNUNET_RECLAIM_Operation); | ||
1064 | op->h = h; | 1060 | op->h = h; |
1065 | op->tr_cb = cb; | 1061 | op->tr_cb = cb; |
1066 | op->cls = cb_cls; | 1062 | op->cls = cb_cls; |
1067 | op->r_id = h->r_id_gen++; | 1063 | op->r_id = h->r_id_gen++; |
1068 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1064 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
1069 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | 1065 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size(attrs); |
1070 | op->env = GNUNET_MQ_msg_extra (tim, | 1066 | op->env = GNUNET_MQ_msg_extra(tim, |
1071 | attr_len, | 1067 | attr_len, |
1072 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); | 1068 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); |
1073 | tim->identity = *iss; | 1069 | tim->identity = *iss; |
1074 | tim->rp = *rp; | 1070 | tim->rp = *rp; |
1075 | tim->id = htonl (op->r_id); | 1071 | tim->id = htonl(op->r_id); |
1076 | 1072 | ||
1077 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *) &tim[1]); | 1073 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize(attrs, (char *)&tim[1]); |
1078 | 1074 | ||
1079 | tim->attr_len = htons (attr_len); | 1075 | tim->attr_len = htons(attr_len); |
1080 | if (NULL != h->mq) | 1076 | if (NULL != h->mq) |
1081 | GNUNET_MQ_send_copy (h->mq, op->env); | 1077 | GNUNET_MQ_send_copy(h->mq, op->env); |
1082 | return op; | 1078 | return op; |
1083 | } | 1079 | } |
1084 | 1080 | ||
@@ -1096,7 +1092,7 @@ GNUNET_RECLAIM_ticket_issue ( | |||
1096 | * @return handle to abort the operation | 1092 | * @return handle to abort the operation |
1097 | */ | 1093 | */ |
1098 | struct GNUNET_RECLAIM_Operation * | 1094 | struct GNUNET_RECLAIM_Operation * |
1099 | GNUNET_RECLAIM_ticket_consume ( | 1095 | GNUNET_RECLAIM_ticket_consume( |
1100 | struct GNUNET_RECLAIM_Handle *h, | 1096 | struct GNUNET_RECLAIM_Handle *h, |
1101 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1097 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1102 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1098 | const struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -1106,18 +1102,18 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1106 | struct GNUNET_RECLAIM_Operation *op; | 1102 | struct GNUNET_RECLAIM_Operation *op; |
1107 | struct ConsumeTicketMessage *ctm; | 1103 | struct ConsumeTicketMessage *ctm; |
1108 | 1104 | ||
1109 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 1105 | op = GNUNET_new(struct GNUNET_RECLAIM_Operation); |
1110 | op->h = h; | 1106 | op->h = h; |
1111 | op->ar_cb = cb; | 1107 | op->ar_cb = cb; |
1112 | op->cls = cb_cls; | 1108 | op->cls = cb_cls; |
1113 | op->r_id = h->r_id_gen++; | 1109 | op->r_id = h->r_id_gen++; |
1114 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1110 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
1115 | op->env = GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); | 1111 | op->env = GNUNET_MQ_msg(ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); |
1116 | ctm->identity = *identity; | 1112 | ctm->identity = *identity; |
1117 | ctm->id = htonl (op->r_id); | 1113 | ctm->id = htonl(op->r_id); |
1118 | ctm->ticket = *ticket; | 1114 | ctm->ticket = *ticket; |
1119 | if (NULL != h->mq) | 1115 | if (NULL != h->mq) |
1120 | GNUNET_MQ_send_copy (h->mq, op->env); | 1116 | GNUNET_MQ_send_copy(h->mq, op->env); |
1121 | return op; | 1117 | return op; |
1122 | } | 1118 | } |
1123 | 1119 | ||
@@ -1140,7 +1136,7 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1140 | * @return an iterator handle to use for iteration | 1136 | * @return an iterator handle to use for iteration |
1141 | */ | 1137 | */ |
1142 | struct GNUNET_RECLAIM_TicketIterator * | 1138 | struct GNUNET_RECLAIM_TicketIterator * |
1143 | GNUNET_RECLAIM_ticket_iteration_start ( | 1139 | GNUNET_RECLAIM_ticket_iteration_start( |
1144 | struct GNUNET_RECLAIM_Handle *h, | 1140 | struct GNUNET_RECLAIM_Handle *h, |
1145 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1141 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1146 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1142 | GNUNET_SCHEDULER_TaskCallback error_cb, |
@@ -1156,7 +1152,7 @@ GNUNET_RECLAIM_ticket_iteration_start ( | |||
1156 | uint32_t rid; | 1152 | uint32_t rid; |
1157 | 1153 | ||
1158 | rid = h->r_id_gen++; | 1154 | rid = h->r_id_gen++; |
1159 | it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator); | 1155 | it = GNUNET_new(struct GNUNET_RECLAIM_TicketIterator); |
1160 | it->h = h; | 1156 | it->h = h; |
1161 | it->error_cb = error_cb; | 1157 | it->error_cb = error_cb; |
1162 | it->error_cb_cls = error_cb_cls; | 1158 | it->error_cb_cls = error_cb_cls; |
@@ -1165,14 +1161,14 @@ GNUNET_RECLAIM_ticket_iteration_start ( | |||
1165 | it->tr_cb = proc; | 1161 | it->tr_cb = proc; |
1166 | it->cls = proc_cls; | 1162 | it->cls = proc_cls; |
1167 | it->r_id = rid; | 1163 | it->r_id = rid; |
1168 | GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, h->ticket_it_tail, it); | 1164 | GNUNET_CONTAINER_DLL_insert_tail(h->ticket_it_head, h->ticket_it_tail, it); |
1169 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START); | 1165 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START); |
1170 | msg->id = htonl (rid); | 1166 | msg->id = htonl(rid); |
1171 | msg->identity = *identity; | 1167 | msg->identity = *identity; |
1172 | if (NULL == h->mq) | 1168 | if (NULL == h->mq) |
1173 | it->env = env; | 1169 | it->env = env; |
1174 | else | 1170 | else |
1175 | GNUNET_MQ_send (h->mq, env); | 1171 | GNUNET_MQ_send(h->mq, env); |
1176 | return it; | 1172 | return it; |
1177 | } | 1173 | } |
1178 | 1174 | ||
@@ -1184,15 +1180,15 @@ GNUNET_RECLAIM_ticket_iteration_start ( | |||
1184 | * @param it the iterator | 1180 | * @param it the iterator |
1185 | */ | 1181 | */ |
1186 | void | 1182 | void |
1187 | GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it) | 1183 | GNUNET_RECLAIM_ticket_iteration_next(struct GNUNET_RECLAIM_TicketIterator *it) |
1188 | { | 1184 | { |
1189 | struct GNUNET_RECLAIM_Handle *h = it->h; | 1185 | struct GNUNET_RECLAIM_Handle *h = it->h; |
1190 | struct TicketIterationNextMessage *msg; | 1186 | struct TicketIterationNextMessage *msg; |
1191 | struct GNUNET_MQ_Envelope *env; | 1187 | struct GNUNET_MQ_Envelope *env; |
1192 | 1188 | ||
1193 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT); | 1189 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT); |
1194 | msg->id = htonl (it->r_id); | 1190 | msg->id = htonl(it->r_id); |
1195 | GNUNET_MQ_send (h->mq, env); | 1191 | GNUNET_MQ_send(h->mq, env); |
1196 | } | 1192 | } |
1197 | 1193 | ||
1198 | 1194 | ||
@@ -1204,20 +1200,20 @@ GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1204 | * @param it the iterator | 1200 | * @param it the iterator |
1205 | */ | 1201 | */ |
1206 | void | 1202 | void |
1207 | GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | 1203 | GNUNET_RECLAIM_ticket_iteration_stop(struct GNUNET_RECLAIM_TicketIterator *it) |
1208 | { | 1204 | { |
1209 | struct GNUNET_RECLAIM_Handle *h = it->h; | 1205 | struct GNUNET_RECLAIM_Handle *h = it->h; |
1210 | struct GNUNET_MQ_Envelope *env; | 1206 | struct GNUNET_MQ_Envelope *env; |
1211 | struct TicketIterationStopMessage *msg; | 1207 | struct TicketIterationStopMessage *msg; |
1212 | 1208 | ||
1213 | if (NULL != h->mq) | 1209 | if (NULL != h->mq) |
1214 | { | 1210 | { |
1215 | env = | 1211 | env = |
1216 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); | 1212 | GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); |
1217 | msg->id = htonl (it->r_id); | 1213 | msg->id = htonl(it->r_id); |
1218 | GNUNET_MQ_send (h->mq, env); | 1214 | GNUNET_MQ_send(h->mq, env); |
1219 | } | 1215 | } |
1220 | GNUNET_free (it); | 1216 | GNUNET_free(it); |
1221 | } | 1217 | } |
1222 | 1218 | ||
1223 | 1219 | ||
@@ -1235,7 +1231,7 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1235 | * @return handle to abort the operation | 1231 | * @return handle to abort the operation |
1236 | */ | 1232 | */ |
1237 | struct GNUNET_RECLAIM_Operation * | 1233 | struct GNUNET_RECLAIM_Operation * |
1238 | GNUNET_RECLAIM_ticket_revoke ( | 1234 | GNUNET_RECLAIM_ticket_revoke( |
1239 | struct GNUNET_RECLAIM_Handle *h, | 1235 | struct GNUNET_RECLAIM_Handle *h, |
1240 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1236 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1241 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1237 | const struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -1247,21 +1243,21 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
1247 | uint32_t rid; | 1243 | uint32_t rid; |
1248 | 1244 | ||
1249 | rid = h->r_id_gen++; | 1245 | rid = h->r_id_gen++; |
1250 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 1246 | op = GNUNET_new(struct GNUNET_RECLAIM_Operation); |
1251 | op->h = h; | 1247 | op->h = h; |
1252 | op->rvk_cb = cb; | 1248 | op->rvk_cb = cb; |
1253 | op->cls = cb_cls; | 1249 | op->cls = cb_cls; |
1254 | op->r_id = rid; | 1250 | op->r_id = rid; |
1255 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1251 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
1256 | op->env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); | 1252 | op->env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); |
1257 | msg->id = htonl (rid); | 1253 | msg->id = htonl(rid); |
1258 | msg->identity = *identity; | 1254 | msg->identity = *identity; |
1259 | msg->ticket = *ticket; | 1255 | msg->ticket = *ticket; |
1260 | if (NULL != h->mq) | 1256 | if (NULL != h->mq) |
1261 | { | 1257 | { |
1262 | GNUNET_MQ_send (h->mq, op->env); | 1258 | GNUNET_MQ_send(h->mq, op->env); |
1263 | op->env = NULL; | 1259 | op->env = NULL; |
1264 | } | 1260 | } |
1265 | return op; | 1261 | return op; |
1266 | } | 1262 | } |
1267 | 1263 | ||