merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_spa.c (2203B)


      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 TMH_return_spa (const struct TMH_RequestHandler *rh,
     39                 struct MHD_Connection *connection,
     40                 struct TMH_HandlerContext *hc)
     41 {
     42   const char *infix = hc->infix;
     43 
     44   if ( (NULL == infix) ||
     45        (0 == strcmp (infix,
     46                      "")) )
     47     infix = "index.html";
     48   return TALER_MHD_spa_handler (spa,
     49                                 connection,
     50                                 infix);
     51 }
     52 
     53 
     54 enum GNUNET_GenericReturnValue
     55 TMH_spa_init (const char *spa_dir)
     56 {
     57   if (NULL == spa_dir)
     58     spa = TALER_MHD_spa_load (TALER_MERCHANT_project_data (),
     59                               "spa/");
     60   else
     61     spa = TALER_MHD_spa_load_dir (spa_dir);
     62 
     63   if (NULL == spa)
     64   {
     65     GNUNET_break (0);
     66     return GNUNET_SYSERR;
     67   }
     68   return GNUNET_OK;
     69 }
     70 
     71 
     72 /**
     73  * Nicely shut down.
     74  */
     75 void __attribute__ ((destructor))
     76 get_spa_fini (void);
     77 
     78 /* Declaration to avoid compiler warning */
     79 void __attribute__ ((destructor))
     80 get_spa_fini ()
     81 {
     82   if (NULL != spa)
     83   {
     84     TALER_MHD_spa_free (spa);
     85     spa = NULL;
     86   }
     87 }