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