gnome-system-tools r4192 - trunk/src/network
- From: carlosg svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-system-tools r4192 - trunk/src/network
- Date: Fri, 29 Feb 2008 00:41:27 +0000 (GMT)
Author: carlosg
Date: Fri Feb 29 00:41:27 2008
New Revision: 4192
URL: http://svn.gnome.org/viewvc/gnome-system-tools?rev=4192&view=rev
Log:
2008-02-29 Carlos Garnacho <carlosg gnome org>
* network-locations.c (replace_string) (get_location_key_file)
(gst_network_locations_save_current)
(gst_network_locations_delete_location): Slash can be prone to being
used in a location name, replace it with char 0x2044, so the location
file can be saved. Fixes #519270.
Modified:
trunk/src/network/ChangeLog
trunk/src/network/network-locations.c
Modified: trunk/src/network/network-locations.c
==============================================================================
--- trunk/src/network/network-locations.c (original)
+++ trunk/src/network/network-locations.c Fri Feb 29 00:41:27 2008
@@ -28,6 +28,9 @@
#define GST_NETWORK_LOCATIONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GST_TYPE_NETWORK_LOCATIONS, GstNetworkLocationsPrivate))
+/* utf8 char to replace regular slash in location filenames */
+#define SLASH "\342\201\204"
+
typedef struct _GstNetworkLocationsPrivate GstNetworkLocationsPrivate;
struct _GstNetworkLocationsPrivate
@@ -184,6 +187,27 @@
return GST_NETWORK_LOCATIONS (locations);
}
+static gchar *
+replace_string (const gchar *str,
+ const gchar *old,
+ const gchar *new)
+{
+ gchar *new_str;
+
+ if (strstr (str, old))
+ {
+ gchar **splitted_name;
+
+ splitted_name = g_strsplit (str, old, -1);
+ new_str = g_strjoinv (new, splitted_name);
+ g_strfreev (splitted_name);
+ }
+ else
+ new_str = g_strdup (str);
+
+ return new_str;
+}
+
GList*
gst_network_locations_get_names (GstNetworkLocations *locations)
{
@@ -201,7 +225,15 @@
return NULL;
while ((name = g_dir_read_name (dir)) != NULL)
- list = g_list_prepend (list, strdup (name));
+ {
+ gchar *str, *filename;
+
+ filename = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
+ str = replace_string (filename, SLASH, "/");
+ list = g_list_prepend (list, str);
+
+ g_free (filename);
+ }
g_dir_close (dir);
@@ -214,12 +246,15 @@
{
GstNetworkLocationsPrivate *priv;
GKeyFile *key_file;
- gchar *path;
+ gchar *filename, *str, *path;
priv = (GstNetworkLocationsPrivate *) locations->_priv;
key_file = g_key_file_new ();
g_key_file_set_list_separator (key_file, ',');
- path = g_build_filename (priv->dot_dir, name, NULL);
+
+ filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
+ str = replace_string (filename, "/", SLASH);
+ path = g_build_filename (priv->dot_dir, str, NULL);
if (!g_key_file_load_from_file (key_file, path, 0, NULL))
{
@@ -227,7 +262,10 @@
key_file = NULL;
}
+ g_free (filename);
g_free (path);
+ g_free (str);
+
return key_file;
}
@@ -1062,13 +1100,24 @@
gst_network_locations_save_current (GstNetworkLocations *locations,
const gchar *name)
{
+ gchar *filename, *str;
+ gboolean result;
+
g_return_val_if_fail (GST_IS_NETWORK_LOCATIONS (locations), FALSE);
g_return_val_if_fail (name && *name, FALSE);
/* Unset the previous configuration with the same name, if any */
- gst_network_locations_delete_location (locations, name);
+ gst_network_locations_delete_location (locations, filename);
+
+ filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
+ str = replace_string (filename, "/", SLASH);
+
+ result = save_current (locations, str);
- return save_current (locations, name);
+ g_free (filename);
+ g_free (str);
+
+ return result;
}
gboolean
@@ -1076,16 +1125,20 @@
const gchar *name)
{
GstNetworkLocationsPrivate *priv;
- gchar *location_path;
+ gchar *filename, *str, *location_path;
gboolean success;
g_return_val_if_fail (GST_IS_NETWORK_LOCATIONS (locations), FALSE);
priv = GST_NETWORK_LOCATIONS_GET_PRIVATE (locations);
- location_path = g_build_filename (priv->dot_dir, name, NULL);
+
+ filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
+ str = replace_string (filename, "/", SLASH);
+ location_path = g_build_filename (priv->dot_dir, str, NULL);
g_unlink (location_path);
g_free (location_path);
+ g_free (filename);
return success;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]