summaryrefslogtreecommitdiff
path: root/src/exchange-lib/testing_api_cmd_wire.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-02 14:24:45 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-02 14:29:44 +0200
commitcb55c1a3af9f56a6da38e5589e72df0b70d355b1 (patch)
tree5f9a3af7d9073249f77ce56c690844a6cb27c3e7 /src/exchange-lib/testing_api_cmd_wire.c
parent7a20062bafed42f937c5388aed09042aad7014c0 (diff)
downloadexchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.gz
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.tar.bz2
exchange-cb55c1a3af9f56a6da38e5589e72df0b70d355b1.zip
Changing configuration structure to enable multiple accounts.
This change enables using multiple wire plugins at the same time. Also, we now distinguish between the wire plugin (i.e. EBICS or taler_bank) and the wire method (i.e. SEPA or x-taler-bank) that the wire plugin is implementing. The "taler-bank" wire method was renamed from "test" to "x-taler-bank". This also changes the format of the /wire response of the exchange, as we now need to return multiple accounts. Note that wire fees are specified per wire method, not per wire account. taler-exchange-keyup now automatically signs all of the /wire responses in the location specified by the configuration. Account identification in wire plugins was changed to use payto://-URLs instead of method-specific JSON fields. Signing and validation of /wire responses was moved from each wire plugin to a generic validation method in libtalerutil (crypto) or libtalerjson (for JSON-formatted inputs). Convenience methods were added to generate JSON for wire accounts (salting, signing). Various section and option names were adjusted to streamline the configuration and make it more consistent overall. Documentation was updated as well.
Diffstat (limited to 'src/exchange-lib/testing_api_cmd_wire.c')
-rw-r--r--src/exchange-lib/testing_api_cmd_wire.c129
1 files changed, 47 insertions, 82 deletions
diff --git a/src/exchange-lib/testing_api_cmd_wire.c b/src/exchange-lib/testing_api_cmd_wire.c
index f65daec00..cf8304e29 100644
--- a/src/exchange-lib/testing_api_cmd_wire.c
+++ b/src/exchange-lib/testing_api_cmd_wire.c
@@ -27,6 +27,7 @@
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
#include "exchange_api_handle.h"
+#include "taler_wire_lib.h"
#include "taler_testing_lib.h"
struct WireState
@@ -71,19 +72,6 @@ struct WireState
/**
- * Check all the expected values have been returned by /wire.
- *
- * @param cls closure
- * @param wire_method name of the wire method (i.e. "sepa")
- * @param fees fee structure for this method
- */
-static void
-check_method_and_fee_cb
- (void *cls,
- const char *wire_method,
- const struct TALER_EXCHANGE_WireAggregateFees *fees);
-
-/**
* Callbacks called with the result(s) of a wire format inquiry
* request to the exchange.
*
@@ -92,23 +80,20 @@ check_method_and_fee_cb
* for successful request; 0 if the exchange's
* reply is bogus (fails to follow the protocol)
* @param ec taler-specific error code, #TALER_EC_NONE on success
- * @param obj the received JSON reply, if successful this should
- * be the wire format details as provided by /wire.
+ * @param accounts_len length of the @a accounts array
+ * @param accounts list of wire accounts of the exchange, NULL on error
*/
static void
wire_cb (void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
- const json_t *obj)
+ unsigned int accounts_len,
+ const struct TALER_EXCHANGE_WireAccount *accounts)
{
struct WireState *ws = cls;
- struct TALER_TESTING_Command *cmd
- = &ws->is->commands[ws->is->ip];
+ struct TALER_TESTING_Command *cmd = &ws->is->commands[ws->is->ip];
+ struct TALER_Amount expected_fee;
- /**
- * The handle has been free'd by GNUnet curl-lib. FIXME:
- * shouldn't GNUnet nullify it once it frees it?
- */
ws->wh = NULL;
if (ws->expected_response_code != http_status)
{
@@ -117,74 +102,54 @@ wire_cb (void *cls,
return;
}
- if (GNUNET_OK != TALER_EXCHANGE_wire_get_fees
- (&TALER_EXCHANGE_get_keys (ws->exchange)->master_pub,
- obj,
- // will check synchronously.
- &check_method_and_fee_cb,
- ws))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire fee extraction in command %s failed\n",
- cmd->label);
- json_dumpf (obj, stderr, 0);
- TALER_TESTING_interpreter_fail (ws->is);
- return;
- }
-
- if (ws->method_found != GNUNET_OK)
+ if (MHD_HTTP_OK == http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "/wire does not offer method '%s'\n",
- ws->expected_method);
- TALER_TESTING_interpreter_fail (ws->is);
- return;
- }
- TALER_TESTING_interpreter_next (ws->is);
-}
-
-/**
- * Check all the expected values have been returned by /wire.
- *
- * @param cls closure
- * @param wire_method name of the wire method (i.e. "sepa")
- * @param fees fee structure for this method
- */
-static void
-check_method_and_fee_cb
- (void *cls,
- const char *wire_method,
- const struct TALER_EXCHANGE_WireAggregateFees *fees)
-{
- struct WireState *ws = cls;
- struct TALER_TESTING_Command *cmd
- = &ws->is->commands[ws->is->ip]; // ugly?
- struct TALER_Amount expected_fee;
-
- if (0 == strcmp (ws->expected_method, wire_method))
- ws->method_found = GNUNET_OK;
-
- if ( ws->expected_fee && (ws->method_found == GNUNET_OK) )
- {
- GNUNET_assert (GNUNET_OK == TALER_string_to_amount
- (ws->expected_fee,
- &expected_fee));
- while (NULL != fees)
+ for (unsigned int i=0;i<accounts_len;i++)
{
- if (0 != TALER_amount_cmp (&fees->wire_fee,
- &expected_fee))
+ char *method;
+
+ method = TALER_WIRE_payto_get_method (accounts[i].url);
+ if (0 == strcmp (ws->expected_method,
+ method))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire fee missmatch to command %s\n",
- cmd->label);
- TALER_TESTING_interpreter_fail (ws->is);
- return;
+ ws->method_found = GNUNET_OK;
+ if (NULL != ws->expected_fee)
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (ws->expected_fee,
+ &expected_fee));
+ for (const struct TALER_EXCHANGE_WireAggregateFees *waf = accounts[i].fees;
+ NULL != waf;
+ waf = waf->next)
+ {
+ if (0 != TALER_amount_cmp (&waf->wire_fee,
+ &expected_fee))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Wire fee missmatch to command %s\n",
+ cmd->label);
+ TALER_TESTING_interpreter_fail (ws->is);
+ GNUNET_free (method);
+ return;
+ }
+ }
+ }
}
- fees = fees->next;
+ GNUNET_free (method);
+ }
+ if (GNUNET_OK != ws->method_found)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "/wire does not offer method '%s'\n",
+ ws->expected_method);
+ TALER_TESTING_interpreter_fail (ws->is);
+ return;
}
}
+ TALER_TESTING_interpreter_next (ws->is);
}
+
/**
* Run the command.
*