aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent726b28a61c858b4b251e4a0a006e4021b01886c0 (diff)
downloadgnunet-9cbff235e16bb2888aca2ba492f46bca9351142d.tar.gz
gnunet-9cbff235e16bb2888aca2ba492f46bca9351142d.zip
-add rename
Diffstat (limited to 'src')
-rw-r--r--src/identity/plugin_rest_identity.c76
-rw-r--r--src/rest/rest.c19
2 files changed, 56 insertions, 39 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 };
diff --git a/src/rest/rest.c b/src/rest/rest.c
index f3251db1a..225798db9 100644
--- a/src/rest/rest.c
+++ b/src/rest/rest.c
@@ -188,7 +188,7 @@ int
188GNUNET_REST_jsonapi_resource_check_id (const struct JsonApiResource *resource, 188GNUNET_REST_jsonapi_resource_check_id (const struct JsonApiResource *resource,
189 const char* id) 189 const char* id)
190{ 190{
191 return check_resource_attr_str (resource, id, GNUNET_REST_JSONAPI_KEY_ID); 191 return check_resource_attr_str (resource, GNUNET_REST_JSONAPI_KEY_ID, id);
192} 192}
193 193
194 194
@@ -203,7 +203,7 @@ int
203GNUNET_REST_jsonapi_resource_check_type (const struct JsonApiResource *resource, 203GNUNET_REST_jsonapi_resource_check_type (const struct JsonApiResource *resource,
204 const char* type) 204 const char* type)
205{ 205{
206 return check_resource_attr_str (resource, type, GNUNET_REST_JSONAPI_KEY_TYPE); 206 return check_resource_attr_str (resource, GNUNET_REST_JSONAPI_KEY_TYPE, type);
207} 207}
208 208
209 209
@@ -233,10 +233,8 @@ add_json_resource (struct JsonApiObject *obj,
233 233
234 id_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_ID); 234 id_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_ID);
235 type_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_TYPE); 235 type_json = json_object_get (res_json, GNUNET_REST_JSONAPI_KEY_TYPE);
236
237 if (!json_is_string (id_json) || !json_is_string (type_json)) 236 if (!json_is_string (id_json) || !json_is_string (type_json))
238 return; 237 return;
239
240 res = GNUNET_new (struct JsonApiResource); 238 res = GNUNET_new (struct JsonApiResource);
241 res->next = NULL; 239 res->next = NULL;
242 res->prev = NULL; 240 res->prev = NULL;
@@ -259,7 +257,6 @@ GNUNET_REST_jsonapi_object_parse (const char* data)
259 json_error_t error; 257 json_error_t error;
260 int res_count = 0; 258 int res_count = 0;
261 int i; 259 int i;
262
263 if (NULL == data) 260 if (NULL == data)
264 return NULL; 261 return NULL;
265 root_json = json_loads (data, 0, &error); 262 root_json = json_loads (data, 0, &error);
@@ -287,7 +284,7 @@ GNUNET_REST_jsonapi_object_parse (const char* data)
287 add_json_resource (result, json_array_get (data_json, i)); 284 add_json_resource (result, json_array_get (data_json, i));
288 } 285 }
289 json_decref (root_json); 286 json_decref (root_json);
290 if (0 == res_count) 287 if (0 == result->res_count)
291 { 288 {
292 GNUNET_free (result); 289 GNUNET_free (result);
293 result = NULL; 290 result = NULL;
@@ -366,8 +363,8 @@ GNUNET_REST_jsonapi_object_get_resource (struct JsonApiObject *resp, int num)
366 struct JsonApiResource *res; 363 struct JsonApiResource *res;
367 int i; 364 int i;
368 365
369 if ((0 < resp->res_count) && 366 if ((0 == resp->res_count) ||
370 (num < resp->res_count)) 367 (num >= resp->res_count))
371 return NULL; 368 return NULL;
372 res = resp->res_list_head; 369 res = resp->res_list_head;
373 for (i = 0; i < num; i++) 370 for (i = 0; i < num; i++)
@@ -505,11 +502,11 @@ GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn,
505 for (i = 0; i < count; i++) 502 for (i = 0; i < count; i++)
506 { 503 {
507 if (0 != strcasecmp (conn->method, handlers[i].method)) 504 if (0 != strcasecmp (conn->method, handlers[i].method))
508 break; 505 continue;
509 if (strlen (url) < strlen (handlers[i].namespace)) 506 if (strlen (url) < strlen (handlers[i].namespace))
510 break; 507 continue;
511 if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace)) 508 if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
512 break; 509 continue;
513 //Match 510 //Match
514 handlers[i].proc (conn, (const char*)url, cls); 511 handlers[i].proc (conn, (const char*)url, cls);
515 GNUNET_free (url); 512 GNUNET_free (url);