2020-10-04 05:44:43 -04:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
|
|
|
* Copyright 2018-2020, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file contains functions for rendering XML as JSON.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
#include <string.h>
|
2020-10-07 12:43:58 -04:00
|
|
|
#include <stdlib.h>
|
2020-10-04 11:51:29 -04:00
|
|
|
|
2020-10-04 05:44:43 -04:00
|
|
|
#include "xml2json.h"
|
|
|
|
#include "json.h"
|
2020-10-07 12:54:42 -04:00
|
|
|
#include "util.h"
|
2020-10-04 05:44:43 -04:00
|
|
|
|
2020-10-07 07:56:58 -04:00
|
|
|
/* For XMLSTR() */
|
|
|
|
#include "cfgfile.h"
|
|
|
|
|
2020-10-04 05:44:43 -04:00
|
|
|
#include "logging.h"
|
|
|
|
#define CATMODULE "xml2json"
|
2020-10-04 11:30:50 -04:00
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
struct xml2json_cache {
|
2020-10-06 17:00:53 -04:00
|
|
|
const char *default_namespace;
|
2020-10-04 11:51:29 -04:00
|
|
|
xmlNsPtr ns;
|
|
|
|
void (*render)(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
|
|
|
};
|
|
|
|
|
2020-10-07 12:43:01 -04:00
|
|
|
struct nodelist {
|
|
|
|
xmlNodePtr *nodes;
|
|
|
|
size_t len;
|
|
|
|
size_t fill;
|
|
|
|
};
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
static void render_node(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
2020-10-07 07:56:58 -04:00
|
|
|
static void render_node_generic(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
|
|
|
|
2020-10-07 12:43:58 -04:00
|
|
|
static void nodelist_init(struct nodelist *list)
|
|
|
|
{
|
|
|
|
memset(list, 0, sizeof(*list));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nodelist_free(struct nodelist *list)
|
|
|
|
{
|
|
|
|
free(list->nodes);
|
|
|
|
memset(list, 0, sizeof(*list));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nodelist_push(struct nodelist *list, xmlNodePtr node)
|
|
|
|
{
|
|
|
|
if (list->fill == list->len) {
|
|
|
|
xmlNodePtr *n = realloc(list->nodes, sizeof(xmlNodePtr)*(list->len + 16));
|
|
|
|
if (!n) {
|
|
|
|
ICECAST_LOG_ERROR("Can not allocate memory for node list. BAD.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->nodes = n;
|
|
|
|
list->len += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->nodes[list->fill++] = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static xmlNodePtr nodelist_get(struct nodelist *list, size_t idx)
|
|
|
|
{
|
|
|
|
if (idx >= list->fill)
|
|
|
|
return NULL;
|
|
|
|
return list->nodes[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nodelist_unset(struct nodelist *list, size_t idx)
|
|
|
|
{
|
|
|
|
if (idx >= list->fill)
|
|
|
|
return;
|
|
|
|
list->nodes[idx] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t nodelist_fill(struct nodelist *list)
|
|
|
|
{
|
|
|
|
return list->fill;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nodelist_is_empty(struct nodelist *list)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < list->fill; i++)
|
|
|
|
if (list->nodes[i])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-10 05:50:35 -04:00
|
|
|
static int has_ns_changed(xmlNodePtr node, xmlNodePtr parent)
|
|
|
|
{
|
|
|
|
xmlChar *xmlns;
|
|
|
|
|
|
|
|
if (parent == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (node->ns != parent->ns) {
|
|
|
|
if (node->ns && parent->ns && node->ns->href && parent->ns->href) {
|
|
|
|
if (strcmp((const char *)node->ns->href, (const char *)parent->ns->href) != 0)
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlns = xmlGetProp(node, XMLSTR("xmlns"));
|
|
|
|
if (xmlns) {
|
|
|
|
xmlFree(xmlns);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-10 05:39:02 -04:00
|
|
|
static void handle_node_identification(json_renderer_t *renderer, const char *name, const char *ns, const char *id, const char *definition, const char *akindof)
|
2020-10-10 03:55:46 -04:00
|
|
|
{
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
2020-10-10 05:39:02 -04:00
|
|
|
#define handle_node_identification__single(name) \
|
|
|
|
if ((name)) { \
|
|
|
|
json_renderer_write_key(renderer, ( # name ), JSON_RENDERER_FLAGS_NONE); \
|
|
|
|
json_renderer_write_string(renderer, (name), JSON_RENDERER_FLAGS_NONE); \
|
2020-10-10 03:55:46 -04:00
|
|
|
}
|
2020-10-10 05:39:02 -04:00
|
|
|
|
|
|
|
handle_node_identification__single(name)
|
|
|
|
handle_node_identification__single(ns)
|
|
|
|
handle_node_identification__single(id)
|
|
|
|
handle_node_identification__single(definition)
|
|
|
|
handle_node_identification__single(akindof)
|
|
|
|
|
2020-10-10 03:55:46 -04:00
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
2020-10-07 12:43:01 -04:00
|
|
|
static void handle_textchildnode(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)node->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char*)value, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 12:54:42 -04:00
|
|
|
static void handle_booleanchildnode(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)node->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_boolean(renderer, util_str_to_bool((const char*)value));
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 12:43:01 -04:00
|
|
|
static int handle_node_modules(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
if (node->type == XML_ELEMENT_NODE && strcmp((const char *)node->name, "modules") == 0) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE && cur->name && strcmp((const char *)cur->name, "module") == 0) {
|
|
|
|
xmlChar *name = xmlGetProp(cur, XMLSTR("name"));
|
|
|
|
if (name) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->properties) {
|
|
|
|
xmlAttrPtr prop = node->properties;
|
|
|
|
|
|
|
|
do {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, prop->children, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, (const char*)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char*)value, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
} while ((prop = prop->next));
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
xmlFree(name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
json_renderer_write_key(renderer, "unhandled-child", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
render_node(renderer, doc, cur, node, cache);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-07 07:56:58 -04:00
|
|
|
static void render_node_legacyresponse(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
if (node->type == XML_ELEMENT_NODE) {
|
|
|
|
const char *nodename = (const char *)node->name;
|
|
|
|
handled = 1;
|
|
|
|
if (strcmp(nodename, "iceresponse") == 0) {
|
2020-10-10 04:00:01 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
2020-10-10 05:39:02 -04:00
|
|
|
handle_node_identification(renderer, "iceresponse", XMLNS_LEGACY_RESPONSE, NULL, NULL, NULL);
|
2020-10-07 07:56:58 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int handled_child = 1;
|
|
|
|
|
|
|
|
if (cur->type == XML_ELEMENT_NODE && cur->name) {
|
|
|
|
if (strcmp((const char *)cur->name, "message") == 0) {
|
2020-10-07 12:43:01 -04:00
|
|
|
handle_textchildnode(renderer, doc, cur, node, cache);
|
2020-10-07 07:56:58 -04:00
|
|
|
} else if (strcmp((const char *)cur->name, "return") == 0) {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, "success", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_boolean(renderer, strcmp((const char *)value, "1") == 0);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
} else if (strcmp((const char *)cur->name, "modules") == 0) {
|
|
|
|
json_renderer_write_key(renderer, "modules", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
render_node(renderer, doc, cur, node, cache);
|
|
|
|
} else {
|
|
|
|
handled_child = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
handled_child = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled_child) {
|
|
|
|
json_renderer_write_key(renderer, "unhandled-child", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
render_node(renderer, doc, cur, node, cache);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
2020-10-10 04:00:01 -04:00
|
|
|
json_renderer_end(renderer);
|
2020-10-07 07:56:58 -04:00
|
|
|
} else if (strcmp(nodename, "modules") == 0) {
|
2020-10-07 12:43:01 -04:00
|
|
|
handled = handle_node_modules(renderer, doc, node, parent, cache);
|
2020-10-07 07:56:58 -04:00
|
|
|
} else {
|
|
|
|
handled = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
render_node_generic(renderer, doc, node, parent, cache);
|
|
|
|
}
|
2020-10-04 11:51:29 -04:00
|
|
|
|
2020-10-07 15:11:13 -04:00
|
|
|
static int handle_simple_child(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache, xmlNodePtr child, const char * number_keys[], const char * boolean_keys[])
|
|
|
|
{
|
|
|
|
if (child->type == XML_ELEMENT_NODE && child->name) {
|
2020-10-07 16:58:28 -04:00
|
|
|
const char *childname = (const char *)child->name;
|
2020-10-07 15:11:13 -04:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; number_keys[i]; i++) {
|
2020-10-07 16:58:28 -04:00
|
|
|
if (strcmp(childname, number_keys[i]) == 0) {
|
2020-10-07 15:11:13 -04:00
|
|
|
xmlChar *value = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
2020-10-07 16:58:28 -04:00
|
|
|
json_renderer_write_key(renderer, childname, JSON_RENDERER_FLAGS_NONE);
|
2020-10-07 15:11:13 -04:00
|
|
|
json_renderer_write_int(renderer, strtoll((const char*)value, NULL, 10));
|
|
|
|
xmlFree(value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; boolean_keys[i]; i++) {
|
2020-10-07 16:58:28 -04:00
|
|
|
if (strcmp(childname, boolean_keys[i]) == 0) {
|
2020-10-07 15:11:13 -04:00
|
|
|
handle_booleanchildnode(renderer, doc, child, node, cache);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 16:58:28 -04:00
|
|
|
if (strcmp(childname, "max_listeners") == 0) {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, childname, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (strcmp((const char *)value, "unlimited") == 0) {
|
|
|
|
json_renderer_write_null(renderer);
|
|
|
|
} else {
|
|
|
|
json_renderer_write_int(renderer, strtoll((const char*)value, NULL, 10));
|
|
|
|
}
|
|
|
|
xmlFree(value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(childname, "authenticator") == 0) {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, childname, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_boolean(renderer, strlen((const char *)value));
|
|
|
|
xmlFree(value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 15:11:13 -04:00
|
|
|
if (child->xmlChildrenNode && !child->xmlChildrenNode->next && child->xmlChildrenNode->type == XML_TEXT_NODE) {
|
|
|
|
handle_textchildnode(renderer, doc, child, node, cache);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void render_node_legacystats(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
static const char * number_keys_global[] = {
|
|
|
|
"listeners", "clients", "client_connections", "connections", "file_connections", "listener_connections",
|
|
|
|
"source_client_connections", "source_relay_connections", "source_total_connections", "sources", "stats", "stats_connections", NULL
|
|
|
|
};
|
|
|
|
static const char * boolean_keys_global[] = {
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const char * number_keys_source[] = {
|
|
|
|
"audio_bitrate", "audio_channels", "audio_samplerate", "ice-bitrate", "listener_peak", "listeners", "slow_listeners",
|
2020-10-11 04:18:55 -04:00
|
|
|
"total_bytes_read", "total_bytes_sent", "connected", NULL
|
2020-10-07 15:11:13 -04:00
|
|
|
};
|
|
|
|
static const char * boolean_keys_source[] = {
|
|
|
|
"public", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
if (node->type == XML_ELEMENT_NODE) {
|
|
|
|
const char *nodename = (const char *)node->name;
|
|
|
|
handled = 1;
|
2020-10-11 04:18:55 -04:00
|
|
|
if (strcmp(nodename, "icestats") == 0 || strcmp(nodename, "source") == 0 || strcmp(nodename, "listener") == 0) {
|
2020-10-07 15:11:13 -04:00
|
|
|
int is_icestats = strcmp(nodename, "icestats") == 0;
|
|
|
|
struct nodelist nodelist;
|
|
|
|
size_t i;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
nodelist_init(&nodelist);
|
|
|
|
|
2020-10-09 15:40:52 -04:00
|
|
|
if (is_icestats) {
|
2020-10-07 15:11:13 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
2020-10-10 05:39:02 -04:00
|
|
|
handle_node_identification(renderer, "icestats", XMLNS_LEGACY_STATS, NULL, NULL, NULL);
|
2020-10-09 15:40:52 -04:00
|
|
|
}
|
2020-10-07 15:11:13 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
do {
|
|
|
|
if (!handle_simple_child(renderer, doc, node, parent, cache, cur,
|
|
|
|
is_icestats ? number_keys_global : number_keys_source,
|
|
|
|
is_icestats ? boolean_keys_global : boolean_keys_source
|
|
|
|
)) {
|
|
|
|
nodelist_push(&nodelist, cur);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
len = nodelist_fill(&nodelist);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
xmlNodePtr cur = nodelist_get(&nodelist, i);
|
|
|
|
if (cur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cur->type == XML_ELEMENT_NODE && cur->name) {
|
|
|
|
if (strcmp((const char *)cur->name, "modules") == 0) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
handle_node_modules(renderer, doc, cur, node, cache);
|
|
|
|
nodelist_unset(&nodelist, i);
|
2020-10-11 04:51:38 -04:00
|
|
|
} else if (strcmp((const char *)cur->name, "source") == 0 || strcmp((const char *)cur->name, "role") == 0) {
|
|
|
|
const char *key = "id";
|
2020-10-07 15:11:13 -04:00
|
|
|
size_t j;
|
|
|
|
|
2020-10-11 04:51:38 -04:00
|
|
|
if (strcmp((const char *)cur->name, "source") == 0)
|
|
|
|
key = "mount";
|
|
|
|
|
2020-10-07 15:11:13 -04:00
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
|
|
|
|
for (j = i; j < len; j++) {
|
|
|
|
xmlNodePtr subcur = nodelist_get(&nodelist, j);
|
|
|
|
if (subcur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (subcur->type == XML_ELEMENT_NODE && subcur->name && strcmp((const char *)cur->name, (const char *)subcur->name) == 0) {
|
2020-10-11 04:51:38 -04:00
|
|
|
xmlChar *keyval = xmlGetProp(subcur, XMLSTR(key));
|
|
|
|
if (keyval) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)keyval, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
xmlFree(keyval);
|
2020-10-07 15:11:13 -04:00
|
|
|
nodelist_unset(&nodelist, j);
|
2020-10-07 16:15:49 -04:00
|
|
|
render_node_legacystats(renderer, doc, subcur, cur, cache);
|
2020-10-07 15:11:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_end(renderer);
|
2020-10-11 04:18:55 -04:00
|
|
|
} else if (strcmp((const char *)cur->name, "listener") == 0) {
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
|
|
|
|
for (j = i; j < len; j++) {
|
|
|
|
xmlNodePtr subcur = nodelist_get(&nodelist, j);
|
|
|
|
if (subcur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (subcur->type == XML_ELEMENT_NODE && subcur->name && strcmp((const char *)cur->name, (const char *)subcur->name) == 0) {
|
|
|
|
nodelist_unset(&nodelist, j);
|
|
|
|
render_node_legacystats(renderer, doc, subcur, cur, cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_end(renderer);
|
2020-10-07 15:11:13 -04:00
|
|
|
} else if (strcmp((const char *)cur->name, "metadata") == 0) {
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
for (j = i; j < len; j++) {
|
|
|
|
xmlNodePtr subcur = nodelist_get(&nodelist, j);
|
|
|
|
if (subcur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (subcur->type == XML_ELEMENT_NODE && subcur->name && strcmp((const char *)cur->name, (const char *)subcur->name) == 0) {
|
|
|
|
xmlNodePtr child = subcur->xmlChildrenNode;
|
|
|
|
while (child) {
|
|
|
|
handle_textchildnode(renderer, doc, child, subcur, cache);
|
|
|
|
child = child->next;
|
|
|
|
}
|
|
|
|
nodelist_unset(&nodelist, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
} else if (strcmp((const char *)cur->name, "authentication") == 0) {
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
for (j = i; j < len; j++) {
|
|
|
|
xmlNodePtr subcur = nodelist_get(&nodelist, j);
|
|
|
|
if (subcur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (subcur->type == XML_ELEMENT_NODE && subcur->name && strcmp((const char *)cur->name, (const char *)subcur->name) == 0) {
|
|
|
|
xmlNodePtr child = subcur->xmlChildrenNode;
|
|
|
|
while (child) {
|
|
|
|
render_node_legacystats(renderer, doc, child, subcur, cache);
|
|
|
|
child = child->next;
|
|
|
|
}
|
|
|
|
nodelist_unset(&nodelist, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
} else if (strcmp((const char *)cur->name, "playlist") == 0) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
render_node(renderer, doc, cur, node, cache);
|
|
|
|
nodelist_unset(&nodelist, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//render_node_generic(renderer, doc, node, parent, cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nodelist_is_empty(&nodelist)) {
|
|
|
|
json_renderer_write_key(renderer, "unhandled-child", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
len = nodelist_fill(&nodelist);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
xmlNodePtr cur = nodelist_get(&nodelist, i);
|
|
|
|
if (cur == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
render_node(renderer, doc, cur, node, cache);
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
if (is_icestats)
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
|
|
|
|
nodelist_free(&nodelist);
|
|
|
|
} else if (strcmp(nodename, "role") == 0) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->properties) {
|
|
|
|
xmlAttrPtr cur = node->properties;
|
|
|
|
|
|
|
|
do {
|
|
|
|
const char *name = (const char*)cur->name;
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, cur->children, 1);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (strncmp(name, "can-", 4) == 0) {
|
|
|
|
json_renderer_write_boolean(renderer, util_str_to_bool((const char *)value));
|
|
|
|
} else {
|
|
|
|
json_renderer_write_string(renderer, (const char*)value, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
} while ((cur = cur->next));
|
|
|
|
}
|
2020-10-11 04:51:38 -04:00
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
do {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE && cur->name) {
|
|
|
|
if (strcmp((const char *)cur->name, "users") == 0) {
|
|
|
|
json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
if (cur->xmlChildrenNode) {
|
|
|
|
xmlNodePtr subcur = cur->xmlChildrenNode;
|
|
|
|
do {
|
|
|
|
render_node_legacystats(renderer, doc, subcur, cur, cache);
|
|
|
|
subcur = subcur->next;
|
|
|
|
} while (subcur);
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
} else if (strcmp(nodename, "user") == 0) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
do {
|
|
|
|
if (cur->xmlChildrenNode && !cur->xmlChildrenNode->next && cur->xmlChildrenNode->type == XML_TEXT_NODE) {
|
|
|
|
handle_textchildnode(renderer, doc, cur, node, cache);
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
}
|
2020-10-07 15:11:13 -04:00
|
|
|
json_renderer_end(renderer);
|
|
|
|
} else {
|
|
|
|
handled = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
render_node_generic(renderer, doc, node, parent, cache);
|
|
|
|
}
|
|
|
|
|
2020-10-07 16:14:22 -04:00
|
|
|
static void render_node_xspf(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
const char * text_keys[] = {"title", "creator", "annotation", "info", "identifier", "image", "date", "license", "album", NULL};
|
|
|
|
const char * uint_keys[] = {"trackNum", "duration", NULL};
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
if (node->type == XML_ELEMENT_NODE) {
|
|
|
|
const char *nodename = (const char *)node->name;
|
|
|
|
int handle_childs = 0;
|
|
|
|
int close_after_me = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
handled = 1;
|
|
|
|
|
|
|
|
for (i = 0; text_keys[i]; i++) {
|
|
|
|
if (strcmp(nodename, text_keys[i]) == 0) {
|
|
|
|
handle_textchildnode(renderer, doc, node, parent, cache);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; uint_keys[i]; i++) {
|
|
|
|
if (strcmp(nodename, uint_keys[i]) == 0) {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
|
|
|
if (value) {
|
|
|
|
long long int val = strtoll((const char*)value, NULL, 10);
|
|
|
|
if (val < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, nodename, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_uint(renderer, val);
|
|
|
|
xmlFree(value);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; text_keys[i]; i++) {
|
|
|
|
if (strcmp(nodename, text_keys[i]) == 0) {
|
|
|
|
handle_textchildnode(renderer, doc, node, parent, cache);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(nodename, "playlist") == 0) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
json_renderer_write_key(renderer, "playlist", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
|
|
|
|
handle_childs = 1;
|
|
|
|
close_after_me = 2;
|
|
|
|
} else if (strcmp(nodename, "trackList") == 0) {
|
|
|
|
json_renderer_write_key(renderer, "track", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
|
|
|
|
handle_childs = 1;
|
|
|
|
close_after_me = 1;
|
|
|
|
} else if (strcmp(nodename, "track") == 0) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
|
|
|
|
handle_childs = 1;
|
|
|
|
close_after_me = 1;
|
|
|
|
} else {
|
|
|
|
handled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
if (handle_childs) {
|
|
|
|
xmlNodePtr child = node->xmlChildrenNode;
|
|
|
|
while (child) {
|
|
|
|
render_node_xspf(renderer, doc, child, node, cache);
|
|
|
|
child = child->next;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; close_after_me; close_after_me--)
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
render_node_generic(renderer, doc, node, parent, cache);
|
|
|
|
}
|
|
|
|
|
2020-10-10 05:50:35 -04:00
|
|
|
static void render_node_reportxml(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
static const char * valid_tags[] = {
|
|
|
|
"report", "definition", "incident", "state", "backtrace", "position", "more", "fix",
|
|
|
|
"action", "reason", "text", "timestamp", "resource", "value", "reference", "extension", NULL
|
|
|
|
};
|
|
|
|
static const char * skip_props[] = {
|
|
|
|
"id", "definition", "akindof", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
if (node->type == XML_ELEMENT_NODE) {
|
|
|
|
const char *nodename = (const char *)node->name;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; valid_tags[i]; i++) {
|
|
|
|
if (strcmp(nodename, valid_tags[i]) == 0) {
|
|
|
|
xmlChar *id = xmlGetProp(node, XMLSTR("id"));
|
|
|
|
xmlChar *definition = xmlGetProp(node, XMLSTR("definition"));
|
|
|
|
xmlChar *akindof = xmlGetProp(node, XMLSTR("akindof"));
|
|
|
|
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
handle_node_identification(renderer, nodename, has_ns_changed(node, parent) ? XMLNS_REPORTXML : NULL, (const char *)id, (const char *)definition, (const char *)akindof);
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
xmlFree(id);
|
|
|
|
if (definition)
|
|
|
|
xmlFree(definition);
|
|
|
|
if (akindof)
|
|
|
|
xmlFree(akindof);
|
|
|
|
|
|
|
|
if (node->properties || node->xmlChildrenNode) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
if (node->properties) {
|
|
|
|
xmlAttrPtr cur = node->properties;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int found = 0;
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
for (j = 0; skip_props[j]; j++) {
|
|
|
|
if (strcmp((const char*)cur->name, skip_props[j]) == 0) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
xmlChar *value = xmlNodeListGetString(doc, cur->children, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, (const char*)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char*)value, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while ((cur = cur->next));
|
|
|
|
}
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
xmlNodePtr child = node->xmlChildrenNode;
|
|
|
|
while (child) {
|
|
|
|
render_node(renderer, doc, child, node, cache);
|
|
|
|
child = child->next;
|
|
|
|
};
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render_node_generic(renderer, doc, node, parent, cache);
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
static void render_node_generic(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
2020-10-04 11:30:50 -04:00
|
|
|
{
|
2020-10-10 06:00:23 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
2020-10-04 11:30:50 -04:00
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, "type", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
switch (node->type) {
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
json_renderer_write_string(renderer, "element", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (node->name) {
|
|
|
|
json_renderer_write_key(renderer, "name", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char *)node->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XML_TEXT_NODE:
|
|
|
|
json_renderer_write_string(renderer, "text", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
break;
|
|
|
|
case XML_COMMENT_NODE:
|
|
|
|
json_renderer_write_string(renderer, "comment", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
json_renderer_write_null(renderer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->content) {
|
|
|
|
json_renderer_write_key(renderer, "text", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char *)node->content, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_write_key(renderer, "ns", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (node->ns && node->ns->href) {
|
|
|
|
json_renderer_write_string(renderer, (const char *)node->ns->href, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (node->ns->prefix) {
|
|
|
|
json_renderer_write_key(renderer, "nsprefix", JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char *)node->ns->prefix, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
json_renderer_write_null(renderer);
|
|
|
|
}
|
2020-10-10 06:00:23 -04:00
|
|
|
json_renderer_end(renderer);
|
2020-10-04 11:30:50 -04:00
|
|
|
|
2020-10-10 06:00:23 -04:00
|
|
|
if (node->properties || node->xmlChildrenNode) {
|
2020-10-04 11:30:50 -04:00
|
|
|
xmlAttrPtr cur = node->properties;
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT);
|
2020-10-10 06:00:23 -04:00
|
|
|
|
|
|
|
while (cur) {
|
2020-10-04 11:30:50 -04:00
|
|
|
xmlChar *value = xmlNodeListGetString(doc, cur->children, 1);
|
|
|
|
if (value) {
|
|
|
|
json_renderer_write_key(renderer, (const char*)cur->name, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
json_renderer_write_string(renderer, (const char*)value, JSON_RENDERER_FLAGS_NONE);
|
|
|
|
xmlFree(value);
|
|
|
|
}
|
2020-10-10 06:00:23 -04:00
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
2020-10-04 11:30:50 -04:00
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->xmlChildrenNode) {
|
|
|
|
xmlNodePtr cur = node->xmlChildrenNode;
|
|
|
|
|
|
|
|
json_renderer_begin(renderer, JSON_ELEMENT_TYPE_ARRAY);
|
|
|
|
do {
|
2020-10-04 11:51:29 -04:00
|
|
|
render_node(renderer, doc, cur, node, cache);
|
2020-10-04 11:30:50 -04:00
|
|
|
cur = cur->next;
|
|
|
|
} while (cur);
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
json_renderer_end(renderer);
|
|
|
|
}
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
|
|
|
|
static void render_node(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
|
|
|
{
|
|
|
|
void (*render)(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache) = NULL;
|
2020-10-07 15:23:12 -04:00
|
|
|
xmlChar * workaroundProp = xmlGetProp(node, XMLSTR("xmlns"));
|
2020-10-04 11:51:29 -04:00
|
|
|
|
2020-10-07 15:23:12 -04:00
|
|
|
if (node->ns == cache->ns && !workaroundProp)
|
2020-10-04 11:51:29 -04:00
|
|
|
render = cache->render;
|
|
|
|
|
|
|
|
if (render == NULL) {
|
2020-10-06 17:00:53 -04:00
|
|
|
const char *href = cache->default_namespace;
|
|
|
|
|
|
|
|
if (node->ns && node->ns->href)
|
|
|
|
href = (const char *)node->ns->href;
|
2020-10-04 11:51:29 -04:00
|
|
|
|
2020-10-07 15:55:21 -04:00
|
|
|
if (workaroundProp)
|
2020-10-07 15:23:12 -04:00
|
|
|
href = (const char *)workaroundProp;
|
|
|
|
|
2020-10-06 17:00:53 -04:00
|
|
|
if (href) {
|
2020-10-10 03:44:26 -04:00
|
|
|
if (strcmp(href, XMLNS_LEGACY_RESPONSE) == 0) {
|
2020-10-07 07:56:58 -04:00
|
|
|
render = render_node_legacyresponse;
|
2020-10-10 03:44:26 -04:00
|
|
|
} else if (strcmp(href, XMLNS_LEGACY_STATS) == 0) {
|
2020-10-07 15:11:13 -04:00
|
|
|
render = render_node_legacystats;
|
2020-10-10 03:44:26 -04:00
|
|
|
} else if (strcmp(href, XMLNS_XSPF) == 0) {
|
2020-10-07 15:55:21 -04:00
|
|
|
render = render_node_xspf;
|
2020-10-10 05:50:35 -04:00
|
|
|
} else if (strcmp(href, XMLNS_REPORTXML) == 0) {
|
|
|
|
render = render_node_reportxml;
|
2020-10-07 07:56:58 -04:00
|
|
|
}
|
2020-10-04 11:51:29 -04:00
|
|
|
}
|
|
|
|
|
2020-10-06 17:00:53 -04:00
|
|
|
if (render == NULL)
|
|
|
|
render = render_node_generic;
|
|
|
|
|
|
|
|
cache->ns = node->ns;
|
|
|
|
cache->render = render;
|
|
|
|
}
|
2020-10-04 11:51:29 -04:00
|
|
|
|
2020-10-07 15:23:12 -04:00
|
|
|
if (workaroundProp)
|
|
|
|
xmlFree(workaroundProp);
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
render(renderer, doc, node, parent, cache);
|
|
|
|
}
|
|
|
|
|
2020-10-04 16:37:16 -04:00
|
|
|
char * xml2json_render_doc_simple(xmlDocPtr doc, const char *default_namespace)
|
2020-10-04 11:30:50 -04:00
|
|
|
{
|
2020-10-04 11:51:29 -04:00
|
|
|
struct xml2json_cache cache;
|
2020-10-04 11:30:50 -04:00
|
|
|
json_renderer_t *renderer;
|
|
|
|
xmlNodePtr xmlroot;
|
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
renderer = json_renderer_create(JSON_RENDERER_FLAGS_NONE);
|
|
|
|
if (!renderer)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
xmlroot = xmlDocGetRootElement(doc);
|
|
|
|
if (!xmlroot)
|
|
|
|
return NULL;
|
|
|
|
|
2020-10-04 11:51:29 -04:00
|
|
|
memset(&cache, 0, sizeof(cache));
|
2020-10-06 17:00:53 -04:00
|
|
|
cache.default_namespace = default_namespace;
|
2020-10-04 11:51:29 -04:00
|
|
|
|
|
|
|
render_node(renderer, doc, xmlroot, NULL, &cache);
|
2020-10-04 11:30:50 -04:00
|
|
|
|
|
|
|
return json_renderer_finish(&renderer);
|
|
|
|
}
|