diff options
-rw-r--r-- | src/identity/plugin_rest_identity.c | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 0d55a4cc7..3257b38d5 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -367,7 +367,7 @@ ego_info_response (struct RequestHandle *handle) | |||
367 | json_decref (ego_json); | 367 | json_decref (ego_json); |
368 | 368 | ||
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
370 | handle->proc (handle->proc_cls, result_str, strlen (result_str), GNUNET_OK); | 370 | handle->proc (handle->proc_cls, result_str, strlen (result_str), MHD_HTTP_OK); |
371 | GNUNET_free (result_str); | 371 | GNUNET_free (result_str); |
372 | cleanup_handle (handle); | 372 | cleanup_handle (handle); |
373 | 373 | ||
@@ -382,12 +382,43 @@ do_finished (void *cls, const char *emsg) | |||
382 | if (NULL != emsg) | 382 | if (NULL != emsg) |
383 | { | 383 | { |
384 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 384 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
385 | return; | ||
385 | } | 386 | } |
386 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_OK); | 387 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_OK); |
387 | cleanup_handle (handle); | 388 | cleanup_handle (handle); |
388 | } | 389 | } |
389 | 390 | ||
390 | static void | 391 | static void |
392 | set_finished (void *cls, const char *emsg) | ||
393 | { | ||
394 | struct RequestHandle *handle = cls; | ||
395 | |||
396 | handle->op = NULL; | ||
397 | if (NULL != emsg) | ||
398 | { | ||
399 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
400 | return; | ||
401 | } | ||
402 | handle->proc (handle->proc_cls, NULL, 0, MHD_HTTP_NO_CONTENT); | ||
403 | cleanup_handle (handle); | ||
404 | } | ||
405 | |||
406 | static void | ||
407 | create_finished (void *cls, const char *emsg) | ||
408 | { | ||
409 | struct RequestHandle *handle = cls; | ||
410 | |||
411 | handle->op = NULL; | ||
412 | if (NULL != emsg) | ||
413 | { | ||
414 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
415 | return; | ||
416 | } | ||
417 | handle->proc (handle->proc_cls, NULL, 0, MHD_HTTP_NO_CONTENT); | ||
418 | cleanup_handle (handle); | ||
419 | } | ||
420 | |||
421 | static void | ||
391 | ego_create_cont (struct RequestHandle *handle) | 422 | ego_create_cont (struct RequestHandle *handle) |
392 | { | 423 | { |
393 | const char* egoname; | 424 | const char* egoname; |
@@ -450,7 +481,7 @@ ego_create_cont (struct RequestHandle *handle) | |||
450 | json_decref (root_json); | 481 | json_decref (root_json); |
451 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 482 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
452 | handle->name, | 483 | handle->name, |
453 | &do_finished, | 484 | &create_finished, |
454 | handle); | 485 | handle); |
455 | } | 486 | } |
456 | 487 | ||
@@ -463,10 +494,13 @@ subsys_set_cont (struct RequestHandle *handle) | |||
463 | struct EgoEntry *ego_entry; | 494 | struct EgoEntry *ego_entry; |
464 | int ego_exists = GNUNET_NO; | 495 | int ego_exists = GNUNET_NO; |
465 | json_t *root_json; | 496 | json_t *root_json; |
497 | json_t *data_json; | ||
498 | json_t *type_json; | ||
499 | json_t *id_json; | ||
466 | json_t *subsys_json; | 500 | json_t *subsys_json; |
467 | json_error_t error; | 501 | json_error_t error; |
468 | 502 | ||
469 | if (strlen (API_NAMESPACE) >= strlen (handle->url)) | 503 | if (strlen (API_NAMESPACE) > strlen (handle->url)) |
470 | { | 504 | { |
471 | GNUNET_break(0); | 505 | GNUNET_break(0); |
472 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 506 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
@@ -474,7 +508,7 @@ subsys_set_cont (struct RequestHandle *handle) | |||
474 | return; | 508 | return; |
475 | } | 509 | } |
476 | 510 | ||
477 | egoname = &handle->url[strlen(API_NAMESPACE)+1]; | 511 | egoname = &handle->url[strlen(EGO_NAMESPACE)+1]; |
478 | for (ego_entry = handle->ego_head; | 512 | for (ego_entry = handle->ego_head; |
479 | NULL != ego_entry; | 513 | NULL != ego_entry; |
480 | ego_entry = ego_entry->next) | 514 | ego_entry = ego_entry->next) |
@@ -507,15 +541,48 @@ subsys_set_cont (struct RequestHandle *handle) | |||
507 | 541 | ||
508 | if ((NULL == root_json) || !json_is_object (root_json)) | 542 | if ((NULL == root_json) || !json_is_object (root_json)) |
509 | { | 543 | { |
510 | GNUNET_break(0); | ||
511 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 544 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
512 | cleanup_handle (handle); | 545 | cleanup_handle (handle); |
513 | return; | 546 | return; |
514 | } | 547 | } |
515 | subsys_json = json_object_get (root_json, "subsystem"); | 548 | data_json = json_object_get (root_json, "data"); |
549 | if (!json_is_object (data_json)) | ||
550 | { | ||
551 | json_decref (root_json); | ||
552 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
553 | cleanup_handle (handle); | ||
554 | return; | ||
555 | } | ||
556 | id_json = json_object_get (data_json, "id"); | ||
557 | if (!json_is_string (id_json) || | ||
558 | (0 != strcmp (egoname, json_string_value (id_json)))) | ||
559 | { | ||
560 | json_decref (root_json); | ||
561 | json_decref (data_json); | ||
562 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
563 | cleanup_handle (handle); | ||
564 | return; | ||
565 | } | ||
566 | json_decref (id_json); | ||
567 | |||
568 | type_json = json_object_get (data_json, "type"); | ||
569 | if (!json_is_string (type_json) || | ||
570 | (0 != strcmp (JSON_API_TYPE_EGO, json_string_value (type_json)))) | ||
571 | { | ||
572 | json_decref (root_json); | ||
573 | json_decref (data_json); | ||
574 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | ||
575 | cleanup_handle (handle); | ||
576 | GNUNET_break (0); | ||
577 | return; | ||
578 | } | ||
579 | json_decref (type_json); | ||
580 | |||
581 | subsys_json = json_object_get (data_json, "subsystem"); | ||
516 | if (!json_is_string (subsys_json)) | 582 | if (!json_is_string (subsys_json)) |
517 | { | 583 | { |
518 | GNUNET_break(0); | 584 | json_decref (root_json); |
585 | json_decref (data_json); | ||
519 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); | 586 | handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR); |
520 | cleanup_handle (handle); | 587 | cleanup_handle (handle); |
521 | return; | 588 | return; |
@@ -527,7 +594,7 @@ subsys_set_cont (struct RequestHandle *handle) | |||
527 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 594 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, |
528 | handle->subsys, | 595 | handle->subsys, |
529 | ego_entry->ego, | 596 | ego_entry->ego, |
530 | &do_finished, | 597 | &set_finished, |
531 | handle); | 598 | handle); |
532 | } | 599 | } |
533 | 600 | ||