LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_config.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 19 100.0 %
Date: 2025-06-23 16:22:09 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2019, 2020, 2021, 2023, 2024 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_config.c
      18             :  * @brief implement API for querying configuration data of the backend
      19             :  * @author Florian Dold
      20             :  */
      21             : #include "platform.h"
      22             : #include <jansson.h>
      23             : #include <taler/taler_util.h>
      24             : #include <taler/taler_json_lib.h>
      25             : #include "taler-merchant-httpd.h"
      26             : #include "taler-merchant-httpd_config.h"
      27             : #include "taler-merchant-httpd_mhd.h"
      28             : #include "taler-merchant-httpd_exchanges.h"
      29             : 
      30             : 
      31             : /**
      32             :  * Taler protocol version in the format CURRENT:REVISION:AGE
      33             :  * as used by GNU libtool.  See
      34             :  * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
      35             :  *
      36             :  * Please be very careful when updating and follow
      37             :  * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
      38             :  * precisely.  Note that this version has NOTHING to do with the
      39             :  * release version, and the format is NOT the same that semantic
      40             :  * versioning uses either.
      41             :  *
      42             :  * When changing this version, you likely want to also update
      43             :  * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
      44             :  * merchant_api_config.c!
      45             :  */
      46             : #define MERCHANT_PROTOCOL_VERSION "19:0:16"
      47             : 
      48             : 
      49             : /**
      50             :  * Callback on an exchange known to us. Does not warrant
      51             :  * that the "keys" information is actually available for
      52             :  * @a exchange.
      53             :  *
      54             :  * @param cls closure with `json_t *` array to expand
      55             :  * @param url base URL of the exchange
      56             :  * @param exchange internal handle for the exchange
      57             :  */
      58             : static void
      59          26 : add_exchange (void *cls,
      60             :               const char *url,
      61             :               const struct TMH_Exchange *exchange)
      62             : {
      63          26 :   json_t *xa = cls;
      64             :   json_t *xi;
      65             : 
      66          26 :   xi = GNUNET_JSON_PACK (
      67             :     GNUNET_JSON_pack_data_auto ("master_pub",
      68             :                                 TMH_EXCHANGES_get_master_pub (exchange)),
      69             :     GNUNET_JSON_pack_string ("currency",
      70             :                              TMH_EXCHANGES_get_currency (exchange)),
      71             :     GNUNET_JSON_pack_string ("base_url",
      72             :                              url));
      73          26 :   GNUNET_assert (NULL != xi);
      74          26 :   GNUNET_assert (0 ==
      75             :                  json_array_append_new (xa,
      76             :                                         xi));
      77          26 : }
      78             : 
      79             : 
      80             : MHD_RESULT
      81          15 : MH_handler_config (const struct TMH_RequestHandler *rh,
      82             :                    struct MHD_Connection *connection,
      83             :                    struct TMH_HandlerContext *hc)
      84             : {
      85             :   static struct MHD_Response *response;
      86             : 
      87             :   (void) rh;
      88             :   (void) hc;
      89          15 :   if (NULL == response)
      90             :   {
      91          13 :     json_t *specs = json_object ();
      92          13 :     json_t *exchanges = json_array ();
      93             : 
      94          13 :     GNUNET_assert (NULL != specs);
      95          13 :     GNUNET_assert (NULL != exchanges);
      96          13 :     TMH_exchange_get_trusted (&add_exchange,
      97             :                               exchanges);
      98          78 :     for (unsigned int i = 0; i<TMH_num_cspecs; i++)
      99             :     {
     100          65 :       const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i];
     101             : 
     102          65 :       if (TMH_test_exchange_configured_for_currency (cspec->currency))
     103          26 :         GNUNET_assert (0 ==
     104             :                        json_object_set_new (
     105             :                          specs,
     106             :                          cspec->currency,
     107             :                          TALER_CONFIG_currency_specs_to_json
     108             :                            (cspec)));
     109             :     }
     110          13 :     response = TALER_MHD_MAKE_JSON_PACK (
     111             :       GNUNET_JSON_pack_string ("currency",
     112             :                                TMH_currency),
     113             :       GNUNET_JSON_pack_object_steal ("currencies",
     114             :                                      specs),
     115             :       GNUNET_JSON_pack_array_steal ("exchanges",
     116             :                                     exchanges),
     117             :       GNUNET_JSON_pack_string (
     118             :         "implementation",
     119             :         "urn:net:taler:specs:taler-merchant:c-reference"),
     120             :       GNUNET_JSON_pack_string ("name",
     121             :                                "taler-merchant"),
     122             :       GNUNET_JSON_pack_string ("version",
     123             :                                MERCHANT_PROTOCOL_VERSION));
     124             :   }
     125          15 :   return MHD_queue_response (connection,
     126             :                              MHD_HTTP_OK,
     127             :                              response);
     128             : }
     129             : 
     130             : 
     131             : /* end of taler-merchant-httpd_config.c */

Generated by: LCOV version 1.16