summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-08-25 15:16:52 +0200
committerThomas Haller <thaller@redhat.com>2018-09-05 11:41:40 +0200
commit0c3ba9f2ff76512105ceca609fda72c1db1c2ee2 (patch)
tree1b7ca7ac177e04b95d62da3b721e2b350ee1f485
parentb46fc00896153bfd2cf0024fb2d6d70ef0156fea (diff)
downloadNetworkManager-0c3ba9f2ff76512105ceca609fda72c1db1c2ee2.tar.gz
settings/ifupdown: use nm_streq() in parser
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c21
-rw-r--r--src/settings/plugins/ifupdown/nms-ifupdown-parser.c71
2 files changed, 45 insertions, 47 deletions
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c
index 178acb3039..df76775eee 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-interface-parser.c
@@ -190,7 +190,7 @@ _recursive_ifparser (const char *eni_file, int quiet)
* Create a block for each of them except source and source-directory. */
/* iface stanza takes at least 3 parameters */
- if (strcmp (token[0], "iface") == 0) {
+ if (nm_streq (token[0], "iface")) {
if (toknum < 4) {
if (!quiet) {
nm_log_warn (LOGD_SETTINGS, "Can't parse iface line '%s'\n",
@@ -204,33 +204,33 @@ _recursive_ifparser (const char *eni_file, int quiet)
}
/* auto and allow-auto stanzas are equivalent,
* both can take multiple interfaces as parameters: add one block for each */
- else if (strcmp (token[0], "auto") == 0 ||
- strcmp (token[0], "allow-auto") == 0) {
+ else if (NM_IN_STRSET (token[0], "auto", "allow-auto")) {
int i;
+
for (i = 1; i < toknum; i++)
add_block ("auto", token[i]);
skip_to_block = 0;
}
- else if (strcmp (token[0], "mapping") == 0) {
+ else if (nm_streq (token[0], "mapping")) {
add_block (token[0], join_values_with_spaces (value, token + 1));
skip_to_block = 0;
}
/* allow-* can take multiple interfaces as parameters: add one block for each */
- else if (strncmp (token[0],"allow-",6) == 0) {
+ else if (g_str_has_prefix (token[0], "allow-")) {
int i;
for (i = 1; i < toknum; i++)
add_block (token[0], token[i]);
skip_to_block = 0;
}
/* source and source-directory stanzas take one or more paths as parameters */
- else if (strcmp (token[0], "source") == 0 || strcmp (token[0], "source-directory") == 0) {
+ else if (NM_IN_STRSET (token[0], "source", "source-directory")) {
int i;
char *en_dir;
skip_to_block = 0;
en_dir = g_path_get_dirname (eni_file);
for (i = 1; i < toknum; ++i) {
- if (strcmp (token[0], "source-directory") == 0)
+ if (nm_streq (token[0], "source-directory"))
_ifparser_source (token[i], en_dir, quiet, TRUE);
else
_ifparser_source (token[i], en_dir, quiet, FALSE);
@@ -359,7 +359,8 @@ ifparser_getif (const char* iface)
{
if_block *curr = first;
while (curr != NULL) {
- if (strcmp (curr->type,"iface")==0 && strcmp (curr->name,iface)==0)
+ if ( nm_streq (curr->type, "iface")
+ && nm_streq (curr->name, iface))
return curr;
curr = curr->next;
}
@@ -371,7 +372,7 @@ ifparser_getkey (if_block* iface, const char *key)
{
if_data *curr = iface->info;
while (curr != NULL) {
- if (strcmp (curr->key,key)==0)
+ if (nm_streq (curr->key, key))
return curr->data;
curr = curr->next;
}
@@ -384,7 +385,7 @@ ifparser_haskey (if_block* iface, const char *key)
if_data *curr = iface->info;
while (curr != NULL) {
- if (strcmp (curr->key, key) == 0)
+ if (nm_streq (curr->key, key))
return TRUE;
curr = curr->next;
}
diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c
index 4dd922b4a2..e5d1f90082 100644
--- a/src/settings/plugins/ifupdown/nms-ifupdown-parser.c
+++ b/src/settings/plugins/ifupdown/nms-ifupdown-parser.c
@@ -43,13 +43,13 @@ _ifupdownplugin_guess_connection_type (if_block *block)
if_data *curr = block->info;
const char* ret_type = NULL;
const char* value = ifparser_getkey (block, "inet");
- if (value && !strcmp ("ppp", value)) {
+
+ if (nm_streq0 (value, "ppp"))
ret_type = NM_SETTING_PPP_SETTING_NAME;
- }
while (!ret_type && curr) {
if (!strncmp ("wireless-", curr->key, strlen ("wireless-")) ||
- !strncmp ("wpa-", curr->key, strlen ("wpa-"))) {
+ !strncmp ("wpa-", curr->key, strlen ("wpa-"))) {
ret_type = NM_SETTING_WIRELESS_SETTING_NAME;
}
curr = curr->next;
@@ -71,8 +71,9 @@ static gpointer
map_by_mapping (struct _Mapping *mapping, const char *key)
{
struct _Mapping *curr = mapping;
+
while (curr->domain) {
- if (!strcmp (curr->domain, key))
+ if (nm_streq (curr->domain, key))
return curr->target;
curr++;
}
@@ -97,9 +98,8 @@ update_wireless_setting_from_if_block (NMConnection *connection,
NMSettingWireless *wireless_setting = NULL;
- if (value && !strcmp ("ppp", value)) {
+ if (nm_streq0 (value, "ppp"))
return;
- }
nm_log_info (LOGD_SETTINGS, "update wireless settings (%s).", block->name);
wireless_setting = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
@@ -109,7 +109,7 @@ update_wireless_setting_from_if_block (NMConnection *connection,
!strncmp ("wireless-", curr->key, wireless_l)) {
const char* newkey = map_by_mapping (mapping, curr->key+wireless_l);
nm_log_info (LOGD_SETTINGS, "wireless setting key: %s='%s'", newkey, curr->data);
- if (newkey && !strcmp ("ssid", newkey)) {
+ if (nm_streq0 (newkey, "ssid")) {
GBytes *ssid;
int len = strlen (curr->data);
@@ -117,7 +117,7 @@ update_wireless_setting_from_if_block (NMConnection *connection,
g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL);
g_bytes_unref (ssid);
nm_log_info (LOGD_SETTINGS, "setting wireless ssid = %d", len);
- } else if (newkey && !strcmp ("mode", newkey)) {
+ } else if (nm_streq0 (newkey, "mode")) {
if (!g_ascii_strcasecmp (curr->data, "Managed") || !g_ascii_strcasecmp (curr->data, "Auto"))
g_object_set (wireless_setting, NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL);
else if (!g_ascii_strcasecmp (curr->data, "Ad-Hoc"))
@@ -135,7 +135,7 @@ update_wireless_setting_from_if_block (NMConnection *connection,
&& !strncmp ("wpa-", curr->key, wpa_l)) {
const char* newkey = map_by_mapping (mapping, curr->key+wpa_l);
- if (newkey && !strcmp ("ssid", newkey)) {
+ if (nm_streq0 (newkey, "ssid")) {
GBytes *ssid;
int len = strlen (curr->data);
@@ -302,9 +302,8 @@ update_wireless_security_setting_from_if_block (NMConnection *connection,
NMSettingWireless *s_wireless;
gboolean security = FALSE;
- if (value && !strcmp ("ppp", value)) {
+ if (nm_streq0 (value, "ppp"))
return;
- }
s_wireless = nm_connection_get_setting_wireless (connection);
g_return_if_fail (s_wireless);
@@ -361,20 +360,16 @@ wireless_next:
property_value = (*dupe_func) (curr->data, connection);
nm_log_info (LOGD_SETTINGS, "setting wpa security key: %s=%s",
newkey,
-#ifdef DEBUG_SECRETS
- property_value
-#else /* DEBUG_SECRETS */
- !strcmp ("key", newkey) ||
- !strcmp ("leap-password", newkey) ||
- !strcmp ("pin", newkey) ||
- !strcmp ("psk", newkey) ||
- !strcmp ("wep-key0", newkey) ||
- !strcmp ("wep-key1", newkey) ||
- !strcmp ("wep-key2", newkey) ||
- !strcmp ("wep-key3", newkey) ||
- NULL ?
- "<omitted>" : property_value
-#endif /* DEBUG_SECRETS */
+ NM_IN_STRSET (newkey, "key",
+ "leap-password",
+ "pin",
+ "psk",
+ "wep-key0",
+ "wep-key1",
+ "wep-key2",
+ "wep-key3")
+ ? "<omitted>"
+ : property_value
);
if (type_map_func) {
@@ -385,8 +380,8 @@ wireless_next:
}
g_object_set (wireless_security_setting,
- newkey, typed_property_value ?: property_value,
- NULL);
+ newkey, typed_property_value ?: property_value,
+ NULL);
security = TRUE;
wpa_next:
@@ -444,10 +439,12 @@ update_ip4_setting_from_if_block (NMConnection *connection,
NMSettingIPConfig *s_ip4 = NM_SETTING_IP_CONFIG (nm_setting_ip4_config_new ());
const char *type = ifparser_getkey (block, "inet");
- gboolean is_static = type && !strcmp ("static", type);
- if (!is_static) {
- g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
+ if (!nm_streq0 (type, "static")) {
+ g_object_set (s_ip4,
+ NM_SETTING_IP_CONFIG_METHOD,
+ NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NULL);
} else {
guint32 tmp_mask;
NMIPAddress *addr;
@@ -573,12 +570,12 @@ update_ip6_setting_from_if_block (NMConnection *connection,
{
NMSettingIPConfig *s_ip6 = NM_SETTING_IP_CONFIG (nm_setting_ip6_config_new ());
const char *type = ifparser_getkey (block, "inet6");
- gboolean is_static = type
- && ( !strcmp ("static", type)
- || !strcmp ("v4tunnel", type));
- if (!is_static) {
- g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
+ if (!NM_IN_STRSET (type, "static", "v4tunnel")) {
+ g_object_set (s_ip6,
+ NM_SETTING_IP_CONFIG_METHOD,
+ NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NULL);
} else {
NMIPAddress *addr;
const char *address_v;
@@ -701,9 +698,9 @@ ifupdown_update_connection_from_if_block (NMConnection *connection,
nm_log_info (LOGD_SETTINGS, "update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s",
block->name, type, idstr, nm_setting_connection_get_uuid (s_con));
- if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type))
+ if (nm_streq (type, NM_SETTING_WIRED_SETTING_NAME))
update_wired_setting_from_if_block (connection, block);
- else if (!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) {
+ else if (nm_streq (type, NM_SETTING_WIRELESS_SETTING_NAME)) {
update_wireless_setting_from_if_block (connection, block);
update_wireless_security_setting_from_if_block (connection, block);
}