Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2020, 2023, 2025 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file taler-merchant-httpd_spa.c
18 : * @brief logic to load the single page app (/)
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <gnunet/gnunet_util_lib.h>
23 : #include <taler/taler_util.h>
24 : #include <taler/taler_mhd_lib.h>
25 : #include "taler_merchant_util.h"
26 : #include "taler-merchant-httpd_statics.h"
27 : #include "taler-merchant-httpd_spa.h"
28 : #include <gnunet/gnunet_mhd_compat.h>
29 :
30 :
31 : /**
32 : * Resources of the Merchant SPA.
33 : */
34 : static struct TALER_MHD_Spa *spa;
35 :
36 :
37 : MHD_RESULT
38 1 : TMH_return_spa (const struct TMH_RequestHandler *rh,
39 : struct MHD_Connection *connection,
40 : struct TMH_HandlerContext *hc)
41 : {
42 1 : const char *infix = hc->infix;
43 :
44 1 : if ( (NULL == infix) ||
45 1 : (0 == strcmp (infix,
46 : "")) )
47 1 : infix = "index.html";
48 1 : return TALER_MHD_spa_handler (spa,
49 : connection,
50 : infix);
51 : }
52 :
53 :
54 : enum GNUNET_GenericReturnValue
55 15 : TMH_spa_init ()
56 : {
57 15 : spa = TALER_MHD_spa_load (TALER_MERCHANT_project_data (),
58 : "spa/");
59 15 : if (NULL == spa)
60 : {
61 0 : GNUNET_break (0);
62 0 : return GNUNET_SYSERR;
63 : }
64 15 : return GNUNET_OK;
65 : }
66 :
67 :
68 : /**
69 : * Nicely shut down.
70 : */
71 : void __attribute__ ((destructor))
72 : get_spa_fini (void);
73 :
74 : /* Declaration to avoid compiler warning */
75 : void __attribute__ ((destructor))
76 29 : get_spa_fini ()
77 : {
78 29 : if (NULL != spa)
79 : {
80 15 : TALER_MHD_spa_free (spa);
81 15 : spa = NULL;
82 : }
83 29 : }
|