2002-05-21 00:20:54 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gnc-lot-xml-v2.c -- lot xml i/o implementation *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2001 James LewisMoss <dres@debian.org> *
|
|
|
|
* Copyright (C) 2002 Linas Vepstas <linas@linas.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2002-05-21 00:20:54 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
2015-11-29 19:11:29 -06:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2002-05-21 00:20:54 -05:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-11-29 19:11:29 -06:00
|
|
|
#include "gnc-lot.h"
|
|
|
|
#include "gnc-lot-p.h"
|
|
|
|
}
|
2002-05-21 00:20:54 -05:00
|
|
|
|
|
|
|
#include "gnc-xml-helper.h"
|
|
|
|
#include "sixtp.h"
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
#include "sixtp-parsers.h"
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
#include "sixtp-dom-parsers.h"
|
|
|
|
#include "sixtp-dom-generators.h"
|
|
|
|
|
|
|
|
#include "gnc-xml.h"
|
|
|
|
#include "io-gncxml-gen.h"
|
|
|
|
#include "io-gncxml-v2.h"
|
|
|
|
#include "sixtp-dom-parsers.h"
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofLogModule log_module = GNC_MOD_IO;
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
const gchar* lot_version_string = "2.0.0";
|
2002-05-21 00:20:54 -05:00
|
|
|
|
|
|
|
/* ids */
|
|
|
|
#define gnc_lot_string "gnc:lot"
|
|
|
|
#define lot_id_string "lot:id"
|
|
|
|
#define lot_slots_string "lot:slots"
|
|
|
|
|
|
|
|
xmlNodePtr
|
2016-03-12 16:04:40 -06:00
|
|
|
gnc_lot_dom_tree_create (GNCLot* lot)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
|
|
|
xmlNodePtr ret;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ENTER ("(lot=%p)", lot);
|
|
|
|
ret = xmlNewNode (NULL, BAD_CAST gnc_lot_string);
|
|
|
|
xmlSetProp (ret, BAD_CAST "version", BAD_CAST lot_version_string);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (lot_id_string, gnc_lot_get_guid (lot)));
|
2015-06-13 19:28:11 -05:00
|
|
|
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, qof_instance_slots_to_dom_tree (lot_slots_string,
|
|
|
|
QOF_INSTANCE (lot)));
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
LEAVE ("");
|
2002-05-21 00:20:54 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =================================================================== */
|
|
|
|
|
|
|
|
struct lot_pdata
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GNCLot* lot;
|
|
|
|
QofBook* book;
|
2002-05-21 00:20:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
lot_id_handler (xmlNodePtr node, gpointer p)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct lot_pdata* pdata = static_cast<decltype (pdata)> (p);
|
|
|
|
GncGUID* guid;
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ENTER ("(lot=%p)", pdata->lot);
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
gnc_lot_set_guid (pdata->lot, *guid);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_free (guid);
|
2009-12-29 14:12:48 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
LEAVE ("");
|
2002-05-21 00:20:54 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
lot_slots_handler (xmlNodePtr node, gpointer p)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct lot_pdata* pdata = static_cast<decltype (pdata)> (p);
|
2002-05-21 00:20:54 -05:00
|
|
|
gboolean success;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ENTER ("(lot=%p)", pdata->lot);
|
|
|
|
success = dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->lot));
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
LEAVE ("");
|
|
|
|
g_return_val_if_fail (success, FALSE);
|
2002-05-21 00:20:54 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-29 14:12:48 -06:00
|
|
|
static struct dom_tree_handler lot_handlers_v2[] =
|
|
|
|
{
|
2002-05-21 00:20:54 -05:00
|
|
|
{ lot_id_string, lot_id_handler, 1, 0 },
|
|
|
|
{ lot_slots_string, lot_slots_handler, 0, 0 },
|
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
gnc_lot_end_handler (gpointer data_for_children,
|
|
|
|
GSList* data_from_children, GSList* sibling_data,
|
|
|
|
gpointer parent_data, gpointer global_data,
|
|
|
|
gpointer* result, const gchar* tag)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GNCLot* lot;
|
2002-05-21 00:20:54 -05:00
|
|
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
2016-03-12 16:04:40 -06:00
|
|
|
gxpf_data* gdata = (gxpf_data*)global_data;
|
|
|
|
QofBook* book = static_cast<decltype (book)> (gdata->bookdata);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2009-12-29 14:12:48 -06:00
|
|
|
if (parent_data)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK. For some messed up reason this is getting called again with a
|
|
|
|
NULL tag. So we ignore those cases */
|
2009-12-29 14:12:48 -06:00
|
|
|
if (!tag)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_return_val_if_fail (tree, FALSE);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
lot = dom_tree_to_lot (tree, book);
|
|
|
|
ENTER ("(lot=%p)", lot);
|
2009-12-29 14:12:48 -06:00
|
|
|
if (lot != NULL)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
gdata->cb (tag, gdata->parsedata, lot);
|
2002-05-21 00:20:54 -05:00
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlFreeNode (tree);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
LEAVE ("");
|
2002-05-21 00:20:54 -05:00
|
|
|
return lot != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GNCLot*
|
2016-03-12 16:04:40 -06:00
|
|
|
dom_tree_to_lot (xmlNodePtr node, QofBook* book)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
|
|
|
struct lot_pdata pdata;
|
2016-03-12 16:04:40 -06:00
|
|
|
GNCLot* lot;
|
2002-05-21 00:20:54 -05:00
|
|
|
gboolean successful;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
lot = gnc_lot_new (book);
|
|
|
|
ENTER ("(lot=%p)", lot);
|
2002-05-21 00:20:54 -05:00
|
|
|
|
|
|
|
pdata.lot = lot;
|
|
|
|
pdata.book = book;
|
|
|
|
|
|
|
|
successful = dom_tree_generic_parse (node, lot_handlers_v2,
|
|
|
|
&pdata);
|
|
|
|
if (!successful)
|
|
|
|
{
|
|
|
|
PERR ("failed to parse lot");
|
|
|
|
gnc_lot_destroy (lot);
|
|
|
|
lot = NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
LEAVE ("");
|
2002-05-21 00:20:54 -05:00
|
|
|
return lot;
|
|
|
|
}
|
|
|
|
|
|
|
|
sixtp*
|
2016-03-12 16:04:40 -06:00
|
|
|
gnc_lot_sixtp_parser_create (void)
|
2002-05-21 00:20:54 -05:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
return sixtp_dom_parser_new (gnc_lot_end_handler, NULL, NULL);
|
2002-05-21 00:20:54 -05:00
|
|
|
}
|
2002-05-25 23:44:53 -05:00
|
|
|
|
|
|
|
/* ================== END OF FILE ========================== */
|