summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_responses.h
blob: 24b24621fbedba67b26cbe09bca7af38edaf1cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
  This file is part of TALER
  Copyright (C) 2014-2023 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file taler-exchange-httpd_responses.h
 * @brief API for generating generic replies of the exchange; these
 *        functions are called TEH_RESPONSE_reply_ and they generate
 *        and queue MHD response objects for a given connection.
 * @author Florian Dold
 * @author Benedikt Mueller
 * @author Christian Grothoff
 */
#ifndef TALER_EXCHANGE_HTTPD_RESPONSES_H
#define TALER_EXCHANGE_HTTPD_RESPONSES_H

#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
#include <microhttpd.h>
#include "taler_error_codes.h"
#include "taler-exchange-httpd.h"
#include "taler-exchange-httpd_db.h"
#include "taler_exchangedb_plugin.h"


/**
 * Send assertion that the given denomination key hash
 * is unknown to us at this time.
 *
 * @param connection connection to the client
 * @param dph denomination public key hash
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_unknown_denom_pub_hash (
  struct MHD_Connection *connection,
  const struct TALER_DenominationHashP *dph);


/**
 * Return error message indicating that a reserve had
 * an insufficient balance for the given operation.
 *
 * @param connection connection to the client
 * @param ec specific error code to return with the reserve history
 * @param reserve_balance balance remaining in the reserve
 * @param balance_required the balance required for the operation
 * @param reserve_pub the reserve with insufficient balance
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_reserve_insufficient_balance (
  struct MHD_Connection *connection,
  enum TALER_ErrorCode ec,
  const struct TALER_Amount *reserve_balance,
  const struct TALER_Amount *balance_required,
  const struct TALER_ReservePublicKeyP *reserve_pub);

/**
 * Return error message indicating that a reserve requires age
 * restriction to be set during withdraw, that is: the age-withdraw
 * protocol MUST be used with commitment to an admissible age.
 *
 * @param connection connection to the client
 * @param maximum_allowed_age the balance required for the operation
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_reserve_age_restriction_required (
  struct MHD_Connection *connection,
  uint16_t maximum_allowed_age);


/**
 * Send information that a KYC check must be
 * satisfied to proceed to client.
 *
 * @param connection connection to the client
 * @param h_payto account identifier to include in reply
 * @param kyc details about the KYC requirements
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_kyc_required (struct MHD_Connection *connection,
                                 const struct TALER_PaytoHashP *h_payto,
                                 const struct TALER_EXCHANGEDB_KycStatus *kyc);


/**
 * Send information that an AML process is blocking
 * the operation right now.
 *
 * @param connection connection to the client
 * @param status current AML status
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_aml_blocked (struct MHD_Connection *connection,
                                enum TALER_AmlDecisionState status);


/**
 * Send assertion that the given denomination key hash
 * is not usable (typically expired) at this time.
 *
 * @param connection connection to the client
 * @param dph denomination public key hash
 * @param ec error code to use
 * @param oper name of the operation that is not allowed at this time
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_expired_denom_pub_hash (
  struct MHD_Connection *connection,
  const struct TALER_DenominationHashP *dph,
  enum TALER_ErrorCode ec,
  const char *oper);


/**
 * Send assertion that the given denomination cannot be used for this operation.
 *
 * @param connection connection to the client
 * @param dph denomination public key hash
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_invalid_denom_cipher_for_operation (
  struct MHD_Connection *connection,
  const struct TALER_DenominationHashP *dph);


/**
 * Send proof that a request is invalid to client because of
 * insufficient funds.  This function will create a message with all
 * of the operations affecting the coin that demonstrate that the coin
 * has insufficient value.
 *
 * @param connection connection to the client
 * @param ec error code to return
 * @param h_denom_pub hash of the denomination of the coin
 * @param coin_pub public key of the coin
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_coin_insufficient_funds (
  struct MHD_Connection *connection,
  enum TALER_ErrorCode ec,
  const struct TALER_DenominationHashP *h_denom_pub,
  const struct TALER_CoinSpendPublicKeyP *coin_pub);

/**
 * Send proof that a request is invalid to client because of
 * an conflict with the provided denomination (the exchange had seen
 * this coin before, signed by a different denomination).
 * This function will create a message with the denomination's public key
 * that was seen before.
 *
 * @param connection connection to the client
 * @param ec error code to return
 * @param coin_pub the public key of the coin
 * @param prev_denom_pub the denomination of the coin, as seen previously
 * @param prev_denom_sig the signature with the denomination key over the coin
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_coin_denomination_conflict (
  struct MHD_Connection *connection,
  enum TALER_ErrorCode ec,
  const struct TALER_CoinSpendPublicKeyP *coin_pub,
  const struct TALER_DenominationPublicKey *prev_denom_pub,
  const struct TALER_DenominationSignature *prev_denom_sig);

/**
 * Send the salted hash of the merchant's bank account from conflicting
 * contract.  With this information, the merchant's private key and
 * the hash of the contract terms, the client can retrieve more details
 * about the conflicting deposit
 *
 * @param connection connection to the client
 * @param ec error code to return
 * @param h_wire the salted hash of the merchant's bank account
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_coin_conflicting_contract (
  struct MHD_Connection *connection,
  enum TALER_ErrorCode ec,
  const struct TALER_MerchantWireHashP *h_wire);

/**
 * Send proof that a request is invalid to client because of
 * a conflicting value for the age commitment hash of a coin.
 * This function will create a message with the conflicting
 * hash value for the age commitment of the given coin.
 *
 * @param connection connection to the client
 * @param ec error code to return
 * @param cks specific conflict type
 * @param h_denom_pub hash of the denomination of the coin
 * @param coin_pub public key of the coin
 * @param h_age_commitment hash of the age commitment as found in the database
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_coin_age_commitment_conflict (
  struct MHD_Connection *connection,
  enum TALER_ErrorCode ec,
  enum TALER_EXCHANGEDB_CoinKnownStatus cks,
  const struct TALER_DenominationHashP *h_denom_pub,
  const struct TALER_CoinSpendPublicKeyP *coin_pub,
  const struct TALER_AgeCommitmentHash *h_age_commitment);

/**
 * Fundamental details about a purse.
 */
