diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2022-03-05 13:36:50 +0100 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2022-03-05 13:39:01 +0100 |
commit | 8a906bf96c9c418dbd58727284eb5cfdd6fdff24 (patch) | |
tree | 5174716bc0a87ee985cd090b23e4ac2e048ceca7 /src | |
parent | 43f8ab6b48d6a51988c85fdc1bcd4f9d4f1a7a01 (diff) |
sync tables "extensions" and "extension_details" with auditor
Diffstat (limited to 'src')
-rw-r--r-- | src/auditor/taler-auditor-sync.c | 2 | ||||
-rw-r--r-- | src/exchangedb/irbt_callbacks.c | 51 | ||||
-rw-r--r-- | src/exchangedb/lrbt_callbacks.c | 95 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 53 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 15 |
5 files changed, 215 insertions, 1 deletions
diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c index 4b9595c6c..91b3b0817 100644 --- a/src/auditor/taler-auditor-sync.c +++ b/src/auditor/taler-auditor-sync.c @@ -111,6 +111,8 @@ static struct Table tables[] = { { .rt = TALER_EXCHANGEDB_RT_WIRE_FEE}, { .rt = TALER_EXCHANGEDB_RT_RECOUP}, { .rt = TALER_EXCHANGEDB_RT_RECOUP_REFRESH }, + { .rt = TALER_EXCHANGEDB_RT_EXTENSIONS}, + { .rt = TALER_EXCHANGEDB_RT_EXTENSION_DETAILS }, { .end = true } }; diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c index 012f8df26..deab3cfca 100644 --- a/src/exchangedb/irbt_callbacks.c +++ b/src/exchangedb/irbt_callbacks.c @@ -702,4 +702,55 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure *pg, } +/** + * Function called with extensions records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_extensions (struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&td->serial), + GNUNET_PQ_query_param_string (td->details.extensions.name), + NULL == td->details.extensions.config ? + GNUNET_PQ_query_param_null () : + GNUNET_PQ_query_param_string (td->details.extensions.config), + GNUNET_PQ_query_param_end + }; + + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_extensions", + params); +} + + +/** + * Function called with extension_details records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_extension_details (struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&td->serial), + NULL == + td->details.extension_details.extension_options ? + GNUNET_PQ_query_param_null () : + GNUNET_PQ_query_param_string ( + td->details.extension_details.extension_options), + GNUNET_PQ_query_param_end + }; + + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_extension_details", + params); +} + + /* end of irbt_callbacks.c */ diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/lrbt_callbacks.c index f7b0e28d5..7f1d2fdb9 100644 --- a/src/exchangedb/lrbt_callbacks.c +++ b/src/exchangedb/lrbt_callbacks.c @@ -1306,4 +1306,99 @@ lrbt_cb_table_recoup_refresh (void *cls, } +/** + * Function called with extensions table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_extensions (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_EXTENSIONS + }; + bool no_config = false; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("extension_id", + &td.serial), + GNUNET_PQ_result_spec_string ("name", + &td.details.extensions.name), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("config", + &td.details.extensions.config), + &no_config), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with extension_details table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_extension_details (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_EXTENSION_DETAILS + }; + bool no_config = false; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("extension_details_serial_id", + &td.serial), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("extension_options", + &td.details.extension_details. + extension_options), + &no_config), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + /* end of lrbt_callbacks.c */ diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 754654e32..9a3229f47 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -2123,6 +2123,22 @@ prepare_statements (struct PostgresClosure *pg) " ORDER BY recoup_refresh_uuid DESC" " LIMIT 1;", 0), + GNUNET_PQ_make_prepare ( + "select_serial_by_table_extensions", + "SELECT" + " extension_id AS serial" + " FROM extensions" + " ORDER BY extension_id DESC" + " LIMIT 1;", + 0), + GNUNET_PQ_make_prepare ( + "select_serial_by_table_extension_details", + "SELECT" + " extension_details_serial_id AS serial" + " FROM extension_details" + " ORDER BY extension_details_serial_id DESC" + " LIMIT 1;", + 0), /* For postgres_lookup_records_by_table */ GNUNET_PQ_make_prepare ( "select_above_serial_by_table_denominations", @@ -2727,6 +2743,23 @@ prepare_statements (struct PostgresClosure *pg) ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8);", 8), + GNUNET_PQ_make_prepare ( + "insert_into_table_extensions", + "INSERT INTO extensions" + "(extension_id" + ",name" + ",config" + ") VALUES " + "($1, $2, $3);", + 3), + GNUNET_PQ_make_prepare ( + "insert_into_table_extension_details", + "INSERT INTO extension_details" + "(extension_details_serial_id" + ",extension_options" + ") VALUES " + "($1, $2);", + 2), /* Used in #postgres_begin_shard() */ GNUNET_PQ_make_prepare ( @@ -10807,6 +10840,12 @@ postgres_lookup_serial_by_table (void *cls, case TALER_EXCHANGEDB_RT_RECOUP_REFRESH: statement = "select_serial_by_table_recoup_refresh"; break; + case TALER_EXCHANGEDB_RT_EXTENSIONS: + statement = "select_serial_by_table_extensions"; + break; + case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: + statement = "select_serial_by_table_extension_details"; + break; default: GNUNET_break (0); return GNUNET_DB_STATUS_HARD_ERROR; @@ -10972,6 +11011,14 @@ postgres_lookup_records_by_table (void *cls, statement = "select_above_serial_by_table_recoup_refresh"; rh = &lrbt_cb_table_recoup_refresh; break; + case TALER_EXCHANGEDB_RT_EXTENSIONS: + statement = "select_above_serial_by_table_extensions"; + rh = &lrbt_cb_table_extensions; + break; + case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: + statement = "select_above_serial_by_table_extension_details"; + rh = &lrbt_cb_table_extension_details; + break; default: GNUNET_break (0); return GNUNET_DB_STATUS_HARD_ERROR; @@ -11097,6 +11144,12 @@ postgres_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_RECOUP_REFRESH: rh = &irbt_cb_table_recoup_refresh; break; + case TALER_EXCHANGEDB_RT_EXTENSIONS: + rh = &irbt_cb_table_extensions; + break; + case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS: + rh = &irbt_cb_table_extension_details; + break; default: GNUNET_break (0); return GNUNET_DB_STATUS_HARD_ERROR; diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index c8953b940..878cfe2f2 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -169,7 +169,9 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING, TALER_EXCHANGEDB_RT_WIRE_FEE, TALER_EXCHANGEDB_RT_RECOUP, - TALER_EXCHANGEDB_RT_RECOUP_REFRESH + TALER_EXCHANGEDB_RT_RECOUP_REFRESH, + TALER_EXCHANGEDB_RT_EXTENSIONS, + TALER_EXCHANGEDB_RT_EXTENSION_DETAILS, }; @@ -407,6 +409,17 @@ struct TALER_EXCHANGEDB_TableData uint64_t rrc_serial; } recoup_refresh; + struct + { + char *name; + char *config; + } extensions; + + struct + { + char *extension_options; + } extension_details; + } details; }; |