LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_management_partners.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 26 0.0 %
Date: 2025-06-22 12:09:43 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2023 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_management_partners.c
      18             :  * @brief Handle request to add exchange partner
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "taler/platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include <gnunet/gnunet_json_lib.h>
      24             : #include <jansson.h>
      25             : #include <microhttpd.h>
      26             : #include <pthread.h>
      27             : #include "taler/taler_json_lib.h"
      28             : #include "taler/taler_mhd_lib.h"
      29             : #include "taler/taler_signatures.h"
      30             : #include "taler-exchange-httpd_management.h"
      31             : #include "taler-exchange-httpd_responses.h"
      32             : 
      33             : 
      34             : MHD_RESULT
      35           0 : TEH_handler_management_partners (
      36             :   struct MHD_Connection *connection,
      37             :   const json_t *root)
      38             : {
      39             :   struct TALER_MasterPublicKeyP partner_pub;
      40             :   struct GNUNET_TIME_Timestamp start_date;
      41             :   struct GNUNET_TIME_Timestamp end_date;
      42             :   struct GNUNET_TIME_Relative wad_frequency;
      43             :   struct TALER_Amount wad_fee;
      44             :   const char *partner_base_url;
      45             :   struct TALER_MasterSignatureP master_sig;
      46             :   struct GNUNET_JSON_Specification spec[] = {
      47           0 :     GNUNET_JSON_spec_fixed_auto ("partner_pub",
      48             :                                  &partner_pub),
      49           0 :     GNUNET_JSON_spec_fixed_auto ("master_sig",
      50             :                                  &master_sig),
      51           0 :     TALER_JSON_spec_web_url ("partner_base_url",
      52             :                              &partner_base_url),
      53           0 :     TALER_JSON_spec_amount ("wad_fee",
      54             :                             TEH_currency,
      55             :                             &wad_fee),
      56           0 :     GNUNET_JSON_spec_timestamp ("start_date",
      57             :                                 &start_date),
      58           0 :     GNUNET_JSON_spec_timestamp ("end_date",
      59             :                                 &end_date),
      60           0 :     GNUNET_JSON_spec_relative_time ("wad_frequency",
      61             :                                     &wad_frequency),
      62           0 :     GNUNET_JSON_spec_end ()
      63             :   };
      64             : 
      65             :   {
      66             :     enum GNUNET_GenericReturnValue res;
      67             : 
      68           0 :     res = TALER_MHD_parse_json_data (connection,
      69             :                                      root,
      70             :                                      spec);
      71           0 :     if (GNUNET_SYSERR == res)
      72           0 :       return MHD_NO; /* hard failure */
      73           0 :     if (GNUNET_NO == res)
      74           0 :       return MHD_YES; /* failure */
      75             :   }
      76           0 :   TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
      77           0 :   if (GNUNET_OK !=
      78           0 :       TALER_exchange_offline_partner_details_verify (
      79             :         &partner_pub,
      80             :         start_date,
      81             :         end_date,
      82             :         wad_frequency,
      83             :         &wad_fee,
      84             :         partner_base_url,
      85             :         &TEH_master_public_key,
      86             :         &master_sig))
      87             :   {
      88           0 :     GNUNET_break_op (0);
      89           0 :     return TALER_MHD_reply_with_error (
      90             :       connection,
      91             :       MHD_HTTP_FORBIDDEN,
      92             :       TALER_EC_EXCHANGE_MANAGEMENT_ADD_PARTNER_SIGNATURE_INVALID,
      93             :       NULL);
      94             :   }
      95             :   {
      96             :     enum GNUNET_DB_QueryStatus qs;
      97             : 
      98           0 :     qs = TEH_plugin->insert_partner (TEH_plugin->cls,
      99             :                                      &partner_pub,
     100             :                                      start_date,
     101             :                                      end_date,
     102             :                                      wad_frequency,
     103             :                                      &wad_fee,
     104             :                                      partner_base_url,
     105             :                                      &master_sig);
     106           0 :     if (qs < 0)
     107             :     {
     108           0 :       GNUNET_break (0);
     109           0 :       return TALER_MHD_reply_with_error (connection,
     110             :                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
     111             :                                          TALER_EC_GENERIC_DB_STORE_FAILED,
     112             :                                          "add_partner");
     113             :     }
     114           0 :     if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     115             :     {
     116             :       /* FIXME-#7271: check for idempotency! */
     117           0 :       return TALER_MHD_reply_with_error (connection,
     118             :                                          MHD_HTTP_CONFLICT,
     119             :                                          TALER_EC_EXCHANGE_MANAGEMENT_ADD_PARTNER_DATA_CONFLICT,
     120             :                                          NULL);
     121             :     }
     122             :   }
     123           0 :   return TALER_MHD_reply_static (
     124             :     connection,
     125             :     MHD_HTTP_NO_CONTENT,
     126             :     NULL,
     127             :     NULL,
     128             :     0);
     129             : }
     130             : 
     131             : 
     132             : /* end of taler-exchange-httpd_management_partners.c */

Generated by: LCOV version 1.16