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