Skip to content

Commit

Permalink
Feature: Unifiy response root node generation a bit and make the modu…
Browse files Browse the repository at this point in the history
…le list universally available
  • Loading branch information
ph3-der-loewe committed Aug 8, 2018
1 parent d711ea1 commit bfcac5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion admin/includes/header.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ul>
<li class="on"><a href="/admin/stats.xsl">Administration</a></li>
<li><a href="/admin/listmounts.xsl">Mountpoint list</a></li>
<xsl:for-each select="(/report/extension | /)/icestats/modules/module">
<xsl:for-each select="(/report/extension/icestats | /icestats | /iceresponse)/modules/module">
<xsl:if test="@management-url and @management-title">
<li><a href="{@management-url}"><xsl:value-of select="@management-title" /></a></li>
</xsl:if>
Expand Down
31 changes: 21 additions & 10 deletions src/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ int admin_command_table_unregister(const char *prefix)
return -1;
}

/* build an XML root node including some common tags */
xmlNodePtr admin_build_rootnode(xmlDocPtr doc, const char *name)
{
xmlNodePtr rootnode = xmlNewDocNode(doc, NULL, XMLSTR(name), NULL);
xmlNodePtr modules = module_container_get_modulelist_as_xml(global.modulecontainer);

xmlAddChild(rootnode, modules);

return rootnode;
}

/* build an XML doc containing information about currently running sources.
* If a mountpoint is passed then that source will not be added to the XML
* doc even if the source is running */
Expand All @@ -330,7 +341,7 @@ xmlDocPtr admin_build_sourcelist(const char *mount)
time_t now = time(NULL);

doc = xmlNewDoc (XMLSTR("1.0"));
xmlnode = xmlNewDocNode (doc, NULL, XMLSTR("icestats"), NULL);
xmlnode = admin_build_rootnode(doc, "icestats");
xmlDocSetRootElement(doc, xmlnode);

if (mount) {
Expand Down Expand Up @@ -649,7 +660,7 @@ static void command_move_clients(client_t *client,
ICECAST_LOG_INFO("source is \"%s\", destination is \"%s\"", source->mount, dest->mount);

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
node = admin_build_rootnode(doc, "iceresponse");
xmlDocSetRootElement(doc, node);

source_move_clients(source, dest);
Expand Down Expand Up @@ -744,7 +755,7 @@ static void command_show_listeners(client_t *client,
char buf[22];

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL);
node = admin_build_rootnode(doc, "icestats");
srcnode = xmlNewChild(node, NULL, XMLSTR("source"), NULL);
xmlSetProp(srcnode, XMLSTR("mount"), XMLSTR(source->mount));
xmlDocSetRootElement(doc, node);
Expand Down Expand Up @@ -902,12 +913,12 @@ static void command_manageauth(client_t *client, source_t *source, admin_format_
}

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL);
node = admin_build_rootnode(doc, "icestats");

rolenode = admin_add_role_to_authentication(auth, node);

if (message) {
msgnode = xmlNewChild(node, NULL, XMLSTR("iceresponse"), NULL);
msgnode = admin_build_rootnode(doc, "iceresponse");
xmlNewTextChild(msgnode, NULL, XMLSTR("message"), XMLSTR(message));
}

Expand Down Expand Up @@ -941,7 +952,7 @@ static void command_kill_source(client_t *client,
xmlNodePtr node;

doc = xmlNewDoc (XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
node = admin_build_rootnode(doc, "iceresponse");
xmlNewTextChild(node, NULL, XMLSTR("message"), XMLSTR("Source Removed"));
xmlNewTextChild(node, NULL, XMLSTR("return"), XMLSTR("1"));
xmlDocSetRootElement(doc, node);
Expand Down Expand Up @@ -971,7 +982,7 @@ static void command_kill_client(client_t *client,
listener = source_find_client(source, id);

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
node = admin_build_rootnode(doc, "iceresponse");
xmlDocSetRootElement(doc, node);
ICECAST_LOG_DEBUG("Response is %d", response);

Expand Down Expand Up @@ -1028,7 +1039,7 @@ static void command_metadata(client_t *client,
int same_ip = 1;

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
node = admin_build_rootnode(doc, "iceresponse");
xmlDocSetRootElement(doc, node);

ICECAST_LOG_DEBUG("Got metadata update request");
Expand Down Expand Up @@ -1155,7 +1166,7 @@ static void command_queue_reload(client_t *client, source_t *source, admin_forma
global_unlock();

doc = xmlNewDoc (XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
node = admin_build_rootnode(doc, "iceresponse");
xmlNewTextChild(node, NULL, XMLSTR("message"), XMLSTR("Config reload queued"));
xmlNewTextChild(node, NULL, XMLSTR("return"), XMLSTR("1"));
xmlDocSetRootElement(doc, node);
Expand Down Expand Up @@ -1207,7 +1218,7 @@ static void command_updatemetadata(client_t *client,
xmlNodePtr node, srcnode;

doc = xmlNewDoc(XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL);
node = admin_build_rootnode(doc, "icestats");
srcnode = xmlNewChild(node, NULL, XMLSTR("source"), NULL);
xmlSetProp(srcnode, XMLSTR("mount"), XMLSTR(source->mount));
xmlDocSetRootElement(doc, node);
Expand Down

0 comments on commit bfcac5d

Please sign in to comment.