summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-03-19 09:52:21 +0100
committerChristian Grothoff <christian@grothoff.org>2024-03-19 09:52:21 +0100
commit88a23388c11a755fece7221579be1143e48d32c5 (patch)
treea1dd9f4e08903993dae1df92fd1f2ecb2d94b674 /src/backenddb
parentef8927863d6f39098c1c68bbc0bf8a36319caccf (diff)
downloadmerchant-88a23388c11a755fece7221579be1143e48d32c5.tar.gz
merchant-88a23388c11a755fece7221579be1143e48d32c5.tar.bz2
merchant-88a23388c11a755fece7221579be1143e48d32c5.zip
implement protocol v13 (#8638)
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/merchantdb_helper.c3
-rw-r--r--src/backenddb/pg_insert_template.c11
-rw-r--r--src/backenddb/pg_lookup_template.c17
-rw-r--r--src/backenddb/pg_lookup_templates.c4
-rw-r--r--src/backenddb/pg_update_template.c23
-rw-r--r--src/backenddb/test_merchantdb.c25
6 files changed, 52 insertions, 31 deletions
diff --git a/src/backenddb/merchantdb_helper.c b/src/backenddb/merchantdb_helper.c
index 4ba70e4b..5894525c 100644
--- a/src/backenddb/merchantdb_helper.c
+++ b/src/backenddb/merchantdb_helper.c
@@ -43,6 +43,8 @@ TALER_MERCHANTDB_template_details_free (
{
GNUNET_free (tp->template_description);
GNUNET_free (tp->otp_id);
+ GNUNET_free (tp->required_currency);
+ json_decref (tp->editable_defaults);
json_decref (tp->template_contract);
}
@@ -69,6 +71,7 @@ TALER_MERCHANTDB_pending_webhook_details_free (
GNUNET_free (pwb->body);
}
+
void
TALER_MERCHANTDB_token_family_details_free (
struct TALER_MERCHANTDB_TokenFamilyDetails *tf)
diff --git a/src/backenddb/pg_insert_template.c b/src/backenddb/pg_insert_template.c
index 5fc76a1d..67cae495 100644
--- a/src/backenddb/pg_insert_template.c
+++ b/src/backenddb/pg_insert_template.c
@@ -42,6 +42,12 @@ TMH_PG_insert_template (void *cls,
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_uint64 (&otp_serial_id),
TALER_PQ_query_param_json (td->template_contract),
+ (NULL == td->editable_defaults)
+ ? GNUNET_PQ_query_param_null ()
+ : TALER_PQ_query_param_json (td->editable_defaults),
+ (NULL == td->required_currency)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (td->required_currency),
GNUNET_PQ_query_param_end
};
@@ -54,13 +60,14 @@ TMH_PG_insert_template (void *cls,
",template_description"
",otp_device_id"
",template_contract"
+ ",editable_defaults"
+ ",required_currency"
")"
" SELECT merchant_serial,"
- " $2, $3, $4, $5"
+ " $2, $3, $4, $5, $6, $7"
" FROM merchant_instances"
" WHERE merchant_id=$1");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_template",
params);
}
-
diff --git a/src/backenddb/pg_lookup_template.c b/src/backenddb/pg_lookup_template.c
index a0326bc8..6e9d3681 100644
--- a/src/backenddb/pg_lookup_template.c
+++ b/src/backenddb/pg_lookup_template.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022, 2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -56,6 +56,8 @@ TMH_PG_lookup_template (void *cls,
" mt.template_description"
",mod.otp_id"
",mt.template_contract"
+ ",mt.required_currency"
+ ",mt.editable_defaults"
" FROM merchant_template mt"
" JOIN merchant_instances mi"
" ON (mi.merchant_serial = mt.merchant_serial)"
@@ -83,16 +85,25 @@ TMH_PG_lookup_template (void *cls,
GNUNET_PQ_result_spec_string ("otp_id",
&td->otp_id),
NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("required_currency",
+ &td->required_currency),
+ NULL),
TALER_PQ_result_spec_json ("template_contract",
&td->template_contract),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("editable_defaults",
+ &td->editable_defaults),
+ NULL),
GNUNET_PQ_result_spec_end
};
- td->otp_id = NULL;
+ memset (td,
+ 0,
+ sizeof (*td));
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"lookup_template",
params,
rs);
}
}
-
diff --git a/src/backenddb/pg_lookup_templates.c b/src/backenddb/pg_lookup_templates.c
index 59240994..7938d575 100644
--- a/src/backenddb/pg_lookup_templates.c
+++ b/src/backenddb/pg_lookup_templates.c
@@ -126,10 +126,8 @@ TMH_PG_lookup_templates (void *cls,
params,
&lookup_templates_cb,
&tlc);
- /* If there was an error inside lookup_template_cb, return a hard error. */
+ /* If there was an error inside lookup_templates_cb, return a hard error. */
if (tlc.extract_failed)
return GNUNET_DB_STATUS_HARD_ERROR;
return qs;
}
-
-
diff --git a/src/backenddb/pg_update_template.c b/src/backenddb/pg_update_template.c
index 9f7f37c3..c0c35df3 100644
--- a/src/backenddb/pg_update_template.c
+++ b/src/backenddb/pg_update_template.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -26,17 +26,6 @@
#include "pg_helper.h"
-/**
- * Update details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to update template for
- * @param template_id template to update
- * @param td update to the template details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
- * does not yet exist.
- */
enum GNUNET_DB_QueryStatus
TMH_PG_update_template (void *cls,
const char *instance_id,
@@ -52,6 +41,12 @@ TMH_PG_update_template (void *cls,
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_string (td->otp_id),
TALER_PQ_query_param_json (td->template_contract),
+ (NULL == td->editable_defaults)
+ ? GNUNET_PQ_query_param_null ()
+ : TALER_PQ_query_param_json (td->editable_defaults),
+ (NULL == td->required_currency)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (td->required_currency),
GNUNET_PQ_query_param_end
};
@@ -73,6 +68,8 @@ TMH_PG_update_template (void *cls,
" COALESCE((SELECT otp_serial"
" FROM otp), NULL)"
",template_contract=$5"
+ ",editable_defaults=$6"
+ ",required_currency=$7"
" WHERE merchant_serial="
" (SELECT merchant_serial"
" FROM mid)"
@@ -81,5 +78,3 @@ TMH_PG_update_template (void *cls,
"update_template",
params);
}
-
-
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 60a0b08b..1a4c15db 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2023 Taler Systems SA
+ (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -5718,15 +5718,16 @@ lookup_templates_cb (void *cls,
const char *template_description)
{
struct TestLookupTemplates_Closure *cmp = cls;
+
if (NULL == cmp)
return;
cmp->results_length += 1;
for (unsigned int i = 0; cmp->templates_to_cmp_length > i; ++i)
{
- if ((0 == strcmp (cmp->templates_to_cmp[i].id,
- template_id)) &&
- (0 == strcmp (cmp->templates_to_cmp[i].template.template_description,
- template_description)) )
+ if ( (0 == strcmp (cmp->templates_to_cmp[i].id,
+ template_id)) &&
+ (0 == strcmp (cmp->templates_to_cmp[i].template.template_description,
+ template_description)) )
cmp->results_matching[i] += 1;
}
}
@@ -5752,7 +5753,10 @@ test_lookup_templates (const struct InstanceData *instance,
.results_matching = results_matching,
.results_length = 0
};
- memset (results_matching, 0, sizeof (unsigned int) * templates_length);
+
+ memset (results_matching,
+ 0,
+ sizeof (unsigned int) * templates_length);
if (0 > plugin->lookup_templates (plugin->cls,
instance->instance.id,
&lookup_templates_cb,
@@ -5915,7 +5919,6 @@ run_test_templates (struct TestTemplates_Closure *cls)
"otp_id",
&td));
}
-
GNUNET_assert (0 ==
json_array_append_new (
cls->templates[0].template.template_contract,
@@ -5923,7 +5926,6 @@ run_test_templates (struct TestTemplates_Closure *cls)
TEST_RET_ON_FAIL (test_update_template (&cls->instance,
&cls->templates[0],
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
TEST_RET_ON_FAIL (test_lookup_template (&cls->instance,
&cls->templates[0]));
TEST_RET_ON_FAIL (test_update_template (&cls->instance,
@@ -5961,8 +5963,13 @@ static int
test_templates (void)
{
struct TestTemplates_Closure test_cls;
+ int test_result;
+
+ memset (&test_cls,
+ 0,
+ sizeof (test_cls));
pre_test_templates (&test_cls);
- int test_result = run_test_templates (&test_cls);
+ test_result = run_test_templates (&test_cls);
post_test_templates (&test_cls);
return test_result;
}