From 1a81a48bb8a1a355ebd227301759a993b9efc5bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1=D1?=
 =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Tue, 27 Dec 2011 15:46:54 +0400
Subject: [PATCH 1/4] Assume UTF-8 (remove loc-conversion), except for
 Extractor-produced data

---
 src/fs/gnunet-fs-gtk-common.c                      |    6 ++--
 src/fs/gnunet-fs-gtk-download.c                    |    9 +----
 src/fs/gnunet-fs-gtk-event_handler.c               |   10 +-----
 src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c   |    7 +---
 .../gnunet-fs-gtk-main_window_create_pseudonym.c   |    7 +---
 src/fs/gnunet-fs-gtk-main_window_file_publish.c    |   33 +++++--------------
 src/fs/gnunet-fs-gtk-main_window_open_directory.c  |    9 ++---
 7 files changed, 22 insertions(+), 59 deletions(-)

diff --git a/src/fs/gnunet-fs-gtk-common.c b/src/fs/gnunet-fs-gtk-common.c
index 4d41684..c4058cd 100644
--- a/src/fs/gnunet-fs-gtk-common.c
+++ b/src/fs/gnunet-fs-gtk-common.c
@@ -60,9 +60,9 @@ GNUNET_FS_GTK_dubious_meta_to_utf8 (enum EXTRACTOR_MetaFormat format,
   if (format == EXTRACTOR_METAFORMAT_C_STRING)
   {
     if (data_len > 0)
-    {                           /* There are no guarantees that data is NULL-terminated, AFAIU,
-                                 * so let's play it safe, shall we?
-                                 */
+    { /* There are no guarantees that data is NULL-terminated, AFAIU,
+      * so let's play it safe, shall we?
+      */
       char *data_copy = GNUNET_malloc (data_len + 1);
 
       memcpy (data_copy, data, data_len);
diff --git a/src/fs/gnunet-fs-gtk-download.c b/src/fs/gnunet-fs-gtk-download.c
index ee6b192..84b8e46 100644
--- a/src/fs/gnunet-fs-gtk-download.c
+++ b/src/fs/gnunet-fs-gtk-download.c
@@ -74,7 +74,7 @@ GNUNET_GTK_save_as_dialog_delete_event_cb (GtkWidget * widget, GdkEvent * event,
   }
   GNUNET_free_non_null (dc->filename);
   dc->filename =
-      GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (dlc->dialog));
+      GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dlc->dialog));
   dc->is_recursive =
       (TRUE ==
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cb))) ? GNUNET_YES :
@@ -177,12 +177,7 @@ GNUNET_FS_GTK_open_download_as_dialog (struct DownloadContext *dc)
         strcat (buf, DIR_SEPARATOR_STR);
         strcat (buf, dc->filename);
       }
-      buf_utf8 = GNUNET_GTK_from_loc_to_utf8 (buf);
-      if (buf_utf8 != NULL)
-      {
-        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf_utf8);
-        GNUNET_free (buf_utf8);
-      }
+      gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad), buf);
     }
   }
   dlc = g_new0 (struct dialog_context, 1);
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index ac734af..46ab20e 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -546,7 +546,6 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
   GtkTreeIter iter;
   GtkTreePath *path;
   struct SearchResult *srp;
-  gchar *filename_utf8;
 
   if (de == NULL)
   {
@@ -586,15 +585,13 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
     return de;
   }
   gtk_tree_path_free (path);
-  filename_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) filename);
   gtk_tree_store_set (de->ts, &iter, 4,
                       (guint) ((size >
                                 0) ? (100 * completed /
                                       size) : 100) /* progress */ ,
-                      6, filename_utf8 /* filename/description */ ,
+                      6, filename /* filename/description */ ,
                       8, "blue" /* status colour: pending */ ,
                       -1);
-  GNUNET_free_non_null (filename_utf8);
   return de;
 }
 
@@ -1637,7 +1634,6 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
   GtkWidget *close_button;
   GtkNotebook *notebook;
   char *size_fancy;
-  char *fn_utf8 = NULL;
 
   if (NULL == parent)
   {
@@ -1705,12 +1701,10 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
   ent = GNUNET_malloc (sizeof (struct PublishEntry));
   ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
   ent->tab = publish_tab;
-  fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) fn);
   gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT,
-                                     0, fn_utf8, 1, size_fancy, 2, "white", 3,
+                                     0, fn, 1, size_fancy, 2, "white", 3,
                                      (guint) 0 /* progress */ ,
                                      4, ent, -1);
-  GNUNET_free_non_null (fn_utf8);
   path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter);
   GNUNET_assert (NULL != path);
   ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path);
