exchange/src/testing/testing_api_cmd_exec_keyup.c

236 lines
5.6 KiB
C
Raw Normal View History

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 testing/testing_api_cmd_exec_keyup.c
2018-01-23 10:28:24 +01:00
* @brief run the taler-exchange-keyup command
* @author Marcello Stanisci
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
#include "taler_signatures.h"
#include "taler_testing_lib.h"
2018-05-26 10:36:54 +02:00
/**
* State for a "keyup" CMD.
*/
2018-01-23 10:28:24 +01:00
struct KeyupState
{
/**
* Process for the "keyup" command.
*/
struct GNUNET_OS_Process *keyup_proc;
/**
2018-05-26 10:36:54 +02:00
* Configuration file used by the command.
2018-01-23 10:28:24 +01:00
*/
const char *config_filename;
/**
* If GNUNET_YES, then the fake @e now value will be
2019-04-03 18:02:58 +02:00
* passed to taler-exchange-keyup via the --time
* option.
*/
unsigned int with_now;
/**
* User-provided fake now.
*/
struct GNUNET_TIME_Absolute now;
2018-01-23 10:28:24 +01:00
};
/**
2018-05-26 10:36:54 +02:00
* Run the command; calls the `taler-exchange-keyup' program.
2018-01-23 10:28:24 +01:00
*
2018-05-26 10:36:54 +02:00
* @param cls closure.
* @param cmd the commaind being run.
* @param is interpreter state.
2018-01-23 10:28:24 +01:00
*/
static void
keyup_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
struct KeyupState *ks = cls;
if (GNUNET_YES == ks->with_now)
{
2019-08-25 16:18:24 +02:00
ks->keyup_proc = GNUNET_OS_start_process
(GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-exchange-keyup",
"taler-exchange-keyup",
"-c", ks->config_filename,
"-o", "auditor.in",
"--time",
GNUNET_STRINGS_absolute_time_to_string (ks->now),
NULL);
}
else
ks->keyup_proc = GNUNET_OS_start_process
2019-08-25 16:18:24 +02:00
(GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-exchange-keyup",
"taler-exchange-keyup",
"-c", ks->config_filename,
"-o", "auditor.in",
NULL);
2018-01-23 10:28:24 +01:00
if (NULL == ks->keyup_proc)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
2019-04-03 18:02:58 +02:00
/* This function does not tell whether the command
* succeeded or not! */
2018-01-23 10:28:24 +01:00
TALER_TESTING_wait_for_sigchld (is);
}
/**
2018-05-26 10:36:54 +02:00
* Free the state of a "keyup" CMD, and possibly kills its
* process if it did not terminate correctly.
2018-01-23 10:28:24 +01:00
*
2018-05-26 10:36:54 +02:00
* @param cls closure.
* @param cmd the command being freed.
2018-01-23 10:28:24 +01:00
*/
static void
keyup_cleanup (void *cls,
const struct TALER_TESTING_Command *cmd)
{
struct KeyupState *ks = cls;
if (NULL != ks->keyup_proc)
{
GNUNET_break (0 ==
GNUNET_OS_process_kill (ks->keyup_proc,
SIGKILL));
GNUNET_OS_process_wait (ks->keyup_proc);
GNUNET_OS_process_destroy (ks->keyup_proc);
ks->keyup_proc = NULL;
}
GNUNET_free (ks);
}
/**
2018-05-26 10:36:54 +02:00
* Offer "keyup" CMD internal data to other commands.
2018-01-23 10:28:24 +01:00
*
2018-05-26 10:36:54 +02:00
* @param cls closure.
2020-01-18 13:57:47 +01:00
* @param[out] ret result
2018-05-26 10:36:54 +02:00
* @param trait name of the trait.
2018-05-29 12:43:34 +02:00
* @param index index number of the object to offer.
2018-05-26 10:36:54 +02:00
*
* @return #GNUNET_OK on success.
2018-01-23 10:28:24 +01:00
*/
static int
keyup_traits (void *cls,
2018-11-17 17:19:02 +01:00
const void **ret,
2018-01-23 10:28:24 +01:00
const char *trait,
unsigned int index)
{
struct KeyupState *ks = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_process (0, &ks->keyup_proc),
TALER_TESTING_trait_end ()
};
return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
}
/**
* Make the "keyup" CMD, with "--timestamp" option.
*
* @param label command label.
* @param config_filename configuration filename.
* @param now Unix timestamp representing the fake "now".
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_keyup_with_now
(const char *label,
2019-08-25 16:18:24 +02:00
const char *config_filename,
struct GNUNET_TIME_Absolute now)
{
struct KeyupState *ks;
ks = GNUNET_new (struct KeyupState);
ks->config_filename = config_filename;
ks->now = now;
ks->with_now = GNUNET_YES;
2020-01-18 13:57:47 +01:00
{
struct TALER_TESTING_Command cmd = {
.cls = ks,
.label = label,
.run = &keyup_run,
.cleanup = &keyup_cleanup,
.traits = &keyup_traits
};
return cmd;
}
}
2019-10-31 12:59:50 +01:00
2018-01-23 10:28:24 +01:00
/**
2018-05-26 10:36:54 +02:00
* Make the "keyup" CMD.
2018-01-23 10:28:24 +01:00
*
2018-05-26 10:36:54 +02:00
* @param label command label.
* @param config_filename configuration filename.
2018-01-23 10:28:24 +01:00
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_keyup (const char *label,
const char *config_filename)
{
struct KeyupState *ks;
ks = GNUNET_new (struct KeyupState);
ks->config_filename = config_filename;
2020-01-18 13:57:47 +01:00
{
struct TALER_TESTING_Command cmd = {
.cls = ks,
.label = label,
.run = &keyup_run,
.cleanup = &keyup_cleanup,
.traits = &keyup_traits
};
return cmd;
}
2018-01-23 10:28:24 +01:00
}
2019-10-31 12:59:50 +01:00
2018-01-23 10:28:24 +01:00
/* end of testing_api_cmd_exec_keyup.c */