1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Feature: Added JSON output for admin command manageauth

This commit is contained in:
Philipp Schafft 2020-10-11 08:51:38 +00:00
parent 5e9feb611a
commit 9ad34f97ad
2 changed files with 43 additions and 6 deletions

View File

@ -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},

View File

@ -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;