Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2016-2024 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or
6 : modify it under the terms of the GNU General Public License
7 : as 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,
11 : but 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 bank-lib/fakebank_twg_admin_add_kycauth.c
21 : * @brief library that fakes being a Taler bank for testcases
22 : * @author Christian Grothoff <christian@grothoff.org>
23 : */
24 : #include "taler/platform.h"
25 : #include "taler/taler_fakebank_lib.h"
26 : #include "taler/taler_bank_service.h"
27 : #include "taler/taler_mhd_lib.h"
28 : #include <gnunet/gnunet_mhd_compat.h>
29 : #include <gnunet/gnunet_mhd_lib.h>
30 : #include "fakebank.h"
31 : #include "fakebank_common_make_admin_transfer.h"
32 : #include "fakebank_twg_admin_add_kycauth.h"
33 :
34 :
35 : MHD_RESULT
36 48 : TALER_FAKEBANK_twg_admin_add_kycauth_ (
37 : struct TALER_FAKEBANK_Handle *h,
38 : struct MHD_Connection *connection,
39 : const char *account,
40 : const char *upload_data,
41 : size_t *upload_data_size,
42 : void **con_cls)
43 : {
44 48 : struct ConnectionContext *cc = *con_cls;
45 : enum GNUNET_MHD_PostResult pr;
46 : json_t *json;
47 : uint64_t row_id;
48 : struct GNUNET_TIME_Timestamp timestamp;
49 :
50 48 : if (NULL == cc)
51 : {
52 16 : cc = GNUNET_new (struct ConnectionContext);
53 16 : cc->ctx_cleaner = &GNUNET_MHD_post_parser_cleanup;
54 16 : *con_cls = cc;
55 : }
56 48 : pr = GNUNET_MHD_post_parser (REQUEST_BUFFER_MAX,
57 : connection,
58 : &cc->ctx,
59 : upload_data,
60 : upload_data_size,
61 : &json);
62 48 : switch (pr)
63 : {
64 0 : case GNUNET_MHD_PR_OUT_OF_MEMORY:
65 0 : GNUNET_break (0);
66 0 : return MHD_NO;
67 32 : case GNUNET_MHD_PR_CONTINUE:
68 32 : return MHD_YES;
69 0 : case GNUNET_MHD_PR_REQUEST_TOO_LARGE:
70 0 : GNUNET_break (0);
71 0 : return MHD_NO;
72 0 : case GNUNET_MHD_PR_JSON_INVALID:
73 0 : GNUNET_break (0);
74 0 : return MHD_NO;
75 16 : case GNUNET_MHD_PR_SUCCESS:
76 16 : break;
77 : }
78 : {
79 : struct TALER_FullPayto debit_account;
80 : struct TALER_Amount amount;
81 : union TALER_AccountPublicKeyP account_pub;
82 : char *debit;
83 : enum GNUNET_GenericReturnValue ret;
84 : struct GNUNET_JSON_Specification spec[] = {
85 16 : GNUNET_JSON_spec_fixed_auto ("account_pub",
86 : &account_pub),
87 16 : TALER_JSON_spec_full_payto_uri ("debit_account",
88 : &debit_account),
89 16 : TALER_JSON_spec_amount ("amount",
90 16 : h->currency,
91 : &amount),
92 16 : GNUNET_JSON_spec_end ()
93 : };
94 :
95 16 : if (GNUNET_OK !=
96 16 : (ret = TALER_MHD_parse_json_data (connection,
97 : json,
98 : spec)))
99 : {
100 0 : GNUNET_break_op (0);
101 0 : json_decref (json);
102 0 : return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
103 : }
104 16 : if (0 != strcasecmp (amount.currency,
105 16 : h->currency))
106 : {
107 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 : "Currency `%s' does not match our configuration\n",
109 : amount.currency);
110 0 : json_decref (json);
111 0 : return TALER_MHD_reply_with_error (
112 : connection,
113 : MHD_HTTP_CONFLICT,
114 : TALER_EC_GENERIC_CURRENCY_MISMATCH,
115 : NULL);
116 : }
117 16 : debit = TALER_xtalerbank_account_from_payto (debit_account);
118 16 : if (NULL == debit)
119 : {
120 0 : GNUNET_break_op (0);
121 0 : return TALER_MHD_reply_with_error (
122 : connection,
123 : MHD_HTTP_BAD_REQUEST,
124 : TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
125 0 : debit_account.full_payto);
126 : }
127 16 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
128 : "Receiving kycauth wire transfer: %s->%s, subject: %s, amount: %s\n",
129 : debit,
130 : account,
131 : TALER_B2S (&account_pub),
132 : TALER_amount2s (&amount));
133 16 : ret = TALER_FAKEBANK_make_kycauth_transfer_ (h,
134 : debit,
135 : account,
136 : &amount,
137 : &account_pub,
138 : &row_id,
139 : ×tamp);
140 16 : GNUNET_free (debit);
141 16 : if (GNUNET_OK != ret)
142 : {
143 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
144 : "Failed to make wire transfer\n");
145 0 : json_decref (json);
146 0 : return TALER_MHD_reply_with_error (
147 : connection,
148 : MHD_HTTP_INTERNAL_SERVER_ERROR,
149 : TALER_EC_GENERIC_ALLOCATION_FAILURE,
150 : NULL);
151 : }
152 : }
153 16 : json_decref (json);
154 :
155 : /* Finally build response object */
156 16 : return TALER_MHD_REPLY_JSON_PACK (connection,
157 : MHD_HTTP_OK,
158 : GNUNET_JSON_pack_uint64 ("row_id",
159 : row_id),
160 : GNUNET_JSON_pack_timestamp ("timestamp",
161 : timestamp));
162 : }
|