bank_api_helper.c (2436B)
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.uri = 46 (src->details.uri.uri != NULL) 47 ? GNUNET_strdup (src->details.uri.uri) 48 : NULL; 49 return; 50 51 case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL: 52 dst->details.ch_qr_bill.credit_amount = 53 src->details.ch_qr_bill.credit_amount; 54 dst->details.ch_qr_bill.qr_reference_number = 55 (src->details.ch_qr_bill.qr_reference_number != NULL) 56 ? GNUNET_strdup (src->details.ch_qr_bill.qr_reference_number) 57 : NULL; 58 return; 59 } 60 GNUNET_break (0); 61 } 62 63 64 void 65 TALER_BANK_transfer_subject_free ( 66 struct TALER_BANK_TransferSubject *subject) 67 { 68 switch (subject->format) 69 { 70 case TALER_BANK_SUBJECT_FORMAT_SIMPLE: 71 GNUNET_free (subject->details.simple.subject); 72 return; 73 74 case TALER_BANK_SUBJECT_FORMAT_URI: 75 GNUNET_free (subject->details.uri.uri); 76 return; 77 78 case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL: 79 GNUNET_free (subject->details.ch_qr_bill.qr_reference_number); 80 return; 81 } 82 GNUNET_break (0); 83 }