LCOV - code coverage report
Current view: top level - bank-lib - fakebank_twg_admin_add_incoming.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 66.0 % 50 33
Test Date: 2026-01-12 22:36:41 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2016-2024 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or
       6              :   modify it under the terms of the GNU General Public License
       7              :   as published by the Free Software Foundation; either version 3,
       8              :   or (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful,
      11              :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file bank-lib/fakebank_twg_admin_add_incoming.c
      21              :  * @brief library that fakes being a Taler bank for testcases
      22              :  * @author Christian Grothoff <christian@grothoff.org>
      23              :  */
      24              : #include "taler/platform.h"
      25              : #include "taler/taler_fakebank_lib.h"
      26              : #include "taler/taler_bank_service.h"
      27              : #include "taler/taler_mhd_lib.h"
      28              : #include <gnunet/gnunet_mhd_compat.h>
      29              : #include <gnunet/gnunet_mhd_lib.h>
      30              : #include "fakebank.h"
      31              : #include "fakebank_common_make_admin_transfer.h"
      32              : #include "fakebank_twg_admin_add_incoming.h"
      33              : 
      34              : MHD_RESULT
      35          183 : TALER_FAKEBANK_twg_admin_add_incoming_ (
      36              :   struct TALER_FAKEBANK_Handle *h,
      37              :   struct MHD_Connection *connection,
      38              :   const char *account,
      39              :   const char *upload_data,
      40              :   size_t *upload_data_size,
      41              :   void **con_cls)
      42              : {
      43          183 :   struct ConnectionContext *cc = *con_cls;
      44              :   enum GNUNET_MHD_PostResult pr;
      45              :   json_t *json;
      46              :   uint64_t row_id;
      47              :   struct GNUNET_TIME_Timestamp timestamp;
      48              : 
      49          183 :   if (NULL == cc)
      50              :   {
      51           61 :     cc = GNUNET_new (struct ConnectionContext);
      52           61 :     cc->ctx_cleaner = &GNUNET_MHD_post_parser_cleanup;
      53           61 :     *con_cls = cc;
      54              :   }
      55          183 :   pr = GNUNET_MHD_post_parser (REQUEST_BUFFER_MAX,
      56              :                                connection,
      57              :                                &cc->ctx,
      58              :                                upload_data,
      59              :                                upload_data_size,
      60              :                                &json);
      61          183 :   switch (pr)
      62              :   {
      63            0 :   case GNUNET_MHD_PR_OUT_OF_MEMORY:
      64            0 :     GNUNET_break (0);
      65            0 :     return MHD_NO;
      66          122 :   case GNUNET_MHD_PR_CONTINUE:
      67          122 :     return MHD_YES;
      68            0 :   case GNUNET_MHD_PR_REQUEST_TOO_LARGE:
      69            0 :     GNUNET_break (0);
      70            0 :     return MHD_NO;
      71            0 :   case GNUNET_MHD_PR_JSON_INVALID:
      72            0 :     GNUNET_break (0);
      73            0 :     return MHD_NO;
      74           61 :   case GNUNET_MHD_PR_SUCCESS:
      75           61 :     break;
      76              :   }
      77              :   {
      78              :     struct TALER_FullPayto debit_account;
      79              :     struct TALER_Amount amount;
      80              :     struct TALER_ReservePublicKeyP reserve_pub;
      81              :     char *debit;
      82              :     enum GNUNET_GenericReturnValue ret;
      83              :     struct GNUNET_JSON_Specification spec[] = {
      84           61 :       GNUNET_JSON_spec_fixed_auto ("reserve_pub",
      85              :                                    &reserve_pub),
      86           61 :       TALER_JSON_spec_full_payto_uri ("debit_account",
      87              :                                       &debit_account),
      88           61 :       TALER_JSON_spec_amount ("amount",
      89           61 :                               h->currency,
      90              :                               &amount),
      91           61 :       GNUNET_JSON_spec_end ()
      92              :     };
      93              : 
      94           61 :     if (GNUNET_OK !=
      95           61 :         (ret = TALER_MHD_parse_json_data (connection,
      96              :                                           json,
      97              :                                           spec)))
      98              :     {
      99            0 :       GNUNET_break_op (0);
     100            0 :       json_decref (json);
     101            2 :       return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
     102              :     }
     103           61 :     if (0 != strcasecmp (amount.currency,
     104           61 :                          h->currency))
     105              :     {
     106            0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     107              :                   "Currency `%s' does not match our configuration\n",
     108              :                   amount.currency);
     109            0 :       json_decref (json);
     110            0 :       return TALER_MHD_reply_with_error (
     111              :         connection,
     112              :         MHD_HTTP_CONFLICT,
     113              :         TALER_EC_GENERIC_CURRENCY_MISMATCH,
     114              :         NULL);
     115              :     }
     116           61 :     debit = TALER_xtalerbank_account_from_payto (debit_account);
     117           61 :     if (NULL == debit)
     118              :     {
     119            0 :       GNUNET_break_op (0);
     120            0 :       return TALER_MHD_reply_with_error (
     121              :         connection,
     122              :         MHD_HTTP_BAD_REQUEST,
     123              :         TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
     124            0 :         debit_account.full_payto);
     125              :     }
     126           61 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     127              :                 "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s\n",
     128              :                 debit,
     129              :                 account,
     130              :                 TALER_B2S (&reserve_pub),
     131              :                 TALER_amount2s (&amount));
     132           61 :     ret = TALER_FAKEBANK_make_admin_transfer_ (h,
     133              :                                                debit,
     134              :                                                account,
     135              :                                                &amount,
     136              :                                                &reserve_pub,
     137              :                                                &row_id,
     138              :                                                &timestamp);
     139           61 :     GNUNET_free (debit);
     140           61 :     if (GNUNET_OK != ret)
     141              :     {
     142            2 :       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     143              :                   "Reserve public key not unique\n");
     144            2 :       json_decref (json);
     145            2 :       return TALER_MHD_reply_with_error (
     146              :         connection,
     147              :         MHD_HTTP_CONFLICT,
     148              :         TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
     149              :         NULL);
     150              :     }
     151              :   }
     152           59 :   json_decref (json);
     153              : 
     154              :   /* Finally build response object */
     155           59 :   return TALER_MHD_REPLY_JSON_PACK (connection,
     156              :                                     MHD_HTTP_OK,
     157              :                                     GNUNET_JSON_pack_uint64 ("row_id",
     158              :                                                              row_id),
     159              :                                     GNUNET_JSON_pack_timestamp ("timestamp",
     160              :                                                                 timestamp));
     161              : }
        

Generated by: LCOV version 2.0-1