/* update the specified source with details from the config or mount. * mountinfo can be NULL in which case default settings should be taken */ void source_update_settings (ice_config_t *config, source_t *source, mount_proxy *mountinfo) { /* skip if source is a fallback to file */ if (source->running && source->client == NULL) { stats_event_hidden (source->mount, NULL, 1); return; } /* set global settings first */ source->queue_size_limit = config->queue_size_limit; source->timeout = config->source_timeout; source->burst_size = config->burst_size; stats_event_args (source->mount, "listenurl", "http://%s:%d%s", config->hostname, config->port, source->mount); source_apply_mount (source, mountinfo); if (source->fallback_mount) DEBUG1 ("fallback %s", source->fallback_mount); if (mountinfo && mountinfo->intro_filename) DEBUG1 ("intro file is %s", mountinfo->intro_filename); if (source->dumpfilename) DEBUG1 ("Dumping stream to %s", source->dumpfilename); if (mountinfo && mountinfo->on_connect) DEBUG1 ("connect script \"%s\"", mountinfo->on_connect); if (mountinfo && mountinfo->on_disconnect) DEBUG1 ("disconnect script \"%s\"", mountinfo->on_disconnect); if (source->on_demand) { DEBUG0 ("on_demand set"); stats_event (source->mount, "on_demand", "1"); stats_event_args (source->mount, "listeners", "%ld", source->listeners); } else stats_event (source->mount, "on_demand", NULL); if (source->hidden) { stats_event_hidden (source->mount, NULL, 1); DEBUG0 ("hidden from public"); } else stats_event_hidden (source->mount, NULL, 0); if (source->max_listeners == -1) stats_event (source->mount, "max_listeners", "unlimited"); else { char buf [10]; snprintf (buf, sizeof (buf), "%ld", source->max_listeners); stats_event (source->mount, "max_listeners", buf); } DEBUG1 ("public set to %d", source->yp_public); 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); DEBUG1 ("fallback_when_full to %u", source->fallback_when_full); }
/* Called when activating a source. Verifies that the source count is not * exceeded and applies any initial parameters. */ int connection_complete_source (source_t *source) { ice_config_t *config = config_get_config(); global_lock (); DEBUG1 ("sources count is %d", global.sources); if (global.sources < config->source_limit) { char *contenttype; mount_proxy *mountproxy = config->mounts; format_type_t format_type; /* setup format handler */ contenttype = httpp_getvar (source->parser, "content-type"); if (contenttype != NULL) { format_type = format_get_type (contenttype); if (format_type == FORMAT_ERROR) { global_unlock(); config_release_config(); if (source->client) client_send_404 (source->client, "Content-type not supported"); WARN1("Content-type \"%s\" not supported, dropping source", contenttype); return -1; } } else { WARN0("No content-type header, falling back to backwards compatibility mode " "for icecast 1.x relays. Assuming content is mp3."); format_type = FORMAT_TYPE_MP3; } if (format_get_plugin (format_type, source) < 0) { global_unlock(); config_release_config(); if (source->client) client_send_404 (source->client, "internal format allocation problem"); WARN1 ("plugin format failed for \"%s\"", source->mount); return -1; } global.sources++; global_unlock(); /* set global settings first */ source->queue_size_limit = config->queue_size_limit; source->timeout = config->source_timeout; source->burst_size = config->burst_size; /* for relays, we don't yet have a client, however we do require one * to retrieve the stream from. This is created here, quite late, * because we can't use this client to return an error code/message, * so we only do this once we know we're going to accept the source. */ if (source->client == NULL) source->client = client_create (source->con, source->parser); while (mountproxy) { if (strcmp (mountproxy->mountname, source->mount) == 0) { source_apply_mount (source, mountproxy); break; } mountproxy = mountproxy->next; } config_release_config(); source->shutdown_rwlock = &_source_shutdown_rwlock; DEBUG0 ("source is ready to start"); return 0; } WARN1("Request to add source when maximum source limit " "reached %d", global.sources); global_unlock(); config_release_config(); if (source->client) client_send_404 (source->client, "too many sources connected"); return -1; }