LCOV - code coverage report
Current view: top level - bank-lib - fakebank_twg.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 58.8 % 34 20
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.c
      21              :  * @brief main entry point for the Taler Wire Gateway API
      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_twg.h"
      31              : #include "fakebank_twg_admin_add_incoming.h"
      32              : #include "fakebank_twg_admin_add_kycauth.h"
      33              : #include "fakebank_twg_get_root.h"
      34              : #include "fakebank_twg_get_transfers.h"
      35              : #include "fakebank_twg_history.h"
      36              : #include "fakebank_twg_transfer.h"
      37              : 
      38              : 
      39              : MHD_RESULT
      40          573 : TALER_FAKEBANK_twg_main_ (
      41              :   struct TALER_FAKEBANK_Handle *h,
      42              :   struct MHD_Connection *connection,
      43              :   const char *account,
      44              :   const char *url,
      45              :   const char *method,
      46              :   const char *upload_data,
      47              :   size_t *upload_data_size,
      48              :   void **con_cls)
      49              : {
      50          573 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      51              :               "Fakebank TWG, serving URL `%s' for account `%s'\n",
      52              :               url,
      53              :               account);
      54          573 :   if ( (0 == strcmp (url,
      55            0 :                      "/config")) &&
      56            0 :        (0 == strcasecmp (method,
      57              :                          MHD_HTTP_METHOD_GET)) )
      58              :   {
      59              :     /* GET /config */
      60            0 :     return TALER_MHD_REPLY_JSON_PACK (
      61              :       connection,
      62              :       MHD_HTTP_OK,
      63              :       GNUNET_JSON_pack_string ("version",
      64              :                                "3:0:3"),
      65              :       GNUNET_JSON_pack_string ("currency",
      66              :                                h->currency),
      67              :       GNUNET_JSON_pack_string ("implementation",
      68              :                                "urn:net:taler:specs:bank:fakebank"),
      69              :       GNUNET_JSON_pack_string ("name",
      70              :                                "taler-wire-gateway"));
      71              :   }
      72          573 :   if (0 == strcasecmp (method,
      73              :                        MHD_HTTP_METHOD_GET))
      74              :   {
      75          177 :     if ( (0 == strcmp (url,
      76          172 :                        "/history/incoming")) &&
      77              :          (NULL != account) )
      78          172 :       return TALER_FAKEBANK_twg_get_credit_history_ (h,
      79              :                                                      connection,
      80              :                                                      account,
      81              :                                                      con_cls);
      82            5 :     if ( (0 == strcmp (url,
      83            5 :                        "/history/outgoing")) &&
      84              :          (NULL != account) )
      85            5 :       return TALER_FAKEBANK_twg_get_debit_history_ (h,
      86              :                                                     connection,
      87              :                                                     account,
      88              :                                                     con_cls);
      89            0 :     if (0 == strcmp (url,
      90              :                      "/"))
      91            0 :       return TALER_FAKEBANK_twg_get_root_ (h,
      92              :                                            connection);
      93            0 :     if ( (0 == strcmp (url,
      94            0 :                        "/transfers")) &&
      95              :          (NULL != account) )
      96            0 :       return TALER_FAKEBANK_twg_get_transfers_ (h,
      97              :                                                 connection,
      98              :                                                 account,
      99              :                                                 con_cls);
     100            0 :     if ( (0 == strncmp (url,
     101              :                         "/transfers/",
     102            0 :                         strlen ("/transfers/"))) &&
     103              :          (NULL != account) )
     104            0 :       return TALER_FAKEBANK_twg_get_transfers_id_ (
     105              :         h,
     106              :         connection,
     107              :         account,
     108              :         &url[strlen ("/transfers/")],
     109              :         con_cls);
     110              :   }
     111          396 :   else if (0 == strcasecmp (method,
     112              :                             MHD_HTTP_METHOD_POST))
     113              :   {
     114          396 :     if ( (0 == strcmp (url,
     115          183 :                        "/admin/add-incoming")) &&
     116              :          (NULL != account) )
     117          183 :       return TALER_FAKEBANK_twg_admin_add_incoming_ (h,
     118              :                                                      connection,
     119              :                                                      account,
     120              :                                                      upload_data,
     121              :                                                      upload_data_size,
     122              :                                                      con_cls);
     123          213 :     if ( (0 == strcmp (url,
     124           48 :                        "/admin/add-kycauth")) &&
     125              :          (NULL != account) )
     126           48 :       return TALER_FAKEBANK_twg_admin_add_kycauth_ (h,
     127              :                                                     connection,
     128              :                                                     account,
     129              :                                                     upload_data,
     130              :                                                     upload_data_size,
     131              :                                                     con_cls);
     132          165 :     if ( (0 == strcmp (url,
     133          165 :                        "/transfer")) &&
     134              :          (NULL != account) )
     135          165 :       return TALER_FAKEBANK_handle_transfer_ (h,
     136              :                                               connection,
     137              :                                               account,
     138              :                                               upload_data,
     139              :                                               upload_data_size,
     140              :                                               con_cls);
     141              :   }
     142              :   /* Unexpected URL path, just close the connection. */
     143            0 :   TALER_LOG_ERROR ("Breaking URL: %s %s\n",
     144              :                    method,
     145              :                    url);
     146            0 :   GNUNET_break_op (0);
     147            0 :   return TALER_MHD_reply_with_error (
     148              :     connection,
     149              :     MHD_HTTP_NOT_FOUND,
     150              :     TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
     151              :     url);
     152              : }
        

Generated by: LCOV version 2.0-1