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