aboutsummaryrefslogtreecommitdiff
path: root/src/identity/plugin_rest_identity.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-05-04 17:18:02 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-05-04 17:18:02 +0000
commita44744499d8f3df64cc1d15cd6b40b4b0e4a3683 (patch)
tree27621a6ee20cbe8e344ffdc18c05754e67d67bf3 /src/identity/plugin_rest_identity.c
parentca11046195a840932edb04900669a38cd60ae682 (diff)
downloadgnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.tar.gz
gnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.zip
Update jsonapi to current specs, refactor
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r--src/identity/plugin_rest_identity.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 4a2429a9c..50d13713a 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -302,14 +302,14 @@ get_ego_for_subsys (void *cls,
302 const char *name) 302 const char *name)
303{ 303{
304 struct RequestHandle *handle = cls; 304 struct RequestHandle *handle = cls;
305 struct GNUNET_JSONAPI_Object *json_object; 305 struct GNUNET_JSONAPI_Document *json_document;
306 struct GNUNET_JSONAPI_Resource *json_resource; 306 struct GNUNET_JSONAPI_Resource *json_resource;
307 struct EgoEntry *ego_entry; 307 struct EgoEntry *ego_entry;
308 struct MHD_Response *resp; 308 struct MHD_Response *resp;
309 json_t *name_json; 309 json_t *name_json;
310 char *result_str; 310 char *result_str;
311 311
312 json_object = GNUNET_JSONAPI_object_new (); 312 json_document = GNUNET_JSONAPI_document_new ();
313 313
314 for (ego_entry = handle->ego_head; 314 for (ego_entry = handle->ego_head;
315 NULL != ego_entry; 315 NULL != ego_entry;
@@ -326,20 +326,20 @@ get_ego_for_subsys (void *cls,
326 GNUNET_REST_JSONAPI_IDENTITY_NAME, 326 GNUNET_REST_JSONAPI_IDENTITY_NAME,
327 name_json); 327 name_json);
328 json_decref (name_json); 328 json_decref (name_json);
329 GNUNET_JSONAPI_object_resource_add (json_object, json_resource); 329 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
330 break; 330 break;
331 } 331 }
332 if (0 == GNUNET_JSONAPI_object_resource_count (json_object)) 332 if (0 == GNUNET_JSONAPI_document_resource_count (json_document))
333 { 333 {
334 GNUNET_JSONAPI_object_delete (json_object); 334 GNUNET_JSONAPI_document_delete (json_document);
335 handle->emsg = GNUNET_strdup("No identity matches results!"); 335 handle->emsg = GNUNET_strdup("No identity matches results!");
336 GNUNET_SCHEDULER_add_now (&do_error, handle); 336 GNUNET_SCHEDULER_add_now (&do_error, handle);
337 return; 337 return;
338 } 338 }
339 GNUNET_JSONAPI_data_serialize (json_object, &result_str); 339 GNUNET_JSONAPI_document_serialize (json_document, &result_str);
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
341 resp = GNUNET_REST_create_json_response (result_str); 341 resp = GNUNET_REST_create_json_response (result_str);
342 GNUNET_JSONAPI_object_delete (json_object); 342 GNUNET_JSONAPI_document_delete (json_document);
343 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 343 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
344 GNUNET_free (result_str); 344 GNUNET_free (result_str);
345 cleanup_handle (handle); 345 cleanup_handle (handle);
@@ -365,7 +365,7 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
365 struct EgoEntry *ego_entry; 365 struct EgoEntry *ego_entry;
366 struct GNUNET_HashCode key; 366 struct GNUNET_HashCode key;
367 struct MHD_Response *resp; 367 struct MHD_Response *resp;
368 struct GNUNET_JSONAPI_Object *json_object; 368 struct GNUNET_JSONAPI_Document *json_document;
369 struct GNUNET_JSONAPI_Resource *json_resource; 369 struct GNUNET_JSONAPI_Resource *json_resource;
370 json_t *name_str; 370 json_t *name_str;
371 371
@@ -415,7 +415,7 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
415 } 415 }
416 } 416 }
417 417
418 json_object = GNUNET_JSONAPI_object_new (); 418 json_document = GNUNET_JSONAPI_document_new ();
419 419
420 //Return all egos 420 //Return all egos
421 for (ego_entry = handle->ego_head; 421 for (ego_entry = handle->ego_head;
@@ -432,19 +432,19 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
432 GNUNET_REST_JSONAPI_IDENTITY_NAME, 432 GNUNET_REST_JSONAPI_IDENTITY_NAME,
433 name_str); 433 name_str);
434 json_decref (name_str); 434 json_decref (name_str);
435 GNUNET_JSONAPI_object_resource_add (json_object, json_resource); 435 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
436 } 436 }
437 if (0 == GNUNET_JSONAPI_object_resource_count (json_object)) 437 if (0 == GNUNET_JSONAPI_document_resource_count (json_document))
438 { 438 {
439 GNUNET_JSONAPI_object_delete (json_object); 439 GNUNET_JSONAPI_document_delete (json_document);
440 handle->emsg = GNUNET_strdup ("No identities found!"); 440 handle->emsg = GNUNET_strdup ("No identities found!");
441 GNUNET_SCHEDULER_add_now (&do_error, handle); 441 GNUNET_SCHEDULER_add_now (&do_error, handle);
442 return; 442 return;
443 } 443 }
444 GNUNET_JSONAPI_data_serialize (json_object, &result_str); 444 GNUNET_JSONAPI_document_serialize (json_document, &result_str);
445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
446 resp = GNUNET_REST_create_json_response (result_str); 446 resp = GNUNET_REST_create_json_response (result_str);
447 GNUNET_JSONAPI_object_delete (json_object); 447 GNUNET_JSONAPI_document_delete (json_document);
448 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 448 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
449 GNUNET_free (result_str); 449 GNUNET_free (result_str);
450 cleanup_handle (handle); 450 cleanup_handle (handle);
@@ -489,7 +489,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
489 struct RequestHandle *handle = cls; 489 struct RequestHandle *handle = cls;
490 struct EgoEntry *ego_entry; 490 struct EgoEntry *ego_entry;
491 struct MHD_Response *resp; 491 struct MHD_Response *resp;
492 struct GNUNET_JSONAPI_Object *json_obj; 492 struct GNUNET_JSONAPI_Document *json_obj;
493 struct GNUNET_JSONAPI_Resource *json_res; 493 struct GNUNET_JSONAPI_Resource *json_res;
494 json_t *egoname_json; 494 json_t *egoname_json;
495 const char* egoname; 495 const char* egoname;
@@ -509,24 +509,24 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
509 } 509 }
510 term_data[handle->data_size] = '\0'; 510 term_data[handle->data_size] = '\0';
511 memcpy (term_data, handle->data, handle->data_size); 511 memcpy (term_data, handle->data, handle->data_size);
512 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, 512 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_parse (term_data,
513 &json_obj)); 513 &json_obj));
514 if (NULL == json_obj) 514 if (NULL == json_obj)
515 { 515 {
516 GNUNET_SCHEDULER_add_now (&do_error, handle); 516 GNUNET_SCHEDULER_add_now (&do_error, handle);
517 return; 517 return;
518 } 518 }
519 if (1 != GNUNET_JSONAPI_object_resource_count (json_obj)) 519 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
520 { 520 {
521 GNUNET_JSONAPI_object_delete (json_obj); 521 GNUNET_JSONAPI_document_delete (json_obj);
522 handle->emsg = GNUNET_strdup ("Provided resource count invalid"); 522 handle->emsg = GNUNET_strdup ("Provided resource count invalid");
523 GNUNET_SCHEDULER_add_now (&do_error, handle); 523 GNUNET_SCHEDULER_add_now (&do_error, handle);
524 return; 524 return;
525 } 525 }
526 json_res = GNUNET_JSONAPI_object_get_resource (json_obj, 0); 526 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
527 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 527 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
528 { 528 {
529 GNUNET_JSONAPI_object_delete (json_obj); 529 GNUNET_JSONAPI_document_delete (json_obj);
530 resp = GNUNET_REST_create_json_response (NULL); 530 resp = GNUNET_REST_create_json_response (NULL);
531 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 531 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
532 cleanup_handle (handle); 532 cleanup_handle (handle);
@@ -535,7 +535,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
535 egoname_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME); 535 egoname_json = GNUNET_JSONAPI_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NAME);
536 if (!json_is_string (egoname_json)) 536 if (!json_is_string (egoname_json))
537 { 537 {
538 GNUNET_JSONAPI_object_delete (json_obj); 538 GNUNET_JSONAPI_document_delete (json_obj);
539 handle->emsg = GNUNET_strdup ("No name provided"); 539 handle->emsg = GNUNET_strdup ("No name provided");
540 GNUNET_SCHEDULER_add_now (&do_error, handle); 540 GNUNET_SCHEDULER_add_now (&do_error, handle);
541 return; 541 return;
@@ -547,7 +547,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
547 { 547 {
548 if (0 == strcasecmp (egoname, ego_entry->identifier)) 548 if (0 == strcasecmp (egoname, ego_entry->identifier))
549 { 549 {
550 GNUNET_JSONAPI_object_delete (json_obj); 550 GNUNET_JSONAPI_document_delete (json_obj);
551 resp = GNUNET_REST_create_json_response (NULL); 551 resp = GNUNET_REST_create_json_response (NULL);
552 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 552 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
553 cleanup_handle (handle); 553 cleanup_handle (handle);
@@ -555,7 +555,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con,
555 } 555 }
556 } 556 }
557 GNUNET_asprintf (&handle->name, "%s", egoname); 557 GNUNET_asprintf (&handle->name, "%s", egoname);
558 GNUNET_JSONAPI_object_delete (json_obj); 558 GNUNET_JSONAPI_document_delete (json_obj);
559 handle->op = GNUNET_IDENTITY_create (handle->identity_handle, 559 handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
560 handle->name, 560 handle->name,
561 &do_finished, 561 &do_finished,
@@ -575,7 +575,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
575 const char *url, 575 const char *url,
576 void *cls) 576 void *cls)
577{ 577{
578 struct GNUNET_JSONAPI_Object *json_obj; 578 struct GNUNET_JSONAPI_Document *json_obj;
579 struct GNUNET_JSONAPI_Resource *json_res; 579 struct GNUNET_JSONAPI_Resource *json_res;
580 struct RequestHandle *handle = cls; 580 struct RequestHandle *handle = cls;
581 struct EgoEntry *ego_entry; 581 struct EgoEntry *ego_entry;
@@ -624,7 +624,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
624 624
625 term_data[handle->data_size] = '\0'; 625 term_data[handle->data_size] = '\0';
626 memcpy (term_data, handle->data, handle->data_size); 626 memcpy (term_data, handle->data, handle->data_size);
627 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, 627 GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_parse (term_data,
628 &json_obj)); 628 &json_obj));
629 629
630 if (NULL == json_obj) 630 if (NULL == json_obj)
@@ -634,18 +634,18 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
634 return; 634 return;
635 } 635 }
636 636
637 if (1 != GNUNET_JSONAPI_object_resource_count (json_obj)) 637 if (1 != GNUNET_JSONAPI_document_resource_count (json_obj))
638 { 638 {
639 GNUNET_JSONAPI_object_delete (json_obj); 639 GNUNET_JSONAPI_document_delete (json_obj);
640 handle->emsg = GNUNET_strdup ("Resource amount invalid"); 640 handle->emsg = GNUNET_strdup ("Resource amount invalid");
641 GNUNET_SCHEDULER_add_now (&do_error, handle); 641 GNUNET_SCHEDULER_add_now (&do_error, handle);
642 return; 642 return;
643 } 643 }
644 json_res = GNUNET_JSONAPI_object_get_resource (json_obj, 0); 644 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
645 645
646 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 646 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
647 { 647 {
648 GNUNET_JSONAPI_object_delete (json_obj); 648 GNUNET_JSONAPI_document_delete (json_obj);
649 handle->emsg = GNUNET_strdup ("Resource type invalid"); 649 handle->emsg = GNUNET_strdup ("Resource type invalid");
650 GNUNET_SCHEDULER_add_now (&do_error, handle); 650 GNUNET_SCHEDULER_add_now (&do_error, handle);
651 return; 651 return;
@@ -665,7 +665,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
665 0 != strcasecmp (keystring, ego_entry->keystring)) 665 0 != strcasecmp (keystring, ego_entry->keystring))
666 { 666 {
667 //Ego with same name not allowed 667 //Ego with same name not allowed
668 GNUNET_JSONAPI_object_delete (json_obj); 668 GNUNET_JSONAPI_document_delete (json_obj);
669 resp = GNUNET_REST_create_json_response (NULL); 669 resp = GNUNET_REST_create_json_response (NULL);
670 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); 670 handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
671 cleanup_handle (handle); 671 cleanup_handle (handle);
@@ -677,7 +677,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
677 newname, 677 newname,
678 &do_finished, 678 &do_finished,
679 handle); 679 handle);
680 GNUNET_JSONAPI_object_delete (json_obj); 680 GNUNET_JSONAPI_document_delete (json_obj);
681 return; 681 return;
682 } 682 }
683 683
@@ -687,7 +687,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
687 { 687 {
688 subsys = json_string_value (subsys_json); 688 subsys = json_string_value (subsys_json);
689 GNUNET_asprintf (&handle->subsys, "%s", subsys); 689 GNUNET_asprintf (&handle->subsys, "%s", subsys);
690 GNUNET_JSONAPI_object_delete (json_obj); 690 GNUNET_JSONAPI_document_delete (json_obj);
691 handle->op = GNUNET_IDENTITY_set (handle->identity_handle, 691 handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
692 handle->subsys, 692 handle->subsys,
693 ego_entry->ego, 693 ego_entry->ego,
@@ -695,7 +695,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
695 handle); 695 handle);
696 return; 696 return;
697 } 697 }
698 GNUNET_JSONAPI_object_delete (json_obj); 698 GNUNET_JSONAPI_document_delete (json_obj);
699 handle->emsg = GNUNET_strdup ("Subsystem not provided"); 699 handle->emsg = GNUNET_strdup ("Subsystem not provided");
700 GNUNET_SCHEDULER_add_now (&do_error, handle); 700 GNUNET_SCHEDULER_add_now (&do_error, handle);
701} 701}