challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

gc.c (1988B)


      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/gc.c
     18  * @brief Implementation of the gc function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "challenger-database/gc.h"
     24 #include "challenger-database/preflight.h"
     25 #include "pg_helper.h"
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 CHALLENGERDB_gc (struct CHALLENGERDB_PostgresContext *pg,
     30                  struct GNUNET_TIME_Absolute expire)
     31 {
     32   struct GNUNET_PQ_QueryParam params[] = {
     33     GNUNET_PQ_query_param_absolute_time (&expire),
     34     GNUNET_PQ_query_param_end
     35   };
     36   enum GNUNET_DB_QueryStatus qs;
     37 
     38   GNUNET_PQ_reconnect_if_down (pg->conn);
     39   PREPARE (pg,
     40            "gc_validations",
     41            "DELETE FROM validations"
     42            " WHERE expiration_time < $1;");
     43   PREPARE (pg,
     44            "gc_tokens",
     45            "DELETE FROM tokens"
     46            " WHERE token_expiration_time < $1;");
     47   CHALLENGERDB_preflight (pg);
     48   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     49                                            "gc_validations",
     50                                            params);
     51   if (qs < 0)
     52     return qs;
     53   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     54                                              "gc_tokens",
     55                                              params);
     56 }