[Gnucash-changes] Patch to fix bug #88078 - Incorrect namespace definition in XML file.

Neil Williams codehelp at cvs.gnucash.org
Mon Aug 22 15:54:32 EDT 2005


Log Message:
-----------
Patch to fix bug #88078 -  Incorrect namespace definition in XML file. part 2
New backend configuration support using translatable XML and KVP.
Avoid building core-utils functions in the backend - not portable to CashUtil. FIXME.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/backend/file:
        gnc-backend-file.c
        gnc-book-xml-v2.c
        io-gncxml-v2.c
        io-gncxml-v2.h
        sixtp-utils.c

Revision Data
-------------
Index: io-gncxml-v2.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/io-gncxml-v2.c,v
retrieving revision 1.24.4.8
retrieving revision 1.24.4.9
diff -Lsrc/backend/file/io-gncxml-v2.c -Lsrc/backend/file/io-gncxml-v2.c -u -r1.24.4.8 -r1.24.4.9
--- src/backend/file/io-gncxml-v2.c
+++ src/backend/file/io-gncxml-v2.c
@@ -1039,30 +1039,48 @@
     } while ( (schedXactions = schedXactions->next) );
 }
 
-#if 0
-static void
-write_namespace_decl (FILE *out, const char *namespace)
+void
+gnc_xml2_write_namespace_decl (FILE *out, const char *namespace)
 {
   g_return_if_fail (namespace);
-  fprintf(out, " xmlns:%s=\"\"", namespace);
+  fprintf(out, "\n     xmlns:%s=\"http://www.gnucash.org/XML/%s\"",
+          namespace, namespace);
+}
+
+static void
+do_write_namespace_cb (const char *type, gpointer data_p, gpointer file_p)
+{
+  GncXmlDataType_t *data = data_p;
+  FILE *out = file_p;
+
+  g_return_if_fail (type && data && out);
+  g_return_if_fail (data->version == GNC_FILE_BACKEND_VERS);
+
+  if (data->ns)
+    (data->ns)(out);
 }
-#endif
 
 static void
 write_v2_header (FILE *out)
 {
     fprintf(out, "<?xml version=\"1.0\"?>\n");
     fprintf(out, "<" GNC_V2_STRING);
-    /*
-    write_namespace_decl (out, "cd");
-    write_namespace_decl (out, "gnc");
-    write_namespace_decl (out, "act");
-    write_namespace_decl (out, "cmdty");
-    write_namespace_decl (out, "trn");
-    write_namespace_decl (out, "ts");
-    write_namespace_decl (out, "split");
-    write_namespace_decl (out, "sx");
-    */
+    
+    gnc_xml2_write_namespace_decl (out, "gnc");
+    gnc_xml2_write_namespace_decl (out, "act");
+    gnc_xml2_write_namespace_decl (out, "book");
+    gnc_xml2_write_namespace_decl (out, "cd");
+    gnc_xml2_write_namespace_decl (out, "cmdty");
+    gnc_xml2_write_namespace_decl (out, "price");
+    gnc_xml2_write_namespace_decl (out, "slot");
+    gnc_xml2_write_namespace_decl (out, "split");
+    gnc_xml2_write_namespace_decl (out, "sx");
+    gnc_xml2_write_namespace_decl (out, "trn");
+    gnc_xml2_write_namespace_decl (out, "ts");
+
+    /* now cope with the plugins */
+    qof_object_foreach_backend (GNC_FILE_BACKEND, do_write_namespace_cb, out);
+
     fprintf(out, ">\n");
 }
 
Index: gnc-book-xml-v2.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/gnc-book-xml-v2.c,v
retrieving revision 1.6.4.6
retrieving revision 1.6.4.7
diff -Lsrc/backend/file/gnc-book-xml-v2.c -Lsrc/backend/file/gnc-book-xml-v2.c -u -r1.6.4.6 -r1.6.4.7
--- src/backend/file/gnc-book-xml-v2.c
+++ src/backend/file/gnc-book-xml-v2.c
@@ -46,8 +46,8 @@
 #include "sixtp-dom-parsers.h"
 #include "gnc-engine-util.h"
 #include "Group.h"
