LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-instances-ID.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 20 65.0 %
Date: 2025-06-23 16:22:09 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2019-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-instances-ID.c
      18             :  * @brief implement GET /instances/$ID
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-get-instances-ID.h"
      23             : #include <taler/taler_json_lib.h>
      24             : 
      25             : 
      26             : /**
      27             :  * Handle a GET "/instances/$ID" request.
      28             :  *
      29             :  * @param mi instance to return information about
      30             :  * @param connection the MHD connection to handle
      31             :  * @return MHD result code
      32             :  */
      33             : static MHD_RESULT
      34           6 : get_instances_ID (struct TMH_MerchantInstance *mi,
      35             :                   struct MHD_Connection *connection)
      36             : {
      37             :   json_t *ja;
      38             :   json_t *auth;
      39             : 
      40           6 :   GNUNET_assert (NULL != mi);
      41           6 :   ja = json_array ();
      42           6 :   GNUNET_assert (NULL != ja);
      43           6 :   for (struct TMH_WireMethod *wm = mi->wm_head;
      44           9 :        NULL != wm;
      45           3 :        wm = wm->next)
      46             :   {
      47           3 :     GNUNET_assert (
      48             :       0 ==
      49             :       json_array_append_new (
      50             :         ja,
      51             :         GNUNET_JSON_PACK (
      52             :           TALER_JSON_pack_full_payto (
      53             :             "payto_uri",
      54             :             wm->payto_uri),
      55             :           GNUNET_JSON_pack_allow_null (
      56             :             GNUNET_JSON_pack_string (
      57             :               "credit_facade_url",
      58             :               wm->credit_facade_url)),
      59             :           GNUNET_JSON_pack_data_auto ("h_wire",
      60             :                                       &wm->h_wire),
      61             :           GNUNET_JSON_pack_data_auto (
      62             :             "salt",
      63             :             &wm->wire_salt),
      64             :           GNUNET_JSON_pack_bool ("active",
      65             :                                  wm->active))));
      66             :   }
      67             : 
      68           6 :   auth = GNUNET_JSON_PACK (
      69             :     GNUNET_JSON_pack_string ("method",
      70             :                              GNUNET_is_zero (&mi->auth.auth_hash)
      71             :                                                     ? "external"
      72             :                                                     : "token"));
      73           6 :   return TALER_MHD_REPLY_JSON_PACK (
      74             :     connection,
      75             :     MHD_HTTP_OK,
      76             :     GNUNET_JSON_pack_array_steal ("accounts",
      77             :                                   ja),
      78             :     GNUNET_JSON_pack_string ("name",
      79             :                              mi->settings.name),
      80             :     GNUNET_JSON_pack_string (
      81             :       "user_type",
      82             :       "business"),
      83             :     GNUNET_JSON_pack_allow_null (
      84             :       GNUNET_JSON_pack_string ("website",
      85             :                                mi->settings.website)),
      86             :     GNUNET_JSON_pack_allow_null (
      87             :       GNUNET_JSON_pack_string ("email",
      88             :                                mi->settings.email)),
      89             :     GNUNET_JSON_pack_allow_null (
      90             :       GNUNET_JSON_pack_string ("logo",
      91             :                                mi->settings.logo)),
      92             :     GNUNET_JSON_pack_data_auto ("merchant_pub",
      93             :                                 &mi->merchant_pub),
      94             :     GNUNET_JSON_pack_object_incref ("address",
      95             :                                     mi->settings.address),
      96             :     GNUNET_JSON_pack_object_incref ("jurisdiction",
      97             :                                     mi->settings.jurisdiction),
      98             :     GNUNET_JSON_pack_bool ("use_stefan",
      99             :                            mi->settings.use_stefan),
     100             :     GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
     101             :                                mi->settings.default_wire_transfer_delay),
     102             :     GNUNET_JSON_pack_time_rel ("default_pay_delay",
     103             :                                mi->settings.default_pay_delay),
     104             :     GNUNET_JSON_pack_object_steal ("auth",
     105             :                                    auth));
     106             : }
     107             : 
     108             : 
     109             : MHD_RESULT
     110           6 : TMH_private_get_instances_ID (const struct TMH_RequestHandler *rh,
     111             :                               struct MHD_Connection *connection,
     112             :                               struct TMH_HandlerContext *hc)
     113             : {
     114           6 :   struct TMH_MerchantInstance *mi = hc->instance;
     115             : 
     116           6 :   return get_instances_ID (mi,
     117             :                            connection);
     118             : }
     119             : 
     120             : 
     121             : MHD_RESULT
     122           0 : TMH_private_get_instances_default_ID (const struct TMH_RequestHandler *rh,
     123             :                                       struct MHD_Connection *connection,
     124             :                                       struct TMH_HandlerContext *hc)
     125             : {
     126             :   struct TMH_MerchantInstance *mi;
     127             : 
     128           0 :   mi = TMH_lookup_instance (hc->infix);
     129           0 :   if ( (NULL == mi) ||
     130           0 :        (mi->deleted) )
     131             :   {
     132           0 :     return TALER_MHD_reply_with_error (connection,
     133             :                                        MHD_HTTP_NOT_FOUND,
     134             :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     135           0 :                                        hc->infix);
     136             :   }
     137           0 :   return get_instances_ID (mi,
     138             :                            connection);
     139             : }
     140             : 
     141             : 
     142             : /* end of taler-merchant-httpd_private-get-instances-ID.c */

Generated by: LCOV version 1.16