reuse TALER_url_join
This commit is contained in:
parent
dd6bad739a
commit
a9ae2171b8
@ -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,
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
char *ret;
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
GNUNET_assert ('/' == path[0]);
|
||||
ret = TALER_url_join (h->url,
|
||||
path + 1,
|
||||
NULL);
|
||||
GNUNET_assert (NULL != ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user