-// used to set the GUID of the book
-#include "qofbook-p.h"
+#include "qofbook.h"
+#include "qofid-p.h"
 
 /* non-static because it's used in io-gncxml-v2.c */
 const gchar *gnc_v2_book_version_string = "2.0.0";
@@ -188,8 +188,7 @@
     GUID *guid;
 
     guid = dom_tree_to_guid(node);
-    qof_book_set_guid(book, guid);
-
+    qof_entity_set_guid(QOF_ENTITY(book), guid);
     g_free(guid);
     
     return TRUE;
Index: sixtp-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/sixtp-utils.c,v
retrieving revision 1.7.4.4
retrieving revision 1.7.4.5
diff -Lsrc/backend/file/sixtp-utils.c -Lsrc/backend/file/sixtp-utils.c -u -r1.7.4.4 -r1.7.4.5
--- src/backend/file/sixtp-utils.c
+++ src/backend/file/sixtp-utils.c
@@ -388,17 +388,20 @@
 gnc_timegm (struct tm *tm)
 {
   time_t result;
+#ifdef GNUCASH_MAJOR_VERSION
   char *put_str;
+#endif
   char *old_tz;
 
   old_tz = getenv ("TZ");
-
+#ifdef GNUCASH_MAJOR_VERSION
+/** \todo Implement a separate method of configuration handling. */
   /* FIXME: there's no way to report this error to the caller. */
   if(gnc_setenv("TZ", "UTC", 1) != 0)
     PERR ("couldn't switch the TZ.");
-
+#endif
   result = mktime (tm);
-
+#ifdef GNUCASH_MAJOR_VERSION
   if(old_tz)
   {
     /* FIXME: there's no way to report this error to the caller. */
@@ -412,6 +415,7 @@
     if(errno != 0)
       PERR ("couldn't restore the TZ to undefined.");
   }
+#endif
   return result;
 }
 #endif
Index: gnc-backend-file.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/gnc-backend-file.c,v
retrieving revision 1.23.4.9
retrieving revision 1.23.4.10
diff -Lsrc/backend/file/gnc-backend-file.c -Lsrc/backend/file/gnc-backend-file.c -u -r1.23.4.9 -r1.23.4.10
--- src/backend/file/gnc-backend-file.c
+++ src/backend/file/gnc-backend-file.c
@@ -44,7 +44,6 @@
 #include "TransLog.h"
 #include "gnc-engine.h"
 #include "gnc-date.h"
-#include "gnc-gconf-utils.h"
 #include "gnc-trace.h"
 #include "gnc-engine-util.h"
 #include "gnc-filepath-utils.h"
@@ -59,10 +58,51 @@
 #include "qofbackend-p.h"
 #include "qofbook.h"
 #include "qofsession.h"
+
+#ifdef GNUCASH_MAJOR_VERSION
 #include "qsf-xml.h"
+#endif
+
+#define GNC_BE_DAYS "file_retention_days"
+#define GNC_BE_ZIP  "file_compression"
 
 static short module = MOD_BACKEND;
 
+static gint file_retention_days = 0;
+static gboolean file_compression = FALSE;
+
+static void
+gnc_file_be_set_config(QofBackend *be, KvpFrame *config)
+{
+	gchar* temp;
+
+	if(!be | !config) { return; }
+	file_retention_days = (gint)kvp_frame_get_gint64(config, GNC_BE_DAYS);
+	temp = kvp_frame_get_string(config, GNC_BE_ZIP);
+	file_compression = (gboolean)qof_util_bool_to_int(temp);
+	
+}
+
+static KvpFrame*
+gnc_file_be_get_config(QofBackend *be)
+{
+	if(!be) { return NULL; }
+	if(!kvp_frame_is_empty(be->backend_configuration)) {
+		kvp_frame_delete(be->backend_configuration);
+		be->backend_configuration = kvp_frame_new();
+	}
+	kvp_frame_add_gint64(be->backend_configuration, 
+		GNC_BE_DAYS, (gint64)file_retention_days);
+	if(file_compression) {
+		kvp_frame_add_string(be->backend_configuration, 
+			GNC_BE_ZIP, "TRUE");
+	}
+	else {
+		kvp_frame_add_string(be->backend_configuration, 
+			GNC_BE_ZIP, "FALSE");
+	}
+	return be->backend_configuration;
+}
 
 /* ================================================================= */
 
