changeset 899:f716c8dbeaff

2007-3-22 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/protocols.c - fixed two remaining codepage related issues: i) The first was a problem parsing the remote_charsets option. ii) The second was the same IConv structure being used for the local and remote side. Each side now has their own IConv structure. (from Alexander Orlov <alxorlov@pochta.ru>)
author masneyb
date Thu, 22 Mar 2007 22:11:27 +0000
parents a5ca449ea12a
children 1e44c7b7f41b
files ChangeLog lib/gftp.h lib/protocols.c
diffstat 3 files changed, 82 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 22 14:51:10 2007 +0000
+++ b/ChangeLog	Thu Mar 22 22:11:27 2007 +0000
@@ -1,3 +1,10 @@
+2007-3-22 Brian Masney <masneyb@gftp.org>
+	* lib/gftp.h lib/protocols.c - fixed two remaining codepage related
+	issues: i) The first was a problem parsing the remote_charsets option.
+	ii) The second was the same IConv structure being used for the local
+	and remote side. Each side now has their own IConv structure.
+	(from Alexander Orlov <alxorlov@pochta.ru>)
+
 2007-3-15 Brian Masney <masneyb@gftp.org>
 	* Makefile.am configure.in - fixes so that automake 1.9 can be used.
 
--- a/lib/gftp.h	Thu Mar 22 14:51:10 2007 +0000
+++ b/lib/gftp.h	Thu Mar 22 22:11:27 2007 +0000
@@ -502,8 +502,9 @@
 #endif
 
 #if GLIB_MAJOR_VERSION > 1
-  GIConv iconv; 
-  unsigned int iconv_initialized : 1;
+  GIConv iconv_to, iconv_from; 
+  unsigned int iconv_from_initialized : 1,
+               iconv_to_initialized : 1;
   char *iconv_charset;
 #endif
 };
--- a/lib/protocols.c	Thu Mar 22 14:51:10 2007 +0000
+++ b/lib/protocols.c	Thu Mar 22 22:11:27 2007 +0000
@@ -157,13 +157,23 @@
 #endif
 
 #if GLIB_MAJOR_VERSION > 1
-  if (request->iconv_initialized)
+  if (request->iconv_from_initialized)
+    {
+      g_iconv_close (request->iconv_from);
+      request->iconv_from_initialized = 0;
+    }
+
+  if (request->iconv_to_initialized)
     {
-      g_iconv_close (request->iconv);
-      request->iconv_initialized = 0;
-      g_free (request->iconv_charset);
-      request->iconv_charset = NULL;
+      g_iconv_close (request->iconv_to);
+      request->iconv_to_initialized = 0;
     }
+
+  if (request->iconv_charset)
+  {
+    g_free (request->iconv_charset);
+    request->iconv_charset = NULL;
+  }
 #endif
 
   request->cached = 0;
@@ -431,6 +441,7 @@
        (*curpos)[retlen - 1] == ' ' || (*curpos)[retlen - 1] == '\t';
        retlen--);
 
+  retlen++; /* Needed due to the len - 1 above... */
   ret = g_malloc0 (retlen + 1);
   memcpy (ret, *curpos, retlen);
 
@@ -502,14 +513,29 @@
       return (ret);
     }
 
-  if (request->iconv_initialized)
+  if (from_utf8)
     {
-      ret = g_convert_with_iconv (str, -1, request->iconv, &bread, dest_len,
-                                  &error);
-      if (ret == NULL)
-        _do_show_iconv_error (str, request->iconv_charset, from_utf8, error);
-
-      return (ret);
+      if (request->iconv_from_initialized)
+        {
+          ret = g_convert_with_iconv (str, -1, request->iconv_from, &bread, dest_len,
+                                      &error);
+          if (ret == NULL)
+            _do_show_iconv_error (str, request->iconv_charset, from_utf8, error);
+
+          return (ret);
+        }
+    }
+  else
+    {
+      if (request->iconv_to_initialized)
+        {
+          ret = g_convert_with_iconv (str, -1, request->iconv_to, &bread, dest_len,
+                                      &error);
+          if (ret == NULL)
+            _do_show_iconv_error (str, request->iconv_charset, from_utf8, error);
+
+          return (ret);
+        }
     }
 
   stpos = remote_charsets;
@@ -519,30 +545,47 @@
         {
           fromset = "UTF-8";
           toset = cur_charset;
+          if ((request->iconv_from = g_iconv_open (toset, fromset)) == (GIConv) -1)
+            {
+              g_free (cur_charset);
+              continue;
+            }
+
+          error = NULL;
+          if ((ret = g_convert_with_iconv (str, -1, request->iconv_from, &bread,
+                                           dest_len, &error)) == NULL)
+            {
+              g_iconv_close (request->iconv_from);
+              request->iconv_from = NULL;
+              _do_show_iconv_error (str, cur_charset, from_utf8, error);
+              g_free (cur_charset);
+            }
+
+          request->iconv_from_initialized = 1;
         }
       else
         {
           fromset = cur_charset;
           toset = "UTF-8";
-        }
-
-      if ((request->iconv = g_iconv_open (toset, fromset)) == (GIConv) -1)
-        {
-          g_free (cur_charset);
-          continue;
+          if ((request->iconv_to = g_iconv_open (toset, fromset)) == (GIConv) -1)
+            {
+              g_free (cur_charset);
+              continue;
+            }
+
+          error = NULL;
+          if ((ret = g_convert_with_iconv (str, -1, request->iconv_to, &bread,
+                                           dest_len, &error)) == NULL)
+            {
+              g_iconv_close (request->iconv_to);
+              request->iconv_to = NULL;
+              _do_show_iconv_error (str, cur_charset, from_utf8, error);
+              g_free (cur_charset);
+            }
+
+          request->iconv_to_initialized = 1;
         }
 
-      error = NULL;
-      if ((ret = g_convert_with_iconv (str, -1, request->iconv, &bread,
-                                       dest_len, &error)) == NULL)
-        {
-          g_iconv_close (request->iconv);
-          request->iconv = NULL;
-          _do_show_iconv_error (str, cur_charset, from_utf8, error);
-          g_free (cur_charset);
-        }
-
-      request->iconv_initialized = 1;
       request->iconv_charset = cur_charset;
       return (ret);
     }