From payto:// to base url.

The conversion prepends http// or https://
depending on the port given beside the hostname.
If port is 433, then prepends https://, otherwise
prepends http://.

For now, the conversion was only necessary at
the /history bank lib.
This commit is contained in:
Marcello Stanisci 2018-06-12 19:16:43 +02:00
parent 01f933bbdc
commit 6f579eb833
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
5 changed files with 60 additions and 11 deletions

View File

@ -78,6 +78,7 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh,
const json_t *history) const json_t *history)
{ {
json_t *history_array; json_t *history_array;
char *bank_hostname;
if (NULL == (history_array = json_object_get (history, "data"))) if (NULL == (history_array = json_object_get (history, "data")))
{ {
@ -136,11 +137,17 @@ parse_account_history (struct TALER_BANK_HistoryHandle *hh,
GNUNET_JSON_parse_free (hist_spec); GNUNET_JSON_parse_free (hist_spec);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
/* Note, bank_base_url has _always_ the protocol scheme
* and it proved to be good at this point. */
bank_hostname = strchr (hh->bank_base_url, ':');
GNUNET_assert (NULL != bank_hostname);
bank_hostname += 3;
GNUNET_asprintf (&td.account_url, GNUNET_asprintf (&td.account_url,
('/' == hh->bank_base_url[strlen(hh->bank_base_url)-1]) ('/' == bank_hostname[strlen(bank_hostname)-1])
? "payto://x-taler-bank/%s%llu" ? "payto://x-taler-bank/%s%llu"
: "payto://x-taler-bank/%s/%llu", : "payto://x-taler-bank/%s/%llu",
hh->bank_base_url, bank_hostname,
(unsigned long long) other_account); (unsigned long long) other_account);
hh->hcb (hh->hcb_cls, hh->hcb (hh->hcb_cls,
MHD_HTTP_OK, MHD_HTTP_OK,

View File

@ -960,6 +960,8 @@ handle_mhd_request (void *cls,
/* Unexpected URL path, just close the connection. */ /* Unexpected URL path, just close the connection. */
/* we're rather impolite here, but it's a testcase. */ /* we're rather impolite here, but it's a testcase. */
TALER_LOG_ERROR ("Breaking URL: %s\n",
url);
GNUNET_break_op (0); GNUNET_break_op (0);
return MHD_NO; return MHD_NO;
} }

View File

@ -328,7 +328,7 @@ build_history (struct InterpreterState *is,
h[total].direction |= TALER_BANK_DIRECTION_CANCEL; h[total].direction |= TALER_BANK_DIRECTION_CANCEL;
GNUNET_asprintf (&h[total].details.account_url, GNUNET_asprintf (&h[total].details.account_url,
"payto://x-taler-bank/%s/%llu", "payto://x-taler-bank/%s/%llu",
"http://localhost:8080", "localhost:8080",
(unsigned long long) pos->details.admin_add_incoming.debit_account_no); (unsigned long long) pos->details.admin_add_incoming.debit_account_no);
} }
if ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_DEBIT)) && if ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_DEBIT)) &&
@ -340,7 +340,7 @@ build_history (struct InterpreterState *is,
h[total].direction |= TALER_BANK_DIRECTION_CANCEL; h[total].direction |= TALER_BANK_DIRECTION_CANCEL;
GNUNET_asprintf (&h[total].details.account_url, GNUNET_asprintf (&h[total].details.account_url,
"payto://x-taler-bank/%s/%llu", "payto://x-taler-bank/%s/%llu",
"http://localhost:8080", "localhost:8080",
(unsigned long long) pos->details.admin_add_incoming.credit_account_no); (unsigned long long) pos->details.admin_add_incoming.credit_account_no);
} }
if ( ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_CREDIT)) && if ( ( (0 != (cmd->details.history.direction & TALER_BANK_DIRECTION_CREDIT)) &&

View File

@ -380,6 +380,9 @@ build_history (struct TALER_TESTING_Interpreter *is,
const struct TALER_TESTING_Command *pos = &is->commands[off]; const struct TALER_TESTING_Command *pos = &is->commands[off];
int cancelled; int cancelled;
const uint64_t *row_id; const uint64_t *row_id;
char *bank_hostname;
const uint64_t *credit_account_no;
const uint64_t *debit_account_no;
if (GNUNET_OK != TALER_TESTING_GET_TRAIT_ROW_ID if (GNUNET_OK != TALER_TESTING_GET_TRAIT_ROW_ID
(pos, &row_id)) (pos, &row_id))
@ -408,8 +411,6 @@ build_history (struct TALER_TESTING_Interpreter *is,
TALER_LOG_INFO ("hit limit specified by command\n"); TALER_LOG_INFO ("hit limit specified by command\n");
break; break;
} }
const uint64_t *credit_account_no;
const uint64_t *debit_account_no;
GNUNET_assert GNUNET_assert
(GNUNET_OK == TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT (GNUNET_OK == TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT
@ -444,6 +445,10 @@ build_history (struct TALER_TESTING_Interpreter *is,
continue; continue;
} }
bank_hostname = strchr (hs->bank_url, ':');
GNUNET_assert (NULL != bank_hostname);
bank_hostname += 3;
if ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && if ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) &&
(hs->account_no == *credit_account_no)) (hs->account_no == *credit_account_no))
{ {
@ -453,10 +458,10 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_asprintf GNUNET_asprintf
(&h[total].details.account_url, (&h[total].details.account_url,
('/' == hs->bank_url[strlen(hs->bank_url) -1]) ('/' == bank_hostname[strlen(bank_hostname) -1])
? "payto://x-taler-bank/%s%llu" ? "payto://x-taler-bank/%s%llu"
: "payto://x-taler-bank/%s/%llu", : "payto://x-taler-bank/%s/%llu",
hs->bank_url, bank_hostname,
(unsigned long long) *debit_account_no); (unsigned long long) *debit_account_no);
} }
if ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) && if ( (0 != (hs->direction & TALER_BANK_DIRECTION_DEBIT)) &&
@ -468,10 +473,10 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_asprintf GNUNET_asprintf
(&h[total].details.account_url, (&h[total].details.account_url,
('/' == hs->bank_url[strlen(hs->bank_url) -1]) ('/' == bank_hostname[strlen(bank_hostname) -1])
? "payto://x-taler-bank/%s%llu" ? "payto://x-taler-bank/%s%llu"
: "payto://x-taler-bank/%s/%llu", : "payto://x-taler-bank/%s/%llu",
hs->bank_url, bank_hostname,
(unsigned long long) *credit_account_no); (unsigned long long) *credit_account_no);
} }
if ( ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) && if ( ( (0 != (hs->direction & TALER_BANK_DIRECTION_CREDIT)) &&

View File

@ -978,6 +978,9 @@ taler_bank_get_history (void *cls,
const uint64_t *start_off_b64; const uint64_t *start_off_b64;
uint64_t start_row; uint64_t start_row;
struct Account account; struct Account account;
char *bank_base_url;
char *p;
long long unsigned port;
if (0 == num_results) if (0 == num_results)
{ {
@ -1029,8 +1032,40 @@ taler_bank_get_history (void *cls,
whh->hres_cb = hres_cb; whh->hres_cb = hres_cb;
whh->hres_cb_cls = hres_cb_cls; whh->hres_cb_cls = hres_cb_cls;
if (NULL != (p = strchr (account.hostname,
(unsigned char) ':')))
{
p++;
if (1 != sscanf (p,
"%llu",
&port))
{
GNUNET_break (0);
TALER_LOG_ERROR ("Malformed host from payto:// URI\n");
return NULL;
}
}
if (443 != port)
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&bank_base_url,
"http://%s",
account.hostname));
}
else
{
GNUNET_assert
(GNUNET_SYSERR != GNUNET_asprintf
(&bank_base_url,
"https://%s",
account.hostname));
}
whh->hh = TALER_BANK_history (tc->ctx, whh->hh = TALER_BANK_history (tc->ctx,
account.hostname, bank_base_url,
&whh->auth, &whh->auth,
(uint64_t) account.no, (uint64_t) account.no,
direction, direction,