LCOV - code coverage report
Current view: top level - bank-lib - fakebank_tbi.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 28 0
Test Date: 2026-01-12 22:36:41 Functions: 0.0 % 1 0

            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_tbi.c
      21              :  * @brief main entry point to the Taler Bank Integration (TBI) API implementation
      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 "fakebank.h"
      30              : #include "fakebank_tbi.h"
      31              : #include "fakebank_tbi_get_withdrawal_operation.h"
      32              : #include "fakebank_tbi_post_withdrawal_operation.h"
      33              : 
      34              : 
      35              : MHD_RESULT
      36            0 : TALER_FAKEBANK_tbi_main_ (struct TALER_FAKEBANK_Handle *h,
      37              :                           struct MHD_Connection *connection,
      38              :                           const char *url,
      39              :                           const char *method,
      40              :                           const char *upload_data,
      41              :                           size_t *upload_data_size,
      42              :                           void **con_cls)
      43              : {
      44            0 :   if (0 == strcasecmp (method,
      45              :                        MHD_HTTP_METHOD_HEAD))
      46            0 :     method = MHD_HTTP_METHOD_GET;
      47            0 :   if ( (0 == strcmp (url,
      48            0 :                      "/config")) &&
      49            0 :        (0 == strcasecmp (method,
      50              :                          MHD_HTTP_METHOD_GET)) )
      51              :   {
      52              :     struct TALER_Amount zero;
      53              : 
      54            0 :     GNUNET_assert (GNUNET_OK ==
      55              :                    TALER_amount_set_zero (h->currency,
      56              :                                           &zero));
      57            0 :     return TALER_MHD_REPLY_JSON_PACK (
      58              :       connection,
      59              :       MHD_HTTP_OK,
      60              :       GNUNET_JSON_pack_string ("version",
      61              :                                "1:0:1"),
      62              :       GNUNET_JSON_pack_string ("currency",
      63              :                                h->currency),
      64              :       GNUNET_JSON_pack_string ("implementation",
      65              :                                "urn:net:taler:specs:bank:fakebank"),
      66              :       GNUNET_JSON_pack_bool ("allow_conversion",
      67              :                              false),
      68              :       GNUNET_JSON_pack_bool ("allow_registrations",
      69              :                              true),
      70              :       GNUNET_JSON_pack_bool ("allow_deletions",
      71              :                              false),
      72              :       GNUNET_JSON_pack_bool ("allow_edit_name",
      73              :                              false),
      74              :       GNUNET_JSON_pack_bool ("allow_edit_cashout_payto_uri",
      75              :                              false),
      76              :       TALER_JSON_pack_amount ("default_debit_threshold",
      77              :                               &zero),
      78              :       GNUNET_JSON_pack_array_steal ("supported_tan_channels",
      79              :                                     json_array ()),
      80              :       GNUNET_JSON_pack_object_steal (
      81              :         "currency_specification",
      82              :         GNUNET_JSON_PACK (
      83              :           GNUNET_JSON_pack_string ("name",
      84              :                                    h->currency),
      85              :           GNUNET_JSON_pack_string ("currency",
      86              :                                    h->currency),
      87              :           GNUNET_JSON_pack_uint64 ("num_fractional_input_digits",
      88              :                                    2),
      89              :           GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits",
      90              :                                    2),
      91              :           GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits",
      92              :                                    2),
      93              :           GNUNET_JSON_pack_object_steal (
      94              :             "alt_unit_names",
      95              :             GNUNET_JSON_PACK (
      96              :               GNUNET_JSON_pack_string ("0",
      97              :                                        h->currency))),
      98              :           GNUNET_JSON_pack_string ("name",
      99              :                                    h->currency))),
     100              :       GNUNET_JSON_pack_string ("name",
     101              :                                "taler-bank-integration"));
     102              :   }
     103            0 :   if ( (0 == strncmp (url,
     104              :                       "/withdrawal-operation/",
     105            0 :                       strlen ("/withdrawal-operation/"))) &&
     106            0 :        (0 == strcasecmp (method,
     107              :                          MHD_HTTP_METHOD_GET)) )
     108              :   {
     109            0 :     const char *wopid = &url[strlen ("/withdrawal-operation/")];
     110              :     const char *lp_s
     111            0 :       = MHD_lookup_connection_value (connection,
     112              :                                      MHD_GET_ARGUMENT_KIND,
     113              :                                      "long_poll_ms");
     114            0 :     struct GNUNET_TIME_Relative lp = GNUNET_TIME_UNIT_ZERO;
     115              : 
     116            0 :     if (NULL != lp_s)
     117              :     {
     118              :       unsigned long long d;
     119              :       char dummy;
     120              : 
     121            0 :       if (1 != sscanf (lp_s,
     122              :                        "%llu%c",
     123              :                        &d,
     124              :                        &dummy))
     125              :       {
     126            0 :         GNUNET_break_op (0);
     127            0 :         return TALER_MHD_reply_with_error (connection,
     128              :                                            MHD_HTTP_BAD_REQUEST,
     129              :                                            TALER_EC_GENERIC_PARAMETER_MALFORMED,
     130              :                                            "long_poll_ms");
     131              :       }
     132            0 :       lp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
     133              :                                           d);
     134              :     }
     135            0 :     return TALER_FAKEBANK_tbi_get_withdrawal_operation_ (h,
     136              :                                                          connection,
     137              :                                                          wopid,
     138              :                                                          lp,
     139              :                                                          con_cls);
     140              : 
     141              :   }
     142            0 :   if ( (0 == strncmp (url,
     143              :                       "/withdrawal-operation/",
     144            0 :                       strlen ("/withdrawal-operation/"))) &&
     145            0 :        (0 == strcasecmp (method,
     146              :                          MHD_HTTP_METHOD_POST)) )
     147              :   {
     148            0 :     const char *wopid = &url[strlen ("/withdrawal-operation/")];
     149              : 
     150            0 :     return TALER_FAKEBANK_tbi_post_withdrawal (h,
     151              :                                                connection,
     152              :                                                wopid,
     153              :                                                upload_data,
     154              :                                                upload_data_size,
     155              :                                                con_cls);
     156              :   }
     157              : 
     158            0 :   TALER_LOG_ERROR ("Breaking URL: %s %s\n",
     159              :                    method,
     160              :                    url);
     161            0 :   GNUNET_break_op (0);
     162            0 :   return TALER_MHD_reply_with_error (
     163              :     connection,
     164              :     MHD_HTTP_NOT_FOUND,
     165              :     TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
     166              :     url);
     167              : }
        

Generated by: LCOV version 2.0-1