ifcfg-rh/trivial: rename svGetValue() and related

svGetValue() had the meaning of returning a string, except the
empty word "" was coerced to NULL.

svGetValueFull() had the meaing of returing the value as string,
including the empty word.

Rename those functions to better express what they do.

Same for svSetValue*().
This commit is contained in:
Thomas Haller 2016-10-31 13:10:55 +01:00
parent 2a3b238d49
commit 917ab8334b
5 changed files with 412 additions and 413 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -324,11 +324,11 @@ find_line (shvarFile *s, const char *key)
return NULL;
}
/* svGetValueFull() is identical to svGetValue() except that
* svGetValue() will never return an empty value (but %NULL instead).
* svGetValueFull() will return empty values if that is the value for the @key. */
/* svGetValue() is identical to svGetValueString() except that
* svGetValueString() will never return an empty value (but %NULL instead).
* svGetValue() will return empty values if that is the value for the @key. */
char *
svGetValueFull (shvarFile *s, const char *key)
svGetValue (shvarFile *s, const char *key)
{
const char *line_val;
char *value;
@ -350,11 +350,11 @@ svGetValueFull (shvarFile *s, const char *key)
* be freed by the caller.
*/
char *
svGetValue (shvarFile *s, const char *key)
svGetValueString (shvarFile *s, const char *key)
{
char *value;
value = svGetValueFull (s, key);
value = svGetValue (s, key);
if (value && !*value) {
g_free (value);
return NULL;
@ -376,7 +376,7 @@ svGetValueBoolean (shvarFile *s, const char *key, gint fallback)
{
gs_free char *tmp = NULL;
tmp = svGetValue (s, key);
tmp = svGetValueString (s, key);
return svParseBoolean (tmp, fallback);
}
@ -397,7 +397,7 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
gint64 result;
int errsv;
tmp = svGetValueFull (s, key);
tmp = svGetValue (s, key);
if (!tmp) {
errno = 0;
return fallback;
@ -414,10 +414,10 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m
/*****************************************************************************/
/* Same as svSetValue() but it preserves empty @value -- contrary to
* svSetValue() for which "" effectively means to remove the value. */
/* Same as svSetValueString() but it preserves empty @value -- contrary to
* svSetValueString() for which "" effectively means to remove the value. */
void
svSetValueFull (shvarFile *s, const char *key, const char *value)
svSetValue (shvarFile *s, const char *key, const char *value)
{
gs_free char *newval_free = NULL;
gs_free char *oldval = NULL;
@ -439,7 +439,7 @@ svSetValueFull (shvarFile *s, const char *key, const char *value)
}
value = svEscape (value, &newval_free);
oldval = svGetValueFull (s, key);
oldval = svGetValue (s, key);
keyValue = g_strdup_printf ("%s=%s", key, value);
if (!oldval) {
@ -467,9 +467,9 @@ svSetValueFull (shvarFile *s, const char *key, const char *value)
* to the bottom of the file.
*/
void
svSetValue (shvarFile *s, const char *key, const char *value)
svSetValueString (shvarFile *s, const char *key, const char *value)
{
svSetValueFull (s, key, value && value[0] ? value : NULL);
svSetValue (s, key, value && value[0] ? value : NULL);
}
void
@ -477,20 +477,19 @@ svSetValueInt64 (shvarFile *s, const char *key, gint64 value)
{
char buf[NM_DECIMAL_STR_MAX (value)];
svSetValueFull (s, key,
nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value));
svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value));
}
void
svSetValueBoolean (shvarFile *s, const char *key, gboolean value)
{
svSetValueFull (s, key, value ? "yes" : "no");
svSetValue (s, key, value ? "yes" : "no");
}
void
svUnsetValue (shvarFile *s, const char *key)
{
svSetValueFull (s, key, NULL);
svSetValue (s, key, NULL);
}
/*****************************************************************************/

View file

@ -45,8 +45,8 @@ shvarFile *svOpenFile (const char *name, GError **error);
* pointing at the line containing the value. The char* returned MUST
* be freed by the caller.
*/
char *svGetValueString (shvarFile *s, const char *key);
char *svGetValue (shvarFile *s, const char *key);
char *svGetValueFull (shvarFile *s, const char *key);
gint svParseBoolean (const char *value, gint def);
@ -63,8 +63,8 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g
* the key=value pair after that line. Otherwise, prepend the pair
* to the top of the file.
*/
void svSetValueString (shvarFile *s, const char *key, const char *value);
void svSetValue (shvarFile *s, const char *key, const char *value);
void svSetValueFull (shvarFile *s, const char *key, const char *value);
void svSetValueBoolean (shvarFile *s, const char *key, gboolean value);
void svSetValueInt64 (shvarFile *s, const char *key, gint64 value);

View file

@ -1789,7 +1789,7 @@ test_clear_master (void)
g_assert_no_error (error);
g_assert (f);
val = svGetValue (f, "BRIDGE");
val = svGetValueString (f, "BRIDGE");
g_assert (!val);
svCloseFile (f);
}
@ -3014,7 +3014,7 @@ test_write_wifi_hidden (void)
g_assert (f);
/* re-read the file to check that what key was written. */
val = svGetValue (f, "SSID_HIDDEN");
val = svGetValueString (f, "SSID_HIDDEN");
g_assert (val);
g_assert_cmpstr (val, ==, "yes");
g_free (val);
@ -3113,7 +3113,7 @@ test_write_wifi_mac_random (gconstpointer user_data)
g_assert (f);
/* re-read the file to check that what key was written. */
val = svGetValue (f, "MAC_ADDRESS_RANDOMIZATION");
val = svGetValueString (f, "MAC_ADDRESS_RANDOMIZATION");
g_assert_cmpstr (val, ==, write_expected);
g_free (val);
svCloseFile (f);
@ -3177,7 +3177,7 @@ test_write_wired_wake_on_lan (void)
g_assert (f);
/* re-read the file to check that the key was written. */
val = svGetValue (f, "ETHTOOL_OPTS");
val = svGetValueString (f, "ETHTOOL_OPTS");
g_assert (val);
g_assert (strstr (val, "wol"));
g_assert (strstr (val, "sopass 00:00:00:11:22:33"));
@ -3266,7 +3266,7 @@ test_write_wifi_band_a (void)
g_assert (f);
/* re-read the file to check that what key was written. */
val = svGetValue (f, "BAND");
val = svGetValueString (f, "BAND");
g_assert (val);
g_assert_cmpstr (val, ==, "a");
g_free (val);
@ -3975,7 +3975,7 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data)
g_assert_no_error (error);
g_assert (ifcfg);
written_ifcfg_gateway = svGetValue (ifcfg, "IPV6_DEFAULTGW");
written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW");
svCloseFile (ifcfg);
}
@ -4499,15 +4499,15 @@ test_write_wired_aliases (void)
/* Create some pre-existing alias files, to make sure they get overwritten / deleted. */
ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":2");
svSetValue (ifcfg, "DEVICE", "alias0:2");
svSetValue (ifcfg, "IPADDR", "192.168.1.2");
svSetValueString (ifcfg, "DEVICE", "alias0:2");
svSetValueString (ifcfg, "IPADDR", "192.168.1.2");
svWriteFile (ifcfg, 0644, NULL);
svCloseFile (ifcfg);
g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS));
ifcfg = svCreateFile (TEST_SCRATCH_ALIAS_BASE ":5");
svSetValue (ifcfg, "DEVICE", "alias0:5");
svSetValue (ifcfg, "IPADDR", "192.168.1.5");
svSetValueString (ifcfg, "DEVICE", "alias0:5");
svSetValueString (ifcfg, "IPADDR", "192.168.1.5");
svWriteFile (ifcfg, 0644, NULL);
svCloseFile (ifcfg);
g_assert (g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS));
@ -4628,41 +4628,41 @@ test_write_gateway (void)
g_assert (f);
/* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */
val = svGetValue (f, "IPADDR");
val = svGetValueString (f, "IPADDR");
g_assert (val);
g_assert_cmpstr (val, ==, "1.1.1.3");
g_free (val);
val = svGetValue (f, "IPADDR1");
val = svGetValueString (f, "IPADDR1");
g_assert (val);
g_assert_cmpstr (val, ==, "2.2.2.5");
g_free (val);
val = svGetValue (f, "IPADDR0");
val = svGetValueString (f, "IPADDR0");
g_assert (val == NULL);
val = svGetValue (f, "PREFIX");
val = svGetValueString (f, "PREFIX");
g_assert (val);
g_assert_cmpstr (val, ==, "24");
g_free (val);
val = svGetValue (f, "PREFIX1");
val = svGetValueString (f, "PREFIX1");
g_assert (val);
g_assert_cmpstr (val, ==, "24");
g_free (val);
val = svGetValue (f, "PREFIX0");
val = svGetValueString (f, "PREFIX0");
g_assert (val == NULL);
val = svGetValue (f, "GATEWAY");
val = svGetValueString (f, "GATEWAY");
g_assert (val);
g_assert_cmpstr (val, ==, "1.1.1.254");
g_free (val);
val = svGetValue (f, "GATEWAY0");
val = svGetValueString (f, "GATEWAY0");
g_assert (val == NULL);
val = svGetValue (f, "GATEWAY1");
val = svGetValueString (f, "GATEWAY1");
g_assert (val == NULL);
svCloseFile (f);
@ -4756,7 +4756,7 @@ test_write_wifi_open (void)
g_assert_no_error (error);
g_assert (ifcfg != NULL);
tmp = svGetValue (ifcfg, "ESSID");
tmp = svGetValueString (ifcfg, "ESSID");
g_assert_cmpstr (tmp, ==, "Test SSID");
g_free (tmp);
@ -6506,11 +6506,11 @@ test_write_wifi_dynamic_wep_leap (void)
ifcfg = svOpenFile (testfile, &error);
g_assert_no_error (error);
g_assert (ifcfg);
tmp = svGetValue (ifcfg, "SECURITYMODE");
tmp = svGetValueString (ifcfg, "SECURITYMODE");
g_assert_cmpstr (tmp, ==, NULL);
g_free (tmp);
tmp = svGetValue (ifcfg, "IEEE_8021X_EAP_METHODS");
tmp = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS");
g_assert_cmpstr (tmp, ==, "LEAP");
g_free (tmp);
@ -6672,13 +6672,13 @@ test_write_wired_ctc_dhcp (void)
g_assert_no_error (error);
g_assert (ifcfg);
tmp = svGetValue (ifcfg, "CTCPROT");
tmp = svGetValueString (ifcfg, "CTCPROT");
g_assert (tmp);
g_assert_cmpstr (tmp, ==, "0");
g_free (tmp);
/* And that it's not in the generic OPTIONS string */
tmp = svGetValue (ifcfg, "OPTIONS");
tmp = svGetValueString (ifcfg, "OPTIONS");
g_assert (tmp == NULL);
g_free (tmp);
@ -8421,7 +8421,7 @@ test_write_fcoe_mode (gconstpointer user_data)
g_assert_no_error (error);
g_assert (ifcfg);
written_mode = svGetValue (ifcfg, "DCB_APP_FCOE_MODE");
written_mode = svGetValueString (ifcfg, "DCB_APP_FCOE_MODE");
svCloseFile (ifcfg);
g_assert_cmpstr (written_mode, ==, expected_mode);
g_free (written_mode);
@ -8558,11 +8558,11 @@ test_write_team_master (void)
g_assert (f);
/* re-read the file to check that what key was written. */
val = svGetValue (f, "DEVICETYPE");
val = svGetValueString (f, "DEVICETYPE");
g_assert (val);
g_assert_cmpstr (val, ==, "Team");
g_free (val);
val = svGetValue (f, "TEAM_CONFIG");
val = svGetValueString (f, "TEAM_CONFIG");
g_assert (val);
g_assert_cmpstr (val, ==, expected_config);
g_free (val);
@ -8652,16 +8652,16 @@ test_write_team_port (void)
g_assert (f);
/* re-read the file to check that what key was written. */
val = svGetValue (f, "TYPE");
val = svGetValueString (f, "TYPE");
g_assert (!val);
val = svGetValue (f, "DEVICETYPE");
val = svGetValueString (f, "DEVICETYPE");
g_assert (val);
g_assert_cmpstr (val, ==, "TeamPort");
g_free (val);
val = svGetValue (f, "TEAM_PORT_CONFIG");
val = svGetValueString (f, "TEAM_PORT_CONFIG");
g_assert_cmpstr (val, ==, expected_config);
g_free (val);
val = svGetValue (f, "TEAM_MASTER");
val = svGetValueString (f, "TEAM_MASTER");
g_assert_cmpstr (val, ==, "team0");
g_free (val);
svCloseFile (f);