aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-08-08 23:26:11 +0200
committerPhil <phil.buschmann@tum.de>2018-08-08 23:26:11 +0200
commitcffad0ad30400dda7c7c4ef77ed7625013193dbe (patch)
tree270af7381f2796771c2b3e0896dcc4314fa1f8ad
parent995c8c9ce229d3ad25eeda53a0fbeda5cafa4f05 (diff)
downloadgnunet-cffad0ad30400dda7c7c4ef77ed7625013193dbe.tar.gz
gnunet-cffad0ad30400dda7c7c4ef77ed7625013193dbe.zip
Peerinfo Rest API finished
-rw-r--r--src/peerinfo/plugin_rest_peerinfo.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/src/peerinfo/plugin_rest_peerinfo.c b/src/peerinfo/plugin_rest_peerinfo.c
index a65089b32..97c473e36 100644
--- a/src/peerinfo/plugin_rest_peerinfo.c
+++ b/src/peerinfo/plugin_rest_peerinfo.c
@@ -32,10 +32,11 @@
32#include <jansson.h> 32#include <jansson.h>
33 33
34#define GNUNET_REST_API_NS_PEERINFO "/peerinfo" 34#define GNUNET_REST_API_NS_PEERINFO "/peerinfo"
35
35#define GNUNET_REST_API_PEERINFO_PEER "peer" 36#define GNUNET_REST_API_PEERINFO_PEER "peer"
36#define GNUNET_REST_API_PEERINFO_FRIEND "friend" 37#define GNUNET_REST_API_PEERINFO_FRIEND "friend"
38#define GNUNET_REST_API_PEERINFO_ARRAY "array"
37 39
38//TODO define other variables
39#define GNUNET_REST_ERROR_UNKNOWN "Unkown Error" 40#define GNUNET_REST_ERROR_UNKNOWN "Unkown Error"
40 41
41/** 42/**
@@ -60,8 +61,6 @@ struct Plugin
60 const struct GNUNET_CONFIGURATION_Handle *cfg; 61 const struct GNUNET_CONFIGURATION_Handle *cfg;
61}; 62};
62 63
63//TODO add specific structs
64
65 64
66/** 65/**
67 * Record we keep for each printable address. 66 * Record we keep for each printable address.
@@ -155,9 +154,19 @@ static struct PrintContext *pc_tail;
155 154
156struct RequestHandle 155struct RequestHandle
157{ 156{
158 //TODO add specific entries 157 /**
158 * JSON temporary array
159 */
159 json_t *temp_array; 160 json_t *temp_array;
161
162 /**
163 * Expiration time string
164 */
160 char *expiration_str; 165 char *expiration_str;
166
167 /**
168 * Address string
169 */
161 const char *address; 170 const char *address;
162 171
163 /** 172 /**
@@ -166,7 +175,7 @@ struct RequestHandle
166 char *pubkey; 175 char *pubkey;
167 176
168 /** 177 /**
169 * JSON array response 178 * JSON response
170 */ 179 */
171 json_t *response; 180 json_t *response;
172 181
@@ -243,7 +252,18 @@ cleanup_handle (void *cls)
243 GNUNET_free (handle->url); 252 GNUNET_free (handle->url);
244 if (NULL != handle->emsg) 253 if (NULL != handle->emsg)
245 GNUNET_free (handle->emsg); 254 GNUNET_free (handle->emsg);
246 255 if (NULL != handle->address)
256 GNUNET_free ((char*)handle->address);
257 if (NULL != handle->expiration_str)
258 GNUNET_free (handle->expiration_str);
259 if (NULL != handle->pubkey)
260 GNUNET_free (handle->pubkey);
261
262 if (NULL != handle->temp_array)
263 {
264 json_decref(handle->temp_array);
265 handle->temp_array = NULL;
266 }
247 if (NULL != handle->response) 267 if (NULL != handle->response)
248 { 268 {
249 json_decref(handle->response); 269 json_decref(handle->response);
@@ -255,14 +275,11 @@ cleanup_handle (void *cls)
255 GNUNET_PEERINFO_iterate_cancel(handle->list_it); 275 GNUNET_PEERINFO_iterate_cancel(handle->list_it);
256 handle->list_it = NULL; 276 handle->list_it = NULL;
257 } 277 }
258
259 if (NULL != handle->peerinfo_handle) 278 if (NULL != handle->peerinfo_handle)
260 { 279 {
261 GNUNET_PEERINFO_disconnect(handle->peerinfo_handle); 280 GNUNET_PEERINFO_disconnect(handle->peerinfo_handle);
262 handle->peerinfo_handle = NULL; 281 handle->peerinfo_handle = NULL;
263 } 282 }
264
265 //TODO add specific cleanup
266 283
267 GNUNET_free (handle); 284 GNUNET_free (handle);
268} 285}
@@ -358,13 +375,16 @@ dump_pc (struct PrintContext *pc)
358{ 375{
359 struct RequestHandle *handle; 376 struct RequestHandle *handle;
360 unsigned int i; 377 unsigned int i;
378 json_t *response_entry;
361 json_t *temp_array; 379 json_t *temp_array;
362 json_t *object; 380 json_t *object;
363 json_t *address; 381 json_t *address;
364 json_t *expires; 382 json_t *expires;
383 json_t *friend_and_peer_json;
365 char *friend_and_peer; 384 char *friend_and_peer;
366 385
367 temp_array = json_array(); 386 temp_array = json_array();
387 response_entry = json_object();
368 388
369// printf (_("%sPeer `%s'\n"), 389// printf (_("%sPeer `%s'\n"),
370// (GNUNET_YES == pc->friend_only) ? "F2F: " : "", 390// (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
@@ -395,13 +415,20 @@ dump_pc (struct PrintContext *pc)
395 "%s%s", 415 "%s%s",
396 (GNUNET_YES == pc->friend_only) ? "F2F:" : "", 416 (GNUNET_YES == pc->friend_only) ? "F2F:" : "",
397 GNUNET_i2s_full (&pc->peer)); 417 GNUNET_i2s_full (&pc->peer));
398 json_object_set(pc->handle->response, 418 friend_and_peer_json = json_string(friend_and_peer);
399 friend_and_peer, 419 json_object_set(response_entry,
420 GNUNET_REST_API_PEERINFO_PEER,
421 friend_and_peer_json);
422 json_object_set(response_entry,
423 GNUNET_REST_API_PEERINFO_ARRAY,
400 temp_array); 424 temp_array);
425 json_array_append(pc->handle->response, response_entry);
426 json_decref(friend_and_peer_json);
401 GNUNET_free(friend_and_peer); 427 GNUNET_free(friend_and_peer);
402 } 428 }
403 429
404 json_decref (temp_array); 430 json_decref (temp_array);
431 json_decref(response_entry);
405 432
406 GNUNET_free_non_null (pc->address_list); 433 GNUNET_free_non_null (pc->address_list);
407 GNUNET_CONTAINER_DLL_remove (pc_head, 434 GNUNET_CONTAINER_DLL_remove (pc_head,
@@ -519,7 +546,7 @@ peerinfo_list_iteration(void *cls,
519 546
520 if (NULL == handle->response) 547 if (NULL == handle->response)
521 { 548 {
522 handle->response = json_object(); 549 handle->response = json_array();
523 } 550 }
524 551
525 if (NULL == peer) 552 if (NULL == peer)
@@ -658,7 +685,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
658static void 685static void
659init_cont (struct RequestHandle *handle) 686init_cont (struct RequestHandle *handle)
660{ 687{
661 //TODO specify parameter of init_cont if necessary
662 struct GNUNET_REST_RequestHandlerError err; 688 struct GNUNET_REST_RequestHandlerError err;
663 static const struct GNUNET_REST_RequestHandler handlers[] = { 689 static const struct GNUNET_REST_RequestHandler handlers[] = {
664 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get}, 690 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get},
@@ -705,8 +731,6 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
705 if (handle->url[strlen (handle->url)-1] == '/') 731 if (handle->url[strlen (handle->url)-1] == '/')
706 handle->url[strlen (handle->url)-1] = '\0'; 732 handle->url[strlen (handle->url)-1] = '\0';
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
708 //TODO connect to specific service
709 //connect ( cfg, [..., &callback_function, handle]);
710 handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg); 734 handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg);
711 init_cont(handle); 735 init_cont(handle);
712 handle->timeout_task = 736 handle->timeout_task =