mhd2.c (3136B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-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 mhd2.c 18 * @brief MHD utility functions (used by the merchant backend) 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_util.h" 22 #include "taler/taler_mhd2_lib.h" 23 24 25 enum GNUNET_GenericReturnValue 26 TALER_MHD2_is_https (struct MHD_Request *request) 27 { 28 struct MHD_StringNullable forwarded_proto; 29 union MHD_RequestInfoFixedData ci; 30 union MHD_DaemonInfoFixedData di; 31 32 if ( (MHD_NO != 33 MHD_request_get_value (request, 34 MHD_VK_HEADER, 35 "X-Forwarded-Proto", 36 &forwarded_proto)) && 37 (NULL != forwarded_proto.cstr) ) 38 { 39 if (0 == strcasecmp (forwarded_proto.cstr, 40 "https")) 41 return GNUNET_YES; 42 if (0 == strcasecmp (forwarded_proto.cstr, 43 "http")) 44 return GNUNET_NO; 45 GNUNET_break (0); 46 return GNUNET_SYSERR; 47 } 48 /* likely not reverse proxy, figure out if we are 49 http by asking MHD */ 50 if (MHD_SC_OK != 51 MHD_request_get_info_fixed (request, 52 MHD_REQUEST_INFO_FIXED_DAEMON, 53 &ci)) 54 { 55 GNUNET_break (0); 56 return GNUNET_SYSERR; 57 } 58 if (MHD_SC_OK != 59 MHD_daemon_get_info_fixed (ci.v_daemon, 60 MHD_DAEMON_INFO_FIXED_TLS_BACKEND, 61 &di)) 62 { 63 GNUNET_break (0); 64 return GNUNET_SYSERR; 65 } 66 if (MHD_TLS_BACKEND_NONE != di.v_tls_backend) 67 return GNUNET_YES; 68 return GNUNET_NO; 69 } 70 71 72 bool 73 TALER_MHD2_arg_to_yna (struct MHD_Request *request, 74 const char *arg, 75 enum TALER_EXCHANGE_YesNoAll default_val, 76 enum TALER_EXCHANGE_YesNoAll *yna) 77 { 78 struct MHD_StringNullable nstr; 79 80 if ( (MHD_NO == 81 MHD_request_get_value (request, 82 MHD_VK_URI_QUERY_PARAM, 83 arg, 84 &nstr)) || 85 (NULL == nstr.cstr) ) 86 { 87 *yna = default_val; 88 return true; 89 } 90 if (0 == strcasecmp (nstr.cstr, 91 "yes")) 92 { 93 *yna = TALER_EXCHANGE_YNA_YES; 94 return true; 95 } 96 if (0 == strcasecmp (nstr.cstr, 97 "no")) 98 { 99 *yna = TALER_EXCHANGE_YNA_NO; 100 return true; 101 } 102 if (0 == strcasecmp (nstr.cstr, 103 "all")) 104 { 105 *yna = TALER_EXCHANGE_YNA_ALL; 106 return true; 107 } 108 return false; 109 }