[gnome-pilot] Fix handling of non-ASCII characters in pilot username. Fixes #641289 2011-02-15 Matt Davey <mcdav



commit 92d68413666359c2840c829dcf2949ebec74b93c
Author: Matt Davey <mcdavey mrao cam ac uk>
Date:   Tue Feb 15 21:22:02 2011 +0000

    Fix handling of non-ASCII characters in pilot username.  Fixes #641289
    2011-02-15  Matt Davey <mcdavey mrao cam ac uk>
           * capplet/pilot.c: Avoid sending non-UTF8 pilot-encoded username
    	over DBUS.  Store username as UTF8 and convert at the last moment
    	when sending/receiving from pda. #641289
           * capplet/gnome-pilot-pdialog.c: ditto
           * gpilotd/gnome-pilot-client.gob: ditto
           * gpilotd/gpilot-daemon.c: ditto

 ChangeLog                      |    8 ++++++++
 capplet/gnome-pilot-pdialog.c  |   17 +++--------------
 capplet/pilot.c                |   24 ++++--------------------
 gpilotd/gnome-pilot-client.gob |    2 ++
 gpilotd/gpilot-daemon.c        |   16 +++++++++++++++-
 5 files changed, 32 insertions(+), 35 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2052f08..a14600b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-02-15  Matt Davey <mcdavey mrao cam ac uk>
+       * capplet/pilot.c: Avoid sending non-UTF8 pilot-encoded username
+	over DBUS.  Store username as UTF8 and convert at the last moment
+	when sending/receiving from pda. #641289
+       * capplet/gnome-pilot-pdialog.c: ditto
+       * gpilotd/gnome-pilot-client.gob: ditto
+       * gpilotd/gpilot-daemon.c: ditto
+
 2011-01-03  Matt Davey <mcdavey mrao cam ac uk>
        * applet/Makefile.am: fix gob rules to support
 		parallel builds.  Thanks Matt McCutchen.  #634874
