2018-01-23 10:28:24 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2018 Taler Systems SA
|
|
|
|
|
|
|
|
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/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file exchange-lib/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
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include "exchange_api_handle.h"
|
|
|
|
#include "taler_signatures.h"
|
|
|
|
#include "taler_testing_lib.h"
|
|
|
|
|
|
|
|
#define TALER_TESTING_TRAIT_CONTRACT_TERMS "contract-terms"
|
2020-01-11 15:19:56 +01:00
|
|
|
#define TALER_TESTING_TRAIT_STRING "string"
|
2018-01-23 10:28:24 +01:00
|
|
|
#define TALER_TESTING_TRAIT_AMOUNT "amount"
|
2018-02-14 12:46:01 +01:00
|
|
|
#define TALER_TESTING_TRAIT_URL "url"
|
2018-02-15 16:36:00 +01:00
|
|
|
#define TALER_TESTING_TRAIT_ORDER_ID "order-id"
|
2018-02-22 14:51:12 +01:00
|
|
|
#define TALER_TESTING_TRAIT_REJECTED "rejected"
|
2018-01-23 10:28:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain contract terms from @a cmd.
|
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the contract terms from.
|
|
|
|
* @param index contract terms index number.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @param contract_terms[out] where to write the contract
|
|
|
|
* terms.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @return #GNUNET_OK on success.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_TESTING_get_trait_contract_terms
|
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
unsigned int index,
|
|
|
|
const json_t **contract_terms)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2018-11-17 17:19:02 +01:00
|
|
|
(const void **) contract_terms,
|
2018-01-23 10:28:24 +01:00
|
|
|
TALER_TESTING_TRAIT_CONTRACT_TERMS,
|
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
/**
|
2018-05-28 17:23:05 +02:00
|
|
|
* Offer contract terms.
|
|
|
|
*
|
|
|
|
* @param index contract terms index number.
|
|
|
|
* @param contract_terms contract terms to offer.
|
|
|
|
* @return the trait.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
|
|
|
TALER_TESTING_make_trait_contract_terms
|
|
|
|
(unsigned int index,
|
2019-08-25 16:18:24 +02:00
|
|
|
const json_t *contract_terms)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
|
|
|
.trait_name = TALER_TESTING_TRAIT_CONTRACT_TERMS,
|
|
|
|
.ptr = (const void *) contract_terms
|
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
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-11 15:19:56 +01:00
|
|
|
* @param s[out] where to write the offered
|
|
|
|
* 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-11 15:19:56 +01:00
|
|
|
TALER_TESTING_get_trait_string
|
2018-01-23 10:28:24 +01:00
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
unsigned int index,
|
2020-01-11 15:19:56 +01:00
|
|
|
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-11 15:19:56 +01:00
|
|
|
TALER_TESTING_make_trait_string
|
2018-01-23 10:28:24 +01:00
|
|
|
(unsigned int index,
|
2020-01-11 15:19:56 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain an amount from @a cmd.
|
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the amount from.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @param index which amount is to be picked, in case
|
|
|
|
* multiple are offered.
|
|
|
|
* @param amount[out] where to write the wire details.
|
2018-05-28 17:23:05 +02:00
|
|
|
*
|
|
|
|
* @return #GNUNET_OK on success.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_TESTING_get_trait_amount
|
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
unsigned int index,
|
|
|
|
const char **amount)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2018-11-17 17:19:02 +01:00
|
|
|
(const void **) amount,
|
2018-01-23 10:28:24 +01:00
|
|
|
TALER_TESTING_TRAIT_AMOUNT,
|
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
/**
|
|
|
|
* Offer amount in a trait.
|
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param index which amount is to be offered,
|
|
|
|
* in case multiple are offered.
|
|
|
|
* @param amount the amount to offer.
|
|
|
|
*
|
|
|
|
* @return the trait.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
|
|
|
TALER_TESTING_make_trait_amount
|
|
|
|
(unsigned int index,
|
2019-08-25 16:18:24 +02:00
|
|
|
const char *amount)
|
2018-01-23 10:28:24 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
|
|
|
.trait_name = TALER_TESTING_TRAIT_AMOUNT,
|
|
|
|
.ptr = (const void *) amount
|
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-14 12:46:01 +01:00
|
|
|
/**
|
|
|
|
* Obtain a url from @a cmd.
|
|
|
|
*
|
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.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param url[out] where to write the url.
|
|
|
|
*
|
|
|
|
* @return #GNUNET_OK on success.
|
2018-02-14 12:46:01 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_TESTING_get_trait_url
|
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
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
|
|
|
/**
|
|
|
|
* Offer url in a trait.
|
|
|
|
*
|
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
|
|
|
|
TALER_TESTING_make_trait_url
|
|
|
|
(unsigned int index,
|
2019-08-25 16:18:24 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
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.
|
|
|
|
* @param order_id[out] 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
|
|
|
|
TALER_TESTING_get_trait_order_id
|
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
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
|
|
|
|
TALER_TESTING_make_trait_order_id
|
|
|
|
(unsigned int index,
|
2019-08-25 16:18:24 +02:00
|
|
|
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
|
|
|
/**
|
2018-05-28 17:23:05 +02:00
|
|
|
* Obtain the reference to a "reject" CMD. Usually offered
|
|
|
|
* by _rejected_ bank transfers.
|
2018-02-22 14:51:12 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param cmd command to extract the reference from.
|
2018-02-22 14:51:12 +01:00
|
|
|
* @param index which reference is to be picked, in case
|
|
|
|
* multiple are offered.
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param rejected_reference[out] where to write the reference.
|
|
|
|
*
|
|
|
|
* @return #GNUNET_OK on success.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
TALER_TESTING_get_trait_rejected
|
|
|
|
(const struct TALER_TESTING_Command *cmd,
|
2019-08-25 16:18:24 +02:00
|
|
|
unsigned int index,
|
|
|
|
const char **rejected_reference)
|
2018-02-22 14:51:12 +01:00
|
|
|
{
|
|
|
|
return cmd->traits (cmd->cls,
|
2018-11-17 17:19:02 +01:00
|
|
|
(const void **) rejected_reference,
|
2018-02-22 14:51:12 +01:00
|
|
|
TALER_TESTING_TRAIT_REJECTED,
|
|
|
|
index);
|
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-02-22 14:51:12 +01:00
|
|
|
/**
|
2018-05-28 17:23:05 +02:00
|
|
|
* Offer a "reject" CMD reference.
|
2018-02-22 14:51:12 +01:00
|
|
|
*
|
2018-05-28 17:23:05 +02:00
|
|
|
* @param index which reference is to be offered,
|
|
|
|
* in case multiple are offered.
|
|
|
|
* @param rejected_reference the reference to offer.
|
|
|
|
*
|
|
|
|
* @return the trait.
|
2018-02-22 14:51:12 +01:00
|
|
|
*/
|
|
|
|
struct TALER_TESTING_Trait
|
|
|
|
TALER_TESTING_make_trait_rejected
|
|
|
|
(unsigned int index,
|
2019-08-25 16:18:24 +02:00
|
|
|
const char *rejected)
|
2018-02-22 14:51:12 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Trait ret = {
|
|
|
|
.index = index,
|
|
|
|
.trait_name = TALER_TESTING_TRAIT_REJECTED,
|
2018-04-02 14:24:45 +02:00
|
|
|
.ptr = (const void *) rejected
|
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 */
|