diff --git a/src/exchange/taler-exchange-httpd_management_extensions.c b/src/exchange/taler-exchange-httpd_management_extensions.c index 6a771bf43..522c317c1 100644 --- a/src/exchange/taler-exchange-httpd_management_extensions.c +++ b/src/exchange/taler-exchange-httpd_management_extensions.c @@ -42,7 +42,7 @@ struct Extension // configuration for the age restriction struct TALER_AgeMask mask; - /* TODO oec - peer2peer config */ + /* TODO oec - add peer2peer config */ }; }; @@ -77,9 +77,46 @@ set_extensions (void *cls, struct MHD_Connection *connection, MHD_RESULT *mhd_ret) { - // struct SetExtensionContext *sec = cls; + struct SetExtensionsContext *sec = cls; + + /* save the configurations of all extensions */ + for (uint32_t i = 0; inum_extensions; i++) + { + struct Extension *ext = &sec->extensions[i]; + struct TALER_MasterSignatureP *sig = &sec->extensions_sigs[i]; + enum GNUNET_DB_QueryStatus qs; + char *config; + + config = json_dumps (ext->config_json, JSON_COMPACT | JSON_SORT_KEYS); + if (NULL == config) + { + GNUNET_break (0); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_JSON_INVALID, + "convert configuration to string"); + return GNUNET_DB_STATUS_SOFT_ERROR; /* FIXME: right error? */ + } + + qs = TEH_plugin->set_extension_config ( + TEH_plugin->cls, + TEH_extensions[ext->type].name, + config, + sig); + + if (qs < 0) + { + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + return qs; + GNUNET_break (0); + *mhd_ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "save extension configuration"); + } + + } - // TODO oec return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */ } @@ -99,7 +136,6 @@ TEH_handler_management_post_extensions ( &extensions_sigs), GNUNET_JSON_spec_end () }; - bool ok; MHD_RESULT ret; { @@ -123,7 +159,7 @@ TEH_handler_management_post_extensions ( connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, - "array expected for extensions and extensions_sig"); + "array expected for extensions and extensions_sigs"); } sec.num_extensions = json_array_size (extensions_sigs); @@ -135,7 +171,7 @@ TEH_handler_management_post_extensions ( connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, - "arrays extensions and extensions_sig are not of equal size"); + "arrays extensions and extensions_sigs are not of equal size"); } GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -145,11 +181,9 @@ TEH_handler_management_post_extensions ( struct Extension); sec.extensions_sigs = GNUNET_new_array (sec.num_extensions, struct TALER_MasterSignatureP); - ok = true; for (unsigned int i = 0; iconn, + "set_extension_config", + params); +} + + +/** + * Function called to get the configuration of an extension + * (age-restriction, peer2peer, ...) + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param extension_name the name of the extension + * @param[out] config JSON object of the configuration as string + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +postgres_get_extension_config (void *cls, + const char *extension_name, + char **config) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (extension_name), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("config", config), + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "get_extension_config", + params, + rs); +} + + /** * Initialize Postgres database subsystem. * @@ -11628,6 +11708,10 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &postgres_release_revolving_shard; plugin->delete_shard_locks = &postgres_delete_shard_locks; + plugin->set_extension_config + = &postgres_set_extension_config; + plugin->get_extension_config + = &postgres_get_extension_config; return plugin; } diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index ee691084e..4aa80b674 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -4025,8 +4025,35 @@ struct TALER_EXCHANGEDB_Plugin (*delete_shard_locks)(void *cls); /** - * TODO-oec: add function for adding extension config + * Function called to save the configuration of an extension + * (age-restriction, peer2peer, ...) + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param extension_name the name of the extension + * @param config JSON object of the configuration as string + * @param config_sig signature of the configuration by the offline master key + * @return transaction status code */ + enum GNUNET_DB_QueryStatus + (*set_extension_config)(void *cls, + const char *extension_name, + const char *config, + const struct TALER_MasterSignatureP *config_sig); + + /** + * Function called to retrieve the configuration of an extension + * (age-restriction, peer2peer, ...) + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param extension_name the name of the extension + * @param[out] config JSON object of the configuration as string + * @param[out] config_sig signature of the configuration by the master key + * @return transaction status code + */ + enum GNUNET_DB_QueryStatus + (*get_extension_config)(void *cls, + const char *extension_name, + char **config); };