donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit c46d51edeb856453d1b3ccdabcfe7fa5f9c490cc
parent d094616fc290711cb1316bb924262c179b840412
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Sat,  6 Jan 2024 16:52:45 +0100

added pg logic for get charities

Diffstat:
Asrc/donaudb/pg_get_charities.c | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_get_charities.h | 37+++++++++++++++++++++++++++++++++++++
2 files changed, 163 insertions(+), 0 deletions(-)

diff --git a/src/donaudb/pg_get_charities.c b/src/donaudb/pg_get_charities.c @@ -0,0 +1,126 @@ +/* + 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 CHARITYABILITY 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/> + */ +/** + * @file donaudb/pg_lookup_donation_unit_key.c + * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @author Johannes Casaburi + */ +#include "taler/platform.h" +#include "taler/taler_error_codes.h" +#include "taler/taler_dbevents.h" +#include "taler/taler_pq_lib.h" +#include "pg_lookup_charity.h" +#include "pg_helper.h" + + +/** + * Closure for #get_charities_cb(). + */ +struct GetCharitiesContext +{ + /** + * Function to call per result. + */ + DONAUDB_GetCharitiesCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Flag set to #GNUNET_OK as long as everything is fine. + */ + enum GNUNET_GenericReturnValue status; + +}; + + +/** + * Invoke the callback for each result. + * + * @param cls a `struct MissingWireContext *` + * @param result SQL result + * @param num_results number of rows in @a result + */ +static void +get_charities_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct GetCharitiesContext *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *charity_name; + char *charity_url; + + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("charity_name", + &charity_name), + GNUNET_PQ_result_spec_string ("charity_url", + &charity_url) + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->status = GNUNET_SYSERR; + return; + } + ctx->cb (ctx->cb_cls, + charity_name, + charity_url); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +DH_PG_get_charities (void *cls, + DONAUDB_GetCharitiesCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + struct GetWireAccountsContext ctx = { + .cb = cb, + .cb_cls = cb_cls, + .status = GNUNET_OK + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "get_charities", + "SELECT" + " charity_name" + ",charity_url" + " FROM charities"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "get_charities", + params, + &get_charities_cb, + &ctx); + if (GNUNET_OK != ctx.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/donaudb/pg_get_charities.h b/src/donaudb/pg_get_charities.h @@ -0,0 +1,37 @@ +/* + 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 CHARITYABILITY 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/> + */ +/** + * @file donaudb/pg_lookup_charity.h + * @brief implementation of the get_charities function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_GET_CHARITIES_H +#define PG_GET_CHARITIES_H + +/** + * Obtain information about the enabled wire accounts of the exchange. + * + * @param cls closure + * @param cb function to call on each account + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_get_charities (void *cls, + DONAUDB_GetCharitiesCallback cb, + void *cb_cls); + +#endif