LCOV - code coverage report
Current view: top level - exchangedb - pg_select_all_kyc_attributes.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 29 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (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 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_select_all_kyc_attributes.c
      18             :  * @brief Implementation of the select_all_kyc_attributes 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_select_all_kyc_attributes.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : /**
      29             :  * Closure for #get_all_attributes_cb().
      30             :  */
      31             : struct GetAttributesContext
      32             : {
      33             :   /**
      34             :    * Function to call per result.
      35             :    */
      36             :   TALER_EXCHANGEDB_AllAttributesCallback cb;
      37             : 
      38             :   /**
      39             :    * Closure for @e cb.
      40             :    */
      41             :   void *cb_cls;
      42             : 
      43             :   /**
      44             :    * Plugin context.
      45             :    */
      46             :   struct PostgresClosure *pg;
      47             : 
      48             :   /**
      49             :    * Flag set to #GNUNET_OK as long as everything is fine.
      50             :    */
      51             :   enum GNUNET_GenericReturnValue status;
      52             : 
      53             : };
      54             : 
      55             : /**
      56             :  * Invoke the callback for each result.
      57             :  *
      58             :  * @param cls a `struct GetAttributesContext *`
      59             :  * @param result SQL result
      60             :  * @param num_results number of rows in @a result
      61             :  */
      62             : static void
      63           0 : get_attributes_cb (void *cls,
      64             :                    PGresult *result,
      65             :                    unsigned int num_results)
      66             : {
      67           0 :   struct GetAttributesContext *ctx = cls;
      68             : 
      69           0 :   for (unsigned int i = 0; i < num_results; i++)
      70             :   {
      71             :     uint64_t rowid;
      72             :     struct GNUNET_TIME_Timestamp collection_time;
      73             :     struct GNUNET_TIME_Timestamp expiration_time;
      74             :     struct TALER_NormalizedPaytoHashP h_payto;
      75           0 :     json_t *properties = NULL;
      76             :     size_t enc_attributes_size;
      77             :     void *enc_attributes;
      78             :     char *provider;
      79           0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      80           0 :       GNUNET_PQ_result_spec_string ("provider_name",
      81             :                                     &provider),
      82           0 :       GNUNET_PQ_result_spec_uint64 ("kyc_attributes_serial_id",
      83             :                                     &rowid),
      84           0 :       GNUNET_PQ_result_spec_allow_null (
      85             :         TALER_PQ_result_spec_json ("jproperties",
      86             :                                    &properties),
      87             :         NULL),
      88           0 :       GNUNET_PQ_result_spec_timestamp ("collection_time",
      89             :                                        &collection_time),
      90           0 :       GNUNET_PQ_result_spec_timestamp ("expiration_time",
      91             :                                        &expiration_time),
      92           0 :       GNUNET_PQ_result_spec_auto_from_type ("h_payto",
      93             :                                             &h_payto),
      94           0 :       GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
      95             :                                            &enc_attributes,
      96             :                                            &enc_attributes_size),
      97             :       GNUNET_PQ_result_spec_end
      98             :     };
      99             : 
     100           0 :     if (GNUNET_OK !=
     101           0 :         GNUNET_PQ_extract_result (result,
     102             :                                   rs,
     103             :                                   i))
     104             :     {
     105           0 :       GNUNET_break (0);
     106           0 :       ctx->status = GNUNET_SYSERR;
     107           0 :       return;
     108             :     }
     109           0 :     ctx->cb (ctx->cb_cls,
     110             :              rowid,
     111             :              &h_payto,
     112             :              provider,
     113             :              collection_time,
     114             :              expiration_time,
     115             :              properties,
     116             :              enc_attributes_size,
     117             :              enc_attributes);
     118           0 :     GNUNET_PQ_cleanup_result (rs);
     119             :   }
     120             : }
     121             : 
     122             : 
     123             : enum GNUNET_DB_QueryStatus
     124           0 : TEH_PG_select_all_kyc_attributes (
     125             :   void *cls,
     126             :   uint64_t min_row_id,
     127             :   TALER_EXCHANGEDB_AllAttributesCallback cb,
     128             :   void *cb_cls)
     129             : {
     130           0 :   struct PostgresClosure *pg = cls;
     131           0 :   struct GNUNET_PQ_QueryParam params[] = {
     132           0 :     GNUNET_PQ_query_param_uint64 (&min_row_id),
     133             :     GNUNET_PQ_query_param_end
     134             :   };
     135           0 :   struct GetAttributesContext ctx = {
     136             :     .cb = cb,
     137             :     .cb_cls = cb_cls,
     138             :     .pg = pg,
     139             :     .status = GNUNET_OK
     140             :   };
     141             :   enum GNUNET_DB_QueryStatus qs;
     142             : 
     143           0 :   PREPARE (pg,
     144             :            "select_all_kyc_attributes",
     145             :            "SELECT "
     146             :            " lp.provider_name"
     147             :            ",ka.h_payto"
     148             :            ",ka.kyc_attributes_serial_id"
     149             :            ",lo.jproperties"
     150             :            ",ka.collection_time"
     151             :            ",ka.expiration_time"
     152             :            ",ka.encrypted_attributes"
     153             :            " FROM kyc_attributes ka"
     154             :            " JOIN legitimization_processes lp"
     155             :            "   ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
     156             :            " LEFT JOIN legitimization_outcomes lo"
     157             :            "   ON (ka.h_payto = lo.h_payto)"
     158             :            /* **IF** we joined with 'lo', the lo must be active */
     159             :            " WHERE COALESCE(lo.is_active,TRUE)"
     160             :            "   AND kyc_attributes_serial_id > $1"
     161             :            " ORDER BY kyc_attributes_serial_id ASC"
     162             :            );
     163           0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     164             :     pg->conn,
     165             :     "select_all_kyc_attributes",
     166             :     params,
     167             :     &get_attributes_cb,
     168             :     &ctx);
     169           0 :   if (GNUNET_OK != ctx.status)
     170           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     171           0 :   return qs;
     172             : }

Generated by: LCOV version 1.16