[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 72/75: Peerinfo Rest API finished
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 72/75: Peerinfo Rest API finished |
Date: |
Thu, 09 Aug 2018 23:59:09 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit cffad0ad30400dda7c7c4ef77ed7625013193dbe
Author: Phil <address@hidden>
AuthorDate: Wed Aug 8 23:26:11 2018 +0200
Peerinfo Rest API finished
---
src/peerinfo/plugin_rest_peerinfo.c | 54 ++++++++++++++++++++++++++-----------
1 file 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 @@
#include <jansson.h>
#define GNUNET_REST_API_NS_PEERINFO "/peerinfo"
+
#define GNUNET_REST_API_PEERINFO_PEER "peer"
#define GNUNET_REST_API_PEERINFO_FRIEND "friend"
+#define GNUNET_REST_API_PEERINFO_ARRAY "array"
-//TODO define other variables
#define GNUNET_REST_ERROR_UNKNOWN "Unkown Error"
/**
@@ -60,8 +61,6 @@ struct Plugin
const struct GNUNET_CONFIGURATION_Handle *cfg;
};
-//TODO add specific structs
-
/**
* Record we keep for each printable address.
@@ -155,9 +154,19 @@ static struct PrintContext *pc_tail;
struct RequestHandle
{
- //TODO add specific entries
+ /**
+ * JSON temporary array
+ */
json_t *temp_array;
+
+ /**
+ * Expiration time string
+ */
char *expiration_str;
+
+ /**
+ * Address string
+ */
const char *address;
/**
@@ -166,7 +175,7 @@ struct RequestHandle
char *pubkey;
/**
- * JSON array response
+ * JSON response
*/
json_t *response;
@@ -243,7 +252,18 @@ cleanup_handle (void *cls)
GNUNET_free (handle->url);
if (NULL != handle->emsg)
GNUNET_free (handle->emsg);
-
+ if (NULL != handle->address)
+ GNUNET_free ((char*)handle->address);
+ if (NULL != handle->expiration_str)
+ GNUNET_free (handle->expiration_str);
+ if (NULL != handle->pubkey)
+ GNUNET_free (handle->pubkey);
+
+ if (NULL != handle->temp_array)
+ {
+ json_decref(handle->temp_array);
+ handle->temp_array = NULL;
+ }
if (NULL != handle->response)
{
json_decref(handle->response);
@@ -255,14 +275,11 @@ cleanup_handle (void *cls)
GNUNET_PEERINFO_iterate_cancel(handle->list_it);
handle->list_it = NULL;
}
-
if (NULL != handle->peerinfo_handle)
{
GNUNET_PEERINFO_disconnect(handle->peerinfo_handle);
handle->peerinfo_handle = NULL;
}
-
- //TODO add specific cleanup
GNUNET_free (handle);
}
@@ -358,13 +375,16 @@ dump_pc (struct PrintContext *pc)
{
struct RequestHandle *handle;
unsigned int i;
+ json_t *response_entry;
json_t *temp_array;
json_t *object;
json_t *address;
json_t *expires;
+ json_t *friend_and_peer_json;
char *friend_and_peer;
temp_array = json_array();
+ response_entry = json_object();
// printf (_("%sPeer `%s'\n"),
// (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
@@ -395,13 +415,20 @@ dump_pc (struct PrintContext *pc)
"%s%s",
(GNUNET_YES == pc->friend_only) ? "F2F:" : "",
GNUNET_i2s_full (&pc->peer));
- json_object_set(pc->handle->response,
- friend_and_peer,
+ friend_and_peer_json = json_string(friend_and_peer);
+ json_object_set(response_entry,
+ GNUNET_REST_API_PEERINFO_PEER,
+ friend_and_peer_json);
+ json_object_set(response_entry,
+ GNUNET_REST_API_PEERINFO_ARRAY,
temp_array);
+ json_array_append(pc->handle->response, response_entry);
+ json_decref(friend_and_peer_json);
GNUNET_free(friend_and_peer);
}
json_decref (temp_array);
+ json_decref(response_entry);
GNUNET_free_non_null (pc->address_list);
GNUNET_CONTAINER_DLL_remove (pc_head,
@@ -519,7 +546,7 @@ peerinfo_list_iteration(void *cls,
if (NULL == handle->response)
{
- handle->response = json_object();
+ handle->response = json_array();
}
if (NULL == peer)
@@ -658,7 +685,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
static void
init_cont (struct RequestHandle *handle)
{
- //TODO specify parameter of init_cont if necessary
struct GNUNET_REST_RequestHandlerError err;
static const struct GNUNET_REST_RequestHandler handlers[] = {
{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get},
@@ -705,8 +731,6 @@ rest_process_request(struct GNUNET_REST_RequestHandle
*rest_handle,
if (handle->url[strlen (handle->url)-1] == '/')
handle->url[strlen (handle->url)-1] = '\0';
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
- //TODO connect to specific service
- //connect ( cfg, [..., &callback_function, handle]);
handle->peerinfo_handle = GNUNET_PEERINFO_connect(cfg);
init_cont(handle);
handle->timeout_task =
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] 49/75: update dockerfile, (continued)
- [GNUnet-SVN] [gnunet] 49/75: update dockerfile, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 58/75: added name search, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 61/75: fix makefiles, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 53/75: -Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 54/75: -Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 75/75: Merge branch 'gsoc2018/rest_api', gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 64/75: fix lowercase identities, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 62/75: -fix json and namestore, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 68/75: fix gns and identity test script, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 57/75: -fix identity file, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 72/75: Peerinfo Rest API finished,
gnunet <=
- [GNUnet-SVN] [gnunet] 59/75: -wip namestore api, changed adding gnsrecord, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 71/75: -fix added timeout for gns Rest plugin, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 67/75: GNS REST API finished, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 50/75: -wip fix gns, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 70/75: Namestore Rest API finished, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 65/75: add peerinfo rest api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 73/75: -Merge branch 'master' into gsoc2018/rest_api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 74/75: style, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 33/75: -Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api, gnunet, 2018/08/09
- [GNUnet-SVN] [gnunet] 63/75: -wip peerinfo, async call work in progress, gnunet, 2018/08/09