[goffice] Modify arguments to go_guess_encoding to fix 658916 in view of 648354



commit 5ab5210ac76b2d34001f6d16e53d1b1375804934
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Sep 13 12:28:58 2011 -0600

    Modify arguments to go_guess_encoding to fix 658916 in view of 648354
    
    2011-09-13  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* goffice/utils/go-file.c (go_file_get_owner_name): adjust call
    	to go_guess_encoding
    	(go_file_get_group_name): ditto
    	* goffice/utils/go-glib-extras.h (go_guess_encoding): change
    	arguments
    	* goffice/utils/go-glib-extras.c (go_guess_encoding): change
    	arguments and change all callers

 ChangeLog                      |   10 ++++++++++
 goffice/utils/go-file.c        |   12 ++++++------
 goffice/utils/go-glib-extras.c |   27 +++++++++++++++++++--------
 goffice/utils/go-glib-extras.h |    3 ++-
 4 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 198b352..089d22b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-09-13  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* goffice/utils/go-file.c (go_file_get_owner_name): adjust call
+	to go_guess_encoding
+	(go_file_get_group_name): ditto
+	* goffice/utils/go-glib-extras.h (go_guess_encoding): change
+	arguments
+	* goffice/utils/go-glib-extras.c (go_guess_encoding): change
+	arguments and change all callers
+
 2011-09-08  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* goffice/utils/go-format.c (go_format_refcount_cb): deleted
diff --git a/goffice/utils/go-file.c b/goffice/utils/go-file.c
index 39a1499..487fea0 100644
--- a/goffice/utils/go-file.c
+++ b/goffice/utils/go-file.c
@@ -661,7 +661,7 @@ gchar *
 go_file_get_owner_name (char const *uri)
 {
 	char const *name;
-	char *nameutf8 = NULL;
+	GString *nameutf8 = NULL;
 	GFile *file = g_file_new_for_uri (uri);
 	GError *error = NULL;
 	GFileInfo *info = g_file_query_info (file,
@@ -675,8 +675,8 @@ go_file_get_owner_name (char const *uri)
 
 	name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER);
 	(void) go_guess_encoding (name, strlen (name),
-				  NULL, &nameutf8);
-	return nameutf8;
+				  NULL, &nameutf8, NULL);
+	return (nameutf8 ? g_string_free (nameutf8, FALSE) : NULL);
 }
 
 /*
@@ -687,7 +687,7 @@ gchar *
 go_file_get_group_name (char const *uri)
 {
 	char const *name;
-	char *nameutf8 = NULL;
+	GString *nameutf8 = NULL;
 	GFile *file = g_file_new_for_uri (uri);
 	GError *error = NULL;
 	GFileInfo *info = g_file_query_info (file,
@@ -701,8 +701,8 @@ go_file_get_group_name (char const *uri)
 
 	name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
 	(void) go_guess_encoding (name, strlen (name),
-				  NULL, &nameutf8);
-	return nameutf8;
+				  NULL, &nameutf8, NULL);
+	return (nameutf8 ? g_string_free (nameutf8, FALSE) : NULL);
 }
 
 GOFilePermissions *
diff --git a/goffice/utils/go-glib-extras.c b/goffice/utils/go-glib-extras.c
index e385483..255760e 100644
--- a/goffice/utils/go-glib-extras.c
+++ b/goffice/utils/go-glib-extras.c
@@ -695,7 +695,7 @@ go_str_compare (void const *x, void const *y)
 
 const char *
 go_guess_encoding (const char *raw, size_t len, const char *user_guess,
-		   char **utf8_str)
+		   GString **utf8_str, guint *truncated)
 {
 	int try;
 	gboolean debug = FALSE;
@@ -706,6 +706,8 @@ go_guess_encoding (const char *raw, size_t len, const char *user_guess,
 		char const *guess = NULL;
 		GError *error = NULL;
 		char *utf8_data;
+		gsize bytes_written = 0;
+		gsize bytes_read = 0;
 
 		switch (try) {
 		case 1: guess = user_guess; break;
@@ -743,20 +745,25 @@ go_guess_encoding (const char *raw, size_t len, const char *user_guess,
 			g_print ("Trying %s as encoding.\n", guess);
 
 		utf8_data = g_convert (raw, len, "UTF-8", guess,
-				       NULL, NULL, &error);
+				       &bytes_read, &bytes_written, &error);
 		if (!error) {
 			/*
-			 * We can actually fail this test when gues is UTF-8,
+			 * We can actually fail this test when guess is UTF-8,
 			 * see #401588.
 			 */
-			if (!g_utf8_validate (utf8_data, -1, NULL))
+			if (!g_utf8_validate (utf8_data, -1, NULL)) {
+				g_free (utf8_data);
 				continue;
+			}
 			if (debug)
 				g_print ("Guessed %s as encoding.\n", guess);
 			if (utf8_str)
-				*utf8_str = utf8_data;
+				*utf8_str = g_string_new_len 
+					(utf8_data, bytes_written);
 			else
 				g_free (utf8_data);
+			if (truncated)
+				*truncated = len - bytes_read;
 			return guess;
 		}
 
@@ -782,10 +789,14 @@ go_get_real_name (void)
 			name = g_get_real_name ();
 		if (name == NULL)
 			name = g_get_user_name ();
-		if (name != NULL)
+		if (name != NULL) {
+			GString *converted_name = NULL;
 			(void) go_guess_encoding (name, strlen (name),
-				NULL, &go_real_name);
-		else
+						  NULL, &converted_name, NULL);
+			if (converted_name)
+				go_real_name = g_string_free (converted_name, FALSE);
+		}
+		if (go_real_name == NULL)
 			go_real_name = (char *)"unknown";
 	}
 	return go_real_name;
diff --git a/goffice/utils/go-glib-extras.h b/goffice/utils/go-glib-extras.h
index 4733a5d..ae043c2 100644
--- a/goffice/utils/go-glib-extras.h
+++ b/goffice/utils/go-glib-extras.h
@@ -80,7 +80,8 @@ void        go_string_replace           (GString *target,
 
 char const *go_guess_encoding		(char const *raw, gsize len,
 					 char const *user_guess,
-					 char **utf8_str);
+					 GString **utf8_str,
+					 guint *truncated);
 
 char const *go_get_real_name		(void);
 void	    go_destroy_password	(char *passwd);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]