LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_deposit-confirmation-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 40 77.5 %
Date: 2025-06-05 21:03:14 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014-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 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_deposit-confirmation-get.c
      18             :  * @brief Handle /deposit-confirmation requests; return list of deposit confirmations from merchant
      19             :  * that were not received from the exchange, by auditor.
      20             :  * @author Nic Eigel
      21             :  */
      22             : #include "platform.h"
      23             : #include <gnunet/gnunet_util_lib.h>
      24             : #include <gnunet/gnunet_json_lib.h>
      25             : #include <jansson.h>
      26             : #include <microhttpd.h>
      27             : #include <pthread.h>
      28             : #include "taler_json_lib.h"
      29             : #include "taler_mhd_lib.h"
      30             : #include "taler-auditor-httpd.h"
      31             : #include "taler-auditor-httpd_deposit-confirmation-get.h"
      32             : 
      33             : 
      34             : /**
      35             :  * Add deposit confirmation to the list.
      36             :  *
      37             :  * @param[in,out] cls a `json_t *` array to extend
      38             :  * @param dc struct of deposit confirmation
      39             :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      40             :  */
      41             : static enum GNUNET_GenericReturnValue
      42           3 : add_deposit_confirmation (
      43             :   void *cls,
      44             :   const struct TALER_AUDITORDB_DepositConfirmation *dc)
      45             : {
      46           3 :   json_t *list = cls;
      47             :   json_t *obj;
      48           3 :   json_t *coin_pubs_json = json_array ();
      49           3 :   json_t *coin_sigs_json = json_array ();
      50             : 
      51           3 :   GNUNET_assert (NULL != coin_pubs_json);
      52           3 :   GNUNET_assert (NULL != coin_sigs_json);
      53           6 :   for (unsigned int i = 0; i < dc->num_coins; i++)
      54             :   {
      55             :     json_t *pub;
      56             :     json_t *sig;
      57             : 
      58           3 :     pub = GNUNET_JSON_from_data_auto (&dc->coin_pubs[i]);
      59           3 :     GNUNET_assert (0 ==
      60             :                    json_array_append_new (coin_pubs_json,
      61             :                                           pub));
      62           3 :     sig = GNUNET_JSON_from_data_auto (&dc->coin_sigs[i]);
      63           3 :     GNUNET_assert (0 ==
      64             :                    json_array_append_new (coin_sigs_json,
      65             :                                           sig));
      66             :   }
      67             : 
      68           3 :   obj = GNUNET_JSON_PACK (
      69             :     GNUNET_JSON_pack_int64 ("deposit_confirmation_serial_id",
      70             :                             dc->row_id),
      71             :     GNUNET_JSON_pack_data_auto ("h_contract_terms",
      72             :                                 &dc->h_contract_terms),
      73             :     GNUNET_JSON_pack_data_auto ("h_policy",
      74             :                                 &dc->h_policy),
      75             :     GNUNET_JSON_pack_data_auto ("h_wire",
      76             :                                 &dc->h_wire),
      77             :     GNUNET_JSON_pack_timestamp ("exchange_timestamp",
      78             :                                 dc->exchange_timestamp),
      79             :     GNUNET_JSON_pack_timestamp ("refund_deadline",
      80             :                                 dc->refund_deadline),
      81             :     GNUNET_JSON_pack_timestamp ("wire_deadline",
      82             :                                 dc->wire_deadline),
      83             :     TALER_JSON_pack_amount ("total_without_fee",
      84             :                             &dc->total_without_fee),
      85             :     GNUNET_JSON_pack_array_steal ("coin_pubs",
      86             :                                   coin_pubs_json),
      87             :     GNUNET_JSON_pack_array_steal ("coin_sigs",
      88             :                                   coin_sigs_json),
      89             :     GNUNET_JSON_pack_data_auto ("merchant_pub",
      90             :                                 &dc->merchant),
      91             :     GNUNET_JSON_pack_data_auto ("exchange_sig",
      92             :                                 &dc->exchange_sig),
      93             :     GNUNET_JSON_pack_data_auto ("exchange_pub",
      94             :                                 &dc->exchange_pub),
      95             :     GNUNET_JSON_pack_data_auto ("master_sig",
      96             :                                 &dc->master_sig),
      97             :     GNUNET_JSON_pack_bool ("suppressed",
      98             :                            dc->suppressed)
      99             :     );
     100           3 :   GNUNET_break (0 ==
     101             :                 json_array_append_new (list,
     102             :                                        obj));
     103           3 :   return GNUNET_OK;
     104             : }
     105             : 
     106             : 
     107             : MHD_RESULT
     108           3 : TAH_DEPOSIT_CONFIRMATION_handler_get (
     109             :   struct TAH_RequestHandler *rh,
     110             :   struct MHD_Connection *connection,
     111             :   void **connection_cls,
     112             :   const char *upload_data,
     113             :   size_t *upload_data_size,
     114             :   const char *const args[])
     115             : {
     116             :   json_t *ja;
     117             :   enum GNUNET_DB_QueryStatus qs;
     118           3 :   bool return_suppressed = false;
     119           3 :   int64_t limit = -20;
     120             :   uint64_t offset;
     121             : 
     122             :   (void) rh;
     123             :   (void) connection_cls;
     124             :   (void) upload_data;
     125             :   (void) upload_data_size;
     126           3 :   if (GNUNET_SYSERR ==
     127           3 :       TAH_plugin->preflight (TAH_plugin->cls))
     128             :   {
     129           0 :     GNUNET_break (0);
     130           0 :     return TALER_MHD_reply_with_error (connection,
     131             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     132             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     133             :                                        NULL);
     134             :   }
     135           3 :   TALER_MHD_parse_request_snumber (connection,
     136             :                                    "limit",
     137             :                                    &limit);
     138           3 :   if (limit < 0)
     139           0 :     offset = INT64_MAX;
     140             :   else
     141           3 :     offset = 0;
     142           3 :   TALER_MHD_parse_request_number (connection,
     143             :                                   "offset",
     144             :                                   &offset);
     145             :   {
     146           3 :     const char *ret_s = MHD_lookup_connection_value (connection,
     147             :                                                      MHD_GET_ARGUMENT_KIND,
     148             :                                                      "return_suppressed");
     149           3 :     if ( (NULL != ret_s) &&
     150           0 :          (0 == strcmp (ret_s, "true")) )
     151             :     {
     152           0 :       return_suppressed = true;
     153             :     }
     154             :   }
     155             : 
     156           3 :   ja = json_array ();
     157           3 :   GNUNET_break (NULL != ja);
     158           3 :   qs = TAH_plugin->get_deposit_confirmations (
     159           3 :     TAH_plugin->cls,
     160             :     limit,
     161             :     offset,
     162             :     return_suppressed,
     163             :     &add_deposit_confirmation,
     164             :     ja);
     165           3 :   if (0 > qs)
     166             :   {
     167           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     168           0 :     json_decref (ja);
     169           0 :     TALER_LOG_WARNING (
     170             :       "Failed to handle GET /deposit-confirmation in database\n");
     171           0 :     return TALER_MHD_reply_with_error (connection,
     172             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     173             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     174             :                                        "deposit-confirmation");
     175             :   }
     176           3 :   return TALER_MHD_REPLY_JSON_PACK (
     177             :     connection,
     178             :     MHD_HTTP_OK,
     179             :     GNUNET_JSON_pack_array_steal ("deposit_confirmation",
     180             :                                   ja));
     181             : }
     182             : 
     183             : 
     184             : /* end of taler-auditor-httpd_deposit-confirmation-get.c */

Generated by: LCOV version 1.16