Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2026 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU Affero General Public License as
7 : published by the Free Software Foundation; either version 3,
8 : or (at your option) any later version.
9 :
10 : TALER is distributed in the hope that it will be useful, but
11 : WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public
16 : License along with TALER; see the file COPYING. If not,
17 : see <http://www.gnu.org/licenses/>
18 : */
19 : /**
20 : * @file src/backend/taler-merchant-httpd_post-private-accept-tos-early.c
21 : * @brief implementing POST /private/accept-tos-early request handling
22 : * @author Christian Grothoff
23 : */
24 : #include "platform.h"
25 : #include "taler-merchant-httpd_post-private-accept-tos-early.h"
26 : #include "taler-merchant-httpd_helper.h"
27 : #include <taler/taler_json_lib.h>
28 : #include "merchant-database/insert_tos_accepted_early.h"
29 :
30 :
31 : /**
32 : * How often do we retry the simple INSERT database transaction?
33 : */
34 : #define MAX_RETRIES 3
35 :
36 :
37 : enum MHD_Result
38 0 : TMH_private_post_accept_tos_early (
39 : const struct TMH_RequestHandler *rh,
40 : struct MHD_Connection *connection,
41 : struct TMH_HandlerContext *hc)
42 : {
43 0 : struct TMH_MerchantInstance *mi = hc->instance;
44 : const char *exchange_url;
45 : const char *tos_version;
46 : struct GNUNET_JSON_Specification spec[] = {
47 0 : TALER_JSON_spec_web_url ("exchange_url",
48 : &exchange_url),
49 0 : GNUNET_JSON_spec_string ("tos_version",
50 : &tos_version),
51 0 : GNUNET_JSON_spec_end ()
52 : };
53 : enum GNUNET_DB_QueryStatus qs;
54 :
55 : (void) rh;
56 0 : GNUNET_assert (NULL != mi);
57 : {
58 : enum GNUNET_GenericReturnValue res;
59 :
60 0 : res = TALER_MHD_parse_json_data (connection,
61 0 : hc->request_body,
62 : spec);
63 0 : if (GNUNET_OK != res)
64 : {
65 0 : GNUNET_break_op (0);
66 : return (GNUNET_NO == res)
67 : ? MHD_YES
68 0 : : MHD_NO;
69 : }
70 : }
71 0 : for (unsigned int i = 0; i < MAX_RETRIES; i++)
72 : {
73 0 : qs = TALER_MERCHANTDB_insert_tos_accepted_early (TMH_db,
74 0 : mi->settings.id,
75 : exchange_url,
76 : tos_version);
77 0 : if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
78 0 : break;
79 : }
80 0 : GNUNET_JSON_parse_free (spec);
81 0 : if (qs < 0)
82 : {
83 0 : GNUNET_break (0);
84 0 : return TALER_MHD_reply_with_error (
85 : connection,
86 : MHD_HTTP_INTERNAL_SERVER_ERROR,
87 : (GNUNET_DB_STATUS_SOFT_ERROR == qs)
88 : ? TALER_EC_GENERIC_DB_SOFT_FAILURE
89 : : TALER_EC_GENERIC_DB_STORE_FAILED,
90 : NULL);
91 : }
92 0 : return TALER_MHD_reply_static (connection,
93 : MHD_HTTP_NO_CONTENT,
94 : NULL,
95 : NULL,
96 : 0);
97 : }
98 :
99 :
100 : /* end of taler-merchant-httpd_post-private-accept-tos-early.c */
|