LCOV - code coverage report
Current view: top level - exchangedb - lookup_kyc_history.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 37 0
Test Date: 2026-04-14 15:39:31 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 exchangedb/lookup_kyc_history.c
      18              :  * @brief Implementation of the lookup_kyc_history function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_error_codes.h"
      22              : #include "taler/taler_pq_lib.h"
      23              : #include "exchange-database/lookup_kyc_history.h"
      24              : #include "helper.h"
      25              : 
      26              : /**
      27              :  * Closure for callbacks called from #TALER_EXCHANGEDB_lookup_kyc_history()
      28              :  */
      29              : struct KycHistoryContext
      30              : {
      31              : 
      32              :   /**
      33              :    * Function to call on each result.
      34              :    */
      35              :   TALER_EXCHANGEDB_KycHistoryCallback cb;
      36              : 
      37              :   /**
      38              :    * Closure for @e cb.
      39              :    */
      40              :   void *cb_cls;
      41              : 
      42              :   /**
      43              :    * Plugin context.
      44              :    */
      45              :   struct TALER_EXCHANGEDB_PostgresContext *pg;
      46              : 
      47              :   /**
      48              :    * Set to 'true' if the transaction failed.
      49              :    */
      50              :   bool failed;
      51              : 
      52              : };
      53              : 
      54              : 
      55              : /**
      56              :  * Function 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 KycHistoryContext`
      60              :  * @param result the postgres result
      61              :  * @param num_results the number of results in @a result
      62              :  */
      63              : static void
      64            0 : handle_kyc_entry (void *cls,
      65              :                   PGresult *result,
      66              :                   unsigned int num_results)
      67              : {
      68            0 :   struct KycHistoryContext *khc = cls;
      69              : 
      70            0 :   for (unsigned int i = 0; i < num_results; i++)
      71              :   {
      72            0 :     char *provider_name = NULL;
      73              :     bool finished;
      74              :     uint32_t error_code;
      75            0 :     char *error_message = NULL;
      76            0 :     char *provider_user_id = NULL;
      77            0 :     char *provider_legitimization_id = NULL;
      78              :     struct GNUNET_TIME_Timestamp collection_time;
      79            0 :     struct GNUNET_TIME_Absolute expiration_time
      80              :       = GNUNET_TIME_UNIT_ZERO_ABS;
      81              :     void *encrypted_attributes;
      82              :     size_t encrypted_attributes_len;
      83              : 
      84            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      85            0 :       GNUNET_PQ_result_spec_allow_null (
      86              :         GNUNET_PQ_result_spec_string ("provider_name",
      87              :                                       &provider_name),
      88              :         NULL),
      89            0 :       GNUNET_PQ_result_spec_bool ("finished",
      90              :                                   &finished),
      91            0 :       GNUNET_PQ_result_spec_uint32 ("error_code",
      92              :                                     &error_code),
      93            0 :       GNUNET_PQ_result_spec_allow_null (
      94              :         GNUNET_PQ_result_spec_string ("error_message",
      95              :                                       &error_message),
      96              :         NULL),
      97            0 :       GNUNET_PQ_result_spec_allow_null (
      98              :         GNUNET_PQ_result_spec_string ("provider_user_id",
      99              :                                       &provider_user_id),
     100              :         NULL),
     101            0 :       GNUNET_PQ_result_spec_allow_null (
     102              :         GNUNET_PQ_result_spec_string ("provider_legitimization_id",
     103              :                                       &provider_legitimization_id),
     104              :         NULL),
     105            0 :       GNUNET_PQ_result_spec_timestamp ("collection_time",
     106              :                                        &collection_time),
     107            0 :       GNUNET_PQ_result_spec_allow_null (
     108              :         GNUNET_PQ_result_spec_absolute_time ("expiration_time",
     109              :                                              &expiration_time),
     110              :         NULL),
     111            0 :       GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
     112              :                                            &encrypted_attributes,
     113              :                                            &encrypted_attributes_len),
     114              :       GNUNET_PQ_result_spec_end
     115              :     };
     116              : 
     117            0 :     if (GNUNET_OK !=
     118            0 :         GNUNET_PQ_extract_result (result,
     119              :                                   rs,
     120              :                                   i))
     121              :     {
     122            0 :       GNUNET_break (0);
     123            0 :       khc->failed = true;
     124            0 :       return;
     125              :     }
     126            0 :     khc->cb (khc->cb_cls,
     127              :              provider_name,
     128              :              finished,
     129              :              (enum TALER_ErrorCode) error_code,
     130              :              error_message,
     131              :              provider_user_id,
     132              :              provider_legitimization_id,
     133              :              collection_time,
     134              :              expiration_time,
     135              :              encrypted_attributes_len,
     136              :              encrypted_attributes);
     137            0 :     GNUNET_PQ_cleanup_result (rs);
     138              :   }
     139              : }
     140              : 
     141              : 
     142              : enum GNUNET_DB_QueryStatus
     143            0 : TALER_EXCHANGEDB_lookup_kyc_history (
     144              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
     145              :   const struct TALER_NormalizedPaytoHashP *h_payto,
     146              :   TALER_EXCHANGEDB_KycHistoryCallback cb,
     147              :   void *cb_cls)
     148              : {
     149            0 :   struct KycHistoryContext khc = {
     150              :     .pg = pg,
     151              :     .cb = cb,
     152              :     .cb_cls = cb_cls
     153              :   };
     154            0 :   struct GNUNET_PQ_QueryParam params[] = {
     155            0 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
     156              :     GNUNET_PQ_query_param_end
     157              :   };
     158              :   enum GNUNET_DB_QueryStatus qs;
     159              : 
     160            0 :   PREPARE (pg,
     161              :            "lookup_kyc_history",
     162              :            "SELECT"
     163              :            " lp.provider_name"
     164              :            ",lp.finished"
     165              :            ",lp.error_code"
     166              :            ",lp.error_message"
     167              :            ",lp.provider_user_id"
     168              :            ",lp.provider_legitimization_id"
     169              :            ",ka.collection_time"
     170              :            ",ka.expiration_time"
     171              :            ",ka.encrypted_attributes"
     172              :            " FROM kyc_attributes ka"
     173              :            "    JOIN legitimization_processes lp"
     174              :            "      ON (ka.legitimization_serial = lp.legitimization_process_serial_id)"
     175              :            " WHERE ka.h_payto=$1"
     176              :            " ORDER BY ka.collection_time DESC;");
     177              : 
     178            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     179              :     pg->conn,
     180              :     "lookup_kyc_history",
     181              :     params,
     182              :     &handle_kyc_entry,
     183              :     &khc);
     184            0 :   if (qs <= 0)
     185            0 :     return qs;
     186            0 :   if (khc.failed)
     187              :   {
     188            0 :     GNUNET_break (0);
     189            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     190              :   }
     191            0 :   return qs;
     192              : }
        

Generated by: LCOV version 2.0-1