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_tbi.c
21 : * @brief main entry point to the Taler Bank Integration (TBI) API implementation
22 : * @author Christian Grothoff <christian@grothoff.org>
23 : */
24 : #include "taler/taler_fakebank_lib.h"
25 : #include "taler/taler_bank_service.h"
26 : #include "taler/taler_mhd_lib.h"
27 : #include <gnunet/gnunet_mhd_compat.h>
28 : #include "fakebank.h"
29 : #include "fakebank_tbi.h"
30 : #include "fakebank_tbi_get_withdrawal_operation.h"
31 : #include "fakebank_tbi_post_withdrawal_operation.h"
32 :
33 :
34 : MHD_RESULT
35 0 : TALER_FAKEBANK_tbi_main_ (struct TALER_FAKEBANK_Handle *h,
36 : struct MHD_Connection *connection,
37 : const char *url,
38 : const char *method,
39 : const char *upload_data,
40 : size_t *upload_data_size,
41 : void **con_cls)
42 : {
43 0 : if (0 == strcasecmp (method,
44 : MHD_HTTP_METHOD_HEAD))
45 0 : method = MHD_HTTP_METHOD_GET;
46 0 : if ( (0 == strcmp (url,
47 0 : "/config")) &&
48 0 : (0 == strcasecmp (method,
49 : MHD_HTTP_METHOD_GET)) )
50 : {
51 : struct TALER_Amount zero;
52 :
53 0 : GNUNET_assert (GNUNET_OK ==
54 : TALER_amount_set_zero (h->currency,
55 : &zero));
56 0 : return TALER_MHD_REPLY_JSON_PACK (
57 : connection,
58 : MHD_HTTP_OK,
59 : GNUNET_JSON_pack_string ("version",
60 : "1:0:1"),
61 : GNUNET_JSON_pack_string ("currency",
62 : h->currency),
63 : GNUNET_JSON_pack_string ("implementation",
64 : "urn:net:taler:specs:bank:fakebank"),
65 : GNUNET_JSON_pack_bool ("allow_conversion",
66 : false),
67 : GNUNET_JSON_pack_bool ("allow_registrations",
68 : true),
69 : GNUNET_JSON_pack_bool ("allow_deletions",
70 : false),
71 : GNUNET_JSON_pack_bool ("allow_edit_name",
72 : false),
73 : GNUNET_JSON_pack_bool ("allow_edit_cashout_payto_uri",
74 : false),
75 : TALER_JSON_pack_amount ("default_debit_threshold",
76 : &zero),
77 : GNUNET_JSON_pack_array_steal ("supported_tan_channels",
78 : json_array ()),
79 : GNUNET_JSON_pack_object_steal (
80 : "currency_specification",
81 : GNUNET_JSON_PACK (
82 : GNUNET_JSON_pack_string ("name",
83 : h->currency),
84 : GNUNET_JSON_pack_string ("currency",
85 : h->currency),
86 : GNUNET_JSON_pack_uint64 ("num_fractional_input_digits",
87 : 2),
88 : GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits",
89 : 2),
90 : GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits",
91 : 2),
92 : GNUNET_JSON_pack_object_steal (
93 : "alt_unit_names",
94 : GNUNET_JSON_PACK (
95 : GNUNET_JSON_pack_string ("0",
96 : h->currency))),
97 : GNUNET_JSON_pack_string ("name",
98 : h->currency))),
99 : GNUNET_JSON_pack_string ("name",
100 : "taler-bank-integration"));
101 : }
102 0 : if ( (0 == strncmp (url,
103 : "/withdrawal-operation/",
104 0 : strlen ("/withdrawal-operation/"))) &&
105 0 : (0 == strcasecmp (method,
106 : MHD_HTTP_METHOD_GET)) )
107 : {
108 0 : const char *wopid = &url[strlen ("/withdrawal-operation/")];
109 : const char *lp_s
110 0 : = MHD_lookup_connection_value (connection,
111 : MHD_GET_ARGUMENT_KIND,
112 : "long_poll_ms");
113 0 : struct GNUNET_TIME_Relative lp = GNUNET_TIME_UNIT_ZERO;
114 :
115 0 : if (NULL != lp_s)
116 : {
117 : unsigned long long d;
118 : char dummy;
119 :
120 0 : if (1 != sscanf (lp_s,
121 : "%llu%c",
122 : &d,
123 : &dummy))
124 : {
125 0 : GNUNET_break_op (0);
126 0 : return TALER_MHD_reply_with_error (connection,
127 : MHD_HTTP_BAD_REQUEST,
128 : TALER_EC_GENERIC_PARAMETER_MALFORMED,
129 : "long_poll_ms");
130 : }
131 0 : lp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
132 : d);
133 : }
134 0 : return TALER_FAKEBANK_tbi_get_withdrawal_operation_ (h,
135 : connection,
136 : wopid,
137 : lp,
138 : con_cls);
139 :
140 : }
141 0 : if ( (0 == strncmp (url,
142 : "/withdrawal-operation/",
143 0 : strlen ("/withdrawal-operation/"))) &&
144 0 : (0 == strcasecmp (method,
145 : MHD_HTTP_METHOD_POST)) )
146 : {
147 0 : const char *wopid = &url[strlen ("/withdrawal-operation/")];
148 :
149 0 : return TALER_FAKEBANK_tbi_post_withdrawal (h,
150 : connection,
151 : wopid,
152 : upload_data,
153 : upload_data_size,
154 : con_cls);
155 : }
156 :
157 0 : TALER_LOG_ERROR ("Breaking URL: %s %s\n",
158 : method,
159 : url);
160 0 : GNUNET_break_op (0);
161 0 : return TALER_MHD_reply_with_error (
162 : connection,
163 : MHD_HTTP_NOT_FOUND,
164 : TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
165 : url);
166 : }
|