[Gnucash-changes] Fix character encodings of imported transactions.

Christian Stimming cstim at cvs.gnucash.org
Sat Mar 19 03:59:42 EST 2005


Log Message:
-----------
Fix character encodings of imported transactions.

2005-03-19  Christian Stimming  <stimming at tuhh.de>

	* src/import-export/hbci/gnc-hbci-utils.c (gnc_hbci_descr_tognc):
	Correctly convert imported transaction description from utf-8 to
	iso-8859-15 which currently comes closest to gnucash's internal
	encoding. This needs to be changed again for the gnome2 port, but
	I'll think of that early enough.

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/import-export/hbci:
        gnc-hbci-utils.c
        hbci-interaction.c

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1898
retrieving revision 1.1899
diff -LChangeLog -LChangeLog -u -r1.1898 -r1.1899
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,11 @@
+2005-03-19  Christian Stimming  <stimming at tuhh.de>
+
+	* src/import-export/hbci/gnc-hbci-utils.c (gnc_hbci_descr_tognc):
+	Correctly convert imported transaction description from utf-8 to
+	iso-8859-15 which currently comes closest to gnucash's internal
+	encoding. This needs to be changed again for the gnome2 port, but
+	I'll think of that early enough.
+
 2005-03-13  Christian Stimming  <stimming at tuhh.de>
 
 	* src/import-export/hbci/gnc-hbci-getbalance.c: Improve user
Index: hbci-interaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interaction.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -Lsrc/import-export/hbci/hbci-interaction.c -Lsrc/import-export/hbci/hbci-interaction.c -u -r1.52 -r1.53
--- src/import-export/hbci/hbci-interaction.c
+++ src/import-export/hbci/hbci-interaction.c
@@ -54,7 +54,11 @@
   
   data = g_new0 (GNCInteractor, 1);
   data->parent = parent;
-  data->gnc_iconv_handler = iconv_open("ISO8859-1", "UTF-8");
+  /* FIXME: The internal target encoding is hard-coded so far. This
+     needs to be fixed for the gnome2 version; the target encoding is
+     then probably utf-8 as well. iconv is also used in
+     gnc_hbci_descr_tognc() in gnc-hbci-utils.c. */
+  data->gnc_iconv_handler = iconv_open("ISO8859-15", "UTF-8");
   g_assert(data->gnc_iconv_handler != (iconv_t)(-1));
   data->keepAlive = TRUE;
   data->cache_pin = 
Index: gnc-hbci-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-utils.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -Lsrc/import-export/hbci/gnc-hbci-utils.c -Lsrc/import-export/hbci/gnc-hbci-utils.c -u -r1.49 -r1.50
--- src/import-export/hbci/gnc-hbci-utils.c
+++ src/import-export/hbci/gnc-hbci-utils.c
@@ -25,6 +25,7 @@
 
 #include <gnome.h>
 #include <errno.h>
+#include <iconv.h>
 #include <gwenhywfar/directory.h>
 
 #include "gnc-ui.h"
@@ -475,16 +476,30 @@
   }
 }
 
+struct cb_struct {
+  gchar **result;
+  iconv_t gnc_iconv_handler;
+};
+
 /* Needed for the gnc_hbci_descr_tognc and gnc_hbci_memo_tognc. */
 static void *gnc_list_string_cb (const char *string, void *user_data)
 {
-  gchar **res = user_data;
-  gchar *tmp1, *tmp2;
+  struct cb_struct *u = user_data;
+  gchar **res = u->result;
+  gchar *tmp1, *tmp2, *outbuffer;
+  char *inbuffer = (char*)string;
+  size_t inbytes = strlen(string), outbytes = inbytes+2;
 
   if (!string) return NULL;
-  tmp1 = g_strdup (string);
-  g_strstrip (tmp1);
+  tmp1 = g_strndup (string, outbytes);
+  outbuffer = tmp1;
+
+  iconv(u->gnc_iconv_handler, &inbuffer, &inbytes,
+	&outbuffer, &outbytes);
+  if (outbytes > 0)
+    *outbuffer = '\0';
 
+  g_strstrip (tmp1);
   if (strlen (tmp1) > 0) {
     if (*res != NULL) {
       /* The " " is the separating string in between each two strings. */
@@ -511,19 +526,30 @@
   char *g_descr;
   const GWEN_STRINGLIST *h_purpose = AB_Transaction_GetPurpose (h_trans);
   const GWEN_STRINGLIST *h_remotename = AB_Transaction_GetRemoteName (h_trans);
+  struct cb_struct cb_object;
+
+  /* FIXME: The internal target encoding is hard-coded so far. This
+     needs to be fixed for the gnome2 version; the target encoding is
+     then probably utf-8 as well. iconv is also used in
+     gnc_AB_BANKING_interactors() in hbci-interaction.c. */
+  cb_object.gnc_iconv_handler = iconv_open("ISO8859-15", "UTF-8");
+  g_assert(cb_object.gnc_iconv_handler != (iconv_t)(-1));
 
   /* Don't use list_string_concat_delim here since we need to
      g_strstrip every single element of the string list, which is
      only done in our callback gnc_list_string_cb. The separator is
      also set there. */
+  cb_object.result = &h_descr;
   if (h_purpose)
     GWEN_StringList_ForEach (h_purpose,
 			     &gnc_list_string_cb,
-			     &h_descr);
+			     &cb_object);
+
+  cb_object.result = &othername;
   if (h_remotename)
     GWEN_StringList_ForEach (h_remotename,
 			     &gnc_list_string_cb,
-			     &othername);
+			     &cb_object);
   /*DEBUG("HBCI Description '%s'", h_descr);*/
 
   if (othername && (strlen (othername) > 0))
@@ -539,6 +565,7 @@
        g_strdup (h_descr) : 
        g_strdup (_("Unspecified")));
 
+  iconv_close(cb_object.gnc_iconv_handler);
   free (h_descr);
   free (othername);
   return g_descr;


More information about the gnucash-changes mailing list