taler-exchange-httpd_spa.c (3235B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2020, 2023, 2024 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 EXCHANGEABILITY 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-exchange-httpd_spa.c 18 * @brief logic to load single page apps (/) 19 * @author Christian Grothoff 20 */ 21 #include "taler/platform.h" 22 #include <gnunet/gnunet_util_lib.h> 23 #include "taler/taler_util.h" 24 #include "taler/taler_mhd_lib.h" 25 #include <gnunet/gnunet_mhd_compat.h> 26 #include "taler-exchange-httpd.h" 27 #include "taler-exchange-httpd_spa.h" 28 29 30 /** 31 * Resources of the AML SPA. 32 */ 33 static struct TALER_MHD_Spa *aml_spa; 34 35 /** 36 * Resources of the KYC SPA. 37 */ 38 static struct TALER_MHD_Spa *kyc_spa; 39 40 41 MHD_RESULT 42 TEH_handler_aml_spa (struct TEH_RequestContext *rc, 43 const char *const args[]) 44 { 45 const char *path = args[0]; 46 47 return TALER_MHD_spa_handler (aml_spa, 48 rc->connection, 49 path); 50 } 51 52 53 MHD_RESULT 54 TEH_handler_kyc_spa (struct TEH_RequestContext *rc, 55 const char *const args[]) 56 { 57 const char *path = args[0]; 58 struct TALER_AccountAccessTokenP tok; 59 60 if (NULL == path) 61 { 62 GNUNET_break_op (0); 63 return TALER_MHD_reply_with_error ( 64 rc->connection, 65 MHD_HTTP_FORBIDDEN, 66 TALER_EC_GENERIC_TOKEN_PERMISSION_INSUFFICIENT, 67 "no account access token specified"); 68 } 69 if (GNUNET_OK == 70 GNUNET_STRINGS_string_to_data (path, 71 strlen (path), 72 &tok, 73 sizeof (tok))) 74 { 75 /* The access token is used internally by the SPA, 76 we simply map all access tokens to "index.html" */ 77 path = "index.html"; 78 } 79 return TALER_MHD_spa_handler (kyc_spa, 80 rc->connection, 81 path); 82 } 83 84 85 enum GNUNET_GenericReturnValue 86 TEH_spa_init () 87 { 88 aml_spa = TALER_MHD_spa_load (TALER_EXCHANGE_project_data (), 89 "aml-spa/"); 90 if (NULL == aml_spa) 91 { 92 GNUNET_break (0); 93 return GNUNET_SYSERR; 94 } 95 kyc_spa = TALER_MHD_spa_load (TALER_EXCHANGE_project_data (), 96 "kyc-spa/"); 97 if (NULL == kyc_spa) 98 { 99 GNUNET_break (0); 100 TALER_MHD_spa_free (aml_spa); 101 aml_spa = NULL; 102 return GNUNET_SYSERR; 103 } 104 return GNUNET_OK; 105 } 106 107 108 /* Suppresses warning */ 109 void __attribute__ ((destructor)) 110 get_spa_fini (void); 111 112 /** 113 * Nicely shut down. 114 */ 115 void __attribute__ ((destructor)) 116 get_spa_fini (void) 117 { 118 if (NULL != kyc_spa) 119 { 120 TALER_MHD_spa_free (kyc_spa); 121 kyc_spa = NULL; 122 } 123 if (NULL != aml_spa) 124 { 125 TALER_MHD_spa_free (aml_spa); 126 aml_spa = NULL; 127 } 128 }