LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-instances-ID.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 19 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2019-2021 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           0 : get_instances_ID (struct TMH_MerchantInstance *mi,
      35             :                   struct MHD_Connection *connection)
      36             : {
      37             :   json_t *ja;
      38             :   json_t *auth;
      39             : 
      40           0 :   GNUNET_assert (NULL != mi);
      41           0 :   ja = json_array ();
      42           0 :   GNUNET_assert (NULL != ja);
      43           0 :   for (struct TMH_WireMethod *wm = mi->wm_head;
      44             :        NULL != wm;
      45           0 :        wm = wm->next)
      46             :   {
      47           0 :     GNUNET_assert (
      48             :       0 ==
      49             :       json_array_append_new (
      50             :         ja,
      51             :         GNUNET_JSON_PACK (
      52             :           GNUNET_JSON_pack_string (
      53             :             "payto_uri",
      54             :             wm->payto_uri),
      55             :           GNUNET_JSON_pack_data_auto ("h_wire",
      56             :                                       &wm->h_wire),
      57             :           GNUNET_JSON_pack_data_auto (
      58             :             "salt",
      59             :             &wm->wire_salt),
      60             :           GNUNET_JSON_pack_bool ("active",
      61             :                                  wm->active))));
      62             :   }
      63             : 
      64           0 :   auth = GNUNET_JSON_PACK (
      65             :     GNUNET_JSON_pack_string ("method",
      66             :                              GNUNET_is_zero (&mi->auth.auth_hash)
      67             :                                                     ? "external"
      68             :                                                     : "token"));
      69           0 :   return TALER_MHD_REPLY_JSON_PACK (
      70             :     connection,
      71             :     MHD_HTTP_OK,
      72             :     GNUNET_JSON_pack_array_steal ("accounts",
      73             :                                   ja),
      74             :     GNUNET_JSON_pack_string ("name",
      75             :                              mi->settings.name),
      76             :     GNUNET_JSON_pack_allow_null (
      77             :       GNUNET_JSON_pack_string ("website",
      78             :                                mi->settings.website)),
      79             :     GNUNET_JSON_pack_allow_null (
      80             :       GNUNET_JSON_pack_string ("email",
      81             :                                mi->settings.email)),
      82             :     GNUNET_JSON_pack_allow_null (
      83             :       GNUNET_JSON_pack_string ("logo",
      84             :                                mi->settings.logo)),
      85             :     GNUNET_JSON_pack_data_auto ("merchant_pub",
      86             :                                 &mi->merchant_pub),
      87             :     GNUNET_JSON_pack_object_incref ("address",
      88             :                                     mi->settings.address),
      89             :     GNUNET_JSON_pack_object_incref ("jurisdiction",
      90             :                                     mi->settings.jurisdiction),
      91             :     TALER_JSON_pack_amount ("default_max_wire_fee",
      92             :                             &mi->settings.default_max_wire_fee),
      93             :     TALER_JSON_pack_amount ("default_max_deposit_fee",
      94             :                             &mi->settings.default_max_deposit_fee),
      95             :     GNUNET_JSON_pack_uint64 ("default_wire_fee_amortization",
      96             :                              mi->settings.default_wire_fee_amortization),
      97             :     GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
      98             :                                mi->settings.default_wire_transfer_delay),
      99             :     GNUNET_JSON_pack_time_rel ("default_pay_delay",
     100             :                                mi->settings.default_pay_delay),
     101             :     GNUNET_JSON_pack_object_steal ("auth",
     102             :                                    auth));
     103             : }
     104             : 
     105             : 
     106             : MHD_RESULT
     107           0 : TMH_private_get_instances_ID (const struct TMH_RequestHandler *rh,
     108             :                               struct MHD_Connection *connection,
     109             :                               struct TMH_HandlerContext *hc)
     110             : {
     111           0 :   struct TMH_MerchantInstance *mi = hc->instance;
     112             : 
     113           0 :   return get_instances_ID (mi,
     114             :                            connection);
     115             : }
     116             : 
     117             : 
     118             : MHD_RESULT
     119           0 : TMH_private_get_instances_default_ID (const struct TMH_RequestHandler *rh,
     120             :                                       struct MHD_Connection *connection,
     121             :                                       struct TMH_HandlerContext *hc)
     122             : {
     123             :   struct TMH_MerchantInstance *mi;
     124             : 
     125           0 :   mi = TMH_lookup_instance (hc->infix);
     126           0 :   if ( (NULL == mi) ||
     127           0 :        (mi->deleted) )
     128             :   {
     129           0 :     return TALER_MHD_reply_with_error (connection,
     130             :                                        MHD_HTTP_NOT_FOUND,
     131             :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     132           0 :                                        hc->infix);
     133             :   }
     134           0 :   return get_instances_ID (mi,
     135             :                            connection);
     136             : }
     137             : 
     138             : 
     139             : /* end of taler-merchant-httpd_private-get-instances-ID.c */

Generated by: LCOV version 1.14