taler-merchant-httpd_get-private-fountains-FOUNTAIN_ID.c (4994B)
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-FOUNTAIN_ID.c 22 * @brief implementing GET /private/fountains/$FOUNTAIN_ID request handling 23 * @author Bohdan Potuzhnyi 24 */ 25 #include "platform.h" 26 #include "taler-merchant-httpd_get-private-fountains-FOUNTAIN_ID.h" 27 #include <taler/taler_json_lib.h> 28 #include "merchant-database/get_fountain.h" 29 #include "merchant-database/iterate_fountain_grants.h" 30 31 32 /** 33 * Add a fountain grant to the JSON array in @a cls. 34 * 35 * @param cls a `json_t *` JSON array to build 36 * @param token_family_slug slug of the granted token family 37 * @param token_family_serial serial of the granted token family 38 * @param tokens_per_period_limit maximum withdrawals per period 39 * @param tokens_per_period_stash suggested tokens to hold per period 40 * @param key_window_size number of slots ahead withdrawals are allowed 41 */ 42 static void 43 add_grant (void *cls, 44 const char *token_family_slug, 45 uint64_t token_family_serial, 46 uint64_t tokens_per_period_limit, 47 uint64_t tokens_per_period_stash, 48 uint32_t key_window_size) 49 { 50 json_t *ga = cls; 51 52 (void) token_family_serial; 53 GNUNET_assert (0 == 54 json_array_append_new ( 55 ga, 56 GNUNET_JSON_PACK ( 57 GNUNET_JSON_pack_string ("token_family_slug", 58 token_family_slug), 59 GNUNET_JSON_pack_uint64 ("tokens_per_period_limit", 60 tokens_per_period_limit), 61 GNUNET_JSON_pack_uint64 ("tokens_per_period_stash", 62 tokens_per_period_stash), 63 GNUNET_JSON_pack_uint64 ("key_window_size", 64 key_window_size)))); 65 } 66 67 68 enum MHD_Result 69 TMH_private_get_fountains_FOUNTAIN_ID (const struct TMH_RequestHandler *rh, 70 struct MHD_Connection *connection, 71 struct TMH_HandlerContext *hc) 72 { 73 struct TMH_MerchantInstance *mi = hc->instance; 74 struct TALER_MERCHANTDB_FountainDetails fd; 75 json_t *ga; 76 enum GNUNET_DB_QueryStatus qs; 77 78 GNUNET_assert (NULL != mi); 79 GNUNET_assert (NULL != hc->infix); 80 qs = TALER_MERCHANTDB_get_fountain (TMH_db, 81 mi->settings.id, 82 hc->infix, 83 &fd); 84 if (0 > qs) 85 { 86 GNUNET_break (0); 87 return TALER_MHD_reply_with_error (connection, 88 MHD_HTTP_INTERNAL_SERVER_ERROR, 89 TALER_EC_GENERIC_DB_FETCH_FAILED, 90 "get_fountain"); 91 } 92 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 93 return TALER_MHD_reply_with_error (connection, 94 MHD_HTTP_NOT_FOUND, 95 TALER_EC_MERCHANT_GENERIC_FOUNTAIN_UNKNOWN, 96 hc->infix); 97 ga = json_array (); 98 GNUNET_assert (NULL != ga); 99 qs = TALER_MERCHANTDB_iterate_fountain_grants (TMH_db, 100 mi->settings.id, 101 fd.fountain_serial, 102 &add_grant, 103 ga); 104 if (0 > qs) 105 { 106 GNUNET_break (0); 107 json_decref (ga); 108 GNUNET_free (fd.description); 109 return TALER_MHD_reply_with_error (connection, 110 MHD_HTTP_INTERNAL_SERVER_ERROR, 111 TALER_EC_GENERIC_DB_FETCH_FAILED, 112 "iterate_fountain_grants"); 113 } 114 { 115 enum MHD_Result mret; 116 117 mret = TALER_MHD_REPLY_JSON_PACK ( 118 connection, 119 MHD_HTTP_OK, 120 GNUNET_JSON_pack_string ("description", 121 fd.description), 122 GNUNET_JSON_pack_time_rel ("poll_freq", 123 fd.poll_freq), 124 GNUNET_JSON_pack_array_steal ("grants", 125 ga)); 126 GNUNET_free (fd.description); 127 return mret; 128 } 129 } 130 131 132 /* end of taler-merchant-httpd_get-private-fountains-FOUNTAIN_ID.c */