Line data Source code
1 : /* 2 : This file is part of TALER 3 : (C) 2023 Taler Systems SA 4 : 5 : TALER is free software; you can redistribute it and/or modify it under the 6 : terms of the GNU Affero 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 taler-merchant-httpd_private-get-accounts-ID.c 18 : * @brief implement GET /accounts/$ID 19 : * @author Christian Grothoff 20 : */ 21 : #include "platform.h" 22 : #include "taler-merchant-httpd_private-get-accounts-ID.h" 23 : #include <taler/taler_json_lib.h> 24 : 25 : 26 : /** 27 : * Handle a GET "/accounts/$ID" request. 28 : * 29 : * @param rh context of the handler 30 : * @param connection the MHD connection to handle 31 : * @param[in,out] hc context with further information about the request 32 : * @return MHD result code 33 : */ 34 : MHD_RESULT 35 0 : TMH_private_get_accounts_ID (const struct TMH_RequestHandler *rh, 36 : struct MHD_Connection *connection, 37 : struct TMH_HandlerContext *hc) 38 : { 39 0 : struct TMH_MerchantInstance *mi = hc->instance; 40 0 : const char *h_wire_s = hc->infix; 41 : struct TALER_MerchantWireHashP h_wire; 42 0 : struct TALER_MERCHANTDB_AccountDetails tp = { 0 }; 43 : enum GNUNET_DB_QueryStatus qs; 44 : 45 0 : GNUNET_assert (NULL != mi); 46 0 : GNUNET_assert (NULL != h_wire_s); 47 0 : if (GNUNET_OK != 48 0 : GNUNET_STRINGS_string_to_data (h_wire_s, 49 : strlen (h_wire_s), 50 : &h_wire, 51 : sizeof (h_wire))) 52 : { 53 0 : GNUNET_break_op (0); 54 0 : return TALER_MHD_reply_with_error (connection, 55 : MHD_HTTP_BAD_REQUEST, 56 : TALER_EC_MERCHANT_GENERIC_H_WIRE_MALFORMED, 57 : h_wire_s); 58 : } 59 0 : qs = TMH_db->select_account (TMH_db->cls, 60 0 : mi->settings.id, 61 : &h_wire, 62 : &tp); 63 0 : if (0 > qs) 64 : { 65 0 : GNUNET_break (0); 66 0 : return TALER_MHD_reply_with_error (connection, 67 : MHD_HTTP_INTERNAL_SERVER_ERROR, 68 : TALER_EC_GENERIC_DB_FETCH_FAILED, 69 : "lookup_account"); 70 : } 71 0 : if (0 == qs) 72 : { 73 0 : return TALER_MHD_reply_with_error (connection, 74 : MHD_HTTP_NOT_FOUND, 75 : TALER_EC_MERCHANT_GENERIC_ACCOUNT_UNKNOWN, 76 0 : hc->infix); 77 : } 78 : { 79 : MHD_RESULT ret; 80 : 81 0 : ret = TALER_MHD_REPLY_JSON_PACK ( 82 : connection, 83 : MHD_HTTP_OK, 84 : GNUNET_JSON_pack_bool ("active", 85 : tp.active), 86 : TALER_JSON_pack_full_payto ("payto_uri", 87 : tp.payto_uri), 88 : GNUNET_JSON_pack_data_auto ("h_wire", 89 : &tp.h_wire), 90 : GNUNET_JSON_pack_data_auto ("salt", 91 : &tp.salt), 92 : GNUNET_JSON_pack_allow_null ( 93 : GNUNET_JSON_pack_string ("credit_facade_url", 94 : tp.credit_facade_url))); 95 : /* We do not return the credentials, as they may 96 : be sensitive */ 97 0 : json_decref (tp.credit_facade_credentials); 98 0 : GNUNET_free (tp.payto_uri.full_payto); 99 0 : GNUNET_free (tp.credit_facade_url); 100 0 : return ret; 101 : } 102 : } 103 : 104 : 105 : /* end of taler-merchant-httpd_private-get-accounts-ID.c */