Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (C) 2018, 2021, 2024 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 json/json_wire.c 18 : * @brief helper functions to generate or check /wire replies 19 : * @author Christian Grothoff 20 : */ 21 : #include "platform.h" 22 : #include <gnunet/gnunet_util_lib.h> 23 : #include "taler_util.h" 24 : #include "taler_json_lib.h" 25 : 26 : 27 : enum GNUNET_GenericReturnValue 28 108 : TALER_JSON_merchant_wire_signature_hash (const json_t *wire_s, 29 : struct TALER_MerchantWireHashP *hc) 30 : { 31 : struct TALER_FullPayto payto_uri; 32 : struct TALER_WireSaltP salt; 33 : struct GNUNET_JSON_Specification spec[] = { 34 108 : TALER_JSON_spec_full_payto_uri ("payto_uri", 35 : &payto_uri), 36 108 : GNUNET_JSON_spec_fixed_auto ("salt", 37 : &salt), 38 108 : GNUNET_JSON_spec_end () 39 : }; 40 : 41 108 : if (GNUNET_OK != 42 108 : GNUNET_JSON_parse (wire_s, 43 : spec, 44 : NULL, NULL)) 45 : { 46 0 : GNUNET_break_op (0); 47 0 : return GNUNET_SYSERR; 48 : } 49 108 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 50 : "Validating `%s'\n", 51 : payto_uri.full_payto); 52 : { 53 : char *err; 54 : 55 108 : err = TALER_payto_validate (payto_uri); 56 108 : if (NULL != err) 57 : { 58 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 59 : "URI `%s' ill-formed: %s\n", 60 : payto_uri.full_payto, 61 : err); 62 0 : GNUNET_free (err); 63 0 : return GNUNET_SYSERR; 64 : } 65 : } 66 108 : TALER_merchant_wire_signature_hash (payto_uri, 67 : &salt, 68 : hc); 69 108 : return GNUNET_OK; 70 : } 71 : 72 : 73 : struct TALER_FullPayto 74 0 : TALER_JSON_wire_to_payto (const json_t *wire_s) 75 : { 76 : json_t *payto_o; 77 : const char *payto_str; 78 0 : struct TALER_FullPayto payto = { 79 : NULL 80 : }; 81 : char *err; 82 : 83 0 : payto_o = json_object_get (wire_s, 84 : "payto_uri"); 85 0 : if ( (NULL == payto_o) || 86 0 : (NULL == (payto_str = json_string_value (payto_o))) ) 87 : { 88 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 89 : "Malformed wire record encountered: lacks payto://-url\n"); 90 0 : return payto; 91 : } 92 0 : payto.full_payto = GNUNET_strdup (payto_str); 93 0 : if (NULL != 94 0 : (err = TALER_payto_validate (payto))) 95 : { 96 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 97 : "Malformed wire record encountered: payto URI `%s' invalid: %s\n", 98 : payto_str, 99 : err); 100 0 : GNUNET_free (payto.full_payto); 101 0 : GNUNET_free (err); 102 0 : return payto; 103 : } 104 0 : return payto; 105 : } 106 : 107 : 108 : char * 109 0 : TALER_JSON_wire_to_method (const json_t *wire_s) 110 : { 111 : json_t *payto_o; 112 : const char *payto_str; 113 : 114 0 : payto_o = json_object_get (wire_s, 115 : "payto_uri"); 116 0 : if ( (NULL == payto_o) || 117 0 : (NULL == (payto_str = json_string_value (payto_o))) ) 118 : { 119 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 120 : "Fatally malformed wire record encountered: lacks payto://-url\n"); 121 0 : return NULL; 122 : } 123 0 : return TALER_payto_get_method (payto_str); 124 : } 125 : 126 : 127 : /* end of json_wire.c */