aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-26 16:40:36 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-26 16:40:36 +0000
commit9cbff235e16bb2888aca2ba492f46bca9351142d (patch)
tree35ad6c7ff0751026c3995cc606fe2d2f5ea6bba1 /src/identity
parent726b28a61c858b4b251e4a0a006e4021b01886c0 (diff)
downloadgnunet-9cbff235e16bb2888aca2ba492f46bca9351142d.tar.gz
gnunet-9cbff235e16bb2888aca2ba492f46bca9351142d.zip
-add rename
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/plugin_rest_identity.c76
1 files changed, 48 insertions, 28 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 2fb29d87d..20e48aba9 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -43,6 +43,8 @@
43 43
44#define GNUNET_REST_JSONAPI_IDENTITY_KEY "key" 44#define GNUNET_REST_JSONAPI_IDENTITY_KEY "key"
45 45
46#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname"
47
46#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem" 48#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem"
47 49
48/** 50/**
@@ -381,11 +383,11 @@ do_finished (void *cls, const char *emsg)
381} 383}
382 384
383static void 385static void
384set_finished (void *cls, const char *emsg) 386edit_finished (void *cls, const char *emsg)
385{ 387{
386 struct RequestHandle *handle = cls; 388 struct RequestHandle *handle = cls;
387 struct MHD_Response *resp; 389 struct MHD_Response *resp;
388 390
389 handle->op = NULL; 391 handle->op = NULL;
390 if (NULL != emsg) 392 if (NULL != emsg)
391 { 393 {
@@ -427,7 +429,6 @@ ego_create_cont (struct RestConnectionDataHandle *con,
427 json_t *egoname_json; 429 json_t *egoname_json;
428 char term_data[handle->data_size+1]; 430 char term_data[handle->data_size+1];
429 const char* egoname; 431 const char* egoname;
430
431 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) 432 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
432 { 433 {
433 GNUNET_SCHEDULER_add_now (&do_error, handle); 434 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -441,19 +442,20 @@ ego_create_cont (struct RestConnectionDataHandle *con,
441 term_data[handle->data_size] = '\0'; 442 term_data[handle->data_size] = '\0';
442 memcpy (term_data, handle->data, handle->data_size); 443 memcpy (term_data, handle->data, handle->data_size);
443 json_obj = GNUNET_REST_jsonapi_object_parse (term_data); 444 json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
444 445GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "2\n");
445 if (NULL == json_obj) 446 if (NULL == json_obj)
446 { 447 {
447 GNUNET_SCHEDULER_add_now (&do_error, handle); 448 GNUNET_SCHEDULER_add_now (&do_error, handle);
448 return; 449 return;
449 } 450 }
451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "2.1\n");
450 if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj)) 452 if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
451 { 453 {
452 GNUNET_REST_jsonapi_object_delete (json_obj); 454 GNUNET_REST_jsonapi_object_delete (json_obj);
453 GNUNET_SCHEDULER_add_now (&do_error, handle); 455 GNUNET_SCHEDULER_add_now (&do_error, handle);
454 return; 456 return;
455 } 457 }
456 458GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "3\n");
457 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0); 459 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
458 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 460 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
459 { 461 {
@@ -463,7 +465,7 @@ ego_create_cont (struct RestConnectionDataHandle *con,
463 cleanup_handle (handle); 465 cleanup_handle (handle);
464 return; 466 return;
465 } 467 }
466 468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "4\n");
467 egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_KEY_ID); 469 egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_KEY_ID);
468 if (!json_is_string (egoname_json)) 470 if (!json_is_string (egoname_json))
469 { 471 {
@@ -496,7 +498,7 @@ ego_create_cont (struct RestConnectionDataHandle *con,
496} 498}
497 499
498void 500void
499subsys_set_cont (struct RestConnectionDataHandle *con, 501ego_edit_cont (struct RestConnectionDataHandle *con,
500 const char *url, 502 const char *url,
501 void *cls) 503 void *cls)
502{ 504{
@@ -504,12 +506,14 @@ subsys_set_cont (struct RestConnectionDataHandle *con,
504 struct JsonApiResource *json_res; 506 struct JsonApiResource *json_res;
505 const char *egoname; 507 const char *egoname;
506 const char *subsys; 508 const char *subsys;
509 const char *newname;
507 struct RequestHandle *handle = cls; 510 struct RequestHandle *handle = cls;
508 char term_data[handle->data_size+1]; 511 char term_data[handle->data_size+1];
509 struct EgoEntry *ego_entry; 512 struct EgoEntry *ego_entry;
510 struct MHD_Response *resp; 513 struct MHD_Response *resp;
511 int ego_exists = GNUNET_NO; 514 int ego_exists = GNUNET_NO;
512 json_t *subsys_json; 515 json_t *subsys_json;
516 json_t *name_json;
513 517
514 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url)) 518 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
515 { 519 {
@@ -557,39 +561,55 @@ subsys_set_cont (struct RestConnectionDataHandle *con,
557 GNUNET_SCHEDULER_add_now (&do_error, handle); 561 GNUNET_SCHEDULER_add_now (&do_error, handle);
558 return; 562 return;
559 } 563 }
560 564 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
561 json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0); 565 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO))
562 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_id (json_res, egoname))
563 { 566 {
564 GNUNET_REST_jsonapi_object_delete (json_obj); 567 GNUNET_REST_jsonapi_object_delete (json_obj);
565 GNUNET_SCHEDULER_add_now (&do_error, handle); 568 GNUNET_SCHEDULER_add_now (&do_error, handle);
566 return; 569 return;
567 } 570 }
568 571 //This is a rename
569 if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_id (json_res, GNUNET_REST_JSONAPI_IDENTITY_EGO)) 572 name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
573 if (NULL != name_json)
570 { 574 {
571 GNUNET_REST_jsonapi_object_delete (json_obj); 575 newname = NULL;
572 GNUNET_SCHEDULER_add_now (&do_error, handle); 576 if (json_is_string (name_json))
573 return; 577 {
578 newname = json_string_value (name_json);
579 handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
580 egoname,
581 newname,
582 &edit_finished,
583 handle);
584 GNUNET_REST_jsonapi_object_delete (json_obj);
585 json_decref (name_json);
586 return;
587 }
588 json_decref (name_json);
574 } 589 }
575 590
576 subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM); 591 subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
577 if (!json_is_string (subsys_json)) 592 if (NULL != subsys_json)
578 { 593 {
594 subsys = NULL;
595 if (json_is_string (subsys_json))
596 {
597 subsys = json_string_value (subsys_json);
598 GNUNET_asprintf (&handle->subsys, "%s", subsys);
599 GNUNET_REST_jsonapi_object_delete (json_obj);
600 handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
601 handle->subsys,
602 ego_entry->ego,
603 &edit_finished,
604 handle);
605 json_decref (subsys_json);
606 return;
607 }
579 json_decref (subsys_json); 608 json_decref (subsys_json);
580 GNUNET_REST_jsonapi_object_delete (json_obj);
581 GNUNET_SCHEDULER_add_now (&do_error, handle);
582 return;
583 } 609 }
584 subsys = json_string_value (subsys_json);
585 GNUNET_asprintf (&handle->subsys, "%s", subsys);
586 json_decref (subsys_json);
587 GNUNET_REST_jsonapi_object_delete (json_obj); 610 GNUNET_REST_jsonapi_object_delete (json_obj);
588 handle->op = GNUNET_IDENTITY_set (handle->identity_handle, 611 GNUNET_SCHEDULER_add_now (&do_error, handle);
589 handle->subsys, 612
590 ego_entry->ego,
591 &set_finished,
592 handle);
593} 613}
594 614
595void 615void
@@ -640,7 +660,7 @@ init_cont (struct RequestHandle *handle)
640 static const struct GNUNET_REST_RestConnectionHandler handlers[] = { 660 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
641 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response}, 661 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
642 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont}, 662 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
643 {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &subsys_set_cont}, 663 {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont},
644 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont}, 664 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
645 GNUNET_REST_HANDLER_END 665 GNUNET_REST_HANDLER_END
646 }; 666 };