ifcfg: some refactoring of reader using vGetValueStr()/vGetValue_cp()

This commit is contained in:
Thomas Haller 2017-02-21 15:34:55 +01:00
parent ccbfda5c08
commit c9f6cb9fe4
2 changed files with 11 additions and 18 deletions

View file

@ -145,12 +145,10 @@ make_connection_setting (const char *file,
if (!uuid)
uuid = nm_utils_uuid_generate_from_string (svFileGetName (ifcfg), -1, NM_UTILS_UUID_TYPE_LEGACY, NULL);
stable_id = svGetValueStr_cp (ifcfg, "STABLE_ID");
g_object_set (s_con,
NM_SETTING_CONNECTION_TYPE, type,
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_STABLE_ID, stable_id,
NM_SETTING_CONNECTION_STABLE_ID, svGetValue (ifcfg, "STABLE_ID", &stable_id),
NULL);
g_free (uuid);
@ -285,8 +283,8 @@ read_ip4_address (shvarFile *ifcfg,
nm_assert (tag);
nm_assert (!error || !*error);
value = svGetValue (ifcfg, tag, &value_to_free);
if (!value || !value[0]) {
value = svGetValueStr (ifcfg, tag, &value_to_free);
if (!value) {
NM_SET_OUT (out_has_key, FALSE);
NM_SET_OUT (out_addr, 0);
return TRUE;
@ -335,23 +333,20 @@ is_any_ip4_address_defined (shvarFile *ifcfg, int *idx)
ret_idx = idx ? idx : &ignore;
for (i = -1; i <= 2; i++) {
char tag[256];
gs_free char *value = NULL;
char tag[256];
value = svGetValueStr_cp (ifcfg, numbered_tag (tag, "IPADDR", i));
if (value) {
if (svGetValueStr (ifcfg, numbered_tag (tag, "IPADDR", i), &value)) {
*ret_idx = i;
return TRUE;
}
value = svGetValueStr_cp (ifcfg, numbered_tag (tag, "PREFIX", i));
if (value) {
if (svGetValueStr (ifcfg, numbered_tag (tag, "PREFIX", i), &value)) {
*ret_idx = i;
return TRUE;
}
value = svGetValueStr_cp (ifcfg, numbered_tag (tag, "NETMASK", i));
if (value) {
if (svGetValueStr (ifcfg, numbered_tag (tag, "NETMASK", i), &value)) {
*ret_idx = i;
return TRUE;
}

View file

@ -2459,7 +2459,6 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
char *tmp;
guint32 i, num, num4;
gint priority;
GString *searches;
NMIPAddress *addr;
const char *dns;
gint64 route_metric;
@ -2560,17 +2559,16 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
/* Write out DNS domains - 'DOMAIN' key is shared for both IPv4 and IPv6 domains */
num = nm_setting_ip_config_get_num_dns_searches (s_ip6);
if (num > 0) {
char *ip4_domains;
ip4_domains = svGetValueStr_cp (ifcfg, "DOMAIN");
searches = g_string_new (ip4_domains);
gs_free char *ip4_domains = NULL;
nm_auto_free_gstring GString *searches = NULL;
searches = g_string_new (svGetValueStr (ifcfg, "DOMAIN", &ip4_domains));
for (i = 0; i < num; i++) {
if (searches->len > 0)
g_string_append_c (searches, ' ');
g_string_append (searches, nm_setting_ip_config_get_dns_search (s_ip6, i));
}
svSetValueStr (ifcfg, "DOMAIN", searches->str);
g_string_free (searches, TRUE);
g_free (ip4_domains);
}