diff --git a/admin/xspf.xsl b/admin/xspf.xsl
new file mode 100644
index 00000000..e988d2e5
--- /dev/null
+++ b/admin/xspf.xsl
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/admin.c b/src/admin.c
index 9f76b42f..cfd38a36 100644
--- a/src/admin.c
+++ b/src/admin.c
@@ -33,6 +33,7 @@
#include "compat.h"
#include "xslt.h"
#include "fserve.h"
+#include "admin.h"
#include "format.h"
@@ -109,10 +110,6 @@
#define DEFAULT_TRANSFORMED_REQUEST ""
#define BUILDM3U_RAW_REQUEST "buildm3u"
-#define RAW 1
-#define TRANSFORMED 2
-#define PLAINTEXT 3
-
int admin_get_command(char *command)
{
if(!strcmp(command, FALLBACK_RAW_REQUEST))
@@ -195,8 +192,6 @@ static void command_updatemetadata(client_t *client, source_t *source,
static void admin_handle_mount_request(client_t *client, source_t *source,
int command);
static void admin_handle_general_request(client_t *client, int command);
-static void admin_send_response(xmlDocPtr doc, client_t *client,
- int response, char *xslt_template);
/* 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
@@ -267,8 +262,8 @@ xmlDocPtr admin_build_sourcelist (const char *mount)
return(doc);
}
-static void admin_send_response(xmlDocPtr doc, client_t *client,
- int response, char *xslt_template)
+void admin_send_response (xmlDocPtr doc, client_t *client,
+ int response, const char *xslt_template)
{
if (response == RAW)
{
@@ -958,7 +953,7 @@ static void command_stats(client_t *client, int response) {
DEBUG0("Stats request, sending xml stats");
- stats_get_xml(&doc, 1);
+ stats_get_xml(&doc, 1, NULL);
admin_send_response(doc, client, response, STATS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
return;
diff --git a/src/admin.h b/src/admin.h
index e54bc722..a7504e1d 100644
--- a/src/admin.h
+++ b/src/admin.h
@@ -13,9 +13,18 @@
#ifndef __ADMIN_H__
#define __ADMIN_H__
+#include
+#include
+
#include "refbuf.h"
#include "client.h"
+#define RAW 1
+#define TRANSFORMED 2
+#define PLAINTEXT 3
+
void admin_handle_request(client_t *client, char *uri);
+void admin_send_response(xmlDocPtr doc, client_t *client,
+ int response, const char *xslt_template);
#endif /* __ADMIN_H__ */
diff --git a/src/fserve.c b/src/fserve.c
index 80cb6010..ba9ad34a 100644
--- a/src/fserve.c
+++ b/src/fserve.c
@@ -50,6 +50,7 @@
#include "logging.h"
#include "cfgfile.h"
#include "util.h"
+#include "admin.h"
#include "compat.h"
#include "fserve.h"
@@ -376,6 +377,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
int ret = 0;
char *fullpath;
int m3u_requested = 0, m3u_file_available = 1;
+ int xspf_requested = 0, xspf_file_available = 1;
ice_config_t *config;
FILE *file;
@@ -385,11 +387,14 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (strcmp (util_get_extension (fullpath), "m3u") == 0)
m3u_requested = 1;
+ if (strcmp (util_get_extension (fullpath), "xspf") == 0)
+ xspf_requested = 1;
+
/* check for the actual file */
if (stat (fullpath, &file_buf) != 0)
{
/* the m3u can be generated, but send an m3u file if available */
- if (m3u_requested == 0)
+ if (m3u_requested == 0 && xspf_requested == 0)
{
WARN2 ("req for file \"%s\" %s", fullpath, strerror (errno));
client_send_404 (httpclient, "The file you requested could not be found");
@@ -397,6 +402,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
return -1;
}
m3u_file_available = 0;
+ xspf_file_available = 0;
}
httpclient->refbuf->len = PER_CLIENT_REFBUF_SIZE;
@@ -443,6 +449,19 @@ int fserve_client_create (client_t *httpclient, const char *path)
free (fullpath);
return 0;
}
+ if (xspf_requested && xspf_file_available == 0)
+ {
+ xmlDocPtr doc;
+ char *reference = strdup (path);
+ char *eol = strrchr (reference, '.');
+ if (eol)
+ *eol = '\0';
+ stats_get_xml (&doc, 0, reference);
+ free (reference);
+ admin_send_response (doc, httpclient, TRANSFORMED, "xspf.xsl");
+ xmlFreeDoc(doc);
+ return 0;
+ }
/* on demand file serving check */
config = config_get_config();
diff --git a/src/stats.c b/src/stats.c
index 8a1d73b7..009f32d4 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -878,7 +878,7 @@ void stats_transform_xslt(client_t *client, const char *uri)
xmlDocPtr doc;
char *xslpath = util_get_path_from_normalised_uri (uri);
- stats_get_xml(&doc, 0);
+ stats_get_xml(&doc, 0, NULL);
xslt_transform(doc, xslpath, client);
@@ -886,7 +886,7 @@ void stats_transform_xslt(client_t *client, const char *uri)
free (xslpath);
}
-void stats_get_xml(xmlDocPtr *doc, int show_hidden)
+void stats_get_xml(xmlDocPtr *doc, int show_hidden, const char *show_mount)
{
stats_event_t *event;
event_queue_t queue;
@@ -906,16 +906,24 @@ void stats_get_xml(xmlDocPtr *doc, int show_hidden)
{
if (event->hidden <= show_hidden)
{
- xmlChar *name, *value;
- name = xmlEncodeEntitiesReentrant (*doc, event->name);
- value = xmlEncodeEntitiesReentrant (*doc, event->value);
- srcnode = node;
- if (event->source) {
- srcnode = _find_xml_node(event->source, &src_nodes, node);
- }
- xmlNewChild(srcnode, NULL, name, value);
- xmlFree (value);
- xmlFree (name);
+ do
+ {
+ xmlChar *name, *value;
+ name = xmlEncodeEntitiesReentrant (*doc, event->name);
+ value = xmlEncodeEntitiesReentrant (*doc, event->value);
+ srcnode = node;
+ if (event->source)
+ {
+ if (show_mount && strcmp (event->source, show_mount) != 0)
+ break;
+ srcnode = _find_xml_node(event->source, &src_nodes, node);
+ }
+ else
+ srcnode = node;
+ xmlNewChild(srcnode, NULL, name, value);
+ xmlFree (value);
+ xmlFree (name);
+ } while (0);
}
_free_event(event);
diff --git a/src/stats.h b/src/stats.h
index d2484e06..1432eb03 100644
--- a/src/stats.h
+++ b/src/stats.h
@@ -90,7 +90,7 @@ void stats_callback (client_t *client, void *notused);
void stats_transform_xslt(client_t *client, const char *uri);
void stats_sendxml(client_t *client);
-void stats_get_xml(xmlDocPtr *doc, int show_hidden);
+void stats_get_xml(xmlDocPtr *doc, int show_hidden, const char *show_mount);
char *stats_get_value(char *source, char *name);
#endif /* __STATS_H__ */