diff lib/protocols.c @ 207:cf4098008615

2003-7-1 Brian Masney <masneyb@gftp.org> * lib/httpcommon.h lib/rfc2068.c - more HTTP improvements. Mostly with chunked file transfers. Also fixed several memory leaks. Added more informative error messages to aid in debugging. Size parsing fixes * lib/misc.c (base64_encode) - alphabet fix (+ wasn't a valid character, it should have been /) (thanks to Holger Kiehl <Holger.Kiehl@dwd.de> for pointing this out) * lib/config_file.c lib/gftp.h - added copy function for options variables. The functions gftp_config_file_copy_text(), gftp_config_file_copy_ptr_contents() and gftp_config_file_copy_color() were added * lib/protocols.c - make sure the remote_charsets string is restored properly after it is used * src/gtk/bookmarks.c - remove memory leak comments, these are fixed now * src/gtk/transfer.c - removed start_file_transfers variable * src/gtk/misc-gtk.c src/gtk/gftp-gtk.h lib/misc.c lib/gftp.h - moved get_next_selection() to lib * acinclude.h (AC_TYPE_SOCKLEN_T) - AC_DEFINE fix (from Nathan Robertson <nathanr@nathanr.net>)
author masneyb
date Wed, 02 Jul 2003 01:44:57 +0000
parents 0098dae654a5
children d79e2782eb1b
line wrap: on
line diff
--- a/lib/protocols.c	Sat Jun 28 13:52:44 2003 +0000
+++ b/lib/protocols.c	Wed Jul 02 01:44:57 2003 +0000
@@ -339,7 +339,7 @@
 
 #if GLIB_MAJOR_VERSION > 1
 static char *
-_gftp_get_next_charset (char *remote_charsets, char **curpos)
+_gftp_get_next_charset (char *remote_charsets, char *orig_str, char **curpos)
 {
   char *ret, *endpos;
 
@@ -348,24 +348,39 @@
 
   ret = *curpos;
   if (*curpos != remote_charsets)
-    *(*curpos - 1) = ',';
+    {
+      *orig_str = *(*curpos - 1);
+      *(*curpos - 1) = ',';
+    }
 
   if ((endpos = strchr (*curpos, ',')) == NULL)
     *curpos += strlen (*curpos);
   else
     {
       *endpos = '\0';
-      *curpos = endpos + 1;
+
+      if (*orig_str != '\0')
+        *curpos = endpos + 1;
+      else
+        *curpos = endpos;
     }
 
   return (ret);
 }
 
 
+static void
+_gftp_restore_charset_string (char **remote_charsets, char orig_str, char **curpos)
+{
+  if (*curpos != *remote_charsets)
+    *(*curpos - 1) = orig_str;
+}
+
+
 char *
 gftp_string_to_utf8 (gftp_request * request, char *str)
 {
-  char *ret, *remote_charsets, *stpos, *cur_charset;
+  char *ret, *remote_charsets, *stpos, *cur_charset, orig_str;
   gsize bread, bwrite;
   GError * error;
 
@@ -388,7 +403,7 @@
 
   ret = NULL;
   stpos = remote_charsets;
-  while ((cur_charset = _gftp_get_next_charset (remote_charsets, 
+  while ((cur_charset = _gftp_get_next_charset (remote_charsets, &orig_str,
                                                 &stpos)) != NULL)
     {
       if ((request->iconv = g_iconv_open ("UTF-8", cur_charset)) == (GIConv) -1)
@@ -405,10 +420,9 @@
       else
         {
           request->iconv_initialized = 1;
+          _gftp_restore_charset_string (&remote_charsets, *cur_charset, &stpos);
           break;
         }
-
-      /* FIXME 2.0.15 - fix NUL character in remote_charsets */
     }
 
   return (ret);