diff options
-rw-r--r-- | src/escrow/plugin_rest_escrow.c | 82 |
1 files changed, 66 insertions, 16 deletions
diff --git a/src/escrow/plugin_rest_escrow.c b/src/escrow/plugin_rest_escrow.c index 2c81c76c8..d1a7cd1e7 100644 --- a/src/escrow/plugin_rest_escrow.c +++ b/src/escrow/plugin_rest_escrow.c | |||
@@ -112,9 +112,14 @@ | |||
112 | #define GNUNET_REST_ESCROW_ANCHOR_ERROR "Failed to parse anchor" | 112 | #define GNUNET_REST_ESCROW_ANCHOR_ERROR "Failed to parse anchor" |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Parameter anchor | 115 | * Parameter anchor-data |
116 | */ | 116 | */ |
117 | #define GNUNET_REST_ESCROW_PARAM_ANCHOR "anchor" | 117 | #define GNUNET_REST_ESCROW_PARAM_ANCHOR_DATA "anchor-data" |
118 | |||
119 | /** | ||
120 | * Parameter method | ||
121 | */ | ||
122 | #define GNUNET_REST_ESCROW_PARAM_METHOD "method" | ||
118 | 123 | ||
119 | /** | 124 | /** |
120 | * Parameter user-secret | 125 | * Parameter user-secret |
@@ -479,7 +484,8 @@ escrow_finished (void *cls, | |||
479 | struct RequestHandle *handle = cls; | 484 | struct RequestHandle *handle = cls; |
480 | struct MHD_Response *resp; | 485 | struct MHD_Response *resp; |
481 | json_t *json_anchor; | 486 | json_t *json_anchor; |
482 | char *anchor_string, *result_string; | 487 | const char*anchor_data; |
488 | char *anchor_data_enc, *result_string; | ||
483 | 489 | ||
484 | if (NULL == anchor) | 490 | if (NULL == anchor) |
485 | { | 491 | { |
@@ -491,11 +497,19 @@ escrow_finished (void *cls, | |||
491 | return; | 497 | return; |
492 | } | 498 | } |
493 | 499 | ||
494 | anchor_string = GNUNET_ESCROW_anchor_data_to_string (anchor); | ||
495 | json_anchor = json_object (); | 500 | json_anchor = json_object (); |
496 | json_object_set_new (json_anchor, | 501 | json_object_set_new (json_anchor, |
497 | GNUNET_REST_ESCROW_PARAM_ANCHOR, | 502 | GNUNET_REST_ESCROW_PARAM_METHOD, |
498 | json_string (anchor_string)); | 503 | json_string (GNUNET_ESCROW_method_number_to_string ( |
504 | anchor->method))); | ||
505 | json_object_set_new (json_anchor, | ||
506 | GNUNET_REST_ESCROW_PARAM_NAME, | ||
507 | json_string (anchor->egoName)); | ||
508 | anchor_data = (const char *)&anchor[1]; | ||
509 | GNUNET_STRINGS_urlencode (anchor_data, anchor->size, &anchor_data_enc); | ||
510 | json_object_set_new (json_anchor, | ||
511 | GNUNET_REST_ESCROW_PARAM_ANCHOR_DATA, | ||
512 | json_string (anchor_data_enc)); | ||
499 | 513 | ||
500 | result_string = json_dumps (json_anchor, 0); | 514 | result_string = json_dumps (json_anchor, 0); |
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_string); | 515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_string); |
@@ -505,7 +519,7 @@ escrow_finished (void *cls, | |||
505 | 519 | ||
506 | json_decref (json_anchor); | 520 | json_decref (json_anchor); |
507 | GNUNET_free (result_string); | 521 | GNUNET_free (result_string); |
508 | GNUNET_free (anchor_string); | 522 | GNUNET_free (anchor_data_enc); |
509 | 523 | ||
510 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 524 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
511 | } | 525 | } |
@@ -594,11 +608,45 @@ escrow_identity (struct GNUNET_REST_RequestHandle *con_handle, | |||
594 | 608 | ||
595 | 609 | ||
596 | static struct GNUNET_ESCROW_Anchor * | 610 | static struct GNUNET_ESCROW_Anchor * |
611 | build_anchor (const char *method_string, | ||
612 | const char *ego_name, | ||
613 | const char *anchor_data_enc) | ||
614 | { | ||
615 | struct GNUNET_ESCROW_Anchor *anchor; | ||
616 | char *ptr; | ||
617 | enum GNUNET_ESCROW_Key_Escrow_Method method; | ||
618 | char *anchor_data; | ||
619 | |||
620 | method = GNUNET_ESCROW_method_string_to_number (method_string); | ||
621 | if (GNUNET_ESCROW_KEY_NONE == method) | ||
622 | return NULL; | ||
623 | GNUNET_STRINGS_urldecode (anchor_data_enc, | ||
624 | strlen (anchor_data_enc), | ||
625 | &anchor_data); | ||
626 | |||
627 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) | ||
628 | + strlen (anchor_data) | ||
629 | + strlen (ego_name) + 1); | ||
630 | anchor->method = method; | ||
631 | anchor->size = strlen (anchor_data); | ||
632 | ptr = (char *)&anchor[1]; | ||
633 | GNUNET_memcpy (ptr, anchor_data, strlen (anchor_data)); | ||
634 | ptr += strlen (anchor_data); | ||
635 | anchor->egoName = ptr; | ||
636 | strcpy (ptr, ego_name); | ||
637 | |||
638 | GNUNET_free (anchor_data); | ||
639 | |||
640 | return anchor; | ||
641 | } | ||
642 | |||
643 | |||
644 | static struct GNUNET_ESCROW_Anchor * | ||
597 | get_anchor_from_payload (struct RequestHandle *handle) | 645 | get_anchor_from_payload (struct RequestHandle *handle) |
598 | { | 646 | { |
599 | json_t *json_data; | 647 | json_t *json_data; |
600 | json_error_t err; | 648 | json_error_t err; |
601 | char *anchor_string; | 649 | char *method, *ego_name, *anchor_data_enc; |
602 | int json_unpack_state; | 650 | int json_unpack_state; |
603 | char term_data[handle->data_size + 1]; | 651 | char term_data[handle->data_size + 1]; |
604 | struct GNUNET_ESCROW_Anchor *anchor; | 652 | struct GNUNET_ESCROW_Anchor *anchor; |
@@ -625,8 +673,10 @@ get_anchor_from_payload (struct RequestHandle *handle) | |||
625 | 673 | ||
626 | json_unpack_state = 0; | 674 | json_unpack_state = 0; |
627 | json_unpack_state = | 675 | json_unpack_state = |
628 | json_unpack (json_data, "{s:s}", | 676 | json_unpack (json_data, "{s:s, s:s, s:s}", |
629 | GNUNET_REST_ESCROW_PARAM_ANCHOR, &anchor_string); | 677 | GNUNET_REST_ESCROW_PARAM_METHOD, &method, |
678 | GNUNET_REST_ESCROW_PARAM_NAME, &ego_name, | ||
679 | GNUNET_REST_ESCROW_PARAM_ANCHOR_DATA, &anchor_data_enc); | ||
630 | if (0 != json_unpack_state) | 680 | if (0 != json_unpack_state) |
631 | { | 681 | { |
632 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 682 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
@@ -636,7 +686,7 @@ get_anchor_from_payload (struct RequestHandle *handle) | |||
636 | return NULL; | 686 | return NULL; |
637 | } | 687 | } |
638 | 688 | ||
639 | if (NULL == anchor_string) | 689 | if (NULL == method || NULL == ego_name || NULL == anchor_data_enc) |
640 | { | 690 | { |
641 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 691 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
642 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 692 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
@@ -644,24 +694,24 @@ get_anchor_from_payload (struct RequestHandle *handle) | |||
644 | json_decref (json_data); | 694 | json_decref (json_data); |
645 | return NULL; | 695 | return NULL; |
646 | } | 696 | } |
647 | if (0 >= strlen (anchor_string)) | 697 | if (0 >= strlen (method) || 0 >= strlen (ego_name) || 0 >= strlen (anchor_data_enc)) |
648 | { | 698 | { |
649 | json_decref (json_data); | ||
650 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 699 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
651 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 700 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
652 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 701 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
702 | json_decref (json_data); | ||
653 | return NULL; | 703 | return NULL; |
654 | } | 704 | } |
655 | 705 | ||
656 | anchor = GNUNET_ESCROW_anchor_string_to_data (anchor_string); | 706 | anchor = build_anchor (method, ego_name, anchor_data_enc); |
657 | if (NULL == anchor) | 707 | if (NULL == anchor) |
658 | { | 708 | { |
659 | json_decref (json_data); | ||
660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
661 | "Failed to parse anchor: %s.\n", anchor_string); | 710 | "Failed to parse anchor.\n"); |
662 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 711 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
663 | handle->emsg = GNUNET_strdup (GNUNET_REST_ESCROW_ANCHOR_ERROR); | 712 | handle->emsg = GNUNET_strdup (GNUNET_REST_ESCROW_ANCHOR_ERROR); |
664 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 713 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
714 | json_decref (json_data); | ||
665 | return NULL; | 715 | return NULL; |
666 | } | 716 | } |
667 | 717 | ||