aboutsummaryrefslogtreecommitdiff
path: root/src/identity/plugin_rest_identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r--src/identity/plugin_rest_identity.c229
1 files changed, 127 insertions, 102 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 52685c52e..fd6562f1d 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -17,6 +17,7 @@
17 */ 17 */
18/** 18/**
19 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
20 * @author Philippe Buschmann
20 * @file identity/plugin_rest_identity.c 21 * @file identity/plugin_rest_identity.c
21 * @brief GNUnet Namestore REST plugin 22 * @brief GNUnet Namestore REST plugin
22 * 23 *
@@ -26,8 +27,6 @@
26#include "gnunet_rest_plugin.h" 27#include "gnunet_rest_plugin.h"
27#include "gnunet_identity_service.h" 28#include "gnunet_identity_service.h"
28#include "gnunet_rest_lib.h" 29#include "gnunet_rest_lib.h"
29#include "gnunet_jsonapi_lib.h"
30#include "gnunet_jsonapi_util.h"
31#include "microhttpd.h" 30#include "microhttpd.h"
32#include <jansson.h> 31#include <jansson.h>
33#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
@@ -50,23 +49,23 @@
50/** 49/**
51 * Resource type 50 * Resource type
52 */ 51 */
53#define GNUNET_REST_JSONAPI_IDENTITY_EGO "ego" 52#define GNUNET_REST_JSON_IDENTITY_EGO "ego"
54 53
55/** 54/**
56 * Name attribute 55 * Name attribute
57 */ 56 */
58#define GNUNET_REST_JSONAPI_IDENTITY_NAME "name" 57#define GNUNET_REST_JSON_IDENTITY_NAME "name"
59 58
60/** 59/**
61 * Attribute to rename "name" TODO we changed id to the pubkey 60 * Attribute to rename "name" TODO we changed id to the pubkey
62 * so this can be unified with "name" 61 * so this can be unified with "name"
63 */ 62 */
64#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname" 63#define GNUNET_REST_JSON_IDENTITY_NEWNAME "newname"
65 64
66/** 65/**
67 * URL parameter to change the subsytem for ego 66 * URL parameter to change the subsytem for ego
68 */ 67 */
69#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem" 68#define GNUNET_REST_JSON_IDENTITY_SUBSYSTEM "subsystem"
70 69
71 70
72/** 71/**
@@ -74,6 +73,7 @@
74 */ 73 */
75#define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid" 74#define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid"
76#define GNUNET_REST_ERROR_NO_DATA "No data" 75#define GNUNET_REST_ERROR_NO_DATA "No data"
76#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
77 77
78/** 78/**
79 * GNUid token lifetime 79 * GNUid token lifetime
@@ -276,16 +276,16 @@ do_error (void *cls)
276 struct MHD_Response *resp; 276 struct MHD_Response *resp;
277 char *json_error; 277 char *json_error;
278 278
279 GNUNET_asprintf (&json_error, 279 if (NULL == handle->emsg)
280 "{Error while processing request: %s}", 280 handle->emsg = GNUNET_strdup("Unknown Error");
281 &handle->emsg); 281
282 GNUNET_asprintf (&json_error, "{\"error\": \"%s\"}", handle->emsg);
283 handle->response_code = MHD_HTTP_OK;
282 284
283 resp = GNUNET_REST_create_response (json_error); 285 resp = GNUNET_REST_create_response (json_error);
284 handle->proc (handle->proc_cls, 286 handle->proc (handle->proc_cls, resp, handle->response_code);
285 resp,
286 handle->response_code);
287 cleanup_handle (handle); 287 cleanup_handle (handle);
288 GNUNET_free (json_error); 288 GNUNET_free(json_error);
289} 289}
290 290
291 291
@@ -304,14 +304,15 @@ get_ego_for_subsys (void *cls,
304 const char *name) 304 const char *name)
305{ 305{
306 struct RequestHandle *handle = cls; 306 struct RequestHandle *handle = cls;
307 struct GNUNET_JSONAPI_Document *json_document;
308 struct GNUNET_JSONAPI_Resource *json_resource;
309 struct EgoEntry *ego_entry; 307 struct EgoEntry *ego_entry;
310 struct MHD_Response *resp; 308 struct MHD_Response *resp;
309 json_t *json_root;
310 json_t *json_ego;
311 json_t *name_json; 311 json_t *name_json;
312 char *result_str; 312 char *result_str;
313 size_t index;
313 314
314 json_document = GNUNET_JSONAPI_document_new (); 315 json_root = json_array();
315 316
316 for (ego_entry = handle->ego_head; 317 for (ego_entry = handle->ego_head;
317 NULL != ego_entry; 318 NULL != ego_entry;
@@ -321,32 +322,38 @@ get_ego_for_subsys (void *cls,
321 continue; 322 continue;
322 if (NULL == name) 323 if (NULL == name)
323 continue; 324 continue;
324 json_resource = GNUNET_JSONAPI_resource_new 325
325 (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring); 326 json_ego = json_object();
326 name_json = json_string (ego_entry->identifier); 327 name_json = json_string (ego_entry->identifier);
327 GNUNET_JSONAPI_resource_add_attr (json_resource, 328 json_object_set_new(json_ego, GNUNET_REST_JSON_IDENTITY_EGO, name_json);
328 GNUNET_REST_JSONAPI_IDENTITY_NAME, 329 json_array_append(json_root, json_ego);
329 name_json); 330
330 json_decref (name_json);
331 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
332 break; 331 break;
333 } 332 }
334 if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) 333
334 if (0 == json_array_size(json_root))
335 { 335 {
336 GNUNET_JSONAPI_document_delete (json_document); 336 json_decref(json_root);
337 handle->emsg = GNUNET_strdup("No identity matches results!"); 337 handle->emsg = GNUNET_strdup("No identity matches results!");
338 GNUNET_SCHEDULER_add_now (&do_error, handle); 338 GNUNET_SCHEDULER_add_now (&do_error, handle);
339 return; 339 return;
340 } 340 }
341 GNUNET_JSONAPI_document_serialize (json_document, &result_str); 341
342 result_str = json_dumps(json_root, 0);
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
343 resp = GNUNET_REST_create_response (result_str); 344 resp = GNUNET_REST_create_response (result_str);
344 GNUNET_JSONAPI_document_delete (json_document); 345
346 json_array_foreach(json_root, index, json_ego )
347 {
348 json_decref(json_ego);
349 }
350 json_decref (json_root);
345 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 351 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
346 GNUNET_free (result_str); 352 GNUNET_free (result_str);
347 cleanup_handle (handle); 353 cleanup_handle (handle);
348} 354}
349 355
356
350/** 357/**
351 * Create a response with requested ego(s) 358 * Create a response with requested ego(s)
352 * 359 *
@@ -367,9 +374,10 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
367 struct EgoEntry *ego_entry; 374 struct EgoEntry *ego_entry;
368 struct GNUNET_HashCode key; 375 struct GNUNET_HashCode key;
369 struct MHD_Response *resp; 376 struct MHD_Response *resp;
370 struct GNUNET_JSONAPI_Document *json_document; 377 json_t *json_root;
371 struct GNUNET_JSONAPI_Resource *json_resource; 378 json_t *json_ego;
372 json_t *name_str; 379 json_t *name_str;
380 size_t index;
373 381
374 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) 382 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY))
375 { 383 {
@@ -395,8 +403,8 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
395 } 403 }
396 404
397 if ( NULL == egoname ) { 405 if ( NULL == egoname ) {
398 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM, 406 GNUNET_CRYPTO_hash (GNUNET_REST_JSON_IDENTITY_SUBSYSTEM,
399 strlen (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM), 407 strlen (GNUNET_REST_JSON_IDENTITY_SUBSYSTEM),
400 &key); 408 &key);
401 if ( GNUNET_YES == 409 if ( GNUNET_YES ==
402 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, 410 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
@@ -417,7 +425,7 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
417 } 425 }
418 } 426 }
419 427
420 json_document = GNUNET_JSONAPI_document_new (); 428 json_root = json_array();
421 429
422 //Return all egos 430 //Return all egos
423 for (ego_entry = handle->ego_head; 431 for (ego_entry = handle->ego_head;
@@ -426,27 +434,35 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
426 { 434 {
427 if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) 435 if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) )
428 continue; 436 continue;
429 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO, 437
430 ego_entry->keystring); 438 json_ego = json_object();
439
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_JSON_IDENTITY_EGO));
431 name_str = json_string (ego_entry->identifier); 442 name_str = json_string (ego_entry->identifier);
432 GNUNET_JSONAPI_resource_add_attr ( 443 json_object_set_new( json_ego, "name", name_str);
433 json_resource, 444
434 GNUNET_REST_JSONAPI_IDENTITY_NAME, 445 json_array_append( json_root, json_ego );
435 name_str);
436 json_decref (name_str);
437 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
438 } 446 }
439 if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) 447
448 if ((size_t)0 == json_array_size(json_root))
440 { 449 {
441 GNUNET_JSONAPI_document_delete (json_document); 450 json_decref (json_root);
442 handle->emsg = GNUNET_strdup ("No identities found!"); 451 handle->emsg = GNUNET_strdup ("No identities found!");
443 GNUNET_SCHEDULER_add_now (&do_error, handle); 452 GNUNET_SCHEDULER_add_now (&do_error, handle);
444 return; 453 return;
445 } 454 }
446 GNUNET_JSONAPI_document_serialize (json_document, &result_str); 455
456 result_str = json_dumps(json_root, 0);
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
448 resp = GNUNET_REST_create_response (result_str); 458 resp = GNUNET_REST_create_response (result_str);
449 GNUNET_JSONAPI_document_delete (json_document); 459
460 //delete json_objects in json_array with macro
461 json_array_foreach(json_root, index, json_ego )
462 {
463 json_decref(json_ego);
464 }
465 json_decref (json_root);
450 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 466 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
451 GNUNET_free (result_str); 467 GNUNET_free (result_str);
452 cleanup_handle (handle); 468 cleanup_handle (handle);
@@ -472,7 +488,7 @@ do_finished (void *cls, const char *emsg)
472 return; 488 return;
473 } 489 }
474 resp = GNUNET_REST_create_response (NULL); 490 resp = GNUNET_REST_create_response (NULL);
475 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT); 491 handle->proc (handle->proc_cls, resp, handle->response_code);
476 cleanup_handle (handle); 492 cleanup_handle (handle);
477} 493}
478 494
@@ -491,23 +507,19 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
491 struct RequestHandle *handle = cls; 507 struct RequestHandle *handle = cls;
492 struct EgoEntry *ego_entry; 508 struct EgoEntry *ego_entry;
493 struct MHD_Response *resp; 509 struct MHD_Response *resp;
494 struct GNUNET_JSONAPI_Document *json_obj;
495 struct GNUNET_JSONAPI_Resource *json_res;
496 json_t *egoname_json; 510 json_t *egoname_json;
497 json_t *data_js; 511 json_t *data_js;
498 json_error_t err; 512 json_error_t err;
499 const char* egoname; 513 const char* egoname;
500 char term_data[handle->data_size+1]; 514 char term_data[handle->data_size+1];
501 struct GNUNET_JSON_Specification docspec[] = { 515
502 GNUNET_JSON_spec_jsonapi_document (&json_obj),
503 GNUNET_JSON_spec_end()
504 };
505 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) 516 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
506 { 517 {
507 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID); 518 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
508 GNUNET_SCHEDULER_add_now (&do_error, handle); 519 GNUNET_SCHEDULER_add_now (&do_error, handle);
509 return; 520 return;
510 } 521 }
522
511 if (0 >= handle->data_size) 523 if (0 >= handle->data_size)
512 { 524 {
513 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); 525 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
@@ -519,50 +531,54 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
519 data_js = json_loads (term_data, 531 data_js = json_loads (term_data,
520 JSON_DECODE_ANY, 532 JSON_DECODE_ANY,
521 &err); 533 &err);
522 GNUNET_assert (NULL != data_js);
523 GNUNET_assert (GNUNET_OK ==
524 GNUNET_JSON_parse (data_js, docspec,
525 NULL, NULL));
526 534
527 json_decref (data_js);
528 535
529 if (NULL == json_obj) 536 if (NULL == data_js)
530 { 537 {
538 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
531 GNUNET_SCHEDULER_add_now (&do_error, handle); 539 GNUNET_SCHEDULER_add_now (&do_error, handle);
532 return; 540 return;
533 } 541 }
534 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) 542 //instead of parse
543 if (!json_is_object(data_js))
535 { 544 {
536 GNUNET_JSONAPI_document_delete (json_obj); 545 json_decref(data_js);
537 handle->emsg = GNUNET_strdup ("Provided resource count invalid"); 546 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
538 GNUNET_SCHEDULER_add_now (&do_error, handle); 547 GNUNET_SCHEDULER_add_now (&do_error, handle);
539 return; 548 return;
540 } 549 }
541 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); 550
542 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 551 if (1 != json_object_size (data_js))
543 { 552 {
544 GNUNET_JSONAPI_document_delete (json_obj); 553 json_decref (data_js);
545 resp = GNUNET_REST_create_response (NULL); 554 handle->emsg = GNUNET_strdup("Provided resource count invalid");
546 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 555 GNUNET_SCHEDULER_add_now (&do_error, handle);
547 cleanup_handle (handle);
548 return; 556 return;
549 } 557 }
550 egoname_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME); 558
559 egoname_json = json_object_get (data_js, GNUNET_REST_JSON_IDENTITY_NAME);
551 if (!json_is_string (egoname_json)) 560 if (!json_is_string (egoname_json))
552 { 561 {
553 GNUNET_JSONAPI_document_delete (json_obj); 562 json_decref (data_js);
554 handle->emsg = GNUNET_strdup ("No name provided"); 563 handle->emsg = GNUNET_strdup ("No name provided");
555 GNUNET_SCHEDULER_add_now (&do_error, handle); 564 GNUNET_SCHEDULER_add_now (&do_error, handle);
556 return; 565 return;
557 } 566 }
558 egoname = json_string_value (egoname_json); 567 egoname = json_string_value (egoname_json);
568 if(0 >= strlen(egoname))
569 {
570 json_decref (data_js);
571 handle->emsg = GNUNET_strdup ("No name provided");
572 GNUNET_SCHEDULER_add_now (&do_error, handle);
573 return;
574 }
559 for (ego_entry = handle->ego_head; 575 for (ego_entry = handle->ego_head;
560 NULL != ego_entry; 576 NULL != ego_entry;
561 ego_entry = ego_entry->next) 577 ego_entry = ego_entry->next)
562 { 578 {
563 if (0 == strcasecmp (egoname, ego_entry->identifier)) 579 if (0 == strcasecmp (egoname, ego_entry->identifier))
564 { 580 {
565 GNUNET_JSONAPI_document_delete (json_obj); 581 json_decref (data_js);
566 resp = GNUNET_REST_create_response (NULL); 582 resp = GNUNET_REST_create_response (NULL);
567 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 583 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
568 cleanup_handle (handle); 584 cleanup_handle (handle);
@@ -570,7 +586,8 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
570 } 586 }
571 } 587 }
572 GNUNET_asprintf (&handle->name, "%s", egoname); 588 GNUNET_asprintf (&handle->name, "%s", egoname);
573 GNUNET_JSONAPI_document_delete (json_obj); 589 json_decref (data_js);
590 handle->response_code = MHD_HTTP_CREATED;
574 handle->op = GNUNET_IDENTITY_create (handle->identity_handle, 591 handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
575 handle->name, 592 handle->name,
576 &do_finished, 593 &do_finished,
@@ -590,8 +607,6 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
590 const char *url, 607 const char *url,
591 void *cls) 608 void *cls)
592{ 609{
593 struct GNUNET_JSONAPI_Document *json_obj;
594 struct GNUNET_JSONAPI_Resource *json_res;
595 struct RequestHandle *handle = cls; 610 struct RequestHandle *handle = cls;
596 struct EgoEntry *ego_entry; 611 struct EgoEntry *ego_entry;
597 struct EgoEntry *ego_entry_tmp; 612 struct EgoEntry *ego_entry_tmp;
@@ -605,10 +620,6 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
605 const char *newname; 620 const char *newname;
606 char term_data[handle->data_size+1]; 621 char term_data[handle->data_size+1];
607 int ego_exists = GNUNET_NO; 622 int ego_exists = GNUNET_NO;
608 struct GNUNET_JSON_Specification docspec[] = {
609 GNUNET_JSON_spec_jsonapi_document (&json_obj),
610 GNUNET_JSON_spec_end()
611 };
612 623
613 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url)) 624 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
614 { 625 {
@@ -649,43 +660,40 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
649 data_js = json_loads (term_data, 660 data_js = json_loads (term_data,
650 JSON_DECODE_ANY, 661 JSON_DECODE_ANY,
651 &err); 662 &err);
652 GNUNET_assert (NULL != data_js); 663 if (NULL == data_js)
653 GNUNET_assert (GNUNET_OK ==
654 GNUNET_JSON_parse (data_js, docspec,
655 NULL, NULL));
656
657 json_decref (data_js);
658
659 if (NULL == json_obj)
660 { 664 {
661 handle->emsg = GNUNET_strdup ("Data invalid"); 665 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
662 GNUNET_SCHEDULER_add_now (&do_error, handle); 666 GNUNET_SCHEDULER_add_now (&do_error, handle);
663 return; 667 return;
664 } 668 }
665 669 if (!json_is_object(data_js))
666 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
667 { 670 {
668 GNUNET_JSONAPI_document_delete (json_obj); 671 json_decref (data_js);
669 handle->emsg = GNUNET_strdup ("Resource amount invalid"); 672 handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID);
670 GNUNET_SCHEDULER_add_now (&do_error, handle); 673 GNUNET_SCHEDULER_add_now (&do_error, handle);
671 return; 674 return;
672 } 675 }
673 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
674 676
675 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 677 if (1 != json_object_size(data_js))
676 { 678 {
677 GNUNET_JSONAPI_document_delete (json_obj); 679 json_decref (data_js);
678 handle->emsg = GNUNET_strdup ("Resource type invalid"); 680 handle->emsg = GNUNET_strdup ("Resource amount invalid");
679 GNUNET_SCHEDULER_add_now (&do_error, handle); 681 GNUNET_SCHEDULER_add_now (&do_error, handle);
680 return; 682 return;
681 } 683 }
682 684
683 //This is a rename 685 //This is a rename
684 name_json = GNUNET_JSONAPI_resource_read_attr (json_res, 686 name_json = json_object_get (data_js, GNUNET_REST_JSON_IDENTITY_NEWNAME);
685 GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
686 if ((NULL != name_json) && json_is_string (name_json)) 687 if ((NULL != name_json) && json_is_string (name_json))
687 { 688 {
688 newname = json_string_value (name_json); 689 newname = json_string_value (name_json);
690 if(0 >= strlen(newname))
691 {
692 json_decref (data_js);
693 handle->emsg = GNUNET_strdup ("No name provided");
694 GNUNET_SCHEDULER_add_now (&do_error, handle);
695 return;
696 }
689 for (ego_entry_tmp = handle->ego_head; 697 for (ego_entry_tmp = handle->ego_head;
690 NULL != ego_entry_tmp; 698 NULL != ego_entry_tmp;
691 ego_entry_tmp = ego_entry_tmp->next) 699 ego_entry_tmp = ego_entry_tmp->next)
@@ -694,29 +702,38 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
694 0 != strcasecmp (keystring, ego_entry_tmp->keystring)) 702 0 != strcasecmp (keystring, ego_entry_tmp->keystring))
695 { 703 {
696 //Ego with same name not allowed 704 //Ego with same name not allowed
697 GNUNET_JSONAPI_document_delete (json_obj); 705 json_decref (data_js);
698 resp = GNUNET_REST_create_response (NULL); 706 resp = GNUNET_REST_create_response (NULL);
699 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 707 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
700 cleanup_handle (handle); 708 cleanup_handle (handle);
701 return; 709 return;
702 } 710 }
703 } 711 }
712 handle->response_code = MHD_HTTP_NO_CONTENT;
704 handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, 713 handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
705 ego_entry->identifier, 714 ego_entry->identifier,
706 newname, 715 newname,
707 &do_finished, 716 &do_finished,
708 handle); 717 handle);
709 GNUNET_JSONAPI_document_delete (json_obj); 718 json_decref (data_js);
710 return; 719 return;
711 } 720 }
712 721
713 //Set subsystem 722 //Set subsystem
714 subsys_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM); 723 subsys_json = json_object_get (data_js, GNUNET_REST_JSON_IDENTITY_SUBSYSTEM);
715 if ( (NULL != subsys_json) && json_is_string (subsys_json)) 724 if ( (NULL != subsys_json) && json_is_string (subsys_json))
716 { 725 {
717 subsys = json_string_value (subsys_json); 726 subsys = json_string_value (subsys_json);
727 if(0 >= strlen(subsys))
728 {
729 json_decref (data_js);
730 handle->emsg = GNUNET_strdup ("No name provided");
731 GNUNET_SCHEDULER_add_now (&do_error, handle);
732 return;
733 }
718 GNUNET_asprintf (&handle->subsys, "%s", subsys); 734 GNUNET_asprintf (&handle->subsys, "%s", subsys);
719 GNUNET_JSONAPI_document_delete (json_obj); 735 json_decref (data_js);
736 handle->response_code = MHD_HTTP_NO_CONTENT;
720 handle->op = GNUNET_IDENTITY_set (handle->identity_handle, 737 handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
721 handle->subsys, 738 handle->subsys,
722 ego_entry->ego, 739 ego_entry->ego,
@@ -724,11 +741,18 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
724 handle); 741 handle);
725 return; 742 return;
726 } 743 }
727 GNUNET_JSONAPI_document_delete (json_obj); 744 json_decref (data_js);
728 handle->emsg = GNUNET_strdup ("Subsystem not provided"); 745 handle->emsg = GNUNET_strdup ("Subsystem not provided");
729 GNUNET_SCHEDULER_add_now (&do_error, handle); 746 GNUNET_SCHEDULER_add_now (&do_error, handle);
730} 747}
731 748
749/**
750 * Handle ego delete request
751 *
752 * @param con_handle the connection handle
753 * @param url the url
754 * @param cls the RequestHandle
755 */
732void 756void
733ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle, 757ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle,
734 const char* url, 758 const char* url,
@@ -764,6 +788,7 @@ ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle,
764 cleanup_handle (handle); 788 cleanup_handle (handle);
765 return; 789 return;
766 } 790 }
791 handle->response_code = MHD_HTTP_NO_CONTENT;
767 handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, 792 handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
768 ego_entry->identifier, 793 ego_entry->identifier,
769 &do_finished, 794 &do_finished,
@@ -815,7 +840,7 @@ init_cont (struct RequestHandle *handle)
815 GNUNET_REST_HANDLER_END 840 GNUNET_REST_HANDLER_END
816 }; 841 };
817 842
818 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (handle->conndata_handle, 843 if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle,
819 handlers, 844 handlers,
820 &err, 845 &err,
821 handle)) 846 handle))
@@ -907,7 +932,7 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
907 932
908 933
909 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 934 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
910 935 handle->response_code = MHD_HTTP_OK;
911 handle->proc_cls = proc_cls; 936 handle->proc_cls = proc_cls;
912 handle->proc = proc; 937 handle->proc = proc;
913 handle->state = ID_REST_STATE_INIT; 938 handle->state = ID_REST_STATE_INIT;