LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-pots.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 26 0
Test Date: 2025-12-29 21:26:17 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2025 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
      12              :   details.
      13              : 
      14              :   You should have received a copy of the GNU Affero General Public License
      15              :   along with TALER; see the file COPYING.  If not, see
      16              :   <http://www.gnu.org/licenses/>
      17              : */
      18              : /**
      19              :  * @file merchant/backend/taler-merchant-httpd_private-get-pots.c
      20              :  * @brief implementation of GET /private/pots
      21              :  * @author Christian Grothoff
      22              :  */
      23              : #include "platform.h"
      24              : #include "taler-merchant-httpd_private-get-pots.h"
      25              : #include <taler/taler_json_lib.h>
      26              : 
      27              : 
      28              : /**
      29              :  * Sensible bound on the limit.
      30              :  */
      31              : #define MAX_DELTA 1024
      32              : 
      33              : 
      34              : /**
      35              :  * Callback for listing money pots.
      36              :  *
      37              :  * @param cls closure with a `json_t *`
      38              :  * @param money_pot_id unique identifier of the pot
      39              :  * @param name name of the pot
      40              :  * @param description human-readable description (ignored for listing)
      41              :  * @param pot_total_len length of the @a pot_totals array
      42              :  * @param pot_totals current total amounts in the pot
      43              :  */
      44              : static void
      45            0 : add_pot (void *cls,
      46              :          uint64_t money_pot_id,
      47              :          const char *name,
      48              :          size_t pot_total_len,
      49              :          const struct TALER_Amount *pot_totals)
      50              : {
      51            0 :   json_t *pots = cls;
      52              :   json_t *entry;
      53              : 
      54            0 :   entry = GNUNET_JSON_PACK (
      55              :     GNUNET_JSON_pack_uint64 ("pot_serial",
      56              :                              money_pot_id),
      57              :     GNUNET_JSON_pack_string ("pot_name",
      58              :                              name),
      59              :     (0 == pot_total_len)
      60              :     ? GNUNET_JSON_pack_array_steal ("pot_totals",
      61              :                                     json_array ())
      62              :     : TALER_JSON_pack_amount_array ("pot_totals",
      63              :                                     pot_total_len,
      64              :                                     pot_totals));
      65            0 :   GNUNET_assert (NULL != entry);
      66            0 :   GNUNET_assert (0 ==
      67              :                  json_array_append_new (pots,
      68              :                                         entry));
      69            0 : }
      70              : 
      71              : 
      72              : MHD_RESULT
      73            0 : TMH_private_get_pots (const struct TMH_RequestHandler *rh,
      74              :                       struct MHD_Connection *connection,
      75              :                       struct TMH_HandlerContext *hc)
      76              : {
      77            0 :   int64_t limit = -20;
      78              :   uint64_t offset;
      79              :   json_t *pots;
      80              : 
      81              :   (void) rh;
      82            0 :   TALER_MHD_parse_request_snumber (connection,
      83              :                                    "limit",
      84              :                                    &limit);
      85            0 :   if (limit > 0)
      86            0 :     offset = 0;
      87              :   else
      88            0 :     offset = INT64_MAX;
      89            0 :   TALER_MHD_parse_request_number (connection,
      90              :                                   "offset",
      91              :                                   &offset);
      92            0 :   if ( (-MAX_DELTA > limit) ||
      93            0 :        (limit > MAX_DELTA) )
      94              :   {
      95            0 :     GNUNET_break_op (0);
      96            0 :     return TALER_MHD_reply_with_error (connection,
      97              :                                        MHD_HTTP_BAD_REQUEST,
      98              :                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
      99              :                                        "limit");
     100              :   }
     101              : 
     102            0 :   pots = json_array ();
     103            0 :   GNUNET_assert (NULL != pots);
     104              :   {
     105              :     enum GNUNET_DB_QueryStatus qs;
     106              : 
     107            0 :     qs = TMH_db->select_money_pots (TMH_db->cls,
     108            0 :                                     hc->instance->settings.id,
     109              :                                     limit,
     110              :                                     offset,
     111              :                                     &add_pot,
     112              :                                     pots);
     113            0 :     if (qs < 0)
     114              :     {
     115            0 :       GNUNET_break (0);
     116            0 :       json_decref (pots);
     117            0 :       return TALER_MHD_reply_with_error (connection,
     118              :                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
     119              :                                          TALER_EC_GENERIC_DB_FETCH_FAILED,
     120              :                                          "select_money_pots");
     121              :     }
     122              :   }
     123            0 :   return TALER_MHD_REPLY_JSON_PACK (
     124              :     connection,
     125              :     MHD_HTTP_OK,
     126              :     GNUNET_JSON_pack_array_steal ("pots",
     127              :                                   pots));
     128              : }
        

Generated by: LCOV version 2.0-1