2018-01-23 10:28:24 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2020-01-12 23:13:46 +01:00
|
|
|
Copyright (C) 2018-2020 Taler Systems SA
|
2018-01-23 10:28:24 +01:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published
|
|
|
|
by the Free Software Foundation; either version 3, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with TALER; see the file COPYING. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
2020-01-19 15:23:19 +01:00
|
|
|
* @file testing/testing_api_trait_string.c
|
2018-05-28 17:23:05 +02:00
|
|
|
* @brief offers strings traits.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @author Marcello Stanisci
|
2020-01-12 23:13:46 +01:00
|
|
|
* @author Christian Grothoff
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include "taler_signatures.h"
|
|
|
|
#include "taler_testing_lib.h"
|
|
|
|
|
2020-01-12 23:13:46 +01:00
|
|
|
/**
|
|
|
|
* Some string. Avoid, use something more precise!
|
|
|
|
*/
|
2020-01-11 15:19:56 +01:00
|
|
|
#define TALER_TESTING_TRAIT_STRING "string"
|
2020-01-12 23:13:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An HTTP-URL.
|
|
|
|
*/
|
2018-02-14 12:46:01 +01:00
|
|
|
#define TALER_TESTING_TRAIT_URL "url"
|
2020-01-12 23:13:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A PAYTO-URL.
|
|
|
|
*/
|
|
|
|
#define TALER_TESTING_TRAIT_PAYTO "payto"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String identifying an order.
|
|
|
|
*/
|
2018-02-15 16:36:00 +01:00
|
|
|
#define TALER_TESTING_TRAIT_ORDER_ID "order-id"
|
2020-01-12 23:13:46 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-11 15:19:56 +01:00
|
|
|
* Obtain a string from @a cmd.
|
2018-01-23 10:28:24 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the subject from.
|
|
|
|
* @param index index number associated with the transfer
|
|
|
|
* subject to offer.
|
2020-01-18 13:23:10 +01:00
|
|
|
* @param[out] s where to write the offered
|
2020-01-11 15:19:56 +01:00
|
|
|
* string
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return #GNUNET_OK on success.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
int
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_get_trait_string (const struct TALER_TESTING_Command *cmd,
|
|
|
|
unsigned int index,
|
|
|
|
const char **s)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2020-01-11 15:19:56 +01:00
|
|
|
(const void **) s,
|
|
|
|
TALER_TESTING_TRAIT_STRING,
|
2018-01-23 10:28:24 +01:00
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
/**
|
2020-01-11 15:19:56 +01:00
|
|
|
* Offer string.
|
2018-01-23 10:28:24 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param index index number associated with the transfer
|
|
|
|
* subject being offered.
|
2020-01-11 15:19:56 +01:00
|
|
|
* @param s transfer subject to offer.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return the trait.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_make_trait_string (unsigned int index,
|
|
|
|
const char *s)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
2020-01-11 15:19:56 +01:00
|
|
|
.trait_name = TALER_TESTING_TRAIT_STRING,
|
|
|
|
.ptr = (const void *) s
|
2018-01-23 10:28:24 +01:00
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-01-12 23:13:46 +01:00
|
|
|
* Obtain a HTTP url from @a cmd.
|
2018-02-14 12:46:01 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the url from.
|
2018-02-14 12:46:01 +01:00
|
|
|
* @param index which url is to be picked, in case
|
|
|
|
* multiple are offered.
|
2020-01-18 13:23:10 +01:00
|
|
|
* @param[out] url where to write the url.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return #GNUNET_OK on success.
|
2018-02-14 12:46:01 +01:00
|
|
|
*/
|
|
|
|
int
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_get_trait_url (const struct TALER_TESTING_Command *cmd,
|
|
|
|
unsigned int index,
|
|
|
|
const char **url)
|
2018-02-14 12:46:01 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2018-11-17 17:19:02 +01:00
|
|
|
(const void **) url,
|
2018-02-14 12:46:01 +01:00
|
|
|
TALER_TESTING_TRAIT_URL,
|
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-14 12:46:01 +01:00
|
|
|
/**
|
2020-01-12 23:13:46 +01:00
|
|
|
* Offer HTTP url in a trait.
|
2018-02-14 12:46:01 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param index which url is to be picked,
|
|
|
|
* in case multiple are offered.
|
|
|
|
* @param url the url to offer.
|
|
|
|
*
|
|
|
|
* @return the trait.
|
2018-02-14 12:46:01 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_make_trait_url (unsigned int index,
|
|
|
|
const char *url)
|
2018-02-14 12:46:01 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
|
|
|
.trait_name = TALER_TESTING_TRAIT_URL,
|
|
|
|
.ptr = (const void *) url
|
|
|
|
};
|
2020-01-12 23:13:46 +01:00
|
|
|
|
|
|
|
GNUNET_assert (0 != strncasecmp (url,
|
|
|
|
"payto://",
|
|
|
|
strlen ("payto://")));
|
|
|
|
|
2018-02-14 12:46:01 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-15 16:36:00 +01:00
|
|
|
/**
|
|
|
|
* Obtain a order id from @a cmd.
|
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the order id from.
|
2018-02-15 16:36:00 +01:00
|
|
|
* @param index which order id is to be picked, in case
|
|
|
|
* multiple are offered.
|
2020-01-18 13:23:10 +01:00
|
|
|
* @param[out] order_id where to write the order id.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return #GNUNET_OK on success.
|
2018-02-15 16:36:00 +01:00
|
|
|
*/
|
|
|
|
int
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_get_trait_order_id (const struct TALER_TESTING_Command *cmd,
|
|
|
|
unsigned int index,
|
|
|
|
const char **order_id)
|
2018-02-15 16:36:00 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2018-11-17 17:19:02 +01:00
|
|
|
(const void **) order_id,
|
2018-02-15 16:36:00 +01:00
|
|
|
TALER_TESTING_TRAIT_ORDER_ID,
|
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-15 16:36:00 +01:00
|
|
|
/**
|
|
|
|
* Offer order id in a trait.
|
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param index which order id is to be offered,
|
|
|
|
* in case multiple are offered.
|
|
|
|
* @param order_id the order id to offer.
|
|
|
|
* @return the trait.
|
2018-02-15 16:36:00 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_make_trait_order_id (unsigned int index,
|
|
|
|
const char *order_id)
|
2018-02-15 16:36:00 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
2018-02-15 17:23:29 +01:00
|
|
|
.trait_name = TALER_TESTING_TRAIT_ORDER_ID,
|
2018-04-02 14:24:45 +02:00
|
|
|
.ptr = (const void *) order_id
|
2018-02-15 16:36:00 +01:00
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
2018-02-14 12:46:01 +01:00
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/**
|
2020-01-12 23:13:46 +01:00
|
|
|
* Obtain a PAYTO-url from @a cmd.
|
2018-02-22 14:51:12 +01:00
|
|
|
*
|
2020-01-12 23:13:46 +01:00
|
|
|
* @param cmd command to extract the url from.
|
2020-01-15 13:22:28 +01:00
|
|
|
* @param pt which url is to be picked, in case
|
2018-02-22 14:51:12 +01:00
|
|
|
* multiple are offered.
|
2020-01-18 13:23:10 +01:00
|
|
|
* @param[out] url where to write the url.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return #GNUNET_OK on success.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
int
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_get_trait_payto (const struct TALER_TESTING_Command *cmd,
|
|
|
|
enum TALER_TESTING_PaytoType pt,
|
|
|
|
const char **url)
|
2018-02-22 14:51:12 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2020-01-12 23:13:46 +01:00
|
|
|
(const void **) url,
|
|
|
|
TALER_TESTING_TRAIT_PAYTO,
|
2020-01-15 13:22:28 +01:00
|
|
|
(unsigned int) pt);
|
2018-02-22 14:51:12 +01:00
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/**
|
2020-01-12 23:13:46 +01:00
|
|
|
* Offer a "payto" URL reference.
|
2018-02-22 14:51:12 +01:00
|
|
|
*
|
2020-01-15 13:22:28 +01:00
|
|
|
* @param pt which reference is to be offered,
|
2018-05-28 17:23:05 +02:00
|
|
|
* in case multiple are offered.
|
2020-01-18 20:20:24 +01:00
|
|
|
* @param payto_uri the payto URI
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return the trait.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
2020-01-15 13:22:28 +01:00
|
|
|
TALER_TESTING_make_trait_payto (enum TALER_TESTING_PaytoType pt,
|
2020-01-18 20:20:24 +01:00
|
|
|
const char *payto_uri)
|
2018-02-22 14:51:12 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
2020-01-15 13:22:28 +01:00
|
|
|
.index = (unsigned int) pt,
|
2020-01-12 23:13:46 +01:00
|
|
|
.trait_name = TALER_TESTING_TRAIT_PAYTO,
|
2020-01-18 20:20:24 +01:00
|
|
|
.ptr = (const void *) payto_uri,
|
2018-02-22 14:51:12 +01:00
|
|
|
};
|
2020-01-12 23:13:46 +01:00
|
|
|
|
2020-01-18 20:20:24 +01:00
|
|
|
GNUNET_assert (0 == strncasecmp (payto_uri,
|
2020-01-12 23:13:46 +01:00
|
|
|
"payto://",
|
|
|
|
strlen ("payto://")));
|
2018-02-22 14:51:12 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
/* end of testing_api_trait_string.c */
|