Commit 4a0c399b authored by Philipp Schafft's avatar Philipp Schafft 🦁

Added 'lagcay' mode stats.xml.

Add '?omode=legacy' to any URI or <resource ... omode="legacy" />.
Please test.
closes #2097
parent dc016bc0
......@@ -657,7 +657,7 @@ static void command_move_clients(client_t *client, source_t *source,
xmlFreeDoc(doc);
}
static inline xmlNodePtr __add_listener(client_t *client, xmlNodePtr parent, time_t now) {
static inline xmlNodePtr __add_listener(client_t *client, xmlNodePtr parent, time_t now, operation_mode mode) {
const char *tmp;
xmlNodePtr node;
char buf[22];
......@@ -675,13 +675,13 @@ static inline xmlNodePtr __add_listener(client_t *client, xmlNodePtr parent, tim
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf)-1, "%lu", client->con->id);
xmlSetProp(node, XMLSTR("id"), XMLSTR(buf));
xmlNewChild(node, NULL, XMLSTR("ID"), XMLSTR(buf));
xmlNewChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "ID" : "id"), XMLSTR(buf));
xmlNewChild(node, NULL, XMLSTR("IP"), XMLSTR(client->con->ip));
xmlNewChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "IP" : "ip"), XMLSTR(client->con->ip));
tmp = httpp_getvar(client->parser, "user-agent");
if (tmp)
xmlNewChild(node, NULL, XMLSTR("UserAgent"), XMLSTR(tmp));
xmlNewChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "UserAgent" : "useragent"), XMLSTR(tmp));
tmp = httpp_getvar(client->parser, "referer");
if (tmp)
......@@ -689,7 +689,7 @@ static inline xmlNodePtr __add_listener(client_t *client, xmlNodePtr parent, tim
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf), "%lu", (unsigned long)(now - client->con->con_time));
xmlNewChild(node, NULL, XMLSTR("Connected"), XMLSTR(buf));
xmlNewChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "Connected" : "connected"), XMLSTR(buf));
if (client->username)
xmlNewChild(node, NULL, XMLSTR("username"), XMLSTR(client->username));
......@@ -700,14 +700,14 @@ static inline xmlNodePtr __add_listener(client_t *client, xmlNodePtr parent, tim
return node;
}
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent) {
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent, operation_mode mode) {
time_t now = time(NULL);
avl_node *client_node;
avl_tree_rlock(source->client_tree);
client_node = avl_get_first(source->client_tree);
while(client_node) {
__add_listener((client_t *)client_node->key, parent, now);
__add_listener((client_t *)client_node->key, parent, now, mode);
client_node = avl_get_next(client_node);
}
avl_tree_unlock(source->client_tree);
......@@ -730,7 +730,7 @@ static void command_show_listeners(client_t *client, source_t *source,
snprintf (buf, sizeof(buf), "%lu", source->listeners);
xmlNewChild(srcnode, NULL, XMLSTR("Listeners"), XMLSTR(buf));
admin_add_listeners_to_mount(source, srcnode);
admin_add_listeners_to_mount(source, srcnode, client->mode);
admin_send_response(doc, client, response,
LISTCLIENTS_TRANSFORMED_REQUEST);
......@@ -1078,7 +1078,7 @@ static void command_stats(client_t *client, const char *mount, int response) {
ICECAST_LOG_DEBUG("Stats request, sending xml stats");
doc = stats_get_xml(1, mount);
doc = stats_get_xml(1, mount, client->mode);
admin_send_response(doc, client, response, STATS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);
return;
......
......@@ -39,7 +39,7 @@ void admin_handle_request(client_t *client, const char *uri);
void admin_send_response(xmlDocPtr doc, client_t *client,
int response, const char *xslt_template);
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent);
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent, operation_mode mode);
int admin_get_command(const char *command);
int admin_get_command_type(int command);
......
......@@ -108,6 +108,22 @@ static void _parse_events(event_registration_t **events, xmlNodePtr node);
static void merge_mounts(mount_proxy * dst, mount_proxy * src);
static inline void _merge_mounts_all(ice_config_t *c);
operation_mode config_str_to_omode(const char *str) {
if (!str || !*str)
return OMODE_DEFAULT;
if (strcasecmp(str, "default") == 0) {
return OMODE_DEFAULT;
} else if (strcasecmp(str, "normal") == 0) {
return OMODE_NORMAL;
} else if (strcasecmp(str, "legacy-compat") == 0 || strcasecmp(str, "legacy") == 0) {
return OMODE_LEGACY;
} else {
ICECAST_LOG_ERROR("Unknown operation mode \"%s\", falling back to DEFAULT.", str);
return OMODE_DEFAULT;
}
}
static void create_locks(void) {
thread_mutex_create(&_locks.relay_lock);
thread_rwlock_create(&_locks.config_lock);
......@@ -1696,6 +1712,13 @@ static void _parse_paths(xmlDocPtr doc, xmlNodePtr node,
alias->port = -1;
alias->bind_address = (char *)xmlGetProp(node, XMLSTR("bind-address"));
alias->vhost = (char *)xmlGetProp(node, XMLSTR("vhost"));
temp = (char *)xmlGetProp(node, XMLSTR("omode"));
if (temp) {
alias->omode = config_str_to_omode(temp);
xmlFree(temp);
} else {
alias->omode = OMODE_DEFAULT;
}
current = configuration->aliases;
last = NULL;
while (current) {
......
......@@ -32,6 +32,12 @@ struct _mount_proxy;
#define XMLSTR(str) ((xmlChar *)(str))
typedef enum _operation_mode {
OMODE_DEFAULT = 0,
OMODE_NORMAL,
OMODE_LEGACY
} operation_mode;
typedef enum _http_header_type {
/* static: headers are passed as is to the client. */
HTTP_HEADER_TYPE_STATIC
......@@ -125,6 +131,7 @@ typedef struct _aliases {
int port;
char *bind_address;
char *vhost;
operation_mode omode;
struct _aliases *next;
} aliases;
......@@ -220,6 +227,8 @@ typedef struct {
void config_initialize(void);
void config_shutdown(void);
operation_mode config_str_to_omode(const char *str);
void config_reread_config(void);
int config_parse_file(const char *filename, ice_config_t *configuration);
int config_initial_parse_file(const char *filename);
......
......@@ -22,6 +22,7 @@
#include "connection.h"
#include "refbuf.h"
#include "acl.h"
#include "cfgfile.h"
#include "common/httpp/httpp.h"
typedef enum _protocol_tag {
......@@ -31,6 +32,9 @@ typedef enum _protocol_tag {
typedef struct _client_tag
{
/* mode of operation for this client */
operation_mode mode;
/* the client's connection */
connection_t *con;
/* the client's http headers */
......
......@@ -1270,6 +1270,8 @@ static int _handle_aliases(client_t *client, char **uri) {
(alias->bind_address == NULL || (serverhost != NULL && strcmp(alias->bind_address, serverhost) == 0)) &&
(alias->vhost == NULL || (vhost != NULL && strcmp(alias->vhost, vhost) == 0)) ) {
new_uri = strdup(alias->destination);
if (alias->omode != OMODE_DEFAULT)
client->mode = alias->omode;
ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri);
break;
}
......@@ -1508,6 +1510,8 @@ static void _handle_connection(void)
continue;
}
client->mode = config_str_to_omode(httpp_get_query_param(client->parser, "omode"));
if (_handle_aliases(client, &uri) != 0) {
client_destroy (client);
continue;
......
......@@ -495,7 +495,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
char *eol = strrchr (reference, '.');
if (eol)
*eol = '\0';
doc = stats_get_xml (0, reference);
doc = stats_get_xml (0, reference, httpclient->mode);
free (reference);
admin_send_response (doc, httpclient, TRANSFORMED, xslt_playlist_requested);
xmlFreeDoc(doc);
......
......@@ -978,7 +978,7 @@ void stats_transform_xslt(client_t *client, const char *uri)
char *xslpath = util_get_path_from_normalised_uri(uri);
const char *mount = httpp_get_query_param(client->parser, "mount");
doc = stats_get_xml(0, mount);
doc = stats_get_xml(0, mount, client->mode);
xslt_transform(doc, xslpath, client);
......@@ -1009,7 +1009,7 @@ static void __add_metadata(xmlNodePtr node, const char *tag) {
free(name);
}
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount)
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount, operation_mode mode)
{
xmlDocPtr doc;
xmlNodePtr node;
......@@ -1029,7 +1029,7 @@ xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount)
source = source_find_mount_raw(show_mount);
for (i = 0; i < source->format->vc.comments; i++)
__add_metadata(metadata, source->format->vc.user_comments[i]);
admin_add_listeners_to_mount(source, node);
admin_add_listeners_to_mount(source, node, mode);
avl_tree_unlock(global.source_tree);
}
......
......@@ -96,7 +96,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);
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount);
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount, operation_mode mode);
char *stats_get_value(const char *source, const char *name);
#endif /* __STATS_H__ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment