mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-09-29 04:25:55 -04:00
various type cleanups. Add mechanism for enabling/disabling relays via
admin URL svn path=/icecast/branches/kh/icecast/; revision=9317
This commit is contained in:
parent
f158db640d
commit
5f782591f6
60
src/admin.c
60
src/admin.c
@ -67,10 +67,12 @@
|
||||
#define COMMAND_RAW_LISTSTREAM 103
|
||||
#define COMMAND_PLAINTEXT_LISTSTREAM 104
|
||||
#define COMMAND_RAW_ADMIN_FUNCTION 105
|
||||
#define COMMAND_RAW_UPDATE_RELAY 106
|
||||
#define COMMAND_TRANSFORMED_LIST_MOUNTS 201
|
||||
#define COMMAND_TRANSFORMED_STATS 202
|
||||
#define COMMAND_TRANSFORMED_LISTSTREAM 203
|
||||
#define COMMAND_TRANSFORMED_ADMIN_FUNCTION 204
|
||||
#define COMMAND_TRANSFORMED_UPDATE_RELAY 205
|
||||
|
||||
/* Client management commands */
|
||||
#define COMMAND_RAW_KILL_CLIENT 301
|
||||
@ -106,6 +108,8 @@
|
||||
#define MANAGEAUTH_TRANSFORMED_REQUEST "manageauth.xsl"
|
||||
#define UPDATEMETADATA_RAW_REQUEST "updatemetadata"
|
||||
#define UPDATEMETADATA_TRANSFORMED_REQUEST "updatemetadata.xsl"
|
||||
#define UPDATE_RELAY_RAW_REQUEST "updaterelay"
|
||||
#define UPDATE_RELAY_TRANSFORMED_REQUEST "updaterelay.xsl"
|
||||
#define ADM_FUNCTION_RAW_REQUEST "function"
|
||||
#define ADM_FUNCTION_TRANSFORMED_REQUEST "function.xsl"
|
||||
#define DEFAULT_RAW_REQUEST ""
|
||||
@ -168,6 +172,10 @@ int admin_get_command(char *command)
|
||||
return COMMAND_TRANSFORMED_UPDATEMETADATA;
|
||||
else if(!strcmp(command, BUILDM3U_RAW_REQUEST))
|
||||
return COMMAND_BUILDM3U;
|
||||
else if(!strcmp(command, UPDATE_RELAY_RAW_REQUEST))
|
||||
return COMMAND_RAW_UPDATE_RELAY;
|
||||
else if(!strcmp(command, UPDATE_RELAY_TRANSFORMED_REQUEST))
|
||||
return COMMAND_TRANSFORMED_UPDATE_RELAY;
|
||||
else if(!strcmp(command, ADM_FUNCTION_RAW_REQUEST))
|
||||
return COMMAND_RAW_ADMIN_FUNCTION;
|
||||
else if(!strcmp(command, ADM_FUNCTION_TRANSFORMED_REQUEST))
|
||||
@ -200,6 +208,7 @@ static void command_kill_source(client_t *client, source_t *source,
|
||||
static void command_updatemetadata(client_t *client, source_t *source,
|
||||
int response);
|
||||
static void command_admin_function (client_t *client, int response);
|
||||
static void command_update_relay (client_t *client, int response);
|
||||
|
||||
static void admin_handle_mount_request(client_t *client, source_t *source,
|
||||
int command);
|
||||
@ -456,6 +465,9 @@ static void admin_handle_general_request(client_t *client, int command)
|
||||
case COMMAND_RAW_LISTSTREAM:
|
||||
command_list_mounts(client, RAW);
|
||||
break;
|
||||
case COMMAND_RAW_UPDATE_RELAY:
|
||||
command_update_relay (client, RAW);
|
||||
break;
|
||||
case COMMAND_RAW_ADMIN_FUNCTION:
|
||||
command_admin_function(client, RAW);
|
||||
break;
|
||||
@ -474,6 +486,9 @@ static void admin_handle_general_request(client_t *client, int command)
|
||||
case COMMAND_TRANSFORMED_MOVE_CLIENTS:
|
||||
command_list_mounts(client, TRANSFORMED);
|
||||
break;
|
||||
case COMMAND_TRANSFORMED_UPDATE_RELAY:
|
||||
command_update_relay (client, TRANSFORMED);
|
||||
break;
|
||||
case COMMAND_TRANSFORMED_ADMIN_FUNCTION:
|
||||
command_admin_function(client, TRANSFORMED);
|
||||
break;
|
||||
@ -694,6 +709,51 @@ static void command_admin_function (client_t *client, int response)
|
||||
}
|
||||
|
||||
|
||||
static void command_update_relay (client_t *client, int response)
|
||||
{
|
||||
char *relay_mount, *enable;
|
||||
const char *msg;
|
||||
relay_server *relay;
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr node;
|
||||
|
||||
COMMAND_REQUIRE (client, "relay", relay_mount);
|
||||
COMMAND_REQUIRE (client, "enable", enable);
|
||||
|
||||
if (relay_mount == NULL)
|
||||
return;
|
||||
|
||||
thread_mutex_lock (&(config_locks()->relay_lock));
|
||||
|
||||
relay = slave_find_relay (global.relays, relay_mount);
|
||||
if (relay == NULL)
|
||||
relay = slave_find_relay (global.master_relays, relay_mount);
|
||||
|
||||
msg = "no such relay";
|
||||
if (relay)
|
||||
{
|
||||
relay->enable = atoi (enable);
|
||||
msg = "relay has been changed";
|
||||
if (relay->enable == 0)
|
||||
{
|
||||
if (relay->source && relay->source->running == 0)
|
||||
relay->source->on_demand = 0;
|
||||
}
|
||||
slave_rebuild_mounts();
|
||||
}
|
||||
thread_mutex_unlock (&(config_locks()->relay_lock));
|
||||
|
||||
doc = xmlNewDoc("1.0");
|
||||
node = xmlNewDocNode(doc, NULL, "iceresponse", NULL);
|
||||
xmlDocSetRootElement(doc, node);
|
||||
xmlNewChild(node, NULL, "message", msg);
|
||||
xmlNewChild(node, NULL, "return", "1");
|
||||
admin_send_response(doc, client, response, ADMIN_XSL_RESPONSE);
|
||||
xmlFreeDoc(doc);
|
||||
client_destroy(client);
|
||||
}
|
||||
|
||||
|
||||
static void command_show_listeners(client_t *client, source_t *source,
|
||||
int response)
|
||||
{
|
||||
|
@ -218,8 +218,8 @@ int add_client_to_source (source_t *source, client_t *client)
|
||||
unsigned int total;
|
||||
thread_mutex_lock (&source->lock);
|
||||
total = source->new_listeners + source->listeners;
|
||||
DEBUG2 ("max on %s is %d", source->mount, source->max_listeners);
|
||||
DEBUG2 ("pending %d, current %d", source->new_listeners, source->listeners);
|
||||
DEBUG2 ("max on %s is %lu", source->mount, source->max_listeners);
|
||||
DEBUG2 ("pending %d, current %lu", source->new_listeners, source->listeners);
|
||||
if (source->max_listeners == -1)
|
||||
break;
|
||||
if (client->is_slave)
|
||||
|
@ -70,7 +70,7 @@ typedef struct auth_tag
|
||||
int allow_duplicate_users;
|
||||
|
||||
void *state;
|
||||
void *type;
|
||||
char *type;
|
||||
} auth_t;
|
||||
|
||||
void add_client (const char *mount, client_t *client);
|
||||
|
@ -695,6 +695,7 @@ static void _parse_relay(xmlDocPtr doc, xmlNodePtr node,
|
||||
|
||||
relay->next = NULL;
|
||||
relay->mp3metadata = 1;
|
||||
relay->enable = 1;
|
||||
relay->on_demand = configuration->on_demand;
|
||||
|
||||
do {
|
||||
@ -736,6 +737,11 @@ static void _parse_relay(xmlDocPtr doc, xmlNodePtr node,
|
||||
relay->on_demand = atoi(tmp);
|
||||
if (tmp) xmlFree(tmp);
|
||||
}
|
||||
else if (strcmp(node->name, "enable") == 0) {
|
||||
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
|
||||
relay->enable = atoi(tmp);
|
||||
if (tmp) xmlFree(tmp);
|
||||
}
|
||||
} while ((node = node->next));
|
||||
if (relay->localmount == NULL)
|
||||
relay->localmount = xmlStrdup (relay->mount);
|
||||
|
@ -506,10 +506,9 @@ int connection_complete_source (source_t *source, connection_t *con, http_parser
|
||||
|
||||
source->running = 1;
|
||||
mountinfo = config_find_mount (config, source->mount);
|
||||
if (mountinfo)
|
||||
source_recheck_mounts ();
|
||||
else
|
||||
if (mountinfo == NULL)
|
||||
source_update_settings (config, source, mountinfo);
|
||||
source_recheck_mounts ();
|
||||
config_release_config();
|
||||
|
||||
source->shutdown_rwlock = &_source_shutdown_rwlock;
|
||||
|
@ -452,7 +452,7 @@ int fserve_client_create(client_t *httpclient, const char *path)
|
||||
if (S_ISREG (file_buf.st_mode) == 0)
|
||||
{
|
||||
client_send_404 (httpclient, "The file you requested could not be found");
|
||||
INFO1 ("found requested file but there is no handler for it", fullpath);
|
||||
WARN1 ("found requested file but there is no handler for it: %s", fullpath);
|
||||
free (fullpath);
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
typedef struct _refbuf_tag
|
||||
{
|
||||
char *data;
|
||||
unsigned int len;
|
||||
unsigned long len;
|
||||
int sync_point;
|
||||
struct _refbuf_tag *associated;
|
||||
struct _refbuf_tag *next;
|
||||
|
51
src/slave.c
51
src/slave.c
@ -104,6 +104,7 @@ relay_server *relay_copy (relay_server *r)
|
||||
copy->port = r->port;
|
||||
copy->mp3metadata = r->mp3metadata;
|
||||
copy->on_demand = r->on_demand;
|
||||
copy->enable = r->enable;
|
||||
copy->source = r->source;
|
||||
r->source = NULL;
|
||||
}
|
||||
@ -371,21 +372,7 @@ static void check_relay_stream (relay_server *relay)
|
||||
/* new relay, reserve the name */
|
||||
relay->source = source_reserve (relay->localmount);
|
||||
if (relay->source)
|
||||
{
|
||||
DEBUG1("Adding relay source at mountpoint \"%s\"", relay->localmount);
|
||||
relay->source->on_demand = relay->on_demand;
|
||||
if (relay->on_demand)
|
||||
{
|
||||
ice_config_t *config = config_get_config ();
|
||||
mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
|
||||
if (mountinfo)
|
||||
slave_rebuild_mounts();
|
||||
else
|
||||
source_update_settings (config, relay->source, mountinfo);
|
||||
config_release_config ();
|
||||
stats_event (relay->localmount, "listeners", "0");
|
||||
}
|
||||
}
|
||||
else
|
||||
WARN1 ("new relay but source \"%s\" already exists", relay->localmount);
|
||||
}
|
||||
@ -394,8 +381,23 @@ static void check_relay_stream (relay_server *relay)
|
||||
source_t *source = relay->source;
|
||||
if (relay->source == NULL || relay->running)
|
||||
break;
|
||||
if (relay->enable == 0)
|
||||
{
|
||||
stats_event (relay->localmount, NULL, NULL);
|
||||
break;
|
||||
}
|
||||
if (relay->on_demand)
|
||||
{
|
||||
ice_config_t *config = config_get_config ();
|
||||
mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
|
||||
|
||||
if (mountinfo == NULL)
|
||||
source_update_settings (config, relay->source, mountinfo);
|
||||
config_release_config ();
|
||||
slave_rebuild_mounts();
|
||||
stats_event (relay->localmount, "listeners", "0");
|
||||
relay->source->on_demand = relay->on_demand;
|
||||
|
||||
if (source->fallback_mount && source->fallback_override)
|
||||
{
|
||||
source_t *fallback;
|
||||
@ -404,7 +406,7 @@ static void check_relay_stream (relay_server *relay)
|
||||
fallback = source_find_mount (source->fallback_mount);
|
||||
if (fallback && fallback->running && fallback->listeners)
|
||||
{
|
||||
DEBUG2 ("fallback running %d with %d listeners", fallback->running, fallback->listeners);
|
||||
DEBUG2 ("fallback running %d with %lu listeners", fallback->running, fallback->listeners);
|
||||
source->on_demand_req = 1;
|
||||
}
|
||||
avl_tree_unlock (global.source_tree);
|
||||
@ -426,8 +428,13 @@ static void check_relay_stream (relay_server *relay)
|
||||
relay->thread = NULL;
|
||||
relay->cleanup = 0;
|
||||
relay->running = 0;
|
||||
relay->source->on_demand = relay->on_demand;
|
||||
|
||||
if (relay->enable == 0)
|
||||
{
|
||||
stats_event (relay->localmount, NULL, NULL);
|
||||
slave_rebuild_mounts();
|
||||
return;
|
||||
}
|
||||
if (relay->on_demand)
|
||||
{
|
||||
ice_config_t *config = config_get_config ();
|
||||
@ -746,6 +753,18 @@ static void *_slave_thread(void *arg)
|
||||
}
|
||||
|
||||
|
||||
relay_server *slave_find_relay (relay_server *relays, const char *mount)
|
||||
{
|
||||
while (relays)
|
||||
{
|
||||
if (strcmp (relays->localmount, mount) == 0)
|
||||
break;
|
||||
relays = relays->next;
|
||||
}
|
||||
return relays;
|
||||
}
|
||||
|
||||
|
||||
/* remove this slave clients entry in the slave host list */
|
||||
void slave_host_remove (client_t *client)
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ typedef struct _relay_server {
|
||||
int on_demand;
|
||||
int running;
|
||||
int cleanup;
|
||||
int enable;
|
||||
thread_type *thread;
|
||||
struct _relay_server *next;
|
||||
} relay_server;
|
||||
@ -46,6 +47,7 @@ void slave_shutdown(void);
|
||||
void slave_recheck_mounts (void);
|
||||
void slave_rebuild_mounts (void);
|
||||
void slave_rescan (void);
|
||||
relay_server *slave_find_relay (relay_server *relays, const char *mount);
|
||||
int slave_redirect (const char *mountpoint, struct _client_tag *client);
|
||||
void slave_host_add (struct _client_tag *client, const char *header);
|
||||
void slave_host_remove (struct _client_tag *client);
|
||||
|
20
src/source.c
20
src/source.c
@ -261,6 +261,7 @@ void source_clear_source (source_t *source)
|
||||
source->intro_file = NULL;
|
||||
}
|
||||
|
||||
source->on_demand = 0;
|
||||
source->on_demand_req = 0;
|
||||
}
|
||||
|
||||
@ -377,7 +378,7 @@ void source_move_clients (source_t *source, source_t *dest)
|
||||
count++;
|
||||
}
|
||||
if (count != source->listeners)
|
||||
WARN2 ("count %u, listeners %u", count, source->listeners);
|
||||
WARN2 ("count %u, listeners %lu", count, source->listeners);
|
||||
count = 0;
|
||||
while (source->pending_clients)
|
||||
{
|
||||
@ -562,10 +563,9 @@ static void get_next_buffer (source_t *source)
|
||||
/* general send routine per listener. The deletion_expected tells us whether
|
||||
* the last in the queue is about to disappear, so if this client is still
|
||||
* referring to it after writing then drop the client as it's fallen too far
|
||||
* behind.
|
||||
* behind
|
||||
*
|
||||
* return 1 for client should be specially handled, either removed or placed
|
||||
* elsewhere
|
||||
* return 1 for fast client, limiter kicked in
|
||||
* 0 for normal case.
|
||||
*/
|
||||
static int send_to_listener (source_t *source, client_t *client, int deletion_expected)
|
||||
@ -676,8 +676,8 @@ static void process_listeners (source_t *source, int fast_clients_only, int dele
|
||||
/* has the listener count changed */
|
||||
if (source->listeners != listeners)
|
||||
{
|
||||
INFO2("listener count on %s now %d", source->mount, source->listeners);
|
||||
stats_event_args (source->mount, "listeners", "%d", source->listeners);
|
||||
INFO2("listener count on %s now %lu", source->mount, source->listeners);
|
||||
stats_event_args (source->mount, "listeners", "%lu", source->listeners);
|
||||
if (source->listeners == 0)
|
||||
rate_add (source->format->out_bitrate, 0, 0);
|
||||
if (source->listeners == 0 && source->on_demand)
|
||||
@ -1237,7 +1237,7 @@ void source_update_settings (ice_config_t *config, source_t *source, mount_proxy
|
||||
stats_event (source->mount, "on_demand", NULL);
|
||||
|
||||
DEBUG1 ("public set to %d", source->yp_public);
|
||||
DEBUG1 ("max listeners to %d", source->max_listeners);
|
||||
DEBUG1 ("max listeners to %ld", source->max_listeners);
|
||||
DEBUG1 ("queue size to %u", source->queue_size_limit);
|
||||
DEBUG1 ("burst size to %u", source->burst_size);
|
||||
DEBUG1 ("source timeout to %u", source->timeout);
|
||||
@ -1269,10 +1269,12 @@ void *source_client_thread (void *arg)
|
||||
stats_event_inc(NULL, "source_client_connections");
|
||||
stats_event (source->mount, "listeners", "0");
|
||||
stats_event (source->mount, "source_ip", source->client->con->ip);
|
||||
source_main (source);
|
||||
source_free_source (source);
|
||||
|
||||
source_main (source);
|
||||
|
||||
source_free_source (source);
|
||||
source_recheck_mounts ();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user