taler-merchant-httpd_get-private-fountains.c (2887B)
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_get-private-fountains.c 22 * @brief implementing GET /private/fountains request handling 23 * @author Bohdan Potuzhnyi 24 */ 25 #include "platform.h" 26 #include "taler-merchant-httpd_get-private-fountains.h" 27 #include <taler/taler_json_lib.h> 28 #include "merchant-database/iterate_fountains.h" 29 30 31 /** 32 * Add fountain details to the JSON array in @a cls. 33 * 34 * @param cls a `json_t *` JSON array to build 35 * @param fountain_id public identifier of the fountain 36 * @param description description of the fountain 37 */ 38 static void 39 add_fountain (void *cls, 40 const char *fountain_id, 41 const char *description) 42 { 43 json_t *pa = cls; 44 45 GNUNET_assert (0 == 46 json_array_append_new ( 47 pa, 48 GNUNET_JSON_PACK ( 49 GNUNET_JSON_pack_string ("fountain_id", 50 fountain_id), 51 GNUNET_JSON_pack_string ("description", 52 description)))); 53 } 54 55 56 enum MHD_Result 57 TMH_private_get_fountains (const struct TMH_RequestHandler *rh, 58 struct MHD_Connection *connection, 59 struct TMH_HandlerContext *hc) 60 { 61 struct TMH_MerchantInstance *mi = hc->instance; 62 json_t *pa; 63 enum GNUNET_DB_QueryStatus qs; 64 65 GNUNET_assert (NULL != mi); 66 pa = json_array (); 67 GNUNET_assert (NULL != pa); 68 qs = TALER_MERCHANTDB_iterate_fountains (TMH_db, 69 mi->settings.id, 70 &add_fountain, 71 pa); 72 if (0 > qs) 73 { 74 GNUNET_break (0); 75 json_decref (pa); 76 return TALER_MHD_reply_with_error (connection, 77 MHD_HTTP_INTERNAL_SERVER_ERROR, 78 TALER_EC_GENERIC_DB_FETCH_FAILED, 79 "iterate_fountains"); 80 } 81 return TALER_MHD_REPLY_JSON_PACK ( 82 connection, 83 MHD_HTTP_OK, 84 GNUNET_JSON_pack_array_steal ("fountains", 85 pa)); 86 } 87 88 89 /* end of taler-merchant-httpd_get-private-fountains.c */