aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-15 14:57:58 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-15 14:58:10 +0100
commitb37fff0d5b08926169633ce8822de7ac616ae169 (patch)
tree88be0f24a260f2e7037cabd60227584a5c7f6749
parentd822035216d9ad33665a2f8274432918ca7d42be (diff)
ftbfs
-rw-r--r--src/include/taler_util.h11
-rw-r--r--src/lib/testing_api_cmd_bank_admin_add_incoming.c168
-rw-r--r--src/lib/testing_api_cmd_bank_history_credit.c40
-rw-r--r--src/util/test_payto.c7
-rw-r--r--src/util/util.c54
5 files changed, 178 insertions, 102 deletions
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 0f4eaab66..504f9b39c 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -259,6 +259,17 @@ TALER_payto_xtalerbank_make (const char *bank_url,
/**
+ * Create an x-taler-bank payto:// URL from an @a account_url.
+ *
+ * @param account_url the bank URL
+ * @param account_name the account name
+ * @return payto:// URL
+ */
+char *
+TALER_payto_xtalerbank_make2 (const char *account_url);
+
+
+/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*
diff --git a/src/lib/testing_api_cmd_bank_admin_add_incoming.c b/src/lib/testing_api_cmd_bank_admin_add_incoming.c
index e490fce25..04e7d5637 100644
--- a/src/lib/testing_api_cmd_bank_admin_add_incoming.c
+++ b/src/lib/testing_api_cmd_bank_admin_add_incoming.c
@@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>
*/
/**
- * @file exchange-lib/testing_api_cmd_admin_add_incoming.c
+ * @file lib/testing_api_cmd_admin_add_incoming.c
* @brief implementation of a bank /admin/add-incoming command
* @author Christian Grothoff
* @author Marcello Stanisci
@@ -59,6 +59,11 @@ struct AdminAddIncomingState
const char *payto_debit_account;
/**
+ * Money sender account URL.
+ */
+ char *payto_credit_account;
+
+ /**
* Username to use for authentication.
*/
struct TALER_BANK_AuthenticationData auth;
@@ -376,6 +381,7 @@ admin_add_incoming_cleanup (void *cls,
GNUNET_SCHEDULER_cancel (fts->retry_task);
fts->retry_task = NULL;
}
+ GNUNET_free (fts->payto_credit_account);
GNUNET_free (fts);
}
@@ -402,7 +408,8 @@ admin_add_incoming_traits (void *cls,
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_DEBIT,
fts->payto_debit_account),
TALER_TESTING_make_trait_payto (TALER_TESTING_PT_CREDIT,
- fts->exchange_credit_url),
+ fts->payto_credit_account),
+ TALER_TESTING_make_trait_url (0, fts->exchange_credit_url),
TALER_TESTING_make_trait_amount_obj (0, &fts->amount),
TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp),
TALER_TESTING_make_trait_reserve_priv (0,
@@ -420,52 +427,88 @@ admin_add_incoming_traits (void *cls,
/**
- * Create admin/add-incoming command.
+ * Create internal state for "/admin/add-incoming" CMD.
*
- * @param label command label.
- * @param amount amount to transfer.
- * @param exchange_base_url base URL of the account that receives this
- * wire transer (which account receives money).
- * @param payto_debit_account which account sends money.
+ * @param amount the amount to transfer.
+ * @param account_bank_url base URL of the exchange account receiving the money
+ * @param payto_debit_account which account sends money
* @param auth authentication data
- * @return the command.
+ * @return the internal state
*/
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_admin_add_incoming
- (const char *label,
- const char *amount,
- const char *exchange_base_url,
- const struct TALER_BANK_AuthenticationData *auth,
- const char *payto_debit_account)
+static struct AdminAddIncomingState *
+make_fts (const char *amount,
+ const char *exchange_base_url,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *payto_debit_account)
{
struct AdminAddIncomingState *fts;
fts = GNUNET_new (struct AdminAddIncomingState);
fts->exchange_credit_url = exchange_base_url;
fts->payto_debit_account = payto_debit_account;
+ fts->payto_credit_account
+ = TALER_payto_xtalerbank_make2 (exchange_base_url);
fts->auth = *auth;
if (GNUNET_OK !=
TALER_string_to_amount (amount,
&fts->amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %s\n",
- amount,
- label);
+ "Failed to parse amount `%s'\n",
+ amount);
GNUNET_assert (0);
}
+ return fts;
+}
- {
- struct TALER_TESTING_Command cmd = {
- .cls = fts,
- .label = label,
- .run = &admin_add_incoming_run,
- .cleanup = &admin_add_incoming_cleanup,
- .traits = &admin_add_incoming_traits
- };
-
- return cmd;
- }
+
+/**
+ * Helper function to create admin/add-incoming command.
+ *
+ * @param label command label.
+ * @param fts internal state to use
+ * @return the command.
+ */
+static struct TALER_TESTING_Command
+make_command (const char *label,
+ struct AdminAddIncomingState *fts)
+{
+ struct TALER_TESTING_Command cmd = {
+ .cls = fts,
+ .label = label,
+ .run = &admin_add_incoming_run,
+ .cleanup = &admin_add_incoming_cleanup,
+ .traits = &admin_add_incoming_traits
+ };
+
+ return cmd;
+}
+
+
+/**
+ * Create admin/add-incoming command.
+ *
+ * @param label command label.
+ * @param amount amount to transfer.
+ * @param exchange_base_url base URL of the account that receives this
+ * wire transer (which account receives money).
+ * @param payto_debit_account which account sends money.
+ * @param auth authentication data
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_admin_add_incoming
+ (const char *label,
+ const char *amount,
+ const char *exchange_base_url,
+ const struct TALER_BANK_AuthenticationData *auth,
+ const char *payto_debit_account)
+{
+ return make_command (label,
+ make_fts (amount,
+ exchange_base_url,
+ auth,
+ payto_debit_account));
}
@@ -495,32 +538,13 @@ TALER_TESTING_cmd_admin_add_incoming_with_ref
{
struct AdminAddIncomingState *fts;
- fts = GNUNET_new (struct AdminAddIncomingState);
- fts->exchange_credit_url = account_base_url;
- fts->payto_debit_account = payto_debit_account;
- fts->auth = *auth;
+ fts = make_fts (amount,
+ account_base_url,
+ auth,
+ payto_debit_account);
fts->reserve_reference = ref;
- if (GNUNET_OK !=
- TALER_string_to_amount (amount,
- &fts->amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %s\n",
- amount,
- label);
- GNUNET_assert (0);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = fts,
- .label = label,
- .run = &admin_add_incoming_run,
- .cleanup = &admin_add_incoming_cleanup,
- .traits = &admin_add_incoming_traits
- };
-
- return cmd;
- }
+ return make_command (label,
+ fts);
}
@@ -557,33 +581,15 @@ TALER_TESTING_cmd_admin_add_incoming_with_instance
{
struct AdminAddIncomingState *fts;
- fts = GNUNET_new (struct AdminAddIncomingState);
- fts->exchange_credit_url = account_base_url;
- fts->payto_debit_account = payto_debit_account;
- fts->auth = *auth;
+ fts = make_fts (amount,
+ account_base_url,
+ auth,
+ payto_debit_account);
fts->instance = instance;
fts->config_filename = config_filename;
- if (GNUNET_OK !=
- TALER_string_to_amount (amount,
- &fts->amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %s\n",
- amount,
- label);
- GNUNET_assert (0);
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = fts,
- .label = label,
- .run = &admin_add_incoming_run,
- .cleanup = &admin_add_incoming_cleanup,
- .traits = &admin_add_incoming_traits
- };
-
- return cmd;
- }
+
+ return make_command (label,
+ fts);
}
@@ -607,4 +613,4 @@ TALER_TESTING_cmd_admin_add_incoming_retry (struct TALER_TESTING_Command cmd)
}
-/* end of testing_api_cmd_admin_add_incoming.c */
+/* end of testing_api_cmd_bank_admin_add_incoming.c */
diff --git a/src/lib/testing_api_cmd_bank_history_credit.c b/src/lib/testing_api_cmd_bank_history_credit.c
index 40ec99162..d2f962e20 100644
--- a/src/lib/testing_api_cmd_bank_history_credit.c
+++ b/src/lib/testing_api_cmd_bank_history_credit.c
@@ -304,7 +304,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
continue; /* skip until we find the marker */
TALER_LOG_DEBUG ("Found first row\n");
-
if (build_history_hit_limit (total,
hs,
pos))
@@ -312,16 +311,14 @@ build_history (struct TALER_TESTING_Interpreter *is,
TALER_LOG_DEBUG ("Hit history limit\n");
break;
}
-
-
- GNUNET_assert
- (GNUNET_OK == TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT
- (pos, &credit_account));
-
- GNUNET_assert
- (GNUNET_OK == TALER_TESTING_GET_TRAIT_DEBIT_ACCOUNT
- (pos, &debit_account));
-
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_payto (pos,
+ TALER_TESTING_PT_CREDIT,
+ &credit_account));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_payto (pos,
+ TALER_TESTING_PT_DEBIT,
+ &debit_account));
TALER_LOG_INFO ("Potential history element:"
" %s->%s; my account: %s\n",
debit_account,
@@ -365,8 +362,9 @@ build_history (struct TALER_TESTING_Interpreter *is,
const char *credit_account;
const char *debit_account;
- if (GNUNET_OK != TALER_TESTING_GET_TRAIT_ROW_ID
- (pos, &row_id))
+ if (GNUNET_OK !=
+ TALER_TESTING_GET_TRAIT_ROW_ID (pos,
+ &row_id))
continue;
if (NULL != row_id_start)
@@ -401,14 +399,14 @@ build_history (struct TALER_TESTING_Interpreter *is,
break;
}
- GNUNET_assert
- (GNUNET_OK == TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT
- (pos, &credit_account));
-
- GNUNET_assert
- (GNUNET_OK == TALER_TESTING_GET_TRAIT_DEBIT_ACCOUNT
- (pos, &debit_account));
-
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_payto (pos,
+ TALER_TESTING_PT_CREDIT,
+ &credit_account));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_payto (pos,
+ TALER_TESTING_PT_DEBIT,
+ &debit_account));
TALER_LOG_INFO ("Potential history bit:"
" %s->%s; my account: %s\n",
debit_account,
diff --git a/src/util/test_payto.c b/src/util/test_payto.c
index f0247f19b..28caac1ad 100644
--- a/src/util/test_payto.c
+++ b/src/util/test_payto.c
@@ -50,6 +50,9 @@ main (int argc,
"account");
CHECK ("payto://x-taler-bank/localhost/account",
r);
+ r = TALER_payto_xtalerbank_make2 ("https://localhost/account");
+ CHECK ("payto://x-taler-bank/localhost/account",
+ r);
r = TALER_payto_xtalerbank_make ("http://localhost:80/",
"account");
CHECK ("payto://x-taler-bank/localhost:80/account",
@@ -60,6 +63,10 @@ main (int argc,
r);
r = TALER_payto_xtalerbank_make ("http://localhost/",
"account");
+ r = TALER_payto_xtalerbank_make2 ("http://localhost:80/account");
+ CHECK ("payto://x-taler-bank/localhost:80/account",
+ r);
+ r = TALER_payto_xtalerbank_make2 ("http://localhost/account");
CHECK ("payto://x-taler-bank/localhost:80/account",
r);
r = TALER_xtalerbank_base_url_from_payto (
diff --git a/src/util/util.c b/src/util/util.c
index 7f5e60e4d..761aa98dd 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -624,6 +624,60 @@ TALER_payto_xtalerbank_make (const char *bank_url,
/**
+ * Create an x-taler-bank payto:// URL from an @a account_url.
+ *
+ * @param account_url the bank URL
+ * @param account_name the account name
+ * @return payto:// URL
+ */
+char *
+TALER_payto_xtalerbank_make2 (const char *account_url)
+{
+ char *payto;
+ int plaintext;
+ const char *port;
+ size_t slen;
+ const char *account;
+
+ if (0 == strncasecmp ("https://",
+ account_url,
+ strlen ("https://")))
+ {
+ account_url += strlen ("https://");
+ plaintext = GNUNET_NO;
+ }
+ else if (0 == strncasecmp ("http://",
+ account_url,
+ strlen ("http://")))
+ {
+ account_url += strlen ("http://");
+ plaintext = GNUNET_YES;
+ }
+ else
+ return NULL;
+ account = strchr (account_url,
+ '/');
+ if (NULL == account)
+ return NULL;
+ slen = account - account_url;
+ port = memchr (account_url,
+ ':',
+ slen);
+ if ( (0 < slen) &&
+ ('/' == account_url[slen - 1]) )
+ slen--;
+ GNUNET_asprintf (&payto,
+ ( (NULL == port) && (GNUNET_YES == plaintext) )
+ ? "payto://x-taler-bank/%.*s:80/%s"
+ : "payto://x-taler-bank/%.*s/%s",
+ (int) slen,
+ account_url,
+ account + 1);
+ return payto;
+}
+
+
+/**
* Given an x-taler-bank payto:// URL, compute
* the HTTP(S) base URL of the account.
*