aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd.c')
-rw-r--r--src/backend/taler-merchant-httpd.c83
1 files changed, 73 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index eafef40b..515cefc2 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -45,6 +45,16 @@ unsigned short port;
45static struct MHD_Daemon *mhd; 45static struct MHD_Daemon *mhd;
46 46
47/** 47/**
48 * Shutdown task identifier
49 */
50static struct GNUNET_SCHEDULER_Task *shutdown_task;
51
52/**
53 * Should we do a dry run where temporary tables are used for storing the data.
54 */
55static int dry;
56
57/**
48 * Global return code 58 * Global return code
49 */ 59 */
50static int result; 60static int result;
@@ -216,32 +226,85 @@ url_handler (void *cls,
216 226
217} 227}
218 228
229/**
230 * Shutdown task (magically invoked when the application is being
231 * quit)
232 *
233 * @param cls NULL
234 * @param tc scheduler task context
235 */
236static void
237do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
238{
239
240 if (NULL != mhd)
241 {
242 MHD_stop_daemon (mhd);
243 mhd = NULL;
244 }
245
246}
219 247
220 248
221/** 249/**
222 * The main function of the serve tool 250 * Main function that will be run by the scheduler.
223 * 251 *
224 * @param argc number of arguments from the command line 252 * @param cls closure
225 * @param argv command line arguments 253 * @param args remaining command-line arguments
226 * @return 0 ok, 1 on error 254 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
255 * @param config configuration
227 */ 256 */
228int 257static void
229main (int argc, char *const *argv) 258run (void *cls, char *const *args, const char *cfgfile,
259 const struct GNUNET_CONFIGURATION_Handle *config)
230{ 260{
231 261
232 port = 9966; 262 port = 9966;
263
264 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
265 &do_shutdown, NULL);
266
233 mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, 267 mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY,
234 port, 268 port,
235 NULL, NULL, 269 NULL, NULL,
236 &url_handler, NULL, 270 &url_handler, NULL,
237 MHD_OPTION_END); 271 MHD_OPTION_END);
238 272
239 getchar ();
240 MHD_stop_daemon (mhd);
241 return 0;
242 273
274 EXITIF (NULL == mhd);
275 result = GNUNET_OK;
243 276
277 EXITIF_exit:
278 if (GNUNET_OK != result)
279 GNUNET_SCHEDULER_shutdown ();
244 280
245 281
282}
246 283
284/**
285 * The main function of the serve tool
286 *
287 * @param argc number of arguments from the command line
288 * @param argv command line arguments
289 * @return 0 ok, 1 on error
290 */
291int
292main (int argc, char *const *argv)
293{
294
295 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
296 GNUNET_GETOPT_OPTION_END
297 };
298
299
300 if (GNUNET_OK !=
301 GNUNET_PROGRAM_run (argc, argv,
302 "taler-merchant-serve",
303 "Serve merchant's HTTP interface",
304 options, &run, NULL))
305 return 3;
306 return (GNUNET_OK == result) ? 0 : 1;
307
308
309
247} 310}