Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2023, 2025 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 : /**
21 : * @file taler-merchant-httpd_private-patch-accounts-ID.c
22 : * @brief implementing PATCH /accounts/$ID request handling
23 : * @author Christian Grothoff
24 : */
25 : #include "platform.h"
26 : #include "taler-merchant-httpd_private-patch-accounts-ID.h"
27 : #include "taler-merchant-httpd_helper.h"
28 : #include <taler/taler_json_lib.h>
29 : #include "taler-merchant-httpd_mfa.h"
30 :
31 :
32 : /**
33 : * PATCH configuration of an existing instance, given its configuration.
34 : *
35 : * @param rh context of the handler
36 : * @param connection the MHD connection to handle
37 : * @param[in,out] hc context with further information about the request
38 : * @return MHD result code
39 : */
40 : MHD_RESULT
41 0 : TMH_private_patch_accounts_ID (const struct TMH_RequestHandler *rh,
42 : struct MHD_Connection *connection,
43 : struct TMH_HandlerContext *hc)
44 : {
45 0 : struct TMH_MerchantInstance *mi = hc->instance;
46 0 : const char *h_wire_s = hc->infix;
47 : enum GNUNET_DB_QueryStatus qs;
48 : const json_t *cfc;
49 : const char *cfu;
50 : struct TALER_MerchantWireHashP h_wire;
51 : struct GNUNET_JSON_Specification spec[] = {
52 0 : GNUNET_JSON_spec_mark_optional (
53 : TALER_JSON_spec_web_url ("credit_facade_url",
54 : &cfu),
55 : NULL),
56 0 : GNUNET_JSON_spec_mark_optional (
57 : GNUNET_JSON_spec_object_const ("credit_facade_credentials",
58 : &cfc),
59 : NULL),
60 0 : GNUNET_JSON_spec_end ()
61 : };
62 :
63 0 : GNUNET_assert (NULL != mi);
64 0 : GNUNET_assert (NULL != h_wire_s);
65 0 : if (GNUNET_OK !=
66 0 : GNUNET_STRINGS_string_to_data (h_wire_s,
67 : strlen (h_wire_s),
68 : &h_wire,
69 : sizeof (h_wire)))
70 : {
71 0 : GNUNET_break_op (0);
72 0 : return TALER_MHD_reply_with_error (connection,
73 : MHD_HTTP_BAD_REQUEST,
74 : TALER_EC_MERCHANT_GENERIC_H_WIRE_MALFORMED,
75 : h_wire_s);
76 : }
77 : {
78 : enum GNUNET_GenericReturnValue res;
79 :
80 0 : res = TALER_MHD_parse_json_data (connection,
81 0 : hc->request_body,
82 : spec);
83 0 : if (GNUNET_OK != res)
84 : return (GNUNET_NO == res)
85 : ? MHD_YES
86 0 : : MHD_NO;
87 : }
88 :
89 0 : qs = TMH_db->update_account (TMH_db->cls,
90 0 : mi->settings.id,
91 : &h_wire,
92 : cfu,
93 : cfc);
94 : {
95 0 : MHD_RESULT ret = MHD_NO;
96 :
97 0 : switch (qs)
98 : {
99 0 : case GNUNET_DB_STATUS_HARD_ERROR:
100 0 : GNUNET_break (0);
101 0 : ret = TALER_MHD_reply_with_error (connection,
102 : MHD_HTTP_INTERNAL_SERVER_ERROR,
103 : TALER_EC_GENERIC_DB_STORE_FAILED,
104 : "update_account");
105 0 : break;
106 0 : case GNUNET_DB_STATUS_SOFT_ERROR:
107 0 : GNUNET_break (0);
108 0 : ret = TALER_MHD_reply_with_error (connection,
109 : MHD_HTTP_INTERNAL_SERVER_ERROR,
110 : TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
111 : "unexpected serialization problem");
112 0 : break;
113 0 : case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
114 0 : return TALER_MHD_reply_with_error (connection,
115 : MHD_HTTP_NOT_FOUND,
116 : TALER_EC_MERCHANT_GENERIC_ACCOUNT_UNKNOWN,
117 : h_wire_s);
118 : break;
119 0 : case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
120 0 : ret = TALER_MHD_reply_static (connection,
121 : MHD_HTTP_NO_CONTENT,
122 : NULL,
123 : NULL,
124 : 0);
125 0 : break;
126 : }
127 0 : GNUNET_JSON_parse_free (spec);
128 0 : return ret;
129 : }
130 : }
131 :
132 :
133 : /* end of taler-merchant-httpd_private-patch-accounts-ID.c */
|