summaryrefslogtreecommitdiff
path: root/src/nm-config-data.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-07-08 19:24:49 +0200
committerThomas Haller <thaller@redhat.com>2015-07-14 15:52:50 +0200
commitaa54d5a36eb329e4a9b9fb6e62633cd58c431f96 (patch)
treeb09495dad152a27df55c528571cb12ab40b3ab17 /src/nm-config-data.c
parent5cc2eabe5d24c8d9fe30aa675d48c7fa121d7c93 (diff)
downloadNetworkManager-aa54d5a36eb329e4a9b9fb6e62633cd58c431f96.tar.gz
config: add nm_config_data_get_value_cached() function
nm_config_data_get_value() returns an allocated string. This is inconvenient for the caller. Add a utility function nm_config_data_get_value_cached() that caches the returned value. Of course, use with care as the returned string will be invalidated by each call to nm_config_data_get_value_cached().
Diffstat (limited to 'src/nm-config-data.c')
-rw-r--r--src/nm-config-data.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/nm-config-data.c b/src/nm-config-data.c
index 03cae638c7..5e015f016e 100644
--- a/src/nm-config-data.c
+++ b/src/nm-config-data.c
@@ -72,6 +72,9 @@ typedef struct {
char *dns_mode;
char *rc_manager;
+
+ /* mutable field */
+ char *value_cached;
} NMConfigDataPrivate;
@@ -138,6 +141,22 @@ nm_config_data_get_value (const NMConfigData *self, const char *group, const cha
return nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, flags);
}
+const char *nm_config_data_get_value_cached (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
+{
+ NMConfigDataPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_CONFIG_DATA (self), NULL);
+ g_return_val_if_fail (group && *group, NULL);
+ g_return_val_if_fail (key && *key, NULL);
+
+ priv = NM_CONFIG_DATA_GET_PRIVATE (self);
+
+ /* we modify @value_cached. In C++ jargon, the field is mutable. */
+ g_free (priv->value_cached);
+ priv->value_cached = nm_config_keyfile_get_value (priv->keyfile, group, key, flags);
+ return priv->value_cached;
+}
+
gboolean
nm_config_data_has_value (const NMConfigData *self, const char *group, const char *key, NMConfigGetValueFlags flags)
{
@@ -801,6 +820,8 @@ finalize (GObject *gobject)
g_key_file_unref (priv->keyfile_intern);
G_OBJECT_CLASS (nm_config_data_parent_class)->finalize (gobject);
+
+ g_free (priv->value_cached);
}
static void