network-manager-applet r829 - in branches/mbca: . po src src/connection-editor src/gconf-helpers
- From: kaijanma svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r829 - in branches/mbca: . po src src/connection-editor src/gconf-helpers
- Date: Thu, 7 Aug 2008 08:03:43 +0000 (UTC)
Author: kaijanma
Date: Thu Aug 7 08:03:43 2008
New Revision: 829
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=829&view=rev
Log:
keep up with trunk
Modified:
branches/mbca/ChangeLog
branches/mbca/po/ChangeLog
branches/mbca/po/pt_BR.po
branches/mbca/src/applet-device-gsm.c
branches/mbca/src/connection-editor/ce-page-ip4.glade
branches/mbca/src/connection-editor/ip4-routes-dialog.c
branches/mbca/src/connection-editor/ip4-routes-dialog.h
branches/mbca/src/connection-editor/nm-connection-list.c
branches/mbca/src/connection-editor/page-ip4.c
branches/mbca/src/gconf-helpers/gconf-helpers.c
branches/mbca/src/gconf-helpers/gconf-helpers.h
branches/mbca/src/gconf-helpers/gconf-upgrade.c
branches/mbca/src/gconf-helpers/gconf-upgrade.h
Modified: branches/mbca/src/applet-device-gsm.c
==============================================================================
--- branches/mbca/src/applet-device-gsm.c (original)
+++ branches/mbca/src/applet-device-gsm.c Thu Aug 7 08:03:43 2008
@@ -78,7 +78,7 @@
NMSettingConnection *s_con;
NMSettingIP4Config* ipv4conf;
- gboolean ignore_dhcp_dns = FALSE;
+ gboolean ignore_auto_dns = FALSE;
GArray *dns_servers = FALSE;
const char *method;
@@ -126,7 +126,7 @@
if (conf->provider->dns1) {
struct in_addr tmp_addr;
- ignore_dhcp_dns = TRUE;
+ ignore_auto_dns = TRUE;
dns_servers = g_array_new (FALSE, FALSE, sizeof (guint));
inet_aton (conf->provider->dns1, &tmp_addr);
@@ -143,7 +143,7 @@
g_object_set (ipv4conf,
NM_SETTING_IP4_CONFIG_METHOD, method,
NM_SETTING_IP4_CONFIG_DNS, dns_servers,
- NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
NULL);
nm_connection_add_setting (connection, NM_SETTING (s_gsm));
Modified: branches/mbca/src/connection-editor/ce-page-ip4.glade
==============================================================================
--- branches/mbca/src/connection-editor/ce-page-ip4.glade (original)
+++ branches/mbca/src/connection-editor/ce-page-ip4.glade Thu Aug 7 08:03:43 2008
@@ -358,6 +358,19 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkCheckButton" id="ip4_ignore_auto_routes">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Ignore automatically obtained routes</property>
+ <property name="response_id">0</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
Modified: branches/mbca/src/connection-editor/ip4-routes-dialog.c
==============================================================================
--- branches/mbca/src/connection-editor/ip4-routes-dialog.c (original)
+++ branches/mbca/src/connection-editor/ip4-routes-dialog.c Thu Aug 7 08:03:43 2008
@@ -24,6 +24,8 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <errno.h>
+#include <stdlib.h>
#include <glade/glade.h>
#include <glib/gi18n.h>
@@ -32,7 +34,7 @@
#define COL_ADDRESS 0
#define COL_PREFIX 1
-#define COL_GATEWAY 2
+#define COL_NEXT_HOP 2
#define COL_METRIC 3
static void
@@ -184,7 +186,9 @@
}
GtkWidget *
-ip4_routes_dialog_new (GSList *routes)
+ip4_routes_dialog_new (GSList *routes,
+ gboolean automatic,
+ gboolean ignore_auto_routes)
{
GladeXML *xml;
GtkWidget *dialog, *widget;
@@ -218,7 +222,7 @@
/* Add existing routes */
for (iter = routes; iter; iter = g_slist_next (iter)) {
- NMSettingIP4Address *route = (NMSettingIP4Address *) iter->data;
+ NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
struct in_addr tmp_addr;
char ip_string[50];
@@ -235,11 +239,11 @@
gtk_list_store_set (store, &model_iter, COL_PREFIX, g_strdup_printf ("%d", route->prefix), -1);
- tmp_addr.s_addr = route->gateway;
+ tmp_addr.s_addr = route->next_hop;
if (inet_ntop (AF_INET, &tmp_addr, &ip_string[0], sizeof (ip_string)))
- gtk_list_store_set (store, &model_iter, COL_GATEWAY, g_strdup (ip_string), -1);
+ gtk_list_store_set (store, &model_iter, COL_NEXT_HOP, g_strdup (ip_string), -1);
- gtk_list_store_set (store, &model_iter, COL_METRIC, g_strdup_printf ("%d", 1), -1);
+ gtk_list_store_set (store, &model_iter, COL_METRIC, g_strdup_printf ("%d", route->metric), -1);
}
widget = glade_xml_get_widget (xml, "ip4_routes");
@@ -280,12 +284,12 @@
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "editable", TRUE, NULL);
g_signal_connect (renderer, "edited", G_CALLBACK (cell_edited), xml);
- g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER (COL_GATEWAY));
+ g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER (COL_NEXT_HOP));
g_signal_connect (renderer, "editing-started", G_CALLBACK (cell_editing_started), store);
offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (widget),
-1, _("Gateway"), renderer,
- "text", COL_GATEWAY,
+ "text", COL_NEXT_HOP,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (widget), offset - 1);
gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
@@ -322,11 +326,130 @@
G_CALLBACK (route_delete_clicked),
glade_xml_get_widget (xml, "ip4_routes"));
+ widget = glade_xml_get_widget (xml, "ip4_ignore_auto_routes");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), ignore_auto_routes);
+ gtk_widget_set_sensitive (widget, automatic);
+
return dialog;
}
+static gboolean
+get_one_int (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ int column,
+ const char *name,
+ guint32 max_value,
+ guint32 *out)
+{
+ char *item = NULL;
+ gboolean success = FALSE;
+ long int tmp_int;
+
+ gtk_tree_model_get (model, iter, column, &item, -1);
+ if (!item) {
+ g_warning ("%s: IPv4 %s '%s' missing!",
+ __func__, name, item ? item : "<none>");
+ return FALSE;
+ }
+
+ errno = 0;
+ tmp_int = strtol (item, NULL, 10);
+ if (errno || tmp_int < 0 || tmp_int > max_value) {
+ g_warning ("%s: IPv4 %s '%s' invalid!",
+ __func__, name, item ? item : "<none>");
+ goto out;
+ }
+ *out = (guint32) tmp_int;
+ success = TRUE;
+
+out:
+ g_free (item);
+ return success;
+}
+
+static gboolean
+get_one_addr (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ int column,
+ const char *name,
+ gboolean fail_if_missing,
+ guint32 *out)
+{
+ char *item = NULL;
+ struct in_addr tmp_addr;
+ gboolean success = FALSE;
+
+ gtk_tree_model_get (model, iter, column, &item, -1);
+ if (!item && !fail_if_missing)
+ return TRUE;
+
+ if (item && (inet_pton (AF_INET, item, &tmp_addr) > 0)) {
+ *out = tmp_addr.s_addr;
+ success = TRUE;
+ } else {
+ g_warning ("%s: IPv4 %s '%s' missing or invalid!",
+ __func__, name, item ? item : "<none>");
+ }
+
+ g_free (item);
+ return success;
+}
+
void
ip4_routes_dialog_update_setting (GtkWidget *dialog, NMSettingIP4Config *s_ip4)
{
+ GladeXML *xml;
+ GtkWidget *widget;
+ GtkTreeModel *model;
+ GtkTreeIter tree_iter;
+ gboolean iter_valid;
+
+ g_return_if_fail (dialog != NULL);
+ g_return_if_fail (s_ip4 != NULL);
+
+ xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
+ g_return_if_fail (xml != NULL);
+ g_return_if_fail (GLADE_IS_XML (xml));
+
+ widget = glade_xml_get_widget (xml, "ip4_routes");
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+ iter_valid = gtk_tree_model_get_iter_first (model, &tree_iter);
+
+ g_slist_foreach (s_ip4->routes, (GFunc) g_free, NULL);
+ g_slist_free (s_ip4->routes);
+ s_ip4->routes = NULL;
+
+ while (iter_valid) {
+ guint32 addr = 0, prefix = 0, next_hop = 0, metric = 0;
+ NMSettingIP4Route *route;
+
+ /* Address */
+ if (!get_one_addr (model, &tree_iter, COL_ADDRESS, "address", TRUE, &addr))
+ goto next;
+
+ /* Prefix */
+ if (!get_one_int (model, &tree_iter, COL_PREFIX, "prefix", 32, &prefix))
+ goto next;
+
+ /* Next hop (optional) */
+ get_one_addr (model, &tree_iter, COL_NEXT_HOP, "next hop", TRUE, &next_hop);
+
+ /* Prefix (optional) */
+ get_one_int (model, &tree_iter, COL_METRIC, "metric", G_MAXUINT32, &metric);
+
+ route = g_malloc0 (sizeof (NMSettingIP4Route));
+ route->address = addr;
+ route->prefix = prefix;
+ route->next_hop = next_hop;
+ route->metric = metric;
+
+ s_ip4->routes = g_slist_append (s_ip4->routes, route);
+
+ next:
+ iter_valid = gtk_tree_model_iter_next (model, &tree_iter);
+ }
+
+ widget = glade_xml_get_widget (xml, "ip4_ignore_auto_routes");
+ s_ip4->ignore_auto_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
}
Modified: branches/mbca/src/connection-editor/ip4-routes-dialog.h
==============================================================================
--- branches/mbca/src/connection-editor/ip4-routes-dialog.h (original)
+++ branches/mbca/src/connection-editor/ip4-routes-dialog.h Thu Aug 7 08:03:43 2008
@@ -28,7 +28,9 @@
#include "nm-setting-ip4-config.h"
-GtkWidget *ip4_routes_dialog_new (GSList *routes);
+GtkWidget *ip4_routes_dialog_new (GSList *routes,
+ gboolean automatic,
+ gboolean ignore_auto_routes);
void ip4_routes_dialog_update_setting (GtkWidget *dialog, NMSettingIP4Config *s_ip4);
Modified: branches/mbca/src/connection-editor/nm-connection-list.c
==============================================================================
--- branches/mbca/src/connection-editor/nm-connection-list.c (original)
+++ branches/mbca/src/connection-editor/nm-connection-list.c Thu Aug 7 08:03:43 2008
@@ -753,7 +753,7 @@
NMConnectionList *list = user_data;
NMSettingIP4Config* ipv4conf;
- gboolean ignore_dhcp_dns = FALSE;
+ gboolean ignore_auto_dns = FALSE;
GArray *dns_servers = FALSE;
const char *method;
@@ -796,7 +796,7 @@
if (conf->provider->dns1) {
struct in_addr tmp_addr;
- ignore_dhcp_dns = TRUE;
+ ignore_auto_dns = TRUE;
dns_servers = g_array_new (FALSE, FALSE, sizeof (guint));
inet_aton (conf->provider->dns1, &tmp_addr);
@@ -827,7 +827,7 @@
g_object_set (ipv4conf,
NM_SETTING_IP4_CONFIG_METHOD, method,
NM_SETTING_IP4_CONFIG_DNS, dns_servers,
- NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
NULL);
if (type_setting) {
Modified: branches/mbca/src/connection-editor/page-ip4.c
==============================================================================
--- branches/mbca/src/connection-editor/page-ip4.c (original)
+++ branches/mbca/src/connection-editor/page-ip4.c Thu Aug 7 08:03:43 2008
@@ -76,7 +76,7 @@
#define METHOD_COL_NUM 1
#define IP4_METHOD_AUTO 0
-#define IP4_METHOD_AUTO_MANUAL_DNS 1
+#define IP4_METHOD_AUTO_ADDRESSES 1
#define IP4_METHOD_MANUAL 2
#define IP4_METHOD_LINK_LOCAL 3
#define IP4_METHOD_SHARED 4
@@ -106,8 +106,8 @@
gtk_list_store_append (priv->method_store, &iter);
gtk_list_store_set (priv->method_store, &iter,
- METHOD_COL_NAME, _("Automatic with manual DNS settings"),
- METHOD_COL_NUM, IP4_METHOD_AUTO_MANUAL_DNS,
+ METHOD_COL_NAME, _("Automatic addresses only"),
+ METHOD_COL_NUM, IP4_METHOD_AUTO_ADDRESSES,
-1);
gtk_list_store_append (priv->method_store, &iter);
@@ -123,13 +123,13 @@
METHOD_COL_NAME, _("Link-Local Only"),
METHOD_COL_NUM, IP4_METHOD_LINK_LOCAL,
-1);
- }
- gtk_list_store_append (priv->method_store, &iter);
- gtk_list_store_set (priv->method_store, &iter,
- METHOD_COL_NAME, _("Shared to other computers"),
- METHOD_COL_NUM, IP4_METHOD_SHARED,
- -1);
+ gtk_list_store_append (priv->method_store, &iter);
+ gtk_list_store_set (priv->method_store, &iter,
+ METHOD_COL_NAME, _("Shared to other computers"),
+ METHOD_COL_NUM, IP4_METHOD_SHARED,
+ -1);
+ }
gtk_combo_box_set_model (priv->method, GTK_TREE_MODEL (priv->method_store));
@@ -170,7 +170,7 @@
case IP4_METHOD_AUTO:
dhcp_enabled = routes_enabled = TRUE;
break;
- case IP4_METHOD_AUTO_MANUAL_DNS:
+ case IP4_METHOD_AUTO_ADDRESSES:
addr_enabled = FALSE;
dns_enabled = dhcp_enabled = routes_enabled = TRUE;
break;
@@ -254,8 +254,8 @@
method = IP4_METHOD_SHARED;
}
- if (method == IP4_METHOD_AUTO && setting->ignore_dhcp_dns)
- method = IP4_METHOD_AUTO_MANUAL_DNS;
+ if (method == IP4_METHOD_AUTO && setting->ignore_auto_dns)
+ method = IP4_METHOD_AUTO_ADDRESSES;
info.method = method;
info.combo = priv->method;
@@ -324,7 +324,7 @@
gtk_entry_set_text (priv->dns_searches, string->str);
g_string_free (string, TRUE);
- if ((method == IP4_METHOD_AUTO) || (method = IP4_METHOD_AUTO_MANUAL_DNS)) {
+ if ((method == IP4_METHOD_AUTO) || (method = IP4_METHOD_AUTO_ADDRESSES)) {
if (setting->dhcp_client_id)
gtk_entry_set_text (priv->dhcp_client_id, setting->dhcp_client_id);
}
@@ -499,11 +499,15 @@
CEPageIP4 *self = CE_PAGE_IP4 (user_data);
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
GtkWidget *dialog, *toplevel;
+ gboolean automatic = FALSE;
toplevel = gtk_widget_get_toplevel (CE_PAGE (self)->page);
g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel));
- dialog = ip4_routes_dialog_new (priv->setting->routes);
+ if (!strcmp (priv->setting->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
+ automatic = TRUE;
+
+ dialog = ip4_routes_dialog_new (priv->setting->routes, automatic, priv->setting->ignore_auto_routes);
if (!dialog) {
g_warning ("%s: failed to create the routes dialog!", __func__);
return;
@@ -666,7 +670,7 @@
GPtrArray *addresses = NULL;
gboolean valid = FALSE, iter_valid;
const char *text;
- gboolean ignore_dhcp_dns = FALSE;
+ gboolean ignore_auto_dns = FALSE;
const char *dhcp_client_id = NULL;
char **items = NULL, **iter;
@@ -686,8 +690,8 @@
case IP4_METHOD_SHARED:
method = NM_SETTING_IP4_CONFIG_METHOD_SHARED;
break;
- case IP4_METHOD_AUTO_MANUAL_DNS:
- ignore_dhcp_dns = TRUE;
+ case IP4_METHOD_AUTO_ADDRESSES:
+ ignore_auto_dns = TRUE;
/* fall through */
default:
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
@@ -806,7 +810,7 @@
NM_SETTING_IP4_CONFIG_ADDRESSES, addresses,
NM_SETTING_IP4_CONFIG_DNS, dns_servers,
NM_SETTING_IP4_CONFIG_DNS_SEARCH, search_domains,
- NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, dhcp_client_id,
NULL);
valid = TRUE;
Modified: branches/mbca/src/gconf-helpers/gconf-helpers.c
==============================================================================
--- branches/mbca/src/gconf-helpers/gconf-helpers.c (original)
+++ branches/mbca/src/gconf-helpers/gconf-helpers.c Thu Aug 7 08:03:43 2008
@@ -31,6 +31,7 @@
#include <nm-setting-wireless-security.h>
#include <nm-setting-8021x.h>
#include <nm-setting-vpn.h>
+#include <nm-setting-ip4-config.h>
#include <nm-utils.h>
#include <nm-settings.h>
@@ -401,52 +402,62 @@
}
gboolean
-nm_gconf_get_ip4_addresses_helper (GConfClient *client,
+nm_gconf_get_ip4_helper (GConfClient *client,
const char *path,
const char *key,
const char *network,
+ guint32 tuple_len,
GPtrArray **value)
{
char *gc_key;
- GConfValue *gc_value;
+ GConfValue *gc_value = NULL;
GPtrArray *array;
gboolean success = FALSE;
+ GSList *values, *iter;
+ GArray *tuple = NULL;
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (network != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
+ g_return_val_if_fail (tuple_len > 0, FALSE);
gc_key = g_strdup_printf ("%s/%s/%s", path, network, key);
if (!(gc_value = gconf_client_get (client, gc_key, NULL)))
goto out;
- if (gc_value->type == GCONF_VALUE_LIST
- && gconf_value_get_list_type (gc_value) == GCONF_VALUE_INT)
- {
- GSList *elt;
- GArray *tuple = NULL;
+ if ( (gc_value->type != GCONF_VALUE_LIST)
+ || (gconf_value_get_list_type (gc_value) != GCONF_VALUE_INT))
+ goto out;
- array = g_ptr_array_sized_new (1);
- for (elt = gconf_value_get_list (gc_value); elt != NULL; elt = g_slist_next (elt)) {
- int i = gconf_value_get_int ((GConfValue *) elt->data);
+ values = gconf_value_get_list (gc_value);
+ if (g_slist_length (values) % tuple_len != 0) {
+ g_warning ("%s: %s format invalid; # elements not divisible by %d",
+ __func__, gc_key, tuple_len);
+ goto out;
+ }
- if (tuple == NULL)
- tuple = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
+ array = g_ptr_array_sized_new (1);
+ for (iter = values; iter; iter = g_slist_next (iter)) {
+ int i = gconf_value_get_int ((GConfValue *) iter->data);
- g_array_append_val (tuple, i);
+ if (tuple == NULL)
+ tuple = g_array_sized_new (FALSE, TRUE, sizeof (guint32), tuple_len);
- /* Got addr, netmask, and gateway, add to ptr array */
- if (tuple->len == 3) {
- g_ptr_array_add (array, tuple);
- tuple = NULL;
- }
- }
+ g_array_append_val (tuple, i);
- *value = array;
- success = TRUE;
+ /* Got all members; add to the array */
+ if (tuple->len == tuple_len) {
+ g_ptr_array_add (array, tuple);
+ tuple = NULL;
+ }
}
+ *value = array;
+ success = TRUE;
+
out:
+ if (gc_value)
+ gconf_value_free (gc_value);
g_free (gc_key);
return success;
}
@@ -690,10 +701,11 @@
}
gboolean
-nm_gconf_set_ip4_addresses_helper (GConfClient *client,
+nm_gconf_set_ip4_helper (GConfClient *client,
const char *path,
const char *key,
const char *network,
+ guint32 tuple_len,
GPtrArray *value)
{
char *gc_key;
@@ -703,6 +715,7 @@
g_return_val_if_fail (key != NULL, FALSE);
g_return_val_if_fail (network != NULL, FALSE);
+ g_return_val_if_fail (tuple_len > 0, FALSE);
if (!value)
return TRUE;
@@ -715,22 +728,15 @@
for (i = 0; i < value->len; i++) {
GArray *tuple = g_ptr_array_index (value, i);
+ int j;
- if ((tuple->len < 2) || (tuple->len > 3)) {
- g_warning ("%s: invalid IPv4 address structure!", __func__);
+ if (tuple->len != tuple_len) {
+ g_warning ("%s: invalid IPv4 address/route structure!", __func__);
goto out;
}
- /* IP address */
- list = g_slist_append (list, GUINT_TO_POINTER (g_array_index (tuple, guint32, 0)));
- /* Netmask */
- list = g_slist_append (list, GUINT_TO_POINTER (g_array_index (tuple, guint32, 1)));
-
- /* Gateway */
- if (tuple->len == 3)
- list = g_slist_append (list, GUINT_TO_POINTER (g_array_index (tuple, guint32, 2)));
- else
- list = g_slist_append (list, GUINT_TO_POINTER (0));
+ for (j = 0; j < tuple_len; j++)
+ list = g_slist_append (list, GUINT_TO_POINTER (g_array_index (tuple, guint32, j)));
}
gconf_client_set_list (client, gc_key, GCONF_VALUE_INT, list, NULL);
@@ -753,6 +759,8 @@
nm_gconf_migrate_0_7_wireless_security (client);
nm_gconf_migrate_0_7_netmask_to_prefix (client);
nm_gconf_migrate_0_7_ip4_method (client);
+ nm_gconf_migrate_0_7_ignore_dhcp_dns (client);
+ nm_gconf_migrate_0_7_vpn_routes (client);
connections = gconf_client_all_dirs (client, GCONF_PATH_CONNECTIONS, NULL);
if (!connections) {
@@ -879,8 +887,14 @@
}
} else if (type == DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT) {
GPtrArray *pa_val = NULL;
+ guint32 tuple_len = 0;
+
+ if (!strcmp (key, NM_SETTING_IP4_CONFIG_ADDRESSES))
+ tuple_len = 3;
+ else if (!strcmp (key, NM_SETTING_IP4_CONFIG_ROUTES))
+ tuple_len = 4;
- if (nm_gconf_get_ip4_addresses_helper (info->client, info->dir, key, setting->name, &pa_val)) {
+ if (nm_gconf_get_ip4_helper (info->client, info->dir, key, setting->name, tuple_len, &pa_val)) {
g_object_set (setting, key, pa_val, NULL);
g_ptr_array_foreach (pa_val, (GFunc) free_one_addr, NULL);
g_ptr_array_free (pa_val, TRUE);
@@ -1139,8 +1153,15 @@
key, setting->name,
(GArray *) g_value_get_boxed (value));
} else if (type == DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT) {
- nm_gconf_set_ip4_addresses_helper (info->client, info->dir,
- key, setting->name,
+ guint32 tuple_len = 0;
+
+ if (!strcmp (key, NM_SETTING_IP4_CONFIG_ADDRESSES))
+ tuple_len = 3;
+ else if (!strcmp (key, NM_SETTING_IP4_CONFIG_ROUTES))
+ tuple_len = 4;
+
+ nm_gconf_set_ip4_helper (info->client, info->dir,
+ key, setting->name, tuple_len,
(GPtrArray *) g_value_get_boxed (value));
} else
g_warning ("Unhandled setting property type (write) '%s/%s' : '%s'",
Modified: branches/mbca/src/gconf-helpers/gconf-helpers.h
==============================================================================
--- branches/mbca/src/gconf-helpers/gconf-helpers.h (original)
+++ branches/mbca/src/gconf-helpers/gconf-helpers.h Thu Aug 7 08:03:43 2008
@@ -108,10 +108,11 @@
GHashTable **value);
gboolean
-nm_gconf_get_ip4_addresses_helper (GConfClient *client,
+nm_gconf_get_ip4_helper (GConfClient *client,
const char *path,
const char *key,
const char *network,
+ guint32 tuple_len,
GPtrArray **value);
/* Setters */
@@ -172,10 +173,11 @@
GHashTable *value);
gboolean
-nm_gconf_set_ip4_addresses_helper (GConfClient *client,
+nm_gconf_set_ip4_helper (GConfClient *client,
const char *path,
const char *key,
const char *network,
+ guint32 tuple_len,
GPtrArray *value);
GSList *
Modified: branches/mbca/src/gconf-helpers/gconf-upgrade.c
==============================================================================
--- branches/mbca/src/gconf-helpers/gconf-upgrade.c (original)
+++ branches/mbca/src/gconf-helpers/gconf-upgrade.c Thu Aug 7 08:03:43 2008
@@ -27,6 +27,9 @@
#include <string.h>
#include "wireless-helper.h"
#include <stdlib.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <arpa/inet.h>
#include <gnome-keyring.h>
#include <nm-setting-connection.h>
@@ -504,6 +507,50 @@
return s_vpn_props;
}
+static GSList *
+convert_routes (GSList *str_routes)
+{
+ GSList *routes = NULL, *iter;
+
+ for (iter = str_routes; iter; iter = g_slist_next (iter)) {
+ struct in_addr tmp;
+ char *p, *str_route;
+ long int prefix = 32;
+
+ str_route = g_strdup (iter->data);
+ p = strchr (str_route, '/');
+ if (!p || !(*(p + 1))) {
+ g_warning ("Ignoring invalid route '%s'", str_route);
+ goto next;
+ }
+
+ errno = 0;
+ prefix = strtol (p + 1, NULL, 10);
+ if (errno || prefix <= 0 || prefix > 32) {
+ g_warning ("Ignoring invalid route '%s'", str_route);
+ goto next;
+ }
+
+ /* don't pass the prefix to inet_pton() */
+ *p = '\0';
+ if (inet_pton (AF_INET, str_route, &tmp) > 0) {
+ NMSettingIP4Route *route;
+
+ route = g_new0 (NMSettingIP4Route, 1);
+ route->address = tmp.s_addr;
+ route->prefix = (guint32) prefix;
+
+ routes = g_slist_append (routes, route);
+ } else
+ g_warning ("Ignoring invalid route '%s'", str_route);
+
+next:
+ g_free (str_route);
+ }
+
+ return routes;
+}
+
static NMConnection *
nm_gconf_read_0_6_vpn_connection (GConfClient *client,
const char *dir)
@@ -512,8 +559,9 @@
NMSettingConnection *s_con;
NMSettingVPN *s_vpn;
NMSettingVPNProperties *s_vpn_props;
+ NMSettingIP4Config *s_ip4 = NULL;
char *path, *network, *id = NULL, *service_name = NULL;
- GSList *routes = NULL, *vpn_data = NULL;
+ GSList *str_routes = NULL, *vpn_data = NULL;
path = g_path_get_dirname (dir);
network = g_path_get_basename (dir);
@@ -530,10 +578,10 @@
return NULL;
}
- if (!nm_gconf_get_stringlist_helper (client, path, "routes", network, &routes))
- routes = NULL;
+ if (!nm_gconf_get_stringlist_helper (client, path, "routes", network, &str_routes))
+ str_routes = NULL;
if (!nm_gconf_get_stringlist_helper (client, path, "vpn_data", network, &vpn_data))
- routes = NULL;
+ vpn_data = NULL;
s_con = (NMSettingConnection *)nm_setting_connection_new ();
s_con->id = id;
@@ -541,7 +589,6 @@
s_vpn = (NMSettingVPN *)nm_setting_vpn_new ();
s_vpn->service_type = service_name;
- s_vpn->routes = routes;
if (!strcmp (service_name, "org.freedesktop.NetworkManager.vpnc"))
s_vpn_props = nm_gconf_0_6_vpnc_settings (vpn_data);
@@ -556,11 +603,18 @@
g_free (path);
g_free (network);
+ if (str_routes) {
+ s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ s_ip4->routes = convert_routes (str_routes);
+ }
+
connection = nm_connection_new ();
- nm_connection_add_setting (connection, (NMSetting *)s_con);
- nm_connection_add_setting (connection, (NMSetting *)s_vpn);
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+ nm_connection_add_setting (connection, NM_SETTING (s_vpn));
if (s_vpn_props)
- nm_connection_add_setting (connection, (NMSetting *)s_vpn_props);
+ nm_connection_add_setting (connection, NM_SETTING (s_vpn_props));
+ if (s_ip4)
+ nm_connection_add_setting (connection, NM_SETTING (s_vpn_props));
return connection;
}
@@ -1101,3 +1155,169 @@
gconf_client_suggest_sync (client, NULL);
}
+#define IP4_KEY_IGNORE_DHCP_DNS "ignore-dhcp-dns"
+
+void
+nm_gconf_migrate_0_7_ignore_dhcp_dns (GConfClient *client)
+{
+ GSList *connections, *iter;
+
+ connections = gconf_client_all_dirs (client, GCONF_PATH_CONNECTIONS, NULL);
+ for (iter = connections; iter; iter = iter->next) {
+ char *del_key;
+ gboolean ignore_auto_dns = FALSE;
+
+ if (!nm_gconf_get_bool_helper (client, iter->data,
+ IP4_KEY_IGNORE_DHCP_DNS,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ &ignore_auto_dns))
+ continue;
+
+ /* add new key with new name */
+ if (ignore_auto_dns) {
+ nm_gconf_set_bool_helper (client, iter->data,
+ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ ignore_auto_dns);
+ }
+
+ /* delete old key */
+ del_key = g_strdup_printf ("%s/%s/%s",
+ (const char *) iter->data,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ IP4_KEY_IGNORE_DHCP_DNS);
+ gconf_client_unset (client, del_key, NULL);
+ g_free (del_key);
+ }
+ free_slist (connections);
+
+ gconf_client_suggest_sync (client, NULL);
+}
+
+static gboolean
+convert_route (const char *in_route, NMSettingIP4Route *converted)
+{
+ struct in_addr tmp;
+ char *p, *str_route;
+ long int prefix = 32;
+ gboolean success = FALSE;
+
+ memset (converted, 0, sizeof (*converted));
+
+ str_route = g_strdup (in_route);
+ p = strchr (str_route, '/');
+ if (!p || !(*(p + 1))) {
+ g_warning ("Ignoring invalid route '%s'", str_route);
+ goto out;
+ }
+
+ errno = 0;
+ prefix = strtol (p + 1, NULL, 10);
+ if (errno || prefix <= 0 || prefix > 32) {
+ g_warning ("Ignoring invalid route '%s'", str_route);
+ goto out;
+ }
+
+ /* don't pass the prefix to inet_pton() */
+ *p = '\0';
+ if (inet_pton (AF_INET, str_route, &tmp) <= 0) {
+ g_warning ("Ignoring invalid route '%s'", str_route);
+ goto out;
+ }
+
+ converted->address = tmp.s_addr;
+ converted->prefix = (guint32) prefix;
+ success = TRUE;
+
+out:
+ g_free (str_route);
+ return success;
+}
+
+#define VPN_KEY_ROUTES "routes"
+
+static void
+free_one_route (gpointer data, gpointer user_data)
+{
+ g_array_free ((GArray *) data, TRUE);
+}
+
+void
+nm_gconf_migrate_0_7_vpn_routes (GConfClient *client)
+{
+ GSList *connections, *iter;
+
+ connections = gconf_client_all_dirs (client, GCONF_PATH_CONNECTIONS, NULL);
+ for (iter = connections; iter; iter = iter->next) {
+ char *del_key;
+ GSList *old_routes = NULL, *routes_iter;
+ GPtrArray *new_routes = NULL;
+
+ if (!nm_gconf_get_stringlist_helper (client, iter->data,
+ VPN_KEY_ROUTES,
+ NM_SETTING_VPN_SETTING_NAME,
+ &old_routes))
+ continue;
+
+ /* Convert 'x.x.x.x/x' into a route structure */
+ for (routes_iter = old_routes; routes_iter; routes_iter = g_slist_next (routes_iter)) {
+ NMSettingIP4Route route;
+
+ if (convert_route (routes_iter->data, &route)) {
+ GArray *tmp_route;
+
+ if (!new_routes)
+ new_routes = g_ptr_array_sized_new (3);
+
+ tmp_route = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
+ g_array_append_val (tmp_route, route.address);
+ g_array_append_val (tmp_route, route.prefix);
+ g_array_append_val (tmp_route, route.next_hop);
+ g_array_append_val (tmp_route, route.metric);
+ g_ptr_array_add (new_routes, tmp_route);
+ }
+ }
+
+ if (new_routes) {
+ char *method = NULL;
+
+ /* Set new routes */
+ nm_gconf_set_ip4_helper (client, iter->data,
+ NM_SETTING_IP4_CONFIG_ROUTES,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ 4,
+ new_routes);
+
+ g_ptr_array_foreach (new_routes, (GFunc) free_one_route, NULL);
+ g_ptr_array_free (new_routes, TRUE);
+
+ /* To make a valid ip4 setting, need a method too */
+ if (!nm_gconf_get_string_helper (client, iter->data,
+ NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ &method)) {
+ /* If no method was specified, use 'auto' */
+ nm_gconf_set_string_helper (client, iter->data,
+ NM_SETTING_IP4_CONFIG_METHOD,
+ NM_SETTING_IP4_CONFIG_SETTING_NAME,
+ NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ }
+ g_free (method);
+ }
+
+ /* delete old key */
+ del_key = g_strdup_printf ("%s/%s/%s",
+ (const char *) iter->data,
+ NM_SETTING_VPN_SETTING_NAME,
+ VPN_KEY_ROUTES);
+ gconf_client_unset (client, del_key, NULL);
+ g_free (del_key);
+
+ g_slist_foreach (old_routes, (GFunc) g_free, NULL);
+ g_slist_free (old_routes);
+ }
+ free_slist (connections);
+
+ gconf_client_suggest_sync (client, NULL);
+}
+
Modified: branches/mbca/src/gconf-helpers/gconf-upgrade.h
==============================================================================
--- branches/mbca/src/gconf-helpers/gconf-upgrade.h (original)
+++ branches/mbca/src/gconf-helpers/gconf-upgrade.h Thu Aug 7 08:03:43 2008
@@ -38,5 +38,9 @@
void nm_gconf_migrate_0_7_ip4_method (GConfClient *client);
+void nm_gconf_migrate_0_7_ignore_dhcp_dns (GConfClient *client);
+
+void nm_gconf_migrate_0_7_vpn_routes (GConfClient *client);
+
#endif /* GCONF_UPGRADE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]