[libgda] Validate error strings in PostgreSQL provider



commit ea869bd648a5574851c64058ecd4265cc1757fab
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 1fc61e4..1ee79be 100644
--- a/providers/postgres/gda-postgres-util.c
+++ b/providers/postgres/gda-postgres-util.c
@@ -44,6 +44,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()
@@ -71,7 +92,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]