mhd.c (2834B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2020 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 mhd.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_mhd_lib.h" 23 24 25 enum GNUNET_GenericReturnValue 26 TALER_mhd_is_https (struct MHD_Connection *connection) 27 { 28 const union MHD_ConnectionInfo *ci; 29 const union MHD_DaemonInfo *di; 30 const char *forwarded_proto = MHD_lookup_connection_value (connection, 31 MHD_HEADER_KIND, 32 "X-Forwarded-Proto"); 33 34 if (NULL != forwarded_proto) 35 { 36 if (0 == strcasecmp (forwarded_proto, 37 "https")) 38 return GNUNET_YES; 39 if (0 == strcasecmp (forwarded_proto, 40 "http")) 41 return GNUNET_NO; 42 GNUNET_break (0); 43 return GNUNET_SYSERR; 44 } 45 /* likely not reverse proxy, figure out if we are 46 http by asking MHD */ 47 ci = MHD_get_connection_info (connection, 48 MHD_CONNECTION_INFO_DAEMON); 49 if (NULL == ci) 50 { 51 GNUNET_break (0); 52 return GNUNET_SYSERR; 53 } 54 di = MHD_get_daemon_info (ci->daemon, 55 MHD_DAEMON_INFO_FLAGS); 56 if (NULL == di) 57 { 58 GNUNET_break (0); 59 return GNUNET_SYSERR; 60 } 61 if (0 != (di->flags & MHD_USE_TLS)) 62 return GNUNET_YES; 63 return GNUNET_NO; 64 } 65 66 67 bool 68 TALER_MHD_arg_to_yna (struct MHD_Connection *connection, 69 const char *arg, 70 enum TALER_EXCHANGE_YesNoAll default_val, 71 enum TALER_EXCHANGE_YesNoAll *yna) 72 { 73 const char *str; 74 75 str = MHD_lookup_connection_value (connection, 76 MHD_GET_ARGUMENT_KIND, 77 arg); 78 if (NULL == str) 79 { 80 *yna = default_val; 81 return true; 82 } 83 if (0 == strcasecmp (str, "yes")) 84 { 85 *yna = TALER_EXCHANGE_YNA_YES; 86 return true; 87 } 88 if (0 == strcasecmp (str, "no")) 89 { 90 *yna = TALER_EXCHANGE_YNA_NO; 91 return true; 92 } 93 if (0 == strcasecmp (str, "all")) 94 { 95 *yna = TALER_EXCHANGE_YNA_ALL; 96 return true; 97 } 98 return false; 99 }