exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

fakebank_twg.c (5678B)


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