diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-04 19:40:23 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-04 19:40:23 +0200 |
commit | 815ded19f106990a37bbacec83546b1b897491f6 (patch) | |
tree | 9f9b013616809dad4cec996f96d0ca5e59331410 | |
parent | 080519e980d8f8a3b138c733f837417bdb1b6757 (diff) | |
download | gnunet-815ded19f106990a37bbacec83546b1b897491f6.tar.gz gnunet-815ded19f106990a37bbacec83546b1b897491f6.zip |
rest: fix #6462
-rw-r--r-- | src/gns/plugin_rest_gns.c | 65 | ||||
-rw-r--r-- | src/identity/plugin_rest_identity.c | 290 | ||||
-rw-r--r-- | src/include/gnunet_rest_plugin.h | 8 | ||||
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 242 | ||||
-rw-r--r-- | src/peerinfo-tool/plugin_rest_peerinfo.c | 66 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_openid_connect.c | 241 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 293 | ||||
-rw-r--r-- | src/rest/gnunet-rest-server.c | 120 | ||||
-rw-r--r-- | src/rest/plugin_rest_config.c | 7 | ||||
-rw-r--r-- | src/rest/plugin_rest_copying.c | 32 |
10 files changed, 645 insertions, 719 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index 37313c529..a3006ce23 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -63,6 +63,11 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
63 | static char *allow_methods; | 63 | static char *allow_methods; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Connection to GNS | ||
67 | */ | ||
68 | static struct GNUNET_GNS_Handle *gns; | ||
69 | |||
70 | /** | ||
66 | * @brief struct returned by the initialization function of the plugin | 71 | * @brief struct returned by the initialization function of the plugin |
67 | */ | 72 | */ |
68 | struct Plugin | 73 | struct Plugin |
@@ -76,11 +81,6 @@ struct Plugin | |||
76 | struct RequestHandle | 81 | struct RequestHandle |
77 | { | 82 | { |
78 | /** | 83 | /** |
79 | * Connection to GNS | ||
80 | */ | ||
81 | struct GNUNET_GNS_Handle *gns; | ||
82 | |||
83 | /** | ||
84 | * Active GNS lookup | 84 | * Active GNS lookup |
85 | */ | 85 | */ |
86 | struct GNUNET_GNS_LookupWithTldRequest *gns_lookup; | 86 | struct GNUNET_GNS_LookupWithTldRequest *gns_lookup; |
@@ -153,12 +153,6 @@ cleanup_handle (void *cls) | |||
153 | GNUNET_GNS_lookup_with_tld_cancel (handle->gns_lookup); | 153 | GNUNET_GNS_lookup_with_tld_cancel (handle->gns_lookup); |
154 | handle->gns_lookup = NULL; | 154 | handle->gns_lookup = NULL; |
155 | } | 155 | } |
156 | if (NULL != handle->gns) | ||
157 | { | ||
158 | GNUNET_GNS_disconnect (handle->gns); | ||
159 | handle->gns = NULL; | ||
160 | } | ||
161 | |||
162 | if (NULL != handle->timeout_task) | 156 | if (NULL != handle->timeout_task) |
163 | { | 157 | { |
164 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 158 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
@@ -318,7 +312,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
318 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; | 312 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
319 | } | 313 | } |
320 | 314 | ||
321 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, | 315 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld (gns, |
322 | handle->name, | 316 | handle->name, |
323 | handle->record_type, | 317 | handle->record_type, |
324 | GNUNET_GNS_LO_DEFAULT, | 318 | GNUNET_GNS_LO_DEFAULT, |
@@ -352,29 +346,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
352 | 346 | ||
353 | 347 | ||
354 | /** | 348 | /** |
355 | * Handle rest request | ||
356 | * | ||
357 | * @param handle the request handle | ||
358 | */ | ||
359 | static void | ||
360 | init_cont (struct RequestHandle *handle) | ||
361 | { | ||
362 | struct GNUNET_REST_RequestHandlerError err; | ||
363 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
364 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont }, | ||
365 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont }, | ||
366 | GNUNET_REST_HANDLER_END }; | ||
367 | |||
368 | if (GNUNET_NO == | ||
369 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
370 | { | ||
371 | handle->response_code = err.error_code; | ||
372 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
373 | } | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Function processing the REST call | 349 | * Function processing the REST call |
379 | * | 350 | * |
380 | * @param method HTTP method | 351 | * @param method HTTP method |
@@ -385,12 +356,17 @@ init_cont (struct RequestHandle *handle) | |||
385 | * @param proc_cls closure for callback function | 356 | * @param proc_cls closure for callback function |
386 | * @return GNUNET_OK if request accepted | 357 | * @return GNUNET_OK if request accepted |
387 | */ | 358 | */ |
388 | static void | 359 | static enum GNUNET_GenericReturnValue |
389 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 360 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
390 | GNUNET_REST_ResultProcessor proc, | 361 | GNUNET_REST_ResultProcessor proc, |
391 | void *proc_cls) | 362 | void *proc_cls) |
392 | { | 363 | { |
393 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 364 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
365 | struct GNUNET_REST_RequestHandlerError err; | ||
366 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
367 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont }, | ||
368 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont }, | ||
369 | GNUNET_REST_HANDLER_END }; | ||
394 | 370 | ||
395 | handle->response_code = 0; | 371 | handle->response_code = 0; |
396 | handle->timeout = | 372 | handle->timeout = |
@@ -402,14 +378,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
402 | handle->url = GNUNET_strdup (rest_handle->url); | 378 | handle->url = GNUNET_strdup (rest_handle->url); |
403 | if (handle->url[strlen (handle->url) - 1] == '/') | 379 | if (handle->url[strlen (handle->url) - 1] == '/') |
404 | handle->url[strlen (handle->url) - 1] = '\0'; | 380 | handle->url[strlen (handle->url) - 1] = '\0'; |
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 381 | if (GNUNET_NO == |
406 | handle->gns = GNUNET_GNS_connect (cfg); | 382 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
407 | init_cont (handle); | 383 | { |
384 | cleanup_handle (handle); | ||
385 | return GNUNET_NO; | ||
386 | } | ||
387 | |||
408 | 388 | ||
409 | handle->timeout_task = | 389 | handle->timeout_task = |
410 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 390 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); |
411 | 391 | return GNUNET_YES; | |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | ||
413 | } | 392 | } |
414 | 393 | ||
415 | 394 | ||
@@ -441,6 +420,7 @@ libgnunet_plugin_rest_gns_init (void *cls) | |||
441 | MHD_HTTP_METHOD_PUT, | 420 | MHD_HTTP_METHOD_PUT, |
442 | MHD_HTTP_METHOD_DELETE, | 421 | MHD_HTTP_METHOD_DELETE, |
443 | MHD_HTTP_METHOD_OPTIONS); | 422 | MHD_HTTP_METHOD_OPTIONS); |
423 | gns = GNUNET_GNS_connect (cfg); | ||
444 | 424 | ||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n")); | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Gns REST API initialized\n")); |
446 | return api; | 426 | return api; |
@@ -460,6 +440,9 @@ libgnunet_plugin_rest_gns_done (void *cls) | |||
460 | struct Plugin *plugin = api->cls; | 440 | struct Plugin *plugin = api->cls; |
461 | 441 | ||
462 | plugin->cfg = NULL; | 442 | plugin->cfg = NULL; |
443 | if (NULL != gns) | ||
444 | GNUNET_GNS_disconnect (gns); | ||
445 | |||
463 | 446 | ||
464 | GNUNET_free (allow_methods); | 447 | GNUNET_free (allow_methods); |
465 | GNUNET_free (api); | 448 | GNUNET_free (api); |
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 02e42d03f..6859396d6 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -127,6 +127,26 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
127 | static char *allow_methods; | 127 | static char *allow_methods; |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * Ego list | ||
131 | */ | ||
132 | static struct EgoEntry *ego_head; | ||
133 | |||
134 | /** | ||
135 | * Ego list | ||
136 | */ | ||
137 | static struct EgoEntry *ego_tail; | ||
138 | |||
139 | /** | ||
140 | * The processing state | ||
141 | */ | ||
142 | static int state; | ||
143 | |||
144 | /** | ||
145 | * Handle to Identity service. | ||
146 | */ | ||
147 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
148 | |||
149 | /** | ||
130 | * @brief struct returned by the initialization function of the plugin | 150 | * @brief struct returned by the initialization function of the plugin |
131 | */ | 151 | */ |
132 | struct Plugin | 152 | struct Plugin |
@@ -185,27 +205,6 @@ struct RequestHandle | |||
185 | */ | 205 | */ |
186 | size_t data_size; | 206 | size_t data_size; |
187 | 207 | ||
188 | |||
189 | /** | ||
190 | * Ego list | ||
191 | */ | ||
192 | struct EgoEntry *ego_head; | ||
193 | |||
194 | /** | ||
195 | * Ego list | ||
196 | */ | ||
197 | struct EgoEntry *ego_tail; | ||
198 | |||
199 | /** | ||
200 | * The processing state | ||
201 | */ | ||
202 | int state; | ||
203 | |||
204 | /** | ||
205 | * Handle to Identity service. | ||
206 | */ | ||
207 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
208 | |||
209 | /** | 208 | /** |
210 | * IDENTITY Operation | 209 | * IDENTITY Operation |
211 | */ | 210 | */ |
@@ -260,8 +259,6 @@ static void | |||
260 | cleanup_handle (void *cls) | 259 | cleanup_handle (void *cls) |
261 | { | 260 | { |
262 | struct RequestHandle *handle = cls; | 261 | struct RequestHandle *handle = cls; |
263 | struct EgoEntry *ego_entry; | ||
264 | struct EgoEntry *ego_tmp; | ||
265 | 262 | ||
266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
267 | if (NULL != handle->timeout_task) | 264 | if (NULL != handle->timeout_task) |
@@ -276,17 +273,6 @@ cleanup_handle (void *cls) | |||
276 | GNUNET_free (handle->emsg); | 273 | GNUNET_free (handle->emsg); |
277 | if (NULL != handle->name) | 274 | if (NULL != handle->name) |
278 | GNUNET_free (handle->name); | 275 | GNUNET_free (handle->name); |
279 | if (NULL != handle->identity_handle) | ||
280 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
281 | |||
282 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | ||
283 | { | ||
284 | ego_tmp = ego_entry; | ||
285 | ego_entry = ego_entry->next; | ||
286 | GNUNET_free (ego_tmp->identifier); | ||
287 | GNUNET_free (ego_tmp->keystring); | ||
288 | GNUNET_free (ego_tmp); | ||
289 | } | ||
290 | 276 | ||
291 | GNUNET_free (handle); | 277 | GNUNET_free (handle); |
292 | } | 278 | } |
@@ -338,7 +324,7 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
338 | 324 | ||
339 | if (NULL != pubkey) | 325 | if (NULL != pubkey) |
340 | { | 326 | { |
341 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 327 | for (ego_entry = ego_head; NULL != ego_entry; |
342 | ego_entry = ego_entry->next) | 328 | ego_entry = ego_entry->next) |
343 | { | 329 | { |
344 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) | 330 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) |
@@ -348,7 +334,7 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
348 | } | 334 | } |
349 | if (NULL != name) | 335 | if (NULL != name) |
350 | { | 336 | { |
351 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 337 | for (ego_entry = ego_head; NULL != ego_entry; |
352 | ego_entry = ego_entry->next) | 338 | ego_entry = ego_entry->next) |
353 | { | 339 | { |
354 | if (0 != strcasecmp (name, ego_entry->identifier)) | 340 | if (0 != strcasecmp (name, ego_entry->identifier)) |
@@ -438,7 +424,7 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
438 | // requested default identity of subsystem | 424 | // requested default identity of subsystem |
439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); |
440 | 426 | ||
441 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 427 | handle->op = GNUNET_IDENTITY_get (identity_handle, |
442 | subsystem, | 428 | subsystem, |
443 | &ego_get_for_subsystem, | 429 | &ego_get_for_subsystem, |
444 | handle); | 430 | handle); |
@@ -476,7 +462,7 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
476 | 462 | ||
477 | json_root = json_array (); | 463 | json_root = json_array (); |
478 | // Return ego/egos | 464 | // Return ego/egos |
479 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 465 | for (ego_entry = ego_head; NULL != ego_entry; |
480 | ego_entry = ego_entry->next) | 466 | ego_entry = ego_entry->next) |
481 | { | 467 | { |
482 | json_ego = json_object (); | 468 | json_ego = json_object (); |
@@ -766,7 +752,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
766 | json_decref (data_js); | 752 | json_decref (data_js); |
767 | return; | 753 | return; |
768 | } | 754 | } |
769 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | 755 | handle->op = GNUNET_IDENTITY_rename (identity_handle, |
770 | ego_entry->identifier, | 756 | ego_entry->identifier, |
771 | newname, | 757 | newname, |
772 | &do_finished, | 758 | &do_finished, |
@@ -956,7 +942,7 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
956 | } | 942 | } |
957 | 943 | ||
958 | handle->response_code = MHD_HTTP_NO_CONTENT; | 944 | handle->response_code = MHD_HTTP_NO_CONTENT; |
959 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 945 | handle->op = GNUNET_IDENTITY_set (identity_handle, |
960 | newsubsys, | 946 | newsubsys, |
961 | ego_entry->ego, | 947 | ego_entry->ego, |
962 | &do_finished, | 948 | &do_finished, |
@@ -1047,7 +1033,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1047 | return; | 1033 | return; |
1048 | } | 1034 | } |
1049 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); | 1035 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); |
1050 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1036 | for (ego_entry = ego_head; NULL != ego_entry; |
1051 | ego_entry = ego_entry->next) | 1037 | ego_entry = ego_entry->next) |
1052 | { | 1038 | { |
1053 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | 1039 | if (0 == strcasecmp (egoname, ego_entry->identifier)) |
@@ -1073,7 +1059,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1073 | pk_ptr = NULL; | 1059 | pk_ptr = NULL; |
1074 | json_decref (data_js); | 1060 | json_decref (data_js); |
1075 | handle->response_code = MHD_HTTP_CREATED; | 1061 | handle->response_code = MHD_HTTP_CREATED; |
1076 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1062 | handle->op = GNUNET_IDENTITY_create (identity_handle, |
1077 | handle->name, | 1063 | handle->name, |
1078 | pk_ptr, | 1064 | pk_ptr, |
1079 | &do_finished_create, | 1065 | &do_finished_create, |
@@ -1118,7 +1104,7 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1118 | } | 1104 | } |
1119 | 1105 | ||
1120 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1106 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1121 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1107 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1122 | ego_entry->identifier, | 1108 | ego_entry->identifier, |
1123 | &do_finished, | 1109 | &do_finished, |
1124 | handle); | 1110 | handle); |
@@ -1162,7 +1148,7 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1162 | } | 1148 | } |
1163 | 1149 | ||
1164 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1150 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1165 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1151 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1166 | ego_entry->identifier, | 1152 | ego_entry->identifier, |
1167 | &do_finished, | 1153 | &do_finished, |
1168 | handle); | 1154 | handle); |
@@ -1193,144 +1179,78 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1193 | } | 1179 | } |
1194 | 1180 | ||
1195 | 1181 | ||
1196 | /** | ||
1197 | * Handle rest request | ||
1198 | * | ||
1199 | * @param handle the request handle | ||
1200 | */ | ||
1201 | static void | ||
1202 | init_cont (struct RequestHandle *handle) | ||
1203 | { | ||
1204 | struct GNUNET_REST_RequestHandlerError err; | ||
1205 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1206 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | ||
1207 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1208 | &ego_get_pubkey }, | ||
1209 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | ||
1210 | { MHD_HTTP_METHOD_GET, | ||
1211 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1212 | &ego_get_subsystem }, | ||
1213 | { MHD_HTTP_METHOD_PUT, | ||
1214 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1215 | &ego_edit_pubkey }, | ||
1216 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | ||
1217 | { MHD_HTTP_METHOD_PUT, | ||
1218 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1219 | &ego_edit_subsystem }, | ||
1220 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | ||
1221 | { MHD_HTTP_METHOD_DELETE, | ||
1222 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1223 | &ego_delete_pubkey }, | ||
1224 | { MHD_HTTP_METHOD_DELETE, | ||
1225 | GNUNET_REST_API_NS_IDENTITY_NAME, | ||
1226 | &ego_delete_name }, | ||
1227 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, | ||
1228 | GNUNET_REST_HANDLER_END }; | ||
1229 | |||
1230 | if (GNUNET_NO == | ||
1231 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
1232 | { | ||
1233 | handle->response_code = err.error_code; | ||
1234 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
1235 | } | ||
1236 | } | ||
1237 | |||
1238 | |||
1239 | /** | ||
1240 | * If listing is enabled, prints information about the egos. | ||
1241 | * | ||
1242 | * This function is initially called for all egos and then again | ||
1243 | * whenever a ego's identifier changes or if it is deleted. At the | ||
1244 | * end of the initial pass over all egos, the function is once called | ||
1245 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
1246 | * be invoked in the future or that there was an error. | ||
1247 | * | ||
1248 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
1249 | * this function is only called ONCE, and 'NULL' being passed in | ||
1250 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
1251 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
1252 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
1253 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
1254 | * that one was not NULL). | ||
1255 | * | ||
1256 | * When an identity is renamed, this function is called with the | ||
1257 | * (known) ego but the NEW identifier. | ||
1258 | * | ||
1259 | * When an identity is deleted, this function is called with the | ||
1260 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
1261 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
1262 | * cleaned up). | ||
1263 | * | ||
1264 | * @param cls closure | ||
1265 | * @param ego ego handle | ||
1266 | * @param ctx context for application to store data for this ego | ||
1267 | * (during the lifetime of this process, initially NULL) | ||
1268 | * @param identifier identifier assigned by the user for this ego, | ||
1269 | * NULL if the user just deleted the ego and it | ||
1270 | * must thus no longer be used | ||
1271 | */ | ||
1272 | static void | 1182 | static void |
1273 | init_egos (void *cls, | 1183 | list_ego (void *cls, |
1274 | struct GNUNET_IDENTITY_Ego *ego, | 1184 | struct GNUNET_IDENTITY_Ego *ego, |
1275 | void **ctx, | 1185 | void **ctx, |
1276 | const char *identifier) | 1186 | const char *identifier) |
1277 | { | 1187 | { |
1278 | struct RequestHandle *handle = cls; | ||
1279 | struct EgoEntry *ego_entry; | 1188 | struct EgoEntry *ego_entry; |
1280 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1189 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1281 | 1190 | ||
1282 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1191 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1283 | { | 1192 | { |
1284 | handle->state = ID_REST_STATE_POST_INIT; | 1193 | state = ID_REST_STATE_POST_INIT; |
1285 | init_cont (handle); | ||
1286 | return; | 1194 | return; |
1287 | } | 1195 | } |
1288 | if (ID_REST_STATE_INIT == handle->state) | 1196 | if (ID_REST_STATE_INIT == state) |
1289 | { | 1197 | { |
1290 | ego_entry = GNUNET_new (struct EgoEntry); | 1198 | ego_entry = GNUNET_new (struct EgoEntry); |
1291 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1199 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1292 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1200 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
1293 | ego_entry->ego = ego; | 1201 | ego_entry->ego = ego; |
1294 | ego_entry->identifier = GNUNET_strdup (identifier); | 1202 | ego_entry->identifier = GNUNET_strdup (identifier); |
1295 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 1203 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
1296 | handle->ego_tail, | 1204 | ego_tail, |
1297 | ego_entry); | 1205 | ego_entry); |
1298 | return; | ||
1299 | } | 1206 | } |
1300 | // Check if ego exists | 1207 | /* Ego renamed or added */ |
1301 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 1208 | if (identifier != NULL) |
1302 | { | 1209 | { |
1303 | struct EgoEntry *tmp = ego_entry; | 1210 | for (ego_entry = ego_head; NULL != ego_entry; |
1304 | ego_entry = ego_entry->next; | 1211 | ego_entry = ego_entry->next) |
1305 | if (ego != tmp->ego) | ||
1306 | continue; | ||
1307 | // Deleted | ||
1308 | if (NULL == identifier) | ||
1309 | { | 1212 | { |
1310 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | 1213 | if (ego_entry->ego == ego) |
1311 | handle->ego_tail, | 1214 | { |
1312 | tmp); | 1215 | /* Rename */ |
1313 | GNUNET_free (tmp->keystring); | 1216 | GNUNET_free (ego_entry->identifier); |
1314 | GNUNET_free (tmp->identifier); | 1217 | ego_entry->identifier = GNUNET_strdup (identifier); |
1315 | GNUNET_free (tmp); | 1218 | break; |
1219 | } | ||
1316 | } | 1220 | } |
1317 | else | 1221 | if (NULL == ego_entry) |
1318 | { | 1222 | { |
1319 | // Renamed | 1223 | /* Add */ |
1320 | GNUNET_free (tmp->identifier); | 1224 | ego_entry = GNUNET_new (struct EgoEntry); |
1321 | tmp->identifier = GNUNET_strdup (identifier); | 1225 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1226 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
1227 | ego_entry->ego = ego; | ||
1228 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
1229 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
1230 | ego_tail, | ||
1231 | ego_entry); | ||
1322 | } | 1232 | } |
1233 | } | ||
1234 | else | ||
1235 | { | ||
1236 | /* Delete */ | ||
1237 | for (ego_entry = ego_head; NULL != ego_entry; | ||
1238 | ego_entry = ego_entry->next) | ||
1239 | { | ||
1240 | if (ego_entry->ego == ego) | ||
1241 | break; | ||
1242 | } | ||
1243 | if (NULL == ego_entry) | ||
1244 | return; /* Not found */ | ||
1245 | |||
1246 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
1247 | ego_tail, | ||
1248 | ego_entry); | ||
1249 | GNUNET_free (ego_entry->identifier); | ||
1250 | GNUNET_free (ego_entry->keystring); | ||
1251 | GNUNET_free (ego_entry); | ||
1323 | return; | 1252 | return; |
1324 | } | 1253 | } |
1325 | // New ego | ||
1326 | ego_entry = GNUNET_new (struct EgoEntry); | ||
1327 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
1328 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
1329 | ego_entry->ego = ego; | ||
1330 | GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); | ||
1331 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | ||
1332 | handle->ego_tail, | ||
1333 | ego_entry); | ||
1334 | 1254 | ||
1335 | } | 1255 | } |
1336 | 1256 | ||
@@ -1346,12 +1266,38 @@ init_egos (void *cls, | |||
1346 | * @param proc_cls closure for callback function | 1266 | * @param proc_cls closure for callback function |
1347 | * @return GNUNET_OK if request accepted | 1267 | * @return GNUNET_OK if request accepted |
1348 | */ | 1268 | */ |
1349 | static void | 1269 | static enum GNUNET_GenericReturnValue |
1350 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1270 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
1351 | GNUNET_REST_ResultProcessor proc, | 1271 | GNUNET_REST_ResultProcessor proc, |
1352 | void *proc_cls) | 1272 | void *proc_cls) |
1353 | { | 1273 | { |
1354 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1274 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1275 | struct GNUNET_REST_RequestHandlerError err; | ||
1276 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1277 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | ||
1278 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1279 | &ego_get_pubkey }, | ||
1280 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | ||
1281 | { MHD_HTTP_METHOD_GET, | ||
1282 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1283 | &ego_get_subsystem }, | ||
1284 | { MHD_HTTP_METHOD_PUT, | ||
1285 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1286 | &ego_edit_pubkey }, | ||
1287 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | ||
1288 | { MHD_HTTP_METHOD_PUT, | ||
1289 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1290 | &ego_edit_subsystem }, | ||
1291 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | ||
1292 | { MHD_HTTP_METHOD_DELETE, | ||
1293 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1294 | &ego_delete_pubkey }, | ||
1295 | { MHD_HTTP_METHOD_DELETE, | ||
1296 | GNUNET_REST_API_NS_IDENTITY_NAME, | ||
1297 | &ego_delete_name }, | ||
1298 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, | ||
1299 | GNUNET_REST_HANDLER_END }; | ||
1300 | |||
1355 | 1301 | ||
1356 | handle->response_code = 0; | 1302 | handle->response_code = 0; |
1357 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1303 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1365,13 +1311,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1365 | if (handle->url[strlen (handle->url) - 1] == '/') | 1311 | if (handle->url[strlen (handle->url) - 1] == '/') |
1366 | handle->url[strlen (handle->url) - 1] = '\0'; | 1312 | handle->url[strlen (handle->url) - 1] = '\0'; |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1368 | 1314 | if (GNUNET_NO == | |
1369 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &init_egos, handle); | 1315 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
1316 | { | ||
1317 | cleanup_handle (handle); | ||
1318 | return GNUNET_NO; | ||
1319 | } | ||
1370 | 1320 | ||
1371 | handle->timeout_task = | 1321 | handle->timeout_task = |
1372 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | 1322 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); |
1373 | |||
1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1324 | return GNUNET_YES; | ||
1375 | } | 1325 | } |
1376 | 1326 | ||
1377 | 1327 | ||
@@ -1403,6 +1353,7 @@ libgnunet_plugin_rest_identity_init (void *cls) | |||
1403 | MHD_HTTP_METHOD_PUT, | 1353 | MHD_HTTP_METHOD_PUT, |
1404 | MHD_HTTP_METHOD_DELETE, | 1354 | MHD_HTTP_METHOD_DELETE, |
1405 | MHD_HTTP_METHOD_OPTIONS); | 1355 | MHD_HTTP_METHOD_OPTIONS); |
1356 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | ||
1406 | 1357 | ||
1407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); | 1358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); |
1408 | return api; | 1359 | return api; |
@@ -1420,8 +1371,21 @@ libgnunet_plugin_rest_identity_done (void *cls) | |||
1420 | { | 1371 | { |
1421 | struct GNUNET_REST_Plugin *api = cls; | 1372 | struct GNUNET_REST_Plugin *api = cls; |
1422 | struct Plugin *plugin = api->cls; | 1373 | struct Plugin *plugin = api->cls; |
1374 | struct EgoEntry *ego_entry; | ||
1375 | struct EgoEntry *ego_tmp; | ||
1423 | 1376 | ||
1424 | plugin->cfg = NULL; | 1377 | plugin->cfg = NULL; |
1378 | if (NULL != identity_handle) | ||
1379 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
1380 | |||
1381 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
1382 | { | ||
1383 | ego_tmp = ego_entry; | ||
1384 | ego_entry = ego_entry->next; | ||
1385 | GNUNET_free (ego_tmp->identifier); | ||
1386 | GNUNET_free (ego_tmp->keystring); | ||
1387 | GNUNET_free (ego_tmp); | ||
1388 | } | ||
1425 | 1389 | ||
1426 | GNUNET_free (allow_methods); | 1390 | GNUNET_free (allow_methods); |
1427 | GNUNET_free (api); | 1391 | GNUNET_free (api); |
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h index 770ba66f2..96454f66b 100644 --- a/src/include/gnunet_rest_plugin.h +++ b/src/include/gnunet_rest_plugin.h | |||
@@ -69,10 +69,12 @@ struct GNUNET_REST_Plugin | |||
69 | * @param data_size the length of the data | 69 | * @param data_size the length of the data |
70 | * @param proc the callback for result | 70 | * @param proc the callback for result |
71 | * @param proc_cls closure for callback | 71 | * @param proc_cls closure for callback |
72 | * @return GNUNET_YES if the request was processed | ||
72 | */ | 73 | */ |
73 | void (*process_request) (struct GNUNET_REST_RequestHandle *handle, | 74 | enum GNUNET_GenericReturnValue (*process_request)( |
74 | GNUNET_REST_ResultProcessor proc, | 75 | struct GNUNET_REST_RequestHandle *handle, |
75 | void *proc_cls); | 76 | GNUNET_REST_ResultProcessor proc, |
77 | void *proc_cls); | ||
76 | }; | 78 | }; |
77 | 79 | ||
78 | 80 | ||
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index f1cbfb38b..c993518ea 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -85,6 +85,31 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
85 | static char *allow_methods; | 85 | static char *allow_methods; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Ego list | ||
89 | */ | ||
90 | static struct EgoEntry *ego_head; | ||
91 | |||
92 | /** | ||
93 | * Ego list | ||
94 | */ | ||
95 | static struct EgoEntry *ego_tail; | ||
96 | |||
97 | /** | ||
98 | * The processing state | ||
99 | */ | ||
100 | static int state; | ||
101 | |||
102 | /** | ||
103 | * Handle to NAMESTORE | ||
104 | */ | ||
105 | static struct GNUNET_NAMESTORE_Handle *ns_handle; | ||
106 | |||
107 | /** | ||
108 | * Handle to Identity service. | ||
109 | */ | ||
110 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
111 | |||
112 | /** | ||
88 | * @brief struct returned by the initialization function of the plugin | 113 | * @brief struct returned by the initialization function of the plugin |
89 | */ | 114 | */ |
90 | struct Plugin | 115 | struct Plugin |
@@ -170,15 +195,6 @@ struct RequestHandle | |||
170 | */ | 195 | */ |
171 | json_t *resp_object; | 196 | json_t *resp_object; |
172 | 197 | ||
173 | /** | ||
174 | * The processing state | ||
175 | */ | ||
176 | int state; | ||
177 | |||
178 | /** | ||
179 | * Handle to NAMESTORE | ||
180 | */ | ||
181 | struct GNUNET_NAMESTORE_Handle *ns_handle; | ||
182 | 198 | ||
183 | /** | 199 | /** |
184 | * Handle to NAMESTORE it | 200 | * Handle to NAMESTORE it |
@@ -196,26 +212,11 @@ struct RequestHandle | |||
196 | struct EgoEntry *ego_entry; | 212 | struct EgoEntry *ego_entry; |
197 | 213 | ||
198 | /** | 214 | /** |
199 | * Ego list | ||
200 | */ | ||
201 | struct EgoEntry *ego_head; | ||
202 | |||
203 | /** | ||
204 | * Ego list | ||
205 | */ | ||
206 | struct EgoEntry *ego_tail; | ||
207 | |||
208 | /** | ||
209 | * IDENTITY Operation | 215 | * IDENTITY Operation |
210 | */ | 216 | */ |
211 | struct GNUNET_IDENTITY_Operation *op; | 217 | struct GNUNET_IDENTITY_Operation *op; |
212 | 218 | ||
213 | /** | 219 | /** |
214 | * Handle to Identity service. | ||
215 | */ | ||
216 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
217 | |||
218 | /** | ||
219 | * Rest connection | 220 | * Rest connection |
220 | */ | 221 | */ |
221 | struct GNUNET_REST_RequestHandle *rest_handle; | 222 | struct GNUNET_REST_RequestHandle *rest_handle; |
@@ -264,8 +265,6 @@ static void | |||
264 | cleanup_handle (void *cls) | 265 | cleanup_handle (void *cls) |
265 | { | 266 | { |
266 | struct RequestHandle *handle = cls; | 267 | struct RequestHandle *handle = cls; |
267 | struct EgoEntry *ego_entry; | ||
268 | struct EgoEntry *ego_tmp; | ||
269 | 268 | ||
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
271 | if (NULL != handle->timeout_task) | 270 | if (NULL != handle->timeout_task) |
@@ -294,21 +293,6 @@ cleanup_handle (void *cls) | |||
294 | GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it); | 293 | GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it); |
295 | if (NULL != handle->ns_qe) | 294 | if (NULL != handle->ns_qe) |
296 | GNUNET_NAMESTORE_cancel (handle->ns_qe); | 295 | GNUNET_NAMESTORE_cancel (handle->ns_qe); |
297 | if (NULL != handle->identity_handle) | ||
298 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
299 | if (NULL != handle->ns_handle) | ||
300 | { | ||
301 | GNUNET_NAMESTORE_disconnect (handle->ns_handle); | ||
302 | } | ||
303 | |||
304 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | ||
305 | { | ||
306 | ego_tmp = ego_entry; | ||
307 | ego_entry = ego_entry->next; | ||
308 | GNUNET_free (ego_tmp->identifier); | ||
309 | GNUNET_free (ego_tmp->keystring); | ||
310 | GNUNET_free (ego_tmp); | ||
311 | } | ||
312 | 296 | ||
313 | if (NULL != handle->resp_object) | 297 | if (NULL != handle->resp_object) |
314 | { | 298 | { |
@@ -368,7 +352,7 @@ get_egoentry_namestore (struct RequestHandle *handle, char *name) | |||
368 | if (NULL == name) | 352 | if (NULL == name) |
369 | return NULL; | 353 | return NULL; |
370 | tmp = strtok (copy, "/"); | 354 | tmp = strtok (copy, "/"); |
371 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 355 | for (ego_entry = ego_head; NULL != ego_entry; |
372 | ego_entry = ego_entry->next) | 356 | ego_entry = ego_entry->next) |
373 | { | 357 | { |
374 | if (0 != strcasecmp (tmp, ego_entry->identifier)) | 358 | if (0 != strcasecmp (tmp, ego_entry->identifier)) |
@@ -647,7 +631,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
647 | if (1 >= strlen (labelname)) | 631 | if (1 >= strlen (labelname)) |
648 | { | 632 | { |
649 | handle->list_it = | 633 | handle->list_it = |
650 | GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | 634 | GNUNET_NAMESTORE_zone_iteration_start (ns_handle, |
651 | handle->zone_pkey, | 635 | handle->zone_pkey, |
652 | &namestore_iteration_error, | 636 | &namestore_iteration_error, |
653 | handle, | 637 | handle, |
@@ -664,7 +648,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
664 | return; | 648 | return; |
665 | } | 649 | } |
666 | handle->record_name = GNUNET_strdup (labelname + 1); | 650 | handle->record_name = GNUNET_strdup (labelname + 1); |
667 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 651 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle, |
668 | handle->zone_pkey, | 652 | handle->zone_pkey, |
669 | handle->record_name, | 653 | handle->record_name, |
670 | &ns_lookup_error_cb, | 654 | &ns_lookup_error_cb, |
@@ -699,7 +683,7 @@ ns_lookup_cb (void *cls, | |||
699 | } | 683 | } |
700 | for (j = 0; j < handle->rd_count; j++) | 684 | for (j = 0; j < handle->rd_count; j++) |
701 | rd_new[i + j] = handle->rd[j]; | 685 | rd_new[i + j] = handle->rd[j]; |
702 | handle->ns_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 686 | handle->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, |
703 | handle->zone_pkey, | 687 | handle->zone_pkey, |
704 | handle->record_name, | 688 | handle->record_name, |
705 | i + j, | 689 | i + j, |
@@ -791,7 +775,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, | |||
791 | return; | 775 | return; |
792 | } | 776 | } |
793 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 777 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
794 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 778 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle, |
795 | handle->zone_pkey, | 779 | handle->zone_pkey, |
796 | handle->record_name, | 780 | handle->record_name, |
797 | &ns_lookup_error_cb, | 781 | &ns_lookup_error_cb, |
@@ -892,7 +876,7 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
892 | } | 876 | } |
893 | 877 | ||
894 | handle->record_name = GNUNET_strdup (labelname + 1); | 878 | handle->record_name = GNUNET_strdup (labelname + 1); |
895 | handle->ns_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 879 | handle->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle, |
896 | handle->zone_pkey, | 880 | handle->zone_pkey, |
897 | handle->record_name, | 881 | handle->record_name, |
898 | 0, | 882 | 0, |
@@ -932,90 +916,79 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
932 | } | 916 | } |
933 | 917 | ||
934 | 918 | ||
935 | /** | ||
936 | * Handle rest request | ||
937 | * | ||
938 | * @param handle the request handle | ||
939 | */ | ||
940 | static void | ||
941 | init_cont (struct RequestHandle *handle) | ||
942 | { | ||
943 | struct GNUNET_REST_RequestHandlerError err; | ||
944 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
945 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get }, | ||
946 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add }, | ||
947 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_update }, | ||
948 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete }, | ||
949 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont }, | ||
950 | GNUNET_REST_HANDLER_END }; | ||
951 | |||
952 | if (GNUNET_NO == | ||
953 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
954 | { | ||
955 | handle->response_code = err.error_code; | ||
956 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
957 | } | ||
958 | } | ||
959 | |||
960 | |||
961 | /** | ||
962 | * This function is initially called for all egos and then again | ||
963 | * whenever a ego's identifier changes or if it is deleted. At the | ||
964 | * end of the initial pass over all egos, the function is once called | ||
965 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
966 | * be invoked in the future or that there was an error. | ||
967 | * | ||
968 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
969 | * this function is only called ONCE, and 'NULL' being passed in | ||
970 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
971 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
972 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
973 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
974 | * that one was not NULL). | ||
975 | * | ||
976 | * When an identity is renamed, this function is called with the | ||
977 | * (known) ego but the NEW identifier. | ||
978 | * | ||
979 | * When an identity is deleted, this function is called with the | ||
980 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
981 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
982 | * cleaned up). | ||
983 | * | ||
984 | * @param cls closure | ||
985 | * @param ego ego handle | ||
986 | * @param ctx context for application to store data for this ego | ||
987 | * (during the lifetime of this process, initially NULL) | ||
988 | * @param name identifier assigned by the user for this ego, | ||
989 | * NULL if the user just deleted the ego and it | ||
990 | * must thus no longer be used | ||
991 | */ | ||
992 | static void | 919 | static void |
993 | id_connect_cb (void *cls, | 920 | list_ego (void *cls, |
994 | struct GNUNET_IDENTITY_Ego *ego, | 921 | struct GNUNET_IDENTITY_Ego *ego, |
995 | void **ctx, | 922 | void **ctx, |
996 | const char *name) | 923 | const char *identifier) |
997 | { | 924 | { |
998 | struct RequestHandle *handle = cls; | ||
999 | struct EgoEntry *ego_entry; | 925 | struct EgoEntry *ego_entry; |
1000 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 926 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1001 | 927 | ||
1002 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 928 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1003 | { | 929 | { |
1004 | handle->state = ID_REST_STATE_POST_INIT; | 930 | state = ID_REST_STATE_POST_INIT; |
1005 | init_cont (handle); | ||
1006 | return; | 931 | return; |
1007 | } | 932 | } |
1008 | if (ID_REST_STATE_INIT == handle->state) | 933 | if (ID_REST_STATE_INIT == state) |
1009 | { | 934 | { |
1010 | ego_entry = GNUNET_new (struct EgoEntry); | 935 | ego_entry = GNUNET_new (struct EgoEntry); |
1011 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 936 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1012 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 937 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
1013 | ego_entry->ego = ego; | 938 | ego_entry->ego = ego; |
1014 | GNUNET_asprintf (&ego_entry->identifier, "%s", name); | 939 | ego_entry->identifier = GNUNET_strdup (identifier); |
1015 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 940 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
1016 | handle->ego_tail, | 941 | ego_tail, |
1017 | ego_entry); | 942 | ego_entry); |
1018 | } | 943 | } |
944 | /* Ego renamed or added */ | ||
945 | if (identifier != NULL) | ||
946 | { | ||
947 | for (ego_entry = ego_head; NULL != ego_entry; | ||
948 | ego_entry = ego_entry->next) | ||
949 | { | ||
950 | if (ego_entry->ego == ego) | ||
951 | { | ||
952 | /* Rename */ | ||
953 | GNUNET_free (ego_entry->identifier); | ||
954 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
955 | break; | ||
956 | } | ||
957 | } | ||
958 | if (NULL == ego_entry) | ||
959 | { | ||
960 | /* Add */ | ||
961 | ego_entry = GNUNET_new (struct EgoEntry); | ||
962 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
963 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
964 | ego_entry->ego = ego; | ||
965 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
966 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | ||
967 | ego_tail, | ||
968 | ego_entry); | ||
969 | } | ||
970 | } | ||
971 | else | ||
972 | { | ||
973 | /* Delete */ | ||
974 | for (ego_entry = ego_head; NULL != ego_entry; | ||
975 | ego_entry = ego_entry->next) | ||
976 | { | ||
977 | if (ego_entry->ego == ego) | ||
978 | break; | ||
979 | } | ||
980 | if (NULL == ego_entry) | ||
981 | return; /* Not found */ | ||
982 | |||
983 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
984 | ego_tail, | ||
985 | ego_entry); | ||
986 | GNUNET_free (ego_entry->identifier); | ||
987 | GNUNET_free (ego_entry->keystring); | ||
988 | GNUNET_free (ego_entry); | ||
989 | return; | ||
990 | } | ||
991 | |||
1019 | } | 992 | } |
1020 | 993 | ||
1021 | 994 | ||
@@ -1030,12 +1003,20 @@ id_connect_cb (void *cls, | |||
1030 | * @param proc_cls closure for callback function | 1003 | * @param proc_cls closure for callback function |
1031 | * @return GNUNET_OK if request accepted | 1004 | * @return GNUNET_OK if request accepted |
1032 | */ | 1005 | */ |
1033 | static void | 1006 | static enum GNUNET_GenericReturnValue |
1034 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1007 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
1035 | GNUNET_REST_ResultProcessor proc, | 1008 | GNUNET_REST_ResultProcessor proc, |
1036 | void *proc_cls) | 1009 | void *proc_cls) |
1037 | { | 1010 | { |
1038 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1011 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1012 | struct GNUNET_REST_RequestHandlerError err; | ||
1013 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
1014 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get }, | ||
1015 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add }, | ||
1016 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_update }, | ||
1017 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete }, | ||
1018 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont }, | ||
1019 | GNUNET_REST_HANDLER_END }; | ||
1039 | 1020 | ||
1040 | handle->response_code = 0; | 1021 | handle->response_code = 0; |
1041 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1022 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1048,14 +1029,18 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1048 | if (handle->url[strlen (handle->url) - 1] == '/') | 1029 | if (handle->url[strlen (handle->url) - 1] == '/') |
1049 | handle->url[strlen (handle->url) - 1] = '\0'; | 1030 | handle->url[strlen (handle->url) - 1] = '\0'; |
1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1032 | if (GNUNET_NO == | ||
1033 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
1034 | { | ||
1035 | cleanup_handle (handle); | ||
1036 | return GNUNET_NO; | ||
1037 | } | ||
1051 | 1038 | ||
1052 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | ||
1053 | handle->identity_handle = | ||
1054 | GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
1055 | handle->timeout_task = | 1039 | handle->timeout_task = |
1056 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | 1040 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); |
1057 | 1041 | ||
1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1043 | return GNUNET_YES; | ||
1059 | } | 1044 | } |
1060 | 1045 | ||
1061 | 1046 | ||
@@ -1087,6 +1072,8 @@ libgnunet_plugin_rest_namestore_init (void *cls) | |||
1087 | MHD_HTTP_METHOD_PUT, | 1072 | MHD_HTTP_METHOD_PUT, |
1088 | MHD_HTTP_METHOD_DELETE, | 1073 | MHD_HTTP_METHOD_DELETE, |
1089 | MHD_HTTP_METHOD_OPTIONS); | 1074 | MHD_HTTP_METHOD_OPTIONS); |
1075 | ns_handle = GNUNET_NAMESTORE_connect (cfg); | ||
1076 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | ||
1090 | 1077 | ||
1091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n")); | 1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n")); |
1092 | return api; | 1079 | return api; |
@@ -1104,8 +1091,23 @@ libgnunet_plugin_rest_namestore_done (void *cls) | |||
1104 | { | 1091 | { |
1105 | struct GNUNET_REST_Plugin *api = cls; | 1092 | struct GNUNET_REST_Plugin *api = cls; |
1106 | struct Plugin *plugin = api->cls; | 1093 | struct Plugin *plugin = api->cls; |
1094 | struct EgoEntry *ego_entry; | ||
1095 | struct EgoEntry *ego_tmp; | ||
1107 | 1096 | ||
1108 | plugin->cfg = NULL; | 1097 | plugin->cfg = NULL; |
1098 | if (NULL != identity_handle) | ||
1099 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
1100 | if (NULL != ns_handle) | ||
1101 | GNUNET_NAMESTORE_disconnect (ns_handle); | ||
1102 | |||
1103 | for (ego_entry = ego_head; NULL != ego_entry;) | ||
1104 | { | ||
1105 | ego_tmp = ego_entry; | ||
1106 | ego_entry = ego_entry->next; | ||
1107 | GNUNET_free (ego_tmp->identifier); | ||
1108 | GNUNET_free (ego_tmp->keystring); | ||
1109 | GNUNET_free (ego_tmp); | ||
1110 | } | ||
1109 | 1111 | ||
1110 | GNUNET_free (allow_methods); | 1112 | GNUNET_free (allow_methods); |
1111 | GNUNET_free (api); | 1113 | GNUNET_free (api); |
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c index 1ab6d6f75..1d7461b1a 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/peerinfo-tool/plugin_rest_peerinfo.c | |||
@@ -70,7 +70,12 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
70 | /** | 70 | /** |
71 | * HTTP methods allows for this plugin | 71 | * HTTP methods allows for this plugin |
72 | */ | 72 | */ |
73 | static char*allow_methods; | 73 | static char *allow_methods; |
74 | |||
75 | /** | ||
76 | * Handle to PEERINFO | ||
77 | */ | ||
78 | static struct GNUNET_PEERINFO_Handle *peerinfo_handle; | ||
74 | 79 | ||
75 | /** | 80 | /** |
76 | * @brief struct returned by the initialization function of the plugin | 81 | * @brief struct returned by the initialization function of the plugin |
@@ -204,10 +209,6 @@ struct RequestHandle | |||
204 | */ | 209 | */ |
205 | struct GNUNET_PEERINFO_IteratorContext *list_it; | 210 | struct GNUNET_PEERINFO_IteratorContext *list_it; |
206 | 211 | ||
207 | /** | ||
208 | * Handle to PEERINFO | ||
209 | */ | ||
210 | struct GNUNET_PEERINFO_Handle *peerinfo_handle; | ||
211 | 212 | ||
212 | /** | 213 | /** |
213 | * Rest connection | 214 | * Rest connection |
@@ -294,10 +295,10 @@ cleanup_handle (void *cls) | |||
294 | GNUNET_PEERINFO_iterate_cancel (handle->list_it); | 295 | GNUNET_PEERINFO_iterate_cancel (handle->list_it); |
295 | handle->list_it = NULL; | 296 | handle->list_it = NULL; |
296 | } | 297 | } |
297 | if (NULL != handle->peerinfo_handle) | 298 | if (NULL != peerinfo_handle) |
298 | { | 299 | { |
299 | GNUNET_PEERINFO_disconnect (handle->peerinfo_handle); | 300 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
300 | handle->peerinfo_handle = NULL; | 301 | peerinfo_handle = NULL; |
301 | } | 302 | } |
302 | 303 | ||
303 | GNUNET_free (handle); | 304 | GNUNET_free (handle); |
@@ -664,7 +665,7 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
664 | // specific_peer = GNUNET_PEER_resolve2(peer_id); | 665 | // specific_peer = GNUNET_PEER_resolve2(peer_id); |
665 | } | 666 | } |
666 | 667 | ||
667 | handle->list_it = GNUNET_PEERINFO_iterate (handle->peerinfo_handle, | 668 | handle->list_it = GNUNET_PEERINFO_iterate (peerinfo_handle, |
668 | include_friend_only, | 669 | include_friend_only, |
669 | specific_peer, | 670 | specific_peer, |
670 | &peerinfo_list_iteration, | 671 | &peerinfo_list_iteration, |
@@ -699,32 +700,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
699 | 700 | ||
700 | 701 | ||
701 | /** | 702 | /** |
702 | * Handle rest request | ||
703 | * | ||
704 | * @param handle the request handle | ||
705 | */ | ||
706 | static void | ||
707 | init_cont (struct RequestHandle *handle) | ||
708 | { | ||
709 | struct GNUNET_REST_RequestHandlerError err; | ||
710 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
711 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get }, | ||
712 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_PEERINFO, &options_cont }, | ||
713 | GNUNET_REST_HANDLER_END | ||
714 | }; | ||
715 | |||
716 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, | ||
717 | handlers, | ||
718 | &err, | ||
719 | handle)) | ||
720 | { | ||
721 | handle->response_code = err.error_code; | ||
722 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
723 | } | ||
724 | } | ||
725 | |||
726 | |||
727 | /** | ||
728 | * Function processing the REST call | 703 | * Function processing the REST call |
729 | * | 704 | * |
730 | * @param method HTTP method | 705 | * @param method HTTP method |
@@ -735,12 +710,18 @@ init_cont (struct RequestHandle *handle) | |||
735 | * @param proc_cls closure for callback function | 710 | * @param proc_cls closure for callback function |
736 | * @return GNUNET_OK if request accepted | 711 | * @return GNUNET_OK if request accepted |
737 | */ | 712 | */ |
738 | static void | 713 | static enum GNUNET_GenericReturnValue |
739 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 714 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
740 | GNUNET_REST_ResultProcessor proc, | 715 | GNUNET_REST_ResultProcessor proc, |
741 | void *proc_cls) | 716 | void *proc_cls) |
742 | { | 717 | { |
743 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 718 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
719 | struct GNUNET_REST_RequestHandlerError err; | ||
720 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
721 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get }, | ||
722 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_PEERINFO, &options_cont }, | ||
723 | GNUNET_REST_HANDLER_END | ||
724 | }; | ||
744 | 725 | ||
745 | handle->response_code = 0; | 726 | handle->response_code = 0; |
746 | handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 727 | handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
@@ -753,14 +734,20 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
753 | if (handle->url[strlen (handle->url) - 1] == '/') | 734 | if (handle->url[strlen (handle->url) - 1] == '/') |
754 | handle->url[strlen (handle->url) - 1] = '\0'; | 735 | handle->url[strlen (handle->url) - 1] = '\0'; |
755 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
756 | handle->peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 737 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, |
757 | init_cont (handle); | 738 | handlers, |
739 | &err, | ||
740 | handle)) | ||
741 | { | ||
742 | cleanup_handle (handle); | ||
743 | return GNUNET_NO; | ||
744 | } | ||
758 | handle->timeout_task = | 745 | handle->timeout_task = |
759 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 746 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
760 | &do_error, | 747 | &do_error, |
761 | handle); | 748 | handle); |
762 | |||
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
750 | return GNUNET_YES; | ||
764 | } | 751 | } |
765 | 752 | ||
766 | 753 | ||
@@ -792,6 +779,7 @@ libgnunet_plugin_rest_peerinfo_init (void *cls) | |||
792 | MHD_HTTP_METHOD_PUT, | 779 | MHD_HTTP_METHOD_PUT, |
793 | MHD_HTTP_METHOD_DELETE, | 780 | MHD_HTTP_METHOD_DELETE, |
794 | MHD_HTTP_METHOD_OPTIONS); | 781 | MHD_HTTP_METHOD_OPTIONS); |
782 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | ||
795 | 783 | ||
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
797 | _ ("Peerinfo REST API initialized\n")); | 785 | _ ("Peerinfo REST API initialized\n")); |
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index eb602a08f..64782fb72 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c | |||
@@ -249,6 +249,36 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
249 | static char *allow_methods; | 249 | static char *allow_methods; |
250 | 250 | ||
251 | /** | 251 | /** |
252 | * Ego list | ||
253 | */ | ||
254 | static struct EgoEntry *ego_head; | ||
255 | |||
256 | /** | ||
257 | * Ego list | ||
258 | */ | ||
259 | static struct EgoEntry *ego_tail; | ||
260 | |||
261 | /** | ||
262 | * The processing state | ||
263 | */ | ||
264 | static int state; | ||
265 | |||
266 | /** | ||
267 | * Handle to Identity service. | ||
268 | */ | ||
269 | static struct GNUNET_IDENTITY_Handle *identity_handle; | ||
270 | |||
271 | /** | ||
272 | * GNS handle | ||
273 | */ | ||
274 | static struct GNUNET_GNS_Handle *gns_handle; | ||
275 | |||
276 | /** | ||
277 | * Identity Provider | ||
278 | */ | ||
279 | static struct GNUNET_RECLAIM_Handle *idp; | ||
280 | |||
281 | /** | ||
252 | * @brief struct returned by the initialization function of the plugin | 282 | * @brief struct returned by the initialization function of the plugin |
253 | */ | 283 | */ |
254 | struct Plugin | 284 | struct Plugin |
@@ -361,15 +391,6 @@ struct EgoEntry | |||
361 | 391 | ||
362 | struct RequestHandle | 392 | struct RequestHandle |
363 | { | 393 | { |
364 | /** | ||
365 | * Ego list | ||
366 | */ | ||
367 | struct EgoEntry *ego_head; | ||
368 | |||
369 | /** | ||
370 | * Ego list | ||
371 | */ | ||
372 | struct EgoEntry *ego_tail; | ||
373 | 394 | ||
374 | /** | 395 | /** |
375 | * Selected ego | 396 | * Selected ego |
@@ -387,39 +408,14 @@ struct RequestHandle | |||
387 | struct OIDC_Variables *oidc; | 408 | struct OIDC_Variables *oidc; |
388 | 409 | ||
389 | /** | 410 | /** |
390 | * The processing state | ||
391 | */ | ||
392 | int state; | ||
393 | |||
394 | /** | ||
395 | * Handle to Identity service. | ||
396 | */ | ||
397 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
398 | |||
399 | /** | ||
400 | * Rest connection | ||
401 | */ | ||
402 | struct GNUNET_REST_RequestHandle *rest_handle; | ||
403 | |||
404 | /** | ||
405 | * GNS handle | ||
406 | */ | ||
407 | struct GNUNET_GNS_Handle *gns_handle; | ||
408 | |||
409 | /** | ||
410 | * GNS lookup op | 411 | * GNS lookup op |
411 | */ | 412 | */ |
412 | struct GNUNET_GNS_LookupRequest *gns_op; | 413 | struct GNUNET_GNS_LookupRequest *gns_op; |
413 | 414 | ||
414 | /** | 415 | /** |
415 | * Handle to NAMESTORE | 416 | * Rest connection |
416 | */ | ||
417 | struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
418 | |||
419 | /** | ||
420 | * Iterator for NAMESTORE | ||
421 | */ | 417 | */ |
422 | struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it; | 418 | struct GNUNET_REST_RequestHandle *rest_handle; |
423 | 419 | ||
424 | /** | 420 | /** |
425 | * Attribute claim list for id_token | 421 | * Attribute claim list for id_token |
@@ -442,10 +438,6 @@ struct RequestHandle | |||
442 | */ | 438 | */ |
443 | struct GNUNET_IDENTITY_Operation *op; | 439 | struct GNUNET_IDENTITY_Operation *op; |
444 | 440 | ||
445 | /** | ||
446 | * Identity Provider | ||
447 | */ | ||
448 | struct GNUNET_RECLAIM_Handle *idp; | ||
449 | 441 | ||
450 | /** | 442 | /** |
451 | * Idp Operation | 443 | * Idp Operation |
@@ -529,6 +521,7 @@ struct RequestHandle | |||
529 | int response_code; | 521 | int response_code; |
530 | }; | 522 | }; |
531 | 523 | ||
524 | |||
532 | /** | 525 | /** |
533 | * Cleanup lookup handle | 526 | * Cleanup lookup handle |
534 | * @param handle Handle to clean up | 527 | * @param handle Handle to clean up |
@@ -536,13 +529,10 @@ struct RequestHandle | |||
536 | static void | 529 | static void |
537 | cleanup_handle (struct RequestHandle *handle) | 530 | cleanup_handle (struct RequestHandle *handle) |
538 | { | 531 | { |
539 | struct EgoEntry *ego_entry; | ||
540 | 532 | ||
541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
542 | if (NULL != handle->timeout_task) | 534 | if (NULL != handle->timeout_task) |
543 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 535 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
544 | if (NULL != handle->identity_handle) | ||
545 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
546 | if (NULL != handle->attr_it) | 536 | if (NULL != handle->attr_it) |
547 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); | 537 | GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); |
548 | if (NULL != handle->attest_it) | 538 | if (NULL != handle->attest_it) |
@@ -551,8 +541,6 @@ cleanup_handle (struct RequestHandle *handle) | |||
551 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); | 541 | GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); |
552 | if (NULL != handle->idp_op) | 542 | if (NULL != handle->idp_op) |
553 | GNUNET_RECLAIM_cancel (handle->idp_op); | 543 | GNUNET_RECLAIM_cancel (handle->idp_op); |
554 | if (NULL != handle->idp) | ||
555 | GNUNET_RECLAIM_disconnect (handle->idp); | ||
556 | GNUNET_free (handle->url); | 544 | GNUNET_free (handle->url); |
557 | GNUNET_free (handle->tld); | 545 | GNUNET_free (handle->tld); |
558 | GNUNET_free (handle->redirect_prefix); | 546 | GNUNET_free (handle->redirect_prefix); |
@@ -561,11 +549,6 @@ cleanup_handle (struct RequestHandle *handle) | |||
561 | GNUNET_free (handle->edesc); | 549 | GNUNET_free (handle->edesc); |
562 | if (NULL != handle->gns_op) | 550 | if (NULL != handle->gns_op) |
563 | GNUNET_GNS_lookup_cancel (handle->gns_op); | 551 | GNUNET_GNS_lookup_cancel (handle->gns_op); |
564 | if (NULL != handle->gns_handle) | ||
565 | GNUNET_GNS_disconnect (handle->gns_handle); | ||
566 | |||
567 | if (NULL != handle->namestore_handle) | ||
568 | GNUNET_NAMESTORE_disconnect (handle->namestore_handle); | ||
569 | if (NULL != handle->oidc) | 552 | if (NULL != handle->oidc) |
570 | { | 553 | { |
571 | GNUNET_free (handle->oidc->client_id); | 554 | GNUNET_free (handle->oidc->client_id); |
@@ -585,15 +568,6 @@ cleanup_handle (struct RequestHandle *handle) | |||
585 | if (NULL!=handle->attests_list) | 568 | if (NULL!=handle->attests_list) |
586 | GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list); | 569 | GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list); |
587 | 570 | ||
588 | while (NULL != (ego_entry = handle->ego_head)) | ||
589 | { | ||
590 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | ||
591 | handle->ego_tail, | ||
592 | ego_entry); | ||
593 | GNUNET_free (ego_entry->identifier); | ||
594 | GNUNET_free (ego_entry->keystring); | ||
595 | GNUNET_free (ego_entry); | ||
596 | } | ||
597 | GNUNET_free (handle); | 571 | GNUNET_free (handle); |
598 | } | 572 | } |
599 | 573 | ||
@@ -993,7 +967,8 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
993 | handle->redirect_prefix, | 967 | handle->redirect_prefix, |
994 | handle->tld, | 968 | handle->tld, |
995 | handle->redirect_suffix, | 969 | handle->redirect_suffix, |
996 | (NULL == strchr(handle->redirect_suffix, '?') ? "?" : "&"), | 970 | (NULL == strchr (handle->redirect_suffix, '?') ? "?" : |
971 | "&"), | ||
997 | handle->oidc->response_type, | 972 | handle->oidc->response_type, |
998 | code_string, | 973 | code_string, |
999 | handle->oidc->state); | 974 | handle->oidc->state); |
@@ -1003,7 +978,8 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
1003 | GNUNET_asprintf (&redirect_uri, | 978 | GNUNET_asprintf (&redirect_uri, |
1004 | "%s%s%s=%s&state=%s", | 979 | "%s%s%s=%s&state=%s", |
1005 | handle->oidc->redirect_uri, | 980 | handle->oidc->redirect_uri, |
1006 | (NULL == strchr(handle->oidc->redirect_uri, '?') ? "?" : "&"), | 981 | (NULL == strchr (handle->oidc->redirect_uri, '?') ? "?" : |
982 | "&"), | ||
1007 | handle->oidc->response_type, | 983 | handle->oidc->response_type, |
1008 | code_string, | 984 | code_string, |
1009 | handle->oidc->state); | 985 | handle->oidc->state); |
@@ -1082,7 +1058,7 @@ oidc_attest_collect_finished_cb (void *cls) | |||
1082 | handle->attest_it = NULL; | 1058 | handle->attest_it = NULL; |
1083 | merged_list = attribute_list_merge (handle->attr_idtoken_list, | 1059 | merged_list = attribute_list_merge (handle->attr_idtoken_list, |
1084 | handle->attr_userinfo_list); | 1060 | handle->attr_userinfo_list); |
1085 | handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp, | 1061 | handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp, |
1086 | &handle->priv_key, | 1062 | &handle->priv_key, |
1087 | &handle->oidc->client_pkey, | 1063 | &handle->oidc->client_pkey, |
1088 | merged_list, | 1064 | merged_list, |
@@ -1149,7 +1125,7 @@ oidc_attr_collect_finished_cb (void *cls) | |||
1149 | } | 1125 | } |
1150 | handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); | 1126 | handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); |
1151 | handle->attest_it = | 1127 | handle->attest_it = |
1152 | GNUNET_RECLAIM_get_attestations_start (handle->idp, | 1128 | GNUNET_RECLAIM_get_attestations_start (idp, |
1153 | &handle->priv_key, | 1129 | &handle->priv_key, |
1154 | &oidc_iteration_error, | 1130 | &oidc_iteration_error, |
1155 | handle, | 1131 | handle, |
@@ -1315,7 +1291,7 @@ code_redirect (void *cls) | |||
1315 | return; | 1291 | return; |
1316 | } | 1292 | } |
1317 | // iterate over egos and compare their public key | 1293 | // iterate over egos and compare their public key |
1318 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; | 1294 | for (handle->ego_entry = ego_head; NULL != handle->ego_entry; |
1319 | handle->ego_entry = handle->ego_entry->next) | 1295 | handle->ego_entry = handle->ego_entry->next) |
1320 | { | 1296 | { |
1321 | GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey); | 1297 | GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey); |
@@ -1323,13 +1299,12 @@ code_redirect (void *cls) | |||
1323 | { | 1299 | { |
1324 | handle->priv_key = | 1300 | handle->priv_key = |
1325 | *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego); | 1301 | *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego); |
1326 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
1327 | handle->attr_idtoken_list = | 1302 | handle->attr_idtoken_list = |
1328 | GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 1303 | GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
1329 | handle->attr_userinfo_list = | 1304 | handle->attr_userinfo_list = |
1330 | GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 1305 | GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
1331 | handle->attr_it = | 1306 | handle->attr_it = |
1332 | GNUNET_RECLAIM_get_attributes_start (handle->idp, | 1307 | GNUNET_RECLAIM_get_attributes_start (idp, |
1333 | &handle->priv_key, | 1308 | &handle->priv_key, |
1334 | &oidc_iteration_error, | 1309 | &oidc_iteration_error, |
1335 | handle, | 1310 | handle, |
@@ -1474,7 +1449,7 @@ client_redirect (void *cls) | |||
1474 | 1449 | ||
1475 | /* Lookup client redirect uri to verify request */ | 1450 | /* Lookup client redirect uri to verify request */ |
1476 | handle->gns_op = | 1451 | handle->gns_op = |
1477 | GNUNET_GNS_lookup (handle->gns_handle, | 1452 | GNUNET_GNS_lookup (gns_handle, |
1478 | GNUNET_GNS_EMPTY_LABEL_AT, | 1453 | GNUNET_GNS_EMPTY_LABEL_AT, |
1479 | &handle->oidc->client_pkey, | 1454 | &handle->oidc->client_pkey, |
1480 | GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, | 1455 | GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT, |
@@ -1700,14 +1675,14 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1700 | 1675 | ||
1701 | // If we know this identity, translated the corresponding TLD | 1676 | // If we know this identity, translated the corresponding TLD |
1702 | // TODO: We might want to have a reverse lookup functionality for TLDs? | 1677 | // TODO: We might want to have a reverse lookup functionality for TLDs? |
1703 | for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) | 1678 | for (tmp_ego = ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) |
1704 | { | 1679 | { |
1705 | priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); | 1680 | priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); |
1706 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey); | 1681 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey); |
1707 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) | 1682 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) |
1708 | { | 1683 | { |
1709 | handle->tld = GNUNET_strdup (tmp_ego->identifier); | 1684 | handle->tld = GNUNET_strdup (tmp_ego->identifier); |
1710 | handle->ego_entry = handle->ego_tail; | 1685 | handle->ego_entry = ego_tail; |
1711 | } | 1686 | } |
1712 | } | 1687 | } |
1713 | handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY); | 1688 | handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY); |
@@ -1790,6 +1765,7 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1790 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 1765 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); |
1791 | } | 1766 | } |
1792 | 1767 | ||
1768 | |||
1793 | static int | 1769 | static int |
1794 | parse_credentials_basic_auth (struct RequestHandle *handle, | 1770 | parse_credentials_basic_auth (struct RequestHandle *handle, |
1795 | char **client_id, | 1771 | char **client_id, |
@@ -1847,8 +1823,8 @@ parse_credentials_basic_auth (struct RequestHandle *handle, | |||
1847 | 1823 | ||
1848 | static int | 1824 | static int |
1849 | parse_credentials_post_body (struct RequestHandle *handle, | 1825 | parse_credentials_post_body (struct RequestHandle *handle, |
1850 | char **client_id, | 1826 | char **client_id, |
1851 | char **client_secret) | 1827 | char **client_secret) |
1852 | { | 1828 | { |
1853 | struct GNUNET_HashCode cache_key; | 1829 | struct GNUNET_HashCode cache_key; |
1854 | char *client_id_tmp; | 1830 | char *client_id_tmp; |
@@ -1861,8 +1837,9 @@ parse_credentials_post_body (struct RequestHandle *handle, | |||
1861 | ->url_param_map, | 1837 | ->url_param_map, |
1862 | &cache_key)) | 1838 | &cache_key)) |
1863 | return GNUNET_SYSERR; | 1839 | return GNUNET_SYSERR; |
1864 | client_id_tmp = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, | 1840 | client_id_tmp = GNUNET_CONTAINER_multihashmap_get ( |
1865 | &cache_key); | 1841 | handle->rest_handle->url_param_map, |
1842 | &cache_key); | ||
1866 | if (NULL == client_id_tmp) | 1843 | if (NULL == client_id_tmp) |
1867 | return GNUNET_SYSERR; | 1844 | return GNUNET_SYSERR; |
1868 | *client_id = strdup (client_id_tmp); | 1845 | *client_id = strdup (client_id_tmp); |
@@ -1896,13 +1873,16 @@ check_authorization (struct RequestHandle *handle, | |||
1896 | { | 1873 | { |
1897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1898 | "Received client credentials in HTTP AuthZ header\n"); | 1875 | "Received client credentials in HTTP AuthZ header\n"); |
1899 | } else if (GNUNET_OK == parse_credentials_post_body (handle, | 1876 | } |
1900 | &received_cid, | 1877 | else if (GNUNET_OK == parse_credentials_post_body (handle, |
1901 | &received_cpw)) | 1878 | &received_cid, |
1879 | &received_cpw)) | ||
1902 | { | 1880 | { |
1903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1881 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1904 | "Received client credentials in POST body\n"); | 1882 | "Received client credentials in POST body\n"); |
1905 | } else { | 1883 | } |
1884 | else | ||
1885 | { | ||
1906 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1886 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); |
1907 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1887 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
1908 | return GNUNET_SYSERR; | 1888 | return GNUNET_SYSERR; |
@@ -1931,7 +1911,7 @@ check_authorization (struct RequestHandle *handle, | |||
1931 | return GNUNET_SYSERR; | 1911 | return GNUNET_SYSERR; |
1932 | } | 1912 | } |
1933 | // check client_id | 1913 | // check client_id |
1934 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; | 1914 | for (handle->ego_entry = ego_head; NULL != handle->ego_entry; |
1935 | handle->ego_entry = handle->ego_entry->next) | 1915 | handle->ego_entry = handle->ego_entry->next) |
1936 | { | 1916 | { |
1937 | if (0 == strcmp (handle->ego_entry->keystring, received_cid)) | 1917 | if (0 == strcmp (handle->ego_entry->keystring, received_cid)) |
@@ -1963,7 +1943,7 @@ find_ego (struct RequestHandle *handle, | |||
1963 | struct EgoEntry *ego_entry; | 1943 | struct EgoEntry *ego_entry; |
1964 | struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; | 1944 | struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; |
1965 | 1945 | ||
1966 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1946 | for (ego_entry = ego_head; NULL != ego_entry; |
1967 | ego_entry = ego_entry->next) | 1947 | ego_entry = ego_entry->next) |
1968 | { | 1948 | { |
1969 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key); | 1949 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key); |
@@ -2321,14 +2301,13 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
2321 | return; | 2301 | return; |
2322 | } | 2302 | } |
2323 | 2303 | ||
2324 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
2325 | handle->oidc->response = json_object (); | 2304 | handle->oidc->response = json_object (); |
2326 | json_object_set_new (handle->oidc->response, | 2305 | json_object_set_new (handle->oidc->response, |
2327 | "sub", | 2306 | "sub", |
2328 | json_string (iss_ego->keystring)); | 2307 | json_string (iss_ego->keystring)); |
2329 | privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego); | 2308 | privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego); |
2330 | 2309 | ||
2331 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, | 2310 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp, |
2332 | privkey, | 2311 | privkey, |
2333 | ticket, | 2312 | ticket, |
2334 | consume_ticket, | 2313 | consume_ticket, |
@@ -2338,36 +2317,6 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
2338 | 2317 | ||
2339 | 2318 | ||
2340 | /** | 2319 | /** |
2341 | * Handle rest request | ||
2342 | * | ||
2343 | * @param handle the request handle | ||
2344 | */ | ||
2345 | static void | ||
2346 | init_cont (struct RequestHandle *handle) | ||
2347 | { | ||
2348 | struct GNUNET_REST_RequestHandlerError err; | ||
2349 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
2350 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, | ||
2351 | { MHD_HTTP_METHOD_POST, | ||
2352 | GNUNET_REST_API_NS_AUTHORIZE, | ||
2353 | &authorize_endpoint }, // url-encoded | ||
2354 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont }, | ||
2355 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint }, | ||
2356 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, | ||
2357 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, | ||
2358 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont }, | ||
2359 | GNUNET_REST_HANDLER_END }; | ||
2360 | |||
2361 | if (GNUNET_NO == | ||
2362 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | ||
2363 | { | ||
2364 | handle->response_code = err.error_code; | ||
2365 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
2366 | } | ||
2367 | } | ||
2368 | |||
2369 | |||
2370 | /** | ||
2371 | * If listing is enabled, prints information about the egos. | 2320 | * If listing is enabled, prints information about the egos. |
2372 | * | 2321 | * |
2373 | * This function is initially called for all egos and then again | 2322 | * This function is initially called for all egos and then again |
@@ -2406,18 +2355,16 @@ list_ego (void *cls, | |||
2406 | void **ctx, | 2355 | void **ctx, |
2407 | const char *identifier) | 2356 | const char *identifier) |
2408 | { | 2357 | { |
2409 | struct RequestHandle *handle = cls; | ||
2410 | struct EgoEntry *ego_entry; | 2358 | struct EgoEntry *ego_entry; |
2411 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 2359 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
2412 | 2360 | ||
2413 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 2361 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
2414 | { | 2362 | { |
2415 | handle->state = ID_REST_STATE_POST_INIT; | 2363 | state = ID_REST_STATE_POST_INIT; |
2416 | init_cont (handle); | ||
2417 | return; | 2364 | return; |
2418 | } | 2365 | } |
2419 | GNUNET_assert (NULL != ego); | 2366 | GNUNET_assert (NULL != ego); |
2420 | if (ID_REST_STATE_INIT == handle->state) | 2367 | if (ID_REST_STATE_INIT == state) |
2421 | 2368 | ||
2422 | { | 2369 | { |
2423 | ego_entry = GNUNET_new (struct EgoEntry); | 2370 | ego_entry = GNUNET_new (struct EgoEntry); |
@@ -2425,15 +2372,15 @@ list_ego (void *cls, | |||
2425 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2372 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
2426 | ego_entry->ego = ego; | 2373 | ego_entry->ego = ego; |
2427 | ego_entry->identifier = GNUNET_strdup (identifier); | 2374 | ego_entry->identifier = GNUNET_strdup (identifier); |
2428 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 2375 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
2429 | handle->ego_tail, | 2376 | ego_tail, |
2430 | ego_entry); | 2377 | ego_entry); |
2431 | return; | 2378 | return; |
2432 | } | 2379 | } |
2433 | /* Ego renamed or added */ | 2380 | /* Ego renamed or added */ |
2434 | if (identifier != NULL) | 2381 | if (identifier != NULL) |
2435 | { | 2382 | { |
2436 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 2383 | for (ego_entry = ego_head; NULL != ego_entry; |
2437 | ego_entry = ego_entry->next) | 2384 | ego_entry = ego_entry->next) |
2438 | { | 2385 | { |
2439 | if (ego_entry->ego == ego) | 2386 | if (ego_entry->ego == ego) |
@@ -2452,15 +2399,15 @@ list_ego (void *cls, | |||
2452 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2399 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
2453 | ego_entry->ego = ego; | 2400 | ego_entry->ego = ego; |
2454 | ego_entry->identifier = GNUNET_strdup (identifier); | 2401 | ego_entry->identifier = GNUNET_strdup (identifier); |
2455 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 2402 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
2456 | handle->ego_tail, | 2403 | ego_tail, |
2457 | ego_entry); | 2404 | ego_entry); |
2458 | } | 2405 | } |
2459 | } | 2406 | } |
2460 | else | 2407 | else |
2461 | { | 2408 | { |
2462 | /* Delete */ | 2409 | /* Delete */ |
2463 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 2410 | for (ego_entry = ego_head; NULL != ego_entry; |
2464 | ego_entry = ego_entry->next) | 2411 | ego_entry = ego_entry->next) |
2465 | { | 2412 | { |
2466 | if (ego_entry->ego == ego) | 2413 | if (ego_entry->ego == ego) |
@@ -2469,8 +2416,8 @@ list_ego (void *cls, | |||
2469 | if (NULL == ego_entry) | 2416 | if (NULL == ego_entry) |
2470 | return; /* Not found */ | 2417 | return; /* Not found */ |
2471 | 2418 | ||
2472 | GNUNET_CONTAINER_DLL_remove (handle->ego_head, | 2419 | GNUNET_CONTAINER_DLL_remove (ego_head, |
2473 | handle->ego_tail, | 2420 | ego_tail, |
2474 | ego_entry); | 2421 | ego_entry); |
2475 | GNUNET_free (ego_entry->identifier); | 2422 | GNUNET_free (ego_entry->identifier); |
2476 | GNUNET_free (ego_entry->keystring); | 2423 | GNUNET_free (ego_entry->keystring); |
@@ -2480,12 +2427,23 @@ list_ego (void *cls, | |||
2480 | } | 2427 | } |
2481 | 2428 | ||
2482 | 2429 | ||
2483 | static void | 2430 | static enum GNUNET_GenericReturnValue |
2484 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 2431 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
2485 | GNUNET_REST_ResultProcessor proc, | 2432 | GNUNET_REST_ResultProcessor proc, |
2486 | void *proc_cls) | 2433 | void *proc_cls) |
2487 | { | 2434 | { |
2488 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 2435 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
2436 | struct GNUNET_REST_RequestHandlerError err; | ||
2437 | static const struct GNUNET_REST_RequestHandler handlers[] = | ||
2438 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, | ||
2439 | { MHD_HTTP_METHOD_POST, | ||
2440 | GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, // url-encoded | ||
2441 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont }, | ||
2442 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint }, | ||
2443 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, | ||
2444 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint }, | ||
2445 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont }, | ||
2446 | GNUNET_REST_HANDLER_END }; | ||
2489 | 2447 | ||
2490 | handle->oidc = GNUNET_new (struct OIDC_Variables); | 2448 | handle->oidc = GNUNET_new (struct OIDC_Variables); |
2491 | if (NULL == OIDC_cookie_jar_map) | 2449 | if (NULL == OIDC_cookie_jar_map) |
@@ -2495,19 +2453,17 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
2495 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 2453 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
2496 | handle->proc_cls = proc_cls; | 2454 | handle->proc_cls = proc_cls; |
2497 | handle->proc = proc; | 2455 | handle->proc = proc; |
2498 | handle->state = ID_REST_STATE_INIT; | ||
2499 | handle->rest_handle = rest_handle; | 2456 | handle->rest_handle = rest_handle; |
2500 | |||
2501 | handle->url = GNUNET_strdup (rest_handle->url); | 2457 | handle->url = GNUNET_strdup (rest_handle->url); |
2502 | if (handle->url[strlen (handle->url) - 1] == '/') | 2458 | if (handle->url[strlen (handle->url) - 1] == '/') |
2503 | handle->url[strlen (handle->url) - 1] = '\0'; | 2459 | handle->url[strlen (handle->url) - 1] = '\0'; |
2504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 2460 | if (GNUNET_NO == |
2505 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); | 2461 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
2506 | handle->gns_handle = GNUNET_GNS_connect (cfg); | 2462 | return GNUNET_NO; |
2507 | handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg); | 2463 | |
2508 | handle->timeout_task = | 2464 | handle->timeout_task = |
2509 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | 2465 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); |
2510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 2466 | return GNUNET_YES; |
2511 | } | 2467 | } |
2512 | 2468 | ||
2513 | 2469 | ||
@@ -2532,6 +2488,11 @@ libgnunet_plugin_rest_openid_connect_init (void *cls) | |||
2532 | api->cls = &plugin; | 2488 | api->cls = &plugin; |
2533 | api->name = GNUNET_REST_API_NS_OIDC; | 2489 | api->name = GNUNET_REST_API_NS_OIDC; |
2534 | api->process_request = &rest_identity_process_request; | 2490 | api->process_request = &rest_identity_process_request; |
2491 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | ||
2492 | gns_handle = GNUNET_GNS_connect (cfg); | ||
2493 | idp = GNUNET_RECLAIM_connect (cfg); | ||
2494 | |||
2495 | state = ID_REST_STATE_INIT; | ||
2535 | GNUNET_asprintf (&allow_methods, | 2496 | GNUNET_asprintf (&allow_methods, |
2536 | "%s, %s, %s, %s, %s", | 2497 | "%s, %s, %s, %s, %s", |
2537 | MHD_HTTP_METHOD_GET, | 2498 | MHD_HTTP_METHOD_GET, |
@@ -2557,6 +2518,7 @@ libgnunet_plugin_rest_openid_connect_done (void *cls) | |||
2557 | { | 2518 | { |
2558 | struct GNUNET_REST_Plugin *api = cls; | 2519 | struct GNUNET_REST_Plugin *api = cls; |
2559 | struct Plugin *plugin = api->cls; | 2520 | struct Plugin *plugin = api->cls; |
2521 | struct EgoEntry *ego_entry; | ||
2560 | 2522 | ||
2561 | plugin->cfg = NULL; | 2523 | plugin->cfg = NULL; |
2562 | 2524 | ||
@@ -2573,6 +2535,21 @@ libgnunet_plugin_rest_openid_connect_done (void *cls) | |||
2573 | 2535 | ||
2574 | GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it); | 2536 | GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it); |
2575 | GNUNET_free (allow_methods); | 2537 | GNUNET_free (allow_methods); |
2538 | if (NULL != gns_handle) | ||
2539 | GNUNET_GNS_disconnect (gns_handle); | ||
2540 | if (NULL != identity_handle) | ||
2541 | GNUNET_IDENTITY_disconnect (identity_handle); | ||
2542 | if (NULL != idp) | ||
2543 | GNUNET_RECLAIM_disconnect (idp); | ||
2544 | while (NULL != (ego_entry = ego_head)) | ||
2545 | { | ||
2546 | GNUNET_CONTAINER_DLL_remove (ego_head, | ||
2547 | ego_tail, | ||
2548 | ego_entry); | ||
2549 | GNUNET_free (ego_entry->identifier); | ||
2550 | GNUNET_free (ego_entry->keystring); | ||
2551 | GNUNET_free (ego_entry); | ||
2552 | } | ||
2576 | GNUNET_free (api); | 2553 | GNUNET_free (api); |
2577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2578 | "OpenID Connect REST plugin is finished\n"); | 2555 | "OpenID Connect REST plugin is finished\n"); |
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; | |||
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 | ||
@@ -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 | */ | ||
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. | 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 | ||
1422 | static void | 1388 | static enum GNUNET_GenericReturnValue |
1423 | rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1389 | rest_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); |
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 519a27515..44d4f345e 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -115,11 +115,6 @@ static struct MHD_Response *failure_response; | |||
115 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 115 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Map of loaded plugins. | ||
119 | */ | ||
120 | static struct GNUNET_CONTAINER_MultiHashMap *plugin_map; | ||
121 | |||
122 | /** | ||
123 | * Echo request Origin in CORS | 118 | * Echo request Origin in CORS |
124 | */ | 119 | */ |
125 | static int echo_origin; | 120 | static int echo_origin; |
@@ -140,6 +135,38 @@ static char *allow_headers; | |||
140 | static char *allow_credentials; | 135 | static char *allow_credentials; |
141 | 136 | ||
142 | /** | 137 | /** |
138 | * Plugin list head | ||
139 | */ | ||
140 | static struct PluginListEntry *plugins_head; | ||
141 | |||
142 | /** | ||
143 | * Plugin list tail | ||
144 | */ | ||
145 | static struct PluginListEntry *plugins_tail; | ||
146 | |||
147 | /** | ||
148 | * A plugin list entry | ||
149 | */ | ||
150 | struct PluginListEntry | ||
151 | { | ||
152 | /* DLL */ | ||
153 | struct PluginListEntry *next; | ||
154 | |||
155 | /* DLL */ | ||
156 | struct PluginListEntry *prev; | ||
157 | |||
158 | /** | ||
159 | * libname (to cleanup) | ||
160 | */ | ||
161 | char *libname; | ||
162 | |||
163 | /** | ||
164 | * The plugin | ||
165 | */ | ||
166 | struct GNUNET_REST_Plugin *plugin; | ||
167 | }; | ||
168 | |||
169 | /** | ||
143 | * MHD Connection handle | 170 | * MHD Connection handle |
144 | */ | 171 | */ |
145 | struct MhdConnectionHandle | 172 | struct MhdConnectionHandle |
@@ -148,8 +175,6 @@ struct MhdConnectionHandle | |||
148 | 175 | ||
149 | struct MHD_Response *response; | 176 | struct MHD_Response *response; |
150 | 177 | ||
151 | struct GNUNET_REST_Plugin *plugin; | ||
152 | |||
153 | struct GNUNET_REST_RequestHandle *data_handle; | 178 | struct GNUNET_REST_RequestHandle *data_handle; |
154 | 179 | ||
155 | struct MHD_PostProcessor *pp; | 180 | struct MHD_PostProcessor *pp; |
@@ -322,15 +347,15 @@ post_data_iter (void *cls, | |||
322 | 347 | ||
323 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); | 348 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); |
324 | val = GNUNET_CONTAINER_multihashmap_get (handle->url_param_map, | 349 | val = GNUNET_CONTAINER_multihashmap_get (handle->url_param_map, |
325 | &hkey); | 350 | &hkey); |
326 | if (NULL == val) | 351 | if (NULL == val) |
327 | { | 352 | { |
328 | val = GNUNET_malloc (65536); | 353 | val = GNUNET_malloc (65536); |
329 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( | 354 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
330 | handle->url_param_map, | 355 | handle->url_param_map, |
331 | &hkey, | 356 | &hkey, |
332 | val, | 357 | val, |
333 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 358 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
334 | { | 359 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
336 | "Could not add url param '%s'\n", | 361 | "Could not add url param '%s'\n", |
@@ -378,39 +403,21 @@ create_response (void *cls, | |||
378 | size_t *upload_data_size, | 403 | size_t *upload_data_size, |
379 | void **con_cls) | 404 | void **con_cls) |
380 | { | 405 | { |
381 | char *plugin_name; | ||
382 | char *origin; | 406 | char *origin; |
383 | struct GNUNET_HashCode key; | 407 | struct GNUNET_HashCode key; |
384 | struct MhdConnectionHandle *con_handle; | 408 | struct MhdConnectionHandle *con_handle; |
385 | struct GNUNET_REST_RequestHandle *rest_conndata_handle; | 409 | struct GNUNET_REST_RequestHandle *rest_conndata_handle; |
410 | struct PluginListEntry *ple; | ||
386 | 411 | ||
387 | con_handle = *con_cls; | 412 | con_handle = *con_cls; |
388 | 413 | ||
389 | if (NULL == *con_cls) | 414 | if (NULL == *con_cls) |
390 | { | 415 | { |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New connection %s\n", url); | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New connection %s\n", url); |
392 | char tmp_url[strlen (url) + 1]; | ||
393 | strcpy (tmp_url, url); | ||
394 | con_handle = GNUNET_new (struct MhdConnectionHandle); | 417 | con_handle = GNUNET_new (struct MhdConnectionHandle); |
395 | con_handle->con = con; | 418 | con_handle->con = con; |
396 | con_handle->state = GN_REST_STATE_INIT; | 419 | con_handle->state = GN_REST_STATE_INIT; |
397 | *con_cls = con_handle; | 420 | *con_cls = con_handle; |
398 | |||
399 | plugin_name = strtok (tmp_url, "/"); | ||
400 | |||
401 | if (NULL != plugin_name) | ||
402 | { | ||
403 | GNUNET_CRYPTO_hash (plugin_name, strlen (plugin_name), &key); | ||
404 | |||
405 | con_handle->plugin = GNUNET_CONTAINER_multihashmap_get (plugin_map, &key); | ||
406 | } | ||
407 | if (NULL == con_handle->plugin) | ||
408 | { | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing response with MHD\n"); | ||
410 | GNUNET_free (con_handle); | ||
411 | return MHD_queue_response (con, MHD_HTTP_NOT_FOUND, failure_response); | ||
412 | } | ||
413 | |||
414 | return MHD_YES; | 421 | return MHD_YES; |
415 | } | 422 | } |
416 | if (GN_REST_STATE_INIT == con_handle->state) | 423 | if (GN_REST_STATE_INIT == con_handle->state) |
@@ -445,9 +452,18 @@ create_response (void *cls, | |||
445 | MHD_destroy_post_processor (con_handle->pp); | 452 | MHD_destroy_post_processor (con_handle->pp); |
446 | 453 | ||
447 | con_handle->state = GN_REST_STATE_PROCESSING; | 454 | con_handle->state = GN_REST_STATE_PROCESSING; |
448 | con_handle->plugin->process_request (rest_conndata_handle, | 455 | for (ple = plugins_head; NULL != ple; ple = ple->next) |
449 | &plugin_callback, | 456 | { |
450 | con_handle); | 457 | if (GNUNET_YES == ple->plugin->process_request (rest_conndata_handle, |
458 | &plugin_callback, | ||
459 | con_handle)) | ||
460 | break; /* Request handled */ | ||
461 | } | ||
462 | if (NULL == ple) | ||
463 | { | ||
464 | /** Request not handled **/ | ||
465 | MHD_queue_response (con, MHD_HTTP_NOT_FOUND, failure_response); | ||
466 | } | ||
451 | *upload_data_size = 0; | 467 | *upload_data_size = 0; |
452 | run_mhd_now (); | 468 | run_mhd_now (); |
453 | return MHD_YES; | 469 | return MHD_YES; |
@@ -732,6 +748,18 @@ do_accept (void *cls) | |||
732 | static void | 748 | static void |
733 | do_shutdown (void *cls) | 749 | do_shutdown (void *cls) |
734 | { | 750 | { |
751 | struct PluginListEntry *ple; | ||
752 | |||
753 | while (NULL != plugins_head) | ||
754 | { | ||
755 | ple = plugins_head; | ||
756 | GNUNET_CONTAINER_DLL_remove (plugins_head, | ||
757 | plugins_tail, | ||
758 | ple); | ||
759 | GNUNET_PLUGIN_unload (ple->libname, NULL); | ||
760 | GNUNET_free (ple->libname); | ||
761 | GNUNET_free (ple); | ||
762 | } | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); | 763 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); |
736 | kill_httpd (); | 764 | kill_httpd (); |
737 | GNUNET_free (allow_credentials); | 765 | GNUNET_free (allow_credentials); |
@@ -820,7 +848,7 @@ static void | |||
820 | load_plugin (void *cls, const char *libname, void *lib_ret) | 848 | load_plugin (void *cls, const char *libname, void *lib_ret) |
821 | { | 849 | { |
822 | struct GNUNET_REST_Plugin *plugin = lib_ret; | 850 | struct GNUNET_REST_Plugin *plugin = lib_ret; |
823 | struct GNUNET_HashCode key; | 851 | struct PluginListEntry *ple; |
824 | 852 | ||
825 | if (NULL == lib_ret) | 853 | if (NULL == lib_ret) |
826 | { | 854 | { |
@@ -831,18 +859,12 @@ load_plugin (void *cls, const char *libname, void *lib_ret) | |||
831 | } | 859 | } |
832 | GNUNET_assert (1 < strlen (plugin->name)); | 860 | GNUNET_assert (1 < strlen (plugin->name)); |
833 | GNUNET_assert ('/' == *plugin->name); | 861 | GNUNET_assert ('/' == *plugin->name); |
834 | GNUNET_CRYPTO_hash (plugin->name + 1, strlen (plugin->name + 1), &key); | 862 | ple = GNUNET_new (struct PluginListEntry); |
835 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( | 863 | ple->libname = GNUNET_strdup (libname); |
836 | plugin_map, | 864 | ple->plugin = plugin; |
837 | &key, | 865 | GNUNET_CONTAINER_DLL_insert (plugins_head, |
838 | plugin, | 866 | plugins_tail, |
839 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 867 | ple); |
840 | { | ||
841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
842 | "Could not load add plugin `%s'\n", | ||
843 | libname); | ||
844 | return; | ||
845 | } | ||
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded plugin `%s'\n", libname); | 868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded plugin `%s'\n", libname); |
847 | } | 869 | } |
848 | 870 | ||
@@ -864,8 +886,8 @@ run (void *cls, | |||
864 | char *addr_str; | 886 | char *addr_str; |
865 | 887 | ||
866 | cfg = c; | 888 | cfg = c; |
867 | plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 889 | plugins_head = NULL; |
868 | 890 | plugins_tail = NULL; | |
869 | /* Get port to bind to */ | 891 | /* Get port to bind to */ |
870 | if (GNUNET_OK != | 892 | if (GNUNET_OK != |
871 | GNUNET_CONFIGURATION_get_value_number (cfg, "rest", "HTTP_PORT", &port)) | 893 | GNUNET_CONFIGURATION_get_value_number (cfg, "rest", "HTTP_PORT", &port)) |
diff --git a/src/rest/plugin_rest_config.c b/src/rest/plugin_rest_config.c index 43dea1b9f..d9ae57acd 100644 --- a/src/rest/plugin_rest_config.c +++ b/src/rest/plugin_rest_config.c | |||
@@ -347,7 +347,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
347 | * @param proc_cls closure for @a proc | 347 | * @param proc_cls closure for @a proc |
348 | * @return #GNUNET_OK if request accepted | 348 | * @return #GNUNET_OK if request accepted |
349 | */ | 349 | */ |
350 | static void | 350 | static enum GNUNET_GenericReturnValue |
351 | rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | 351 | rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, |
352 | GNUNET_REST_ResultProcessor proc, | 352 | GNUNET_REST_ResultProcessor proc, |
353 | void *proc_cls) | 353 | void *proc_cls) |
@@ -371,9 +371,10 @@ rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | |||
371 | if (GNUNET_NO == | 371 | if (GNUNET_NO == |
372 | GNUNET_REST_handle_request (conndata_handle, handlers, &err, handle)) | 372 | GNUNET_REST_handle_request (conndata_handle, handlers, &err, handle)) |
373 | { | 373 | { |
374 | handle->response_code = err.error_code; | 374 | cleanup_handle (handle); |
375 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 375 | return GNUNET_NO; |
376 | } | 376 | } |
377 | return GNUNET_YES; | ||
377 | } | 378 | } |
378 | 379 | ||
379 | 380 | ||
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c index e601e505e..1649da3bb 100644 --- a/src/rest/plugin_rest_copying.c +++ b/src/rest/plugin_rest_copying.c | |||
@@ -82,24 +82,6 @@ cleanup_handle (struct RequestHandle *handle) | |||
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Task run on shutdown. Cleans up everything. | ||
86 | * | ||
87 | * @param cls unused | ||
88 | * @param tc scheduler context | ||
89 | */ | ||
90 | static void | ||
91 | do_error (void *cls) | ||
92 | { | ||
93 | struct RequestHandle *handle = cls; | ||
94 | struct MHD_Response *resp; | ||
95 | |||
96 | resp = GNUNET_REST_create_response (NULL); | ||
97 | handle->proc (handle->proc_cls, resp, handle->response_code); | ||
98 | cleanup_handle (handle); | ||
99 | } | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Handle rest request | 85 | * Handle rest request |
104 | * | 86 | * |
105 | * @param handle the lookup handle | 87 | * @param handle the lookup handle |
@@ -155,7 +137,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
155 | * @param proc_cls closure for @a proc | 137 | * @param proc_cls closure for @a proc |
156 | * @return #GNUNET_OK if request accepted | 138 | * @return #GNUNET_OK if request accepted |
157 | */ | 139 | */ |
158 | static void | 140 | static enum GNUNET_GenericReturnValue |
159 | rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | 141 | rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, |
160 | GNUNET_REST_ResultProcessor proc, | 142 | GNUNET_REST_ResultProcessor proc, |
161 | void *proc_cls) | 143 | void *proc_cls) |
@@ -172,14 +154,10 @@ rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | |||
172 | handle->proc = proc; | 154 | handle->proc = proc; |
173 | handle->rest_handle = conndata_handle; | 155 | handle->rest_handle = conndata_handle; |
174 | 156 | ||
175 | if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, | 157 | return GNUNET_REST_handle_request (conndata_handle, |
176 | handlers, | 158 | handlers, |
177 | &err, | 159 | &err, |
178 | handle)) | 160 | handle); |
179 | { | ||
180 | handle->response_code = err.error_code; | ||
181 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
182 | } | ||
183 | } | 161 | } |
184 | 162 | ||
185 | 163 | ||