30 #include "gnc-xml-helper.h"
33 #include "sixtp-utils.h"
34 #include "sixtp-parsers.h"
35 #include "sixtp-utils.h"
36 #include "sixtp-dom-parsers.h"
37 #include "sixtp-dom-generators.h"
40 #include "io-gncxml-gen.h"
42 #include "sixtp-dom-parsers.h"
48 const gchar *commodity_version_string =
"2.0.0";
51 #define gnc_commodity_string "gnc:commodity"
52 #define cmdty_namespace "cmdty:space"
53 #define cmdty_id "cmdty:id"
54 #define cmdty_name "cmdty:name"
55 #define cmdty_xcode "cmdty:xcode"
56 #define cmdty_fraction "cmdty:fraction"
57 #define cmdty_get_quotes "cmdty:get_quotes"
58 #define cmdty_quote_source "cmdty:quote_source"
59 #define cmdty_quote_tz "cmdty:quote_tz"
60 #define cmdty_slots "cmdty:slots"
70 kvp_frame_to_dom_tree(cmdty_slots,
71 qof_instance_get_slots(QOF_INSTANCE(com)));
76 ret = xmlNewNode(NULL, BAD_CAST gnc_commodity_string);
78 xmlSetProp(ret, BAD_CAST
"version", BAD_CAST commodity_version_string);
80 xmlAddChild(ret, text_to_dom_tree(cmdty_namespace,
82 xmlAddChild(ret, text_to_dom_tree(cmdty_id,
89 xmlAddChild(ret, text_to_dom_tree(cmdty_name,
96 xmlAddChild(ret, text_to_dom_tree(
101 xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
107 xmlNewChild(ret, NULL, BAD_CAST cmdty_get_quotes, NULL);
110 xmlAddChild(ret, text_to_dom_tree(cmdty_quote_source,
114 xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz,
string));
118 xmlAddChild(ret, kvpnode);
144 if (g_strcmp0((
char*) node->name, cmdty_fraction) == 0)
149 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
150 if (string_to_gint64(
string, &val))
156 else if (g_strcmp0((
char*)node->name, cmdty_get_quotes) == 0)
160 else if (g_strcmp0((
char*)node->name, cmdty_quote_source) == 0)
165 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
172 else if (g_strcmp0((
char*)node->name, cmdty_slots) == 0)
175 dom_tree_to_kvp_frame_given(node,
176 qof_instance_get_slots(QOF_INSTANCE(com)));
182 for (mark = com_handlers; mark->tag; mark++)
184 if (g_strcmp0(mark->tag, (
char*)node->name) == 0)
186 gchar* val = dom_tree_to_text(node);
188 (mark->func)(com, val);
201 PWARN(
"Invalid commodity: no namespace");
206 PWARN(
"Invalid commodity: no mnemonic");
211 PWARN(
"Invalid commodity: 0 fraction");
218 gnc_commodity_find_currency (
QofBook *book, xmlNodePtr tree)
222 gchar *exchange = NULL, *mnemonic = NULL;
225 for (node = tree->xmlChildrenNode; node; node = node->next)
227 if (g_strcmp0((
char*) node->name, cmdty_namespace) == 0)
228 exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
229 if (g_strcmp0((
char*) node->name, cmdty_id) == 0)
230 mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
238 currency = gnc_commodity_table_lookup(table, exchange, mnemonic);
250 gnc_commodity_end_handler(gpointer data_for_children,
251 GSList* data_from_children, GSList* sibling_data,
252 gpointer parent_data, gpointer global_data,
253 gpointer *result,
const gchar *tag)
257 xmlNodePtr tree = (xmlNodePtr)data_for_children;
259 QofBook *book = gdata->bookdata;
273 g_return_val_if_fail(tree, FALSE);
276 old_com = gnc_commodity_find_currency(book, tree);
280 for (achild = tree->xmlChildrenNode; achild; achild = achild->next)
282 set_commodity_value(achild, com);
285 if (!valid_commodity(com))
287 PWARN(
"Invalid commodity parsed");
288 xmlElemDump(stdout, NULL, tree);
295 gdata->cb(tag, gdata->parsedata, com);
304 gnc_commodity_sixtp_parser_create(
void)
306 return sixtp_dom_parser_new(gnc_commodity_end_handler, NULL, NULL);
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
const char * gnc_commodity_get_namespace_compat(const gnc_commodity *cm)
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define PWARN(format, args...)
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Account handling public routines.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
void gnc_commodity_destroy(gnc_commodity *cm)
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
const gchar * QofLogModule