1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-09-22 04:15:54 -04:00

first part of patch to allow kh like admin stats with listener tags inside

svn path=/icecast/trunk/icecast/; revision=19343
This commit is contained in:
Philipp Schafft 2014-11-21 15:37:50 +00:00
parent 1fe898adb5
commit 237eb4f770
3 changed files with 67 additions and 31 deletions

View File

@ -704,16 +704,65 @@ 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) {
const char *tmp;
xmlNodePtr node;
char buf[22];
#if 0
xmlSetProp (node, XMLSTR("id"), XMLSTR(buf));
xmlNewChild (node, NULL, XMLSTR("lag"), XMLSTR(buf));
#endif
node = xmlNewChild(parent, NULL, XMLSTR("listener"), NULL);
if (!node)
return NULL;
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf)-1, "%lu", client->con->id);
xmlNewChild(node, NULL, XMLSTR("ID"), XMLSTR(buf));
xmlNewChild(node, NULL, XMLSTR("IP"), XMLSTR(client->con->ip));
tmp = httpp_getvar(client->parser, "user-agent");
if (tmp)
xmlNewChild(node, NULL, XMLSTR("UserAgent"), XMLSTR(tmp));
tmp = httpp_getvar(client->parser, "referer");
if (tmp)
xmlNewChild(node, NULL, XMLSTR("Referer"), XMLSTR(tmp));
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf), "%lu", (unsigned long)(now - client->con->con_time));
xmlNewChild(node, NULL, XMLSTR("Connected"), XMLSTR(buf));
if (client->username)
xmlNewChild(node, NULL, XMLSTR("username"), XMLSTR(client->username));
return node;
}
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent) {
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);
client_node = avl_get_next(client_node);
}
avl_tree_unlock(source->client_tree);
}
static void command_show_listeners(client_t *client, source_t *source,
int response)
{
xmlDocPtr doc;
xmlNodePtr node, srcnode, listenernode;
avl_node *client_node;
client_t *current;
xmlNodePtr node, srcnode;
char buf[22];
const char *userAgent = NULL;
time_t now = time(NULL);
doc = xmlNewDoc (XMLSTR("1.0"));
node = xmlNewDocNode(doc, NULL, XMLSTR("icestats"), NULL);
@ -725,33 +774,8 @@ 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));
avl_tree_rlock(source->client_tree);
admin_add_listeners_to_mount(source, srcnode);
client_node = avl_get_first(source->client_tree);
while(client_node) {
current = (client_t *)client_node->key;
listenernode = xmlNewChild(srcnode, NULL, XMLSTR("listener"), NULL);
xmlNewChild(listenernode, NULL, XMLSTR("IP"), XMLSTR(current->con->ip));
userAgent = httpp_getvar(current->parser, "user-agent");
if (userAgent) {
xmlNewChild(listenernode, NULL, XMLSTR("UserAgent"), XMLSTR(userAgent));
}
else {
xmlNewChild(listenernode, NULL, XMLSTR("UserAgent"), XMLSTR("Unknown"));
}
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf), "%lu", (unsigned long)(now - current->con->con_time));
xmlNewChild(listenernode, NULL, XMLSTR("Connected"), XMLSTR(buf));
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf)-1, "%lu", current->con->id);
xmlNewChild(listenernode, NULL, XMLSTR("ID"), XMLSTR(buf));
if (current->username) {
xmlNewChild(listenernode, NULL, XMLSTR("username"), XMLSTR(current->username));
}
client_node = avl_get_next(client_node);
}
avl_tree_unlock(source->client_tree);
admin_send_response(doc, client, response,
LISTCLIENTS_TRANSFORMED_REQUEST);
xmlFreeDoc(doc);

View File

@ -18,6 +18,7 @@
#include "refbuf.h"
#include "client.h"
#include "source.h"
#define RAW 1
#define TRANSFORMED 2
@ -27,4 +28,6 @@ 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);
#endif /* __ADMIN_H__ */

View File

@ -35,6 +35,7 @@
#include "global.h"
#include "refbuf.h"
#include "client.h"
#include "admin.h"
#include "stats.h"
#include "xslt.h"
#include "util.h"
@ -988,6 +989,7 @@ xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount)
{
xmlDocPtr doc;
xmlNodePtr node;
source_t * source;
doc = xmlNewDoc (XMLSTR("1.0"));
node = xmlNewDocNode (doc, NULL, XMLSTR("icestats"), NULL);
@ -995,6 +997,13 @@ xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount)
node = _dump_stats_to_doc (node, show_mount, show_hidden);
if (show_mount && node) {
avl_tree_rlock(global.source_tree);
source = source_find_mount_raw(show_mount);
admin_add_listeners_to_mount(source, node);
avl_tree_unlock(global.source_tree);
}
return doc;
}