aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_rest_reclaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r--src/reclaim/plugin_rest_reclaim.c293
1 files changed, 151 insertions, 142 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 10ee2f801..eb442bc3b 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;
88static char *allow_methods; 88static char *allow_methods;
89 89
90/** 90/**
91 * Ego list
92 */
93static struct EgoEntry *ego_head;
94
95/**
96 * Ego list
97 */
98static struct EgoEntry *ego_tail;
99
100/**
101 * The processing state
102 */
103static int state;
104
105/**
106 * Handle to Identity service.
107 */
108static struct GNUNET_IDENTITY_Handle *identity_handle;
109
110/**
111 * Identity Provider
112 */
113static 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 */
93struct Plugin 118struct Plugin
@@ -129,15 +154,6 @@ struct EgoEntry
129 154
130struct RequestHandle 155struct 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 */
253static void 253static void
254cleanup_handle (struct RequestHandle *handle) 254cleanup_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
292static void
293cleanup_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)
339static void 319static void
340collect_error_cb (void *cls) 320collect_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
@@ -359,7 +337,7 @@ finished_cont (void *cls, int32_t success, const char *emsg)
359 return; 337 return;
360 } 338 }
361 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 339 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
362 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 340 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
363} 341}
364 342
365 343
@@ -376,7 +354,7 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg)
376 return; 354 return;
377 } 355 }
378 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 356 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
379 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 357 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
380} 358}
381 359
382 360
@@ -485,7 +463,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
485 identity = handle->url + strlen ( 463 identity = handle->url + strlen (
486 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; 464 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
487 465
488 for (ego_entry = handle->ego_head; NULL != ego_entry; 466 for (ego_entry = ego_head; NULL != ego_entry;
489 ego_entry = ego_entry->next) 467 ego_entry = ego_entry->next)
490 if (0 == strcmp (identity, ego_entry->identifier)) 468 if (0 == strcmp (identity, ego_entry->identifier))
491 break; 469 break;
@@ -523,9 +501,8 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
523 */ 501 */
524 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) 502 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
525 GNUNET_RECLAIM_id_generate (&attribute->id); 503 GNUNET_RECLAIM_id_generate (&attribute->id);
526 handle->idp = GNUNET_RECLAIM_connect (cfg);
527 exp = GNUNET_TIME_UNIT_HOURS; 504 exp = GNUNET_TIME_UNIT_HOURS;
528 handle->idp_op = GNUNET_RECLAIM_attestation_store (handle->idp, 505 handle->idp_op = GNUNET_RECLAIM_attestation_store (idp,
529 identity_priv, 506 identity_priv,
530 attribute, 507 attribute,
531 &exp, 508 &exp,
@@ -644,7 +621,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
644 identity = handle->url + strlen ( 621 identity = handle->url + strlen (
645 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1; 622 GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
646 623
647 for (ego_entry = handle->ego_head; NULL != ego_entry; 624 for (ego_entry = ego_head; NULL != ego_entry;
648 ego_entry = ego_entry->next) 625 ego_entry = ego_entry->next)
649 if (0 == strcmp (identity, ego_entry->identifier)) 626 if (0 == strcmp (identity, ego_entry->identifier))
650 break; 627 break;
@@ -659,8 +636,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
659 return; 636 return;
660 } 637 }
661 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 638 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
662 handle->idp = GNUNET_RECLAIM_connect (cfg); 639 handle->attest_it = GNUNET_RECLAIM_get_attestations_start (idp,
663 handle->attest_it = GNUNET_RECLAIM_get_attestations_start (handle->idp,
664 priv_key, 640 priv_key,
665 &collect_error_cb, 641 &collect_error_cb,
666 handle, 642 handle,
@@ -713,7 +689,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
713 return; 689 return;
714 } 690 }
715 691
716 for (ego_entry = handle->ego_head; NULL != ego_entry; 692 for (ego_entry = ego_head; NULL != ego_entry;
717 ego_entry = ego_entry->next) 693 ego_entry = ego_entry->next)
718 if (0 == strcmp (identity, ego_entry->identifier)) 694 if (0 == strcmp (identity, ego_entry->identifier))
719 break; 695 break;
@@ -727,11 +703,10 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
727 return; 703 return;
728 } 704 }
729 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 705 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)); 706 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation));
732 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); 707 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
733 attr.name = ""; 708 attr.name = "";
734 handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp, 709 handle->idp_op = GNUNET_RECLAIM_attestation_delete (idp,
735 priv_key, 710 priv_key,
736 &attr, 711 &attr,
737 &delete_finished_cb, 712 &delete_finished_cb,
@@ -768,7 +743,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
768 } 743 }
769 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; 744 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
770 745
771 for (ego_entry = handle->ego_head; NULL != ego_entry; 746 for (ego_entry = ego_head; NULL != ego_entry;
772 ego_entry = ego_entry->next) 747 ego_entry = ego_entry->next)
773 if (0 == strcmp (identity, ego_entry->identifier)) 748 if (0 == strcmp (identity, ego_entry->identifier))
774 break; 749 break;
@@ -782,9 +757,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
782 return; 757 return;
783 } 758 }
784 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 759 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
785 handle->idp = GNUNET_RECLAIM_connect (cfg);
786 handle->ticket_it = 760 handle->ticket_it =
787 GNUNET_RECLAIM_ticket_iteration_start (handle->idp, 761 GNUNET_RECLAIM_ticket_iteration_start (idp,
788 priv_key, 762 priv_key,
789 &collect_error_cb, 763 &collect_error_cb,
790 handle, 764 handle,
@@ -823,7 +797,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
823 } 797 }
824 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 798 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
825 799
826 for (ego_entry = handle->ego_head; NULL != ego_entry; 800 for (ego_entry = ego_head; NULL != ego_entry;
827 ego_entry = ego_entry->next) 801 ego_entry = ego_entry->next)
828 if (0 == strcmp (identity, ego_entry->identifier)) 802 if (0 == strcmp (identity, ego_entry->identifier))
829 break; 803 break;
@@ -862,9 +836,8 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
862 */ 836 */
863 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id)) 837 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
864 GNUNET_RECLAIM_id_generate (&attribute->id); 838 GNUNET_RECLAIM_id_generate (&attribute->id);
865 handle->idp = GNUNET_RECLAIM_connect (cfg);
866 exp = GNUNET_TIME_UNIT_HOURS; 839 exp = GNUNET_TIME_UNIT_HOURS;
867 handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, 840 handle->idp_op = GNUNET_RECLAIM_attribute_store (idp,
868 identity_priv, 841 identity_priv,
869 attribute, 842 attribute,
870 &exp, 843 &exp,
@@ -1012,7 +985,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1012 } 985 }
1013 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 986 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
1014 987
1015 for (ego_entry = handle->ego_head; NULL != ego_entry; 988 for (ego_entry = ego_head; NULL != ego_entry;
1016 ego_entry = ego_entry->next) 989 ego_entry = ego_entry->next)
1017 if (0 == strcmp (identity, ego_entry->identifier)) 990 if (0 == strcmp (identity, ego_entry->identifier))
1018 break; 991 break;
@@ -1027,8 +1000,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1027 return; 1000 return;
1028 } 1001 }
1029 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1002 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1030 handle->idp = GNUNET_RECLAIM_connect (cfg); 1003 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (idp,
1031 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
1032 priv_key, 1004 priv_key,
1033 &collect_error_cb, 1005 &collect_error_cb,
1034 handle, 1006 handle,
@@ -1078,7 +1050,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1078 return; 1050 return;
1079 } 1051 }
1080 1052
1081 for (ego_entry = handle->ego_head; NULL != ego_entry; 1053 for (ego_entry = ego_head; NULL != ego_entry;
1082 ego_entry = ego_entry->next) 1054 ego_entry = ego_entry->next)
1083 if (0 == strcmp (identity, ego_entry->identifier)) 1055 if (0 == strcmp (identity, ego_entry->identifier))
1084 break; 1056 break;
@@ -1092,11 +1064,10 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
1092 return; 1064 return;
1093 } 1065 }
1094 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1066 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)); 1067 memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
1097 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); 1068 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
1098 attr.name = ""; 1069 attr.name = "";
1099 handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, 1070 handle->idp_op = GNUNET_RECLAIM_attribute_delete (idp,
1100 priv_key, 1071 priv_key,
1101 &attr, 1072 &attr,
1102 &delete_finished_cb, 1073 &delete_finished_cb,
@@ -1152,7 +1123,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1152 return; 1123 return;
1153 } 1124 }
1154 1125
1155 for (ego_entry = handle->ego_head; NULL != ego_entry; 1126 for (ego_entry = ego_head; NULL != ego_entry;
1156 ego_entry = ego_entry->next) 1127 ego_entry = ego_entry->next)
1157 { 1128 {
1158 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 1129 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1169,8 +1140,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1169 } 1140 }
1170 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1141 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1171 1142
1172 handle->idp = GNUNET_RECLAIM_connect (cfg); 1143 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (idp,
1173 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp,
1174 identity_priv, 1144 identity_priv,
1175 ticket, 1145 ticket,
1176 &finished_cont, 1146 &finished_cont,
@@ -1256,7 +1226,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1256 json_decref (data_json); 1226 json_decref (data_json);
1257 return; 1227 return;
1258 } 1228 }
1259 for (ego_entry = handle->ego_head; NULL != ego_entry; 1229 for (ego_entry = ego_head; NULL != ego_entry;
1260 ego_entry = ego_entry->next) 1230 ego_entry = ego_entry->next)
1261 { 1231 {
1262 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 1232 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1273,8 +1243,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1273 } 1243 }
1274 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1244 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1275 handle->resp_object = json_object (); 1245 handle->resp_object = json_object ();
1276 handle->idp = GNUNET_RECLAIM_connect (cfg); 1246 handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
1277 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
1278 identity_priv, 1247 identity_priv,
1279 ticket, 1248 ticket,
1280 &consume_cont, 1249 &consume_cont,
@@ -1308,55 +1277,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
1308 1277
1309 1278
1310/** 1279/**
1311 * Handle rest request
1312 *
1313 * @param handle the request handle
1314 */
1315static void
1316init_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. 1280 * If listing is enabled, prints information about the egos.
1361 * 1281 *
1362 * This function is initially called for all egos and then again 1282 * This function is initially called for all egos and then again
@@ -1395,52 +1315,126 @@ list_ego (void *cls,
1395 void **ctx, 1315 void **ctx,
1396 const char *identifier) 1316 const char *identifier)
1397{ 1317{
1398 struct RequestHandle *handle = cls;
1399 struct EgoEntry *ego_entry; 1318 struct EgoEntry *ego_entry;
1400 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 1319 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1401 1320
1402 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 1321 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1403 { 1322 {
1404 handle->state = ID_REST_STATE_POST_INIT; 1323 state = ID_REST_STATE_POST_INIT;
1405 init_cont (handle);
1406 return; 1324 return;
1407 } 1325 }
1408 if (ID_REST_STATE_INIT == handle->state) 1326 if (ID_REST_STATE_INIT == state)
1409 { 1327 {
1410 ego_entry = GNUNET_new (struct EgoEntry); 1328 ego_entry = GNUNET_new (struct EgoEntry);
1411 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 1329 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1412 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 1330 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1413 ego_entry->ego = ego; 1331 ego_entry->ego = ego;
1414 ego_entry->identifier = GNUNET_strdup (identifier); 1332 ego_entry->identifier = GNUNET_strdup (identifier);
1415 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 1333 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
1416 handle->ego_tail, 1334 ego_tail,
1417 ego_entry); 1335 ego_entry);
1418 } 1336 }
1337 /* Ego renamed or added */
1338 if (identifier != NULL)
1339 {
1340 for (ego_entry = ego_head; NULL != ego_entry;
1341 ego_entry = ego_entry->next)
1342 {
1343 if (ego_entry->ego == ego)
1344 {
1345 /* Rename */
1346 GNUNET_free (ego_entry->identifier);
1347 ego_entry->identifier = GNUNET_strdup (identifier);
1348 break;
1349 }
1350 }
1351 if (NULL == ego_entry)
1352 {
1353 /* Add */
1354 ego_entry = GNUNET_new (struct EgoEntry);
1355 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
1356 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
1357 ego_entry->ego = ego;
1358 ego_entry->identifier = GNUNET_strdup (identifier);
1359 GNUNET_CONTAINER_DLL_insert_tail (ego_head,
1360 ego_tail,
1361 ego_entry);
1362 }
1363 }
1364 else
1365 {
1366 /* Delete */
1367 for (ego_entry = ego_head; NULL != ego_entry;
1368 ego_entry = ego_entry->next)
1369 {
1370 if (ego_entry->ego == ego)
1371 break;
1372 }
1373 if (NULL == ego_entry)
1374 return; /* Not found */
1375
1376 GNUNET_CONTAINER_DLL_remove (ego_head,
1377 ego_tail,
1378 ego_entry);
1379 GNUNET_free (ego_entry->identifier);
1380 GNUNET_free (ego_entry->keystring);
1381 GNUNET_free (ego_entry);
1382 return;
1383 }
1384
1419} 1385}
1420 1386
1421 1387
1422static void 1388static enum GNUNET_GenericReturnValue
1423rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1389rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1424 GNUNET_REST_ResultProcessor proc, 1390 GNUNET_REST_ResultProcessor proc,
1425 void *proc_cls) 1391 void *proc_cls)
1426{ 1392{
1427 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1393 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1394 struct GNUNET_REST_RequestHandlerError err;
1395 static const struct GNUNET_REST_RequestHandler handlers[] =
1396 { { MHD_HTTP_METHOD_GET,
1397 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont },
1398 { MHD_HTTP_METHOD_POST,
1399 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont },
1400 { MHD_HTTP_METHOD_DELETE,
1401 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont },
1402 { MHD_HTTP_METHOD_GET,
1403 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont },
1404 { MHD_HTTP_METHOD_POST,
1405 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont },
1406 { MHD_HTTP_METHOD_DELETE,
1407 GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont },
1408 { MHD_HTTP_METHOD_GET,
1409 GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont },
1410 { MHD_HTTP_METHOD_POST,
1411 GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont },
1412 { MHD_HTTP_METHOD_POST,
1413 GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont },
1414 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1415 GNUNET_REST_HANDLER_END
1416 };
1428 1417
1429 handle->response_code = 0; 1418 handle->response_code = 0;
1430 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1419 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1431 handle->proc_cls = proc_cls; 1420 handle->proc_cls = proc_cls;
1432 handle->proc = proc; 1421 handle->proc = proc;
1433 handle->state = ID_REST_STATE_INIT; 1422 state = ID_REST_STATE_INIT;
1434 handle->rest_handle = rest_handle; 1423 handle->rest_handle = rest_handle;
1435 1424
1436 handle->url = GNUNET_strdup (rest_handle->url); 1425 handle->url = GNUNET_strdup (rest_handle->url);
1437 if (handle->url[strlen (handle->url) - 1] == '/') 1426 if (handle->url[strlen (handle->url) - 1] == '/')
1438 handle->url[strlen (handle->url) - 1] = '\0'; 1427 handle->url[strlen (handle->url) - 1] = '\0';
1439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 1428 if (GNUNET_NO ==
1440 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); 1429 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1430 {
1431 cleanup_handle (handle);
1432 return GNUNET_NO;
1433 }
1434
1441 handle->timeout_task = 1435 handle->timeout_task =
1442 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 1436 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 1437 return GNUNET_YES;
1444} 1438}
1445 1439
1446 1440
@@ -1472,7 +1466,8 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1472 MHD_HTTP_METHOD_PUT, 1466 MHD_HTTP_METHOD_PUT,
1473 MHD_HTTP_METHOD_DELETE, 1467 MHD_HTTP_METHOD_DELETE,
1474 MHD_HTTP_METHOD_OPTIONS); 1468 MHD_HTTP_METHOD_OPTIONS);
1475 1469 identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
1470 idp = GNUNET_RECLAIM_connect (cfg);
1476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1477 _ ("Identity Provider REST API initialized\n")); 1472 _ ("Identity Provider REST API initialized\n"));
1478 return api; 1473 return api;
@@ -1490,8 +1485,22 @@ libgnunet_plugin_rest_reclaim_done (void *cls)
1490{ 1485{
1491 struct GNUNET_REST_Plugin *api = cls; 1486 struct GNUNET_REST_Plugin *api = cls;
1492 struct Plugin *plugin = api->cls; 1487 struct Plugin *plugin = api->cls;
1488 struct EgoEntry *ego_entry;
1489 struct EgoEntry *ego_tmp;
1493 1490
1494 plugin->cfg = NULL; 1491 plugin->cfg = NULL;
1492 if (NULL != idp)
1493 GNUNET_RECLAIM_disconnect (idp);
1494 if (NULL != identity_handle)
1495 GNUNET_IDENTITY_disconnect (identity_handle);
1496 for (ego_entry = ego_head; NULL != ego_entry;)
1497 {
1498 ego_tmp = ego_entry;
1499 ego_entry = ego_entry->next;
1500 GNUNET_free (ego_tmp->identifier);
1501 GNUNET_free (ego_tmp->keystring);
1502 GNUNET_free (ego_tmp);
1503 }
1495 1504
1496 GNUNET_free (allow_methods); 1505 GNUNET_free (allow_methods);
1497 GNUNET_free (api); 1506 GNUNET_free (api);