LCOV - code coverage report
Current view: top level - backenddb - pg_lookup_order.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 24 95.8 %
Date: 2025-06-23 16:22:09 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2022 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 backenddb/pg_lookup_order.c
      18             :  * @brief Implementation of the lookup_order function for Postgres
      19             :  * @author Iván Ávalos
      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 "pg_lookup_order.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : enum GNUNET_DB_QueryStatus
      29         141 : TMH_PG_lookup_order (void *cls,
      30             :                      const char *instance_id,
      31             :                      const char *order_id,
      32             :                      struct TALER_ClaimTokenP *claim_token,
      33             :                      struct TALER_MerchantPostDataHashP *h_post_data,
      34             :                      json_t **contract_terms)
      35             : {
      36         141 :   struct PostgresClosure *pg = cls;
      37             :   json_t *j;
      38             :   struct TALER_ClaimTokenP ct;
      39             :   enum GNUNET_DB_QueryStatus qs;
      40         141 :   struct GNUNET_PQ_QueryParam params[] = {
      41         141 :     GNUNET_PQ_query_param_string (instance_id),
      42         141 :     GNUNET_PQ_query_param_string (order_id),
      43             :     GNUNET_PQ_query_param_end
      44             :   };
      45         141 :   struct GNUNET_PQ_ResultSpec rs[] = {
      46         141 :     TALER_PQ_result_spec_json ("contract_terms",
      47             :                                &j),
      48         141 :     GNUNET_PQ_result_spec_auto_from_type ("claim_token",
      49             :                                           &ct),
      50         141 :     GNUNET_PQ_result_spec_auto_from_type ("h_post_data",
      51             :                                           h_post_data),
      52             :     GNUNET_PQ_result_spec_end
      53             :   };
      54             : 
      55         141 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      56             :               "Finding contract term, order_id: '%s', instance_id: '%s'.\n",
      57             :               order_id,
      58             :               instance_id);
      59         141 :   check_connection (pg);
      60         141 :   PREPARE (pg,
      61             :            "lookup_order",
      62             :            "SELECT"
      63             :            " contract_terms"
      64             :            ",claim_token"
      65             :            ",h_post_data"
      66             :            ",pos_key"
      67             :            " FROM merchant_orders"
      68             :            " WHERE merchant_orders.merchant_serial="
      69             :            "     (SELECT merchant_serial "
      70             :            "        FROM merchant_instances"
      71             :            "        WHERE merchant_id=$1)"
      72             :            "   AND merchant_orders.order_id=$2");
      73         141 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      74             :                                                  "lookup_order",
      75             :                                                  params,
      76             :                                                  rs);
      77         141 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
      78             :   {
      79          73 :     if (NULL != contract_terms)
      80          73 :       *contract_terms = j;
      81             :     else
      82           0 :       json_decref (j);
      83          73 :     if (NULL != claim_token)
      84          72 :       *claim_token = ct;
      85             :   }
      86             :   else
      87             :   {
      88             :     /* just to be safe: NULL it */
      89          68 :     if (NULL != contract_terms)
      90          64 :       *contract_terms = NULL;
      91          68 :     if (NULL != claim_token)
      92          64 :       *claim_token = (struct TALER_ClaimTokenP) { 0 }
      93             :     ;
      94             :   }
      95         141 :   return qs;
      96             : }

Generated by: LCOV version 1.16