LCOV - code coverage report
Current view: top level - auditordb - pg_get_progress_points.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 28 0
Test Date: 2025-12-28 14:06:02 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 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 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 auditordb/pg_get_progress_points.c
      18              :  * @brief Implementation of the get_progress_points function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/platform.h"
      22              : #include "taler/taler_error_codes.h"
      23              : #include "taler/taler_dbevents.h"
      24              : #include "taler/taler_pq_lib.h"
      25              : #include "pg_get_progress_points.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : struct ProgressContext
      30              : {
      31              : 
      32              :   /**
      33              :    * Function to call for each progress point.
      34              :    */
      35              :   TALER_AUDITORDB_ProgressPointsCallback cb;
      36              : 
      37              :   /**
      38              :    * Closure for @e cb
      39              :    */
      40              :   void *cb_cls;
      41              : 
      42              :   /**
      43              :    * Plugin context.
      44              :    */
      45              :   struct PostgresClosure *pg;
      46              : 
      47              :   /**
      48              :    * Query status to return.
      49              :    */
      50              :   enum GNUNET_DB_QueryStatus qs;
      51              : };
      52              : 
      53              : 
      54              : /**
      55              :  * Helper function for #TAH_PG_get_progress_points().
      56              :  * To be called with the results of a SELECT statement
      57              :  * that has returned @a num_results results.
      58              :  *
      59              :  * @param cls closure of type `struct ProgressContext *`
      60              :  * @param result the postgres result
      61              :  * @param num_results the number of results in @a result
      62              :  */
      63              : static void
      64            0 : progress_cb (void *cls,
      65              :              PGresult *result,
      66              :              unsigned int num_results)
      67              : {
      68            0 :   struct ProgressContext *dcc = cls;
      69              : 
      70            0 :   for (unsigned int i = 0; i < num_results; i++)
      71              :   {
      72              :     struct TALER_AUDITORDB_Progress dc;
      73            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      74            0 :       GNUNET_PQ_result_spec_string ("progress_key",
      75              :                                     &dc.progress_key),
      76            0 :       GNUNET_PQ_result_spec_uint64 ("progress_offset",
      77              :                                     &dc.progress_offset),
      78              :       GNUNET_PQ_result_spec_end
      79              :     };
      80              :     enum GNUNET_GenericReturnValue rval;
      81              : 
      82            0 :     if (GNUNET_OK !=
      83            0 :         GNUNET_PQ_extract_result (result,
      84              :                                   rs,
      85              :                                   i))
      86              :     {
      87            0 :       GNUNET_break (0);
      88            0 :       dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
      89            0 :       return;
      90              :     }
      91            0 :     dcc->qs = i + 1;
      92            0 :     rval = dcc->cb (dcc->cb_cls,
      93              :                     &dc);
      94            0 :     GNUNET_PQ_cleanup_result (rs);
      95            0 :     if (GNUNET_OK != rval)
      96            0 :       break;
      97              :   }
      98              : }
      99              : 
     100              : 
     101              : enum GNUNET_DB_QueryStatus
     102            0 : TAH_PG_get_progress_points (
     103              :   void *cls,
     104              :   const char *progress_key,
     105              :   TALER_AUDITORDB_ProgressPointsCallback cb,
     106              :   void *cb_cls)
     107              : {
     108            0 :   struct PostgresClosure *pg = cls;
     109            0 :   struct GNUNET_PQ_QueryParam params[] = {
     110              :     NULL == progress_key
     111            0 :     ? GNUNET_PQ_query_param_null ()
     112            0 :     : GNUNET_PQ_query_param_string (progress_key),
     113              :     GNUNET_PQ_query_param_end
     114              :   };
     115            0 :   struct ProgressContext dcc = {
     116              :     .cb = cb,
     117              :     .cb_cls = cb_cls,
     118              :     .pg = pg
     119              :   };
     120              :   enum GNUNET_DB_QueryStatus qs;
     121              : 
     122            0 :   PREPARE (pg,
     123              :            "auditor_progress_points_get",
     124              :            "SELECT"
     125              :            " progress_key"
     126              :            ",progress_offset"
     127              :            " FROM auditor_progress"
     128              :            " WHERE ($1::TEXT IS NULL OR progress_key = $1)"
     129              :            );
     130            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     131              :     pg->conn,
     132              :     "auditor_progress_points_get",
     133              :     params,
     134              :     &progress_cb,
     135              :     &dcc);
     136            0 :   if (qs > 0)
     137            0 :     return dcc.qs;
     138            0 :   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
     139            0 :   return qs;
     140              : }
        

Generated by: LCOV version 2.0-1