aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-16 21:57:40 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-16 21:57:40 +0100
commita9ae2171b897dfc9635e9ab72a04d65379bf2208 (patch)
tree11d67216d1c5594a4048d333b56ac40b4cf0acd1 /src
parentdd6bad739a7b7539952af6bebb74bfe3ffa0f9d7 (diff)
reuse TALER_url_join
Diffstat (limited to 'src')
-rw-r--r--src/bank-lib/bank_api_admin.c11
-rw-r--r--src/bank-lib/bank_api_common.c29
-rw-r--r--src/bank-lib/bank_api_common.h12
-rw-r--r--src/bank-lib/bank_api_credit.c18
-rw-r--r--src/bank-lib/bank_api_debit.c19
-rw-r--r--src/bank-lib/bank_api_transfer.c17
-rw-r--r--src/lib/auditor_api_handle.c35
-rw-r--r--src/lib/auditor_api_handle.h12
-rw-r--r--src/lib/exchange_api_handle.c36
-rw-r--r--src/lib/exchange_api_handle.h13
-rw-r--r--src/lib/test_taler_exchange_wirewatch.c45
-rw-r--r--src/util/util.c14
12 files changed, 89 insertions, 172 deletions
diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c
index d81c54dd6..d78cbaa20 100644
--- a/src/bank-lib/bank_api_admin.c
+++ b/src/bank-lib/bank_api_admin.c
@@ -202,8 +202,15 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
aai = GNUNET_new (struct TALER_BANK_AdminAddIncomingHandle);
aai->cb = res_cb;
aai->cb_cls = res_cb_cls;
- aai->request_url = TALER_BANK_path_to_url_ (account_base_url,
- "/admin/add-incoming");
+ aai->request_url = TALER_url_join (account_base_url,
+ "admin/add-incoming",
+ NULL);
+ if (NULL == aai->request_url)
+ {
+ GNUNET_free (aai);
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting administrative transaction at `%s' for reserve %s\n",
aai->request_url,
diff --git a/src/bank-lib/bank_api_common.c b/src/bank-lib/bank_api_common.c
index 5e7ce6876..abdeee31a 100644
--- a/src/bank-lib/bank_api_common.c
+++ b/src/bank-lib/bank_api_common.c
@@ -68,33 +68,4 @@ TALER_BANK_setup_auth_ (CURL *easy,
}
-/**
- * Obtain the URL to use for an API request.
- * FIXME: duplicates MAH_path_to_url2, and likely also logic in util!
- * FIXME: duplicates TEAH_path_to_url2, and likely also logic in util!
- *
- * @param u base URL of the bank.
- * @param path Taler API path (i.e. "/history").
- *
- * @return the full URL to use with cURL, must be
- * freed by the caller.
- */
-char *
-TALER_BANK_path_to_url_ (const char *u,
- const char *path)
-{
- char *url;
-
- if ( ('/' == path[0]) &&
- (0 < strlen (u)) &&
- ('/' == u[strlen (u) - 1]) )
- path++; /* avoid generating URL with "//" from concat */
- GNUNET_asprintf (&url,
- "%s%s",
- u,
- path);
- return url;
-}
-
-
/* end of bank_api_common.c */
diff --git a/src/bank-lib/bank_api_common.h b/src/bank-lib/bank_api_common.h
index d2d022bd0..de7f7d659 100644
--- a/src/bank-lib/bank_api_common.h
+++ b/src/bank-lib/bank_api_common.h
@@ -51,16 +51,4 @@ TALER_BANK_setup_auth_ (CURL *easy,
const struct TALER_BANK_AuthenticationData *auth);
-/**
- * Obtain the URL to use for an API request.
- *
- * @param u base URL of the bank
- * @param path Taler API path (i.e. "/history")
- * @return the full URL to use with cURL
- */
-char *
-TALER_BANK_path_to_url_ (const char *u,
- const char *path);
-
-
#endif
diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c
index be4c1972e..95e91d7db 100644
--- a/src/bank-lib/bank_api_credit.c
+++ b/src/bank-lib/bank_api_credit.c
@@ -257,19 +257,27 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
( (0 == start_row) &&
(0 < num_results) ) )
GNUNET_asprintf (&url,
- "/history/incoming?delta=%lld",
+ "history/incoming?delta=%lld",
(long long) num_results);
else
GNUNET_asprintf (&url,
- "/history/incoming?delta=%lld&start=%llu",
+ "history/incoming?delta=%lld&start=%llu",
(long long) num_results,
start_row);
hh = GNUNET_new (struct TALER_BANK_CreditHistoryHandle);
hh->hcb = hres_cb;
hh->hcb_cls = hres_cb_cls;
+ hh->request_url = TALER_url_join (bank_base_url,
+ url,
+ NULL);
+ GNUNET_free (url);
+ if (NULL == hh->request_url)
+ {
+ GNUNET_free (hh);
+ GNUNET_break (0);
+ return NULL;
+ }
hh->bank_base_url = GNUNET_strdup (bank_base_url);
- hh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
- url);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting history at `%s'\n",
hh->request_url);
@@ -285,7 +293,6 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
GNUNET_break (0);
TALER_BANK_credit_history_cancel (hh);
curl_easy_cleanup (eh);
- GNUNET_free (url);
return NULL;
}
hh->job = GNUNET_CURL_job_add2 (ctx,
@@ -293,7 +300,6 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
NULL,
&handle_history_finished,
hh);
- GNUNET_free (url);
return hh;
}
diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c
index 1afe0e457..652dde8d5 100644
--- a/src/bank-lib/bank_api_debit.c
+++ b/src/bank-lib/bank_api_debit.c
@@ -254,19 +254,26 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
( (0 == start_row) &&
(0 < num_results) ) )
GNUNET_asprintf (&url,
- "/history/outgoing?delta=%lld",
+ "history/outgoing?delta=%lld",
(long long) num_results);
else
GNUNET_asprintf (&url,
- "/history/outgoing?delta=%lld&start=%llu",
+ "history/outgoing?delta=%lld&start=%llu",
(long long) num_results,
start_row);
hh = GNUNET_new (struct TALER_BANK_DebitHistoryHandle);
hh->hcb = hres_cb;
hh->hcb_cls = hres_cb_cls;
- hh->request_url = TALER_BANK_path_to_url_ (account_base_url,
- url);
-
+ hh->request_url = TALER_url_join (account_base_url,
+ url,
+ NULL);
+ GNUNET_free (url);
+ if (NULL == hh->request_url)
+ {
+ GNUNET_free (hh);
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting history at `%s'\n",
hh->request_url);
@@ -282,7 +289,6 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
GNUNET_break (0);
TALER_BANK_debit_history_cancel (hh);
curl_easy_cleanup (eh);
- GNUNET_free (url);
return NULL;
}
hh->job = GNUNET_CURL_job_add2 (ctx,
@@ -290,7 +296,6 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
NULL,
&handle_history_finished,
hh);
- GNUNET_free (url);
return hh;
}
diff --git a/src/bank-lib/bank_api_transfer.c b/src/bank-lib/bank_api_transfer.c
index 96ed0071f..a23e515ff 100644
--- a/src/bank-lib/bank_api_transfer.c
+++ b/src/bank-lib/bank_api_transfer.c
@@ -288,6 +288,18 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
}
TALER_amount_ntoh (&amount,
&wp->amount);
+ weh = GNUNET_new (struct TALER_BANK_WireExecuteHandle);
+ weh->cb = cc;
+ weh->cb_cls = cc_cls;
+ weh->request_url = TALER_url_join (bank_base_url,
+ "transfer",
+ NULL);
+ if (NULL == weh->request_url)
+ {
+ GNUNET_free (weh);
+ GNUNET_break (0);
+ return NULL;
+ }
transfer_obj = json_pack ("{s:o, s:o, s:s, s:o, s:s}",
"request_uid", GNUNET_JSON_from_data_auto (
&wp->request_uid),
@@ -300,11 +312,6 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
GNUNET_break (0);
return NULL;
}
- weh = GNUNET_new (struct TALER_BANK_WireExecuteHandle);
- weh->cb = cc;
- weh->cb_cls = cc_cls;
- weh->request_url = TALER_BANK_path_to_url_ (bank_base_url,
- "/transfer");
weh->post_ctx.headers = curl_slist_append
(weh->post_ctx.headers,
"Content-Type: application/json");
diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c
index f1df204cb..aa0489a30 100644
--- a/src/lib/auditor_api_handle.c
+++ b/src/lib/auditor_api_handle.c
@@ -405,34 +405,13 @@ char *
MAH_path_to_url (struct TALER_AUDITOR_Handle *h,
const char *path)
{
- return MAH_path_to_url2 (h->url,
- path);
-}
-
-
-/**
- * Obtain the URL to use for an API request.
- * FIXME: duplicates TEAH_path_to_url2, and likely also logic in util!
- *
- * @param base_url base URL of the auditor (i.e. "http://auditor/")
- * @param path Taler API path (i.e. "/deposit-confirmation")
- * @return the full URL to use with cURL
- */
-char *
-MAH_path_to_url2 (const char *base_url,
- const char *path)
-{
- char *url;
-
- if ( ('/' == path[0]) &&
- (0 < strlen (base_url)) &&
- ('/' == base_url[strlen (base_url) - 1]) )
- path++; /* avoid generating URL with "//" from concat */
- GNUNET_asprintf (&url,
- "%s%s",
- base_url,
- path);
- return url;
+ char *ret;
+ GNUNET_assert ('/' == path[0]);
+ ret = TALER_url_join (h->url,
+ path + 1,
+ NULL);
+ GNUNET_assert (NULL != ret);
+ return ret;
}
diff --git a/src/lib/auditor_api_handle.h b/src/lib/auditor_api_handle.h
index eac007c45..8c6d83bc3 100644
--- a/src/lib/auditor_api_handle.h
+++ b/src/lib/auditor_api_handle.h
@@ -56,16 +56,4 @@ MAH_path_to_url (struct TALER_AUDITOR_Handle *h,
const char *path);
-/**
- * Obtain the URL to use for an API request.
- *
- * @param base_url base URL of the auditor (i.e. "http://auditor/")
- * @param path Taler API path (i.e. "/deposit-confirmation")
- * @return the full URL to use with cURL
- */
-char *
-MAH_path_to_url2 (const char *base_url,
- const char *path);
-
-
/* end of auditor_api_handle.h */
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index c7b402b5e..c3a0598f8 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -1415,34 +1415,14 @@ char *
TEAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
const char *path)
{
- return TEAH_path_to_url2 (h->url,
- path);
-}
-
-
-/**
- * Obtain the URL to use for an API request.
- * FIXME: duplicates MAH_path_to_url2, and likely also logic in util!
- *
- * @param base_url base URL of the exchange (i.e. "http://exchange/")
- * @param path Taler API path (i.e. "/reserve/withdraw")
- * @return the full URL to use with cURL
- */
-char *
-TEAH_path_to_url2 (const char *base_url,
- const char *path)
-{
- char *url;
-
- if ( ('/' == path[0]) &&
- (0 < strlen (base_url)) &&
- ('/' == base_url[strlen (base_url) - 1]) )
- path++; /* avoid generating URL with "//" from concat */
- GNUNET_asprintf (&url,
- "%s%s",
- base_url,
- path);
- return url;
+ char *ret;
+
+ GNUNET_assert ('/' == path[0]);
+ ret = TALER_url_join (h->url,
+ path + 1,
+ NULL);
+ GNUNET_assert (NULL != ret);
+ return ret;
}
diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h
index a88cb70de..52b44c8bd 100644
--- a/src/lib/exchange_api_handle.h
+++ b/src/lib/exchange_api_handle.h
@@ -136,17 +136,4 @@ char *
TEAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
const char *path);
-
-/**
- * Obtain the URL to use for an API request.
- *
- * @param base_url base URL of the exchange (i.e. "http://exchange/")
- * @param path Taler API path (i.e. "/reserve/withdraw")
- * @return the full URL to use with cURL
- */
-char *
-TEAH_path_to_url2 (const char *base_url,
- const char *path);
-
-
/* end of exchange_api_handle.h */
diff --git a/src/lib/test_taler_exchange_wirewatch.c b/src/lib/test_taler_exchange_wirewatch.c
index 39a222ae4..3a7b40097 100644
--- a/src/lib/test_taler_exchange_wirewatch.c
+++ b/src/lib/test_taler_exchange_wirewatch.c
@@ -50,7 +50,7 @@ static char *config_filename;
static struct TALER_TESTING_Command
transfer_to_exchange (const char *label,
- const char *amount)
+ const char *amount)
{
return TALER_TESTING_cmd_admin_add_incoming (label,
amount,
@@ -59,6 +59,7 @@ transfer_to_exchange (const char *label,
bc.user42_payto);
}
+
/**
* Main function that will tell the interpreter what commands to
* run.
@@ -72,37 +73,38 @@ run (void *cls,
struct TALER_TESTING_Command all[] = {
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-empty",
- config_filename),
+ config_filename),
TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty",
- config_filename),
+ config_filename),
TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"),
transfer_to_exchange ("run-transfer-good-to-exchange",
- "EUR:5"),
+ "EUR:5"),
TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-good-transfer",
- config_filename),
+ config_filename),
- TALER_TESTING_cmd_check_bank_admin_transfer ("clear-good-transfer-to-the-exchange",
- "EUR:5",
- bc.user42_payto, // debit
- bc.exchange_payto, // credit
- "run-transfer-good-to-exchange"),
+ TALER_TESTING_cmd_check_bank_admin_transfer (
+ "clear-good-transfer-to-the-exchange",
+ "EUR:5",
+ bc.user42_payto, // debit
+ bc.exchange_payto, // credit
+ "run-transfer-good-to-exchange"),
TALER_TESTING_cmd_exec_aggregator ("run-aggregator-non-expired-reserve",
- config_filename),
+ config_filename),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"),
TALER_TESTING_cmd_sleep ("wait (5s)",
- 5),
+ 5),
TALER_TESTING_cmd_exec_aggregator ("run-aggregator-on-expired-reserve",
- config_filename),
+ config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
- ec.exchange_url,
- "EUR:4.99",
- bc.exchange_payto,
- bc.user42_payto),
+ ec.exchange_url,
+ "EUR:4.99",
+ bc.exchange_payto,
+ bc.user42_payto),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"),
- TALER_TESTING_cmd_end ()
+ TALER_TESTING_cmd_end ()
};
TALER_TESTING_run_with_fakebank (is,
@@ -110,15 +112,13 @@ run (void *cls,
bc.bank_url);
}
+
int
main (int argc,
char *const argv[])
{
const char *plugin_name;
char *testname;
- struct GNUNET_OS_Process *proc;
- struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_SIGNAL_Context *shc_chld;
/* these might get in the way */
unsetenv ("XDG_DATA_HOME");
@@ -157,7 +157,7 @@ main (int argc,
TALER_TESTING_cleanup_files (config_filename);
if (GNUNET_OK != TALER_TESTING_prepare_exchange (config_filename,
- &ec))
+ &ec))
{
TALER_LOG_INFO ("Could not prepare the exchange\n");
return 77;
@@ -175,4 +175,5 @@ main (int argc,
config_filename)) ? 0 : 1;
}
+
/* end of test_taler_exchange_wirewatch.c */
diff --git a/src/util/util.c b/src/util/util.c
index 761aa98dd..f2ec95a98 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -278,22 +278,20 @@ TALER_url_join (const char *base_url,
if ('/' != base_url[strlen (base_url) - 1])
{
/* Must be an actual base URL! */
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Base URL `%s' does not end with '/'\n",
+ base_url);
return NULL;
}
if ('/' == path[0])
{
/* The path must be relative. */
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Path `%s' is not relative\n",
+ path);
return NULL;
}
- /* Path should be relative to existing path of base URL */
- GNUNET_break ('/' != path[0]);
-
- if ('/' == path[0])
- GNUNET_break (0);
-
/* 1st pass: compute length */
len = strlen (base_url) + strlen (path) + 1;