aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_rest_reclaim.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-05-22 16:25:38 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-05-22 16:25:38 +0200
commitb2e257ecb9c82b19f6ab23431faa3605718d3f01 (patch)
tree767b8cf35d6e1c9a741ee7e87f33dc852a6593cc /src/reclaim/plugin_rest_reclaim.c
parentf9c41505dd2ad80d08d6b516c534df0a66ea55fc (diff)
downloadgnunet-b2e257ecb9c82b19f6ab23431faa3605718d3f01.tar.gz
gnunet-b2e257ecb9c82b19f6ab23431faa3605718d3f01.zip
clang-format and cleanup
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r--src/reclaim/plugin_rest_reclaim.c79
1 files changed, 32 insertions, 47 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 1a3784e64..7fe5283c4 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -15,7 +15,7 @@
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
@@ -25,21 +25,19 @@
25 * 25 *
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28
29#include "microhttpd.h" 28#include "microhttpd.h"
30#include <inttypes.h> 29#include <inttypes.h>
31#include <jansson.h> 30#include <jansson.h>
32
33#include "gnunet_gns_service.h" 31#include "gnunet_gns_service.h"
34#include "gnunet_gnsrecord_lib.h" 32#include "gnunet_gnsrecord_lib.h"
35#include "gnunet_identity_service.h" 33#include "gnunet_identity_service.h"
36#include "gnunet_namestore_service.h"
37#include "gnunet_reclaim_attribute_lib.h" 34#include "gnunet_reclaim_attribute_lib.h"
38#include "gnunet_reclaim_service.h" 35#include "gnunet_reclaim_service.h"
39#include "gnunet_rest_lib.h" 36#include "gnunet_rest_lib.h"
40#include "gnunet_rest_plugin.h" 37#include "gnunet_rest_plugin.h"
41#include "gnunet_signatures.h" 38#include "gnunet_signatures.h"
42#include "json_reclaim.h" 39#include "json_reclaim.h"
40
43/** 41/**
44 * REST root namespace 42 * REST root namespace
45 */ 43 */
@@ -163,16 +161,6 @@ struct RequestHandle
163 struct GNUNET_REST_RequestHandle *rest_handle; 161 struct GNUNET_REST_RequestHandle *rest_handle;
164 162
165 /** 163 /**
166 * Handle to NAMESTORE
167 */
168 struct GNUNET_NAMESTORE_Handle *namestore_handle;
169
170 /**
171 * Iterator for NAMESTORE
172 */
173 struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it;
174
175 /**
176 * Attribute claim list 164 * Attribute claim list
177 */ 165 */
178 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list; 166 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
@@ -276,8 +264,6 @@ cleanup_handle (struct RequestHandle *handle)
276 GNUNET_free (handle->url); 264 GNUNET_free (handle->url);
277 if (NULL != handle->emsg) 265 if (NULL != handle->emsg)
278 GNUNET_free (handle->emsg); 266 GNUNET_free (handle->emsg);
279 if (NULL != handle->namestore_handle)
280 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
281 if (NULL != handle->attr_list) { 267 if (NULL != handle->attr_list) {
282 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) { 268 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;) {
283 claim_tmp = claim_entry; 269 claim_tmp = claim_entry;
@@ -420,12 +406,12 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
420 json_array_append (handle->resp_object, json_resource); 406 json_array_append (handle->resp_object, json_resource);
421 407
422 tmp = GNUNET_STRINGS_data_to_string_alloc ( 408 tmp = GNUNET_STRINGS_data_to_string_alloc (
423 &ticket->identity, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 409 &ticket->identity, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
424 value = json_string (tmp); 410 value = json_string (tmp);
425 json_object_set_new (json_resource, "issuer", value); 411 json_object_set_new (json_resource, "issuer", value);
426 GNUNET_free (tmp); 412 GNUNET_free (tmp);
427 tmp = GNUNET_STRINGS_data_to_string_alloc ( 413 tmp = GNUNET_STRINGS_data_to_string_alloc (
428 &ticket->audience, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 414 &ticket->audience, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
429 value = json_string (tmp); 415 value = json_string (tmp);
430 json_object_set_new (json_resource, "audience", value); 416 json_object_set_new (json_resource, "audience", value);
431 GNUNET_free (tmp); 417 GNUNET_free (tmp);
@@ -477,8 +463,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
477 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 463 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
478 handle->idp = GNUNET_RECLAIM_connect (cfg); 464 handle->idp = GNUNET_RECLAIM_connect (cfg);
479 handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start ( 465 handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (
480 handle->idp, priv_key, &collect_error_cb, handle, &ticket_collect, handle, 466 handle->idp, priv_key, &collect_error_cb, handle, &ticket_collect, handle,
481 &collect_finished_cb, handle); 467 &collect_finished_cb, handle);
482} 468}
483 469
484 470
@@ -496,7 +482,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
496 json_t *data_json; 482 json_t *data_json;
497 json_error_t err; 483 json_error_t err;
498 struct GNUNET_JSON_Specification attrspec[] = { 484 struct GNUNET_JSON_Specification attrspec[] = {
499 GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end ()}; 485 GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end ()};
500 486
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n", 487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n",
502 handle->url); 488 handle->url);
@@ -541,11 +527,11 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
541 */ 527 */
542 if (0 == attribute->id) 528 if (0 == attribute->id)
543 attribute->id = 529 attribute->id =
544 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); 530 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
545 handle->idp = GNUNET_RECLAIM_connect (cfg); 531 handle->idp = GNUNET_RECLAIM_connect (cfg);
546 exp = GNUNET_TIME_UNIT_HOURS; 532 exp = GNUNET_TIME_UNIT_HOURS;
547 handle->idp_op = GNUNET_RECLAIM_attribute_store ( 533 handle->idp_op = GNUNET_RECLAIM_attribute_store (
548 handle->idp, identity_priv, attribute, &exp, &finished_cont, handle); 534 handle->idp, identity_priv, attribute, &exp, &finished_cont, handle);
549 GNUNET_JSON_parse_free (attrspec); 535 GNUNET_JSON_parse_free (attrspec);
550} 536}
551 537
@@ -629,8 +615,8 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
629 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 615 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
630 handle->idp = GNUNET_RECLAIM_connect (cfg); 616 handle->idp = GNUNET_RECLAIM_connect (cfg);
631 handle->attr_it = GNUNET_RECLAIM_get_attributes_start ( 617 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (
632 handle->idp, priv_key, &collect_error_cb, handle, &attr_collect, handle, 618 handle->idp, priv_key, &collect_error_cb, handle, &attr_collect, handle,
633 &collect_finished_cb, handle); 619 &collect_finished_cb, handle);
634} 620}
635 621
636 622
@@ -676,7 +662,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
676 return; 662 return;
677 } 663 }
678 identity_id_str = 664 identity_id_str =
679 strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1); 665 strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
680 identity = strtok (identity_id_str, "/"); 666 identity = strtok (identity_id_str, "/");
681 id = strtok (NULL, "/"); 667 id = strtok (NULL, "/");
682 if ((NULL == identity) || (NULL == id)) { 668 if ((NULL == identity) || (NULL == id)) {
@@ -704,7 +690,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
704 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t)); 690 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t));
705 attr.name = ""; 691 attr.name = "";
706 handle->idp_op = GNUNET_RECLAIM_attribute_delete ( 692 handle->idp_op = GNUNET_RECLAIM_attribute_delete (
707 handle->idp, priv_key, &attr, &delete_finished_cb, handle); 693 handle->idp, priv_key, &attr, &delete_finished_cb, handle);
708 GNUNET_free (identity_id_str); 694 GNUNET_free (identity_id_str);
709} 695}
710 696
@@ -722,7 +708,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
722 json_t *data_json; 708 json_t *data_json;
723 json_error_t err; 709 json_error_t err;
724 struct GNUNET_JSON_Specification tktspec[] = { 710 struct GNUNET_JSON_Specification tktspec[] = {
725 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; 711 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()};
726 712
727 if (0 >= handle->rest_handle->data_size) { 713 if (0 >= handle->rest_handle->data_size) {
728 GNUNET_SCHEDULER_add_now (&do_error, handle); 714 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -766,7 +752,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
766 752
767 handle->idp = GNUNET_RECLAIM_connect (cfg); 753 handle->idp = GNUNET_RECLAIM_connect (cfg);
768 handle->idp_op = GNUNET_RECLAIM_ticket_revoke ( 754 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (
769 handle->idp, identity_priv, ticket, &finished_cont, handle); 755 handle->idp, identity_priv, ticket, &finished_cont, handle);
770 GNUNET_JSON_parse_free (tktspec); 756 GNUNET_JSON_parse_free (tktspec);
771} 757}
772 758
@@ -810,7 +796,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
810 json_t *data_json; 796 json_t *data_json;
811 json_error_t err; 797 json_error_t err;
812 struct GNUNET_JSON_Specification tktspec[] = { 798 struct GNUNET_JSON_Specification tktspec[] = {
813 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; 799 GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()};
814 800
815 if (0 >= handle->rest_handle->data_size) { 801 if (0 >= handle->rest_handle->data_size) {
816 GNUNET_SCHEDULER_add_now (&do_error, handle); 802 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -850,7 +836,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
850 handle->resp_object = json_object (); 836 handle->resp_object = json_object ();
851 handle->idp = GNUNET_RECLAIM_connect (cfg); 837 handle->idp = GNUNET_RECLAIM_connect (cfg);
852 handle->idp_op = GNUNET_RECLAIM_ticket_consume ( 838 handle->idp_op = GNUNET_RECLAIM_ticket_consume (
853 handle->idp, identity_priv, ticket, &consume_cont, handle); 839 handle->idp, identity_priv, ticket, &consume_cont, handle);
854 GNUNET_JSON_parse_free (tktspec); 840 GNUNET_JSON_parse_free (tktspec);
855} 841}
856 842
@@ -887,20 +873,20 @@ init_cont (struct RequestHandle *handle)
887{ 873{
888 struct GNUNET_REST_RequestHandlerError err; 874 struct GNUNET_REST_RequestHandlerError err;
889 static const struct GNUNET_REST_RequestHandler handlers[] = { 875 static const struct GNUNET_REST_RequestHandler handlers[] = {
890 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 876 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
891 &list_attribute_cont}, 877 &list_attribute_cont},
892 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 878 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
893 &add_attribute_cont}, 879 &add_attribute_cont},
894 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 880 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
895 &delete_attribute_cont}, 881 &delete_attribute_cont},
896 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, 882 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS,
897 &list_tickets_cont}, 883 &list_tickets_cont},
898 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, 884 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE,
899 &revoke_ticket_cont}, 885 &revoke_ticket_cont},
900 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME, 886 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME,
901 &consume_ticket_cont}, 887 &consume_ticket_cont},
902 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont}, 888 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont},
903 GNUNET_REST_HANDLER_END}; 889 GNUNET_REST_HANDLER_END};
904 890
905 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, handlers, 891 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, handlers,
906 &err, handle)) { 892 &err, handle)) {
@@ -983,9 +969,8 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
983 handle->url[strlen (handle->url) - 1] = '\0'; 969 handle->url[strlen (handle->url) - 1] = '\0';
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
985 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); 971 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
986 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
987 handle->timeout_task = 972 handle->timeout_task =
988 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 973 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
990} 975}
991 976