taler-merchant-httpd_private-patch-accounts-ID.c (4655B)
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 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 *cfu; 50 struct TALER_MerchantWireHashP h_wire; 51 struct GNUNET_JSON_Specification spec[] = { 52 GNUNET_JSON_spec_mark_optional ( 53 TALER_JSON_spec_web_url ("credit_facade_url", 54 &cfu), 55 NULL), 56 GNUNET_JSON_spec_mark_optional ( 57 GNUNET_JSON_spec_object_const ("credit_facade_credentials", 58 &cfc), 59 NULL), 60 GNUNET_JSON_spec_end () 61 }; 62 63 GNUNET_assert (NULL != mi); 64 GNUNET_assert (NULL != h_wire_s); 65 if (GNUNET_OK != 66 GNUNET_STRINGS_string_to_data (h_wire_s, 67 strlen (h_wire_s), 68 &h_wire, 69 sizeof (h_wire))) 70 { 71 GNUNET_break_op (0); 72 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 res = TALER_MHD_parse_json_data (connection, 81 hc->request_body, 82 spec); 83 if (GNUNET_OK != res) 84 return (GNUNET_NO == res) 85 ? MHD_YES 86 : MHD_NO; 87 } 88 89 qs = TMH_db->update_account (TMH_db->cls, 90 mi->settings.id, 91 &h_wire, 92 cfu, 93 cfc); 94 { 95 MHD_RESULT ret = MHD_NO; 96 97 switch (qs) 98 { 99 case GNUNET_DB_STATUS_HARD_ERROR: 100 GNUNET_break (0); 101 ret = TALER_MHD_reply_with_error (connection, 102 MHD_HTTP_INTERNAL_SERVER_ERROR, 103 TALER_EC_GENERIC_DB_STORE_FAILED, 104 "update_account"); 105 break; 106 case GNUNET_DB_STATUS_SOFT_ERROR: 107 GNUNET_break (0); 108 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 break; 113 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 114 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 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 120 ret = TALER_MHD_reply_static (connection, 121 MHD_HTTP_NO_CONTENT, 122 NULL, 123 NULL, 124 0); 125 break; 126 } 127 GNUNET_JSON_parse_free (spec); 128 return ret; 129 } 130 } 131 132 133 /* end of taler-merchant-httpd_private-patch-accounts-ID.c */