1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/*
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_helpers_auditor.c
* @brief helper functions
* @author Christian Grothoff
*/
#include "platform.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
#include "taler_testing_lib.h"
#include "taler_auditor_service.h"
/**
* Closure for #cleanup_auditor.
*/
struct CleanupContext
{
/**
* Where we find the state to clean up.
*/
struct TALER_TESTING_Interpreter *is;
/**
* Next cleanup routine to call, NULL for none.
*/
GNUNET_SCHEDULER_TaskCallback fcb;
/**
* Closure for @e fcb
*/
void *fcb_cls;
};
/**
* Function to clean up the auditor connection.
*
* @param cls a `struct CleanupContext`
*/
static void
cleanup_auditor (void *cls)
{
struct CleanupContext *cc = cls;
struct TALER_TESTING_Interpreter *is = cc->is;
TALER_AUDITOR_disconnect (is->auditor);
is->auditor = NULL;
if (NULL != cc->fcb)
cc->fcb (cc->fcb_cls);
GNUNET_free (cc);
}
/**
* Closure for #auditor_main_wrapper()
*/
struct MainWrapperContext
{
/**
* Main function to launch.
*/
TALER_TESTING_Main main_cb;
/**
* Closure for @e main_cb.
*/
void *main_cb_cls;
/**
* Configuration we use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Name of the configuration file.
*/
const char *config_filename;
};
/**
* Function called with information about the auditor.
*
* @param cls closure
* @param hr http response details
* @param vi basic information about the auditor
* @param compat protocol compatibility information
*/
static void
auditor_version_cb (void *cls,
const struct TALER_AUDITOR_HttpResponse *hr,
const struct TALER_AUDITOR_VersionInformation *vi,
enum TALER_AUDITOR_VersionCompatibility compat)
{
struct TALER_TESTING_Interpreter *is = cls;
(void) hr;
if (TALER_AUDITOR_VC_MATCH != compat)
{
TALER_TESTING_interpreter_fail (is);
return;
}
is->auditor_working = GNUNET_YES;
}
/**
* Setup the @a is 'auditor' member before running the main test loop.
*
* @param cls must be a `struct MainWrapperContext *`
* @param[in,out] is interpreter state to setup
*/
static void
auditor_main_wrapper (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct MainWrapperContext *mwc = cls;
struct CleanupContext *cc;
char *auditor_base_url;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (mwc->cfg,
"auditor",
"BASE_URL",
&auditor_base_url))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"auditor",
"BASE_URL");
return;
}
is->auditor = TALER_AUDITOR_connect (is->ctx,
auditor_base_url,
&auditor_version_cb,
is);
GNUNET_free (auditor_base_url);
if (NULL == is->auditor)
{
GNUNET_break (0);
return;
}
cc = GNUNET_new (struct CleanupContext);
cc->is = is;
cc->fcb = is->final_cleanup_cb;
cc->fcb_cls = is->final_cleanup_cb_cls;
is->final_cleanup_cb = cleanup_auditor;
is->final_cleanup_cb_cls = cc;
mwc->main_cb (mwc->main_cb_cls,
is);
}
/**
* Install signal handlers plus schedules the main wrapper
* around the "run" method.
*
* @param cls our `struct MainWrapperContext`
* @param cfg configuration we use
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
* times.
*/
static int
setup_with_cfg (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct MainWrapperContext *mwc = cls;
struct TALER_TESTING_SetupContext setup_ctx = {
.config_filename = mwc->config_filename,
.main_cb = &auditor_main_wrapper,
.main_cb_cls = mwc
};
mwc->cfg = cfg;
return TALER_TESTING_setup_with_auditor_and_exchange_cfg (&setup_ctx,
cfg);
}
/**
* Install signal handlers plus schedules the main wrapper
* around the "run" method.
*
* @param main_cb the "run" method which contains all the
* commands.
* @param main_cb_cls a closure for "run", typically NULL.
* @param config_filename configuration filename.
* @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
* non-GNUNET_OK codes are #GNUNET_SYSERR most of the
* times.
*/
int
TALER_TESTING_auditor_setup (TALER_TESTING_Main main_cb,
void *main_cb_cls,
const char *config_filename)
{
struct MainWrapperContext mwc = {
.main_cb = main_cb,
.main_cb_cls = main_cb_cls,
.config_filename = config_filename
};
return GNUNET_CONFIGURATION_parse_and_run (config_filename,
&setup_with_cfg,
&mwc);
}
/* end of testing_auditor_api_helpers.c */
|