Line data Source code
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 0 : TALER_BANK_transfer_subject_copy (
29 : struct TALER_BANK_TransferSubject *dst,
30 : const struct TALER_BANK_TransferSubject *src)
31 : {
32 0 : dst->format = src->format;
33 :
34 0 : switch (src->format)
35 : {
36 0 : case TALER_BANK_SUBJECT_FORMAT_SIMPLE:
37 0 : dst->details.simple.credit_amount = src->details.simple.credit_amount;
38 0 : dst->details.simple.subject =
39 0 : (src->details.simple.subject != NULL)
40 0 : ? GNUNET_strdup (src->details.simple.subject)
41 0 : : NULL;
42 0 : return;
43 :
44 0 : case TALER_BANK_SUBJECT_FORMAT_URI:
45 0 : dst->details.uri.credit_amount = src->details.uri.credit_amount;
46 0 : dst->details.uri.uri =
47 0 : (src->details.uri.uri != NULL)
48 0 : ? GNUNET_strdup (src->details.uri.uri)
49 0 : : NULL;
50 0 : return;
51 :
52 0 : case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL:
53 0 : dst->details.ch_qr_bill.credit_amount =
54 : src->details.ch_qr_bill.credit_amount;
55 0 : dst->details.ch_qr_bill.qr_reference_number =
56 0 : (src->details.ch_qr_bill.qr_reference_number != NULL)
57 0 : ? GNUNET_strdup (src->details.ch_qr_bill.qr_reference_number)
58 0 : : NULL;
59 0 : return;
60 : }
61 0 : GNUNET_break (0);
62 : }
63 :
64 :
65 : void
66 0 : TALER_BANK_transfer_subject_free (
67 : struct TALER_BANK_TransferSubject *subject)
68 : {
69 0 : switch (subject->format)
70 : {
71 0 : case TALER_BANK_SUBJECT_FORMAT_SIMPLE:
72 0 : GNUNET_free (subject->details.simple.subject);
73 0 : return;
74 :
75 0 : case TALER_BANK_SUBJECT_FORMAT_URI:
76 0 : GNUNET_free (subject->details.uri.uri);
77 0 : return;
78 :
79 0 : case TALER_BANK_SUBJECT_FORMAT_CH_QR_BILL:
80 0 : GNUNET_free (subject->details.ch_qr_bill.qr_reference_number);
81 0 : return;
82 : }
83 0 : GNUNET_break (0);
84 : }
|