Commit 19cb11cc authored by Karl Heyes's avatar Karl Heyes

merge in a few fixes and cleanups I've accumulated in my branch.

svn path=/icecast/trunk/icecast/; revision=9152
parent f502efd2
......@@ -978,7 +978,7 @@ static void command_list_mounts(client_t *client, int response)
{
source_t *source = (source_t *)node->key;
node = avl_get_next(node);
if (source->hidden)
if (source->hidden || source->running == 0)
continue;
remaining -= ret;
buf += ret;
......
......@@ -482,6 +482,7 @@ int connection_complete_source (source_t *source)
if (source->client)
client_send_404 (source->client, "internal format allocation problem");
WARN1 ("plugin format failed for \"%s\"", source->mount);
source->client = NULL;
return -1;
}
......@@ -708,7 +709,7 @@ static void _handle_source_request(connection_t *con,
* protocol: attempt to diagnose this and return an error
*/
/* TODO: Do what the above comment says */
WARN1("Source (%s) attempted to login with invalid or missing password", uri);
INFO1("Source (%s) attempted to login with invalid or missing password", uri);
client_send_401(client);
return;
}
......@@ -772,7 +773,7 @@ static void _handle_get_request(connection_t *con,
struct stat statbuf;
source_t *source;
int fileserve;
char *host;
char *host = NULL;
int port;
int i;
char *serverhost = NULL;
......@@ -785,7 +786,8 @@ static void _handle_get_request(connection_t *con,
config = config_get_config();
fileserve = config->fileserve;
host = config->hostname;
if (config->hostname)
host = strdup (config->hostname);
port = config->port;
for(i = 0; i < global.server_sockets; i++) {
if(global.serversock[i] == con->serversock) {
......@@ -827,6 +829,7 @@ static void _handle_get_request(connection_t *con,
(strncmp(uri, "/admin/", 7) == 0)) {
admin_handle_request(client, uri);
if (uri != passed_uri) free (uri);
free (host);
return;
}
......@@ -851,6 +854,7 @@ static void _handle_get_request(connection_t *con,
}
free(fullpath);
if (uri != passed_uri) free (uri);
free (host);
return;
}
else if(fileserve && stat(fullpath, &statbuf) == 0 &&
......@@ -863,6 +867,7 @@ static void _handle_get_request(connection_t *con,
fserve_client_create(client, fullpath);
free(fullpath);
if (uri != passed_uri) free (uri);
free (host);
return;
}
free(fullpath);
......@@ -884,8 +889,10 @@ static void _handle_get_request(connection_t *con,
client_destroy(client);
free(sourceuri);
if (uri != passed_uri) free (uri);
free (host);
return;
}
free (host);
global_lock();
if (global.clients >= client_limit) {
......
......@@ -66,7 +66,7 @@ static void write_mp3_to_file (struct source_tag *source, refbuf_t *refbuf);
typedef struct {
int use_metadata;
unsigned int interval;
int metadata_offset;
unsigned int since_meta_block;
int in_metadata;
......@@ -105,14 +105,17 @@ int format_mp3_get_plugin (source_t *source)
memcpy (meta->data, "\0\0", 2);
meta->len = 1;
state->metadata = meta;
state->interval = ICY_METADATA_INTERVAL;
state->interval = -1;
metadata = httpp_getvar (source->parser, "icy-metaint");
if (metadata)
{
state->inline_metadata_interval = atoi (metadata);
state->offset = 0;
plugin->get_buffer = mp3_get_filter_meta;
if (state->inline_metadata_interval > 0)
{
state->offset = 0;
plugin->get_buffer = mp3_get_filter_meta;
}
}
source->format = plugin;
thread_mutex_create (&state->url_lock);
......@@ -260,15 +263,15 @@ static int send_mp3_metadata (client_t *client, refbuf_t *associated)
/* If there is a change in metadata then send it else
* send a single zero value byte in its place
*/
if (associated == client_mp3->associated)
if (associated && associated != client_mp3->associated)
{
metadata = "\0";
meta_len = 1;
metadata = associated->data + client_mp3->metadata_offset;
meta_len = associated->len - client_mp3->metadata_offset;
}
else
{
metadata = associated->data + client_mp3->metadata_offset;
meta_len = associated->len - client_mp3->metadata_offset;
metadata = "\0";
meta_len = 1;
}
ret = client_send_bytes (client, metadata, meta_len);
......@@ -297,7 +300,6 @@ static int format_mp3_write_buf_to_client (format_plugin_t *self, client_t *clie
{
int ret, written = 0;
mp3_client_data *client_mp3 = client->format_data;
mp3_state *source_mp3 = self->_state;
refbuf_t *refbuf = client->refbuf;
char *buf;
unsigned int len;
......@@ -328,9 +330,9 @@ static int format_mp3_write_buf_to_client (format_plugin_t *self, client_t *clie
written += ret;
}
/* see if we need to send the current metadata to the client */
if (client_mp3->use_metadata)
if (client_mp3->interval)
{
unsigned int remaining = source_mp3->interval -
unsigned int remaining = client_mp3->interval -
client_mp3->since_meta_block;
/* sending the metadata block */
......@@ -572,17 +574,24 @@ static refbuf_t *mp3_get_filter_meta (source_t *source)
static int format_mp3_create_client_data(source_t *source, client_t *client)
{
mp3_client_data *data = calloc(1,sizeof(mp3_client_data));
mp3_client_data *client_mp3 = calloc(1,sizeof(mp3_client_data));
char *metadata;
mp3_state *source_mp3 = source->format->_state;
if (data == NULL)
if (client_mp3 == NULL)
return -1;
client->format_data = data;
client->format_data = client_mp3;
client->free_client_data = free_mp3_client_data;
metadata = httpp_getvar(client->parser, "icy-metadata");
if(metadata)
data->use_metadata = atoi(metadata)>0?1:0;
if (metadata && atoi(metadata))
{
if (source_mp3->interval > 0)
client_mp3->interval = source_mp3->interval;
else
client_mp3->interval = ICY_METADATA_INTERVAL;
}
return 0;
}
......@@ -632,10 +641,10 @@ static void format_mp3_send_headers(format_plugin_t *self,
if (bytes > 0)
client->con->sent_bytes += bytes;
if (mp3data->use_metadata)
if (mp3data->interval)
{
int bytes = sock_write(client->con->sock, "icy-metaint:%d\r\n",
ICY_METADATA_INTERVAL);
mp3data->interval);
if(bytes > 0)
client->con->sent_bytes += bytes;
}
......
......@@ -22,7 +22,7 @@ typedef struct {
/* These are for inline metadata */
int inline_metadata_interval;
int offset;
unsigned interval;
int interval;
char *url_artist;
char *url_title;
int update_metadata;
......
......@@ -139,6 +139,8 @@ static void free_ogg_codecs (ogg_state_t *ogg_info)
while (codec)
{
ogg_codec_t *next = codec->next;
if (codec->possible_start)
refbuf_release (codec->possible_start);
codec->codec_free (ogg_info, codec);
codec = next;
}
......
......@@ -200,7 +200,11 @@ static refbuf_t *get_buffer_finished (ogg_state_t *ogg_info, ogg_codec_t *codec)
format_ogg_free_headers (ogg_info);
source_vorbis->get_buffer_page = NULL;
source_vorbis->process_packet = process_vorbis_headers;
if (source_vorbis->prev_packet)
source_vorbis->process_packet = process_vorbis_headers;
else
source_vorbis->process_packet = NULL;
if (source_vorbis->initial_audio_packet == 0)
source_vorbis->prev_window = 0;
......@@ -264,6 +268,8 @@ static int process_vorbis_audio (ogg_state_t *ogg_info, ogg_codec_t *codec)
if (packet.e_o_s)
{
initiate_flush (source_vorbis);
free_ogg_packet (source_vorbis->prev_packet);
source_vorbis->prev_packet = NULL;
return 1;
}
......@@ -275,6 +281,7 @@ static int process_vorbis_audio (ogg_state_t *ogg_info, ogg_codec_t *codec)
{
initiate_flush (source_vorbis);
source_vorbis->stream_notify = 0;
return 1;
}
return -1;
}
......@@ -329,7 +336,6 @@ static int process_vorbis_headers (ogg_state_t *ogg_info, ogg_codec_t *codec)
*/
ogg_codec_t *initial_vorbis_page (format_plugin_t *plugin, ogg_page *page)
{
// ogg_state_t *ogg_info = plugin->_state;
ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
ogg_packet packet;
......
......@@ -60,7 +60,7 @@
#define CATMODULE "slave"
static void *_slave_thread(void *arg);
thread_type *_slave_thread_id;
static thread_type *_slave_thread_id;
static int slave_running = 0;
volatile static unsigned int max_interval = 0;
volatile static int rescan_relays = 0;
......@@ -305,29 +305,29 @@ update_relay_set (relay_server **current, relay_server *updated)
while (relay)
{
existing_relay = *current;
existing_p = current;
while (existing_relay)
{
/* break out if keeping relay */
if (strcmp (relay->localmount, existing_relay->localmount) == 0)
break;
existing_p = &existing_relay->next;
existing_relay = existing_relay->next;
}
if (existing_relay == NULL)
{
/* new one, copy and insert */
existing_relay = relay_copy (relay);
}
else
{
*existing_p = existing_relay->next;
}
existing_relay->next = new_list;
new_list = existing_relay;
relay = relay->next;
existing_relay = *current;
existing_p = current;
while (existing_relay)
{
/* break out if keeping relay */
if (strcmp (relay->localmount, existing_relay->localmount) == 0)
break;
existing_p = &existing_relay->next;
existing_relay = existing_relay->next;
}
if (existing_relay == NULL)
{
/* new one, copy and insert */
existing_relay = relay_copy (relay);
}
else
{
*existing_p = existing_relay->next;
}
existing_relay->next = new_list;
new_list = existing_relay;
relay = relay->next;
}
return new_list;
}
......@@ -480,11 +480,13 @@ static void *_slave_thread(void *arg)
ice_config_t *config;
unsigned int interval = 0;
while (slave_running)
while (1)
{
relay_server *cleanup_relays;
thread_sleep (1000000);
if (slave_running == 0)
break;
if (rescan_relays == 0 && max_interval > ++interval)
continue;
......
......@@ -228,10 +228,21 @@ void source_clear_source (source_t *source)
avl_tree_unlock (source->pending_tree);
if (source->format && source->format->free_plugin)
{
source->format->free_plugin (source->format);
}
source->format = NULL;
/* Lets clear out the source queue too */
while (source->stream_data)
{
refbuf_t *p = source->stream_data;
source->stream_data = p->next;
/* can be referenced by burst handler as well */
while (p->_count > 1)
refbuf_release (p);
refbuf_release (p);
}
source->stream_data_tail = NULL;
if (source->yp_public)
yp_remove (source->mount);
......@@ -255,18 +266,6 @@ void source_clear_source (source_t *source)
free(source->dumpfilename);
source->dumpfilename = NULL;
/* Lets clear out the source queue too */
while (source->stream_data)
{
refbuf_t *p = source->stream_data;
source->stream_data = p->next;
/* can be referenced by burst handler as well */
while (p->_count > 1)
refbuf_release (p);
refbuf_release (p);
}
source->stream_data_tail = NULL;
}
......
......@@ -419,6 +419,8 @@ static void modify_node_event (stats_node_t *node, stats_event_t *event)
}
str = malloc (16);
snprintf (str, 16, "%d", value);
if (event->value == NULL)
event->value = strdup (str);
}
else
str = (char *)strdup (event->value);
......
......@@ -68,6 +68,8 @@ void xslt_initialize()
{
memset(cache, 0, sizeof(stylesheet_cache_t)*CACHESIZE);
thread_mutex_create(&xsltlock);
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
}
void xslt_shutdown() {
......@@ -80,6 +82,7 @@ void xslt_shutdown() {
xsltFreeStylesheet(cache[i].stylesheet);
}
thread_mutex_destroy (&xsltlock);
xsltCleanupGlobals();
}
......@@ -157,9 +160,6 @@ void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client)
params[0] = NULL;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
thread_mutex_lock(&xsltlock);
cur = xslt_get_stylesheet(xslfilename);
......
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