dispatcher: trivial code rearrangement
Reorganize some code in preparation for the GDBus port. (Most of the diff is actually just reindentation.) This also makes explicit something that was probably a bug; IP4_NUM_ROUTES is always set, even if it's "0" (while the same is not true of IP6_NUM_ROUTES). (This behavior is preserved for compatibility.)
This commit is contained in:
@@ -91,8 +91,8 @@ add_domains (GSList *items,
|
|||||||
static GSList *
|
static GSList *
|
||||||
construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
||||||
{
|
{
|
||||||
GSList *addresses = NULL, *routes = NULL, *iter;
|
GSList *addresses, *routes, *iter;
|
||||||
GArray *dns = NULL, *wins = NULL;
|
GArray *dns, *wins;
|
||||||
guint32 num, i;
|
guint32 num, i;
|
||||||
GString *tmp;
|
GString *tmp;
|
||||||
GValue *val;
|
GValue *val;
|
||||||
@@ -107,7 +107,7 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||||||
|
|
||||||
/* IP addresses */
|
/* IP addresses */
|
||||||
val = g_hash_table_lookup (ip4_config, "addresses");
|
val = g_hash_table_lookup (ip4_config, "addresses");
|
||||||
if (val)
|
if (val) {
|
||||||
addresses = nm_utils_ip4_addresses_from_gvalue (val);
|
addresses = nm_utils_ip4_addresses_from_gvalue (val);
|
||||||
|
|
||||||
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -123,12 +123,12 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||||||
}
|
}
|
||||||
if (num)
|
if (num)
|
||||||
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ADDRESSES=%d", prefix, num));
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ADDRESSES=%d", prefix, num));
|
||||||
if (addresses)
|
|
||||||
g_slist_free_full (addresses, (GDestroyNotify) nm_ip4_address_unref);
|
g_slist_free_full (addresses, (GDestroyNotify) nm_ip4_address_unref);
|
||||||
|
}
|
||||||
|
|
||||||
/* DNS servers */
|
/* DNS servers */
|
||||||
val = g_hash_table_lookup (ip4_config, "nameservers");
|
val = g_hash_table_lookup (ip4_config, "nameservers");
|
||||||
if (val && G_VALUE_HOLDS (val, DBUS_TYPE_G_UINT_ARRAY))
|
if (val && G_VALUE_HOLDS (val, DBUS_TYPE_G_UINT_ARRAY)) {
|
||||||
dns = (GArray *) g_value_get_boxed (val);
|
dns = (GArray *) g_value_get_boxed (val);
|
||||||
|
|
||||||
if (dns && (dns->len > 0)) {
|
if (dns && (dns->len > 0)) {
|
||||||
@@ -148,13 +148,14 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||||||
items = g_slist_prepend (items, tmp->str);
|
items = g_slist_prepend (items, tmp->str);
|
||||||
g_string_free (tmp, FALSE);
|
g_string_free (tmp, FALSE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Search domains */
|
/* Search domains */
|
||||||
items = add_domains (items, ip4_config, prefix, '4');
|
items = add_domains (items, ip4_config, prefix, '4');
|
||||||
|
|
||||||
/* WINS servers */
|
/* WINS servers */
|
||||||
val = g_hash_table_lookup (ip4_config, "wins-servers");
|
val = g_hash_table_lookup (ip4_config, "wins-servers");
|
||||||
if (val && G_VALUE_HOLDS (val, DBUS_TYPE_G_UINT_ARRAY))
|
if (val && G_VALUE_HOLDS (val, DBUS_TYPE_G_UINT_ARRAY)) {
|
||||||
wins = (GArray *) g_value_get_boxed (val);
|
wins = (GArray *) g_value_get_boxed (val);
|
||||||
|
|
||||||
if (wins && wins->len) {
|
if (wins && wins->len) {
|
||||||
@@ -174,10 +175,11 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||||||
items = g_slist_prepend (items, tmp->str);
|
items = g_slist_prepend (items, tmp->str);
|
||||||
g_string_free (tmp, FALSE);
|
g_string_free (tmp, FALSE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Static routes */
|
/* Static routes */
|
||||||
val = g_hash_table_lookup (ip4_config, "routes");
|
val = g_hash_table_lookup (ip4_config, "routes");
|
||||||
if (val)
|
if (val) {
|
||||||
routes = nm_utils_ip4_routes_from_gvalue (val);
|
routes = nm_utils_ip4_routes_from_gvalue (val);
|
||||||
|
|
||||||
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -193,8 +195,9 @@ construct_ip4_items (GSList *items, GHashTable *ip4_config, const char *prefix)
|
|||||||
items = g_slist_prepend (items, routetmp);
|
items = g_slist_prepend (items, routetmp);
|
||||||
}
|
}
|
||||||
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, num));
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, num));
|
||||||
if (routes)
|
|
||||||
g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref);
|
g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||||
|
} else
|
||||||
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=0", prefix));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -223,7 +226,7 @@ construct_device_dhcp4_items (GSList *items, GHashTable *dhcp4_config)
|
|||||||
static GSList *
|
static GSList *
|
||||||
construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
||||||
{
|
{
|
||||||
GSList *addresses = NULL, *routes = NULL, *dns = NULL, *iter;
|
GSList *addresses, *routes, *dns, *iter;
|
||||||
guint32 num;
|
guint32 num;
|
||||||
GString *tmp;
|
GString *tmp;
|
||||||
GValue *val;
|
GValue *val;
|
||||||
@@ -238,7 +241,7 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||||||
|
|
||||||
/* IP addresses */
|
/* IP addresses */
|
||||||
val = g_hash_table_lookup (ip6_config, "addresses");
|
val = g_hash_table_lookup (ip6_config, "addresses");
|
||||||
if (val)
|
if (val) {
|
||||||
addresses = nm_utils_ip6_addresses_from_gvalue (val);
|
addresses = nm_utils_ip6_addresses_from_gvalue (val);
|
||||||
|
|
||||||
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
for (iter = addresses, num = 0; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -254,12 +257,12 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||||||
}
|
}
|
||||||
if (num)
|
if (num)
|
||||||
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ADDRESSES=%d", prefix, num));
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ADDRESSES=%d", prefix, num));
|
||||||
if (addresses)
|
|
||||||
g_slist_free_full (addresses, (GDestroyNotify) nm_ip6_address_unref);
|
g_slist_free_full (addresses, (GDestroyNotify) nm_ip6_address_unref);
|
||||||
|
}
|
||||||
|
|
||||||
/* DNS servers */
|
/* DNS servers */
|
||||||
val = g_hash_table_lookup (ip6_config, "nameservers");
|
val = g_hash_table_lookup (ip6_config, "nameservers");
|
||||||
if (val)
|
if (val) {
|
||||||
dns = nm_utils_ip6_dns_from_gvalue (val);
|
dns = nm_utils_ip6_dns_from_gvalue (val);
|
||||||
|
|
||||||
if (g_slist_length (dns)) {
|
if (g_slist_length (dns)) {
|
||||||
@@ -280,13 +283,14 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||||||
items = g_slist_prepend (items, tmp->str);
|
items = g_slist_prepend (items, tmp->str);
|
||||||
g_string_free (tmp, FALSE);
|
g_string_free (tmp, FALSE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Search domains */
|
/* Search domains */
|
||||||
items = add_domains (items, ip6_config, prefix, '6');
|
items = add_domains (items, ip6_config, prefix, '6');
|
||||||
|
|
||||||
/* Static routes */
|
/* Static routes */
|
||||||
val = g_hash_table_lookup (ip6_config, "routes");
|
val = g_hash_table_lookup (ip6_config, "routes");
|
||||||
if (val)
|
if (val) {
|
||||||
routes = nm_utils_ip6_routes_from_gvalue (val);
|
routes = nm_utils_ip6_routes_from_gvalue (val);
|
||||||
|
|
||||||
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
for (iter = routes, num = 0; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -303,8 +307,8 @@ construct_ip6_items (GSList *items, GHashTable *ip6_config, const char *prefix)
|
|||||||
}
|
}
|
||||||
if (num)
|
if (num)
|
||||||
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ROUTES=%d", prefix, num));
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ROUTES=%d", prefix, num));
|
||||||
if (routes)
|
|
||||||
g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref);
|
g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref);
|
||||||
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user