From d0e27ac82e0ba53c6a0a0327f752fe3aecaf2a31 Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Tue, 13 Sep 2022 10:54:04 -0400 Subject: [PATCH] settings: remove wp_settings_get_all() API Not used anymore. It is better to use parse_object_safe() Lua API instead. --- lib/wp/settings.c | 38 -------------------------- lib/wp/settings.h | 3 -- modules/module-lua-scripting/api/api.c | 23 ---------------- tests/wp/settings.c | 10 ------- tests/wplua/scripts/settings.lua | 10 ------- 5 files changed, 84 deletions(-) diff --git a/lib/wp/settings.c b/lib/wp/settings.c index 52516706..bfa8eb64 100644 --- a/lib/wp/settings.c +++ b/lib/wp/settings.c @@ -185,44 +185,6 @@ wp_settings_get (WpSettings *self, const gchar *setting) return value ? wp_spa_json_new_from_string (value) : NULL; } -/*! - * \brief Gets all the settings with their name matching the given pattern. - * \ingroup wpsettings - * \param self the settings object - * \param pattern (nullable) the pattern to match all the settings. A NULL value - * has the same behavior as the "*" pattern. - * \returns (transfer full) (nullable): A JSON object with all the setting - * values matching the pattern, or NULL if the settings object is not activated. - */ -WpSpaJson * -wp_settings_get_all (WpSettings *self, const gchar *pattern) -{ - g_autoptr (WpSpaJsonBuilder) b = NULL; - g_autoptr (WpIterator) it = NULL; - g_auto (GValue) item = G_VALUE_INIT; - - g_return_val_if_fail (WP_IS_SETTINGS (self), NULL); - - if (!(wp_object_get_active_features (WP_OBJECT (self)) & - WP_OBJECT_FEATURES_ALL)) - return NULL; - - b = wp_spa_json_builder_new_object (); - for (it = wp_properties_new_iterator (self->settings); - wp_iterator_next (it, &item); - g_value_unset (&item)) { - WpPropertiesItem *pi = g_value_get_boxed (&item); - const gchar *key = wp_properties_item_get_key (pi); - const gchar *val = wp_properties_item_get_value (pi); - if (key && val && (!pattern || g_pattern_match_simple (pattern, key))) { - wp_spa_json_builder_add_property (b, key); - wp_spa_json_builder_add_from_string (b, val); - } - } - - return wp_spa_json_builder_end (b); -} - /*! * \brief Safely parses a boolean setting, using the fallback value if the * setting does not exist, or the setting cannot be parsed. A warning is also diff --git a/lib/wp/settings.h b/lib/wp/settings.h index 9ecfac61..b76f908f 100644 --- a/lib/wp/settings.h +++ b/lib/wp/settings.h @@ -64,9 +64,6 @@ gboolean wp_settings_unsubscribe (WpSettings *self, WP_API WpSpaJson * wp_settings_get (WpSettings *self, const gchar *setting); -WP_API -WpSpaJson * wp_settings_get_all (WpSettings *self, const gchar *pattern); - WP_API gboolean wp_settings_parse_boolean_safe (WpSettings *self, const gchar *setting, gboolean value); diff --git a/modules/module-lua-scripting/api/api.c b/modules/module-lua-scripting/api/api.c index 940b7526..91f86d6a 100644 --- a/modules/module-lua-scripting/api/api.c +++ b/modules/module-lua-scripting/api/api.c @@ -1495,28 +1495,6 @@ settings_get (lua_State *L) return 1; } -static int -settings_get_all (lua_State *L) -{ - const char *pattern = luaL_checkstring (L, 1); - const char *m = NULL; - - if (lua_type (L, 2) == LUA_TSTRING) - m = luaL_checkstring (L, 2); - - g_autoptr (WpSettings) s = wp_settings_get_instance (get_wp_core (L), m); - - if (s) { - WpSpaJson *j = wp_settings_get_all (s, pattern); - if (j) - wplua_pushboxed (L, WP_TYPE_SPA_JSON, j); - else - lua_pushnil (L); - } else - lua_pushnil (L); - return 1; -} - static int settings_parse_boolean_safe (lua_State *L) { @@ -1712,7 +1690,6 @@ settings_unsubscribe (lua_State *L) static const luaL_Reg settings_methods[] = { { "get", settings_get }, - { "get_all", settings_get_all }, { "parse_boolean_safe", settings_parse_boolean_safe }, { "parse_int_safe", settings_parse_int_safe }, { "parse_float_safe", settings_parse_float_safe }, diff --git a/tests/wp/settings.c b/tests/wp/settings.c index c3c72e88..e1f85c06 100644 --- a/tests/wp/settings.c +++ b/tests/wp/settings.c @@ -435,16 +435,6 @@ test_wpsettings (TestSettingsFixture *self, gconstpointer data) } } - { - /* _get_all () */ - g_autoptr (WpSpaJson) value = NULL; - value = wp_settings_get_all (s, "*string*"); - g_assert_nonnull (value); - g_assert_true (wp_spa_json_is_object (value)); - g_assert_cmpstr (wp_spa_json_get_data (value), ==, - "{\"test-setting4-string\":\"blahblah\", \"test-setting5-string-with-quotes\":\"a string with \\\"quotes\\\"\"}"); - } - { g_autoptr (WpSettings) s4 = wp_settings_get_instance (self->base.core, NULL); diff --git a/tests/wplua/scripts/settings.lua b/tests/wplua/scripts/settings.lua index 186a04d5..908aec75 100644 --- a/tests/wplua/scripts/settings.lua +++ b/tests/wplua/scripts/settings.lua @@ -119,16 +119,6 @@ value = Settings.parse_object_safe ("test-setting-undefined", "test-settings") assert (value ~= nil) assert (#value == 0) --- test settings _get_all () -value = Settings.get_all ("*string*", "test-settings") -assert (value ~= nil) -assert (value:is_object()) -assert (value:get_data() == - "{\"test-setting4-string\":\"blahblah\", \"test-setting5-string-with-quotes\":\"a string with \\\"quotes\\\"\"}") -val = value:parse () -assert (val["test-setting4-string"] == "blahblah") -assert (val["test-setting5-string-with-quotes"] == "a string with \"quotes\"") - -- test rules -- test #1 local cp = {