Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (C) 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 yna.c 18 : * @brief Utility functions for yes/no/all filters 19 : * @author Jonathan Buchanan 20 : */ 21 : #include "platform.h" 22 : #include "taler_util.h" 23 : 24 : 25 : /** 26 : * Convert query argument to @a yna value. 27 : * 28 : * @param connection connection to take query argument from 29 : * @param arg argument to try for 30 : * @param default_val value to assign if the argument is not present 31 : * @param[out] yna value to set 32 : * @return true on success, false if the parameter was malformed 33 : */ 34 : bool 35 0 : TALER_arg_to_yna (struct MHD_Connection *connection, 36 : const char *arg, 37 : enum TALER_EXCHANGE_YesNoAll default_val, 38 : enum TALER_EXCHANGE_YesNoAll *yna) 39 : { 40 : const char *str; 41 : 42 0 : str = MHD_lookup_connection_value (connection, 43 : MHD_GET_ARGUMENT_KIND, 44 : arg); 45 0 : if (NULL == str) 46 : { 47 0 : *yna = default_val; 48 0 : return true; 49 : } 50 0 : if (0 == strcasecmp (str, "yes")) 51 : { 52 0 : *yna = TALER_EXCHANGE_YNA_YES; 53 0 : return true; 54 : } 55 0 : if (0 == strcasecmp (str, "no")) 56 : { 57 0 : *yna = TALER_EXCHANGE_YNA_NO; 58 0 : return true; 59 : } 60 0 : if (0 == strcasecmp (str, "all")) 61 : { 62 0 : *yna = TALER_EXCHANGE_YNA_ALL; 63 0 : return true; 64 : } 65 0 : return false; 66 : } 67 : 68 : 69 : /** 70 : * Convert YNA value to a string. 71 : * 72 : * @param yna value to convert 73 : * @return string representation ("yes"/"no"/"all"). 74 : */ 75 : const char * 76 0 : TALER_yna_to_string (enum TALER_EXCHANGE_YesNoAll yna) 77 : { 78 0 : switch (yna) 79 : { 80 0 : case TALER_EXCHANGE_YNA_YES: 81 0 : return "yes"; 82 0 : case TALER_EXCHANGE_YNA_NO: 83 0 : return "no"; 84 0 : case TALER_EXCHANGE_YNA_ALL: 85 0 : return "all"; 86 : } 87 0 : GNUNET_assert (0); 88 : }