expose TALER_JSON_validate_payto

This commit is contained in:
Christian Grothoff 2021-07-20 15:36:08 +02:00
parent 195a6b6b3d
commit 5c569d3df7
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -368,27 +368,25 @@ validate_payto_iban (const char *account_url)
} }
/** enum GNUNET_GenericReturnValue
* Validate payto:// account URL (only account information, TALER_JSON_validate_payto (const char *payto_uri)
* wire subject and amount are ignored).
*
* @param account_url URL to parse
* @return #GNUNET_YES if @a account_url is a valid payto://iban URI
* #GNUNET_NO if @a account_url is a payto URI of an unsupported type (but may be valid)
* #GNUNET_SYSERR if the account incorrect or this is not a payto://-URI at all
*/
static int
validate_payto (const char *account_url)
{ {
int ret; enum GNUNET_GenericReturnValue ret;
const char *start;
const char *end;
#define PAYTO_PREFIX "payto://" #define PAYTO_PREFIX "payto://"
if (0 != strncasecmp (account_url, if (0 != strncasecmp (payto_uri,
PAYTO_PREFIX, PAYTO_PREFIX,
strlen (PAYTO_PREFIX))) strlen (PAYTO_PREFIX)))
return GNUNET_SYSERR; /* not payto */ return GNUNET_SYSERR; /* not payto */
start = &payto_uri[strlen (PAYTO_PREFIX)];
#undef PAYTO_PREFIX #undef PAYTO_PREFIX
if (GNUNET_NO != (ret = validate_payto_iban (account_url))) end = strchr (start,
(unsigned char) '/');
if (NULL == end)
return GNUNET_SYSERR;
if (GNUNET_NO != (ret = validate_payto_iban (payto_uri)))
{ {
GNUNET_break_op (GNUNET_SYSERR != ret); GNUNET_break_op (GNUNET_SYSERR != ret);
return ret; /* got a definitive answer */ return ret; /* got a definitive answer */
@ -431,7 +429,8 @@ TALER_JSON_merchant_wire_signature_hash (const json_t *wire_s,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Validating `%s'\n", "Validating `%s'\n",
payto_uri); payto_uri);
if (GNUNET_SYSERR == validate_payto (payto_uri)) if (GNUNET_SYSERR ==
TALER_JSON_validate_payto (payto_uri))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -473,7 +472,8 @@ TALER_JSON_exchange_wire_signature_check (
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if (GNUNET_SYSERR == validate_payto (payto_uri)) if (GNUNET_SYSERR ==
TALER_JSON_validate_payto (payto_uri))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -499,7 +499,8 @@ TALER_JSON_exchange_wire_signature_make (
{ {
struct TALER_MasterSignatureP master_sig; struct TALER_MasterSignatureP master_sig;
if (GNUNET_SYSERR == validate_payto (payto_uri)) if (GNUNET_SYSERR ==
TALER_JSON_validate_payto (payto_uri))
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return NULL; return NULL;
@ -536,7 +537,8 @@ TALER_JSON_wire_to_payto (const json_t *wire_s)
"Malformed wire record encountered: lacks payto://-url\n"); "Malformed wire record encountered: lacks payto://-url\n");
return NULL; return NULL;
} }
if (GNUNET_SYSERR == validate_payto (payto_str)) if (GNUNET_SYSERR ==
TALER_JSON_validate_payto (payto_str))
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed wire record encountered: payto URI `%s' invalid\n", "Malformed wire record encountered: payto URI `%s' invalid\n",