diff --git a/capplet/gnome-pilot-pdialog.c b/capplet/gnome-pilot-pdialog.c
index b175814..4f5f118 100644
--- a/capplet/gnome-pilot-pdialog.c
+++ b/capplet/gnome-pilot-pdialog.c
@@ -398,13 +398,7 @@ gppd_userinfo_requested (GnomePilotClient *gpc,
 
 	if (priv->pilot->pilot_username) 
 		g_free (priv->pilot->pilot_username);
-#ifndef PILOT_LINK_0_12
-	if (!user->username || (convert_FromPilotChar ("UTF-8", user->username, strlen (user->username), &priv->pilot->pilot_username ) == -1)) {
-#else
-	if (!user->username || (convert_FromPilotChar_WithCharset ("UTF-8", user->username, strlen (user->username), &priv->pilot->pilot_username, NULL ) == -1)) {
-#endif
-  		priv->pilot->pilot_username = g_strdup (user->username);
-	}
+	priv->pilot->pilot_username = g_strdup (user->username);
 
 	gtk_entry_set_text (GTK_ENTRY (priv->pilot_username), priv->pilot->pilot_username);
 	g_snprintf (buf, sizeof (buf), "%d", priv->pilot->pilot_id);
@@ -515,13 +509,8 @@ gppd_pilot_send (GtkWidget *widget, gpointer user_data)
 		read_pilot_config (GTK_OBJECT (gppd), pilot);
 
 		user.userID = pilot->pilot_id;
-#ifndef PILOT_LINK_0_12
-		if (! pilot->pilot_username || (convert_ToPilotChar ("UTF-8", pilot->pilot_username,strlen(pilot->pilot_username),&user.username) == -1)) {
-#else
-		if (! pilot->pilot_username || (convert_ToPilotChar_WithCharset ("UTF-8", pilot->pilot_username, strlen(pilot->pilot_username), &user.username, NULL) == -1)) {
-#endif
-			user.username = g_strdup (pilot->pilot_username);
-		}
+		user.username = g_strdup (pilot->pilot_username);
+
 		if (gnome_pilot_client_set_user_info (priv->gpc, 
 						      dev->name, 
 						      user, 
diff --git a/capplet/pilot.c b/capplet/pilot.c
index fe2d304..5c39f9a 100644
--- a/capplet/pilot.c
+++ b/capplet/pilot.c
@@ -233,7 +233,6 @@ loadPilotPilot (PilotState *p)
 {
   GPilotPilot *pilot;
   gchar *iPilot;
-  char *local_name;
   int i, num;
   GKeyFile *kfile;
   GError *error = NULL;
@@ -270,15 +269,8 @@ loadPilotPilot (PilotState *p)
 			  pilot->pilot_id = getuid ();
                   }
 		  g_message ("Pilot id   -> %d", pilot->pilot_id);
-		  local_name = g_key_file_get_string (kfile, iPilot, "pilotusername", NULL);
-#ifdef PILOT_LINK_0_12
-		  if (!local_name || (convert_FromPilotChar_WithCharset ("UTF-8", local_name, strlen(local_name), &pilot->pilot_username, NULL) == -1)) {
-#else
-		  if (!local_name || (convert_FromPilotChar ("UTF-8", local_name, strlen(local_name), &pilot->pilot_username) == -1)) {
-#endif
-  		  	pilot->pilot_username = g_strdup (local_name);
-		  }
-		  g_free (local_name);
+		  /* username is stored as utf8 */
+		  pilot->pilot_username = g_key_file_get_string (kfile, iPilot, "pilotusername", NULL);
 		  g_message ("Pilot username -> %s", pilot->pilot_username);
 	  
 		  pilot->creation = g_key_file_get_integer (kfile, iPilot, "creation", NULL);
@@ -345,7 +337,6 @@ savePilotState (PilotState *state)
   GList *tmp;
   gchar *iDevice;
   gchar *iPilot;
-  char *local_name;
   GKeyFile *kfile;
 
   kfile = get_gpilotd_kfile ();
@@ -394,15 +385,8 @@ savePilotState (PilotState *state)
 	  g_key_file_set_integer (kfile, iPilot, "pilotid", pilot->pilot_id);
 	  g_key_file_set_integer (kfile, iPilot, "creation", pilot->creation);
 	  g_key_file_set_integer (kfile, iPilot, "romversion", pilot->romversion);
-#ifdef PILOT_LINK_0_12
-	  if (!pilot->pilot_username|| (convert_ToPilotChar_WithCharset ("UTF-8", pilot->pilot_username, strlen (pilot->pilot_username), &local_name, NULL) == -1)) {
-#else
-	  if (!pilot->pilot_username|| (convert_ToPilotChar ("UTF-8", pilot->pilot_username, strlen (pilot->pilot_username), &local_name) == -1)) {
-#endif
-		  local_name = g_strdup (pilot->pilot_username);
-	  }
-	  g_key_file_set_string (kfile, iPilot, "pilotusername", local_name);
-	  g_free (local_name);
+	  /* store username as utf8 */
+	  g_key_file_set_string (kfile, iPilot, "pilotusername", pilot->pilot_username);
 	  g_key_file_set_string (kfile, iPilot, "basedir", pilot->sync_options.basedir);
 #ifdef PILOT_LINK_0_12
 	  g_key_file_set_string (kfile, iPilot, "charset", pilot->pilot_charset);
diff --git a/gpilotd/gnome-pilot-client.gob b/gpilotd/gnome-pilot-client.gob
index b9cd7ed..a3b0061 100644
--- a/gpilotd/gnome-pilot-client.gob
+++ b/gpilotd/gnome-pilot-client.gob
@@ -838,6 +838,8 @@ error:		if (file_copied == FALSE) {
 
 		g_return_val_if_fail (self->proxy != NULL, GPILOTD_ERR_NOT_CONNECTED);
 		error = NULL;
+		if (!g_utf8_validate(user.username, -1, NULL))
+		    g_warning("username not valid utf8");
 		res = dbus_g_proxy_call (self->proxy,
 					"SetUserInfo",
 					&error,
diff --git a/gpilotd/gpilot-daemon.c b/gpilotd/gpilot-daemon.c
index 2fec11f..2fb7e03 100644
--- a/gpilotd/gpilot-daemon.c
+++ b/gpilotd/gpilot-daemon.c
@@ -860,6 +860,7 @@ do_cradle_events (int pfd,
 {
 	GList *events, *it;
 	gboolean ret = TRUE;
+	gchar *pilot_username;
 	
 	/* elements in events freed by gpc_request_purge calls
 	   in dbus_notify_completion */
@@ -879,7 +880,14 @@ do_cradle_events (int pfd,
 		switch (req->type) {
 		case GREQ_SET_USERINFO:
 			g_message (_("Setting userinfo..."));
-			g_snprintf (pu->username,127,"%s", req->parameters.set_userinfo.user_id);
+			/* convert username from UTF-8 to pilot charset */
+			convert_ToPilotChar_WithCharset ("UTF-8",
+					req->parameters.set_userinfo.user_id,
+					strlen(req->parameters.set_userinfo.user_id),
+					&pilot_username, NULL);
+			
+			g_snprintf (pu->username,127,"%s", pilot_username);
+			g_free(pilot_username);
 			pu->userID = req->parameters.set_userinfo.pilot_id;
 			dlp_WriteUserInfo (pfd,pu);
 			if (req->parameters.set_userinfo.continue_sync) {
@@ -2614,6 +2622,12 @@ dbus_notify_userinfo (struct PilotUser    user_info,
 
         /* do a strcpy for username to sending sending too long
          string by dbus */
+	/* also, convert from pilot charset to UTF-8 */
+	convert_FromPilotChar_WithCharset ("UTF-8",
+			user_info.username,
+			strlen (user_info.username),
+			&username, NULL );
+
         username = g_strdup (user_info.username);
 
         message = dbus_message_new_signal (GP_DBUS_PATH,



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