LCOV - code coverage report
Current view: top level - mhd - mhd.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 35 40.0 %
Date: 2025-06-05 21:03:14 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.16