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 src/backend/taler-merchant-httpd_get-webui.c
18 : * @brief logic to load the single page app (/)
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <sys/stat.h>
23 : #include <gnunet/gnunet_util_lib.h>
24 : #include <taler/taler_util.h>
25 : #include <taler/taler_mhd_lib.h>
26 : #include "taler/taler_merchant_util.h"
27 : #include "taler-merchant-httpd_statics.h"
28 : #include "taler-merchant-httpd_get-webui.h"
29 : #include <gnunet/gnunet_mhd_compat.h>
30 :
31 :
32 : /**
33 : * Resources of the Merchant SPA.
34 : */
35 : static struct TALER_MHD_Spa *spa;
36 :
37 :
38 : enum MHD_Result
39 1 : TMH_return_spa (const struct TMH_RequestHandler *rh,
40 : struct MHD_Connection *connection,
41 : struct TMH_HandlerContext *hc)
42 : {
43 1 : const char *infix = hc->infix;
44 :
45 1 : if ( (NULL == infix) ||
46 1 : (0 == strcmp (infix,
47 : "")) )
48 1 : infix = "index.html";
49 1 : return TALER_MHD_spa_handler (spa,
50 : connection,
51 : infix);
52 : }
53 :
54 :
55 : enum GNUNET_GenericReturnValue
56 19 : TMH_spa_init (const char *spa_dir)
57 : {
58 19 : bool have_spa = false;
59 19 : if (NULL != spa_dir)
60 : {
61 : struct stat sb;
62 19 : have_spa = stat (spa_dir, &sb) == 0 && S_ISDIR (sb.st_mode);
63 19 : if (! have_spa)
64 : {
65 19 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
66 : "SPA not found at '%s', using fallback\n",
67 : spa_dir);
68 : }
69 : }
70 19 : if (! have_spa)
71 19 : spa = TALER_MHD_spa_load (TALER_MERCHANT_project_data (),
72 : "spa/");
73 : else
74 0 : spa = TALER_MHD_spa_load_dir (spa_dir);
75 :
76 19 : if (NULL == spa)
77 : {
78 0 : GNUNET_break (0);
79 0 : return GNUNET_SYSERR;
80 : }
81 19 : return GNUNET_OK;
82 : }
83 :
84 :
85 : /**
86 : * Nicely shut down.
87 : */
88 : void __attribute__ ((destructor))
89 : get_spa_fini (void);
90 :
91 : /* Declaration to avoid compiler warning */
92 : void __attribute__ ((destructor))
93 38 : get_spa_fini ()
94 : {
95 38 : if (NULL != spa)
96 : {
97 19 : TALER_MHD_spa_free (spa);
98 19 : spa = NULL;
99 : }
100 38 : }
|