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: 14 22 63.6 %
Date: 2025-07-08 09:58:45 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           6 :   if (GNUNET_YES == TMH_strict_v19)
      68             :   {
      69             :     // When pre v19 is deprecated this if guard can be removed
      70             :     // and the code below should never return "external"
      71           0 :     GNUNET_assert (! GNUNET_is_zero (&mi->auth.auth_hash));
      72             :   }
      73           6 :   auth = GNUNET_JSON_PACK (
      74             :     GNUNET_JSON_pack_string ("method",
      75             :                              GNUNET_is_zero (&mi->auth.auth_hash)
      76             :                                                     ? "external"
      77             :                                                     : "token"));
      78           6 :   return TALER_MHD_REPLY_JSON_PACK (
      79             :     connection,
      80             :     MHD_HTTP_OK,
      81             :     GNUNET_JSON_pack_array_steal ("accounts",
      82             :                                   ja),
      83             :     GNUNET_JSON_pack_string ("name",
      84             :                              mi->settings.name),
      85             :     GNUNET_JSON_pack_string (
      86             :       "user_type",
      87             :       "business"),
      88             :     GNUNET_JSON_pack_allow_null (
      89             :       GNUNET_JSON_pack_string ("website",
      90             :                                mi->settings.website)),
      91             :     GNUNET_JSON_pack_allow_null (
      92             :       GNUNET_JSON_pack_string ("email",
      93             :                                mi->settings.email)),
      94             :     GNUNET_JSON_pack_allow_null (
      95             :       GNUNET_JSON_pack_string ("logo",
      96             :                                mi->settings.logo)),
      97             :     GNUNET_JSON_pack_data_auto ("merchant_pub",
      98             :                                 &mi->merchant_pub),
      99             :     GNUNET_JSON_pack_object_incref ("address",
     100             :                                     mi->settings.address),
     101             :     GNUNET_JSON_pack_object_incref ("jurisdiction",
     102             :                                     mi->settings.jurisdiction),
     103             :     GNUNET_JSON_pack_bool ("use_stefan",
     104             :                            mi->settings.use_stefan),
     105             :     GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
     106             :                                mi->settings.default_wire_transfer_delay),
     107             :     GNUNET_JSON_pack_time_rel ("default_pay_delay",
     108             :                                mi->settings.default_pay_delay),
     109             :     GNUNET_JSON_pack_object_steal ("auth",
     110             :                                    auth));
     111             : }
     112             : 
     113             : 
     114             : MHD_RESULT
     115           6 : TMH_private_get_instances_ID (const struct TMH_RequestHandler *rh,
     116             :                               struct MHD_Connection *connection,
     117             :                               struct TMH_HandlerContext *hc)
     118             : {
     119           6 :   struct TMH_MerchantInstance *mi = hc->instance;
     120             : 
     121           6 :   return get_instances_ID (mi,
     122             :                            connection);
     123             : }
     124             : 
     125             : 
     126             : MHD_RESULT
     127           0 : TMH_private_get_instances_default_ID (const struct TMH_RequestHandler *rh,
     128             :                                       struct MHD_Connection *connection,
     129             :                                       struct TMH_HandlerContext *hc)
     130             : {
     131             :   struct TMH_MerchantInstance *mi;
     132             : 
     133           0 :   mi = TMH_lookup_instance (hc->infix);
     134           0 :   if ( (NULL == mi) ||
     135           0 :        (mi->deleted) )
     136             :   {
     137           0 :     return TALER_MHD_reply_with_error (connection,
     138             :                                        MHD_HTTP_NOT_FOUND,
     139             :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     140           0 :                                        hc->infix);
     141             :   }
     142           0 :   return get_instances_ID (mi,
     143             :                            connection);
     144             : }
     145             : 
     146             : 
     147             : /* end of taler-merchant-httpd_private-get-instances-ID.c */

Generated by: LCOV version 1.16