@@ -184,7 +224,9 @@
         return;
     }
     be->fullpath = g_strdup (be->dirname);
+#ifdef GNUCASH_MAJOR_VERSION
     be->be.fullpath = be->fullpath;
+#endif
     p = strrchr (be->dirname, '/');
     if (p && p != be->dirname)
     {
@@ -384,17 +426,27 @@
         return GNC_BOOK_XML1_FILE;
     } else if(is_gzipped_file(path)) {
         return GNC_BOOK_XML2_FILE;
+#ifdef GNUCASH_MAJOR_VERSION
     } else if(is_our_qsf_object(path)) {
         return QSF_GNC_OBJECT;  /**< QSF object file using only GnuCash QOF objects */
     } else if(is_qsf_object(path)) {
 		return QSF_OBJECT;   /**< QSF object file that needs a QSF map */
     } else if(is_qsf_map(path)) {
 		return QSF_MAP;      /**< QSF map file */
+#endif
     } else {
         return GNC_BOOK_BIN_FILE;
     }
 }
 
+static gboolean
+gnc_determine_file_type (QofBackend *be, const char *path)
+{
+	if(gnc_is_xml_data_file_v2(path))   { return TRUE; } 
+	else if(gnc_is_xml_data_file(path)) { return TRUE; } 
+	else if(is_gzipped_file(path))      { return TRUE; }
+	return FALSE;
+}	
 
 static gboolean
 gnc_file_be_backup_file(FileBackend *be)
@@ -454,7 +506,6 @@
     struct stat statbuf;
     int rc;
     QofBackendError be_err;
-    gboolean file_compression;
 
     ENTER (" book=%p file=%s", book, datafile);
 
@@ -480,7 +531,6 @@
         }
     }
   
