[libgda] Init: removed global variable for param list DTD
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Init: removed global variable for param list DTD
- Date: Mon, 15 Apr 2019 03:12:03 +0000 (UTC)
commit 03d527c53a27e0d870348f6945898e139a8819af
Author: Daniel Espinosa <esodan gmail com>
Date: Sun Apr 14 17:16:39 2019 -0500
Init: removed global variable for param list DTD
libgda/gda-init.c | 22 --------
libgda/gda-set.c | 119 ++++++++++++++++++++++++++-------------
libgda/libgda-global-variables.h | 1 -
3 files changed, 80 insertions(+), 62 deletions(-)
---
diff --git a/libgda/gda-init.c b/libgda/gda-init.c
index 7afe2ff56..764656837 100644
--- a/libgda/gda-init.c
+++ b/libgda/gda-init.c
@@ -54,7 +54,6 @@
* #endif
* IMPORT extern gchar *gda_numeric_locale;
*/
-xmlDtdPtr gda_paramlist_dtd = NULL;
xmlDtdPtr _gda_server_op_dtd = NULL;
xmlDtdPtr _gda_db_catalog_dtd = NULL;
@@ -184,27 +183,6 @@ gda_init (void)
/* binreloc */
gda_gbr_init ();
- /* paramlist DTD */
- gda_paramlist_dtd = NULL;
- file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "dtd", "libgda-paramlist.dtd", NULL);
- if (g_file_test (file, G_FILE_TEST_EXISTS))
- gda_paramlist_dtd = xmlParseDTD (NULL, (xmlChar*)file);
-
- if (!gda_paramlist_dtd) {
- if (g_getenv ("GDA_TOP_SRC_DIR")) {
- g_free (file);
- file = g_build_filename (g_getenv ("GDA_TOP_SRC_DIR"), "libgda",
"libgda-paramlist.dtd", NULL);
- gda_paramlist_dtd = xmlParseDTD (NULL, (xmlChar*)file);
- }
- if (!gda_paramlist_dtd)
- g_message (_("Could not parse '%s': "
- "XML data import validation will not be performed (some weird errors may
occur)"),
- file);
- }
- if (gda_paramlist_dtd)
- gda_paramlist_dtd->name = xmlStrdup((xmlChar*) "data-set-spec");
- g_free (file);
-
/* server operation DTD */
_gda_server_op_dtd = NULL;
file = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "dtd", "libgda-server-operation.dtd",
NULL);
diff --git a/libgda/gda-set.c b/libgda/gda-set.c
index 3595a8414..22850b5cf 100644
--- a/libgda/gda-set.c
+++ b/libgda/gda-set.c
@@ -41,7 +41,6 @@
#include "gda-util.h"
#include <libgda/gda-custom-marshal.h>
-extern xmlDtdPtr gda_paramlist_dtd;
extern gchar *gda_lang_locale;
/**
@@ -1335,55 +1334,97 @@ gda_set_new_from_spec_string (const gchar *xml_spec, GError **error)
return NULL;
{
- /* doc validation */
- xmlValidCtxtPtr validc;
- int xmlcheck;
+ /* doc validation */
+ xmlValidCtxtPtr validc;
+ int xmlcheck;
gchar *err_str = NULL;
xmlDtdPtr old_dtd = NULL;
-
- validc = g_new0 (xmlValidCtxt, 1);
- validc->userData = &err_str;
- validc->error = xml_validity_error_func;
- validc->warning = NULL;
-
- xmlcheck = xmlDoValidityCheckingDefaultValue;
- xmlDoValidityCheckingDefaultValue = 1;
-
- /* replace the DTD with ours */
- if (gda_paramlist_dtd) {
+ xmlDtdPtr gda_paramlist_dtd = NULL;
+ GString *dtdpath;
+ GFile *gda_data_dir;
+ gchar *gda_data_dir_path;
+ GFile *file;
+ gchar *path;
+
+ validc = g_new0 (xmlValidCtxt, 1);
+ validc->userData = &err_str;
+ validc->error = xml_validity_error_func;
+ validc->warning = NULL;
+
+ xmlcheck = xmlDoValidityCheckingDefaultValue;
+ xmlDoValidityCheckingDefaultValue = 1;
+
+ /* replace the DTD with ours */
+ /* paramlist DTD */
+ gda_data_dir = g_file_new_for_path (LIBGDA_ABI_NAME);
+ gda_data_dir_path = g_file_get_uri (gda_data_dir);
+ dtdpath = g_string_new (gda_data_dir_path);
+ g_free (gda_data_dir_path);
+ g_object_unref (gda_data_dir);
+ g_string_append (dtdpath, "/dtd/libgda-paramlist.dtd");
+ file = g_file_new_for_path (dtdpath->str);
+ g_string_free (dtdpath, TRUE);
+ if (g_file_query_exists (file, NULL)) {
+ path = g_file_get_path (file);
+ gda_paramlist_dtd = xmlParseDTD (NULL, (xmlChar*) path);
+ g_free (path);
+ }
+ g_object_unref (file);
+
+ if (!gda_paramlist_dtd) {
+ if (g_getenv ("GDA_TOP_SRC_DIR")) {
+ dtdpath = g_string_new (g_getenv ("GDA_TOP_SRC_DIR"));
+ g_string_append (dtdpath, "/libgda/libgda-paramlist.dtd");
+ file = g_file_new_for_path (dtdpath->str);
+ g_string_free (dtdpath, TRUE);
+ path = g_file_get_path (file);
+ gda_paramlist_dtd = xmlParseDTD (NULL, (xmlChar*) path);
+ g_free (path);
+ g_object_unref (file);
+ }
+ if (!gda_paramlist_dtd)
+ g_message (_("Could not parse '%s': XML data import validation will not be
performed (some weird errors may occur)"),
+ path);
+ }
+ if (gda_paramlist_dtd) {
+ gda_paramlist_dtd->name = xmlStrdup((xmlChar*) "data-set-spec");
+ }
+ if (gda_paramlist_dtd) {
old_dtd = doc->intSubset;
doc->intSubset = gda_paramlist_dtd;
}
#ifndef G_OS_WIN32
- if (doc->intSubset && !xmlValidateDocument (validc, doc)) {
+ if (doc->intSubset && !xmlValidateDocument (validc, doc)) {
if (gda_paramlist_dtd)
doc->intSubset = old_dtd;
- xmlFreeDoc (doc);
- g_free (validc);
-
- if (err_str) {
- g_set_error (error,
- GDA_SET_ERROR,
- GDA_SET_XML_SPEC_ERROR,
- "XML spec. does not conform to DTD:\n%s", err_str);
- g_free (err_str);
- }
- else
- g_set_error (error,
- GDA_SET_ERROR,
- GDA_SET_XML_SPEC_ERROR,
- "%s", "XML spec. does not conform to DTD");
-
- xmlDoValidityCheckingDefaultValue = xmlcheck;
- return NULL;
- }
+ xmlFreeDoc (doc);
+ g_free (validc);
+
+ if (err_str) {
+ g_set_error (error,
+ GDA_SET_ERROR,
+ GDA_SET_XML_SPEC_ERROR,
+ "XML spec. does not conform to DTD:\n%s", err_str);
+ g_free (err_str);
+ }
+ else
+ g_set_error (error,
+ GDA_SET_ERROR,
+ GDA_SET_XML_SPEC_ERROR,
+ "%s", "XML spec. does not conform to DTD");
+
+ xmlDoValidityCheckingDefaultValue = xmlcheck;
+ return NULL;
+ }
#endif
- if (gda_paramlist_dtd)
+ if (gda_paramlist_dtd) {
doc->intSubset = old_dtd;
- xmlDoValidityCheckingDefaultValue = xmlcheck;
- g_free (validc);
- }
+ xmlFreeDtd (gda_paramlist_dtd);
+ }
+ xmlDoValidityCheckingDefaultValue = xmlcheck;
+ g_free (validc);
+ }
/* doc is now non NULL */
root = xmlDocGetRootElement (doc);
diff --git a/libgda/libgda-global-variables.h b/libgda/libgda-global-variables.h
index 8c617b364..06721fc9f 100644
--- a/libgda/libgda-global-variables.h
+++ b/libgda/libgda-global-variables.h
@@ -34,6 +34,5 @@
IMPORT extern gchar *gda_numeric_locale;
IMPORT extern gchar *gda_lang_locale;
-IMPORT extern xmlDtdPtr gda_paramlist_dtd;
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]