diff options
author | Phil <phil.buschmann@tum.de> | 2018-06-02 22:15:59 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-06-02 22:15:59 +0200 |
commit | 320c62a4f5b7dac08394cd6f6b82666df4d499e9 (patch) | |
tree | 6d4e57f8beebc4444d35083587cca399deb75e81 | |
parent | 2c2e76228330e4024062a5e8b4ef75f7f04cabbd (diff) | |
download | gnunet-320c62a4f5b7dac08394cd6f6b82666df4d499e9.tar.gz gnunet-320c62a4f5b7dac08394cd6f6b82666df4d499e9.zip |
removed jsonapi structures
-rw-r--r-- | src/identity/plugin_rest_identity.c | 244 |
1 files changed, 149 insertions, 95 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 97f50ff03..3fe749a52 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @author Philippe Buschmann | ||
22 | * @file identity/plugin_rest_identity.c | 23 | * @file identity/plugin_rest_identity.c |
23 | * @brief GNUnet Namestore REST plugin | 24 | * @brief GNUnet Namestore REST plugin |
24 | * | 25 | * |
@@ -76,6 +77,7 @@ | |||
76 | */ | 77 | */ |
77 | #define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid" | 78 | #define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid" |
78 | #define GNUNET_REST_ERROR_NO_DATA "No data" | 79 | #define GNUNET_REST_ERROR_NO_DATA "No data" |
80 | #define GNUNET_REST_ERROR_DATA_INVALID "Data invalid" | ||
79 | 81 | ||
80 | /** | 82 | /** |
81 | * GNUid token lifetime | 83 | * GNUid token lifetime |
@@ -279,9 +281,9 @@ do_error (void *cls) | |||
279 | char *json_error; | 281 | char *json_error; |
280 | 282 | ||
281 | GNUNET_asprintf (&json_error, | 283 | GNUNET_asprintf (&json_error, |
282 | "{Error while processing request: %s}", | 284 | "{\"error\": \"%s\"}", |
283 | &handle->emsg); | 285 | handle->emsg); |
284 | 286 | handle->response_code = MHD_HTTP_OK; | |
285 | resp = GNUNET_REST_create_response (json_error); | 287 | resp = GNUNET_REST_create_response (json_error); |
286 | handle->proc (handle->proc_cls, | 288 | handle->proc (handle->proc_cls, |
287 | resp, | 289 | resp, |
@@ -306,14 +308,15 @@ get_ego_for_subsys (void *cls, | |||
306 | const char *name) | 308 | const char *name) |
307 | { | 309 | { |
308 | struct RequestHandle *handle = cls; | 310 | struct RequestHandle *handle = cls; |
309 | struct GNUNET_JSONAPI_Document *json_document; | ||
310 | struct GNUNET_JSONAPI_Resource *json_resource; | ||
311 | struct EgoEntry *ego_entry; | 311 | struct EgoEntry *ego_entry; |
312 | struct MHD_Response *resp; | 312 | struct MHD_Response *resp; |
313 | json_t *json_root; | ||
314 | json_t *json_ego; | ||
313 | json_t *name_json; | 315 | json_t *name_json; |
314 | char *result_str; | 316 | char *result_str; |
317 | size_t index; | ||
315 | 318 | ||
316 | json_document = GNUNET_JSONAPI_document_new (); | 319 | json_root = json_array(); |
317 | 320 | ||
318 | for (ego_entry = handle->ego_head; | 321 | for (ego_entry = handle->ego_head; |
319 | NULL != ego_entry; | 322 | NULL != ego_entry; |
@@ -323,33 +326,38 @@ get_ego_for_subsys (void *cls, | |||
323 | continue; | 326 | continue; |
324 | if (NULL == name) | 327 | if (NULL == name) |
325 | continue; | 328 | continue; |
326 | json_resource = GNUNET_JSONAPI_resource_new | 329 | |
327 | (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring); | 330 | json_ego = json_object(); |
328 | name_json = json_string (ego_entry->identifier); | 331 | name_json = json_string (ego_entry->identifier); |
329 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 332 | json_object_set_new(json_ego, GNUNET_REST_JSONAPI_IDENTITY_EGO, name_json); |
330 | GNUNET_REST_JSONAPI_IDENTITY_NAME, | 333 | json_array_append(json_root, json_ego); |
331 | name_json); | 334 | |
332 | json_decref (name_json); | ||
333 | GNUNET_JSONAPI_document_resource_add (json_document, json_resource); | ||
334 | break; | 335 | break; |
335 | } | 336 | } |
336 | if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) | 337 | |
338 | if (0 == json_array_size(json_root)) | ||
337 | { | 339 | { |
338 | GNUNET_JSONAPI_document_delete (json_document); | 340 | json_decref(json_root); |
339 | handle->emsg = GNUNET_strdup("No identity matches results!"); | 341 | handle->emsg = GNUNET_strdup("No identity matches results!"); |
340 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 342 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
341 | return; | 343 | return; |
342 | } | 344 | } |
343 | GNUNET_JSONAPI_document_serialize (json_document, &result_str); | 345 | |
346 | result_str = json_dumps(json_root, 0); | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
345 | resp = GNUNET_REST_create_response (result_str); | 348 | resp = GNUNET_REST_create_response (result_str); |
346 | GNUNET_JSONAPI_document_delete (json_document); | 349 | |
350 | json_array_foreach(json_root, index, json_ego ) | ||
351 | { | ||
352 | json_decref(json_ego); | ||
353 | } | ||
354 | json_decref (json_root); | ||
347 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 355 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
348 | GNUNET_free (result_str); | 356 | GNUNET_free (result_str); |
349 | cleanup_handle (handle); | 357 | cleanup_handle (handle); |
350 | } | 358 | } |
351 | 359 | ||
352 | //TODO clean up, fix memleaks | 360 | |
353 | /** | 361 | /** |
354 | * Create a response with requested ego(s) | 362 | * Create a response with requested ego(s) |
355 | * | 363 | * |
@@ -370,12 +378,10 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
370 | struct EgoEntry *ego_entry; | 378 | struct EgoEntry *ego_entry; |
371 | struct GNUNET_HashCode key; | 379 | struct GNUNET_HashCode key; |
372 | struct MHD_Response *resp; | 380 | struct MHD_Response *resp; |
373 | //struct GNUNET_JSONAPI_Document *json_document; | ||
374 | //struct GNUNET_JSONAPI_Resource *json_resource; | ||
375 | json_t *json_root; | 381 | json_t *json_root; |
376 | json_t *json_ego; | 382 | json_t *json_ego; |
377 | json_t *name_str; | 383 | json_t *name_str; |
378 | struct GNUNET_JSON_Specification test; | 384 | size_t index; |
379 | 385 | ||
380 | if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) | 386 | if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY)) |
381 | { | 387 | { |
@@ -424,7 +430,6 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
424 | } | 430 | } |
425 | 431 | ||
426 | json_root = json_array(); | 432 | json_root = json_array(); |
427 | //json_document = GNUNET_JSONAPI_document_new (); | ||
428 | 433 | ||
429 | //Return all egos | 434 | //Return all egos |
430 | for (ego_entry = handle->ego_head; | 435 | for (ego_entry = handle->ego_head; |
@@ -434,37 +439,33 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con, | |||
434 | if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) | 439 | if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) ) |
435 | continue; | 440 | continue; |
436 | 441 | ||
437 | //json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_EGO, | ||
438 | // ego_entry->keystring); | ||
439 | json_ego = json_object(); | 442 | json_ego = json_object(); |
443 | |||
440 | json_object_set_new( json_ego, "id", json_string (ego_entry->keystring)); | 444 | 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)); | 445 | json_object_set_new( json_ego, "type", json_string (GNUNET_REST_JSONAPI_IDENTITY_EGO)); |
442 | name_str = json_string (ego_entry->identifier); | 446 | name_str = json_string (ego_entry->identifier); |
443 | json_object_set_new( json_ego, "name", name_str); | 447 | json_object_set_new( json_ego, "name", name_str); |
448 | |||
444 | json_array_append( json_root, json_ego ); | 449 | json_array_append( json_root, json_ego ); |
445 | //GNUNET_JSONAPI_resource_add_attr ( | 450 | } |
446 | // json_resource, | 451 | |
447 | // GNUNET_REST_JSONAPI_IDENTITY_NAME, | 452 | if ((size_t)0 == json_array_size(json_root)) |
448 | // name_str); | ||
449 | json_decref (name_str); | ||
450 | //GNUNET_JSONAPI_document_resource_add (json_document, json_resource); | ||
451 | } | ||
452 | //if (0 == GNUNET_JSONAPI_document_resource_count (json_document)) | ||
453 | if (0 == json_array_size(json_root)) | ||
454 | { | 453 | { |
455 | //GNUNET_JSONAPI_document_delete (json_document); | 454 | json_decref (json_root); |
456 | json_decref (json_root); | ||
457 | handle->emsg = GNUNET_strdup ("No identities found!"); | 455 | handle->emsg = GNUNET_strdup ("No identities found!"); |
458 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 456 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
459 | return; | 457 | return; |
460 | } | 458 | } |
461 | //TODO here parse | 459 | |
462 | //GNUNET_JSONAPI_document_serialize (json_document, &result_str); | ||
463 | //GNUNET_JSON_parse(); | ||
464 | result_str = json_dumps(json_root, 0); | 460 | result_str = json_dumps(json_root, 0); |
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
466 | resp = GNUNET_REST_create_response (result_str); | 462 | resp = GNUNET_REST_create_response (result_str); |
467 | //GNUNET_JSONAPI_document_delete (json_document); | 463 | |
464 | //delete json_objects in json_array with macro | ||
465 | json_array_foreach(json_root, index, json_ego ) | ||
466 | { | ||
467 | json_decref(json_ego); | ||
468 | } | ||
468 | json_decref (json_root); | 469 | json_decref (json_root); |
469 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 470 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
470 | GNUNET_free (result_str); | 471 | GNUNET_free (result_str); |
@@ -491,10 +492,80 @@ do_finished (void *cls, const char *emsg) | |||
491 | return; | 492 | return; |
492 | } | 493 | } |
493 | resp = GNUNET_REST_create_response (NULL); | 494 | resp = GNUNET_REST_create_response (NULL); |
494 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT); | 495 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CREATED); |
495 | cleanup_handle (handle); | 496 | cleanup_handle (handle); |
496 | } | 497 | } |
497 | 498 | ||
499 | // | ||
500 | // | ||
501 | ///** | ||
502 | // * Parse given JSON object to jsonapi document. | ||
503 | // * | ||
504 | // * @param cls closure, NULL | ||
505 | // * @param root the json object representing data | ||
506 | // * @param[out] spec where to write the data | ||
507 | // * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
508 | // */ | ||
509 | //static int | ||
510 | //parse_jsonapiobject (void *cls, json_t *root, | ||
511 | // struct GNUNET_JSON_Specification *spec) | ||
512 | //{ | ||
513 | // if (NULL == root) | ||
514 | // { | ||
515 | // return GNUNET_SYSERR; | ||
516 | // } | ||
517 | // if (1 == json_is_object(root)) | ||
518 | // { | ||
519 | // if (1 == json_is_string(json_object_get (root, GNUNET_REST_JSONAPI_IDENTITY_NAME))) | ||
520 | // { | ||
521 | // return GNUNET_OK; | ||
522 | // } | ||
523 | // } | ||
524 | // return GNUNET_SYSERR; | ||
525 | //} | ||
526 | // | ||
527 | ///** | ||
528 | // * Cleanup data left from parsing RSA public key. | ||
529 | // * | ||
530 | // * @param cls closure, NULL | ||
531 | // * @param[out] spec where to free the data | ||
532 | // */ | ||
533 | //static void | ||
534 | //clean_jsonapiobject (void *cls, | ||
535 | // struct GNUNET_JSON_Specification *spec) | ||
536 | //{ | ||
537 | // json_t **jsonapi_obj = (json_t **) spec->ptr; | ||
538 | // if (NULL != *jsonapi_obj) | ||
539 | // { | ||
540 | // json_decref (*jsonapi_obj); | ||
541 | // *jsonapi_obj = NULL; | ||
542 | // } | ||
543 | //} | ||
544 | // | ||
545 | ///** | ||
546 | // * JSON object. | ||
547 | // * | ||
548 | // * @param name name of the JSON field | ||
549 | // * @param[out] jsonp where to store the JSON found under @a name | ||
550 | // */ | ||
551 | //struct GNUNET_JSON_Specification | ||
552 | //GNUNET_JSON_spec_json_create_identity (json_t **jsonapi_object) | ||
553 | //{ | ||
554 | // struct GNUNET_JSON_Specification ret = { | ||
555 | // .parser = &parse_jsonapiobject, | ||
556 | // .cleaner = &clean_jsonapiobject, | ||
557 | // .cls = NULL, | ||
558 | // .field = NULL, | ||
559 | // .ptr = jsonapi_object, | ||
560 | // .ptr_size = 0, | ||
561 | // .size_ptr = NULL | ||
562 | // }; | ||
563 | // *jsonapi_object = NULL; | ||
564 | // return ret; | ||
565 | //} | ||
566 | |||
567 | |||
568 | |||
498 | /** | 569 | /** |
499 | * Create a new ego | 570 | * Create a new ego |
500 | * | 571 | * |
@@ -510,23 +581,19 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
510 | struct RequestHandle *handle = cls; | 581 | struct RequestHandle *handle = cls; |
511 | struct EgoEntry *ego_entry; | 582 | struct EgoEntry *ego_entry; |
512 | struct MHD_Response *resp; | 583 | struct MHD_Response *resp; |
513 | struct GNUNET_JSONAPI_Document *json_obj; | ||
514 | struct GNUNET_JSONAPI_Resource *json_res; | ||
515 | json_t *egoname_json; | 584 | json_t *egoname_json; |
516 | json_t *data_js; | 585 | json_t *data_js; |
517 | json_error_t err; | 586 | json_error_t err; |
518 | const char* egoname; | 587 | const char* egoname; |
519 | char term_data[handle->data_size+1]; | 588 | char term_data[handle->data_size+1]; |
520 | struct GNUNET_JSON_Specification docspec[] = { | 589 | |
521 | GNUNET_JSON_spec_jsonapi_document (&json_obj), | ||
522 | GNUNET_JSON_spec_end() | ||
523 | }; | ||
524 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) | 590 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) |
525 | { | 591 | { |
526 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID); | 592 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID); |
527 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 593 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
528 | return; | 594 | return; |
529 | } | 595 | } |
596 | |||
530 | if (0 >= handle->data_size) | 597 | if (0 >= handle->data_size) |
531 | { | 598 | { |
532 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 599 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); |
@@ -538,38 +605,34 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
538 | data_js = json_loads (term_data, | 605 | data_js = json_loads (term_data, |
539 | JSON_DECODE_ANY, | 606 | JSON_DECODE_ANY, |
540 | &err); | 607 | &err); |
541 | GNUNET_assert (NULL != data_js); | ||
542 | GNUNET_assert (GNUNET_OK == | ||
543 | GNUNET_JSON_parse (data_js, docspec, | ||
544 | NULL, NULL)); | ||
545 | 608 | ||
546 | json_decref (data_js); | ||
547 | 609 | ||
548 | if (NULL == json_obj) | 610 | if (NULL == data_js) |
549 | { | 611 | { |
612 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | ||
550 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 613 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
551 | return; | 614 | return; |
552 | } | 615 | } |
553 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) | 616 | //instead of parse |
617 | if (!json_is_object(data_js)) | ||
554 | { | 618 | { |
555 | GNUNET_JSONAPI_document_delete (json_obj); | 619 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
556 | handle->emsg = GNUNET_strdup ("Provided resource count invalid"); | ||
557 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 620 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
558 | return; | 621 | return; |
559 | } | 622 | } |
560 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); | 623 | |
561 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) | 624 | if (1 != json_object_size(data_js)) |
562 | { | 625 | { |
563 | GNUNET_JSONAPI_document_delete (json_obj); | 626 | json_decref (data_js); |
564 | resp = GNUNET_REST_create_response (NULL); | 627 | handle->emsg = GNUNET_strdup ("Provided resource count invalid"); |
565 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 628 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
566 | cleanup_handle (handle); | ||
567 | return; | 629 | return; |
568 | } | 630 | } |
569 | egoname_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME); | 631 | |
632 | egoname_json = json_object_get (data_js, GNUNET_REST_JSONAPI_IDENTITY_NAME); | ||
570 | if (!json_is_string (egoname_json)) | 633 | if (!json_is_string (egoname_json)) |
571 | { | 634 | { |
572 | GNUNET_JSONAPI_document_delete (json_obj); | 635 | json_decref (data_js); |
573 | handle->emsg = GNUNET_strdup ("No name provided"); | 636 | handle->emsg = GNUNET_strdup ("No name provided"); |
574 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 637 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
575 | return; | 638 | return; |
@@ -581,7 +644,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
581 | { | 644 | { |
582 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | 645 | if (0 == strcasecmp (egoname, ego_entry->identifier)) |
583 | { | 646 | { |
584 | GNUNET_JSONAPI_document_delete (json_obj); | 647 | json_decref (data_js); |
585 | resp = GNUNET_REST_create_response (NULL); | 648 | resp = GNUNET_REST_create_response (NULL); |
586 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 649 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
587 | cleanup_handle (handle); | 650 | cleanup_handle (handle); |
@@ -589,7 +652,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
589 | } | 652 | } |
590 | } | 653 | } |
591 | GNUNET_asprintf (&handle->name, "%s", egoname); | 654 | GNUNET_asprintf (&handle->name, "%s", egoname); |
592 | GNUNET_JSONAPI_document_delete (json_obj); | 655 | json_decref (data_js); |
593 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 656 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
594 | handle->name, | 657 | handle->name, |
595 | &do_finished, | 658 | &do_finished, |
@@ -609,8 +672,6 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
609 | const char *url, | 672 | const char *url, |
610 | void *cls) | 673 | void *cls) |
611 | { | 674 | { |
612 | struct GNUNET_JSONAPI_Document *json_obj; | ||
613 | struct GNUNET_JSONAPI_Resource *json_res; | ||
614 | struct RequestHandle *handle = cls; | 675 | struct RequestHandle *handle = cls; |
615 | struct EgoEntry *ego_entry; | 676 | struct EgoEntry *ego_entry; |
616 | struct EgoEntry *ego_entry_tmp; | 677 | struct EgoEntry *ego_entry_tmp; |
@@ -624,10 +685,6 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
624 | const char *newname; | 685 | const char *newname; |
625 | char term_data[handle->data_size+1]; | 686 | char term_data[handle->data_size+1]; |
626 | int ego_exists = GNUNET_NO; | 687 | int ego_exists = GNUNET_NO; |
627 | struct GNUNET_JSON_Specification docspec[] = { | ||
628 | GNUNET_JSON_spec_jsonapi_document (&json_obj), | ||
629 | GNUNET_JSON_spec_end() | ||
630 | }; | ||
631 | 688 | ||
632 | if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url)) | 689 | if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url)) |
633 | { | 690 | { |
@@ -668,40 +725,30 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
668 | data_js = json_loads (term_data, | 725 | data_js = json_loads (term_data, |
669 | JSON_DECODE_ANY, | 726 | JSON_DECODE_ANY, |
670 | &err); | 727 | &err); |
671 | GNUNET_assert (NULL != data_js); | 728 | if (NULL == data_js) |
672 | GNUNET_assert (GNUNET_OK == | ||
673 | GNUNET_JSON_parse (data_js, docspec, | ||
674 | NULL, NULL)); | ||
675 | |||
676 | json_decref (data_js); | ||
677 | |||
678 | if (NULL == json_obj) | ||
679 | { | 729 | { |
680 | handle->emsg = GNUNET_strdup ("Data invalid"); | 730 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); |
681 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 731 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
682 | return; | 732 | return; |
683 | } | 733 | } |
684 | 734 | if (!json_is_object(data_js)) | |
685 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) | ||
686 | { | 735 | { |
687 | GNUNET_JSONAPI_document_delete (json_obj); | 736 | json_decref (data_js); |
688 | handle->emsg = GNUNET_strdup ("Resource amount invalid"); | 737 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
689 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 738 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
690 | return; | 739 | return; |
691 | } | 740 | } |
692 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); | ||
693 | 741 | ||
694 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) | 742 | if (1 != json_object_size(data_js)) |
695 | { | 743 | { |
696 | GNUNET_JSONAPI_document_delete (json_obj); | 744 | json_decref (data_js); |
697 | handle->emsg = GNUNET_strdup ("Resource type invalid"); | 745 | handle->emsg = GNUNET_strdup ("Resource amount invalid"); |
698 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 746 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
699 | return; | 747 | return; |
700 | } | 748 | } |
701 | 749 | ||
702 | //This is a rename | 750 | //This is a rename |
703 | name_json = GNUNET_JSONAPI_resource_read_attr (json_res, | 751 | name_json = json_object_get (data_js, GNUNET_REST_JSONAPI_IDENTITY_NEWNAME); |
704 | GNUNET_REST_JSONAPI_IDENTITY_NEWNAME); | ||
705 | if ((NULL != name_json) && json_is_string (name_json)) | 752 | if ((NULL != name_json) && json_is_string (name_json)) |
706 | { | 753 | { |
707 | newname = json_string_value (name_json); | 754 | newname = json_string_value (name_json); |
@@ -713,7 +760,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
713 | 0 != strcasecmp (keystring, ego_entry_tmp->keystring)) | 760 | 0 != strcasecmp (keystring, ego_entry_tmp->keystring)) |
714 | { | 761 | { |
715 | //Ego with same name not allowed | 762 | //Ego with same name not allowed |
716 | GNUNET_JSONAPI_document_delete (json_obj); | 763 | json_decref (data_js); |
717 | resp = GNUNET_REST_create_response (NULL); | 764 | resp = GNUNET_REST_create_response (NULL); |
718 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 765 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
719 | cleanup_handle (handle); | 766 | cleanup_handle (handle); |
@@ -725,17 +772,17 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
725 | newname, | 772 | newname, |
726 | &do_finished, | 773 | &do_finished, |
727 | handle); | 774 | handle); |
728 | GNUNET_JSONAPI_document_delete (json_obj); | 775 | json_decref (data_js); |
729 | return; | 776 | return; |
730 | } | 777 | } |
731 | 778 | ||
732 | //Set subsystem | 779 | //Set subsystem |
733 | subsys_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM); | 780 | subsys_json = json_object_get (data_js, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM); |
734 | if ( (NULL != subsys_json) && json_is_string (subsys_json)) | 781 | if ( (NULL != subsys_json) && json_is_string (subsys_json)) |
735 | { | 782 | { |
736 | subsys = json_string_value (subsys_json); | 783 | subsys = json_string_value (subsys_json); |
737 | GNUNET_asprintf (&handle->subsys, "%s", subsys); | 784 | GNUNET_asprintf (&handle->subsys, "%s", subsys); |
738 | GNUNET_JSONAPI_document_delete (json_obj); | 785 | json_decref (data_js); |
739 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 786 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, |
740 | handle->subsys, | 787 | handle->subsys, |
741 | ego_entry->ego, | 788 | ego_entry->ego, |
@@ -743,11 +790,18 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
743 | handle); | 790 | handle); |
744 | return; | 791 | return; |
745 | } | 792 | } |
746 | GNUNET_JSONAPI_document_delete (json_obj); | 793 | json_decref (data_js); |
747 | handle->emsg = GNUNET_strdup ("Subsystem not provided"); | 794 | handle->emsg = GNUNET_strdup ("Subsystem not provided"); |
748 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 795 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
749 | } | 796 | } |
750 | 797 | ||
798 | /** | ||
799 | * Handle ego delete request | ||
800 | * | ||
801 | * @param con_handle the connection handle | ||
802 | * @param url the url | ||
803 | * @param cls the RequestHandle | ||
804 | */ | ||
751 | void | 805 | void |
752 | ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle, | 806 | ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle, |
753 | const char* url, | 807 | const char* url, |