diff --git a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
index d429694..d538239 100644
--- a/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
+++ b/src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c
@@ -49,15 +49,10 @@ add_to_list (void *cls, const char *name, const GNUNET_HashCode * id)
 {
   GtkListStore *ls = cls;
   GtkTreeIter iter;
-  char *name_utf8;
-
-  name_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) name);
-
-  gtk_list_store_insert_with_values (ls, &iter, -1, 0, name_utf8, 1,
+  gtk_list_store_insert_with_values (ls, &iter, -1, 0, name, 1,
                                      GNUNET_FS_namespace_create
                                      (GNUNET_FS_GTK_get_fs_handle (), name),
                                      -1);
-  GNUNET_free_non_null (name_utf8);
 }
 
 
diff --git a/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c b/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
index dfa62bb..996b6ad 100644
--- a/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
+++ b/src/fs/gnunet-fs-gtk-main_window_create_pseudonym.c
@@ -32,7 +32,6 @@ GNUNET_GTK_create_namespace_dialog_response_cb (GtkDialog * dialog,
                                                 gpointer user_data)
 {
   const char *name;
-  gchar *name_loc;
   struct GNUNET_FS_Namespace *ns;
   GtkWidget *ad;
   GtkBuilder *builder;
@@ -53,12 +52,10 @@ GNUNET_GTK_create_namespace_dialog_response_cb (GtkDialog * dialog,
                            (builder,
                             "GNUNET_GTK_create_namespace_name_entry")));
   /* FIXME: show busy dialog while doing key creation */
-  name_loc = GNUNET_GTK_from_utf8_to_loc ((char *) name);
-  if (NULL != name_loc)
+  if (NULL != name)
   {
-    ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name_loc);
+    ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name);
     GNUNET_FS_namespace_delete (ns, GNUNET_NO);
-    GNUNET_free (name_loc);
   }
   gtk_widget_destroy (ad);
   g_object_unref (G_OBJECT (builder));
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_publish.c b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
index d214d5f..9bda67c 100644
--- a/src/fs/gnunet-fs-gtk-main_window_file_publish.c
+++ b/src/fs/gnunet-fs-gtk-main_window_file_publish.c
@@ -205,7 +205,6 @@ add_file_at_iter (gpointer data, const char *filename,
   GtkTreePath *path;
   uint64_t file_size;
   const char *short_fn;
-  char *short_fn_utf8;
   struct GNUNET_CONTAINER_MetaData *meta;
   struct GNUNET_FS_Uri *ksk_uri;
   GtkTreeStore *ts;
@@ -243,11 +242,10 @@ add_file_at_iter (gpointer data, const char *filename,
   short_fn = filename;
   while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
     short_fn = 1 + ss;
-  short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
   GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet-gtk>",
                                      EXTRACTOR_METATYPE_FILENAME,
                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
-                                     short_fn_utf8, strlen (short_fn_utf8) + 1);
+                                     short_fn, strlen (short_fn) + 1);
   ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
   gtk_tree_store_insert_before (ts, &pos, iter, NULL);
   path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &pos);
@@ -264,9 +262,8 @@ add_file_at_iter (gpointer data, const char *filename,
   else
     file_size_fancy = GNUNET_STRINGS_byte_size_fancy (file_size);
   gtk_tree_store_set (ts, &pos, 0, file_size_fancy, 1, (gboolean) do_index, 2,
-                      short_fn_utf8, 3, (guint) bo->anonymity_level, 4,
+                      short_fn, 3, (guint) bo->anonymity_level, 4,
                       (guint) bo->content_priority, 5, fi, -1);
-  GNUNET_free_non_null (short_fn_utf8);
   GNUNET_free (file_size_fancy);
   update_selectivity (data);
 }
@@ -503,7 +500,6 @@ extract_file (struct AddDirContext *adc, const char *filename)
   GNUNET_HashCode hc;
   const char *short_fn;
   const char *ss;
-  char *short_fn_utf8;
 
   adc->dir_entry_count++;
   pd = GNUNET_malloc (sizeof (struct PublishData));
@@ -515,12 +511,10 @@ extract_file (struct AddDirContext *adc, const char *filename)
   short_fn = filename;
   while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
     short_fn = 1 + ss;
-  short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
   GNUNET_CONTAINER_meta_data_insert (pd->meta, "<gnunet-gtk>",
                                      EXTRACTOR_METATYPE_FILENAME,
                                      EXTRACTOR_METAFORMAT_UTF8, "text/plain",
-                                     short_fn, strlen (short_fn_utf8) + 1);
-  GNUNET_free_non_null (short_fn_utf8);
+                                     short_fn, strlen (short_fn) + 1);
 
   gtk_tree_store_insert_before (adc->ts, &pd->iter, adc->parent, NULL);
   GNUNET_CRYPTO_hash (filename, strlen (filename), &hc);
