aboutsummaryrefslogtreecommitdiff
path: root/src/bank-lib/fakebank_bank.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bank-lib/fakebank_bank.c')
-rw-r--r--src/bank-lib/fakebank_bank.c501
1 files changed, 388 insertions, 113 deletions
diff --git a/src/bank-lib/fakebank_bank.c b/src/bank-lib/fakebank_bank.c
index ede148a41..c55e9efc8 100644
--- a/src/bank-lib/fakebank_bank.c
+++ b/src/bank-lib/fakebank_bank.c
@@ -28,6 +28,8 @@
#include <gnunet/gnunet_mhd_compat.h>
#include "fakebank.h"
#include "fakebank_bank.h"
+#include "fakebank_tbr.h"
+#include "fakebank_twg.h"
#include "fakebank_bank_get_accounts.h"
#include "fakebank_bank_get_accounts_withdrawals.h"
#include "fakebank_bank_get_root.h"
@@ -50,11 +52,23 @@ TALER_FAKEBANK_bank_main_ (
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_HEAD))
method = MHD_HTTP_METHOD_GET;
+
+ if ( (0 == strcmp (url,
+ "/")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET / */
+ return TALER_FAKEBANK_bank_get_root_ (h,
+ connection);
+ }
+
if ( (0 == strcmp (url,
"/config")) &&
(0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) )
{
+ /* GET /config */
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
@@ -63,162 +77,423 @@ TALER_FAKEBANK_bank_main_ (
GNUNET_JSON_pack_string ("currency",
h->currency),
GNUNET_JSON_pack_string ("name",
- "taler-bank-access"));
+ "libeufin-bank" /* FIXME: spec!? */));
}
+
if ( (0 == strcmp (url,
"/public-accounts")) &&
(0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) )
{
+ /* GET /public-accounts */
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_array_steal ("public_accounts",
json_array ()));
}
- if ( (0 == strncmp (url,
- "/accounts/",
- strlen ("/accounts/"))) &&
+
+ /* account registration API */
+ if ( (0 == strcmp (url,
+ "/accounts")) &&
(0 == strcasecmp (method,
MHD_HTTP_METHOD_POST)) )
{
+ /* POST /accounts */
+ return TALER_FAKEBANK_bank_testing_register_ (h,
+ connection,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ }
+
+ if ( (0 == strcmp (url,
+ "/accounts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /accounts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (0 == strcmp (url,
+ "/cashout-rate")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /cashout-rate */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (0 == strcmp (url,
+ "/cashouts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /cashouts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+
+ if (0 == strncmp (url,
+ "/accounts/",
+ strlen ("/accounts/")))
+ {
const char *acc_name = &url[strlen ("/accounts/")];
const char *end_acc = strchr (acc_name,
'/');
- char *acc;
- MHD_RESULT ret;
- if ( (NULL == end_acc) ||
- (0 != strncmp (end_acc,
- "/withdrawals",
- strlen ("/withdrawals"))) )
+ if ( (NULL != end_acc) &&
+ (0 == strncmp (end_acc,
+ "/taler-wire-gateway/",
+ strlen ("/taler-wire-gateway/"))) )
+ {
+ /* $METHOD /accounts/$ACCOUNT/taler-wire-gateway/ */
+ char *acc;
+ MHD_RESULT ret;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ end_acc += strlen ("/taler-wire-gateway");
+ ret = TALER_FAKEBANK_twg_main_ (h,
+ connection,
+ acc,
+ end_acc,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (acc);
+ return ret;
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strncmp (end_acc,
+ "/taler-revenue/",
+ strlen ("/taler-revenue/"))) )
+ {
+ /* $METHOD /accounts/$ACCOUNT/taler-revenue/ */
+ char *acc;
+ MHD_RESULT ret;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ end_acc += strlen ("/taler-revenue");
+ ret = TALER_FAKEBANK_tbr_main_ (h,
+ connection,
+ acc,
+ end_acc,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (acc);
+ return ret;
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
{
+ /* GET /accounts/$ACCOUNT */
+ return TALER_FAKEBANK_bank_get_accounts_ (h,
+ connection,
+ acc_name);
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_PATCH)) )
+ {
+ /* PATCH /accounts/$USERNAME */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_DELETE)) )
+ {
+ /* DELETE /accounts/$USERNAME */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcmp ("/auth",
+ end_acc)) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_PATCH)) )
+ {
+ /* PATCH /accounts/$USERNAME/auth */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /accounts/$ACCOUNT/+ */
+
+ if (0 == strcmp (end_acc,
+ "/transactions"))
+ {
+ /* GET /accounts/$USERNAME/transactions */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/transactions/",
+ strlen ("/transactions/")))
+ {
+ /* GET /accounts/$USERNAME/transactions/$TID */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strcmp (end_acc,
+ "/withdrawals"))
+ {
+ /* GET /accounts/$USERNAME/withdrawals */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/withdrawals/",
+ strlen ("/withdrawals/")))
+ {
+ /* GET /accounts/$ACCOUNT/withdrawals/$WID */
+ const char *wid;
+ char *acc;
+ MHD_RESULT ret;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ wid = &end_acc[strlen ("/withdrawals/")];
+ ret = TALER_FAKEBANK_bank_get_accounts_withdrawals_ (h,
+ connection,
+ acc,
+ wid);
+ GNUNET_free (acc);
+ return ret;
+ }
+ if (0 == strcmp (end_acc,
+ "/cashouts"))
+ {
+ /* GET /accounts/$USERNAME/cashouts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/cashouts/",
+ strlen ("/cashouts/")))
+ {
+ /* GET /accounts/$USERNAME/cashouts/$CID */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
acc_name);
}
- acc = GNUNET_strndup (acc_name,
- end_acc - acc_name);
- end_acc += strlen ("/withdrawals");
- if ('/' == *end_acc)
+
+ if ( (NULL != end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST)) )
{
- const char *wid = end_acc + 1;
- const char *opid = strchr (wid,
- '/');
- char *wi;
-
- if ( (NULL == opid) ||
- ( (0 != strcmp (opid,
- "/abort")) &&
- (0 != strcmp (opid,
- "/confirm")) ) )
+ /* POST /accounts/$ACCOUNT/+ */
+ char *acc;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ if (0 == strcmp (end_acc,
+ "/cashouts"))
{
- GNUNET_break_op (0);
+ /* POST /accounts/$USERNAME/cashouts */
+ GNUNET_break (0); /* not implemented */
GNUNET_free (acc);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
- acc_name);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/cashouts/",
+ strlen ("/cashouts/")))
+ {
+ /* POST /accounts/$USERNAME/cashouts/+ */
+ const char *cid = end_acc + strlen ("/cashouts/");
+ const char *opid = strchr (cid,
+ '/');
+ char *ci;
+
+ if (NULL == opid)
+ {
+ /* POST /accounts/$ACCOUNT/cashouts/$CID (not defined) */
+ GNUNET_break_op (0);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ acc_name);
+ }
+ ci = GNUNET_strndup (cid,
+ opid - cid);
+ if (0 == strcmp (opid,
+ "/abort"))
+ {
+ GNUNET_break (0); /* not implemented */
+ GNUNET_free (ci);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strcmp (opid,
+ "/confirm"))
+ {
+ GNUNET_break (0); /* not implemented */
+ GNUNET_free (ci);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
}
- wi = GNUNET_strndup (wid,
- opid - wid);
- if (0 == strcmp (opid,
- "/abort"))
+
+ if (0 == strcmp (end_acc,
+ "/withdrawals"))
{
- ret = TALER_FAKEBANK_bank_withdrawals_abort_ (h,
- connection,
- acc,
- wi);
- GNUNET_free (wi);
+ /* POST /accounts/$ACCOUNT/withdrawals */
+ MHD_RESULT ret;
+
+ ret = TALER_FAKEBANK_bank_post_account_withdrawals_ (
+ h,
+ connection,
+ acc,
+ upload_data,
+ upload_data_size,
+ con_cls);
GNUNET_free (acc);
return ret;
}
- if (0 == strcmp (opid,
- "/confirm"))
+
+ if (0 == strncmp (end_acc,
+ "/withdrawals/",
+ strlen ("/withdrawals/")))
{
- ret = TALER_FAKEBANK_bank_withdrawals_confirm_ (h,
+ /* POST /accounts/$ACCOUNT/withdrawals/$WID* */
+ const char *wid = end_acc + strlen ("/withdrawals/");
+ const char *opid = strchr (wid,
+ '/');
+ char *wi;
+
+ if (NULL == opid)
+ {
+ /* POST /accounts/$ACCOUNT/withdrawals/$WID (not defined) */
+ GNUNET_break_op (0);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ acc_name);
+ }
+ wi = GNUNET_strndup (wid,
+ opid - wid);
+ if (0 == strcmp (opid,
+ "/abort"))
+ {
+ /* POST /accounts/$ACCOUNT/withdrawals/$WID/abort */
+ MHD_RESULT ret;
+
+ ret = TALER_FAKEBANK_bank_withdrawals_abort_ (h,
connection,
acc,
wi);
- GNUNET_free (wi);
- GNUNET_free (acc);
- return ret;
- }
- GNUNET_assert (0);
- }
- ret = TALER_FAKEBANK_bank_post_account_withdrawals_ (
- h,
- connection,
- acc,
- upload_data,
- upload_data_size,
- con_cls);
- GNUNET_free (acc);
- return ret;
- }
-
- if ( (0 == strncmp (url,
- "/accounts/",
- strlen ("/accounts/"))) &&
- (0 == strcasecmp (method,
- MHD_HTTP_METHOD_GET)) )
- {
- const char *acc_name = &url[strlen ("/accounts/")];
- const char *end_acc = strchr (acc_name,
- '/');
- const char *wid;
- char *acc;
- MHD_RESULT ret;
+ GNUNET_free (wi);
+ GNUNET_free (acc);
+ return ret;
+ }
+ if (0 == strcmp (opid,
+ "/confirm"))
+ {
+ /* POST /accounts/$ACCOUNT/withdrawals/$WID/confirm */
+ MHD_RESULT ret;
- if (NULL == end_acc)
- {
- return TALER_FAKEBANK_bank_get_accounts_ (h,
- connection,
- acc_name);
- }
- if (0 != strncmp (end_acc,
- "/withdrawals/",
- strlen ("/withdrawals/")))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
- acc_name);
+ ret = TALER_FAKEBANK_bank_withdrawals_confirm_ (h,
+ connection,
+ acc,
+ wi);
+ GNUNET_free (wi);
+ GNUNET_free (acc);
+ return ret;
+ }
+ }
}
- acc = GNUNET_strndup (acc_name,
- end_acc - acc_name);
- wid = &end_acc[strlen ("/withdrawals/")];
- ret = TALER_FAKEBANK_bank_get_accounts_withdrawals_ (h,
- connection,
- acc,
- wid);
- GNUNET_free (acc);
- return ret;
}
- /* FIXME: implement transactions API: 1.12.2 */
- /* registration API */
- if ( (0 == strcmp (url,
- "/testing/register")) &&
- (0 == strcasecmp (method,
- MHD_HTTP_METHOD_POST)) )
- {
- return TALER_FAKEBANK_bank_testing_register_ (h,
- connection,
- upload_data,
- upload_data_size,
- con_cls);
- }
+ GNUNET_break_op (0);
TALER_LOG_ERROR ("Breaking URL: %s %s\n",
method,
url);
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
- url);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
}