diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-17 13:05:29 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-17 13:05:29 +0100 |
commit | 11a9dc2b4fc731b9aff57316d6e2959ed6756c79 (patch) | |
tree | efffc758ad877b5ff32be8f0506933d17d33a61d /src/auditor/taler-auditor-httpd_exchanges.c | |
parent | 540b22ce1ca41e66574eb156678a7ff288403951 (diff) | |
download | exchange-11a9dc2b4fc731b9aff57316d6e2959ed6756c79.tar.xz |
simplify DB logic in auditor-httpd
Diffstat (limited to 'src/auditor/taler-auditor-httpd_exchanges.c')
-rw-r--r-- | src/auditor/taler-auditor-httpd_exchanges.c | 99 |
1 files changed, 30 insertions, 69 deletions
diff --git a/src/auditor/taler-auditor-httpd_exchanges.c b/src/auditor/taler-auditor-httpd_exchanges.c index 3c6bfe68f..e5442a051 100644 --- a/src/auditor/taler-auditor-httpd_exchanges.c +++ b/src/auditor/taler-auditor-httpd_exchanges.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018 Inria and GNUnet e.V. + Copyright (C) 2014-2020 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -27,29 +27,10 @@ #include "taler_json_lib.h" #include "taler_mhd_lib.h" #include "taler-auditor-httpd.h" -#include "taler-auditor-httpd_db.h" #include "taler-auditor-httpd_exchanges.h" /** - * Send confirmation of deposit-confirmation success to client. - * - * @param connection connection to the client - * @param ja array with information about exchanges - * @return MHD result code - */ -static int -reply_exchanges_success (struct MHD_Connection *connection, - json_t *ja) -{ - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "exchanges", ja); -} - - -/** * Add exchange information to the list. * * @param[in,out] cls a `json_t *` array to extend @@ -78,45 +59,6 @@ add_exchange (void *cls, /** - * Execute database transaction for /exchanges. Obtains the list. IF - * it returns a non-error code, the transaction logic MUST NOT queue a - * MHD response. IF it returns an hard error, the transaction logic - * MUST queue a MHD response and set @a mhd_ret. IF it returns the - * soft error code, the function MAY be called again to retry and MUST - * not queue a MHD response. - * - * @param cls[in,out] a `json_t *` with an array of exchanges to be created - * @param connection MHD request context - * @param session database session and transaction to use - * @param[out] mhd_ret set to MHD status on error - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -list_exchanges (void *cls, - struct MHD_Connection *connection, - struct TALER_AUDITORDB_Session *session, - int *mhd_ret) -{ - json_t *list = cls; - enum GNUNET_DB_QueryStatus qs; - - qs = TAH_plugin->list_exchanges (TAH_plugin->cls, - session, - &add_exchange, - list); - if (GNUNET_DB_STATUS_HARD_ERROR == qs) - { - TALER_LOG_WARNING ("Failed to handle /exchanges in database\n"); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_LIST_EXCHANGES_DB_ERROR, - "Could not fetch exchange list from database"); - } - return qs; -} - - -/** * Handle a "/exchanges" request. * * @param rh context of the handler @@ -133,19 +75,38 @@ TAH_EXCHANGES_handler (struct TAH_RequestHandler *rh, const char *upload_data, size_t *upload_data_size) { - int mhd_ret; json_t *ja; + struct TALER_AUDITORDB_Session *session; + enum GNUNET_DB_QueryStatus qs; + session = TAH_plugin->get_session (TAH_plugin->cls); + if (NULL == session) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_DB_SETUP_FAILED, + "failed to establish session with database"); + } ja = json_array (); - if (GNUNET_OK != - TAH_DB_run_transaction (connection, - "list exchanges", - &mhd_ret, - &list_exchanges, - (void *) ja)) - return mhd_ret; - return reply_exchanges_success (connection, - ja); + qs = TAH_plugin->list_exchanges (TAH_plugin->cls, + session, + &add_exchange, + ja); + if (0 > qs) + { + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + json_decref (ja); + TALER_LOG_WARNING ("Failed to handle /exchanges in database\n"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_LIST_EXCHANGES_DB_ERROR, + "Could not fetch exchange list from database"); + } + return TALER_MHD_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:o}", + "exchanges", ja); } |