diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-05-06 19:55:55 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-05-06 19:55:55 +0200 |
commit | 3285ce77d9e6a6ce9c7e97e21dc319bc3b8a07e6 (patch) | |
tree | e9e9a6203222dce16f01dae20c0c027069ae4526 | |
parent | 92160158232a0f7db3c438d5e9c61be3387d7d67 (diff) | |
download | anastasis-3285ce77d9e6a6ce9c7e97e21dc319bc3b8a07e6.tar.gz anastasis-3285ce77d9e6a6ce9c7e97e21dc319bc3b8a07e6.zip |
simplify code by using latest taler_mhd_lib convenience functions
-rw-r--r-- | src/backend/anastasis-httpd_policy-upload.c | 93 | ||||
-rw-r--r-- | src/backend/anastasis-httpd_truth-solve.c | 38 | ||||
-rw-r--r-- | src/backend/anastasis-httpd_truth-upload.c | 78 |
3 files changed, 21 insertions, 188 deletions
diff --git a/src/backend/anastasis-httpd_policy-upload.c b/src/backend/anastasis-httpd_policy-upload.c index 8670483..c4febb2 100644 --- a/src/backend/anastasis-httpd_policy-upload.c +++ b/src/backend/anastasis-httpd_policy-upload.c | |||
@@ -662,34 +662,10 @@ AH_handler_policy_post ( | |||
662 | hc->cc = &cleanup_ctx; | 662 | hc->cc = &cleanup_ctx; |
663 | puc->con = connection; | 663 | puc->con = connection; |
664 | 664 | ||
665 | { | 665 | TALER_MHD_parse_request_header_auto (connection, |
666 | const char *pay_id; | 666 | ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER, |
667 | 667 | &puc->payment_identifier, | |
668 | pay_id = MHD_lookup_connection_value (connection, | 668 | puc->payment_identifier_provided); |
669 | MHD_HEADER_KIND, | ||
670 | ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER); | ||
671 | if (NULL != pay_id) | ||
672 | { | ||
673 | if (GNUNET_OK != | ||
674 | GNUNET_STRINGS_string_to_data ( | ||
675 | pay_id, | ||
676 | strlen (pay_id), | ||
677 | &puc->payment_identifier, | ||
678 | sizeof (struct ANASTASIS_PaymentSecretP))) | ||
679 | { | ||
680 | GNUNET_break_op (0); | ||
681 | return TALER_MHD_reply_with_error (connection, | ||
682 | MHD_HTTP_BAD_REQUEST, | ||
683 | TALER_EC_GENERIC_PARAMETER_MALFORMED, | ||
684 | ANASTASIS_HTTP_HEADER_PAYMENT_IDENTIFIER | ||
685 | " header must be a base32-encoded Payment-Secret"); | ||
686 | } | ||
687 | puc->payment_identifier_provided = true; | ||
688 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
689 | "Policy upload started with payment identifier `%s'\n", | ||
690 | pay_id); | ||
691 | } | ||
692 | } | ||
693 | puc->account = *account_pub; | 669 | puc->account = *account_pub; |
694 | 670 | ||
695 | /* check for meta-data */ | 671 | /* check for meta-data */ |
@@ -768,28 +744,10 @@ AH_handler_policy_post ( | |||
768 | } | 744 | } |
769 | puc->upload_size = (size_t) len; | 745 | puc->upload_size = (size_t) len; |
770 | } | 746 | } |
771 | { | ||
772 | /* Check if header contains Anastasis-Policy-Signature */ | ||
773 | const char *sig_s; | ||
774 | 747 | ||
775 | sig_s = MHD_lookup_connection_value (connection, | 748 | TALER_MHD_parse_request_header_auto_t (connection, |
776 | MHD_HEADER_KIND, | 749 | ANASTASIS_HTTP_HEADER_POLICY_SIGNATURE, |
777 | ANASTASIS_HTTP_HEADER_POLICY_SIGNATURE); | 750 | &puc->account_sig); |
778 | if ( (NULL == sig_s) || | ||
779 | (GNUNET_OK != | ||
780 | GNUNET_STRINGS_string_to_data (sig_s, | ||
781 | strlen (sig_s), | ||
782 | &puc->account_sig, | ||
783 | sizeof (puc->account_sig))) ) | ||
784 | { | ||
785 | GNUNET_break_op (0); | ||
786 | return TALER_MHD_reply_with_error (connection, | ||
787 | MHD_HTTP_BAD_REQUEST, | ||
788 | TALER_EC_ANASTASIS_POLICY_BAD_SIGNATURE, | ||
789 | ANASTASIS_HTTP_HEADER_POLICY_SIGNATURE | ||
790 | " header must include a base32-encoded EdDSA signature"); | ||
791 | } | ||
792 | } | ||
793 | { | 751 | { |
794 | /* Check if header contains an ETAG */ | 752 | /* Check if header contains an ETAG */ |
795 | const char *etag; | 753 | const char *etag; |
@@ -834,39 +792,10 @@ AH_handler_policy_post ( | |||
834 | } | 792 | } |
835 | } | 793 | } |
836 | 794 | ||
837 | { | 795 | puc->timeout = GNUNET_TIME_relative_to_absolute ( |
838 | const char *long_poll_timeout_ms; | 796 | CHECK_PAYMENT_GENERIC_TIMEOUT); |
839 | 797 | TALER_MHD_parse_request_timeout (connection, | |
840 | long_poll_timeout_ms = MHD_lookup_connection_value (connection, | 798 | &puc->timeout); |
841 | MHD_GET_ARGUMENT_KIND, | ||
842 | "timeout_ms"); | ||
843 | if (NULL != long_poll_timeout_ms) | ||
844 | { | ||
845 | unsigned int timeout; | ||
846 | char dummy; | ||
847 | |||
848 | if (1 != sscanf (long_poll_timeout_ms, | ||
849 | "%u%c", | ||
850 | &timeout, | ||
851 | &dummy)) | ||
852 | { | ||
853 | GNUNET_break_op (0); | ||
854 | return TALER_MHD_reply_with_error (connection, | ||
855 | MHD_HTTP_BAD_REQUEST, | ||
856 | TALER_EC_GENERIC_PARAMETER_MALFORMED, | ||
857 | "timeout_ms (must be non-negative number)"); | ||
858 | } | ||
859 | puc->timeout | ||
860 | = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | ||
861 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
862 | timeout)); | ||
863 | } | ||
864 | else | ||
865 | { | ||
866 | puc->timeout = GNUNET_TIME_relative_to_absolute ( | ||
867 | CHECK_PAYMENT_GENERIC_TIMEOUT); | ||
868 | } | ||
869 | } | ||
870 | 799 | ||
871 | /* check if the client insists on paying */ | 800 | /* check if the client insists on paying */ |
872 | { | 801 | { |
diff --git a/src/backend/anastasis-httpd_truth-solve.c b/src/backend/anastasis-httpd_truth-solve.c index 957d924..deb1ee2 100644 --- a/src/backend/anastasis-httpd_truth-solve.c +++ b/src/backend/anastasis-httpd_truth-solve.c | |||
@@ -1140,40 +1140,10 @@ AH_handler_truth_solve ( | |||
1140 | gc->connection = connection; | 1140 | gc->connection = connection; |
1141 | gc->truth_uuid = *truth_uuid; | 1141 | gc->truth_uuid = *truth_uuid; |
1142 | gc->hc->cc = &request_done; | 1142 | gc->hc->cc = &request_done; |
1143 | 1143 | gc->timeout = GNUNET_TIME_relative_to_absolute ( | |
1144 | { | 1144 | GNUNET_TIME_UNIT_SECONDS); |
1145 | const char *long_poll_timeout_ms; | 1145 | TALER_MHD_parse_request_timeout (connection, |
1146 | 1146 | &gc->timeout); | |
1147 | long_poll_timeout_ms = MHD_lookup_connection_value (connection, | ||
1148 | MHD_GET_ARGUMENT_KIND, | ||
1149 | "timeout_ms"); | ||
1150 | if (NULL != long_poll_timeout_ms) | ||
1151 | { | ||
1152 | unsigned int timeout; | ||
1153 | char dummy; | ||
1154 | |||
1155 | if (1 != sscanf (long_poll_timeout_ms, | ||
1156 | "%u%c", | ||
1157 | &timeout, | ||
1158 | &dummy)) | ||
1159 | { | ||
1160 | GNUNET_break_op (0); | ||
1161 | return TALER_MHD_reply_with_error (connection, | ||
1162 | MHD_HTTP_BAD_REQUEST, | ||
1163 | TALER_EC_GENERIC_PARAMETER_MALFORMED, | ||
1164 | "timeout_ms (must be non-negative number)"); | ||
1165 | } | ||
1166 | gc->timeout | ||
1167 | = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | ||
1168 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
1169 | timeout)); | ||
1170 | } | ||
1171 | else | ||
1172 | { | ||
1173 | gc->timeout = GNUNET_TIME_relative_to_absolute ( | ||
1174 | GNUNET_TIME_UNIT_SECONDS); | ||
1175 | } | ||
1176 | } | ||
1177 | } /* end of first-time initialization (if NULL == gc) */ | 1147 | } /* end of first-time initialization (if NULL == gc) */ |
1178 | else | 1148 | else |
1179 | { | 1149 | { |
diff --git a/src/backend/anastasis-httpd_truth-upload.c b/src/backend/anastasis-httpd_truth-upload.c index 362d7e1..2872eb3 100644 --- a/src/backend/anastasis-httpd_truth-upload.c +++ b/src/backend/anastasis-httpd_truth-upload.c | |||
@@ -549,78 +549,12 @@ AH_handler_truth_post ( | |||
549 | tuc->truth_uuid = *truth_uuid; | 549 | tuc->truth_uuid = *truth_uuid; |
550 | hc->ctx = tuc; | 550 | hc->ctx = tuc; |
551 | hc->cc = &cleanup_truth_post; | 551 | hc->cc = &cleanup_truth_post; |
552 | 552 | TALER_MHD_check_content_length (connection, | |
553 | /* check for excessive upload */ | 553 | AH_upload_limit_mb * 1024LLU * 1024LLU); |
554 | { | 554 | tuc->timeout = GNUNET_TIME_relative_to_absolute ( |
555 | const char *lens; | 555 | GNUNET_TIME_UNIT_SECONDS); |
556 | unsigned long len; | 556 | TALER_MHD_parse_request_timeout (connection, |
557 | char dummy; | 557 | &tuc->timeout); |
558 | |||
559 | lens = MHD_lookup_connection_value (connection, | ||
560 | MHD_HEADER_KIND, | ||
561 | MHD_HTTP_HEADER_CONTENT_LENGTH); | ||
562 | if ( (NULL == lens) || | ||
563 | (1 != sscanf (lens, | ||
564 | "%lu%c", | ||
565 | &len, | ||
566 | &dummy)) ) | ||
567 | { | ||
568 | GNUNET_break_op (0); | ||
569 | return TALER_MHD_reply_with_error ( | ||
570 | connection, | ||
571 | MHD_HTTP_BAD_REQUEST, | ||
572 | (NULL == lens) | ||
573 | ? TALER_EC_ANASTASIS_GENERIC_MISSING_CONTENT_LENGTH | ||
574 | : TALER_EC_ANASTASIS_GENERIC_MALFORMED_CONTENT_LENGTH, | ||
575 | NULL); | ||
576 | } | ||
577 | if (len / 1024 / 1024 >= AH_upload_limit_mb) | ||
578 | { | ||
579 | GNUNET_break_op (0); | ||
580 | return TALER_MHD_reply_with_error (connection, | ||
581 | MHD_HTTP_PAYLOAD_TOO_LARGE, | ||
582 | TALER_EC_SYNC_MALFORMED_CONTENT_LENGTH, | ||
583 | "Content-length value not acceptable"); | ||
584 | } | ||
585 | } | ||
586 | |||
587 | { | ||
588 | const char *long_poll_timeout_ms; | ||
589 | |||
590 | long_poll_timeout_ms = MHD_lookup_connection_value (connection, | ||
591 | MHD_GET_ARGUMENT_KIND, | ||
592 | "timeout_ms"); | ||
593 | if (NULL != long_poll_timeout_ms) | ||
594 | { | ||
595 | unsigned int timeout; | ||
596 | char dummy; | ||
597 | |||
598 | if (1 != sscanf (long_poll_timeout_ms, | ||
599 | "%u%c", | ||
600 | &timeout, | ||
601 | &dummy)) | ||
602 | { | ||
603 | GNUNET_break_op (0); | ||
604 | return TALER_MHD_reply_with_error (connection, | ||
605 | MHD_HTTP_BAD_REQUEST, | ||
606 | TALER_EC_GENERIC_PARAMETER_MALFORMED, | ||
607 | "timeout_ms (must be non-negative number)"); | ||
608 | } | ||
609 | tuc->timeout | ||
610 | = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( | ||
611 | GNUNET_TIME_UNIT_MILLISECONDS, | ||
612 | timeout)); | ||
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
614 | "Long polling for %u ms enabled\n", | ||
615 | timeout); | ||
616 | } | ||
617 | else | ||
618 | { | ||
619 | tuc->timeout = GNUNET_TIME_relative_to_absolute ( | ||
620 | GNUNET_TIME_UNIT_SECONDS); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | } /* end 'if (NULL == tuc)' */ | 558 | } /* end 'if (NULL == tuc)' */ |
625 | 559 | ||
626 | if (NULL != tuc->resp) | 560 | if (NULL != tuc->resp) |