testing_api_cmd_offline_sign_global_fees.c (6075B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 20 /** 21 * @file testing/testing_api_cmd_offline_sign_global_fees.c 22 * @brief run the taler-exchange-offline command to download, sign and upload global fees 23 * @author Marcello Stanisci 24 * @author Christian Grothoff 25 */ 26 #include "taler/platform.h" 27 #include "taler/taler_json_lib.h" 28 #include <gnunet/gnunet_curl_lib.h> 29 #include "taler/taler_signatures.h" 30 #include "taler/taler_testing_lib.h" 31 32 33 /** 34 * State for a "offlinesign" CMD. 35 */ 36 struct OfflineSignState 37 { 38 39 /** 40 * Process for the "offlinesign" command. 41 */ 42 struct GNUNET_Process *offlinesign_proc; 43 44 /** 45 * Configuration file used by the command. 46 */ 47 const char *config_filename; 48 49 /** 50 * The history fee to sign. 51 */ 52 const char *history_fee_s; 53 54 /** 55 * The account fee to sign. 56 */ 57 const char *account_fee_s; 58 59 /** 60 * The purse fee to sign. 61 */ 62 const char *purse_fee_s; 63 64 /** 65 * When MUST purses time out? 66 */ 67 struct GNUNET_TIME_Relative purse_timeout; 68 69 /** 70 * How long do we keep the history? 71 */ 72 struct GNUNET_TIME_Relative history_expiration; 73 74 /** 75 * Number of (free) purses per account. 76 */ 77 unsigned int num_purses; 78 }; 79 80 81 /** 82 * Run the command; calls the `taler-exchange-offline` program. 83 * 84 * @param cls closure. 85 * @param cmd the commaind being run. 86 * @param is interpreter state. 87 */ 88 static void 89 offlinesign_run (void *cls, 90 const struct TALER_TESTING_Command *cmd, 91 struct TALER_TESTING_Interpreter *is) 92 { 93 struct OfflineSignState *ks = cls; 94 char num_purses[12]; 95 char history_expiration[32]; 96 char purse_timeout[32]; 97 98 GNUNET_snprintf (num_purses, 99 sizeof (num_purses), 100 "%u", 101 ks->num_purses); 102 GNUNET_snprintf (history_expiration, 103 sizeof (history_expiration), 104 "%s", 105 GNUNET_TIME_relative2s (ks->history_expiration, 106 false)); 107 GNUNET_snprintf (purse_timeout, 108 sizeof (purse_timeout), 109 "%s", 110 GNUNET_TIME_relative2s (ks->purse_timeout, 111 false)); 112 ks->offlinesign_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR); 113 if (GNUNET_OK != 114 GNUNET_process_run_command_va ( 115 ks->offlinesign_proc, 116 "taler-exchange-offline", 117 "taler-exchange-offline", 118 "-c", ks->config_filename, 119 "-L", "INFO", 120 "global-fee", 121 "now", 122 ks->history_fee_s, 123 ks->account_fee_s, 124 ks->purse_fee_s, 125 purse_timeout, 126 history_expiration, 127 num_purses, 128 "upload", 129 NULL)) 130 { 131 GNUNET_break (0); 132 GNUNET_process_destroy (ks->offlinesign_proc); 133 ks->offlinesign_proc = NULL; 134 TALER_TESTING_interpreter_fail (is); 135 return; 136 } 137 TALER_TESTING_wait_for_sigchld (is); 138 } 139 140 141 /** 142 * Free the state of a "offlinesign" CMD, and possibly kills its 143 * process if it did not terminate correctly. 144 * 145 * @param cls closure. 146 * @param cmd the command being freed. 147 */ 148 static void 149 offlinesign_cleanup (void *cls, 150 const struct TALER_TESTING_Command *cmd) 151 { 152 struct OfflineSignState *ks = cls; 153 154 (void) cmd; 155 if (NULL != ks->offlinesign_proc) 156 { 157 GNUNET_break (GNUNET_OK == 158 GNUNET_process_kill (ks->offlinesign_proc, 159 SIGKILL)); 160 GNUNET_process_wait (ks->offlinesign_proc, 161 true, 162 NULL, 163 NULL); 164 GNUNET_process_destroy (ks->offlinesign_proc); 165 ks->offlinesign_proc = NULL; 166 } 167 GNUNET_free (ks); 168 } 169 170 171 /** 172 * Offer "offlinesign" CMD internal data to other commands. 173 * 174 * @param cls closure. 175 * @param[out] ret result 176 * @param trait name of the trait. 177 * @param index index number of the object to offer. 178 * @return #GNUNET_OK on success. 179 */ 180 static enum GNUNET_GenericReturnValue 181 offlinesign_traits (void *cls, 182 const void **ret, 183 const char *trait, 184 unsigned int index) 185 { 186 struct OfflineSignState *ks = cls; 187 struct TALER_TESTING_Trait traits[] = { 188 TALER_TESTING_make_trait_process (&ks->offlinesign_proc), 189 TALER_TESTING_trait_end () 190 }; 191 192 return TALER_TESTING_get_trait (traits, 193 ret, 194 trait, 195 index); 196 } 197 198 199 struct TALER_TESTING_Command 200 TALER_TESTING_cmd_exec_offline_sign_global_fees ( 201 const char *label, 202 const char *config_filename, 203 const char *history_fee, 204 const char *account_fee, 205 const char *purse_fee, 206 struct GNUNET_TIME_Relative purse_timeout, 207 struct GNUNET_TIME_Relative history_expiration, 208 unsigned int num_purses) 209 { 210 struct OfflineSignState *ks; 211 212 ks = GNUNET_new (struct OfflineSignState); 213 ks->config_filename = config_filename; 214 ks->history_fee_s = history_fee; 215 ks->account_fee_s = account_fee; 216 ks->purse_fee_s = purse_fee; 217 ks->purse_timeout = purse_timeout; 218 ks->history_expiration = history_expiration; 219 ks->num_purses = num_purses; 220 { 221 struct TALER_TESTING_Command cmd = { 222 .cls = ks, 223 .label = label, 224 .run = &offlinesign_run, 225 .cleanup = &offlinesign_cleanup, 226 .traits = &offlinesign_traits 227 }; 228 229 return cmd; 230 } 231 } 232 233 234 /* end of testing_api_cmd_exec_offline_sign_global_fees.c */