commit 874f09525fee53e8a69f040cd3cf9b4f369fdee5
parent 5db333a4659da036fdd4e8097c9b1f376260e241
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 24 Apr 2020 19:40:48 +0200
baseURL construction helper function'
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
@@ -121,6 +121,21 @@ TALER_MERCHANT_parse_error_details_ (const json_t *response,
struct TALER_MERCHANT_HttpResponse *hr);
+/**
+ * Construct a new base URL using the existing @a base_url
+ * and the given @a instance_id. The result WILL end with
+ * '/'.
+ *
+ * @param base_url a merchant base URL without "/instances/" in it,
+ * must not be the empty string; MAY end with '/'.
+ * @param instance_id ID of an instance
+ * @return "${base_url}/instances/${instance_id}/"
+ */
+char *
+TALER_MERCHANT_baseurl_add_instance (const char *base_url,
+ const char *instance_id);
+
+
/* ********************* /public/config ****************** */
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
@@ -116,3 +116,37 @@ TALER_MERCHANT_parse_error_details_ (const json_t *response,
hr->exchange_hint = json_string_value (jc);
}
}
+
+
+/**
+ * Construct a new base URL using the existing @a base_url
+ * and the given @a instance_id. The result WILL end with
+ * '/'.
+ *
+ * @param base_url a merchant base URL without "/instances/" in it,
+ * must not be the empty string; MAY end with '/'.
+ * @param instance_id ID of an instance
+ * @return "${base_url}/instances/${instance_id}/"
+ */
+char *
+TALER_MERCHANT_baseurl_add_instance (const char *base_url,
+ const char *instance_id)
+{
+ char *ret;
+ bool end_sl;
+
+ if ('\0' == *base_url)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ end_sl = '/' == base_url[strlen (base_url) - 1];
+
+ GNUNET_asprintf (&ret,
+ (end_sl)
+ ? "%sinstances/%s/"
+ : "%s/instances/%s/",
+ base_url,
+ instance_id);
+ return ret;
+}