31 #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 static QofLogModule log_module = GNC_MOD_IO;
44 const gchar* commodity_version_string =
"2.0.0";
47 #define gnc_commodity_string "gnc:commodity" 48 #define cmdty_namespace "cmdty:space" 49 #define cmdty_id "cmdty:id" 50 #define cmdty_name "cmdty:name" 51 #define cmdty_xcode "cmdty:xcode" 52 #define cmdty_fraction "cmdty:fraction" 53 #define cmdty_get_quotes "cmdty:get_quotes" 54 #define cmdty_quote_source "cmdty:quote_source" 55 #define cmdty_quote_tz "cmdty:quote_tz" 56 #define cmdty_slots "cmdty:slots" 59 gnc_commodity_dom_tree_create (
const gnc_commodity* com)
61 gnc_quote_source* source;
65 xmlNodePtr slotsnode =
66 qof_instance_slots_to_dom_tree (cmdty_slots, QOF_INSTANCE (com));
71 ret = xmlNewNode (NULL, BAD_CAST gnc_commodity_string);
73 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST commodity_version_string);
75 xmlAddChild (ret, text_to_dom_tree (cmdty_namespace,
77 xmlAddChild (ret, text_to_dom_tree (cmdty_id,
84 xmlAddChild (ret, text_to_dom_tree (cmdty_name,
91 xmlAddChild (ret, text_to_dom_tree (cmdty_xcode, cusip));
94 xmlAddChild (ret, int_to_dom_tree (cmdty_fraction,
100 xmlNewChild (ret, NULL, BAD_CAST cmdty_get_quotes, NULL);
103 xmlAddChild (ret, text_to_dom_tree (cmdty_quote_source,
107 xmlAddChild (ret, text_to_dom_tree (cmdty_quote_tz,
string));
111 xmlAddChild (ret, slotsnode);
121 void (*func) (gnc_commodity* com,
const char* val);
135 set_commodity_value (xmlNodePtr node, gnc_commodity* com)
137 if (g_strcmp0 ((
char*) node->name, cmdty_fraction) == 0)
142 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
143 if (string_to_gint64 (
string, &val))
149 else if (g_strcmp0 ((
char*)node->name, cmdty_get_quotes) == 0)
153 else if (g_strcmp0 ((
char*)node->name, cmdty_quote_source) == 0)
155 gnc_quote_source* source;
158 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
165 else if (g_strcmp0 ((
char*)node->name, cmdty_slots) == 0)
168 dom_tree_create_instance_slots (node, QOF_INSTANCE (com));
174 for (mark = com_handlers; mark->tag; mark++)
176 if (g_strcmp0 (mark->tag, (
char*)node->name) == 0)
178 gchar* val = dom_tree_to_text (node);
180 (mark->func) (com, val);
189 valid_commodity (gnc_commodity* com)
193 PWARN (
"Invalid commodity: no namespace");
198 PWARN (
"Invalid commodity: no mnemonic");
203 PWARN (
"Invalid commodity: 0 fraction");
209 static gnc_commodity*
210 gnc_commodity_find_currency (QofBook* book, xmlNodePtr tree)
212 gnc_commodity_table*
table;
213 gnc_commodity* currency = NULL;
214 gchar* exchange = NULL, *mnemonic = NULL;
217 for (node = tree->xmlChildrenNode; node; node = node->next)
219 if (g_strcmp0 ((
char*) node->name, cmdty_namespace) == 0)
220 exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
221 if (g_strcmp0 ((
char*) node->name, cmdty_id) == 0)
222 mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
230 currency = gnc_commodity_table_lookup (
table, exchange, mnemonic);
242 gnc_commodity_end_handler (gpointer data_for_children,
243 GSList* data_from_children, GSList* sibling_data,
244 gpointer parent_data, gpointer global_data,
245 gpointer* result,
const gchar* tag)
247 gnc_commodity* com, *old_com;
249 xmlNodePtr tree = (xmlNodePtr)data_for_children;
250 gxpf_data* gdata = (gxpf_data*)global_data;
251 QofBook* book =
static_cast<decltype (book)
> (gdata->bookdata);
265 g_return_val_if_fail (tree, FALSE);
268 old_com = gnc_commodity_find_currency (book, tree);
272 for (achild = tree->xmlChildrenNode; achild; achild = achild->next)
274 set_commodity_value (achild, com);
277 if (!valid_commodity (com))
279 PWARN (
"Invalid commodity parsed");
280 xmlElemDump (stdout, NULL, tree);
287 gdata->cb (tag, gdata->parsedata, com);
296 gnc_commodity_sixtp_parser_create (
void)
298 return sixtp_dom_parser_new (gnc_commodity_end_handler, NULL, NULL);
This is the private header for the account structure.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
Create a new quote source.
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
Retrieve the automatic price quote timezone for the specified commodity.
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
#define PWARN(format, args...)
Log a warning.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
Account handling public routines.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Create a new commodity.
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source for the specified commodity.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the internal name of this quote source.
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
Copy src into dest.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.