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