From 296d164e840caf41105b2cbe7d717960b83f1934 Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 28 Sep 2017 08:24:57 -0500 Subject: [PATCH] now puting result of get_value in the return buffer --- core/http_request.c | 1 + routing/offline.c | 14 +++++++++++--- routing/online.c | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/http_request.c b/core/http_request.c index 3686de7..1dbdb98 100644 --- a/core/http_request.c +++ b/core/http_request.c @@ -63,6 +63,7 @@ struct HttpResponse* ipfs_core_http_response_new() { if (response != NULL) { response->content_type = NULL; response->bytes = NULL; + response->bytes_size = 0; } return response; } diff --git a/routing/offline.c b/routing/offline.c index 9555205..9d3f4f3 100644 --- a/routing/offline.c +++ b/routing/offline.c @@ -72,9 +72,17 @@ int ipfs_routing_generic_get_value (ipfs_routing* routing, const unsigned char * libp2p_logger_error("offline", "Unable to call API for dht get.\n"); return 0; } - //TODO: put results in val - fprintf(stdout, "%s", response); - return 1; + *vlen = strlen(response); + if (*vlen > 0) { + *val = malloc(*vlen + 1); + uint8_t* ptr = (uint8_t*)*val; + if (ptr == NULL) { + return 0; + } + memcpy(ptr, response, *vlen); + ptr[*vlen] = 0; + retVal = 1; + } } else { struct HashtableNode* node = NULL; *val = NULL; diff --git a/routing/online.c b/routing/online.c index 77d3385..3b1fe91 100644 --- a/routing/online.c +++ b/routing/online.c @@ -373,6 +373,9 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k struct Libp2pVector *peers = NULL; int retVal = 0; + // just to be sure + *buffer_size = 0; + // find a provider routing->FindProviders(routing, key, key_size, &peers); if (peers == NULL) { @@ -423,6 +426,8 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k } } } + if (buffer_size == 0) + goto exit; } retVal = 1;