summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-24 19:40:48 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-24 19:40:48 +0200
commit874f09525fee53e8a69f040cd3cf9b4f369fdee5 (patch)
treee7026eff7a6775c814d50a3a9a8fa03c75be285a /src
parent5db333a4659da036fdd4e8097c9b1f376260e241 (diff)
downloadmerchant-874f09525fee53e8a69f040cd3cf9b4f369fdee5.tar.gz
merchant-874f09525fee53e8a69f040cd3cf9b4f369fdee5.tar.bz2
merchant-874f09525fee53e8a69f040cd3cf9b4f369fdee5.zip
baseURL construction helper function'
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_merchant_service.h15
-rw-r--r--src/lib/merchant_api_common.c34
2 files changed, 49 insertions, 0 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 435f65d2..98acae6f 100644
--- 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
index cb8de653..4d69e720 100644
--- 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;
+}