bank_api_helper.c (2505B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file bank-lib/bank_api_helper.c 19 * @brief convenience functions for the ``struct TALER_BANK_TransferSubject`` 20 * @author Christian Grothoff 21 */ 22 #include "bank_api_common.h" 23 #include <microhttpd.h> /* just for HTTP status codes */ 24 #include "taler/taler_signatures.h" 25 26 27 void 28 TALER_BANK_transfer_subject_copy ( 29 struct TALER_BANK_TransferSubject *dst, 30 const struct TALER_BANK_TransferSubject *src) 31 { 32 dst->format = src->format; 33 34 switch (src->format) 35 { 36 case TALER_BANK_SUBJECT_FORMAT_SIMPLE: 37 dst->details.simple.credit_amount = src->details.simple.credit_amount; 38 dst->details.simple.subject = 39 (src->details.simple.subject != NULL) 40 ? GNUNET_strdup (src->details.simple.subject) 41 : NULL; 42 return; 43 44 case TALER_BANK_SUBJECT_FORMAT_URI: 45 dst->details.uri.credit_amount = src->details.uri.credit_amount; 46 dst->details.uri.uri = 47 (src->details.uri.uri != NULL) 48 ? GNUNET_strdup (src->details.uri.uri) 49 : NULL; 50 return; 51 52 case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL: 53 dst->details.ch_qr_bill.credit_amount = 54 src->details.ch_qr_bill.credit_amount; 55 dst->details.ch_qr_bill.qr_reference_number = 56 (src->details.ch_qr_bill.qr_reference_number != NULL) 57 ? GNUNET_strdup (src->details.ch_qr_bill.qr_reference_number) 58 : NULL; 59 return; 60 } 61 GNUNET_break (0); 62 } 63 64 65 void 66 TALER_BANK_transfer_subject_free ( 67 struct TALER_BANK_TransferSubject *subject) 68 { 69 switch (subject->format) 70 { 71 case TALER_BANK_SUBJECT_FORMAT_SIMPLE: 72 GNUNET_free (subject->details.simple.subject); 73 return; 74 75 case TALER_BANK_SUBJECT_FORMAT_URI: 76 GNUNET_free (subject->details.uri.uri); 77 return; 78 79 case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL: 80 GNUNET_free (subject->details.ch_qr_bill.qr_reference_number); 81 return; 82 } 83 GNUNET_break (0); 84 }