Clean up timespec comments in the XML backend.

Noting where the word must stay; most significantly for KVP types and for
parsing Version 1 XML files.
This commit is contained in:
John Ralls
2018-08-03 14:00:07 -07:00
parent b32a8a9390
commit 755773ac4c
4 changed files with 18 additions and 14 deletions

View File

@@ -271,6 +271,9 @@ add_kvp_value_node (xmlNodePtr node, const gchar* tag, KvpValue* val)
add_text_to_node (val_node, "guid", guidstr);
break;
}
/* Note: The type attribute must remain 'timespec' to maintain
* compatibility.
*/
case KvpValue::Type::TIME64:
{
auto t = val->get<Time64> ();

View File

@@ -348,6 +348,8 @@ struct kvp_val_converter
const gchar* tag;
KvpValue* (*converter) (xmlNodePtr node);
};
/* Note: The type attribute must remain 'timespec' to maintain compatibility.
*/
struct kvp_val_converter val_converters[] =
{
@@ -531,17 +533,16 @@ dom_tree_to_time64 (xmlNodePtr node)
/* Turn something like this
<date-posted>
<s>Mon, 05 Jun 2000 23:16:19 -0500</s>
<ns>658864000</ns>
<ts:date>Mon, 05 Jun 2000 23:16:19 -0500</ts:date>
</date-posted>
into a time64. If this returns FALSE, the effects on *ts are
undefined. The XML is valid if it has at least one of <s> or <ns>
and no more than one of each. Order is irrelevant. */
into a time64, returning INT64_MAX that we're using to flag an erroneous
date if there's a problem. Only one ts:date element is permitted for any
date attribute.
*/
time64 ret {INT64_MAX};
gboolean seen_s = FALSE;
gboolean seen_ns = FALSE;
gboolean seen = FALSE;
xmlNodePtr n;
for (n = node->xmlChildrenNode; n; n = n->next)
@@ -554,7 +555,7 @@ dom_tree_to_time64 (xmlNodePtr node)
case XML_ELEMENT_NODE:
if (g_strcmp0 ("ts:date", (char*)n->name) == 0)
{
if (seen_s)
if (seen)
{
return INT64_MAX;
}
@@ -568,21 +569,21 @@ dom_tree_to_time64 (xmlNodePtr node)
ret = gnc_iso8601_to_time64_gmt (content);
g_free (content);
seen_s = TRUE;
seen = TRUE;
}
}
break;
default:
PERR ("unexpected sub-node.");
return time_parse_failure ();
return INT64_MAX;
break;
}
}
if (!seen_s)
if (!seen)
{
PERR ("no ts:date node found.");
return time_parse_failure ();
return INT64_MAX;
}
return ret;

View File

@@ -346,7 +346,7 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
}
/****************************************************************************/
/* generic timespec handler.
/* generic timespec handler for XML Version 1 files.
A collection of node functions intended to parse a sub-node set
that looks like this:

View File

@@ -138,7 +138,7 @@ test_dom_tree_to_time64 (void)
time64 test_spec2 = dom_tree_to_time64 (test_node);
if (!dom_tree_valid_time64 (test_spec2, (const xmlChar*)"test-spec"))
{
failure_args ("dom_tree_to_timespec",
failure_args ("dom_tree_to_time64",
__FILE__, __LINE__, "NULL return");
printf ("Node looks like:\n");
xmlElemDump (stdout, NULL, test_node);