mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-01-03 14:56:34 -05:00
Update: Generify the render_node_legacyresponse() code a bit
This commit is contained in:
parent
3fd16ac834
commit
7a9d42209e
105
src/xml2json.c
105
src/xml2json.c
@ -31,58 +31,28 @@ struct xml2json_cache {
|
||||
void (*render)(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
||||
};
|
||||
|
||||
struct nodelist {
|
||||
xmlNodePtr *nodes;
|
||||
size_t len;
|
||||
size_t fill;
|
||||
};
|
||||
|
||||
static void render_node(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
||||
static void render_node_generic(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache);
|
||||
|
||||
static void render_node_legacyresponse(json_renderer_t *renderer, xmlDocPtr doc, xmlNodePtr node, xmlNodePtr parent, struct xml2json_cache *cache)
|
||||
static void handle_textchildnode(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) {
|
||||
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) {
|
||||
xmlChar *value = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
|
||||
xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
||||
if (value) {
|
||||
json_renderer_write_key(renderer, "message", JSON_RENDERER_FLAGS_NONE);
|
||||
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);
|
||||
}
|
||||
} 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);
|
||||
} else if (strcmp(nodename, "modules") == 0) {
|
||||
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;
|
||||
@ -116,6 +86,57 @@ static void render_node_legacyresponse(json_renderer_t *renderer, xmlDocPtr doc,
|
||||
} while (cur);
|
||||
}
|
||||
json_renderer_end(renderer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
handle_textchildnode(renderer, doc, cur, node, cache);
|
||||
} 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);
|
||||
} else if (strcmp(nodename, "modules") == 0) {
|
||||
handled = handle_node_modules(renderer, doc, node, parent, cache);
|
||||
} else {
|
||||
handled = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user