exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

mhd2.c (3164B)


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