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