struct TEH_PurseDetails
{
  /**
   * When should the purse expire.
   */
  struct GNUNET_TIME_Timestamp purse_expiration;

  /**
   * Hash of the contract terms of the purse.
   */
  struct TALER_PrivateContractHashP h_contract_terms;

  /**
   * Public key of the purse we are creating.
   */
  struct TALER_PurseContractPublicKeyP purse_pub;

  /**
   * Total amount to be put into the purse.
   */
  struct TALER_Amount target_amount;
};


/**
 * Send confirmation that a purse was created with
 * the current purse balance.
 *
 * @param connection connection to the client
 * @param pd purse details
 * @param exchange_timestamp our time for purse creation
 * @param purse_balance current balance in the purse
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_purse_created (
  struct MHD_Connection *connection,
  struct GNUNET_TIME_Timestamp exchange_timestamp,
  const struct TALER_Amount *purse_balance,
  const struct TEH_PurseDetails *pd);


/**
 * Callback used to set headers in a response.
 *
 * @param cls closure
 * @param[in,out] resp response to modify
 */
typedef void
(*TEH_RESPONSE_SetHeaders)(void *cls,
                           struct MHD_Response *resp);


/**
 * Generate a HTTP "Not modified" response with the
 * given @a etags.
 *
 * @param connection connection to queue response on
 * @param etags ETag header to set
 * @param cb callback to modify response headers
 * @param cb_cls closure for @a cb
 * @return MHD result code
 */
MHD_RESULT
TEH_RESPONSE_reply_not_modified (
  struct MHD_Connection *connection,
  const char *etags,
  TEH_RESPONSE_SetHeaders cb,
  void *cb_cls);


#endif