diff options
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/plugin_rest_peerinfo.c | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/src/peerinfo/plugin_rest_peerinfo.c b/src/peerinfo/plugin_rest_peerinfo.c index 97c473e36..e34bde9f5 100644 --- a/src/peerinfo/plugin_rest_peerinfo.c +++ b/src/peerinfo/plugin_rest_peerinfo.c | |||
@@ -31,13 +31,30 @@ | |||
31 | #include "microhttpd.h" | 31 | #include "microhttpd.h" |
32 | #include <jansson.h> | 32 | #include <jansson.h> |
33 | 33 | ||
34 | /** | ||
35 | * Peerinfo Namespace | ||
36 | */ | ||
34 | #define GNUNET_REST_API_NS_PEERINFO "/peerinfo" | 37 | #define GNUNET_REST_API_NS_PEERINFO "/peerinfo" |
35 | 38 | ||
36 | #define GNUNET_REST_API_PEERINFO_PEER "peer" | 39 | /** |
37 | #define GNUNET_REST_API_PEERINFO_FRIEND "friend" | 40 | * Peerinfo parameter peer |
38 | #define GNUNET_REST_API_PEERINFO_ARRAY "array" | 41 | */ |
42 | #define GNUNET_REST_PEERINFO_PEER "peer" | ||
39 | 43 | ||
40 | #define GNUNET_REST_ERROR_UNKNOWN "Unkown Error" | 44 | /** |
45 | * Peerinfo parameter friend | ||
46 | */ | ||
47 | #define GNUNET_REST_PEERINFO_FRIEND "friend" | ||
48 | |||
49 | /** | ||
50 | * Peerinfo parameter array | ||
51 | */ | ||
52 | #define GNUNET_REST_PEERINFO_ARRAY "array" | ||
53 | |||
54 | /** | ||
55 | * Error message Unknown Error | ||
56 | */ | ||
57 | #define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error" | ||
41 | 58 | ||
42 | /** | 59 | /** |
43 | * How long until we time out during address lookup? | 60 | * How long until we time out during address lookup? |
@@ -94,7 +111,6 @@ struct AddressRecord | |||
94 | */ | 111 | */ |
95 | struct PrintContext | 112 | struct PrintContext |
96 | { | 113 | { |
97 | |||
98 | /** | 114 | /** |
99 | * Kept in DLL. | 115 | * Kept in DLL. |
100 | */ | 116 | */ |
@@ -152,6 +168,9 @@ static struct PrintContext *pc_head; | |||
152 | */ | 168 | */ |
153 | static struct PrintContext *pc_tail; | 169 | static struct PrintContext *pc_tail; |
154 | 170 | ||
171 | /** | ||
172 | * The request handle | ||
173 | */ | ||
155 | struct RequestHandle | 174 | struct RequestHandle |
156 | { | 175 | { |
157 | /** | 176 | /** |
@@ -299,7 +318,7 @@ do_error (void *cls) | |||
299 | char *response; | 318 | char *response; |
300 | 319 | ||
301 | if (NULL == handle->emsg) | 320 | if (NULL == handle->emsg) |
302 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN); | 321 | handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN); |
303 | 322 | ||
304 | json_object_set_new(json_error,"error", json_string(handle->emsg)); | 323 | json_object_set_new(json_error,"error", json_string(handle->emsg)); |
305 | 324 | ||
@@ -315,7 +334,9 @@ do_error (void *cls) | |||
315 | 334 | ||
316 | 335 | ||
317 | /** | 336 | /** |
318 | * Function that assembles our response. | 337 | * Function that assembles the response. |
338 | * | ||
339 | * @param cls the `struct RequestHandle` | ||
319 | */ | 340 | */ |
320 | static void | 341 | static void |
321 | peerinfo_list_finished (void *cls) | 342 | peerinfo_list_finished (void *cls) |
@@ -326,6 +347,7 @@ peerinfo_list_finished (void *cls) | |||
326 | 347 | ||
327 | if (NULL == handle->response) | 348 | if (NULL == handle->response) |
328 | { | 349 | { |
350 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
329 | handle->emsg = GNUNET_strdup ("No peers found"); | 351 | handle->emsg = GNUNET_strdup ("No peers found"); |
330 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 352 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
331 | return; | 353 | return; |
@@ -386,9 +408,6 @@ dump_pc (struct PrintContext *pc) | |||
386 | temp_array = json_array(); | 408 | temp_array = json_array(); |
387 | response_entry = json_object(); | 409 | response_entry = json_object(); |
388 | 410 | ||
389 | // printf (_("%sPeer `%s'\n"), | ||
390 | // (GNUNET_YES == pc->friend_only) ? "F2F: " : "", | ||
391 | // GNUNET_i2s_full (&pc->peer)); | ||
392 | for (i = 0; i < pc->num_addresses; i++) | 411 | for (i = 0; i < pc->num_addresses; i++) |
393 | { | 412 | { |
394 | if (NULL != pc->address_list[i].result) | 413 | if (NULL != pc->address_list[i].result) |
@@ -417,10 +436,10 @@ dump_pc (struct PrintContext *pc) | |||
417 | GNUNET_i2s_full (&pc->peer)); | 436 | GNUNET_i2s_full (&pc->peer)); |
418 | friend_and_peer_json = json_string(friend_and_peer); | 437 | friend_and_peer_json = json_string(friend_and_peer); |
419 | json_object_set(response_entry, | 438 | json_object_set(response_entry, |
420 | GNUNET_REST_API_PEERINFO_PEER, | 439 | GNUNET_REST_PEERINFO_PEER, |
421 | friend_and_peer_json); | 440 | friend_and_peer_json); |
422 | json_object_set(response_entry, | 441 | json_object_set(response_entry, |
423 | GNUNET_REST_API_PEERINFO_ARRAY, | 442 | GNUNET_REST_PEERINFO_ARRAY, |
424 | temp_array); | 443 | temp_array); |
425 | json_array_append(pc->handle->response, response_entry); | 444 | json_array_append(pc->handle->response, response_entry); |
426 | json_decref(friend_and_peer_json); | 445 | json_decref(friend_and_peer_json); |
@@ -615,8 +634,8 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
615 | char* include_friend_only_str; | 634 | char* include_friend_only_str; |
616 | 635 | ||
617 | include_friend_only = GNUNET_NO; | 636 | include_friend_only = GNUNET_NO; |
618 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_FRIEND, | 637 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND, |
619 | strlen (GNUNET_REST_API_PEERINFO_FRIEND), | 638 | strlen (GNUNET_REST_PEERINFO_FRIEND), |
620 | &key); | 639 | &key); |
621 | if ( GNUNET_YES | 640 | if ( GNUNET_YES |
622 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 641 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
@@ -631,15 +650,15 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
631 | } | 650 | } |
632 | 651 | ||
633 | specific_peer = NULL; | 652 | specific_peer = NULL; |
634 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_PEER, | 653 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER, |
635 | strlen (GNUNET_REST_API_PEERINFO_PEER), | 654 | strlen (GNUNET_REST_PEERINFO_PEER), |
636 | &key); | 655 | &key); |
637 | if ( GNUNET_YES | 656 | if ( GNUNET_YES |
638 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 657 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
639 | &key)) | 658 | &key)) |
640 | { | 659 | { |
641 | 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); |
642 | specific_peer = GNUNET_PEER_resolve2(peer_id); | 661 | //specific_peer = GNUNET_PEER_resolve2(peer_id); |
643 | } | 662 | } |
644 | 663 | ||
645 | handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, | 664 | handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, |