anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-db_test_challenge_code_satisfied.c (2701B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020-2022 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis 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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file stasis/anastasis-db_test_challenge_code_satisfied.c
     18  * @brief Anastasis database: test challenge code satisfied
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "anastasis-db_pg.h"
     23 #include "anastasis/anastasis-database/test_challenge_code_satisfied.h"
     24 #include "anastasis/anastasis-database/transaction.h"
     25 #include "anastasis/anastasis-database/preflight.h"
     26 #include <taler/taler_pq_lib.h>
     27 
     28 
     29 /**
     30  * Check if the 'satisfied' bit for the given challenge and code is
     31  * 'true' and the challenge code is not yet expired.
     32  *
     33  * @param truth_uuid identification of the challenge which the code corresponds to
     34  * @param code code which is now satisfied
     35  * @return transaction status,
     36  *        #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the challenge code is not satisfied or expired
     37  *        #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the challenge code has been marked as satisfied
     38  */
     39 enum GNUNET_DB_QueryStatus
     40 ANASTASIS_DB_test_challenge_code_satisfied (
     41   const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
     42   const uint64_t code,
     43   struct GNUNET_TIME_Timestamp after)
     44 {
     45   struct GNUNET_PQ_QueryParam params[] = {
     46     GNUNET_PQ_query_param_auto_from_type (truth_uuid),
     47     GNUNET_PQ_query_param_uint64 (&code),
     48     GNUNET_PQ_query_param_timestamp (&after),
     49     GNUNET_PQ_query_param_end
     50   };
     51   struct GNUNET_PQ_ResultSpec rs[] = {
     52     GNUNET_PQ_result_spec_end
     53   };
     54 
     55   PREPARE ("challengecode_test_satisfied",
     56            "SELECT 1 FROM anastasis_challengecode"
     57            " WHERE truth_uuid=$1"
     58            "   AND satisfied=TRUE"
     59            "   AND code=$2"
     60            "   AND creation_date >= $3"
     61            " LIMIT 1;");
     62   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     63                                                    "challengecode_test_satisfied",
     64                                                    params,
     65                                                    rs);
     66 }
     67 
     68 
     69 /* end of anastasis-db_test_challenge_code_satisfied.c */