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

Generated by: LCOV version 1.14