diff options
author | t3sserakt <t3ss@posteo.de> | 2020-08-06 16:25:51 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2020-08-06 16:25:51 +0200 |
commit | 38193fe48a572e475b4f84717ff5b3edbcaf2d2a (patch) | |
tree | d6deeb56d81f75ab411d88a03b865f7da7eaaed4 /src/reclaim/plugin_rest_reclaim.c | |
parent | 33954ae13d4d26cefa45ac86f5e2184b6abd724f (diff) | |
parent | 6ab14a20690a499ad32e3f2ad448d64d4e6b65fc (diff) | |
download | gnunet-38193fe48a572e475b4f84717ff5b3edbcaf2d2a.tar.gz gnunet-38193fe48a572e475b4f84717ff5b3edbcaf2d2a.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 296 |
1 files changed, 154 insertions, 142 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 10ee2f801..c2d14825e 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -88,6 +88,31 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
88 | static char *allow_methods; | 88 | static char *allow_methods; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Ego list | ||
92 | */ | ||
93 | static struct EgoEntry *ego_head; | ||
94 | |||
95 | /** | ||
96 | * Ego list | ||
97 | */ | ||
98 | static struct EgoEntry *ego_tail; | ||
99 | |||
100 | /** | ||
101 | * The processing state | ||
102 | */ | ||
103 | static int state; | ||
104 | |||
105 | /** | ||
106 | * Handle to Identity service. | ||
107 | */ | ||
108 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
109 | |||
110 | /** | ||
111 | * Identity Provider | ||
112 | */ | ||
113 | static struct GNUNET_RECLAIM_Handle *idp; | ||
114 | |||
115 | /** | ||
91 | * @brief struct returned by the initialization function of the plugin | 116 | * @brief struct returned by the initialization function of the plugin |
92 | */ | 117 | */ |
93 | struct Plugin | 118 | struct Plugin |
@@ -129,15 +154,6 @@ struct EgoEntry | |||
129 | 154 | ||
130 | struct RequestHandle | 155 | struct RequestHandle |
131 | { | 156 | { |
132 | /** | ||
133 | * Ego list | ||
134 | */ | ||
135 | struct EgoEntry *ego_head; | ||
136 | |||
137 | /** | ||
138 | * Ego list | ||
139 | */ | ||
140 | struct EgoEntry *ego_tail; | ||
141 | 157 | ||
142 | /** | 158 | /** |
143 | * Selected ego | 159 | * Selected ego |
@@ -150,16 +166,6 @@ struct RequestHandle | |||
150 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key; | 166 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key; |
151 | 167 | ||
152 | /** | 168 | /** |
153 | * The processing state | ||
154 | */ | ||
155 | int state; | ||
156 | |||
157 | /** | ||
158 | * Handle to Identity service. | ||
159 | */ | ||
160 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
161 | |||
162 | /** | ||
163 | * Rest connection | 169 | * Rest connection |
164 | */ | 170 | */ |
165 | struct GNUNET_REST_RequestHandle *rest_handle; | 171 | struct GNUNET_REST_RequestHandle *rest_handle; |
@@ -175,11 +181,6 @@ struct RequestHandle | |||
175 | struct GNUNET_IDENTITY_Operation *op; | 181 | struct GNUNET_IDENTITY_Operation *op; |
176 | 182 | ||
177 | /** | 183 | /** |
178 | * Identity Provider | ||
179 | */ | ||
180 | struct GNUNET_RECLAIM_Handle *idp; | ||
181 | |||
182 | /** | ||
183 | * Idp Operation | 184 | * Idp Operation |
184 | */ | 185 | */ |
185 | struct GNUNET_RECLAIM_Operation *idp_op; | 186 | struct GNUNET_RECLAIM_Operation *idp_op; |
@@ -194,7 +195,6 @@ struct RequestHandle | |||
194 | */ | 195 | */ |
195 | struct GNUNET_RECLAIM_AttestationIterator *attest_it; | 196 | struct GNUNET_RECLAIM_AttestationIterator *attest_it; |
196 | 197 | ||
197 | |||
198 | /** | 198 | /** |
199 | * Ticket iterator | 199 | * Ticket iterator |
200 | */ | 200 | */ |
@@ -251,51 +251,31 @@ struct RequestHandle | |||
251 | * @param handle Handle to clean up | 251 | * @param handle Handle to clean up |
252 | */ | 252 | */ |
253 | static void | 253 | static void |
254 | cleanup_handle (struct RequestHandle *handle) | 254 | cleanup_handle (void *cls) |
255 | { | 255 | { |
256 | struct EgoEntry *ego_entry; | 256 | struct RequestHandle *handle = cls; |
257 | struct EgoEntry *ego_tmp; | ||
258 | 257 | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
260 | if (NULL != handle->resp_object) | 259 | if (NULL != handle->resp_object) |
261 | json_decref (handle->resp_object); | 260 | json_decref (handle->resp_object); |
262 | if (NULL != handle->timeout_task) | 261 | if (NULL != handle->timeout_task) |
263 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 262 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
264 | if (NULL != handle->identity_handle) | ||
265 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
266 | if (NULL != handle->attr_it) | 263 | if (NULL != handle->attr_it) |
267 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); | 264 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); |
268 | if (NULL != handle->attest_it) | 265 | if (NULL != handle->attest_it) |
269 | GNUNET_RECLAIM_get_attestations_stop (handle->attest_it); | 266 | GNUNET_RECLAIM_get_attestations_stop (handle->attest_it); |
270 | if (NULL != handle->ticket_it) | 267 | if (NULL != handle->ticket_it) |
271 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); | 268 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); |
272 | if (NULL != handle->idp) | ||
273 | GNUNET_RECLAIM_disconnect (handle->idp); | ||
274 | if (NULL != handle->url) | 269 | if (NULL != handle->url) |
275 | GNUNET_free (handle->url); | 270 | GNUNET_free (handle->url); |
276 | if (NULL != handle->emsg) | 271 | if (NULL != handle->emsg) |
277 | GNUNET_free (handle->emsg); | 272 | GNUNET_free (handle->emsg); |
278 | if (NULL != handle->attr_list) | 273 | if (NULL != handle->attr_list) |
279 | GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); | 274 | GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list); |
280 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | ||
281 | { | ||
282 | ego_tmp = ego_entry; | ||
283 | ego_entry = ego_entry->next; | ||
284 | GNUNET_free (ego_tmp->identifier); | ||
285 | GNUNET_free (ego_tmp->keystring); | ||
286 | GNUNET_free (ego_tmp); | ||
287 | } | ||
288 | GNUNET_free (handle); | 275 | GNUNET_free (handle); |
289 | } | 276 | } |
290 | 277 | ||
291 | 278 | ||
292 | static void | ||
293 | cleanup_handle_delayed (void *cls) | ||
294 | { | ||
295 | cleanup_handle (cls); | ||
296 | } | ||
297 | |||
298 | |||
299 | /** | 279 | /** |
300 | * Task run on error, sends error message. Cleans up everything. | 280 | * Task run on error, sends error message. Cleans up everything. |
301 | * | 281 | * |
@@ -316,7 +296,7 @@ do_error (void *cls) | |||
316 | resp = GNUNET_REST_create_response (json_error); | 296 | resp = GNUNET_REST_create_response (json_error); |
317 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 297 | MHD_add_response_header (resp, "Content-Type", "application/json"); |
318 | handle->proc (handle->proc_cls, resp, handle->response_code); | 298 | handle->proc (handle->proc_cls, resp, handle->response_code); |
319 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 299 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
320 | GNUNET_free (json_error); | 300 | GNUNET_free (json_error); |
321 | } | 301 | } |
322 | 302 | ||
@@ -339,9 +319,7 @@ do_timeout (void *cls) | |||
339 | static void | 319 | static void |
340 | collect_error_cb (void *cls) | 320 | collect_error_cb (void *cls) |
341 | { | 321 | { |
342 | struct RequestHandle *handle = cls; | 322 | do_error (cls); |
343 | |||
344 | do_error (handle); | ||
345 | } | 323 | } |
346 | 324 | ||
347 | 325 | ||
@@ -353,13 +331,14 @@ finished_cont (void *cls, int32_t success, const char *emsg) | |||
353 | 331 | ||
354 | resp = GNUNET_REST_create_response (emsg); | 332 | resp = GNUNET_REST_create_response (emsg); |
355 | MHD_add_response_header (resp, "Content-Type", "application/json"); | 333 | MHD_add_response_header (resp, "Content-Type", "application/json"); |
334 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | ||
356 | if (GNUNET_OK != success) | 335 | if (GNUNET_OK != success) |
357 | { | 336 | { |
358 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 337 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
359 | return; | 338 | return; |
360 | } | 339 | } |
361 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 340 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
362 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 341 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
363 | } | 342 | } |
364 | 343 | ||
365 | 344 | ||
@@ -370,13 +349,14 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg) | |||
370 | struct MHD_Response *resp; | 349 | struct MHD_Response *resp; |
371 | 350 | ||
372 | resp = GNUNET_REST_create_response (emsg); | 351 | resp = GNUNET_REST_create_response (emsg); |
352 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | ||
373 | if (GNUNET_OK != success) | 353 | if (GNUNET_OK != success) |
374 | { | 354 | { |
375 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 355 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
376 | return; | 356 | return; |
377 | } | 357 | } |
378 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 358 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
379 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 359 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
380 | } | 360 | } |
381 | 361 | ||
382 | 362 | ||
@@ -395,6 +375,7 @@ return_response (void *cls) | |||
395 | result_str = json_dumps (handle->resp_object, 0); | 375 | result_str = json_dumps (handle->resp_object, 0); |
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
397 | resp = GNUNET_REST_create_response (result_str); | 377 | resp = GNUNET_REST_create_response (result_str); |
378 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | ||
398 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 379 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
399 | GNUNET_free (result_str); | 380 | GNUNET_free (result_str); |
400 | cleanup_handle (handle); | 381 | cleanup_handle (handle); |
@@ -485,7 +466,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
485 | identity = handle->url + strlen ( | 466 | identity = handle->url + strlen ( |
486 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; | 467 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; |
487 | 468 | ||
488 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 469 | for (ego_entry = ego_head; NULL != ego_entry; |
489 | ego_entry = ego_entry->next) | 470 | ego_entry = ego_entry->next) |
490 | if (0 == strcmp (identity, ego_entry->identifier)) | 471 | if (0 == strcmp (identity, ego_entry->identifier)) |
491 | break; | 472 | break; |
@@ -523,9 +504,8 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
523 | */ | 504 | */ |
524 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) | 505 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) |
525 | GNUNET_RECLAIM_id_generate (&attribute->id); | 506 | GNUNET_RECLAIM_id_generate (&attribute->id); |
526 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
527 | exp = GNUNET_TIME_UNIT_HOURS; | 507 | exp = GNUNET_TIME_UNIT_HOURS; |
528 | handle->idp_op = GNUNET_RECLAIM_attestation_store (handle->idp, | 508 | handle->idp_op = GNUNET_RECLAIM_attestation_store (idp, |
529 | identity_priv, | 509 | identity_priv, |
530 | attribute, | 510 | attribute, |
531 | &exp, | 511 | &exp, |
@@ -644,7 +624,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
644 | identity = handle->url + strlen ( | 624 | identity = handle->url + strlen ( |
645 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; | 625 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; |
646 | 626 | ||
647 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 627 | for (ego_entry = ego_head; NULL != ego_entry; |
648 | ego_entry = ego_entry->next) | 628 | ego_entry = ego_entry->next) |
649 | if (0 == strcmp (identity, ego_entry->identifier)) | 629 | if (0 == strcmp (identity, ego_entry->identifier)) |
650 | break; | 630 | break; |
@@ -659,8 +639,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
659 | return; | 639 | return; |
660 | } | 640 | } |
661 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 641 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
662 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 642 | handle->attest_it = GNUNET_RECLAIM_get_attestations_start (idp, |
663 | handle->attest_it = GNUNET_RECLAIM_get_attestations_start (handle->idp, | ||
664 | priv_key, | 643 | priv_key, |
665 | &collect_error_cb, | 644 | &collect_error_cb, |
666 | handle, | 645 | handle, |
@@ -713,7 +692,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
713 | return; | 692 | return; |
714 | } | 693 | } |
715 | 694 | ||
716 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 695 | for (ego_entry = ego_head; NULL != ego_entry; |
717 | ego_entry = ego_entry->next) | 696 | ego_entry = ego_entry->next) |
718 | if (0 == strcmp (identity, ego_entry->identifier)) | 697 | if (0 == strcmp (identity, ego_entry->identifier)) |
719 | break; | 698 | break; |
@@ -727,11 +706,10 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
727 | return; | 706 | return; |
728 | } | 707 | } |
729 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 708 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
730 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
731 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation)); | 709 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation)); |
732 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); | 710 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); |
733 | attr.name = ""; | 711 | attr.name = ""; |
734 | handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp, | 712 | handle->idp_op = GNUNET_RECLAIM_attestation_delete (idp, |
735 | priv_key, | 713 | priv_key, |
736 | &attr, | 714 | &attr, |
737 | &delete_finished_cb, | 715 | &delete_finished_cb, |
@@ -768,7 +746,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
768 | } | 746 | } |
769 | identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; | 747 | identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; |
770 | 748 | ||
771 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 749 | for (ego_entry = ego_head; NULL != ego_entry; |
772 | ego_entry = ego_entry->next) | 750 | ego_entry = ego_entry->next) |
773 | if (0 == strcmp (identity, ego_entry->identifier)) | 751 | if (0 == strcmp (identity, ego_entry->identifier)) |
774 | break; | 752 | break; |
@@ -782,9 +760,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
782 | return; | 760 | return; |
783 | } | 761 | } |
784 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 762 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
785 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
786 | handle->ticket_it = | 763 | handle->ticket_it = |
787 | GNUNET_RECLAIM_ticket_iteration_start (handle->idp, | 764 | GNUNET_RECLAIM_ticket_iteration_start (idp, |
788 | priv_key, | 765 | priv_key, |
789 | &collect_error_cb, | 766 | &collect_error_cb, |
790 | handle, | 767 | handle, |
@@ -823,7 +800,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
823 | } | 800 | } |
824 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; | 801 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; |
825 | 802 | ||
826 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 803 | for (ego_entry = ego_head; NULL != ego_entry; |
827 | ego_entry = ego_entry->next) | 804 | ego_entry = ego_entry->next) |
828 | if (0 == strcmp (identity, ego_entry->identifier)) | 805 | if (0 == strcmp (identity, ego_entry->identifier)) |
829 | break; | 806 | break; |
@@ -862,9 +839,8 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
862 | */ | 839 | */ |
863 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) | 840 | if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) |
864 | GNUNET_RECLAIM_id_generate (&attribute->id); | 841 | GNUNET_RECLAIM_id_generate (&attribute->id); |
865 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
866 | exp = GNUNET_TIME_UNIT_HOURS; | 842 | exp = GNUNET_TIME_UNIT_HOURS; |
867 | handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, | 843 | handle->idp_op = GNUNET_RECLAIM_attribute_store (idp, |
868 | identity_priv, | 844 | identity_priv, |
869 | attribute, | 845 | attribute, |
870 | &exp, | 846 | &exp, |
@@ -1012,7 +988,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1012 | } | 988 | } |
1013 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; | 989 | identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; |
1014 | 990 | ||
1015 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 991 | for (ego_entry = ego_head; NULL != ego_entry; |
1016 | ego_entry = ego_entry->next) | 992 | ego_entry = ego_entry->next) |
1017 | if (0 == strcmp (identity, ego_entry->identifier)) | 993 | if (0 == strcmp (identity, ego_entry->identifier)) |
1018 | break; | 994 | break; |
@@ -1027,8 +1003,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1027 | return; | 1003 | return; |
1028 | } | 1004 | } |
1029 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1005 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1030 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 1006 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (idp, |
1031 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, | ||
1032 | priv_key, | 1007 | priv_key, |
1033 | &collect_error_cb, | 1008 | &collect_error_cb, |
1034 | handle, | 1009 | handle, |
@@ -1078,7 +1053,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1078 | return; | 1053 | return; |
1079 | } | 1054 | } |
1080 | 1055 | ||
1081 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1056 | for (ego_entry = ego_head; NULL != ego_entry; |
1082 | ego_entry = ego_entry->next) | 1057 | ego_entry = ego_entry->next) |
1083 | if (0 == strcmp (identity, ego_entry->identifier)) | 1058 | if (0 == strcmp (identity, ego_entry->identifier)) |
1084 | break; | 1059 | break; |
@@ -1092,11 +1067,10 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1092 | return; | 1067 | return; |
1093 | } | 1068 | } |
1094 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1069 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1095 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
1096 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute)); | 1070 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute)); |
1097 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); | 1071 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); |
1098 | attr.name = ""; | 1072 | attr.name = ""; |
1099 | handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, | 1073 | handle->idp_op = GNUNET_RECLAIM_attribute_delete (idp, |
1100 | priv_key, | 1074 | priv_key, |
1101 | &attr, | 1075 | &attr, |
1102 | &delete_finished_cb, | 1076 | &delete_finished_cb, |
@@ -1152,7 +1126,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1152 | return; | 1126 | return; |
1153 | } | 1127 | } |
1154 | 1128 | ||
1155 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1129 | for (ego_entry = ego_head; NULL != ego_entry; |
1156 | ego_entry = ego_entry->next) | 1130 | ego_entry = ego_entry->next) |
1157 | { | 1131 | { |
1158 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 1132 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); |
@@ -1169,8 +1143,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1169 | } | 1143 | } |
1170 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1144 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1171 | 1145 | ||
1172 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 1146 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke (idp, |
1173 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, | ||
1174 | identity_priv, | 1147 | identity_priv, |
1175 | ticket, | 1148 | ticket, |
1176 | &finished_cont, | 1149 | &finished_cont, |
@@ -1256,7 +1229,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1256 | json_decref (data_json); | 1229 | json_decref (data_json); |
1257 | return; | 1230 | return; |
1258 | } | 1231 | } |
1259 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1232 | for (ego_entry = ego_head; NULL != ego_entry; |
1260 | ego_entry = ego_entry->next) | 1233 | ego_entry = ego_entry->next) |
1261 | { | 1234 | { |
1262 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 1235 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); |
@@ -1273,8 +1246,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1273 | } | 1246 | } |
1274 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1247 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1275 | handle->resp_object = json_object (); | 1248 | handle->resp_object = json_object (); |
1276 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 1249 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp, |
1277 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, | ||
1278 | identity_priv, | 1250 | identity_priv, |
1279 | ticket, | 1251 | ticket, |
1280 | &consume_cont, | 1252 | &consume_cont, |
@@ -1308,55 +1280,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1308 | 1280 | ||
1309 | 1281 | ||
1310 | /** | 1282 | /** |
1311 | * Handle rest request | ||
1312 | * | ||
1313 | * @param handle the request handle | ||
1314 | */ | ||
1315 | static void | ||
1316 | init_cont (struct RequestHandle *handle) | ||
1317 | { | ||
1318 | struct GNUNET_REST_RequestHandlerError err; | ||
1319 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1320 | { { MHD_HTTP_METHOD_GET, | ||
1321 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | ||
1322 | &list_attribute_cont }, | ||
1323 | { MHD_HTTP_METHOD_POST, | ||
1324 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | ||
1325 | &add_attribute_cont }, | ||
1326 | { MHD_HTTP_METHOD_DELETE, | ||
1327 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | ||
1328 | &delete_attribute_cont }, | ||
1329 | { MHD_HTTP_METHOD_GET, | ||
1330 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, | ||
1331 | &list_attestation_cont }, | ||
1332 | { MHD_HTTP_METHOD_POST, | ||
1333 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, | ||
1334 | &add_attestation_cont }, | ||
1335 | { MHD_HTTP_METHOD_DELETE, | ||
1336 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, | ||
1337 | &delete_attestation_cont }, | ||
1338 | { MHD_HTTP_METHOD_GET, | ||
1339 | GNUNET_REST_API_NS_IDENTITY_TICKETS, | ||
1340 | &list_tickets_cont }, | ||
1341 | { MHD_HTTP_METHOD_POST, | ||
1342 | GNUNET_REST_API_NS_IDENTITY_REVOKE, | ||
1343 | &revoke_ticket_cont }, | ||
1344 | { MHD_HTTP_METHOD_POST, | ||
1345 | GNUNET_REST_API_NS_IDENTITY_CONSUME, | ||
1346 | &consume_ticket_cont }, | ||
1347 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, | ||
1348 | GNUNET_REST_HANDLER_END }; | ||
1349 | |||
1350 | if (GNUNET_NO == | ||
1351 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
1352 | { | ||
1353 | handle->response_code = err.error_code; | ||
1354 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
1355 | } | ||
1356 | } | ||
1357 | |||
1358 | |||
1359 | /** | ||
1360 | * If listing is enabled, prints information about the egos. | 1283 | * If listing is enabled, prints information about the egos. |
1361 | * | 1284 | * |
1362 | * This function is initially called for all egos and then again | 1285 | * This function is initially called for all egos and then again |
@@ -1395,52 +1318,126 @@ list_ego (void *cls, | |||
1395 | void **ctx, | 1318 | void **ctx, |
1396 | const char *identifier) | 1319 | const char *identifier) |
1397 | { | 1320 | { |
1398 | struct RequestHandle *handle = cls; | ||
1399 | struct EgoEntry *ego_entry; | 1321 | struct EgoEntry *ego_entry; |
1400 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1322 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1401 | 1323 | ||
1402 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1324 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1403 | { | 1325 | { |
1404 | handle->state = ID_REST_STATE_POST_INIT; | 1326 | state = ID_REST_STATE_POST_INIT; |
1405 | init_cont (handle); | ||
1406 | return; | 1327 | return; |
1407 | } | 1328 | } |
1408 | if (ID_REST_STATE_INIT == handle->state) | 1329 | if (ID_REST_STATE_INIT == state) |
1409 | { | 1330 | { |
1410 | ego_entry = GNUNET_new (struct EgoEntry); | 1331 | ego_entry = GNUNET_new (struct EgoEntry); |
1411 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1332 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1412 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1333 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
1413 | ego_entry->ego = ego; | 1334 | ego_entry->ego = ego; |
1414 | ego_entry->identifier = GNUNET_strdup (identifier); | 1335 | ego_entry->identifier = GNUNET_strdup (identifier); |
1415 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 1336 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
1416 | handle->ego_tail, | 1337 | ego_tail, |
1417 | ego_entry); | 1338 | ego_entry); |
1418 | } | 1339 | } |
1340 | /* Ego renamed or added */ | ||
1341 | if (identifier != NULL) | ||
1342 | { | ||
1343 | for (ego_entry = ego_head; NULL != ego_entry; | ||
1344 | ego_entry = ego_entry->next) | ||
1345 | { | ||
1346 | if (ego_entry->ego == ego) | ||
1347 | { | ||
1348 | /* Rename */ | ||
1349 | GNUNET_free (ego_entry->identifier); | ||
1350 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
1351 | break; | ||
1352 | } | ||
1353 | } | ||
1354 | if (NULL == ego_entry) | ||
1355 | { | ||
1356 | /* Add */ | ||
1357 | ego_entry = GNUNET_new (struct EgoEntry); | ||
1358 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
1359 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
1360 | ego_entry->ego = ego; | ||
1361 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
1362 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
1363 | ego_tail, | ||
1364 | ego_entry); | ||
1365 | } | ||
1366 | } | ||
1367 | else | ||
1368 | { | ||
1369 | /* Delete */ | ||
1370 | for (ego_entry = ego_head; NULL != ego_entry; | ||
1371 | ego_entry = ego_entry->next) | ||
1372 | { | ||
1373 | if (ego_entry->ego == ego) | ||
1374 | break; | ||
1375 | } | ||
1376 | if (NULL == ego_entry) | ||
1377 | return; /* Not found */ | ||
1378 | |||
1379 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
1380 | ego_tail, | ||
1381 | ego_entry); | ||
1382 | GNUNET_free (ego_entry->identifier); | ||
1383 | GNUNET_free (ego_entry->keystring); | ||
1384 | GNUNET_free (ego_entry); | ||
1385 | return; | ||
1386 | } | ||
1387 | |||
1419 | } | 1388 | } |
1420 | 1389 | ||
1421 | 1390 | ||
1422 | static void | 1391 | static enum GNUNET_GenericReturnValue |
1423 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1392 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
1424 | GNUNET_REST_ResultProcessor proc, | 1393 | GNUNET_REST_ResultProcessor proc, |
1425 | void *proc_cls) | 1394 | void *proc_cls) |
1426 | { | 1395 | { |
1427 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1396 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1397 | struct GNUNET_REST_RequestHandlerError err; | ||
1398 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1399 | { { MHD_HTTP_METHOD_GET, | ||
1400 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont }, | ||
1401 | { MHD_HTTP_METHOD_POST, | ||
1402 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont }, | ||
1403 | { MHD_HTTP_METHOD_DELETE, | ||
1404 | GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, | ||
1405 | { MHD_HTTP_METHOD_GET, | ||
1406 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont }, | ||
1407 | { MHD_HTTP_METHOD_POST, | ||
1408 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont }, | ||
1409 | { MHD_HTTP_METHOD_DELETE, | ||
1410 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont }, | ||
1411 | { MHD_HTTP_METHOD_GET, | ||
1412 | GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, | ||
1413 | { MHD_HTTP_METHOD_POST, | ||
1414 | GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont }, | ||
1415 | { MHD_HTTP_METHOD_POST, | ||
1416 | GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont }, | ||
1417 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, | ||
1418 | GNUNET_REST_HANDLER_END | ||
1419 | }; | ||
1428 | 1420 | ||
1429 | handle->response_code = 0; | 1421 | handle->response_code = 0; |
1430 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1422 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1431 | handle->proc_cls = proc_cls; | 1423 | handle->proc_cls = proc_cls; |
1432 | handle->proc = proc; | 1424 | handle->proc = proc; |
1433 | handle->state = ID_REST_STATE_INIT; | 1425 | state = ID_REST_STATE_INIT; |
1434 | handle->rest_handle = rest_handle; | 1426 | handle->rest_handle = rest_handle; |
1435 | 1427 | ||
1436 | handle->url = GNUNET_strdup (rest_handle->url); | 1428 | handle->url = GNUNET_strdup (rest_handle->url); |
1437 | if (handle->url[strlen (handle->url) - 1] == '/') | 1429 | if (handle->url[strlen (handle->url) - 1] == '/') |
1438 | handle->url[strlen (handle->url) - 1] = '\0'; | 1430 | handle->url[strlen (handle->url) - 1] = '\0'; |
1439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1431 | if (GNUNET_NO == |
1440 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); | 1432 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
1433 | { | ||
1434 | cleanup_handle (handle); | ||
1435 | return GNUNET_NO; | ||
1436 | } | ||
1437 | |||
1441 | handle->timeout_task = | 1438 | handle->timeout_task = |
1442 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 1439 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); |
1443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1440 | return GNUNET_YES; |
1444 | } | 1441 | } |
1445 | 1442 | ||
1446 | 1443 | ||
@@ -1472,7 +1469,8 @@ libgnunet_plugin_rest_reclaim_init (void *cls) | |||
1472 | MHD_HTTP_METHOD_PUT, | 1469 | MHD_HTTP_METHOD_PUT, |
1473 | MHD_HTTP_METHOD_DELETE, | 1470 | MHD_HTTP_METHOD_DELETE, |
1474 | MHD_HTTP_METHOD_OPTIONS); | 1471 | MHD_HTTP_METHOD_OPTIONS); |
1475 | 1472 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | |
1473 | idp = GNUNET_RECLAIM_connect (cfg); | ||
1476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1477 | _ ("Identity Provider REST API initialized\n")); | 1475 | _ ("Identity Provider REST API initialized\n")); |
1478 | return api; | 1476 | return api; |
@@ -1490,8 +1488,22 @@ libgnunet_plugin_rest_reclaim_done (void *cls) | |||
1490 | { | 1488 | { |
1491 | struct GNUNET_REST_Plugin *api = cls; | 1489 | struct GNUNET_REST_Plugin *api = cls; |
1492 | struct Plugin *plugin = api->cls; | 1490 | struct Plugin *plugin = api->cls; |
1491 | struct EgoEntry *ego_entry; | ||
1492 | struct EgoEntry *ego_tmp; | ||
1493 | 1493 | ||
1494 | plugin->cfg = NULL; | 1494 | plugin->cfg = NULL; |
1495 | if (NULL != idp) | ||
1496 | GNUNET_RECLAIM_disconnect (idp); | ||
1497 | if (NULL != identity_handle) | ||
1498 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
1499 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
1500 | { | ||
1501 | ego_tmp = ego_entry; | ||
1502 | ego_entry = ego_entry->next; | ||
1503 | GNUNET_free (ego_tmp->identifier); | ||
1504 | GNUNET_free (ego_tmp->keystring); | ||
1505 | GNUNET_free (ego_tmp); | ||
1506 | } | ||
1495 | 1507 | ||
1496 | GNUNET_free (allow_methods); | 1508 | GNUNET_free (allow_methods); |
1497 | GNUNET_free (api); | 1509 | GNUNET_free (api); |