[network-manager-openvpn/th/export-bgo764132: 24/24] properties: refactor args_write_line_int64_str()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/th/export-bgo764132: 24/24] properties: refactor args_write_line_int64_str()
- Date: Thu, 24 Mar 2016 11:49:31 +0000 (UTC)
commit ada62192dc5c36adf5a2b4962cb5f9d0e0d30a98
Author: Thomas Haller <thaller redhat com>
Date: Thu Mar 24 12:21:20 2016 +0100
properties: refactor args_write_line_int64_str()
All callers of args_write_line_int64_str() directly obtained
the value from s_vpn. Also, args_write_line_int64_str() would
only print a line when the argument was a valid integer, thus
similar to args_write_line_setting_value().
Now, args_write_line_setting_value() and
args_write_line_setting_value_int() may both not print a line.
All other args_write_line*() functions always print one line.
properties/import-export.c | 39 +++++++++++++++++++--------------------
1 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 290210f..2033243 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1610,17 +1610,26 @@ args_write_line_int64 (GString *f, const char *key, gint64 value)
}
static void
-args_write_line_int64_str (GString *f, const char *key, const char *value)
+args_write_line_setting_value_int (GString *f,
+ const char *tag_key,
+ NMSettingVpn *s_vpn,
+ const char *setting_key)
{
+ const char *value;
gint64 v;
+ nm_assert (tag_key && tag_key[0]);
+ nm_assert (NM_IS_SETTING_VPN (s_vpn));
+ nm_assert (setting_key && setting_key[0]);
+
+ value = nm_setting_vpn_get_data_item (s_vpn, setting_key);
if (!_arg_is_set (value))
return;
v = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT64, G_MAXINT64, 0);
if (errno)
return;
- args_write_line_int64 (f, key, v);
+ args_write_line_int64 (f, tag_key, v);
}
static void
@@ -1631,10 +1640,6 @@ args_write_line_setting_value (GString *f,
{
const char *value;
- nm_assert (tag_key && tag_key[0]);
- nm_assert (NM_IS_SETTING_VPN (s_vpn));
- nm_assert (setting_key && setting_key[0]);
-
value = nm_setting_vpn_get_data_item (s_vpn, setting_key);
if (_arg_is_set (value))
args_write_line (f, tag_key, value);
@@ -1784,13 +1789,11 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
}
}
- args_write_line_int64_str (f,
- TAG_RENEG_SEC,
- nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS));
+ args_write_line_setting_value_int (f, TAG_RENEG_SEC, s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS);
args_write_line_setting_value (f, TAG_CIPHER, s_vpn, NM_OPENVPN_KEY_CIPHER);
- args_write_line_int64_str (f, TAG_KEYSIZE, nm_setting_vpn_get_data_item (s_vpn,
NM_OPENVPN_KEY_KEYSIZE));
+ args_write_line_setting_value_int (f, TAG_KEYSIZE, s_vpn, NM_OPENVPN_KEY_KEYSIZE);
if (nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO), "yes"))
args_write_line (f, TAG_COMP_LZO, "yes");
@@ -1801,13 +1804,9 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
if (nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_MSSFIX), "yes"))
args_write_line (f, TAG_MSSFIX);
- args_write_line_int64_str (f,
- TAG_TUN_MTU,
- nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TUNNEL_MTU));
+ args_write_line_setting_value_int (f, TAG_TUN_MTU, s_vpn, NM_OPENVPN_KEY_TUNNEL_MTU);
- args_write_line_int64_str (f,
- TAG_FRAGMENT,
- nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_FRAGMENT_SIZE));
+ args_write_line_setting_value_int (f, TAG_FRAGMENT, s_vpn, NM_OPENVPN_KEY_FRAGMENT_SIZE);
{
gs_free char *device_free = NULL;
@@ -1831,13 +1830,13 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP), "yes")
? "tcp" : "udp");
- args_write_line_int64_str (f, TAG_PORT, nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT));
+ args_write_line_setting_value_int (f, TAG_PORT, s_vpn, NM_OPENVPN_KEY_PORT);
- args_write_line_int64_str (f, TAG_PING, nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PING));
+ args_write_line_setting_value_int (f, TAG_PING, s_vpn, NM_OPENVPN_KEY_PING);
- args_write_line_int64_str (f, TAG_PING_EXIT, nm_setting_vpn_get_data_item (s_vpn,
NM_OPENVPN_KEY_PING_EXIT));
+ args_write_line_setting_value_int (f, TAG_PING_EXIT, s_vpn, NM_OPENVPN_KEY_PING_EXIT);
- args_write_line_int64_str (f, TAG_PING_RESTART, nm_setting_vpn_get_data_item (s_vpn,
NM_OPENVPN_KEY_PING_RESTART));
+ args_write_line_setting_value_int (f, TAG_PING_RESTART, s_vpn, NM_OPENVPN_KEY_PING_RESTART);
local_ip = _arg_is_set (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_LOCAL_IP));
remote_ip = _arg_is_set (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE_IP));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]