From 9ad34f97ad7d18b3a4283ca604f25afda31e35a7 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sun, 11 Oct 2020 08:51:38 +0000 Subject: [PATCH] Feature: Added JSON output for admin command manageauth --- src/admin.c | 2 ++ src/xml2json.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/admin.c b/src/admin.c index 6424b37b..aace3423 100644 --- a/src/admin.c +++ b/src/admin.c @@ -100,6 +100,7 @@ #define ADMIN_XSL_RESPONSE "response.xsl" #define MANAGEAUTH_RAW_REQUEST "manageauth" #define MANAGEAUTH_HTML_REQUEST "manageauth.xsl" +#define MANAGEAUTH_JSON_REQUEST "manageauth.json" #define UPDATEMETADATA_RAW_REQUEST "updatemetadata" #define UPDATEMETADATA_HTML_REQUEST "updatemetadata.xsl" #define UPDATEMETADATA_JSON_REQUEST "updatemetadata.json" @@ -177,6 +178,7 @@ static const admin_command_handler_t handlers[] = { { KILLSOURCE_JSON_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_JSON, command_kill_source, NULL}, { MANAGEAUTH_RAW_REQUEST, ADMINTYPE_GENERAL, ADMIN_FORMAT_RAW, command_manageauth, NULL}, { MANAGEAUTH_HTML_REQUEST, ADMINTYPE_GENERAL, ADMIN_FORMAT_HTML, command_manageauth, NULL}, + { MANAGEAUTH_JSON_REQUEST, ADMINTYPE_GENERAL, ADMIN_FORMAT_JSON, command_manageauth, NULL}, { UPDATEMETADATA_RAW_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_RAW, command_updatemetadata, NULL}, { UPDATEMETADATA_HTML_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_HTML, command_updatemetadata, NULL}, { UPDATEMETADATA_JSON_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_JSON, command_updatemetadata, NULL}, diff --git a/src/xml2json.c b/src/xml2json.c index e0d819f4..3e48152c 100644 --- a/src/xml2json.c +++ b/src/xml2json.c @@ -378,9 +378,13 @@ static void render_node_legacystats(json_renderer_t *renderer, xmlDocPtr doc, xm 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); - } else if (strcmp((const char *)cur->name, "source") == 0) { + } else if (strcmp((const char *)cur->name, "source") == 0 || strcmp((const char *)cur->name, "role") == 0) { + const char *key = "id"; size_t j; + if (strcmp((const char *)cur->name, "source") == 0) + key = "mount"; + json_renderer_write_key(renderer, (const char *)cur->name, JSON_RENDERER_FLAGS_NONE); json_renderer_begin(renderer, JSON_ELEMENT_TYPE_OBJECT); @@ -390,10 +394,10 @@ static void render_node_legacystats(json_renderer_t *renderer, xmlDocPtr doc, xm continue; if (subcur->type == XML_ELEMENT_NODE && subcur->name && strcmp((const char *)cur->name, (const char *)subcur->name) == 0) { - xmlChar *mount = xmlGetProp(subcur, XMLSTR("mount")); - if (mount) { - json_renderer_write_key(renderer, (const char *)mount, JSON_RENDERER_FLAGS_NONE); - xmlFree(mount); + xmlChar *keyval = xmlGetProp(subcur, XMLSTR(key)); + if (keyval) { + json_renderer_write_key(renderer, (const char *)keyval, JSON_RENDERER_FLAGS_NONE); + xmlFree(keyval); nodelist_unset(&nodelist, j); render_node_legacystats(renderer, doc, subcur, cur, cache); } @@ -401,7 +405,6 @@ static void render_node_legacystats(json_renderer_t *renderer, xmlDocPtr doc, xm } json_renderer_end(renderer); - nodelist_unset(&nodelist, i); } else if (strcmp((const char *)cur->name, "listener") == 0) { size_t j; @@ -508,6 +511,38 @@ static void render_node_legacystats(json_renderer_t *renderer, xmlDocPtr doc, xm } } while ((cur = cur->next)); } + 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); + } json_renderer_end(renderer); } else { handled = 0;