LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_contract.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 20 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          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 Affero 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 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             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file taler-exchange-httpd_contract.c
      18             :  * @brief Handle GET /contracts/$C_PUB requests
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include <jansson.h>
      24             : #include <microhttpd.h>
      25             : #include "taler_mhd_lib.h"
      26             : #include "taler-exchange-httpd_contract.h"
      27             : #include "taler-exchange-httpd_mhd.h"
      28             : #include "taler-exchange-httpd_responses.h"
      29             : 
      30             : 
      31             : MHD_RESULT
      32           0 : TEH_handler_contracts_get (struct TEH_RequestContext *rc,
      33             :                            const char *const args[1])
      34             : {
      35             :   struct TALER_ContractDiffiePublicP contract_pub;
      36             :   struct TALER_PurseContractPublicKeyP purse_pub;
      37             :   void *econtract;
      38             :   size_t econtract_size;
      39             :   enum GNUNET_DB_QueryStatus qs;
      40             :   struct TALER_PurseContractSignatureP econtract_sig;
      41             :   MHD_RESULT res;
      42             : 
      43           0 :   if (GNUNET_OK !=
      44           0 :       GNUNET_STRINGS_string_to_data (args[0],
      45             :                                      strlen (args[0]),
      46             :                                      &contract_pub,
      47             :                                      sizeof (contract_pub)))
      48             :   {
      49           0 :     GNUNET_break_op (0);
      50           0 :     return TALER_MHD_reply_with_error (rc->connection,
      51             :                                        MHD_HTTP_BAD_REQUEST,
      52             :                                        TALER_EC_EXCHANGE_CONTRACTS_INVALID_CONTRACT_PUB,
      53             :                                        args[0]);
      54             :   }
      55             : 
      56           0 :   qs = TEH_plugin->select_contract (TEH_plugin->cls,
      57             :                                     &contract_pub,
      58             :                                     &purse_pub,
      59             :                                     &econtract_sig,
      60             :                                     &econtract_size,
      61             :                                     &econtract);
      62           0 :   switch (qs)
      63             :   {
      64           0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      65           0 :     GNUNET_break (0);
      66           0 :     return TALER_MHD_reply_with_error (rc->connection,
      67             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      68             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      69             :                                        "select_contract");
      70           0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      71           0 :     GNUNET_break (0);
      72           0 :     return TALER_MHD_reply_with_error (rc->connection,
      73             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      74             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      75             :                                        "select_contract");
      76           0 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      77           0 :     return TALER_MHD_reply_with_error (rc->connection,
      78             :                                        MHD_HTTP_NOT_FOUND,
      79             :                                        TALER_EC_EXCHANGE_CONTRACTS_UNKNOWN,
      80             :                                        NULL);
      81           0 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
      82           0 :     break; /* handled below */
      83             :   }
      84           0 :   res = TALER_MHD_REPLY_JSON_PACK (
      85             :     rc->connection,
      86             :     MHD_HTTP_OK,
      87             :     GNUNET_JSON_pack_data_auto ("purse_pub",
      88             :                                 &purse_pub),
      89             :     GNUNET_JSON_pack_data_auto ("econtract_sig",
      90             :                                 &econtract_sig),
      91             :     GNUNET_JSON_pack_data_varsize ("econtract",
      92             :                                    econtract,
      93             :                                    econtract_size));
      94           0 :   GNUNET_free (econtract);
      95           0 :   return res;
      96             : }
      97             : 
      98             : 
      99             : /* end of taler-exchange-httpd_contract.c */

Generated by: LCOV version 1.14