LCOV - code coverage report
Current view: top level - exchangedb - pg_iterate_active_auditors.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 19 89.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) 2022 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 exchangedb/pg_iterate_active_auditors.c
      18             :  * @brief Implementation of the iterate_active_auditors function for Postgres
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_error_codes.h"
      23             : #include "taler_dbevents.h"
      24             : #include "taler_pq_lib.h"
      25             : #include "pg_iterate_active_auditors.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : /**
      30             :  * Closure for #auditors_cb_helper()
      31             :  */
      32             : struct AuditorsIteratorContext
      33             : {
      34             :   /**
      35             :    * Function to call with the results.
      36             :    */
      37             :   TALER_EXCHANGEDB_AuditorsCallback cb;
      38             : 
      39             :   /**
      40             :    * Closure to pass to @e cb
      41             :    */
      42             :   void *cb_cls;
      43             : 
      44             : };
      45             : 
      46             : 
      47             : /**
      48             :  * Helper function for #TEH_PG_iterate_active_auditors().
      49             :  * Calls the callback with each auditor.
      50             :  *
      51             :  * @param cls a `struct SignkeysIteratorContext`
      52             :  * @param result db results
      53             :  * @param num_results number of results in @a result
      54             :  */
      55             : static void
      56          89 : auditors_cb_helper (void *cls,
      57             :                     PGresult *result,
      58             :                     unsigned int num_results)
      59             : {
      60          89 :   struct AuditorsIteratorContext *dic = cls;
      61             : 
      62          97 :   for (unsigned int i = 0; i<num_results; i++)
      63             :   {
      64             :     struct TALER_AuditorPublicKeyP auditor_pub;
      65             :     char *auditor_url;
      66             :     char *auditor_name;
      67           8 :     struct GNUNET_PQ_ResultSpec rs[] = {
      68           8 :       GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
      69             :                                             &auditor_pub),
      70           8 :       GNUNET_PQ_result_spec_string ("auditor_url",
      71             :                                     &auditor_url),
      72           8 :       GNUNET_PQ_result_spec_string ("auditor_name",
      73             :                                     &auditor_name),
      74             :       GNUNET_PQ_result_spec_end
      75             :     };
      76             : 
      77           8 :     if (GNUNET_OK !=
      78           8 :         GNUNET_PQ_extract_result (result,
      79             :                                   rs,
      80             :                                   i))
      81             :     {
      82           0 :       GNUNET_break (0);
      83           0 :       return;
      84             :     }
      85           8 :     dic->cb (dic->cb_cls,
      86             :              &auditor_pub,
      87             :              auditor_url,
      88             :              auditor_name);
      89           8 :     GNUNET_PQ_cleanup_result (rs);
      90             :   }
      91             : }
      92             : 
      93             : 
      94             : enum GNUNET_DB_QueryStatus
      95          89 : TEH_PG_iterate_active_auditors (void *cls,
      96             :                                 TALER_EXCHANGEDB_AuditorsCallback cb,
      97             :                                 void *cb_cls)
      98             : {
      99          89 :   struct PostgresClosure *pg = cls;
     100          89 :   struct GNUNET_PQ_QueryParam params[] = {
     101             :     GNUNET_PQ_query_param_end
     102             :   };
     103          89 :   struct AuditorsIteratorContext dic = {
     104             :     .cb = cb,
     105             :     .cb_cls = cb_cls,
     106             :   };
     107             : 
     108          89 :   PREPARE (pg,
     109             :            "select_auditors",
     110             :            "SELECT"
     111             :            " auditor_pub"
     112             :            ",auditor_url"
     113             :            ",auditor_name"
     114             :            " FROM auditors"
     115             :            " WHERE"
     116             :            "   is_active;");
     117             : 
     118          89 :   return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     119             :                                                "select_auditors",
     120             :                                                params,
     121             :                                                &auditors_cb_helper,
     122             :                                                &dic);
     123             : }

Generated by: LCOV version 1.16