[libgda/LIBGDA_4.0] Validate error strings in PostgreSQL provider



commit 50a76f33cfc0a5604fed9330914cba606a2e4b03
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Aug 4 18:36:20 2010 +0200

    Validate error strings in PostgreSQL provider
    
    when client tries to connect, but connection is refused,
    error messages use encoding set in configuration of server, which
    is unknown. This situation causes invalid UTF8 errors not being
    displayed by GTK.

 providers/postgres/gda-postgres-util.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/providers/postgres/gda-postgres-util.c b/providers/postgres/gda-postgres-util.c
index df0be97..0ec4fbb 100644
--- a/providers/postgres/gda-postgres-util.c
+++ b/providers/postgres/gda-postgres-util.c
@@ -46,6 +46,27 @@ gda_postgres_sqlsate_to_gda_code (const gchar *sqlstate)
 }
 
 /*
+ * Returns: @str
+ */
+static gchar *
+utf8_validate (gchar *str)
+{
+	gchar *tmp;
+	if (g_utf8_validate (str, -1, (const gchar **) &tmp))
+		return str;
+	else {
+		*tmp = ' ';
+		for (tmp++; tmp; tmp++) {
+			if (g_utf8_validate (tmp, -1, (const gchar **) &tmp))
+				return str;
+			else
+				*tmp = ' ';
+		}
+		return tmp;
+	}
+}
+
+/*
  * Create a new #GdaConnectionEvent object and "adds" it to @cnc
  *
  * Returns: a new GdaConnectionEvent which must not be unrefed()
@@ -73,7 +94,7 @@ _gda_postgres_make_error (GdaConnection *cnc, PGconn *pconn, PGresult *pg_res, G
                         message = g_strdup (PQerrorMessage (pconn));
                         gda_code = GDA_CONNECTION_EVENT_CODE_UNKNOWN;
                 }
-
+		utf8_validate (message);
 		
 		gchar *ptr = message;
 		if (g_str_has_prefix (message, "ERROR:"))



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