|
|
|
@ -67,24 +67,33 @@ static int ooxml_is_int(const char *value, size_t len, int32_t *val) |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int ooxml_parse_value(json_object *wrkptr, const char *element_tag, const xmlChar *node_value) |
|
|
|
|
static int ooxml_parse_value(json_object *wrkptr, const char *arrname, const xmlChar *node_value) |
|
|
|
|
{ |
|
|
|
|
int ret = CL_SUCCESS; |
|
|
|
|
json_object *newobj, *arrobj; |
|
|
|
|
int val; |
|
|
|
|
|
|
|
|
|
arrobj = cli_jsonarray(wrkptr, arrname); |
|
|
|
|
|
|
|
|
|
if (ooxml_is_int(node_value, xmlStrlen(node_value), &val)) { |
|
|
|
|
ret = cli_jsonint(wrkptr, element_tag, val); |
|
|
|
|
newobj = json_object_new_int(val); |
|
|
|
|
} |
|
|
|
|
else if (!xmlStrcmp(node_value, "true")) { |
|
|
|
|
ret = cli_jsonbool(wrkptr, element_tag, 1); |
|
|
|
|
newobj = json_object_new_boolean(1); |
|
|
|
|
} |
|
|
|
|
else if (!xmlStrcmp(node_value, "false")) { |
|
|
|
|
ret = cli_jsonbool(wrkptr, element_tag, 0); |
|
|
|
|
newobj = json_object_new_boolean(0); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
ret = cli_jsonstr(wrkptr, element_tag, node_value); |
|
|
|
|
newobj = json_object_new_string(node_value); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
|
|
|
|
|
if (NULL == newobj) { |
|
|
|
|
cli_errmsg("ooxml_parse_value: no memory for json value for [%s]\n", arrname); |
|
|
|
|
return CL_EMEM; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
json_object_array_add(arrobj, newobj); |
|
|
|
|
return CL_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const char *ooxml_keys[] = { |
|
|
|
@ -237,16 +246,17 @@ static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_objec |
|
|
|
|
return CL_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* handle attributes if you want */ |
|
|
|
|
/* generate json object */ |
|
|
|
|
thisjobj = cli_jsonobj(wrkptr, element_tag); |
|
|
|
|
if (!thisjobj) { |
|
|
|
|
return CL_EPARSE; |
|
|
|
|
} |
|
|
|
|
cli_dbgmsg("ooxml_parse_element: generated json object [%s]\n", element_tag); |
|
|
|
|
|
|
|
|
|
/* handle attributes */ |
|
|
|
|
if (xmlTextReaderHasAttributes(reader) == 1) { |
|
|
|
|
json_object *attributes; |
|
|
|
|
|
|
|
|
|
thisjobj = cli_jsonobj(wrkptr, element_tag); |
|
|
|
|
if (!thisjobj) { |
|
|
|
|
return CL_EPARSE; |
|
|
|
|
} |
|
|
|
|
cli_dbgmsg("ooxml_parse_element: retrieved json object [%s]\n", element_tag); |
|
|
|
|
|
|
|
|
|
attributes = cli_jsonobj(thisjobj, "Attributes"); |
|
|
|
|
if (!thisjobj) { |
|
|
|
|
return CL_EPARSE; |
|
|
|
@ -278,15 +288,6 @@ static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_objec |
|
|
|
|
node_type = xmlTextReaderNodeType(reader); |
|
|
|
|
switch (node_type) { |
|
|
|
|
case XML_READER_TYPE_ELEMENT: |
|
|
|
|
/* generate json object node */ |
|
|
|
|
if (!thisjobj) { |
|
|
|
|
thisjobj = cli_jsonobj(wrkptr, element_tag); |
|
|
|
|
if (!thisjobj) { |
|
|
|
|
return CL_EPARSE; |
|
|
|
|
} |
|
|
|
|
cli_dbgmsg("ooxml_parse_element: retrieved json object [%s]\n", element_tag); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rlvl == 0) |
|
|
|
|
root = thisjobj; |
|
|
|
|
|
|
|
|
@ -324,7 +325,7 @@ static int ooxml_parse_element(cli_ctx *ctx, xmlTextReaderPtr reader, json_objec |
|
|
|
|
case XML_READER_TYPE_TEXT: |
|
|
|
|
node_value = xmlTextReaderConstValue(reader); |
|
|
|
|
|
|
|
|
|
ret = ooxml_parse_value(wrkptr, element_tag, node_value); |
|
|
|
|
ret = ooxml_parse_value(thisjobj, "Value", node_value); |
|
|
|
|
if (ret != CL_SUCCESS) |
|
|
|
|
return ret; |
|
|
|
|
|
|
|
|
|