static inline gboolean set_timespec(xmlNodePtr node, GncOrder* order, void (*func)(GncOrder *order, Timespec ts)) { Timespec ts = dom_tree_to_timespec(node); if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE; func(order, ts); return TRUE; }
static gboolean price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, QofBook *book) { if (!p || !sub_node) return FALSE; gnc_price_begin_edit (p); if (g_strcmp0("price:id", (char*)sub_node->name) == 0) { GncGUID *c = dom_tree_to_guid(sub_node); if (!c) return FALSE; gnc_price_set_guid(p, c); g_free(c); } else if (g_strcmp0("price:commodity", (char*)sub_node->name) == 0) { gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book); if (!c) return FALSE; gnc_price_set_commodity(p, c); } else if (g_strcmp0("price:currency", (char*)sub_node->name) == 0) { gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, book); if (!c) return FALSE; gnc_price_set_currency(p, c); } else if (g_strcmp0("price:time", (char*)sub_node->name) == 0) { Timespec t = dom_tree_to_timespec(sub_node); if (!dom_tree_valid_timespec(&t, sub_node->name)) return FALSE; gnc_price_set_time(p, t); } else if (g_strcmp0("price:source", (char*)sub_node->name) == 0) { char *text = dom_tree_to_text(sub_node); if (!text) return FALSE; gnc_price_set_source(p, text); g_free(text); } else if (g_strcmp0("price:type", (char*)sub_node->name) == 0) { char *text = dom_tree_to_text(sub_node); if (!text) return FALSE; gnc_price_set_typestr(p, text); g_free(text); } else if (g_strcmp0("price:value", (char*)sub_node->name) == 0) { gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node); if (!value) return FALSE; gnc_price_set_value(p, *value); g_free(value); } gnc_price_commit_edit (p); return TRUE; }
static gboolean spl_reconcile_date_handler(xmlNodePtr node, gpointer data) { struct split_pdata *pdata = data; Timespec ts; ts = dom_tree_to_timespec(node); if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE; xaccSplitSetDateReconciledTS(pdata->split, &ts); return TRUE; }
static inline gboolean set_tran_date(xmlNodePtr node, Transaction *trn, void (*func)(Transaction *trn, const Timespec *tm)) { Timespec tm; tm = dom_tree_to_timespec(node); if (!dom_tree_valid_timespec(&tm, node->name)) return FALSE; func(trn, &tm); return TRUE; }
static void test_dom_tree_to_timespec(void) { int i; for (i = 0; i < 20; i++) { Timespec *test_spec1; Timespec test_spec2; xmlNodePtr test_node; test_spec1 = get_random_timespec(); test_node = timespec_to_dom_tree("test-spec", test_spec1); test_spec2 = dom_tree_to_timespec(test_node); if (!dom_tree_valid_timespec(&test_spec2, (const xmlChar*)"test-spec")) { failure_args("dom_tree_to_timespec", __FILE__, __LINE__, "NULL return"); printf("Node looks like:\n"); xmlElemDump(stdout, NULL, test_node); printf("\n"); } else if (timespec_cmp(test_spec1, &test_spec2) == 0) { success("dom_tree_to_timespec"); } else { failure("dom_tree_to_timespec"); printf("Node looks like:\n"); xmlElemDump(stdout, NULL, test_node); printf("\n"); printf("Secs are %" G_GUINT64_FORMAT " vs %" G_GUINT64_FORMAT " :: ", test_spec1->tv_sec, test_spec2.tv_sec); printf("NSecs are %ld vs %ld\n", test_spec1->tv_nsec, test_spec2.tv_nsec); } g_free(test_spec1); xmlFreeNode(test_node); } }