@@ -577,7 +571,6 @@ add_entry_to_ts (GtkTreeStore * ts, GtkTreeIter * iter, const char *filename,
   struct GNUNET_FS_Uri *kill_ksk;
   const char *ss;
   const char *short_fn;
-  char *short_fn_utf8;
   struct stat sbuf;
 
   if (0 != STAT (filename, &sbuf))
@@ -629,11 +622,9 @@ add_entry_to_ts (GtkTreeStore * ts, GtkTreeIter * iter, const char *filename,
   short_fn = filename;
   while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
     short_fn = 1 + ss;
-  short_fn_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
   gtk_tree_store_set (ts, iter, 0, file_size_fancy, 1, (gboolean) do_index, 2,
-                      short_fn_utf8, 3, (guint) bo->anonymity_level, 4,
+                      short_fn, 3, (guint) bo->anonymity_level, 4,
                       (guint) bo->content_priority, 5, fi, -1);
-  GNUNET_free_non_null (short_fn_utf8);
   GNUNET_free (file_size_fancy);
 }
 
@@ -778,7 +769,6 @@ scan_directory (void *cls, const char *filename)
     }
     else
     {
-      char *filename_utf8;
       const char *ss, *short_fn;
 
       GNUNET_assert (mcm == NULL);
@@ -786,13 +776,11 @@ scan_directory (void *cls, const char *filename)
       short_fn = filename;
       while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)))
         short_fn = 1 + ss;
-      filename_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) short_fn);
       GNUNET_CONTAINER_meta_data_insert (pd->meta, "<gnunet-gtk>",
                                          EXTRACTOR_METATYPE_FILENAME,
                                          EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain", filename_utf8,
-                                         strlen (filename_utf8) + 1);
-      GNUNET_free_non_null (filename_utf8);
+                                         "text/plain", filename,
+                                         strlen (filename) + 1);
       add_entry_to_ts (adc->ts, &pd->iter, filename, &adc->bo, adc->do_index,
                        NULL, pd->meta);
     }
@@ -1390,7 +1378,7 @@ GNUNET_GTK_publish_directory_dialog_response_cb (GtkDialog * dialog,
                    (builder, "GNUNET_GTK_publish_directory_dialog"));
   if (response_id == -5)
   {
-    filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
+    filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
     sb = GTK_SPIN_BUTTON (gtk_builder_get_object
                           (builder,
                            "GNUNET_GTK_publish_directory_dialog_expiration_year_spin_button"));
@@ -1613,15 +1601,13 @@ add_namespace_to_ts (void *cls, const char *name, const GNUNET_HashCode * id)
   GtkTreeStore *ts = cls;
   struct UpdateableContext uc;
   GtkTreeIter iter;
-  gchar *name_utf8;
 
   uc.parent = &iter;
   uc.namespace_name = name;
   uc.ts = ts;
   uc.ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name);
   uc.update_called = GNUNET_NO;
-  name_utf8 = GNUNET_GTK_from_loc_to_utf8 ((char *) name);
-  gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, name_utf8, 1,
+  gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, name, 1,
                                      uc.ns, 2, NULL /* last-id */ ,
                                      3, NULL /* last-uri (as string!) */ ,
                                      4, NULL /* meta */ ,
@@ -1630,7 +1616,6 @@ add_namespace_to_ts (void *cls, const char *name, const GNUNET_HashCode * id)
                                      7, TRUE /* update editable */ ,
                                      8, TRUE /* current editable */ ,
                                      -1);
-  GNUNET_free_non_null (name_utf8);
   uc.seen = GNUNET_CONTAINER_multihashmap_create (128);
   GNUNET_FS_namespace_list_updateable (uc.ns, NULL, &add_updateable_to_ts, &uc);
   GNUNET_CONTAINER_multihashmap_destroy (uc.seen);
@@ -1853,7 +1838,7 @@ GNUNET_GTK_publish_file_dialog_response_cb (GtkDialog * dialog,
                                        (builder,
                                         "GNUNET_GTK_publish_file_dialog_do_index_checkbutton")));
 
-    filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
+    filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
     add_file_at_iter (user_data, filename, &bo, do_index, NULL);
     g_free (filename);
     update_selectivity (user_data);
diff --git a/src/fs/gnunet-fs-gtk-main_window_open_directory.c b/src/fs/gnunet-fs-gtk-main_window_open_directory.c
index 094ef67..bf28109 100644
--- a/src/fs/gnunet-fs-gtk-main_window_open_directory.c
+++ b/src/fs/gnunet-fs-gtk-main_window_open_directory.c
@@ -92,7 +92,7 @@ GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog * dialog,
 {
   GtkBuilder *builder;
   GtkWidget *ad;
-  char *filename, *filename_utf8;
+  char *filename;
   struct AddChildContext acc;
 
   builder = GTK_BUILDER (user_data);
@@ -106,15 +106,12 @@ GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog * dialog,
     return;
   }
 
-  filename = GNUNET_GTK_filechooser_get_filename_loc (GTK_FILE_CHOOSER (ad));
-  filename_utf8 =
-      GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
+  filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
   gtk_widget_destroy (ad);
   g_object_unref (G_OBJECT (builder));
-  acc.filename = filename_utf8;
+  acc.filename = filename;
   acc.ts = NULL;
   GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc);
-  g_free (filename_utf8);
   g_free (filename);
 }
 
-- 
1.7.4

