taler-merchant-httpd_patch-private-fountains-FOUNTAIN_ID.c (5084B)
1 /* 2 This file is part of TALER 3 (C) 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-fountains-FOUNTAIN_ID.c 22 * @brief implementing PATCH /private/fountains/$FOUNTAIN_ID request handling 23 * @author Bohdan Potuzhnyi 24 */ 25 #include "platform.h" 26 #include "taler-merchant-httpd_patch-private-fountains-FOUNTAIN_ID.h" 27 #include "taler-merchant-httpd_fountains.h" 28 #include <taler/taler_json_lib.h> 29 #include "merchant-database/do_update_fountain.h" 30 31 32 enum MHD_Result 33 TMH_private_patch_fountains_FOUNTAIN_ID (const struct TMH_RequestHandler *rh, 34 struct MHD_Connection *connection, 35 struct TMH_HandlerContext *hc) 36 { 37 struct TMH_MerchantInstance *mi = hc->instance; 38 const char *description = NULL; 39 struct GNUNET_TIME_Relative poll_freq; 40 bool no_poll_freq; 41 const json_t *jgrants = NULL; 42 struct GNUNET_JSON_Specification spec[] = { 43 GNUNET_JSON_spec_mark_optional ( 44 GNUNET_JSON_spec_string ("description", 45 &description), 46 NULL), 47 GNUNET_JSON_spec_mark_optional ( 48 GNUNET_JSON_spec_relative_time ("poll_freq", 49 &poll_freq), 50 &no_poll_freq), 51 GNUNET_JSON_spec_mark_optional ( 52 GNUNET_JSON_spec_array_const ("grants", 53 &jgrants), 54 NULL), 55 GNUNET_JSON_spec_end () 56 }; 57 unsigned int grants_len = 0; 58 bool replace_grants; 59 60 GNUNET_assert (NULL != mi); 61 GNUNET_assert (NULL != hc->infix); 62 { 63 enum GNUNET_GenericReturnValue res; 64 65 res = TALER_MHD_parse_json_data (connection, 66 hc->request_body, 67 spec); 68 if (GNUNET_OK != res) 69 { 70 GNUNET_break_op (0); 71 return (GNUNET_NO == res) 72 ? MHD_YES 73 : MHD_NO; 74 } 75 } 76 replace_grants = (NULL != jgrants); 77 { 78 struct TALER_MERCHANTDB_FountainGrant grants[TMH_MAX_FOUNTAIN_GRANTS]; 79 char *unknown_slug; 80 bool not_found; 81 enum GNUNET_DB_QueryStatus qs; 82 83 if (replace_grants) 84 { 85 enum GNUNET_GenericReturnValue res; 86 87 res = TMH_fountain_grants_parse (connection, 88 jgrants, 89 grants, 90 &grants_len); 91 if (GNUNET_OK != res) 92 { 93 GNUNET_JSON_parse_free (spec); 94 return (GNUNET_NO == res) 95 ? MHD_YES 96 : MHD_NO; 97 } 98 } 99 qs = TALER_MERCHANTDB_do_update_fountain (TMH_db, 100 mi->settings.id, 101 hc->infix, 102 description, 103 no_poll_freq 104 ? NULL 105 : &poll_freq, 106 replace_grants, 107 grants_len, 108 grants, 109 ¬_found, 110 &unknown_slug); 111 GNUNET_JSON_parse_free (spec); 112 if (qs < 0) 113 { 114 GNUNET_break (0); 115 return TALER_MHD_reply_with_error (connection, 116 MHD_HTTP_INTERNAL_SERVER_ERROR, 117 TALER_EC_GENERIC_DB_STORE_FAILED, 118 "do_update_fountain"); 119 } 120 if (not_found) 121 return TALER_MHD_reply_with_error (connection, 122 MHD_HTTP_NOT_FOUND, 123 TALER_EC_MERCHANT_GENERIC_FOUNTAIN_UNKNOWN, 124 hc->infix); 125 if (NULL != unknown_slug) 126 { 127 enum MHD_Result mret; 128 129 mret = TALER_MHD_reply_with_error ( 130 connection, 131 MHD_HTTP_NOT_FOUND, 132 TALER_EC_MERCHANT_PRIVATE_POST_ORDERS_TOKEN_FAMILY_SLUG_UNKNOWN, 133 unknown_slug); 134 GNUNET_free (unknown_slug); 135 return mret; 136 } 137 } 138 return TALER_MHD_reply_static (connection, 139 MHD_HTTP_NO_CONTENT, 140 NULL, 141 NULL, 142 0); 143 } 144 145 146 /* end of taler-merchant-httpd_patch-private-fountains-FOUNTAIN_ID.c */