Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2020 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_keys.c
22 : * @brief run the taler-exchange-offline command to download, sign and upload keys
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 :
51 :
52 : /**
53 : * Run the command; calls the `taler-exchange-offline` program.
54 : *
55 : * @param cls closure.
56 : * @param cmd the commaind being run.
57 : * @param is interpreter state.
58 : */
59 : static void
60 2 : offlinesign_run (void *cls,
61 : const struct TALER_TESTING_Command *cmd,
62 : struct TALER_TESTING_Interpreter *is)
63 : {
64 2 : struct OfflineSignState *ks = cls;
65 :
66 2 : ks->offlinesign_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
67 2 : if (GNUNET_OK !=
68 2 : GNUNET_process_run_command_va (
69 : ks->offlinesign_proc,
70 : "taler-exchange-offline",
71 : "taler-exchange-offline",
72 : "-c", ks->config_filename,
73 : "-L", "INFO",
74 : "download",
75 : "sign",
76 : "upload",
77 : NULL))
78 : {
79 0 : GNUNET_break (0);
80 0 : GNUNET_process_destroy (ks->offlinesign_proc);
81 0 : ks->offlinesign_proc = NULL;
82 0 : TALER_TESTING_interpreter_fail (is);
83 0 : return;
84 : }
85 2 : TALER_TESTING_wait_for_sigchld (is);
86 : }
87 :
88 :
89 : /**
90 : * Free the state of a "offlinesign" 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 2 : offlinesign_cleanup (void *cls,
98 : const struct TALER_TESTING_Command *cmd)
99 : {
100 2 : struct OfflineSignState *ks = cls;
101 :
102 : (void) cmd;
103 2 : if (NULL != ks->offlinesign_proc)
104 : {
105 0 : GNUNET_break (GNUNET_OK ==
106 : GNUNET_process_kill (ks->offlinesign_proc,
107 : SIGKILL));
108 0 : GNUNET_process_wait (ks->offlinesign_proc,
109 : true,
110 : NULL,
111 : NULL);
112 0 : GNUNET_process_destroy (ks->offlinesign_proc);
113 0 : ks->offlinesign_proc = NULL;
114 : }
115 2 : GNUNET_free (ks);
116 2 : }
117 :
118 :
119 : /**
120 : * Offer "offlinesign" 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 4 : offlinesign_traits (void *cls,
130 : const void **ret,
131 : const char *trait,
132 : unsigned int index)
133 : {
134 4 : struct OfflineSignState *ks = cls;
135 : struct TALER_TESTING_Trait traits[] = {
136 4 : TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
137 4 : TALER_TESTING_trait_end ()
138 : };
139 :
140 4 : return TALER_TESTING_get_trait (traits,
141 : ret,
142 : trait,
143 : index);
144 : }
145 :
146 :
147 : struct TALER_TESTING_Command
148 2 : TALER_TESTING_cmd_exec_offline_sign_keys (const char *label,
149 : const char *config_filename)
150 : {
151 : struct OfflineSignState *ks;
152 :
153 2 : ks = GNUNET_new (struct OfflineSignState);
154 2 : ks->config_filename = config_filename;
155 : {
156 2 : struct TALER_TESTING_Command cmd = {
157 : .cls = ks,
158 : .label = label,
159 : .run = &offlinesign_run,
160 : .cleanup = &offlinesign_cleanup,
161 : .traits = &offlinesign_traits
162 : };
163 :
164 2 : return cmd;
165 : }
166 : }
167 :
168 :
169 : /* end of testing_api_cmd_exec_offline_sign_keys.c */
|