taler-merchant-httpd_patch-private-accounts-H_WIRE.c (5251B)
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 taler-merchant-httpd_patch-private-accounts-H_WIRE.c 22 * @brief implementing PATCH /accounts/$ID request handling 23 * @author Christian Grothoff 24 */ 25 #include "taler/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 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 TMH_private_patch_accounts_ID (const struct TMH_RequestHandler *rh, 42 struct MHD_Connection *connection, 43 struct TMH_HandlerContext *hc) 44 { 45 struct TMH_MerchantInstance *mi = hc->instance; 46 const char *h_wire_s = hc->infix; 47 enum GNUNET_DB_QueryStatus qs; 48 const json_t *cfc; 49 const char *extra_wire_subject_metadata = NULL; 50 const char *cfu; 51 struct TALER_MerchantWireHashP h_wire; 52 struct GNUNET_JSON_Specification spec[] = { 53 GNUNET_JSON_spec_mark_optional ( 54 TALER_JSON_spec_web_url ("credit_facade_url", 55 &cfu), 56 NULL), 57 GNUNET_JSON_spec_mark_optional ( 58 GNUNET_JSON_spec_string ("extra_wire_subject_metadata", 59 &extra_wire_subject_metadata), 60 NULL), 61 GNUNET_JSON_spec_mark_optional ( 62 GNUNET_JSON_spec_object_const ("credit_facade_credentials", 63 &cfc), 64 NULL), 65 GNUNET_JSON_spec_end () 66 }; 67 68 GNUNET_assert (NULL != mi); 69 GNUNET_assert (NULL != h_wire_s); 70 if (GNUNET_OK != 71 GNUNET_STRINGS_string_to_data (h_wire_s, 72 strlen (h_wire_s), 73 &h_wire, 74 sizeof (h_wire))) 75 { 76 GNUNET_break_op (0); 77 return TALER_MHD_reply_with_error (connection, 78 MHD_HTTP_BAD_REQUEST, 79 TALER_EC_MERCHANT_GENERIC_H_WIRE_MALFORMED, 80 h_wire_s); 81 } 82 if (! TALER_is_valid_subject_metadata_string ( 83 extra_wire_subject_metadata)) 84 { 85 GNUNET_break_op (0); 86 return TALER_MHD_reply_with_error ( 87 connection, 88 MHD_HTTP_BAD_REQUEST, 89 TALER_EC_GENERIC_PARAMETER_MALFORMED, 90 "extra_wire_subject_metadata"); 91 } 92 { 93 enum GNUNET_GenericReturnValue res; 94 95 res = TALER_MHD_parse_json_data (connection, 96 hc->request_body, 97 spec); 98 if (GNUNET_OK != res) 99 return (GNUNET_NO == res) 100 ? MHD_YES 101 : MHD_NO; 102 } 103 104 qs = TMH_db->update_account (TMH_db->cls, 105 mi->settings.id, 106 &h_wire, 107 extra_wire_subject_metadata, 108 cfu, 109 cfc); 110 { 111 MHD_RESULT ret = MHD_NO; 112 113 switch (qs) 114 { 115 case GNUNET_DB_STATUS_HARD_ERROR: 116 GNUNET_break (0); 117 ret = TALER_MHD_reply_with_error (connection, 118 MHD_HTTP_INTERNAL_SERVER_ERROR, 119 TALER_EC_GENERIC_DB_STORE_FAILED, 120 "update_account"); 121 break; 122 case GNUNET_DB_STATUS_SOFT_ERROR: 123 GNUNET_break (0); 124 ret = TALER_MHD_reply_with_error (connection, 125 MHD_HTTP_INTERNAL_SERVER_ERROR, 126 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 127 "unexpected serialization problem"); 128 break; 129 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 130 return TALER_MHD_reply_with_error (connection, 131 MHD_HTTP_NOT_FOUND, 132 TALER_EC_MERCHANT_GENERIC_ACCOUNT_UNKNOWN, 133 h_wire_s); 134 break; 135 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 136 ret = TALER_MHD_reply_static (connection, 137 MHD_HTTP_NO_CONTENT, 138 NULL, 139 NULL, 140 0); 141 break; 142 } 143 GNUNET_JSON_parse_free (spec); 144 return ret; 145 } 146 } 147 148 149 /* end of taler-merchant-httpd_patch-private-accounts-H_WIRE.c */