summaryrefslogtreecommitdiff
path: root/src
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
parentef8927863d6f39098c1c68bbc0bf8a36319caccf (diff)
downloadmerchant-88a23388c11a755fece7221579be1143e48d32c5.tar.gz
merchant-88a23388c11a755fece7221579be1143e48d32c5.tar.bz2
merchant-88a23388c11a755fece7221579be1143e48d32c5.zip
implement protocol v13 (#8638)
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_config.c2
-rw-r--r--src/backend/taler-merchant-httpd_get-templates-ID.c15
-rw-r--r--src/backend/taler-merchant-httpd_private-get-templates-ID.c13
-rw-r--r--src/backend/taler-merchant-httpd_private-patch-templates-ID.c12
-rw-r--r--src/backend/taler-merchant-httpd_private-post-templates.c25
-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
-rw-r--r--src/include/taler_merchantdb_plugin.h14
-rw-r--r--src/lib/merchant_api_get_config.c4
13 files changed, 123 insertions, 45 deletions
diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c
index 969cf1ca..c7dec0f9 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -42,7 +42,7 @@
* #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
* merchant_api_config.c!
*/
-#define MERCHANT_PROTOCOL_VERSION "12:0:8"
+#define MERCHANT_PROTOCOL_VERSION "13:0:9"
/**
diff --git a/src/backend/taler-merchant-httpd_get-templates-ID.c b/src/backend/taler-merchant-httpd_get-templates-ID.c
index fee5ec20..add67b4d 100644
--- a/src/backend/taler-merchant-httpd_get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_get-templates-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2022 Taler Systems SA
+ (C) 2022-2024 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
@@ -61,10 +61,15 @@ TMH_get_templates_ID (
ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- GNUNET_JSON_pack_object_steal ("template_contract",
- tp.template_contract));
- GNUNET_free (tp.template_description);
- GNUNET_free (tp.otp_id);
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("required_currency",
+ tp.required_currency)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("editable_defaults",
+ tp.editable_defaults)),
+ GNUNET_JSON_pack_object_incref ("template_contract",
+ tp.template_contract));
+ TALER_MERCHANTDB_template_details_free (&tp);
return ret;
}
}
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.c b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
index a5b05f0c..35fdd1d0 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
@@ -61,15 +61,20 @@ TMH_private_get_templates_ID (
ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("required_currency",
+ tp.required_currency)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("editable_defaults",
+ tp.editable_defaults)),
GNUNET_JSON_pack_string ("template_description",
tp.template_description),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("otp_id",
tp.otp_id)),
- GNUNET_JSON_pack_object_steal ("template_contract",
- tp.template_contract));
- GNUNET_free (tp.template_description);
- GNUNET_free (tp.otp_id);
+ GNUNET_JSON_pack_object_incref ("template_contract",
+ tp.template_contract));
+ TALER_MERCHANTDB_template_details_free (&tp);
return ret;
}
}
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
index 68e0a478..6aebc033 100644
--- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2022 Taler Systems SA
+ (C) 2022, 2024 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
@@ -112,6 +112,14 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
NULL),
GNUNET_JSON_spec_json ("template_contract",
&tp.template_contract),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("required_currency",
+ (const char **) &tp.required_currency),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("editable_defaults",
+ &tp.editable_defaults),
+ NULL),
GNUNET_JSON_spec_end ()
};
@@ -138,6 +146,8 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"template_contract");
}
+ // FIXME: sanity check on required_currency
+ // FIXME: sanity check on editable_defaults
qs = TMH_db->update_template (TMH_db->cls,
mi->settings.id,
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c b/src/backend/taler-merchant-httpd_private-post-templates.c
index a064769c..70052f02 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2022 Taler Systems SA
+ (C) 2022-2024 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
@@ -47,6 +47,18 @@ templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *t1,
(NULL != t2->otp_id) &&
(0 == strcmp (t1->otp_id,
t2->otp_id))) ) &&
+ ( ( (NULL == t1->required_currency) &&
+ (NULL == t2->required_currency) ) ||
+ ( (NULL != t1->required_currency) &&
+ (NULL != t2->required_currency) &&
+ (0 == strcmp (t1->required_currency,
+ t2->required_currency))) ) &&
+ ( ( (NULL == t1->editable_defaults) &&
+ (NULL == t2->editable_defaults) ) ||
+ ( (NULL != t1->editable_defaults) &&
+ (NULL != t2->editable_defaults) &&
+ (1 == json_equal (t1->editable_defaults,
+ t2->editable_defaults))) ) &&
(1 == json_equal (t1->template_contract,
t2->template_contract)) );
}
@@ -72,6 +84,14 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh,
NULL),
GNUNET_JSON_spec_json ("template_contract",
&tp.template_contract),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("required_currency",
+ (const char **) &tp.required_currency),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("editable_defaults",
+ &tp.editable_defaults),
+ NULL),
GNUNET_JSON_spec_end ()
};
uint64_t otp_serial = 0;
@@ -104,6 +124,9 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh,
"template_contract");
}
+ // FIXME: sanity check on required_currency
+ // FIXME: sanity check on editable_defaults
+
if (NULL != tp.otp_id)
{
qs = TMH_db->select_otp_serial (TMH_db->cls,
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;
}
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 404d0eb9..e7eb2d0f 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -377,6 +377,20 @@ struct TALER_MERCHANTDB_TemplateDetails
* ID of the OTP device linked to the template, or NULL.
*/
char *otp_id;
+
+ /**
+ * Currency the payment must be in, NULL to allow any
+ * supported currency.
+ */
+ char *required_currency;
+
+ /**
+ * Editable default values for fields not specified
+ * in the @e template_contract. NULL if the user
+ * cannot edit anything.
+ */
+ json_t *editable_defaults;
+
};
diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c
index 3382c9f2..d75adab7 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -34,12 +34,12 @@
* Which version of the Taler protocol is implemented
* by this library? Used to determine compatibility.
*/
-#define MERCHANT_PROTOCOL_CURRENT 12
+#define MERCHANT_PROTOCOL_CURRENT 13
/**
* How many configs are we backwards-compatible with?
*/
-#define MERCHANT_PROTOCOL_AGE 0
+#define MERCHANT_PROTOCOL_AGE 1
/**