Line data Source code
1 : /* 2 : This file is part of TALER 3 : (C) 2016-2023 Taler Systems SA 4 : 5 : TALER is free software; you can redistribute it and/or 6 : modify it under the terms of the GNU General Public License 7 : as 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, 11 : but 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 : * @file bank-lib/fakebank_bank_get_accounts.c 21 : * @brief implements the Taler Bank API "GET /accounts/" handler 22 : * @author Christian Grothoff <christian@grothoff.org> 23 : */ 24 : #include "taler/platform.h" 25 : #include <pthread.h> 26 : #include "taler/taler_fakebank_lib.h" 27 : #include "taler/taler_bank_service.h" 28 : #include "taler/taler_mhd_lib.h" 29 : #include <gnunet/gnunet_mhd_compat.h> 30 : #include "fakebank.h" 31 : #include "fakebank_bank_get_accounts.h" 32 : #include "fakebank_common_lookup.h" 33 : 34 : /** 35 : * Handle GET /accounts/${account_name} request of the Taler bank API. 36 : * 37 : * @param h the handle 38 : * @param connection the connection 39 : * @param account_name name of the account 40 : * @return MHD result code 41 : */ 42 : MHD_RESULT 43 0 : TALER_FAKEBANK_bank_get_accounts_ (struct TALER_FAKEBANK_Handle *h, 44 : struct MHD_Connection *connection, 45 : const char *account_name) 46 : { 47 : struct Account *acc; 48 : 49 0 : GNUNET_assert (0 == 50 : pthread_mutex_lock (&h->big_lock)); 51 0 : acc = TALER_FAKEBANK_lookup_account_ (h, 52 : account_name, 53 : NULL); 54 0 : if (NULL == acc) 55 : { 56 0 : GNUNET_assert (0 == 57 : pthread_mutex_unlock (&h->big_lock)); 58 0 : return TALER_MHD_reply_with_error (connection, 59 : MHD_HTTP_NOT_FOUND, 60 : TALER_EC_BANK_UNKNOWN_ACCOUNT, 61 : account_name); 62 : } 63 : 64 0 : GNUNET_assert (0 == 65 : pthread_mutex_unlock (&h->big_lock)); 66 0 : return TALER_MHD_REPLY_JSON_PACK ( 67 : connection, 68 : MHD_HTTP_OK, 69 : GNUNET_JSON_pack_string ("payto_uri", 70 : acc->payto_uri), 71 : GNUNET_JSON_pack_object_steal ( 72 : "balance", 73 : GNUNET_JSON_PACK ( 74 : GNUNET_JSON_pack_string ("credit_debit_indicator", 75 : acc->is_negative 76 : ? "debit" 77 : : "credit"), 78 : TALER_JSON_pack_amount ("amount", 79 : &acc->balance)))); 80 : }