Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022 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 <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file backenddb/pg_insert_instance.c
18 : * @brief Implementation of the insert_instance function for Postgres
19 : * @author Christian Grothoff
20 : * @author Iván Ávalos
21 : */
22 : #include "platform.h"
23 : #include <taler/taler_error_codes.h>
24 : #include <taler/taler_dbevents.h>
25 : #include <taler/taler_pq_lib.h>
26 : #include "pg_insert_instance.h"
27 : #include "pg_helper.h"
28 :
29 : enum GNUNET_DB_QueryStatus
30 29 : TMH_PG_insert_instance (
31 : void *cls,
32 : const struct TALER_MerchantPublicKeyP *merchant_pub,
33 : const struct TALER_MerchantPrivateKeyP *merchant_priv,
34 : const struct TALER_MERCHANTDB_InstanceSettings *is,
35 : const struct TALER_MERCHANTDB_InstanceAuthSettings *ias)
36 : {
37 29 : struct PostgresClosure *pg = cls;
38 29 : struct GNUNET_PQ_QueryParam params[] = {
39 29 : GNUNET_PQ_query_param_auto_from_type (merchant_pub),
40 29 : GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash),
41 29 : GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt),
42 29 : GNUNET_PQ_query_param_string (is->id),
43 29 : GNUNET_PQ_query_param_string (is->name),
44 29 : TALER_PQ_query_param_json (is->address),
45 29 : TALER_PQ_query_param_json (is->jurisdiction),
46 29 : GNUNET_PQ_query_param_bool (is->use_stefan),
47 29 : GNUNET_PQ_query_param_relative_time (
48 : &is->default_wire_transfer_delay),
49 29 : GNUNET_PQ_query_param_relative_time (&is->default_pay_delay),
50 29 : (NULL == is->website)
51 29 : ? GNUNET_PQ_query_param_null ()
52 29 : : GNUNET_PQ_query_param_string (is->website),
53 29 : (NULL == is->email)
54 29 : ? GNUNET_PQ_query_param_null ()
55 29 : : GNUNET_PQ_query_param_string (is->email),
56 29 : (NULL == is->logo)
57 29 : ? GNUNET_PQ_query_param_null ()
58 29 : : GNUNET_PQ_query_param_string (is->logo),
59 : GNUNET_PQ_query_param_end
60 : };
61 29 : struct GNUNET_PQ_QueryParam params_priv[] = {
62 29 : GNUNET_PQ_query_param_auto_from_type (merchant_priv),
63 29 : GNUNET_PQ_query_param_string (is->id),
64 : GNUNET_PQ_query_param_end
65 : };
66 : enum GNUNET_DB_QueryStatus qs;
67 :
68 29 : check_connection (pg);
69 29 : PREPARE (pg,
70 : "insert_instance",
71 : "INSERT INTO merchant_instances"
72 : "(merchant_pub"
73 : ",auth_hash"
74 : ",auth_salt"
75 : ",merchant_id"
76 : ",merchant_name"
77 : ",address"
78 : ",jurisdiction"
79 : ",use_stefan"
80 : ",default_wire_transfer_delay"
81 : ",default_pay_delay"
82 : ",website"
83 : ",email"
84 : ",logo"
85 : ",user_type)"
86 : "VALUES"
87 : "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, 0)");
88 29 : qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
89 : "insert_instance",
90 : params);
91 29 : if (qs <= 0)
92 0 : return qs;
93 29 : PREPARE (pg,
94 : "insert_keys",
95 : "INSERT INTO merchant_keys"
96 : "(merchant_priv"
97 : ",merchant_serial)"
98 : " SELECT $1, merchant_serial"
99 : " FROM merchant_instances"
100 : " WHERE merchant_id=$2");
101 29 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
102 : "insert_keys",
103 : params_priv);
104 : }
|