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_common_lookup.c 21 : * @brief common helper functions related to lookups 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_common_lookup.h" 32 : 33 : struct WithdrawalOperation * 34 0 : TALER_FAKEBANK_lookup_withdrawal_operation_ (struct TALER_FAKEBANK_Handle *h, 35 : const char *wopid) 36 : { 37 : struct GNUNET_ShortHashCode sh; 38 : 39 0 : if (NULL == h->wops) 40 0 : return NULL; 41 0 : if (GNUNET_OK != 42 0 : GNUNET_STRINGS_string_to_data (wopid, 43 : strlen (wopid), 44 : &sh, 45 : sizeof (sh))) 46 : { 47 0 : GNUNET_break_op (0); 48 0 : return NULL; 49 : } 50 0 : return GNUNET_CONTAINER_multishortmap_get (h->wops, 51 : &sh); 52 : } 53 : 54 : 55 : struct Account * 56 629 : TALER_FAKEBANK_lookup_account_ (struct TALER_FAKEBANK_Handle *h, 57 : const char *name, 58 : const char *receiver_name) 59 : { 60 : struct GNUNET_HashCode hc; 61 : size_t slen; 62 : struct Account *account; 63 : 64 629 : memset (&hc, 65 : 0, 66 : sizeof (hc)); 67 629 : slen = strlen (name); 68 629 : GNUNET_CRYPTO_hash (name, 69 : slen, 70 : &hc); 71 629 : GNUNET_assert (0 == 72 : pthread_mutex_lock (&h->accounts_lock)); 73 629 : account = GNUNET_CONTAINER_multihashmap_get (h->accounts, 74 : &hc); 75 629 : if (NULL == account) 76 : { 77 54 : if (NULL == receiver_name) 78 : { 79 9 : GNUNET_assert (0 == 80 : pthread_mutex_unlock (&h->accounts_lock)); 81 9 : return NULL; 82 : } 83 45 : account = GNUNET_new (struct Account); 84 45 : account->account_name = GNUNET_strdup (name); 85 45 : account->receiver_name = GNUNET_strdup (receiver_name); 86 45 : GNUNET_asprintf (&account->payto_uri, 87 : "payto://x-taler-bank/%s/%s?receiver-name=%s", 88 : h->hostname, 89 : account->account_name, 90 : account->receiver_name); 91 45 : GNUNET_assert (GNUNET_OK == 92 : TALER_amount_set_zero (h->currency, 93 : &account->balance)); 94 45 : GNUNET_assert (GNUNET_OK == 95 : GNUNET_CONTAINER_multihashmap_put (h->accounts, 96 : &hc, 97 : account, 98 : GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 99 : } 100 620 : GNUNET_assert (0 == 101 : pthread_mutex_unlock (&h->accounts_lock)); 102 620 : return account; 103 : }