diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-13 10:44:27 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-13 10:44:27 +0000 |
commit | 8aa21ee7de6c4a6cb9c1e132ab4218d3d10e0e30 (patch) | |
tree | 2cfa38c692d279f70ac979a8069976706e60ef21 /src/identity/plugin_rest_identity.c | |
parent | 74f9b73e5592424165236164fbb8e65d03399614 (diff) | |
download | gnunet-8aa21ee7de6c4a6cb9c1e132ab4218d3d10e0e30.tar.gz gnunet-8aa21ee7de6c4a6cb9c1e132ab4218d3d10e0e30.zip |
-fixes, add set ego for service
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 1d9c8305d..3c5c6946e 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -38,6 +38,8 @@ | |||
38 | 38 | ||
39 | #define ID_REST_STATE_POST_INIT 1 | 39 | #define ID_REST_STATE_POST_INIT 1 |
40 | 40 | ||
41 | #define URL_PARAM_SUBSYS "service" | ||
42 | |||
41 | /** | 43 | /** |
42 | * @brief struct returned by the initialization function of the plugin | 44 | * @brief struct returned by the initialization function of the plugin |
43 | */ | 45 | */ |
@@ -87,6 +89,8 @@ struct RequestHandle | |||
87 | * Ego list | 89 | * Ego list |
88 | */ | 90 | */ |
89 | struct EgoEntry *ego_tail; | 91 | struct EgoEntry *ego_tail; |
92 | |||
93 | struct RestConnectionDataHandle *conndata_handle; | ||
90 | 94 | ||
91 | /** | 95 | /** |
92 | * The processing state | 96 | * The processing state |
@@ -208,15 +212,55 @@ do_error (void *cls, | |||
208 | cleanup_handle (handle); | 212 | cleanup_handle (handle); |
209 | } | 213 | } |
210 | 214 | ||
215 | void | ||
216 | get_ego_for_subsys (void *cls, | ||
217 | struct GNUNET_IDENTITY_Ego *ego, | ||
218 | void **ctx, | ||
219 | const char *name) | ||
220 | { | ||
221 | struct RequestHandle *handle = cls; | ||
222 | struct EgoEntry *ego_entry; | ||
223 | char *result_str; | ||
224 | char *keystring; | ||
225 | json_t *ego_json; | ||
226 | json_t *ego_arr; | ||
227 | |||
228 | ego_arr = json_array (); | ||
211 | 229 | ||
230 | //Return all egos | ||
231 | for (ego_entry = handle->ego_head; | ||
232 | NULL != ego_entry; | ||
233 | ego_entry = ego_entry->next) | ||
234 | { | ||
235 | if ( (NULL != name) && (0 != strcmp (name, ego_entry->identifier)) ) | ||
236 | continue; | ||
237 | if (NULL == name) | ||
238 | continue; | ||
239 | ego_json = json_object (); | ||
240 | keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&ego_entry->pk); | ||
241 | json_object_set_new (ego_json, "identity", json_string (ego_entry->identifier)); | ||
242 | json_object_set_new (ego_json, "key", json_string (keystring)); | ||
243 | json_array_append (ego_arr, ego_json); | ||
244 | json_decref (ego_json); | ||
245 | GNUNET_free (keystring); | ||
246 | } | ||
247 | result_str = json_dumps (ego_arr, JSON_COMPACT); | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | ||
249 | json_decref (ego_arr); | ||
250 | handle->proc (handle->proc_cls, result_str, strlen (result_str), GNUNET_OK); | ||
251 | GNUNET_free (result_str); | ||
252 | cleanup_handle (handle); | ||
253 | } | ||
212 | 254 | ||
213 | void | 255 | void |
214 | ego_info_response (struct RequestHandle *handle) | 256 | ego_info_response (struct RequestHandle *handle) |
215 | { | 257 | { |
216 | const char* egoname; | 258 | const char *egoname; |
217 | char* keystring; | 259 | char *keystring; |
218 | char* result_str; | 260 | char *result_str; |
261 | char *subsys_val; | ||
219 | struct EgoEntry *ego_entry; | 262 | struct EgoEntry *ego_entry; |
263 | struct GNUNET_HashCode key; | ||
220 | json_t *ego_arr; | 264 | json_t *ego_arr; |
221 | json_t *ego_json; | 265 | json_t *ego_json; |
222 | 266 | ||
@@ -227,6 +271,28 @@ ego_info_response (struct RequestHandle *handle) | |||
227 | GNUNET_break (0); | 271 | GNUNET_break (0); |
228 | return; | 272 | return; |
229 | } | 273 | } |
274 | |||
275 | if ( (strlen (EGO_NAMESPACE) + 1 >= strlen (handle->url) )) { | ||
276 | GNUNET_CRYPTO_hash (URL_PARAM_SUBSYS, strlen (URL_PARAM_SUBSYS), &key); | ||
277 | if ( GNUNET_YES == | ||
278 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | ||
279 | &key) ) | ||
280 | { | ||
281 | subsys_val = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | ||
282 | &key); | ||
283 | if (NULL != subsys_val) | ||
284 | { | ||
285 | GNUNET_asprintf (&handle->subsys, "%s", subsys_val); | ||
286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking for %s's ego\n", subsys_val); | ||
287 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
288 | handle->subsys, | ||
289 | &get_ego_for_subsys, | ||
290 | handle); | ||
291 | return; | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | |||
230 | ego_arr = json_array (); | 296 | ego_arr = json_array (); |
231 | 297 | ||
232 | egoname = &handle->url[strlen (EGO_NAMESPACE)]; | 298 | egoname = &handle->url[strlen (EGO_NAMESPACE)]; |
@@ -237,7 +303,7 @@ ego_info_response (struct RequestHandle *handle) | |||
237 | } | 303 | } |
238 | 304 | ||
239 | //Return all egos | 305 | //Return all egos |
240 | for (ego_entry = handle->ego_head; | 306 | for (ego_entry = handle->ego_head; |
241 | NULL != ego_entry; | 307 | NULL != ego_entry; |
242 | ego_entry = ego_entry->next) | 308 | ego_entry = ego_entry->next) |
243 | { | 309 | { |
@@ -336,9 +402,9 @@ ego_create_cont (struct RequestHandle *handle) | |||
336 | json_decref (egoname_json); | 402 | json_decref (egoname_json); |
337 | json_decref (root_json); | 403 | json_decref (root_json); |
338 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 404 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
339 | handle->name, | 405 | handle->name, |
340 | &do_finished, | 406 | &do_finished, |
341 | handle); | 407 | handle); |
342 | } | 408 | } |
343 | 409 | ||
344 | void | 410 | void |
@@ -505,16 +571,16 @@ init_cont (struct RequestHandle *handle) | |||
505 | * @param identifier identifier assigned by the user for this ego, | 571 | * @param identifier identifier assigned by the user for this ego, |
506 | * NULL if the user just deleted the ego and it | 572 | * NULL if the user just deleted the ego and it |
507 | * must thus no longer be used | 573 | * must thus no longer be used |
508 | */ | 574 | */ |
509 | static void | 575 | static void |
510 | list_ego (void *cls, | 576 | list_ego (void *cls, |
511 | struct GNUNET_IDENTITY_Ego *ego, | 577 | struct GNUNET_IDENTITY_Ego *ego, |
512 | void **ctx, | 578 | void **ctx, |
513 | const char *identifier) | 579 | const char *identifier) |
514 | { | 580 | { |
515 | struct RequestHandle *handle = cls; | 581 | struct RequestHandle *handle = cls; |
516 | struct EgoEntry *ego_entry; | 582 | struct EgoEntry *ego_entry; |
517 | 583 | ||
518 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 584 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
519 | { | 585 | { |
520 | handle->state = ID_REST_STATE_POST_INIT; | 586 | handle->state = ID_REST_STATE_POST_INIT; |
@@ -556,6 +622,7 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle, | |||
556 | handle->proc_cls = proc_cls; | 622 | handle->proc_cls = proc_cls; |
557 | handle->proc = proc; | 623 | handle->proc = proc; |
558 | handle->state = ID_REST_STATE_INIT; | 624 | handle->state = ID_REST_STATE_INIT; |
625 | handle->conndata_handle = conndata_handle; | ||
559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
560 | "Connecting...\n"); | 627 | "Connecting...\n"); |
561 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, | 628 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, |