diff options
author | Cedric Zwahlen <cedric.zwahlen@students.bfh.ch> | 2024-04-01 03:22:07 +0200 |
---|---|---|
committer | Cedric Zwahlen <cedric.zwahlen@students.bfh.ch> | 2024-04-19 20:47:30 +0200 |
commit | b657e22d470f53dd9a876bc8580a0f38b91fb9b8 (patch) | |
tree | 1deda9ff91c51b0d175b6a889ab646319e227585 | |
parent | 25431a7d505b6c5aadc2e949ec17d1b760175d9e (diff) | |
download | exchange-b657e22d470f53dd9a876bc8580a0f38b91fb9b8.tar.gz exchange-b657e22d470f53dd9a876bc8580a0f38b91fb9b8.tar.bz2 exchange-b657e22d470f53dd9a876bc8580a0f38b91fb9b8.zip |
Add CRUD
61 files changed, 5762 insertions, 173 deletions
diff --git a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c index 1fcf3c6b3..fa914daf7 100644 --- a/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c +++ b/src/auditor/taler-auditor-httpd_amount-arithmetic-inconsistency-del.c @@ -15,9 +15,16 @@ TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_delete (struct MHD_RESULT res; enum GNUNET_DB_QueryStatus qs; - // TODO: check for null first - uint64_t row_id = atoi (args[1]); + uint64_t row_id; + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); if (GNUNET_SYSERR == TAH_plugin->preflight (TAH_plugin->cls)) diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-del.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-del.c index 7a3856fa0..042925ef2 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-del.c +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-del.c @@ -1,5 +1,81 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ #include "taler-auditor-httpd_bad-sig-losses-del.h" + + +MHD_RESULT +TAH_BAD_SIG_LOSSES_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_bad_sig_losses (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /bad-sig-losses/ %s", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "BAD_SIG_LOSSES_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-del.h b/src/auditor/taler-auditor-httpd_bad-sig-losses-del.h index fd1596754..18855c185 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-del.h +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-del.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ #ifndef SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_DEL_H #define SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_BAD_SIG_LOSSES_DELETE_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_BAD_SIG_LOSSES_DELETE_done (void); + +/** + * Handle a "/bad-sig-losses" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] connection_cls the connection's closure (can be updated) + * @param upload_data upload data + * @param[in,out] upload_data_size number of bytes (left) in @a upload_data + * @return MHD result code + */ +MHD_RESULT +TAH_BAD_SIG_LOSSES_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_DEL_H diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c index 29bdb7252..eca1d92cf 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c @@ -1,5 +1,169 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_bad-sig-losses-get.h" + +/** +* Add bad-sig-losses to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +add_bad_sig_losses (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_BadSigLosses + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + GNUNET_JSON_pack_string ("operation", dc->operation), + TALER_JSON_pack_amount ("loss", &dc->loss), + GNUNET_JSON_pack_data_auto ("operation_specific_pub", + dc->operation_specific_pub), + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_BAD_SIG_LOSSES_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_bad_sig_losses ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_bad_sig_losses, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /bad-sig-losses\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "bad-sig-losses"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("bad-sig-losses", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.h b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.h index f61b7fe7a..ce630c4ec 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.h +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_GET_H #define SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_BAD_SIG_LOSSES_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_BAD_SIG_LOSSES_GET_done (void); + +/** +* Handle a "/bad-sig-losses" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_BAD_SIG_LOSSES_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_GET_H diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-put.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-put.c index 13132514c..e43457e58 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-put.c +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-put.c @@ -1,5 +1,159 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_bad-sig-losses-put.h" + +/** +* We have parsed the JSON information about the bad-sig-losses, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the bad-sig-losses +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_BadSigLosses *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_bad_sig_losses (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /bad-sig-losses in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "bad-sig-losses"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "BAD_SIG_LOSSES_OK")); +} + + +MHD_RESULT +TAH_BAD_SIG_LOSSES_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_BadSigLosses dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + GNUNET_JSON_spec_string ("operation", *dc->operation), + TALER_JSON_spec_amount ("loss", *dc->loss), + GNUNET_JSON_spec_fixed_auto ("operation_specific_pub", + *dc->operation_specific_pub), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_BAD_SIG_LOSSES_PUT_init (void) +{ + +} + + +void +TEAH_BAD_SIG_LOSSES_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-put.h b/src/auditor/taler-auditor-httpd_bad-sig-losses-put.h index 4bd233f75..59d8b5a60 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-put.h +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_PUT_H #define SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_BAD_SIG_LOSSES_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_BAD_SIG_LOSSES_PUT_done (void); + + +/** +* Handle a "/bad-sig-losses" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_BAD_SIG_LOSSES_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_BAD_SIG_LOSSES_PUT_H diff --git a/src/auditor/taler-auditor-httpd_closure-lags-del.c b/src/auditor/taler-auditor-httpd_closure-lags-del.c new file mode 100644 index 000000000..bf9e169c7 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_closure-lags-del.c @@ -0,0 +1,82 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "taler-auditor-httpd_closure-lags-del.h" + + +MHD_RESULT +TAH_CLOSURE_LAGS_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_closure_lags (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /closure-lags/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "CLOSURE_LAGS_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_closure-lags-del.h b/src/auditor/taler-auditor-httpd_closure-lags-del.h new file mode 100644 index 000000000..65d6eb17d --- /dev/null +++ b/src/auditor/taler-auditor-httpd_closure-lags-del.h @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#ifndef SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_DEL_H +#define SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_DEL_H + + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_CLOSURE_LAGS_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_CLOSURE_LAGS_DELETE_done (void); + +/** +* Handle a "/closure-lags" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_CLOSURE_LAGS_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + +#endif // SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_DEL_H diff --git a/src/auditor/taler-auditor-httpd_closure-lags-get.c b/src/auditor/taler-auditor-httpd_closure-lags-get.c index 5d82f8e82..4f7233114 100644 --- a/src/auditor/taler-auditor-httpd_closure-lags-get.c +++ b/src/auditor/taler-auditor-httpd_closure-lags-get.c @@ -1,5 +1,173 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_closure-lags-get.h" + +/** +* Add closure-lags to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +add_closure_lags (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_ClosureLags + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + // GNUNET_JSON_pack_... ("", &dc->), + // TALER_JSON_pack_... ("", &dc->), + + TALER_JSON_pack_amount ("amount", &dc->amount), + GNUNET_JSON_pack_int64 ("deadline", dc->deadline), + GNUNET_JSON_pack_string ("wtid", dc->wtid), + GNUNET_JSON_pack_string ("account", dc->account) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_CLOSURE_LAGS_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_closure_lags ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_closure_lags, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /closure-lags\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "closure-lags"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("closure-lags", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_closure-lags-get.h b/src/auditor/taler-auditor-httpd_closure-lags-get.h index b2e664412..0d9ae88f5 100644 --- a/src/auditor/taler-auditor-httpd_closure-lags-get.h +++ b/src/auditor/taler-auditor-httpd_closure-lags-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_GET_H #define SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_CLOSURE_LAGS_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_CLOSURE_LAGS_GET_done (void); + +/** +* Handle a "/closure-lags" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_CLOSURE_LAGS_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_GET_H diff --git a/src/auditor/taler-auditor-httpd_closure-lags-put.c b/src/auditor/taler-auditor-httpd_closure-lags-put.c new file mode 100644 index 000000000..aa28a2894 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_closure-lags-put.c @@ -0,0 +1,159 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" +#include "taler-auditor-httpd_closure-lags-put.h" + +/** +* We have parsed the JSON information about the closure-lags, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the closure-lags +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_ClosureLags *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_closure_lags (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /closure-lags in database"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "closure-lags"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "CLOSURE_LAGS_OK")); +} + + +MHD_RESULT +TAH_CLOSURE_LAGS_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_ClosureLags dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + TALER_JSON_spec_amount ("amount", *dc->amount), + GNUNET_JSON_spec_int64 ("deadline", dc->deadline), + GNUNET_JSON_spec_string ("wtid", dc->wtid), + GNUNET_JSON_spec_string ("account", *dc->account), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_CLOSURE_LAGS_PUT_init (void) +{ + +} + + +void +TEAH_CLOSURE_LAGS_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_closure-lags-put.h b/src/auditor/taler-auditor-httpd_closure-lags-put.h new file mode 100644 index 000000000..683aaed91 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_closure-lags-put.h @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#ifndef SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_PUT_H +#define SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_PUT_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_CLOSURE_LAGS_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_CLOSURE_LAGS_PUT_done (void); + + +/** +* Handle a "/closure-lags" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_CLOSURE_LAGS_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + +#endif // SRC_TALER_AUDITOR_HTTPD_CLOSURE_LAGS_PUT_H diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.c b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.c index 02fac61fb..5650a108e 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.c +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.c @@ -1,6 +1,94 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include \ "taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.h" + + +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection + * + connection, + void ** + connection_cls, + const char + * + upload_data, + size_t * + upload_data_size, + const char + *const + args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_denomination_key_validity_withdraw_inconsistency ( + TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /denomination-key-validity-withdraw-inconsistency/ %s", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.h b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.h index efa1fb4c9..2c266d266 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.h +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-del.h @@ -1,10 +1,69 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ #ifndef \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_DEL_H #define \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** + * Initialize subsystem. + */ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_DELETE_init (void); + +/** + * Shut down subsystem. + */ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_DELETE_done (void); + +/** + * Handle a "/denomination-key-validity-withdraw-inconsistency" request. Parses the JSON, and, if + * successful, checks the signatures and stores the result in the DB. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] connection_cls the connection's closure (can be updated) + * @param upload_data upload data + * @param[in,out] upload_data_size number of bytes (left) in @a upload_data + * @return MHD result code + */ +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection + * + connection, + void ** + connection_cls, + const char + * + upload_data, + size_t * + upload_data_size, + const char + *const + args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_DEL_H diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c index f48211e06..9b67ec6ea 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c @@ -1,6 +1,180 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include \ "taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h" + +/** +* Add denomination-key-validity-withdraw-inconsistency to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_denomination_key_validity_withdraw_inconsistency (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + TALER_JSON_pack_amount ("amount", &dc->amount), + GNUNET_JSON_pack_int64 ("deadline", dc->deadline), + GNUNET_JSON_pack_string ("wtid", dc->wtid), + GNUNET_JSON_pack_string ("account", dc->account) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection + * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char * + const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_denomination_key_validity_withdraw_inconsistency ( + TAH_plugin->cls, + row_id, + return_suppressed, + &process_denomination_key_validity_withdraw_inconsistency, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /denomination-key-validity-withdraw-inconsistency\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "denomination-key-validity-withdraw-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ( + "denomination-key-validity-withdraw-inconsistency", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h index 9d2cb3b1b..e33620390 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h @@ -1,10 +1,67 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_GET_H #define \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_GET_done (void); + +/** +* Handle a "/denomination-key-validity-withdraw-inconsistency" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection + * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char * + const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_GET_H diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.c b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.c index 6862f37e4..2fb367722 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.c +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.c @@ -1,6 +1,160 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include \ "taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.h" + +/** +* We have parsed the JSON information about the denomination-key-validity-withdraw-inconsistency, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the denomination-key-validity-withdraw-inconsistency +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_denomination_key_validity_withdraw_inconsistency ( + TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /denomination-key-validity-withdraw-inconsistency in database "); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "denomination-key-validity-withdraw-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_OK")); +} + + +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + TALER_JSON_spec_amount ("amount", &dc->amount), + GNUNET_JSON_spec_int64 ("deadline", dc->deadline), + GNUNET_JSON_spec_string ("wtid", dc->wtid), + GNUNET_JSON_spec_string ("account", dc->account), + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.h b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.h index cded0db20..6b7b00273 100644 --- a/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.h +++ b/src/auditor/taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-put.h @@ -1,10 +1,68 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_H #define \ SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_done (void); + + +/** +* Handle a "/denomination-key-validity-withdraw-inconsistency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_handler (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection + * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char * + const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_PUT_H diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-del.c b/src/auditor/taler-auditor-httpd_emergency-by-count-del.c index 83770f556..3c100c6be 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-del.c +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-del.c @@ -1,5 +1,82 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_emergency-by-count-del.h" + + +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_emergency_by_count (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /emergency-by-count/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "EMERGENCY_BY_COUNT_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-del.h b/src/auditor/taler-auditor-httpd_emergency-by-count-del.h index 6ab769e8f..ab50fa4bc 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-del.h +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_DEL_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_DELETE_done (void); + +/** +* Handle a "/emergency-by-count" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_DEL_H diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-get.c b/src/auditor/taler-auditor-httpd_emergency-by-count-get.c index 3d5949e46..7961aafff 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-get.c +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-get.c @@ -1,5 +1,177 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_emergency-by-count-get.h" + +/** +* Add emergency-by-count to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_emergency_by_count (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_EmergenciesByCount + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + // GNUNET_JSON_pack_... ("", &dc->), + // TALER_JSON_pack_... ("", &dc->), + + GNUNET_JSON_pack_data_auto ("denompub_h", *dc->denompub_h), + + GNUNET_JSON_pack_int64 ("num_issued", &dc->num_issued), + GNUNET_JSON_pack_int64 ("num_known", &dc->num_known), + TALER_JSON_pack_amount ("risk", &dc->risk), + GNUNET_JSON_pack_int64 ("start", &dc->start), + GNUNET_JSON_pack_int64 ("deposit_end",&dc->deposit_end), + TALER_JSON_pack_amount ("value", &dc->value) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_emergency_by_count ( + TAH_plugin->cls, + row_id, + return_suppressed, + &process_emergency_by_count, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /emergency-by-count\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "emergency-by-count"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("emergency-by-count", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-get.h b/src/auditor/taler-auditor-httpd_emergency-by-count-get.h index 54f9b6a24..d5de67c30 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-get.h +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_GET_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_GET_done (void); + +/** +* Handle a "/emergency-by-count" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_GET_H diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-put.c b/src/auditor/taler-auditor-httpd_emergency-by-count-put.c index ca9ffa7f8..e7a8ed125 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-put.c +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-put.c @@ -1,5 +1,161 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_emergency-by-count-put.h" + +/** +* We have parsed the JSON information about the emergency-by-count, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the emergency-by-count +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_EmergenciesByCount *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_emergency_by_count (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /emergency-by-count in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "emergency-by-count"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "EMERGENCY_BY_COUNT_OK")); +} + + +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_EmergencyByCount dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + GNUNET_JSON_spec_int64 ("num_issued", dc->num_issued), + GNUNET_JSON_spec_int64 ("num_known", dc->num_known), + TALER_JSON_spec_amount ("risk", dc->risk), + GNUNET_JSON_spec_int64 ("start", dc->start), + GNUNET_JSON_spec_int64 ("deposit_end",dc->deposit_end), + TALER_JSON_spec_amount ("value", dc->value), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_EMERGENCY_BY_COUNT_PUT_init (void) +{ + +} + + +void +TEAH_EMERGENCY_BY_COUNT_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_emergency-by-count-put.h b/src/auditor/taler-auditor-httpd_emergency-by-count-put.h index c99d95a9d..511c6cc50 100644 --- a/src/auditor/taler-auditor-httpd_emergency-by-count-put.h +++ b/src/auditor/taler-auditor-httpd_emergency-by-count-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_PUT_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_BY_COUNT_PUT_done (void); + + +/** +* Handle a "/emergency-by-count" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_BY_COUNT_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_BY_COUNT_PUT_H diff --git a/src/auditor/taler-auditor-httpd_emergency-del.c b/src/auditor/taler-auditor-httpd_emergency-del.c index 500124bec..8735b0d4e 100644 --- a/src/auditor/taler-auditor-httpd_emergency-del.c +++ b/src/auditor/taler-auditor-httpd_emergency-del.c @@ -1,5 +1,82 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_emergency-del.h" + + +MHD_RESULT +TAH_EMERGENCY_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_emergency (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /emergency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "EMERGENCY_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_emergency-del.h b/src/auditor/taler-auditor-httpd_emergency-del.h index 733ff183e..2fabf6777 100644 --- a/src/auditor/taler-auditor-httpd_emergency-del.h +++ b/src/auditor/taler-auditor-httpd_emergency-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_DEL_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_DELETE_done (void); + +/** +* Handle a "/emergency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_DEL_H diff --git a/src/auditor/taler-auditor-httpd_emergency-get.c b/src/auditor/taler-auditor-httpd_emergency-get.c index 7f82f89e0..63ffca758 100644 --- a/src/auditor/taler-auditor-httpd_emergency-get.c +++ b/src/auditor/taler-auditor-httpd_emergency-get.c @@ -1,5 +1,177 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_emergency-get.h" + +/** +* Add emergency to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_emergency (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_Emergency + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + // GNUNET_JSON_pack_... ("", &dc->), + // TALER_JSON_pack_... ("", &dc->), + + GNUNET_JSON_pack_data_auto ("denompub_h", *dc->denompub_h), + + TALER_JSON_pack_amount ("denom_risk", &dc->denom_risk), + TALER_JSON_pack_amount ("denom_loss", &dc->denom_loss), + + GNUNET_JSON_pack_int64 ("deposit_start", &dc->deposit_start), + GNUNET_JSON_pack_int64 ("deposit_end", &dc->deposit_end), + + TALER_JSON_pack_amount ("value", &dc->value) + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_emergency ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_emergency, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /emergency\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "emergency"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("emergency", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_emergency-get.h b/src/auditor/taler-auditor-httpd_emergency-get.h index 5b35d2bf1..7fc1e0553 100644 --- a/src/auditor/taler-auditor-httpd_emergency-get.h +++ b/src/auditor/taler-auditor-httpd_emergency-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_GET_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_GET_done (void); + +/** +* Handle a "/emergency" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_GET_H diff --git a/src/auditor/taler-auditor-httpd_emergency-put.c b/src/auditor/taler-auditor-httpd_emergency-put.c index 8da054f8b..b5ffb218b 100644 --- a/src/auditor/taler-auditor-httpd_emergency-put.c +++ b/src/auditor/taler-auditor-httpd_emergency-put.c @@ -1,5 +1,164 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_emergency-put.h" + +/** +* We have parsed the JSON information about the emergency, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the emergency +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_Emergency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_emergency (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /emergency in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "emergency"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "EMERGENCY_OK")); +} + + +MHD_RESULT +TAH_EMERGENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_Emergency dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + GNUNET_JSON_spec_fixed_auto ("denompub_h", dc->denompub_h), + + TALER_JSON_spec_amount ("denom_risk", &dc->denom_risk), + TALER_JSON_spec_amount ("denom_loss", &dc->denom_loss), + + GNUNET_JSON_spec_int64 ("deposit_start", dc->deposit_start), + GNUNET_JSON_spec_int64 ("deposit_end", dc->deposit_end), + + TALER_JSON_spec_amount ("value", &dc->value), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_EMERGENCY_PUT_init (void) +{ + +} + + +void +TEAH_EMERGENCY_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_emergency-put.h b/src/auditor/taler-auditor-httpd_emergency-put.h index 30087c4a5..db4ab77dc 100644 --- a/src/auditor/taler-auditor-httpd_emergency-put.h +++ b/src/auditor/taler-auditor-httpd_emergency-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_EMERGENCY_PUT_H #define SRC_TALER_AUDITOR_HTTPD_EMERGENCY_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_EMERGENCY_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_EMERGENCY_PUT_done (void); + + +/** +* Handle a "/emergency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_EMERGENCY_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_EMERGENCY_PUT_H diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.c b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.c index a780c4084..6dfb1b919 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.c +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.c @@ -1,5 +1,82 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_fee-time-inconsistency-del.h" + + +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_fee_time_inconsistency (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /fee-time-inconsistency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "FEE_TIME_INCONSISTENCY_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.h b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.h index b7fa90318..20d445502 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.h +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_DEL_H #define SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_DELETE_done (void); + +/** +* Handle a "/fee-time-inconsistency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_DEL_H diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c index 58bddc5b7..ea01dfd45 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.c @@ -1,5 +1,170 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_fee-time-inconsistency-get.h" + +/** +* Add fee-time-inconsistency to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_fee_time_inconsistency (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_FeeTimeInconsistency + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + GNUNET_JSON_pack_string ("type", dc->type), + GNUNET_JSON_pack_int64 ("time", &dc->time), + GNUNET_JSON_pack_string ("diagnostic", dc->diagnostic) + + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_fee_time_inconsistency ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_fee_time_inconsistency, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /fee-time-inconsistency\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "fee-time-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("fee-time-inconsistency", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.h b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.h index c00abd6c7..c1a05802d 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.h +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_GET_H #define SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_GET_done (void); + +/** +* Handle a "/fee-time-inconsistency" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_GET_H diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.c b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.c index 79fabb724..66ccc0ec5 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.c +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.c @@ -1,5 +1,158 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_fee-time-inconsistency-put.h" + +/** +* We have parsed the JSON information about the fee-time-inconsistency, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the fee-time-inconsistency +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_FeeTimeInconsistency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_fee_time_inconsistency (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /fee-time-inconsistency in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "fee-time-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "FEE_TIME_INCONSISTENCY_OK")); +} + + +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_FeeTimeInconsistency dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + GNUNET_JSON_spec_string ("type", &dc->type), + GNUNET_JSON_spec_int64 ("time", &dc->time), + GNUNET_JSON_spec_string ("diagnostic", &dc->diagnostic), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_FEE_TIME_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_FEE_TIME_INCONSISTENCY_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.h b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.h index b66d999f6..13be30d4e 100644 --- a/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.h +++ b/src/auditor/taler-auditor-httpd_fee-time-inconsistency-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_PUT_H #define SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_FEE_TIME_INCONSISTENCY_PUT_done (void); + + +/** +* Handle a "/fee-time-inconsistency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_FEE_TIME_INCONSISTENCY_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_FEE_TIME_INCONSISTENCY_PUT_H diff --git a/src/auditor/taler-auditor-httpd_progress-del.c b/src/auditor/taler-auditor-httpd_progress-del.c index 4a541acb2..bd374d8f6 100644 --- a/src/auditor/taler-auditor-httpd_progress-del.c +++ b/src/auditor/taler-auditor-httpd_progress-del.c @@ -1,5 +1,82 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_progress-del.h" + + +MHD_RESULT +TAH_PROGRESS_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_progress (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /progress/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "PROGRESS_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_progress-del.h b/src/auditor/taler-auditor-httpd_progress-del.h index 4edfd0c89..603a0d727 100644 --- a/src/auditor/taler-auditor-httpd_progress-del.h +++ b/src/auditor/taler-auditor-httpd_progress-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_DEL_H #define SRC_TALER_AUDITOR_HTTPD_PROGRESS_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PROGRESS_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PROGRESS_DELETE_done (void); + +/** +* Handle a "/progress" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PROGRESS_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_PROGRESS_DEL_H diff --git a/src/auditor/taler-auditor-httpd_progress-get.c b/src/auditor/taler-auditor-httpd_progress-get.c index 3a5aeab0c..d818264d2 100644 --- a/src/auditor/taler-auditor-httpd_progress-get.c +++ b/src/auditor/taler-auditor-httpd_progress-get.c @@ -1,5 +1,168 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_progress-get.h" + +/** +* Add progress to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_progress (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_Progress + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + GNUNET_JSON_pack_string ("progress_key", dc->progress_key), + GNUNET_JSON_pack_string ("progress_offset", dc->progress_offset) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PROGRESS_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_progress ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_progress, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /progress\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "progress"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("progress", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_progress-get.h b/src/auditor/taler-auditor-httpd_progress-get.h index 7ad144183..c2d9c47a4 100644 --- a/src/auditor/taler-auditor-httpd_progress-get.h +++ b/src/auditor/taler-auditor-httpd_progress-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H #define SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PROGRESS_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PROGRESS_GET_done (void); + +/** +* Handle a "/progress" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PROGRESS_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H diff --git a/src/auditor/taler-auditor-httpd_progress-put.c b/src/auditor/taler-auditor-httpd_progress-put.c index ba87dbd82..3bc3968b8 100644 --- a/src/auditor/taler-auditor-httpd_progress-put.c +++ b/src/auditor/taler-auditor-httpd_progress-put.c @@ -1,5 +1,157 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_progress-put.h" + +/** +* We have parsed the JSON information about the progress, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the progress +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_Progress *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_progress (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /progress in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "progress"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "PROGRESS_OK")); +} + + +MHD_RESULT +TAH_PROGRESS_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_Progress dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + GNUNET_JSON_spec_string ("progress_key", *dc->progress_key), + GNUNET_JSON_spec_string ("progress_offset", *dc->progress_offset), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_PROGRESS_PUT_init (void) +{ + +} + + +void +TEAH_PROGRESS_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_progress-put.h b/src/auditor/taler-auditor-httpd_progress-put.h index e80614a65..db0067f3a 100644 --- a/src/auditor/taler-auditor-httpd_progress-put.h +++ b/src/auditor/taler-auditor-httpd_progress-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H #define SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PROGRESS_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PROGRESS_PUT_done (void); + + +/** +* Handle a "/progress" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PROGRESS_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.c b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.c index 0841664ac..e03cd19fc 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.c +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.c @@ -1,5 +1,83 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_purse-not-closed-inconsistencies-del.h" + + +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_purse_not_closed_inconsistencies (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /purse-not-closed-inconsistencies/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "PURSE_NOT_CLOSED_INCONSISTENCIES_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.h b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.h index 11b04924d..a52cc42f7 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.h +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_DEL_H #define SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_DELETE_done (void); + +/** +* Handle a "/purse-not-closed-inconsistencies" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_DEL_H diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.c b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.c index f972c140c..a2c613711 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.c +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.c @@ -1,5 +1,173 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_purse-not-closed-inconsistencies-get.h" + +/** +* Add purse-not-closed-inconsistencies to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_purse_not_closed_inconsistencies (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_PurseNotClosedInconsistencies + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + // GNUNET_JSON_pack_... ("", &dc->), + + + GNUNET_JSON_pack_data_auto ("purse_pub", dc->purse_pub), + TALER_JSON_pack_amount ("amount", *dc->amount), + GNUNET_JSON_pack_int64 ("progress_offset", dc->expiration_date) + + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_purse_not_closed_inconsistencies ( + TAH_plugin->cls, + row_id, + return_suppressed, + &process_purse_not_closed_inconsistencies, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /purse-not-closed-inconsistencies\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "purse-not-closed-inconsistencies"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("purse-not-closed-inconsistencies", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.h b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.h index 6a8200257..dc90041ca 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.h +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_GET_H #define SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_GET_done (void); + +/** +* Handle a "/purse-not-closed-inconsistencies" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_GET_H diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.c b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.c index 32a7c54be..0b674f089 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.c +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.c @@ -1,5 +1,161 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_purse-not-closed-inconsistencies-put.h" + +/** +* We have parsed the JSON information about the purse-not-closed-inconsistencies, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the purse-not-closed-inconsistencies +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_purse_not_closed_inconsistencies (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /purse-not-closed-inconsistencies in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "purse-not-closed-inconsistencies"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "PURSE_NOT_CLOSED_INCONSISTENCIES_OK")); +} + + +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_PurseNotClosedInconsistencies dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + // GNUNET_JSON_spec_... ("", &dc.), + // TALER_JSON_spec_... ("", TAH_currency, &dc.), + + GNUNET_JSON_spec_fixed_auto ("purse_pub", dc->purse_pub), + TALER_JSON_spec_amount ("amount", *dc->amount), + GNUNET_JSON_spec_int64 ("progress_offset", dc->expiration_date), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_init (void) +{ + +} + + +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.h b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.h index 7497b817f..19d7fd7b2 100644 --- a/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.h +++ b/src/auditor/taler-auditor-httpd_purse-not-closed-inconsistencies-put.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_H #define SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_done (void); + + +/** +* Handle a "/purse-not-closed-inconsistencies" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_PURSE_NOT_CLOSED_INCONSISTENCIES_PUT_H diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-del.c b/src/auditor/taler-auditor-httpd_refreshes-hanging-del.c index c1e15563b..c103ed271 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-del.c +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-del.c @@ -1,5 +1,82 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_refreshes-hanging-del.h" + + +MHD_RESULT +TAH_REFRESHES_HANGING_handler_delete (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_refreshes_hanging (TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /refreshes-hanging/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "REFRESHES_HANGING_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-del.h b/src/auditor/taler-auditor-httpd_refreshes-hanging-del.h index 23194fab6..eba7b7342 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-del.h +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-del.h @@ -1,8 +1,58 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_DEL_H #define SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_REFRESHES_HANGING_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_REFRESHES_HANGING_DELETE_done (void); + +/** +* Handle a "/refreshes-hanging" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_REFRESHES_HANGING_handler_delete (struct + TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_DEL_H diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-get.c b/src/auditor/taler-auditor-httpd_refreshes-hanging-get.c index be1a7232a..d8549776d 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-get.c +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-get.c @@ -1,5 +1,169 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_refreshes-hanging-get.h" + +/** +* Add refreshes-hanging to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_refreshes_hanging (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_RefreshesHanging + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + + TALER_JSON_pack_amount ("amount", *dc->amount), + GNUNET_JSON_pack_data_auto ("coin_pub", dc->coin_pub) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_REFRESHES_HANGING_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_refreshes_hanging ( + TAH_plugin->cls, + row_id, + return_suppressed, + &add_refreshes_hanging, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /refreshes-hanging\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "refreshes-hanging"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("refreshes-hanging", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-get.h b/src/auditor/taler-auditor-httpd_refreshes-hanging-get.h index 4a60732ee..d01513a32 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-get.h +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-get.h @@ -1,8 +1,57 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_GET_H #define SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_REFRESHES_HANGING_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_REFRESHES_HANGING_GET_done (void); + +/** +* Handle a "/refreshes-hanging" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_REFRESHES_HANGING_handler_get (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_GET_H diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-put.c b/src/auditor/taler-auditor-httpd_refreshes-hanging-put.c index b83d355af..779f4cab8 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-put.c +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-put.c @@ -1,5 +1,159 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_refreshes-hanging-put.h" + +/** +* We have parsed the JSON information about the refreshes-hanging, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the refreshes-hanging +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_RefreshesHanging *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_refreshes_hanging (TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /refreshes-hanging in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "refreshes-hanging"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "REFRESHES_HANGING_OK")); +} + + +MHD_RESULT +TAH_REFRESHES_HANGING_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_RefreshesHanging dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + // GNUNET_JSON_spec_... ("", &dc.), + // TALER_JSON_spec_... ("", TAH_currency, &dc.), + + TALER_JSON_spec_amount ("amount", *dc->amount), + GNUNET_JSON_spec_fixed_auto ("coin_pub", dc->coin_pub), + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_REFRESHES_HANGING_PUT_init (void) +{ + +} + + +void +TEAH_REFRESHES_HANGING_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_refreshes-hanging-put.h b/src/auditor/taler-auditor-httpd_refreshes-hanging-put.h index 015111eb0..90fde33b1 100644 --- a/src/auditor/taler-auditor-httpd_refreshes-hanging-put.h +++ b/src/auditor/taler-auditor-httpd_refreshes-hanging-put.h @@ -1,8 +1,58 @@ -N// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_PUT_H #define SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_PUT_H +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_REFRESHES_HANGING_PUT_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_REFRESHES_HANGING_PUT_done (void); + + +/** +* Handle a "/refreshes-hanging" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_REFRESHES_HANGING_PUT_handler (struct TAH_RequestHandler *rh, + struct MHD_Connection * + connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_REFRESHES_HANGING_PUT_H diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.c b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.c index 1e823b26a..1f018cac9 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.c +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.c @@ -1,5 +1,90 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #include "taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h" + + +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char *const + args[]) +{ + + MHD_RESULT res; + enum GNUNET_DB_QueryStatus qs; + + uint64_t row_id; + + if (args[1] != NULL) + row_id = atoi (args[1]); + else + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + + // execute the transaction + qs = TAH_plugin->delete_reserve_balance_insufficient_inconsistency ( + TAH_plugin->cls, + row_id); + + if (0 > qs) + { + // goes in here if there was an error with the transaction + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to handle DELETE /reserve-balance-insufficient-inconsistency/ %s\n", + args[1]); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + // TODO: not the correct ec + TALER_EC_AUDITOR_DEPOSIT_CONFIRMATION_SIGNATURE_INVALID, + "exchange signature invalid"); + + } + + // on success? + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_NO_CONTENT, + GNUNET_JSON_pack_string ("status", + "RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_OK")); + + return res; +} diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h index 234770d8e..1af5150f1 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h @@ -1,8 +1,64 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_DEL_H #define SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_DEL_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_DELETE_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_DELETE_done (void); + +/** +* Handle a "/reserve-balance-insufficient-inconsistency" request. Parses the JSON, and, if +* successful, checks the signatures and stores the result in the DB. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_delete (struct + TAH_RequestHandler + *rh, + struct + MHD_Connection * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char *const + args[]); + #endif // SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_DEL_H diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c index 63fefae38..a6bcd5c3e 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c @@ -1,5 +1,180 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h" + +/** +* Add reserve-balance-insufficient-inconsistency to the list. +* +* @param[in,out] cls a `json_t *` array to extend +* @param serial_id location of the @a dc in the database +* @param dc struct of inconsistencies +* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating +*/ +static enum GNUNET_GenericReturnValue +process_reserve_balance_insufficient_inconsistency (void *cls, + uint64_t serial_id, + const struct + TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency + *dc) +{ + json_t *list = cls; + json_t *obj; + + obj = GNUNET_JSON_PACK ( + + // TODO: fill in + + // GNUNET_JSON_pack_... ("", &dc->), + // TALER_JSON_pack_... ("", &dc->), + + + GNUNET_JSON_pack_data_auto ("reserve_pub", dc->reserve_pub), + GNUNET_JSON_pack_bool ("inconsistency_gain", dc->inconsistency_gain), + TALER_JSON_pack_amount ("inconsistency_amount", &dc->inconsistency_amount) + + ); + GNUNET_break (0 == + json_array_append_new (list, + obj)); + + + return GNUNET_OK; +} + + +/** +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get (struct + TAH_RequestHandler * + rh, + struct + MHD_Connection * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char *const + args[]) +{ + json_t *ja; + enum GNUNET_DB_QueryStatus qs; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + ja = json_array (); + GNUNET_break (NULL != ja); + + uint64_t row_id = 0; + bool return_suppressed; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_uint64 ("row_id", + &row_id), + + GNUNET_JSON_spec_bool ("return_suppressed", + &return_suppressed), + + GNUNET_JSON_spec_end () + }; + + + // read the input json + json_t *json_in; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json_in); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json_in)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json_in, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json_in); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json_in); + return MHD_YES; /* failure */ + } + } + + qs = TAH_plugin->get_reserve_balance_insufficient_inconsistency ( + TAH_plugin->cls, + row_id, + return_suppressed, + &process_reserve_balance_insufficient_inconsistency, + ja); + + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ( + "Failed to handle GET /reserve-balance-insufficient-inconsistency\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "reserve-balance-insufficient-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("reserve-balance-insufficient-inconsistency", + ja)); +} diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h index d7970a754..b633a1cd0 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h @@ -1,8 +1,64 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + #ifndef SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H #define SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_done (void); + +/** +* Handle a "/reserve-balance-insufficient-inconsistency" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get (struct + TAH_RequestHandler * + rh, + struct + MHD_Connection * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char *const + args[]); + + #endif // SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.c b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.c index 4aa8d1d2f..b1de95eb1 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.c +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.c @@ -1,5 +1,162 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include <pthread.h> +#include "taler_json_lib.h" +#include "taler_mhd_lib.h" +#include "taler-auditor-httpd.h" #include "taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.h" + +/** +* We have parsed the JSON information about the reserve-balance-insufficient-inconsistency, do some +* basic sanity checks and then execute the +* transaction. +* +* @param connection the MHD connection to handle +* @param dc information about the reserve-balance-insufficient-inconsistency +* @return MHD result code +*/ +static MHD_RESULT +process_inconsistency ( + struct MHD_Connection *connection, + const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc) +{ + + enum GNUNET_DB_QueryStatus qs; + + if (GNUNET_SYSERR == + TAH_plugin->preflight (TAH_plugin->cls)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SETUP_FAILED, + NULL); + } + + /* execute transaction */ + qs = TAH_plugin->insert_reserve_balance_insufficient_inconsistency ( + TAH_plugin->cls, + dc); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + TALER_LOG_WARNING ( + "Failed to store /reserve-balance-insufficient-inconsistency in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "reserve-balance-insufficient-inconsistency"); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("status", + "RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_OK")); +} + + +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_handler ( + struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + + struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency dc; + + + struct GNUNET_JSON_Specification spec[] = { + + // TODO: fill in + + // GNUNET_JSON_spec_... ("", &dc.), + // TALER_JSON_spec_... ("", TAH_currency, &dc.), + + GNUNET_JSON_spec_data_auto ("reserve_pub", dc->reserve_pub), + GNUNET_JSON_spec_bool ("inconsistency_gain", dc->inconsistency_gain), + TALER_JSON_spec_amount ("inconsistency_amount", *dc->inconsistency_amount), + + + GNUNET_JSON_spec_end () + }; + + + json_t *json; + + (void) rh; + (void) connection_cls; + (void) upload_data; + (void) upload_data_size; + { + enum GNUNET_GenericReturnValue res; + + res = TALER_MHD_parse_post_json (connection, + connection_cls, + upload_data, + upload_data_size, + &json); + if (GNUNET_SYSERR == res) + return MHD_NO; + if ((GNUNET_NO == res) || + (NULL == json)) + return MHD_YES; + res = TALER_MHD_parse_json_data (connection, + json, + spec); + if (GNUNET_SYSERR == res) + { + json_decref (json); + return MHD_NO; /* hard failure */ + } + if (GNUNET_NO == res) + { + json_decref (json); + return MHD_YES; /* failure */ + } + } + + MHD_RESULT res; + + res = process_inconsistency (connection, &dc); + GNUNET_JSON_parse_free (spec); + + json_decref (json); + return res; + +} + + +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_init (void) +{ + +} + + +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_done (void) +{ + +} diff --git a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.h b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.h index 6d9f0a14a..b633a1cd0 100644 --- a/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.h +++ b/src/auditor/taler-auditor-httpd_reserve-balance-insufficient-inconsistency-put.h @@ -1,8 +1,64 @@ -// -// Created by parallels on 27/03/24. -// +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA -#ifndef SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_H -#define SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_H + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. -#endif // SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_PUT_H + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + + +#ifndef SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H +#define SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H + +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + +/** +* Initialize subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_init (void); + +/** +* Shut down subsystem. +*/ +void +TEAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_done (void); + +/** +* Handle a "/reserve-balance-insufficient-inconsistency" request. +* +* @param rh context of the handler +* @param connection the MHD connection to handle +* @param[in,out] connection_cls the connection's closure (can be updated) +* @param upload_data upload data +* @param[in,out] upload_data_size number of bytes (left) in @a upload_data +* @return MHD result code +*/ +MHD_RESULT +TAH_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_handler_get (struct + TAH_RequestHandler * + rh, + struct + MHD_Connection * + connection, + void ** + connection_cls, + const char * + upload_data, + size_t * + upload_data_size, + const char *const + args[]); + + +#endif // SRC_TALER_AUDITOR_HTTPD_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY_GET_H |