LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_exchanges.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 13 19 68.4 %
Date: 2021-08-30 06:43:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014-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 Affero General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU Affero General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file taler-auditor-httpd_exchanges.c
      18             :  * @brief Handle /exchanges requests; returns list of exchanges we audit
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include <gnunet/gnunet_json_lib.h>
      24             : #include <jansson.h>
      25             : #include <microhttpd.h>
      26             : #include <pthread.h>
      27             : #include "taler_json_lib.h"
      28             : #include "taler_mhd_lib.h"
      29             : #include "taler-auditor-httpd.h"
      30             : #include "taler-auditor-httpd_exchanges.h"
      31             : 
      32             : 
      33             : /**
      34             :  * Add exchange information to the list.
      35             :  *
      36             :  * @param[in,out] cls a `json_t *` array to extend
      37             :  * @param master_pub master public key of an exchange
      38             :  * @param exchange_url base URL of an exchange
      39             :  */
      40             : static void
      41           1 : add_exchange (void *cls,
      42             :               const struct TALER_MasterPublicKeyP *master_pub,
      43             :               const char *exchange_url)
      44             : {
      45           1 :   json_t *list = cls;
      46             :   json_t *obj;
      47             : 
      48           1 :   obj = GNUNET_JSON_PACK (
      49             :     GNUNET_JSON_pack_data_auto ("master_pub",
      50             :                                 master_pub),
      51             :     GNUNET_JSON_pack_string ("exchange_url",
      52             :                              exchange_url));
      53           1 :   GNUNET_break (0 ==
      54             :                 json_array_append_new (list,
      55             :                                        obj));
      56             : 
      57           1 : }
      58             : 
      59             : 
      60             : /**
      61             :  * Handle a "/exchanges" request.
      62             :  *
      63             :  * @param rh context of the handler
      64             :  * @param connection the MHD connection to handle
      65             :  * @param[in,out] connection_cls the connection's closure (can be updated)
      66             :  * @param upload_data upload data
      67             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
      68             :  * @return MHD result code
      69             :   */
      70             : MHD_RESULT
      71           1 : TAH_EXCHANGES_handler (struct TAH_RequestHandler *rh,
      72             :                        struct MHD_Connection *connection,
      73             :                        void **connection_cls,
      74             :                        const char *upload_data,
      75             :                        size_t *upload_data_size)
      76             : {
      77             :   json_t *ja;
      78             :   enum GNUNET_DB_QueryStatus qs;
      79             : 
      80             :   (void) rh;
      81             :   (void) connection_cls;
      82             :   (void) upload_data;
      83             :   (void) upload_data_size;
      84           1 :   if (GNUNET_SYSERR ==
      85           1 :       TAH_plugin->preflight (TAH_plugin->cls))
      86             :   {
      87           0 :     GNUNET_break (0);
      88           0 :     return TALER_MHD_reply_with_error (connection,
      89             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      90             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      91             :                                        NULL);
      92             :   }
      93           1 :   ja = json_array ();
      94           1 :   GNUNET_break (NULL != ja);
      95           1 :   qs = TAH_plugin->list_exchanges (TAH_plugin->cls,
      96             :                                    &add_exchange,
      97             :                                    ja);
      98           1 :   if (0 > qs)
      99             :   {
     100           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     101           0 :     json_decref (ja);
     102           0 :     TALER_LOG_WARNING ("Failed to handle /exchanges in database\n");
     103           0 :     return TALER_MHD_reply_with_error (connection,
     104             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     105             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     106             :                                        "exchanges");
     107             :   }
     108           1 :   return TALER_MHD_REPLY_JSON_PACK (
     109             :     connection,
     110             :     MHD_HTTP_OK,
     111             :     GNUNET_JSON_pack_array_steal ("exchanges",
     112             :                                   ja));
     113             : }
     114             : 
     115             : 
     116             : /* end of taler-auditor-httpd_exchanges.c */

Generated by: LCOV version 1.14