LCOV - code coverage report
Current view: top level - challengerdb - delete_client.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.7 % 12 11
Test Date: 2026-09-09 01:07:11 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of Challenger
       3              :    Copyright (C) 2023 Taler Systems SA
       4              : 
       5              :    Challenger 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              :    Challenger 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              :    Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15              :  */
      16              : /**
      17              :  * @file src/challengerdb/delete_client.c
      18              :  * @brief Implementation of the delete_client function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_error_codes.h>
      23              : #include <taler/taler_dbevents.h>
      24              : #include <taler/taler_pq_lib.h>
      25              : #include "delete_client.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30            2 : CHALLENGERDB_delete_client (struct CHALLENGERDB_PostgresContext *ctx,
      31              :                             const char *client_redirect_uri,
      32              :                             uint64_t *validations_deleted)
      33              : {
      34            2 :   struct GNUNET_PQ_QueryParam params[] = {
      35            2 :     GNUNET_PQ_query_param_string (client_redirect_uri),
      36              :     GNUNET_PQ_query_param_end
      37              :   };
      38              :   bool deleted;
      39            2 :   struct GNUNET_PQ_ResultSpec rs[] = {
      40            2 :     GNUNET_PQ_result_spec_uint64 ("validations_deleted",
      41              :                                   validations_deleted),
      42            2 :     GNUNET_PQ_result_spec_bool ("deleted",
      43              :                                 &deleted),
      44              :     GNUNET_PQ_result_spec_end
      45              :   };
      46              :   enum GNUNET_DB_QueryStatus qs;
      47              : 
      48            2 :   *validations_deleted = 0;
      49              :   /* validations_client_serial_id_fkey is ON DELETE CASCADE, so deleting a
      50              :      client silently discards all of its validations -- KYC processes that
      51              :      are in flight right now.  Delete them here explicitly instead, so that
      52              :      we can tell the operator how many were lost.  Note that access tokens
      53              :      already issued are *not* affected: 'tokens' has no client reference at
      54              :      all and thus cannot be revoked per client. */
      55            2 :   PREPARE (ctx,
      56              :            "delete_client",
      57              :            "WITH victim AS ("
      58              :            "  SELECT client_serial_id"
      59              :            "    FROM clients"
      60              :            "   WHERE uri=$1"
      61              :            "), dv AS ("
      62              :            "  DELETE FROM validations"
      63              :            "   WHERE client_serial_id IN"
      64              :            "     (SELECT client_serial_id FROM victim)"
      65              :            "  RETURNING validation_serial_id"
      66              :            "), dc AS ("
      67              :            "  DELETE FROM clients"
      68              :            "   WHERE uri=$1"
      69              :            "  RETURNING client_serial_id"
      70              :            ") SELECT"
      71              :            "   (SELECT COUNT(*) FROM dv) AS validations_deleted"
      72              :            "  ,EXISTS (SELECT 1 FROM dc) AS deleted;");
      73            2 :   qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
      74              :                                                  "delete_client",
      75              :                                                  params,
      76              :                                                  rs);
      77            2 :   if (0 >= qs)
      78            0 :     return qs;
      79              :   return deleted
      80              :          ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
      81            2 :          : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
      82              : }
        

Generated by: LCOV version 2.0-1