From a315af8534ac69cf89dbdf3c78aff9be0e4cdf6f Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 12 Oct 2017 13:04:23 -0500 Subject: [PATCH 1/4] Now correctly initializing Cid variable, and checking after decoding --- core/http_request.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/http_request.c b/core/http_request.c index 0e8ac89..2053c1f 100644 --- a/core/http_request.c +++ b/core/http_request.c @@ -163,8 +163,12 @@ int ipfs_core_http_process_object(struct IpfsNode* local_node, struct HttpReques // do an object_get if (request->arguments->total == 1) { char* hash = (char*)libp2p_utils_vector_get(request->arguments, 0); - struct Cid* cid; - ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid); + struct Cid* cid = NULL; + if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) { + ipfs_cid_free(cid); + cid = NULL; + return 0; + } *response = ipfs_core_http_response_new(); struct HttpResponse* res = *response; res->content_type = "application/json"; @@ -181,7 +185,7 @@ int ipfs_core_http_process_dht_provide(struct IpfsNode* local_node, struct HttpR int failedCount = 0; for (int i = 0; i < request->arguments->total; i++) { char* hash = (char*)libp2p_utils_vector_get(request->arguments, i); - struct Cid* cid; + struct Cid* cid = NULL; if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) { ipfs_cid_free(cid); cid = NULL; @@ -253,7 +257,7 @@ int ipfs_core_http_process_dht_get(struct IpfsNode* local_node, struct HttpReque for (int i = 0; i < request->arguments->total; i++) { char* hash = (char*)libp2p_utils_vector_get(request->arguments, i); - struct Cid* cid; + struct Cid* cid = NULL; if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash, strlen(hash), &cid)) { ipfs_cid_free(cid); cid = NULL; From 4e556221bd8fe56a9a0b8f69e0b7d9ed41082170 Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 12 Oct 2017 20:08:21 -0300 Subject: [PATCH 2/4] Fixed issue when receiving by POST method. --- core/api.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/api.c b/core/api.c index 94417e0..6374a53 100644 --- a/core/api.c +++ b/core/api.c @@ -462,9 +462,6 @@ void *api_connection_thread (void *ptr) goto quit; } - // once we leave the building of the req struct, do we need to do more? This flag will tell us. - int further_processing_necessary = 0; - if (strncmp(req.buf + req.method, "GET", 3)==0) { if (strcmp (req.buf + req.path, "/")==0 || strcmp (req.buf + req.path, "/webui")==0 || @@ -481,10 +478,7 @@ void *api_connection_thread (void *ptr) } else { write_cstr (s, HTTP_500); } - } else if (cstrstart(req.buf + req.path, API_V0_START)) { - req.request = req.path + sizeof(API_V0_START) - 1; - further_processing_necessary = 1; - } else { + } else if (!cstrstart(req.buf + req.path, API_V0_START)) { // TODO: handle download file here. // move out of the if to do further processing } @@ -540,10 +534,10 @@ void *api_connection_thread (void *ptr) // Unexpected??? libp2p_logger_error("api", "fail unexpected '%s'.\n", req.buf + req.method); write_cstr (s, HTTP_500); - further_processing_necessary = 0; } - if (further_processing_necessary) { + if (cstrstart(req.buf + req.path, API_V0_START)) { + req.request = req.path + sizeof(API_V0_START) - 1; // now do something with the request we have built struct HttpRequest* http_request = api_build_http_request(&req); if (http_request != NULL) { From ae6fe6dc29a2f971d1c208d63afac9a5ad2679ec Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 12 Oct 2017 20:12:28 -0300 Subject: [PATCH 3/4] Changed some API calls to use POST method. --- importer/exporter.c | 2 +- namesys/name.c | 4 ++-- routing/offline.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/importer/exporter.c b/importer/exporter.c index 7c4d53b..a15571e 100644 --- a/importer/exporter.c +++ b/importer/exporter.c @@ -295,7 +295,7 @@ int ipfs_exporter_object_cat(struct CliArguments* args, FILE* output_file) { request->arguments = libp2p_utils_vector_new(1); libp2p_utils_vector_add(request->arguments, hash); size_t response_size = 0; - int retVal = ipfs_core_http_request_get(local_node, request, &response, &response_size); + int retVal = ipfs_core_http_request_post(local_node, request, &response, &response_size, "", 0); if (response != NULL && response_size > 0) { fwrite(response, 1, response_size, output_file); free(response); diff --git a/namesys/name.c b/namesys/name.c index f0f2664..cd61e1d 100644 --- a/namesys/name.c +++ b/namesys/name.c @@ -21,7 +21,7 @@ int ipfs_name_publish(struct IpfsNode* local_node, char* name) { request->sub_command = "publish"; libp2p_utils_vector_add(request->arguments, name); size_t response_size = 0; - int retVal = ipfs_core_http_request_get(local_node, request, &response, &response_size); + int retVal = ipfs_core_http_request_post(local_node, request, &response, &response_size, "", 0); if (response != NULL && response_size > 0) { fwrite(response, 1, response_size, stdout); free(response); @@ -40,7 +40,7 @@ int ipfs_name_resolve(struct IpfsNode* local_node, char* name) { request->sub_command = "resolve"; libp2p_utils_vector_add(request->arguments, name); size_t response_size = 0; - int retVal = ipfs_core_http_request_get(local_node, request, &response, &response_size); + int retVal = ipfs_core_http_request_post(local_node, request, &response, &response_size, "", 0); if (response != NULL && response_size > 0) { fwrite(response, 1, response_size, stdout); free(response); diff --git a/routing/offline.c b/routing/offline.c index 3744f0c..c8dd5f5 100644 --- a/routing/offline.c +++ b/routing/offline.c @@ -69,7 +69,7 @@ int ipfs_routing_generic_get_value (ipfs_routing* routing, const unsigned char * req->arguments = libp2p_utils_vector_new(1); libp2p_utils_vector_add(req->arguments, buffer); size_t response_size = 0; - if (!ipfs_core_http_request_get(routing->local_node, req, &response, &response_size)) { + if (!ipfs_core_http_request_post(routing->local_node, req, &response, &response_size, "", 0)) { libp2p_logger_error("offline", "Unable to call API for dht get.\n"); ipfs_core_http_request_free(req); return 0; @@ -181,7 +181,7 @@ int ipfs_routing_offline_provide (ipfs_routing* offlineRouting, const unsigned c request->sub_command = "provide"; libp2p_utils_vector_add(request->arguments, buffer); size_t response_size = 0; - if (!ipfs_core_http_request_get(offlineRouting->local_node, request, &response, &response_size)) { + if (!ipfs_core_http_request_post(offlineRouting->local_node, request, &response, &response_size, "", 0)) { libp2p_logger_error("offline", "Unable to call API for dht publish.\n"); ipfs_core_http_request_free(request); return 0; From 3d7dd87ef3940e3fd5e34486f13f4db21fac0d85 Mon Sep 17 00:00:00 2001 From: Agorise Date: Mon, 16 Oct 2017 13:43:57 +0300 Subject: [PATCH 4/4] Update LICENSE --- LICENSE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 42c3bed..ee2accb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2017 BitShares Munich IVS +Copyright (c) 2017 Agorise, IBC. +Contains works from BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal