Skip to content

Commit dcfc0e4

Browse files
Expand C deserialization support for xen-api dates
Signed-off-by: Danilo Del Busso <[email protected]>
1 parent 8f4c112 commit dcfc0e4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ocaml/sdk-gen/c/autogen/src/xen_common.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,26 @@ static void parse_into(xen_session *s, xmlNode *value_node,
950950
{
951951
struct tm tm;
952952
memset(&tm, 0, sizeof(tm));
953-
strptime((char *)string, "%Y%m%dT%H:%M:%S", &tm);
953+
// We only support basic ISO8601 since the C SDK only
954+
// connects to the XML-RPC backend
955+
char *formats[] = {
956+
// no dashes, no colons
957+
"%Y%m%dT%H%M%S",
958+
// no dashes, with colons
959+
"%Y%m%dT%H:%M:%S",
960+
// dashes and colons
961+
"%Y-%m-%dT%H:%M:%S",
962+
};
963+
int num_formats = sizeof(formats) / sizeof(formats[0]);
964+
965+
for (int i = 0; i < num_formats; i++)
966+
{
967+
if (strptime((char *)string, formats[i], &tm) != NULL)
968+
{
969+
break;
970+
}
971+
}
972+
954973
((time_t *)value)[slot] = (time_t)mktime(&tm);
955974
free(string);
956975
}

0 commit comments

Comments
 (0)