summaryrefslogtreecommitdiff
path: root/src/include/taler_twister_service.h
blob: 13b289da0a43644f65549444bc8104864d65f847 (plain)
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
  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,
  write to the Free Software Foundation, Inc., 51 Franklin
  Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#ifndef TALER_TWISTER_SERVICE_H_
#define TALER_TWISTER_SERVICE_H_

#define TWISTER_FAIL() \
  do {GNUNET_break (0); return NULL; } while (0)

/**
 * @author Christian Grothoff
 * @author Marcello Stanisci
 */

#ifdef __cplusplus
extern "C"
{
#if 0                   /* keep Emacsens' auto-indent happy */
}
#endif
#endif

#include <gnunet/gnunet_util_lib.h>

/**
 * Version of the twister API.
 */
#define TALER_TWISTER_VERSION 0x00000000

/**
 * Handle for
 */
struct TALER_TWISTER_Handle;

/**
 * Connect to the twister service.
 *
 * @param cfg the configuration to use
 * @return handle to use in #TALER_TWISTER_disconnect to disconnect
 */
struct TALER_TWISTER_Handle *
TALER_TWISTER_connect
  (const struct GNUNET_CONFIGURATION_Handle *cfg);


/**
 * Disconnect from twister service.
 *
 * @param h handle to destroy
 */
void
TALER_TWISTER_disconnect (struct TALER_TWISTER_Handle *h);


/**
 * Opaque handle for asynchronous operation.
 */
struct TALER_TWISTER_Operation;


/**
 * Change the response field pointed by @a modify_path with
 * @a modify_value.
 *
 * @param h twister instance to control
 * @param path object-like notation path to the object to modify
 * @param value value to use for @a modify_path
 * @param cb callback to call once twister gets this instruction.
 * @param cb_cls closure for @a cb_callback
 *
 * @return operation handle.
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_modify_path_dl (struct TALER_TWISTER_Handle *h,
                              const char *path,
                              const char *value,
                              GNUNET_SCHEDULER_TaskCallback cb,
                              void *cb_cls);


/**
 * Change the JSON field pointed by @a path to the new @a value.
 * It only applies to upload objects.
 *
 * @param h twister instance to control
 * @param path object-like notation path to the object to modify
 * @param value value to use for @a modify_path
 * @param cb callback to call once twister gets this instruction.
 * @param cb_cls closure for @a cb_callback
 *
 * @return operation handle.
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_modify_path_ul (struct TALER_TWISTER_Handle *h,
                              const char *path,
                              const char *value,
                              GNUNET_SCHEDULER_TaskCallback cb,
                              void *cb_cls);


/**
 * Instruct the twister to flip a character into
 * the string JSON field that belongs to the object
 * being returned to the HTTP client.
 *
 * @param h twister instance to control
 * @param path object-like notation to point the string
 *        object where we seek a character to flip.
 * @param cb function to call once twister has processed this
 *        request
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_flip_download
  (struct TALER_TWISTER_Handle *h,
   const char *path,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Instruct the twister to flip a character into
 * the string JSON field that belongs to the object
 * being uploaded to the proxied service.
 *
 * @param h twister instance to control
 * @param path object-like notation to point the string
 *        object where we seek a character to flip.
 * @param cb function to call once twister has batched this
 *        request
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_flip_upload
  (struct TALER_TWISTER_Handle *h,
   const char *path,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Change the next response code to @a new_rc.
 *
 * @param h twister instance to control
 * @param new_rc response code to return from the next response
 * @param cb function to call once twister is ready
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_change_response_code
  (struct TALER_TWISTER_Handle *h,
   unsigned int new_rc,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Randomly truncate the response.
 *
 * @param h twister instance to control
 * @param cb function to call once twister has processed this
 *           request.
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_malform
  (struct TALER_TWISTER_Handle *h,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Randomly truncate the request.
 *
 * @param h twister instance to control
 * @param cb function to call once twister is ready; tipically
 *        a acknowledge function.
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_malform_upload
  (struct TALER_TWISTER_Handle *h,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Delete the object pointed to by @a path.  Note, this
 * object belongs to the JSON response object.
 *
 * @param h twister instance to control
 * @param path object-like notation to point the object to be
          deleted.  E.g., the path "f1.f2.0" will delete the object
          {"f1": {"f2": [{"to be": "deleted"}]}}.
 * @param cb function to call once twister is ready
 * @param cb_cls closure for @a cb
 * @return operation handle (to possibly abort)
 */
struct TALER_TWISTER_Operation *
TALER_TWISTER_delete_path
  (struct TALER_TWISTER_Handle *h,
   const char *path,
   GNUNET_SCHEDULER_TaskCallback cb,
   void *cb_cls);


/**
 * Abort operation.  Twister behavior may then include the
 * changes requested by the operation, or not!  Must be called
 * before the operations callback was invoked.
 *
 * @param op operation to cancel,
 *        operation's callback will not be called
 */
void
TALER_TWISTER_cancel (struct TALER_TWISTER_Operation *op);


/**
 * Prepare twister for execution; mainly checks whether the
 * HTTP port is available and construct the base URL based on it.
 *
 * @param config_filename configuration file name.
 * @return twister base URL, NULL upon errors.
 */
char *
TALER_TWISTER_prepare_twister (const char *config_filename);


/**
 * Run the twister service.
 *
 * @param config_filename configuration file name.
 * @return twister process handle, NULL upon errors.
 */
struct GNUNET_OS_Process *
TALER_TWISTER_run_twister (const char *config_filename);


#if 0                   /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
}
#endif


#endif /* TALER_NSE_SERVICE_H_ */