aboutsummaryrefslogtreecommitdiff
path: root/src/backend/melted/merchant.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/melted/merchant.c')
-rw-r--r--src/backend/melted/merchant.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/backend/melted/merchant.c b/src/backend/melted/merchant.c
new file mode 100644
index 00000000..f124a030
--- /dev/null
+++ b/src/backend/melted/merchant.c
@@ -0,0 +1,173 @@
1/*
2 This file is part of TALER
3 (C) 2014 Christian Grothoff (and other contributing authors)
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, If not, see <http://www.gnu.org/licenses/>
15*/
16
17/**
18 * @file merchant/merchant.c
19 * @brief Common utility functions for merchant
20 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
21 */
22
23#include "platform.h"
24#include <gnunet/gnunet_util_lib.h>
25#include "merchant.h"
26
27
28#define EXITIF(cond) \
29 do { \
30 if (cond) { GNUNET_break (0); goto EXITIF_exit; } \
31 } while (0)
32
33
34/**
35 * Parses mints from the configuration.
36 *
37 * @param cfg the configuration
38 * @param mints the array of mints upon successful parsing. Will be NULL upon
39 * error.
40 * @return the number of mints in the above array; GNUNET_SYSERR upon error in
41 * parsing.
42 */
43int
44TALER_MERCHANT_parse_mints (const struct GNUNET_CONFIGURATION_Handle *cfg,
45 struct MERCHANT_MintInfo **mints)
46{
47 char *mints_str;
48 char *token_nf; /* do no free (nf) */
49 char *mint_section;
50 char *mint_hostname;
51 char *mint_pubkey_enc;
52 struct MERCHANT_MintInfo *r_mints;
53 struct MERCHANT_MintInfo mint;
54 unsigned long long mint_port;
55 unsigned int cnt;
56 int OK;
57
58 OK = 0;
59 mints_str = NULL;
60 token_nf = NULL;
61 mint_section = NULL;
62 mint_hostname = NULL;
63 mint_pubkey_enc = NULL;
64 r_mints = NULL;
65 cnt = 0;
66 EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
67 "merchant",
68 "TRUSTED_MINTS",
69 &mints_str));
70 for (token_nf = strtok (mints_str, " ");
71 NULL != token_nf;
72 token_nf = strtok (NULL, " "))
73 {
74 GNUNET_assert (0 < GNUNET_asprintf (&mint_section,
75 "mint-%s", token_nf));
76 EXITIF (GNUNET_OK !=
77 GNUNET_CONFIGURATION_get_value_string (cfg,
78 mint_section,
79 "HOSTNAME",
80 &mint_hostname));
81 EXITIF (GNUNET_OK !=
82 GNUNET_CONFIGURATION_get_value_number (cfg,
83 mint_section,
84 "PORT",
85 &mint_port));
86 EXITIF (GNUNET_OK !=
87 GNUNET_CONFIGURATION_get_value_string (cfg,
88 mint_section,
89 "PUBKEY",
90 &mint_pubkey_enc));
91 EXITIF (GNUNET_OK !=
92 GNUNET_CRYPTO_eddsa_public_key_from_string (mint_pubkey_enc,
93 strlen (mint_pubkey_enc),
94 &mint.pubkey));
95 mint.hostname = mint_hostname;
96 mint.port = (uint16_t) mint_port;
97 GNUNET_array_append (r_mints, cnt, mint);
98 mint_hostname = NULL;
99 GNUNET_free (mint_pubkey_enc);
100 mint_pubkey_enc = NULL;
101 GNUNET_free (mint_section);
102 mint_section = NULL;
103 }
104 OK = 1;
105
106 EXITIF_exit:
107 GNUNET_free_non_null (mints_str);
108 GNUNET_free_non_null (mint_section);
109 GNUNET_free_non_null (mint_hostname);
110 GNUNET_free_non_null (mint_pubkey_enc);
111 if (!OK)
112 {
113 GNUNET_free_non_null (r_mints);
114 return GNUNET_SYSERR;
115 }
116
117 *mints = r_mints;
118 return cnt;
119}
120
121
122/**
123 * Parse the SEPA information from the configuration. If any of the required
124 * fileds is missing return NULL.
125 *
126 * @param cfg the configuration
127 * @return Sepa details as a structure; NULL upon error
128 */
129struct MERCHANT_WIREFORMAT_Sepa *
130TALER_MERCHANT_parse_wireformat_sepa (const struct GNUNET_CONFIGURATION_Handle *cfg)
131{
132 struct MERCHANT_WIREFORMAT_Sepa *wf;
133
134 wf = GNUNET_new (struct MERCHANT_WIREFORMAT_Sepa);
135 EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
136 "wire-sepa",
137 "IBAN",
138 &wf->iban));
139 EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
140 "wire-sepa",
141 "NAME",
142 &wf->name));
143 EXITIF (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
144 "wire-sepa",
145 "BIC",
146 &wf->bic));
147 return wf;
148
149 EXITIF_exit:
150 GNUNET_free_non_null (wf->iban);
151 GNUNET_free_non_null (wf->name);
152 GNUNET_free_non_null (wf->bic);
153 GNUNET_free (wf);
154 return NULL;
155
156}
157
158
159/**
160 * Destroy and free resouces occupied by the wireformat structure
161 *
162 * @param wf the wireformat structure
163 */
164void
165TALER_MERCHANT_destroy_wireformat_sepa (struct MERCHANT_WIREFORMAT_Sepa *wf)
166{
167 GNUNET_free_non_null (wf->iban);
168 GNUNET_free_non_null (wf->name);
169 GNUNET_free_non_null (wf->bic);
170 GNUNET_free (wf);
171}
172
173/* end of merchant.c */