diff options
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 6044d0641..97f50ff03 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -349,6 +349,7 @@ get_ego_for_subsys (void *cls, | |||
349 | cleanup_handle (handle); | 349 | cleanup_handle (handle); |
350 | } | 350 | } |
351 | 351 | ||
352 | //TODO clean up, fix memleaks | ||
352 | /** | 353 | /** |
353 | * Create a response with requested ego(s) | 354 | * Create a response with requested ego(s) |
354 | * | 355 | * |
@@ -369,9 +370,12 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
369 | struct EgoEntry *ego_entry; | 370 | struct EgoEntry *ego_entry; |
370 | struct GNUNET_HashCode key; | 371 | struct GNUNET_HashCode key; |
371 | struct MHD_Response *resp; | 372 | struct MHD_Response *resp; |
372 | struct GNUNET_JSONAPI_Document *json_document; | 373 | //struct GNUNET_JSONAPI_Document *json_document; |
373 | struct GNUNET_JSONAPI_Resource *json_resource; | 374 | //struct GNUNET_JSONAPI_Resource *json_resource; |
375 | json_t *json_root; | ||
376 | json_t *json_ego; | ||
374 | json_t *name_str; | 377 | json_t *name_str; |
378 | struct GNUNET_JSON_Specification test; | ||
375 | 379 | ||
376 | if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) | 380 | if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) |
377 | { | 381 | { |
@@ -419,7 +423,8 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
419 | } | 423 | } |
420 | } | 424 | } |
421 | 425 | ||
422 | json_document = GNUNET_JSONAPI_document_new (); | 426 | json_root = json_array(); |
427 | //json_document = GNUNET_JSONAPI_document_new (); | ||
423 | 428 | ||
424 | //Return all egos | 429 | //Return all egos |
425 | for (ego_entry = handle->ego_head; | 430 | for (ego_entry = handle->ego_head; |
@@ -428,27 +433,39 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
428 | { | 433 | { |
429 | if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) | 434 | if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) |
430 | continue; | 435 | continue; |
431 | json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO, | 436 | |
432 | ego_entry->keystring); | 437 | //json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO, |
438 | // ego_entry->keystring); | ||
439 | json_ego = json_object(); | ||
440 | json_object_set_new( json_ego, "id", json_string (ego_entry->keystring)); | ||
441 | json_object_set_new( json_ego, "type", json_string (GNUNET_REST_JSONAPI_IDENTITY_EGO)); | ||
433 | name_str = json_string (ego_entry->identifier); | 442 | name_str = json_string (ego_entry->identifier); |
434 | GNUNET_JSONAPI_resource_add_attr ( | 443 | json_object_set_new( json_ego, "name", name_str); |
435 | json_resource, | 444 | json_array_append( json_root, json_ego ); |
436 | GNUNET_REST_JSONAPI_IDENTITY_NAME, | 445 | //GNUNET_JSONAPI_resource_add_attr ( |
437 | name_str); | 446 | // json_resource, |
447 | // GNUNET_REST_JSONAPI_IDENTITY_NAME, | ||
448 | // name_str); | ||
438 | json_decref (name_str); | 449 | json_decref (name_str); |
439 | GNUNET_JSONAPI_document_resource_add (json_document, json_resource); | 450 | //GNUNET_JSONAPI_document_resource_add (json_document, json_resource); |
440 | } | 451 | } |
441 | if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) | 452 | //if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) |
453 | if (0 == json_array_size(json_root)) | ||
442 | { | 454 | { |
443 | GNUNET_JSONAPI_document_delete (json_document); | 455 | //GNUNET_JSONAPI_document_delete (json_document); |
456 | json_decref (json_root); | ||
444 | handle->emsg = GNUNET_strdup ("No identities found!"); | 457 | handle->emsg = GNUNET_strdup ("No identities found!"); |
445 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 458 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
446 | return; | 459 | return; |
447 | } | 460 | } |
448 | GNUNET_JSONAPI_document_serialize (json_document, &result_str); | 461 | //TODO here parse |
462 | //GNUNET_JSONAPI_document_serialize (json_document, &result_str); | ||
463 | //GNUNET_JSON_parse(); | ||
464 | result_str = json_dumps(json_root, 0); | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
450 | resp = GNUNET_REST_create_response (result_str); | 466 | resp = GNUNET_REST_create_response (result_str); |
451 | GNUNET_JSONAPI_document_delete (json_document); | 467 | //GNUNET_JSONAPI_document_delete (json_document); |
468 | json_decref (json_root); | ||
452 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 469 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
453 | GNUNET_free (result_str); | 470 | GNUNET_free (result_str); |
454 | cleanup_handle (handle); | 471 | cleanup_handle (handle); |