-    file_compression = gnc_gconf_get_bool(GCONF_GENERAL, "compress_files", NULL);
     if(gnc_book_write_to_xml_file_v2(book, tmp_name, file_compression)) 
     {
         /* Record the file's permissions before unlinking it */
@@ -587,7 +637,6 @@
 static void
 gnc_file_be_remove_old_files(FileBackend *be)
 {
-    int file_retention_days;
     struct dirent *dent;
     DIR *dir;
     struct stat lockstatbuf, statbuf;
@@ -621,7 +670,6 @@
         return;
 
     now = time(NULL);
-    file_retention_days = gnc_gconf_get_float(GCONF_GENERAL, "retain_days", NULL);
     while((dent = readdir(dir)) != NULL) {
         char *name;
         int len;
@@ -823,7 +871,7 @@
         rc = qof_session_load_from_xml_file (book, be->fullpath);
         if (FALSE == rc) error = ERR_FILEIO_PARSE_ERROR;
         break;
-
+#ifdef GNUCASH_MAJOR_VERSION
     case QSF_GNC_OBJECT:
 		error = qof_session_load_our_qsf_object(qof_session_get_current_session(), be->fullpath);
 		PINFO (" QSF_GNC_OBJECT error=%d", error);
@@ -839,7 +887,7 @@
 		error = ERR_QSF_MAP_NOT_OBJ;
 		PINFO (" QSF_MAP error=%d", error);
 		break;
-
+#endif
     case GNC_BOOK_BIN_FILE:
         /* presume it's an old-style binary file */
         qof_session_load_from_binfile(book, be->fullpath);
@@ -865,14 +913,14 @@
 static gboolean
 gnc_file_be_save_may_clobber_data (QofBackend *bend)
 {
+#ifdef GNUCASH_MAJOR_VERSION
   struct stat statbuf;
-
   if (!bend->fullpath) return FALSE;
 
   /* FIXME: Make sure this doesn't need more sophisticated semantics
    * in the face of special file, devices, pipes, symlinks, etc. */
   if (stat(bend->fullpath, &statbuf) == 0) return TRUE;
-                                                                                
+#endif                                                                                
   return FALSE;
 }
 
@@ -887,7 +935,7 @@
 }
 
 /* ================================================================= */
-
+#ifdef GNUCASH_MAJOR_VERSION
 QofBackend *
 libgncmod_backend_file_LTX_gnc_backend_new(void)
 {
@@ -923,6 +971,7 @@
     be->process_events = NULL;
 
     be->sync = file_sync_all;
+	be->load_config = gnc_file_be_set_config;
     be->export = gnc_file_be_write_accounts_to_file;
 
     fbe->dirname = NULL;
@@ -935,7 +984,7 @@
 
     return be;
 }
-
+#endif
 QofBackend*
 gnc_backend_new(void)
 {
@@ -970,9 +1019,10 @@
 	be->process_events = NULL;
 
 	be->sync = file_sync_all;
-/* export and price_lookup have been moved but this
-	section is not used yet - it is in preparation for
-	CashUtil and an external QOF library. */
+	be->load_config = gnc_file_be_set_config;
+	be->get_config = gnc_file_be_get_config;
+	be->check_data_type = gnc_determine_file_type;
+
 	gnc_be->export = gnc_file_be_write_accounts_to_file;
 	gnc_be->price_lookup = NULL;
 	gnc_be->dirname = NULL;
@@ -994,9 +1044,6 @@
         g_free (prov);
 }
 
-/* temporary definition*/
-void gnc_provider_init(void);
-
 void
 gnc_provider_init(void)
 {
@@ -1007,7 +1054,9 @@
         prov->partial_book_supported = FALSE;
         prov->backend_new = gnc_backend_new;
         prov->provider_free = gnc_provider_free;
+	    prov->provider_config = "gnucash-file-backend-v2.xml";
         qof_backend_register_provider (prov);
 }
 
+
 /* ========================== END OF FILE ===================== */
Index: io-gncxml-v2.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/io-gncxml-v2.h,v
retrieving revision 1.11.4.2
retrieving revision 1.11.4.3
diff -Lsrc/backend/file/io-gncxml-v2.h -Lsrc/backend/file/io-gncxml-v2.h -u -r1.11.4.2 -r1.11.4.3
--- src/backend/file/io-gncxml-v2.h
+++ src/backend/file/io-gncxml-v2.h
@@ -91,6 +91,9 @@
  *
  * The scrub() method will take a completed, parsed QofBook* and post process
  *   the data, allowing you to 'scrub' the data.
+ *
+ * The ns() method will output XML namespace information for the selected
+ *   plug-in object.
  */
 #define GNC_FILE_BACKEND	"gnc:file:2"
 #define GNC_FILE_BACKEND_VERS	2
@@ -104,6 +107,7 @@
   int	      (*get_count) (QofBook *);
   void		(*write) (FILE*, QofBook*);
   void		(*scrub) (QofBook *);
+  void		(*ns) (FILE*);
 } GncXmlDataType_t;
 
 /**
@@ -139,4 +143,9 @@
  */
 gboolean gnc_is_xml_data_file_v2(const gchar *name);
 
+/* Write a name-space declaration for the provided namespace data type
+ * within the GNC XML namespace at http://www.gnucash.org/XML.
+ */
+void gnc_xml2_write_namespace_decl (FILE *out, const char *namespace);
+
 #endif /* __IO_GNCXML_V2_H__ */


More information about the gnucash-changes mailing list