LCOV - code coverage report
Current view: top level - exchangedb - select_kyc_attributes.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 24 20
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022, 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 exchangedb/select_kyc_attributes.c
      18              :  * @brief Implementation of the select_kyc_attributes function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/select_kyc_attributes.h"
      23              : #include "helper.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Closure for #get_attributes_cb().
      28              :  */
      29              : struct GetAttributesContext
      30              : {
      31              :   /**
      32              :    * Function to call per result.
      33              :    */
      34              :   TALER_EXCHANGEDB_AttributeCallback cb;
      35              : 
      36              :   /**
      37              :    * Closure for @e cb.
      38              :    */
      39              :   void *cb_cls;
      40              : 
      41              :   /**
      42              :    * Plugin context.
      43              :    */
      44              :   struct TALER_EXCHANGEDB_PostgresContext *pg;
      45              : 
      46              :   /**
      47              :    * Key of our query.
      48              :    */
      49              :   const struct TALER_NormalizedPaytoHashP *h_payto;
      50              : 
      51              :   /**
      52              :    * Flag set to #GNUNET_OK as long as everything is fine.
      53              :    */
      54              :   enum GNUNET_GenericReturnValue status;
      55              : 
      56              : };
      57              : 
      58              : 
      59              : /**
      60              :  * Invoke the callback for each result.
      61              :  *
      62              :  * @param cls a `struct GetAttributesContext *`
      63              :  * @param result SQL result
      64              :  * @param num_results number of rows in @a result
      65              :  */
      66              : static void
      67            7 : get_attributes_cb (void *cls,
      68              :                    PGresult *result,
      69              :                    unsigned int num_results)
      70              : {
      71            7 :   struct GetAttributesContext *ctx = cls;
      72              : 
      73            9 :   for (unsigned int i = 0; i < num_results; i++)
      74              :   {
      75              :     struct GNUNET_TIME_Timestamp collection_time;
      76              :     struct GNUNET_TIME_Timestamp expiration_time;
      77              :     size_t enc_attributes_size;
      78              :     void *enc_attributes;
      79              :     char *provider;
      80            2 :     struct GNUNET_PQ_ResultSpec rs[] = {
      81            2 :       GNUNET_PQ_result_spec_string ("provider_name",
      82              :                                     &provider),
      83            2 :       GNUNET_PQ_result_spec_timestamp ("collection_time",
      84              :                                        &collection_time),
      85            2 :       GNUNET_PQ_result_spec_timestamp ("expiration_time",
      86              :                                        &expiration_time),
      87            2 :       GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
      88              :                                            &enc_attributes,
      89              :                                            &enc_attributes_size),
      90              :       GNUNET_PQ_result_spec_end
      91              :     };
      92              : 
      93            2 :     if (GNUNET_OK !=
      94            2 :         GNUNET_PQ_extract_result (result,
      95              :                                   rs,
      96              :                                   i))
      97              :     {
      98            0 :       GNUNET_break (0);
      99            0 :       ctx->status = GNUNET_SYSERR;
     100            0 :       return;
     101              :     }
     102            2 :     ctx->cb (ctx->cb_cls,
     103              :              ctx->h_payto,
     104              :              provider,
     105              :              collection_time,
     106              :              expiration_time,
     107              :              enc_attributes_size,
     108              :              enc_attributes);
     109            2 :     GNUNET_PQ_cleanup_result (rs);
     110              :   }
     111              : }
     112              : 
     113              : 
     114              : enum GNUNET_DB_QueryStatus
     115            7 : TALER_EXCHANGEDB_select_kyc_attributes (
     116              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
     117              :   const struct TALER_NormalizedPaytoHashP *h_payto,
     118              :   TALER_EXCHANGEDB_AttributeCallback cb,
     119              :   void *cb_cls)
     120              : {
     121            7 :   struct GNUNET_PQ_QueryParam params[] = {
     122            7 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
     123              :     GNUNET_PQ_query_param_end
     124              :   };
     125            7 :   struct GetAttributesContext ctx = {
     126              :     .cb = cb,
     127              :     .cb_cls = cb_cls,
     128              :     .pg = pg,
     129              :     .h_payto = h_payto,
     130              :     .status = GNUNET_OK
     131              :   };
     132              :   enum GNUNET_DB_QueryStatus qs;
     133              : 
     134            7 :   PREPARE (pg,
     135              :            "select_kyc_attributes",
     136              :            "SELECT "
     137              :            " lp.provider_name"
     138              :            ",ka.collection_time"
     139              :            ",ka.expiration_time"
     140              :            ",ka.encrypted_attributes"
     141              :            " FROM kyc_attributes ka"
     142              :            " JOIN legitimization_processes lp"
     143              :            "   ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
     144              :            " WHERE ka.h_payto=$1");
     145            7 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     146              :     pg->conn,
     147              :     "select_kyc_attributes",
     148              :     params,
     149              :     &get_attributes_cb,
     150              :     &ctx);
     151            7 :   if (GNUNET_OK != ctx.status)
     152            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     153            7 :   return qs;
     154              : }
        

Generated by: LCOV version 2.0-1