LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-instances-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 63.6 % 22 14
Test Date: 2025-10-26 01:13:37 Functions: 66.7 % 3 2

            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_allow_null (
      86              :       GNUNET_JSON_pack_string ("website",
      87              :                                mi->settings.website)),
      88              :     GNUNET_JSON_pack_allow_null (
      89              :       GNUNET_JSON_pack_string ("email",
      90              :                                mi->settings.email)),
      91              :     GNUNET_JSON_pack_bool ("email_validated",
      92              :                            mi->settings.email_validated),
      93              :     GNUNET_JSON_pack_allow_null (
      94              :       GNUNET_JSON_pack_string ("phone_number",
      95              :                                mi->settings.phone)),
      96              :     GNUNET_JSON_pack_bool ("phone_validated",
      97              :                            mi->settings.phone_validated),
      98              :     GNUNET_JSON_pack_allow_null (
      99              :       GNUNET_JSON_pack_string ("logo",
     100              :                                mi->settings.logo)),
     101              :     GNUNET_JSON_pack_data_auto ("merchant_pub",
     102              :                                 &mi->merchant_pub),
     103              :     GNUNET_JSON_pack_object_incref ("address",
     104              :                                     mi->settings.address),
     105              :     GNUNET_JSON_pack_object_incref ("jurisdiction",
     106              :                                     mi->settings.jurisdiction),
     107              :     GNUNET_JSON_pack_bool ("use_stefan",
     108              :                            mi->settings.use_stefan),
     109              :     GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
     110              :                                mi->settings.default_wire_transfer_delay),
     111              :     GNUNET_JSON_pack_time_rel ("default_pay_delay",
     112              :                                mi->settings.default_pay_delay),
     113              :     GNUNET_JSON_pack_time_rel ("default_refund_delay",
     114              :                                mi->settings.default_refund_delay),
     115              :     GNUNET_JSON_pack_object_steal ("auth",
     116              :                                    auth));
     117              : }
     118              : 
     119              : 
     120              : MHD_RESULT
     121            6 : TMH_private_get_instances_ID (const struct TMH_RequestHandler *rh,
     122              :                               struct MHD_Connection *connection,
     123              :                               struct TMH_HandlerContext *hc)
     124              : {
     125            6 :   struct TMH_MerchantInstance *mi = hc->instance;
     126              : 
     127            6 :   return get_instances_ID (mi,
     128              :                            connection);
     129              : }
     130              : 
     131              : 
     132              : MHD_RESULT
     133            0 : TMH_private_get_instances_default_ID (const struct TMH_RequestHandler *rh,
     134              :                                       struct MHD_Connection *connection,
     135              :                                       struct TMH_HandlerContext *hc)
     136              : {
     137              :   struct TMH_MerchantInstance *mi;
     138              : 
     139            0 :   mi = TMH_lookup_instance (hc->infix);
     140            0 :   if ( (NULL == mi) ||
     141            0 :        (mi->deleted) )
     142              :   {
     143            0 :     return TALER_MHD_reply_with_error (connection,
     144              :                                        MHD_HTTP_NOT_FOUND,
     145              :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     146            0 :                                        hc->infix);
     147              :   }
     148            0 :   return get_instances_ID (mi,
     149              :                            connection);
     150              : }
     151              : 
     152              : 
     153              : /* end of taler-merchant-httpd_private-get-instances-ID.c */
        

Generated by: LCOV version 2.0-1