Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2026 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU Affero General Public License as
7 : published by the Free Software Foundation; either version 3,
8 : or (at your option) any later version.
9 :
10 : TALER is distributed in the hope that it will be useful, but
11 : WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public
16 : License along with TALER; see the file COPYING. If not,
17 : see <http://www.gnu.org/licenses/>
18 : */
19 :
20 : /**
21 : * @file src/backend/taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c
22 : * @brief headers for POST /orders/$ID/unclaim handler
23 : * @author Christian Grothoff
24 : */
25 : #include "platform.h"
26 : #include <jansson.h>
27 : #include <taler/taler_signatures.h>
28 : #include <taler/taler_dbevents.h>
29 : #include <taler/taler_json_lib.h>
30 : #include "taler-merchant-httpd_get-private-orders.h"
31 : #include "taler-merchant-httpd_post-orders-ORDER_ID-unclaim.h"
32 : #include "merchant-database/insert_unclaim_signature.h"
33 : #include "merchant-database/preflight.h"
34 :
35 :
36 : enum MHD_Result
37 0 : TMH_post_orders_ID_unclaim (const struct TMH_RequestHandler *rh,
38 : struct MHD_Connection *connection,
39 : struct TMH_HandlerContext *hc)
40 : {
41 0 : const char *order_id = hc->infix;
42 : struct GNUNET_CRYPTO_EddsaPublicKey nonce;
43 : struct GNUNET_CRYPTO_EddsaSignature nsig;
44 : struct GNUNET_HashCode h_contract;
45 : enum GNUNET_DB_QueryStatus qs;
46 :
47 : {
48 : struct GNUNET_JSON_Specification spec[] = {
49 0 : GNUNET_JSON_spec_fixed_auto ("unclaim_sig",
50 : &nsig),
51 0 : GNUNET_JSON_spec_fixed_auto ("nonce",
52 : &nonce),
53 0 : GNUNET_JSON_spec_fixed_auto ("h_contract",
54 : &h_contract),
55 0 : GNUNET_JSON_spec_end ()
56 : };
57 : enum GNUNET_GenericReturnValue res;
58 :
59 0 : res = TALER_MHD_parse_json_data (connection,
60 0 : hc->request_body,
61 : spec);
62 0 : if (GNUNET_OK != res)
63 : {
64 0 : GNUNET_break_op (0);
65 : return (GNUNET_NO == res)
66 : ? MHD_YES
67 0 : : MHD_NO;
68 : }
69 : }
70 :
71 0 : if (GNUNET_OK !=
72 0 : TALER_wallet_order_unclaim_verify (&h_contract,
73 : &nonce,
74 : &nsig))
75 : {
76 0 : GNUNET_break_op (0);
77 0 : return TALER_MHD_reply_with_error (
78 : connection,
79 : MHD_HTTP_FORBIDDEN,
80 : TALER_EC_MERCHANT_POST_ORDERS_UNCLAIM_SIGNATURE_INVALID,
81 : "unclaim_sig");
82 : }
83 0 : TALER_MERCHANTDB_preflight (TMH_db);
84 0 : qs = TALER_MERCHANTDB_insert_unclaim_signature (TMH_db,
85 0 : hc->instance->settings.id,
86 : order_id,
87 : &nonce,
88 : &h_contract,
89 : &nsig);
90 0 : switch (qs)
91 : {
92 0 : case GNUNET_DB_STATUS_HARD_ERROR:
93 0 : GNUNET_break (0);
94 0 : return TALER_MHD_reply_with_error (connection,
95 : MHD_HTTP_INTERNAL_SERVER_ERROR,
96 : TALER_EC_GENERIC_DB_COMMIT_FAILED,
97 : "insert_unclaim_signature");
98 0 : case GNUNET_DB_STATUS_SOFT_ERROR:
99 0 : GNUNET_break (0);
100 0 : return TALER_MHD_reply_with_error (connection,
101 : MHD_HTTP_INTERNAL_SERVER_ERROR,
102 : TALER_EC_GENERIC_DB_SOFT_FAILURE,
103 : "insert_unclaim_signature");
104 0 : case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
105 0 : GNUNET_break (0);
106 0 : return TALER_MHD_reply_with_error (
107 : connection,
108 : MHD_HTTP_NOT_FOUND,
109 : TALER_EC_MERCHANT_POST_ORDERS_ID_CLAIM_NOT_FOUND,
110 : order_id);
111 0 : case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
112 0 : break; /* Good! return signature (below) */
113 : }
114 :
115 0 : return TALER_MHD_reply_static (connection,
116 : MHD_HTTP_NO_CONTENT,
117 : NULL,
118 : NULL,
119 : 0);
120 : }
121 :
122 :
123 : /* end of taler-merchant-httpd_post-orders-ORDER_ID-unclaim.c */
|