diff options
Diffstat (limited to 'src/peerinfo-tool/plugin_rest_peerinfo.c')
-rw-r--r-- | src/peerinfo-tool/plugin_rest_peerinfo.c | 541 |
1 files changed, 273 insertions, 268 deletions
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c index 238946d54..176e24e42 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/peerinfo-tool/plugin_rest_peerinfo.c | |||
@@ -61,7 +61,7 @@ | |||
61 | /** | 61 | /** |
62 | * How long until we time out during address lookup? | 62 | * How long until we time out during address lookup? |
63 | */ | 63 | */ |
64 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 64 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
65 | /** | 65 | /** |
66 | * The configuration handle | 66 | * The configuration handle |
67 | */ | 67 | */ |
@@ -70,12 +70,13 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
70 | /** | 70 | /** |
71 | * HTTP methods allows for this plugin | 71 | * HTTP methods allows for this plugin |
72 | */ | 72 | */ |
73 | static char* allow_methods; | 73 | static char*allow_methods; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * @brief struct returned by the initialization function of the plugin | 76 | * @brief struct returned by the initialization function of the plugin |
77 | */ | 77 | */ |
78 | struct Plugin { | 78 | struct Plugin |
79 | { | ||
79 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 80 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
80 | }; | 81 | }; |
81 | 82 | ||
@@ -83,7 +84,8 @@ struct Plugin { | |||
83 | /** | 84 | /** |
84 | * Record we keep for each printable address. | 85 | * Record we keep for each printable address. |
85 | */ | 86 | */ |
86 | struct AddressRecord { | 87 | struct AddressRecord |
88 | { | ||
87 | /** | 89 | /** |
88 | * Current address-to-string context (if active, otherwise NULL). | 90 | * Current address-to-string context (if active, otherwise NULL). |
89 | */ | 91 | */ |
@@ -109,7 +111,8 @@ struct AddressRecord { | |||
109 | /** | 111 | /** |
110 | * Structure we use to collect printable address information. | 112 | * Structure we use to collect printable address information. |
111 | */ | 113 | */ |
112 | struct PrintContext { | 114 | struct PrintContext |
115 | { | ||
113 | /** | 116 | /** |
114 | * Kept in DLL. | 117 | * Kept in DLL. |
115 | */ | 118 | */ |
@@ -169,7 +172,8 @@ static struct PrintContext *pc_tail; | |||
169 | /** | 172 | /** |
170 | * The request handle | 173 | * The request handle |
171 | */ | 174 | */ |
172 | struct RequestHandle { | 175 | struct RequestHandle |
176 | { | ||
173 | /** | 177 | /** |
174 | * JSON temporary array | 178 | * JSON temporary array |
175 | */ | 179 | */ |
@@ -252,51 +256,51 @@ struct RequestHandle { | |||
252 | * @param handle Handle to clean up | 256 | * @param handle Handle to clean up |
253 | */ | 257 | */ |
254 | static void | 258 | static void |
255 | cleanup_handle(void *cls) | 259 | cleanup_handle (void *cls) |
256 | { | 260 | { |
257 | struct RequestHandle *handle = cls; | 261 | struct RequestHandle *handle = cls; |
258 | 262 | ||
259 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
260 | "Cleaning up\n"); | 264 | "Cleaning up\n"); |
261 | if (NULL != handle->timeout_task) | 265 | if (NULL != handle->timeout_task) |
262 | { | 266 | { |
263 | GNUNET_SCHEDULER_cancel(handle->timeout_task); | 267 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
264 | handle->timeout_task = NULL; | 268 | handle->timeout_task = NULL; |
265 | } | 269 | } |
266 | if (NULL != handle->url) | 270 | if (NULL != handle->url) |
267 | GNUNET_free(handle->url); | 271 | GNUNET_free (handle->url); |
268 | if (NULL != handle->emsg) | 272 | if (NULL != handle->emsg) |
269 | GNUNET_free(handle->emsg); | 273 | GNUNET_free (handle->emsg); |
270 | if (NULL != handle->address) | 274 | if (NULL != handle->address) |
271 | GNUNET_free((char*)handle->address); | 275 | GNUNET_free ((char*) handle->address); |
272 | if (NULL != handle->expiration_str) | 276 | if (NULL != handle->expiration_str) |
273 | GNUNET_free(handle->expiration_str); | 277 | GNUNET_free (handle->expiration_str); |
274 | if (NULL != handle->pubkey) | 278 | if (NULL != handle->pubkey) |
275 | GNUNET_free(handle->pubkey); | 279 | GNUNET_free (handle->pubkey); |
276 | 280 | ||
277 | if (NULL != handle->temp_array) | 281 | if (NULL != handle->temp_array) |
278 | { | 282 | { |
279 | json_decref(handle->temp_array); | 283 | json_decref (handle->temp_array); |
280 | handle->temp_array = NULL; | 284 | handle->temp_array = NULL; |
281 | } | 285 | } |
282 | if (NULL != handle->response) | 286 | if (NULL != handle->response) |
283 | { | 287 | { |
284 | json_decref(handle->response); | 288 | json_decref (handle->response); |
285 | handle->response = NULL; | 289 | handle->response = NULL; |
286 | } | 290 | } |
287 | 291 | ||
288 | if (NULL != handle->list_it) | 292 | if (NULL != handle->list_it) |
289 | { | 293 | { |
290 | GNUNET_PEERINFO_iterate_cancel(handle->list_it); | 294 | GNUNET_PEERINFO_iterate_cancel (handle->list_it); |
291 | handle->list_it = NULL; | 295 | handle->list_it = NULL; |
292 | } | 296 | } |
293 | if (NULL != handle->peerinfo_handle) | 297 | if (NULL != handle->peerinfo_handle) |
294 | { | 298 | { |
295 | GNUNET_PEERINFO_disconnect(handle->peerinfo_handle); | 299 | GNUNET_PEERINFO_disconnect (handle->peerinfo_handle); |
296 | handle->peerinfo_handle = NULL; | 300 | handle->peerinfo_handle = NULL; |
297 | } | 301 | } |
298 | 302 | ||
299 | GNUNET_free(handle); | 303 | GNUNET_free (handle); |
300 | } | 304 | } |
301 | 305 | ||
302 | 306 | ||
@@ -306,26 +310,26 @@ cleanup_handle(void *cls) | |||
306 | * @param cls the `struct RequestHandle` | 310 | * @param cls the `struct RequestHandle` |
307 | */ | 311 | */ |
308 | static void | 312 | static void |
309 | do_error(void *cls) | 313 | do_error (void *cls) |
310 | { | 314 | { |
311 | struct RequestHandle *handle = cls; | 315 | struct RequestHandle *handle = cls; |
312 | struct MHD_Response *resp; | 316 | struct MHD_Response *resp; |
313 | json_t *json_error = json_object(); | 317 | json_t *json_error = json_object (); |
314 | char *response; | 318 | char *response; |
315 | 319 | ||
316 | if (NULL == handle->emsg) | 320 | if (NULL == handle->emsg) |
317 | handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN); | 321 | handle->emsg = GNUNET_strdup (GNUNET_REST_PEERINFO_ERROR_UNKNOWN); |
318 | 322 | ||
319 | json_object_set_new(json_error, "error", json_string(handle->emsg)); | 323 | json_object_set_new (json_error, "error", json_string (handle->emsg)); |
320 | 324 | ||
321 | if (0 == handle->response_code) | 325 | if (0 == handle->response_code) |
322 | handle->response_code = MHD_HTTP_OK; | 326 | handle->response_code = MHD_HTTP_OK; |
323 | response = json_dumps(json_error, 0); | 327 | response = json_dumps (json_error, 0); |
324 | resp = GNUNET_REST_create_response(response); | 328 | resp = GNUNET_REST_create_response (response); |
325 | handle->proc(handle->proc_cls, resp, handle->response_code); | 329 | handle->proc (handle->proc_cls, resp, handle->response_code); |
326 | json_decref(json_error); | 330 | json_decref (json_error); |
327 | GNUNET_free(response); | 331 | GNUNET_free (response); |
328 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 332 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
329 | } | 333 | } |
330 | 334 | ||
331 | 335 | ||
@@ -335,26 +339,26 @@ do_error(void *cls) | |||
335 | * @param cls the `struct RequestHandle` | 339 | * @param cls the `struct RequestHandle` |
336 | */ | 340 | */ |
337 | static void | 341 | static void |
338 | peerinfo_list_finished(void *cls) | 342 | peerinfo_list_finished (void *cls) |
339 | { | 343 | { |
340 | struct RequestHandle *handle = cls; | 344 | struct RequestHandle *handle = cls; |
341 | char *result_str; | 345 | char *result_str; |
342 | struct MHD_Response *resp; | 346 | struct MHD_Response *resp; |
343 | 347 | ||
344 | if (NULL == handle->response) | 348 | if (NULL == handle->response) |
345 | { | 349 | { |
346 | handle->response_code = MHD_HTTP_NOT_FOUND; | 350 | handle->response_code = MHD_HTTP_NOT_FOUND; |
347 | handle->emsg = GNUNET_strdup("No peers found"); | 351 | handle->emsg = GNUNET_strdup ("No peers found"); |
348 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 352 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
349 | return; | 353 | return; |
350 | } | 354 | } |
351 | 355 | ||
352 | result_str = json_dumps(handle->response, 0); | 356 | result_str = json_dumps (handle->response, 0); |
353 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
354 | resp = GNUNET_REST_create_response(result_str); | 358 | resp = GNUNET_REST_create_response (result_str); |
355 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 359 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
356 | GNUNET_free_non_null(result_str); | 360 | GNUNET_free_non_null (result_str); |
357 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 361 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
358 | } | 362 | } |
359 | 363 | ||
360 | 364 | ||
@@ -367,16 +371,16 @@ peerinfo_list_finished(void *cls) | |||
367 | * @return #GNUNET_OK to keep the address and continue | 371 | * @return #GNUNET_OK to keep the address and continue |
368 | */ | 372 | */ |
369 | static int | 373 | static int |
370 | count_address(void *cls, | 374 | count_address (void *cls, |
371 | const struct GNUNET_HELLO_Address *address, | 375 | const struct GNUNET_HELLO_Address *address, |
372 | struct GNUNET_TIME_Absolute expiration) | 376 | struct GNUNET_TIME_Absolute expiration) |
373 | { | 377 | { |
374 | struct PrintContext *pc = cls; | 378 | struct PrintContext *pc = cls; |
375 | 379 | ||
376 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) | 380 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
377 | { | 381 | { |
378 | return GNUNET_OK; /* ignore expired address */ | 382 | return GNUNET_OK; /* ignore expired address */ |
379 | } | 383 | } |
380 | 384 | ||
381 | pc->off++; | 385 | pc->off++; |
382 | return GNUNET_OK; | 386 | return GNUNET_OK; |
@@ -389,7 +393,7 @@ count_address(void *cls, | |||
389 | * @param pc printing context | 393 | * @param pc printing context |
390 | */ | 394 | */ |
391 | static void | 395 | static void |
392 | dump_pc(struct PrintContext *pc) | 396 | dump_pc (struct PrintContext *pc) |
393 | { | 397 | { |
394 | struct RequestHandle *handle; | 398 | struct RequestHandle *handle; |
395 | unsigned int i; | 399 | unsigned int i; |
@@ -401,62 +405,63 @@ dump_pc(struct PrintContext *pc) | |||
401 | json_t *friend_and_peer_json; | 405 | json_t *friend_and_peer_json; |
402 | char *friend_and_peer; | 406 | char *friend_and_peer; |
403 | 407 | ||
404 | temp_array = json_array(); | 408 | temp_array = json_array (); |
405 | response_entry = json_object(); | 409 | response_entry = json_object (); |
406 | 410 | ||
407 | for (i = 0; i < pc->num_addresses; i++) | 411 | for (i = 0; i < pc->num_addresses; i++) |
412 | { | ||
413 | if (NULL != pc->address_list[i].result) | ||
408 | { | 414 | { |
409 | if (NULL != pc->address_list[i].result) | 415 | object = json_object (); |
410 | { | 416 | address = json_string (pc->address_list[i].result); |
411 | object = json_object(); | 417 | expires = json_string ( |
412 | address = json_string(pc->address_list[i].result); | 418 | GNUNET_STRINGS_absolute_time_to_string ( |
413 | expires = json_string( | 419 | pc->address_list[i].expiration)); |
414 | GNUNET_STRINGS_absolute_time_to_string(pc->address_list[i].expiration)); | 420 | json_object_set (object, "address", address); |
415 | json_object_set(object, "address", address); | 421 | json_object_set (object, "expires", expires); |
416 | json_object_set(object, "expires", expires); | 422 | |
417 | 423 | json_decref (address); | |
418 | json_decref(address); | 424 | json_decref (expires); |
419 | json_decref(expires); | 425 | |
420 | 426 | json_array_append (temp_array, object); | |
421 | json_array_append(temp_array, object); | 427 | json_decref (object); |
422 | json_decref(object); | 428 | GNUNET_free (pc->address_list[i].result); |
423 | GNUNET_free(pc->address_list[i].result); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | if (0 < json_array_size(temp_array)) | ||
428 | { | ||
429 | GNUNET_asprintf(&friend_and_peer, | ||
430 | "%s%s", | ||
431 | (GNUNET_YES == pc->friend_only) ? "F2F:" : "", | ||
432 | GNUNET_i2s_full(&pc->peer)); | ||
433 | friend_and_peer_json = json_string(friend_and_peer); | ||
434 | json_object_set(response_entry, | ||
435 | GNUNET_REST_PEERINFO_PEER, | ||
436 | friend_and_peer_json); | ||
437 | json_object_set(response_entry, | ||
438 | GNUNET_REST_PEERINFO_ARRAY, | ||
439 | temp_array); | ||
440 | json_array_append(pc->handle->response, response_entry); | ||
441 | json_decref(friend_and_peer_json); | ||
442 | GNUNET_free(friend_and_peer); | ||
443 | } | 429 | } |
444 | 430 | } | |
445 | json_decref(temp_array); | 431 | |
446 | json_decref(response_entry); | 432 | if (0 < json_array_size (temp_array)) |
447 | 433 | { | |
448 | GNUNET_free_non_null(pc->address_list); | 434 | GNUNET_asprintf (&friend_and_peer, |
449 | GNUNET_CONTAINER_DLL_remove(pc_head, | 435 | "%s%s", |
450 | pc_tail, | 436 | (GNUNET_YES == pc->friend_only) ? "F2F:" : "", |
451 | pc); | 437 | GNUNET_i2s_full (&pc->peer)); |
438 | friend_and_peer_json = json_string (friend_and_peer); | ||
439 | json_object_set (response_entry, | ||
440 | GNUNET_REST_PEERINFO_PEER, | ||
441 | friend_and_peer_json); | ||
442 | json_object_set (response_entry, | ||
443 | GNUNET_REST_PEERINFO_ARRAY, | ||
444 | temp_array); | ||
445 | json_array_append (pc->handle->response, response_entry); | ||
446 | json_decref (friend_and_peer_json); | ||
447 | GNUNET_free (friend_and_peer); | ||
448 | } | ||
449 | |||
450 | json_decref (temp_array); | ||
451 | json_decref (response_entry); | ||
452 | |||
453 | GNUNET_free_non_null (pc->address_list); | ||
454 | GNUNET_CONTAINER_DLL_remove (pc_head, | ||
455 | pc_tail, | ||
456 | pc); | ||
452 | handle = pc->handle; | 457 | handle = pc->handle; |
453 | GNUNET_free(pc); | 458 | GNUNET_free (pc); |
454 | 459 | ||
455 | if ((NULL == pc_head) && | 460 | if ((NULL == pc_head) && |
456 | (NULL == handle->list_it)) | 461 | (NULL == handle->list_it)) |
457 | { | 462 | { |
458 | GNUNET_SCHEDULER_add_now(&peerinfo_list_finished, handle); | 463 | GNUNET_SCHEDULER_add_now (&peerinfo_list_finished, handle); |
459 | } | 464 | } |
460 | } | 465 | } |
461 | 466 | ||
462 | 467 | ||
@@ -471,31 +476,31 @@ dump_pc(struct PrintContext *pc) | |||
471 | * if #GNUNET_SYSERR: address is invalid | 476 | * if #GNUNET_SYSERR: address is invalid |
472 | */ | 477 | */ |
473 | static void | 478 | static void |
474 | process_resolved_address(void *cls, | 479 | process_resolved_address (void *cls, |
475 | const char *address, | 480 | const char *address, |
476 | int res) | 481 | int res) |
477 | { | 482 | { |
478 | struct AddressRecord *ar = cls; | 483 | struct AddressRecord *ar = cls; |
479 | struct PrintContext *pc = ar->pc; | 484 | struct PrintContext *pc = ar->pc; |
480 | 485 | ||
481 | if (NULL != address) | 486 | if (NULL != address) |
487 | { | ||
488 | if (0 != strlen (address)) | ||
482 | { | 489 | { |
483 | if (0 != strlen(address)) | 490 | if (NULL != ar->result) |
484 | { | 491 | GNUNET_free (ar->result); |
485 | if (NULL != ar->result) | 492 | ar->result = GNUNET_strdup (address); |
486 | GNUNET_free(ar->result); | ||
487 | ar->result = GNUNET_strdup(address); | ||
488 | } | ||
489 | return; | ||
490 | } | 493 | } |
494 | return; | ||
495 | } | ||
491 | ar->atsc = NULL; | 496 | ar->atsc = NULL; |
492 | if (GNUNET_SYSERR == res) | 497 | if (GNUNET_SYSERR == res) |
493 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 498 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
494 | _("Failure: Cannot convert address to string for peer `%s'\n"), | 499 | _ ("Failure: Cannot convert address to string for peer `%s'\n"), |
495 | GNUNET_i2s(&ar->pc->peer)); | 500 | GNUNET_i2s (&ar->pc->peer)); |
496 | pc->num_addresses++; | 501 | pc->num_addresses++; |
497 | if (pc->num_addresses == pc->address_list_size) | 502 | if (pc->num_addresses == pc->address_list_size) |
498 | dump_pc(ar->pc); | 503 | dump_pc (ar->pc); |
499 | } | 504 | } |
500 | 505 | ||
501 | 506 | ||
@@ -508,33 +513,33 @@ process_resolved_address(void *cls, | |||
508 | * @return #GNUNET_OK to keep the address and continue | 513 | * @return #GNUNET_OK to keep the address and continue |
509 | */ | 514 | */ |
510 | static int | 515 | static int |
511 | print_address(void *cls, | 516 | print_address (void *cls, |
512 | const struct GNUNET_HELLO_Address *address, | 517 | const struct GNUNET_HELLO_Address *address, |
513 | struct GNUNET_TIME_Absolute expiration) | 518 | struct GNUNET_TIME_Absolute expiration) |
514 | { | 519 | { |
515 | struct PrintContext *pc = cls; | 520 | struct PrintContext *pc = cls; |
516 | struct AddressRecord *ar; | 521 | struct AddressRecord *ar; |
517 | 522 | ||
518 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) | 523 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
519 | { | 524 | { |
520 | return GNUNET_OK; /* ignore expired address */ | 525 | return GNUNET_OK; /* ignore expired address */ |
521 | } | 526 | } |
522 | 527 | ||
523 | GNUNET_assert(0 < pc->off); | 528 | GNUNET_assert (0 < pc->off); |
524 | ar = &pc->address_list[--pc->off]; | 529 | ar = &pc->address_list[--pc->off]; |
525 | ar->pc = pc; | 530 | ar->pc = pc; |
526 | ar->expiration = expiration; | 531 | ar->expiration = expiration; |
527 | GNUNET_asprintf(&ar->result, | 532 | GNUNET_asprintf (&ar->result, |
528 | "%s:%u:%u", | 533 | "%s:%u:%u", |
529 | address->transport_name, | 534 | address->transport_name, |
530 | address->address_length, | 535 | address->address_length, |
531 | address->local_info); | 536 | address->local_info); |
532 | ar->atsc = GNUNET_TRANSPORT_address_to_string(cfg, | 537 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, |
533 | address, | 538 | address, |
534 | GNUNET_NO, | 539 | GNUNET_NO, |
535 | TIMEOUT, | 540 | TIMEOUT, |
536 | &process_resolved_address, | 541 | &process_resolved_address, |
537 | ar); | 542 | ar); |
538 | return GNUNET_OK; | 543 | return GNUNET_OK; |
539 | } | 544 | } |
540 | 545 | ||
@@ -549,64 +554,64 @@ print_address(void *cls, | |||
549 | * @param err_msg message | 554 | * @param err_msg message |
550 | */ | 555 | */ |
551 | void | 556 | void |
552 | peerinfo_list_iteration(void *cls, | 557 | peerinfo_list_iteration (void *cls, |
553 | const struct GNUNET_PeerIdentity *peer, | 558 | const struct GNUNET_PeerIdentity *peer, |
554 | const struct GNUNET_HELLO_Message *hello, | 559 | const struct GNUNET_HELLO_Message *hello, |
555 | const char *err_msg) | 560 | const char *err_msg) |
556 | { | 561 | { |
557 | struct RequestHandle *handle = cls; | 562 | struct RequestHandle *handle = cls; |
558 | struct PrintContext *pc; | 563 | struct PrintContext *pc; |
559 | int friend_only; | 564 | int friend_only; |
560 | 565 | ||
561 | if (NULL == handle->response) | 566 | if (NULL == handle->response) |
562 | { | 567 | { |
563 | handle->response = json_array(); | 568 | handle->response = json_array (); |
564 | } | 569 | } |
565 | 570 | ||
566 | if (NULL == peer) | 571 | if (NULL == peer) |
572 | { | ||
573 | handle->list_it = NULL; | ||
574 | handle->emsg = GNUNET_strdup ("Error in communication with peerinfo"); | ||
575 | if (NULL != err_msg) | ||
567 | { | 576 | { |
568 | handle->list_it = NULL; | 577 | GNUNET_free (handle->emsg); |
569 | handle->emsg = GNUNET_strdup("Error in communication with peerinfo"); | 578 | handle->emsg = GNUNET_strdup (err_msg); |
570 | if (NULL != err_msg) | 579 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
571 | { | ||
572 | GNUNET_free(handle->emsg); | ||
573 | handle->emsg = GNUNET_strdup(err_msg); | ||
574 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | ||
575 | } | ||
576 | if (NULL == pc_head) | ||
577 | GNUNET_SCHEDULER_add_now(&do_error, handle); | ||
578 | return; | ||
579 | } | 580 | } |
581 | if (NULL == pc_head) | ||
582 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
583 | return; | ||
584 | } | ||
580 | if (NULL == hello) | 585 | if (NULL == hello) |
581 | return; | 586 | return; |
582 | 587 | ||
583 | friend_only = GNUNET_NO; | 588 | friend_only = GNUNET_NO; |
584 | if (NULL != hello) | 589 | if (NULL != hello) |
585 | friend_only = GNUNET_HELLO_is_friend_only(hello); | 590 | friend_only = GNUNET_HELLO_is_friend_only (hello); |
586 | 591 | ||
587 | pc = GNUNET_new(struct PrintContext); | 592 | pc = GNUNET_new (struct PrintContext); |
588 | GNUNET_CONTAINER_DLL_insert(pc_head, | 593 | GNUNET_CONTAINER_DLL_insert (pc_head, |
589 | pc_tail, | 594 | pc_tail, |
590 | pc); | 595 | pc); |
591 | pc->peer = *peer; | 596 | pc->peer = *peer; |
592 | pc->friend_only = friend_only; | 597 | pc->friend_only = friend_only; |
593 | pc->handle = handle; | 598 | pc->handle = handle; |
594 | GNUNET_HELLO_iterate_addresses(hello, | 599 | GNUNET_HELLO_iterate_addresses (hello, |
595 | GNUNET_NO, | 600 | GNUNET_NO, |
596 | &count_address, | 601 | &count_address, |
597 | pc); | 602 | pc); |
598 | if (0 == pc->off) | 603 | if (0 == pc->off) |
599 | { | 604 | { |
600 | dump_pc(pc); | 605 | dump_pc (pc); |
601 | return; | 606 | return; |
602 | } | 607 | } |
603 | pc->address_list_size = pc->off; | 608 | pc->address_list_size = pc->off; |
604 | pc->address_list = GNUNET_malloc( | 609 | pc->address_list = GNUNET_malloc ( |
605 | sizeof(struct AddressRecord) * pc->off); | 610 | sizeof(struct AddressRecord) * pc->off); |
606 | GNUNET_HELLO_iterate_addresses(hello, | 611 | GNUNET_HELLO_iterate_addresses (hello, |
607 | GNUNET_NO, | 612 | GNUNET_NO, |
608 | &print_address, | 613 | &print_address, |
609 | pc); | 614 | pc); |
610 | } | 615 | } |
611 | 616 | ||
612 | /** | 617 | /** |
@@ -617,50 +622,50 @@ peerinfo_list_iteration(void *cls, | |||
617 | * @param cls the RequestHandle | 622 | * @param cls the RequestHandle |
618 | */ | 623 | */ |
619 | void | 624 | void |
620 | peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, | 625 | peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, |
621 | const char* url, | 626 | const char*url, |
622 | void *cls) | 627 | void *cls) |
623 | { | 628 | { |
624 | struct RequestHandle *handle = cls; | 629 | struct RequestHandle *handle = cls; |
625 | struct GNUNET_HashCode key; | 630 | struct GNUNET_HashCode key; |
626 | const struct GNUNET_PeerIdentity *specific_peer; | 631 | const struct GNUNET_PeerIdentity *specific_peer; |
627 | //GNUNET_PEER_Id peer_id; | 632 | // GNUNET_PEER_Id peer_id; |
628 | int include_friend_only; | 633 | int include_friend_only; |
629 | char* include_friend_only_str; | 634 | char*include_friend_only_str; |
630 | 635 | ||
631 | include_friend_only = GNUNET_NO; | 636 | include_friend_only = GNUNET_NO; |
632 | GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_FRIEND, | 637 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND, |
633 | strlen(GNUNET_REST_PEERINFO_FRIEND), | 638 | strlen (GNUNET_REST_PEERINFO_FRIEND), |
634 | &key); | 639 | &key); |
635 | if (GNUNET_YES | 640 | if (GNUNET_YES |
636 | == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, | 641 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
637 | &key)) | 642 | &key)) |
643 | { | ||
644 | include_friend_only_str = GNUNET_CONTAINER_multihashmap_get ( | ||
645 | con_handle->url_param_map, &key); | ||
646 | if (0 == strcmp (include_friend_only_str, "yes")) | ||
638 | { | 647 | { |
639 | include_friend_only_str = GNUNET_CONTAINER_multihashmap_get( | 648 | include_friend_only = GNUNET_YES; |
640 | con_handle->url_param_map, &key); | ||
641 | if (0 == strcmp(include_friend_only_str, "yes")) | ||
642 | { | ||
643 | include_friend_only = GNUNET_YES; | ||
644 | } | ||
645 | } | 649 | } |
650 | } | ||
646 | 651 | ||
647 | specific_peer = NULL; | 652 | specific_peer = NULL; |
648 | GNUNET_CRYPTO_hash(GNUNET_REST_PEERINFO_PEER, | 653 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER, |
649 | strlen(GNUNET_REST_PEERINFO_PEER), | 654 | strlen (GNUNET_REST_PEERINFO_PEER), |
650 | &key); | 655 | &key); |
651 | if (GNUNET_YES | 656 | if (GNUNET_YES |
652 | == GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, | 657 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
653 | &key)) | 658 | &key)) |
654 | { | 659 | { |
655 | //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); | 660 | // peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); |
656 | //specific_peer = GNUNET_PEER_resolve2(peer_id); | 661 | // specific_peer = GNUNET_PEER_resolve2(peer_id); |
657 | } | 662 | } |
658 | 663 | ||
659 | handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, | 664 | handle->list_it = GNUNET_PEERINFO_iterate (handle->peerinfo_handle, |
660 | include_friend_only, | 665 | include_friend_only, |
661 | specific_peer, | 666 | specific_peer, |
662 | &peerinfo_list_iteration, | 667 | &peerinfo_list_iteration, |
663 | handle); | 668 | handle); |
664 | } | 669 | } |
665 | 670 | ||
666 | 671 | ||
@@ -673,20 +678,20 @@ peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, | |||
673 | * @param cls the RequestHandle | 678 | * @param cls the RequestHandle |
674 | */ | 679 | */ |
675 | static void | 680 | static void |
676 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, | 681 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
677 | const char* url, | 682 | const char*url, |
678 | void *cls) | 683 | void *cls) |
679 | { | 684 | { |
680 | struct MHD_Response *resp; | 685 | struct MHD_Response *resp; |
681 | struct RequestHandle *handle = cls; | 686 | struct RequestHandle *handle = cls; |
682 | 687 | ||
683 | //independent of path return all options | 688 | // independent of path return all options |
684 | resp = GNUNET_REST_create_response(NULL); | 689 | resp = GNUNET_REST_create_response (NULL); |
685 | MHD_add_response_header(resp, | 690 | MHD_add_response_header (resp, |
686 | "Access-Control-Allow-Methods", | 691 | "Access-Control-Allow-Methods", |
687 | allow_methods); | 692 | allow_methods); |
688 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 693 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
689 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); | 694 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
690 | return; | 695 | return; |
691 | } | 696 | } |
692 | 697 | ||
@@ -697,7 +702,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle, | |||
697 | * @param handle the request handle | 702 | * @param handle the request handle |
698 | */ | 703 | */ |
699 | static void | 704 | static void |
700 | init_cont(struct RequestHandle *handle) | 705 | init_cont (struct RequestHandle *handle) |
701 | { | 706 | { |
702 | struct GNUNET_REST_RequestHandlerError err; | 707 | struct GNUNET_REST_RequestHandlerError err; |
703 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 708 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
@@ -706,14 +711,14 @@ init_cont(struct RequestHandle *handle) | |||
706 | GNUNET_REST_HANDLER_END | 711 | GNUNET_REST_HANDLER_END |
707 | }; | 712 | }; |
708 | 713 | ||
709 | if (GNUNET_NO == GNUNET_REST_handle_request(handle->rest_handle, | 714 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, |
710 | handlers, | 715 | handlers, |
711 | &err, | 716 | &err, |
712 | handle)) | 717 | handle)) |
713 | { | 718 | { |
714 | handle->response_code = err.error_code; | 719 | handle->response_code = err.error_code; |
715 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 720 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
716 | } | 721 | } |
717 | } | 722 | } |
718 | 723 | ||
719 | 724 | ||
@@ -729,30 +734,31 @@ init_cont(struct RequestHandle *handle) | |||
729 | * @return GNUNET_OK if request accepted | 734 | * @return GNUNET_OK if request accepted |
730 | */ | 735 | */ |
731 | static void | 736 | static void |
732 | rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | 737 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
733 | GNUNET_REST_ResultProcessor proc, | 738 | GNUNET_REST_ResultProcessor proc, |
734 | void *proc_cls) | 739 | void *proc_cls) |
735 | { | 740 | { |
736 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); | 741 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
737 | 742 | ||
738 | handle->response_code = 0; | 743 | handle->response_code = 0; |
739 | handle->timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60); | 744 | handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
745 | 60); | ||
740 | handle->proc_cls = proc_cls; | 746 | handle->proc_cls = proc_cls; |
741 | handle->proc = proc; | 747 | handle->proc = proc; |
742 | handle->rest_handle = rest_handle; | 748 | handle->rest_handle = rest_handle; |
743 | 749 | ||
744 | handle->url = GNUNET_strdup(rest_handle->url); | 750 | handle->url = GNUNET_strdup (rest_handle->url); |
745 | if (handle->url[strlen(handle->url) - 1] == '/') | 751 | if (handle->url[strlen (handle->url) - 1] == '/') |
746 | handle->url[strlen(handle->url) - 1] = '\0'; | 752 | handle->url[strlen (handle->url) - 1] = '\0'; |
747 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
748 | handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg); | 754 | handle->peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
749 | init_cont(handle); | 755 | init_cont (handle); |
750 | handle->timeout_task = | 756 | handle->timeout_task = |
751 | GNUNET_SCHEDULER_add_delayed(handle->timeout, | 757 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
752 | &do_error, | 758 | &do_error, |
753 | handle); | 759 | handle); |
754 | 760 | ||
755 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
756 | } | 762 | } |
757 | 763 | ||
758 | 764 | ||
@@ -763,7 +769,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
763 | * @return NULL on error, otherwise the plugin context | 769 | * @return NULL on error, otherwise the plugin context |
764 | */ | 770 | */ |
765 | void * | 771 | void * |
766 | libgnunet_plugin_rest_peerinfo_init(void *cls) | 772 | libgnunet_plugin_rest_peerinfo_init (void *cls) |
767 | { | 773 | { |
768 | static struct Plugin plugin; | 774 | static struct Plugin plugin; |
769 | struct GNUNET_REST_Plugin *api; | 775 | struct GNUNET_REST_Plugin *api; |
@@ -771,22 +777,22 @@ libgnunet_plugin_rest_peerinfo_init(void *cls) | |||
771 | cfg = cls; | 777 | cfg = cls; |
772 | if (NULL != plugin.cfg) | 778 | if (NULL != plugin.cfg) |
773 | return NULL; /* can only initialize once! */ | 779 | return NULL; /* can only initialize once! */ |
774 | memset(&plugin, 0, sizeof(struct Plugin)); | 780 | memset (&plugin, 0, sizeof(struct Plugin)); |
775 | plugin.cfg = cfg; | 781 | plugin.cfg = cfg; |
776 | api = GNUNET_new(struct GNUNET_REST_Plugin); | 782 | api = GNUNET_new (struct GNUNET_REST_Plugin); |
777 | api->cls = &plugin; | 783 | api->cls = &plugin; |
778 | api->name = GNUNET_REST_API_NS_PEERINFO; | 784 | api->name = GNUNET_REST_API_NS_PEERINFO; |
779 | api->process_request = &rest_process_request; | 785 | api->process_request = &rest_process_request; |
780 | GNUNET_asprintf(&allow_methods, | 786 | GNUNET_asprintf (&allow_methods, |
781 | "%s, %s, %s, %s, %s", | 787 | "%s, %s, %s, %s, %s", |
782 | MHD_HTTP_METHOD_GET, | 788 | MHD_HTTP_METHOD_GET, |
783 | MHD_HTTP_METHOD_POST, | 789 | MHD_HTTP_METHOD_POST, |
784 | MHD_HTTP_METHOD_PUT, | 790 | MHD_HTTP_METHOD_PUT, |
785 | MHD_HTTP_METHOD_DELETE, | 791 | MHD_HTTP_METHOD_DELETE, |
786 | MHD_HTTP_METHOD_OPTIONS); | 792 | MHD_HTTP_METHOD_OPTIONS); |
787 | 793 | ||
788 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | _("Peerinfo REST API initialized\n")); | 795 | _ ("Peerinfo REST API initialized\n")); |
790 | return api; | 796 | return api; |
791 | } | 797 | } |
792 | 798 | ||
@@ -798,19 +804,18 @@ libgnunet_plugin_rest_peerinfo_init(void *cls) | |||
798 | * @return always NULL | 804 | * @return always NULL |
799 | */ | 805 | */ |
800 | void * | 806 | void * |
801 | libgnunet_plugin_rest_peerinfo_done(void *cls) | 807 | libgnunet_plugin_rest_peerinfo_done (void *cls) |
802 | { | 808 | { |
803 | struct GNUNET_REST_Plugin *api = cls; | 809 | struct GNUNET_REST_Plugin *api = cls; |
804 | struct Plugin *plugin = api->cls; | 810 | struct Plugin *plugin = api->cls; |
805 | 811 | ||
806 | plugin->cfg = NULL; | 812 | plugin->cfg = NULL; |
807 | 813 | ||
808 | GNUNET_free_non_null(allow_methods); | 814 | GNUNET_free_non_null (allow_methods); |
809 | GNUNET_free(api); | 815 | GNUNET_free (api); |
810 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
811 | "Peerinfo REST plugin is finished\n"); | 817 | "Peerinfo REST plugin is finished\n"); |
812 | return NULL; | 818 | return NULL; |
813 | } | 819 | } |
814 | 820 | ||
815 | /* end of plugin_rest_peerinfo.c */ | 821 | /* end of plugin_rest_peerinfo.c */ |
816 | |||