testing_api_cmd_offline_sign_extensions.c (4483B)
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_extensions.c 22 * @brief run the taler-exchange-offline command to sign extensions (and therefore activate them) 23 * @author Özgür Kesim 24 */ 25 #include "taler/platform.h" 26 #include "taler/taler_json_lib.h" 27 #include <gnunet/gnunet_curl_lib.h> 28 #include "taler/taler_signatures.h" 29 #include "taler/taler_testing_lib.h" 30 31 32 /** 33 * State for a "extensionssign" CMD. 34 */ 35 struct ExtensionsSignState 36 { 37 38 /** 39 * Process for the "extensionssign" command. 40 */ 41 struct GNUNET_Process *extensionssign_proc; 42 43 /** 44 * Configuration file used by the command. 45 */ 46 const char *config_filename; 47 48 }; 49 50 51 /** 52 * Run the command; calls the `taler-exchange-offline` program. 53 * 54 * @param cls closure. 55 * @param cmd the commaind being run. 56 * @param is interpreter state. 57 */ 58 static void 59 extensionssign_run (void *cls, 60 const struct TALER_TESTING_Command *cmd, 61 struct TALER_TESTING_Interpreter *is) 62 { 63 struct ExtensionsSignState *ks = cls; 64 65 ks->extensionssign_proc 66 = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR); 67 if (GNUNET_OK != 68 GNUNET_process_run_command_va ( 69 ks->extensionssign_proc, 70 "taler-exchange-offline", 71 "taler-exchange-offline", 72 "-c", ks->config_filename, 73 "-L", "INFO", 74 "extensions", 75 "sign", 76 "upload", 77 NULL)) 78 { 79 GNUNET_break (0); 80 GNUNET_process_destroy (ks->extensionssign_proc); 81 ks->extensionssign_proc = NULL; 82 TALER_TESTING_interpreter_fail (is); 83 return; 84 } 85 TALER_TESTING_wait_for_sigchld (is); 86 } 87 88 89 /** 90 * Free the state of a "extensionssign" CMD, and possibly kills its 91 * process if it did not terminate correctly. 92 * 93 * @param cls closure. 94 * @param cmd the command being freed. 95 */ 96 static void 97 extensionssign_cleanup (void *cls, 98 const struct TALER_TESTING_Command *cmd) 99 { 100 struct ExtensionsSignState *ks = cls; 101 102 (void) cmd; 103 if (NULL != ks->extensionssign_proc) 104 { 105 GNUNET_break (GNUNET_OK == 106 GNUNET_process_kill (ks->extensionssign_proc, 107 SIGKILL)); 108 GNUNET_process_wait (ks->extensionssign_proc, 109 true, 110 NULL, 111 NULL); 112 GNUNET_process_destroy (ks->extensionssign_proc); 113 ks->extensionssign_proc = NULL; 114 } 115 GNUNET_free (ks); 116 } 117 118 119 /** 120 * Offer "extensionssign" CMD internal data to other commands. 121 * 122 * @param cls closure. 123 * @param[out] ret result 124 * @param trait name of the trait. 125 * @param index index number of the object to offer. 126 * @return #GNUNET_OK on success. 127 */ 128 static enum GNUNET_GenericReturnValue 129 extensionssign_traits (void *cls, 130 const void **ret, 131 const char *trait, 132 unsigned int index) 133 { 134 struct ExtensionsSignState *ks = cls; 135 struct TALER_TESTING_Trait traits[] = { 136 TALER_TESTING_make_trait_process (&ks->extensionssign_proc), 137 TALER_TESTING_trait_end () 138 }; 139 140 return TALER_TESTING_get_trait (traits, 141 ret, 142 trait, 143 index); 144 } 145 146 147 struct TALER_TESTING_Command 148 TALER_TESTING_cmd_exec_offline_sign_extensions (const char *label, 149 const char *config_filename) 150 { 151 struct ExtensionsSignState *ks; 152 153 ks = GNUNET_new (struct ExtensionsSignState); 154 ks->config_filename = config_filename; 155 { 156 struct TALER_TESTING_Command cmd = { 157 .cls = ks, 158 .label = label, 159 .run = &extensionssign_run, 160 .cleanup = &extensionssign_cleanup, 161 .traits = &extensionssign_traits 162 }; 163 164 return cmd; 165 } 166 } 167 168 169 /* end of testing_api_cmd_exec_offline_sign_extensions.c */