Exemple #1
0
static void command_shoutcast_metadata(client_t *client, source_t *source)
{
    const char *action;
    const char *value;

    DEBUG0("Got shoutcast metadata update request");

    COMMAND_REQUIRE(client, "mode", action);
    COMMAND_REQUIRE(client, "song", value);

    if (strcmp (action, "updinfo") != 0)
    {
        client_send_400 (client, "No such action");
        return;
    }

    if (source->format && source->format->set_tag)
    {
        source->format->set_tag (source->format, "title", value, NULL);

        DEBUG2("Metadata on mountpoint %s changed to \"%s\"", 
                source->mount, value);
        html_success(client, "Metadata update successful");
    }
    else
    {
        client_send_400 (client, "mountpoint will not accept URL updates");
    }
}
Exemple #2
0
static void command_shoutcast_metadata(client_t *client, source_t *source)
{
    char *action;
    char *value;
    mp3_state *state;

    DEBUG0("Got shoutcast metadata update request");

    COMMAND_REQUIRE(client, "mode", action);
    COMMAND_REQUIRE(client, "song", value);

    if (source->format->type == FORMAT_TYPE_OGG) {
        client_send_400 (client, "Cannot update metadata on vorbis streams");
        return;
    }

    if (strcmp (action, "updinfo") != 0)
    {
        client_send_400 (client, "No such action");
        return;
    }

    state = source->format->_state;

    mp3_set_tag (source->format, "title", value);

    DEBUG2("Metadata on mountpoint %s changed to \"%s\"", 
        source->mount, value);


    html_success(client, "Metadata update successful");
}
Exemple #3
0
static int command_fallback (client_t *client, source_t *source, int response)
{
    char *mount = strdup (source->mount);
    mount_proxy *mountinfo;
    ice_config_t *config;

    thread_mutex_unlock (&source->lock);
    DEBUG0("Got fallback request");
    config = config_grab_config();
    mountinfo = config_find_mount (config, mount);
    free (mount);
    if (mountinfo)
    {
        const char *fallback;
        char buffer[200];
        if (COMMAND_REQUIRE(client, "fallback", fallback) < 0)
            return client_send_400 (client, "missing arg, fallback");

        xmlFree (mountinfo->fallback_mount);
        mountinfo->fallback_mount = (char *)xmlCharStrdup (fallback);
        snprintf (buffer, sizeof (buffer), "Fallback for \"%s\" configured", mountinfo->mountname);
        config_release_config ();
        return html_success (client, buffer);
    }
    config_release_config ();
    return client_send_400 (client, "no mount details available");
}
Exemple #4
0
static int command_shoutcast_metadata (client_t *client, source_t *source)
{
    const char *action;
    const char *value;
    int same_ip = 1;

    if (COMMAND_REQUIRE(client, "mode", action) < 0)
    {
        thread_mutex_unlock (&source->lock);
        return client_send_400 (client, "missing arg, mode");
    }

    if ((source->flags & SOURCE_SHOUTCAST_COMPAT) == 0)
    {
        thread_mutex_unlock (&source->lock);
        ERROR0 ("illegal request on non-shoutcast compatible stream");
        return client_send_400 (client, "Not a shoutcast compatible stream");
    }

    if (strcmp (action, "updinfo") == 0)
    {
        DEBUG0("Got shoutcast metadata update request");
        if (COMMAND_REQUIRE (client, "song", value) < 0)
        {
            thread_mutex_unlock (&source->lock);
            return client_send_400 (client, "missing arg, song");
        }
        if (source->client && strcmp (client->connection.ip, source->client->connection.ip) != 0)
            if (connection_check_admin_pass (client->parser) == 0)
                same_ip = 0;

        if (same_ip && source->format && source->format->set_tag)
        {
            httpp_set_query_param (client->parser, "mount", client->server_conn->shoutcast_mount);
            source->format->set_tag (source->format, "title", value, NULL);
            source->format->set_tag (source->format, NULL, NULL, NULL);

            DEBUG2("Metadata on mountpoint %s changed to \"%s\"", source->mount, value);
            thread_mutex_unlock (&source->lock);
            return html_success(client, "Metadata update successful");
        }
        thread_mutex_unlock (&source->lock);
        return client_send_400 (client, "mountpoint will not accept URL updates");
    }
    if (strcmp (action, "viewxml") == 0)
    {
        xmlDocPtr doc;
        DEBUG0("Got shoutcast viewxml request");
        thread_mutex_unlock (&source->lock);
        doc = stats_get_xml (STATS_ALL, source->mount);
        return admin_send_response (doc, client, XSLT, "viewxml.xsl");
    }
    thread_mutex_unlock (&source->lock);
    return client_send_400 (client, "No such action");
}
Exemple #5
0
static void command_fallback(client_t *client, source_t *source,
    int response)
{
    const char *fallback;
    char *old;

    DEBUG0("Got fallback request");

    COMMAND_REQUIRE(client, "fallback", fallback);

    old = source->fallback_mount;
    source->fallback_mount = strdup(fallback);
    free(old);

    html_success(client, "Fallback configured");
}
int main (int argc, char *argv[])
{
	char err_msg[256];
	long file_size = 0;
	long file_begin = 0, file_end = 0;

	// Get multipart file data separator
	char separator[MAX_SEPARATOR_LEN];

	html_header();

	if (get_content_separator(separator, sizeof(separator), &file_size) < 0)
	{
		html_error(RFC_ERROR);
		return -1;
	}

	// Get multipart file name
	char *filename = getenv("UPLOAD_FILENAME");
	if (filename == NULL)
	{
		html_error(RFC_ERROR);
		return -1;
	}

	// Wait until file is completely uploaded
	int tries = 0;
	while (tries>5)
	{
		struct stat filestat;
		if (stat(filename, &filestat)>0)
		{
			if (filestat.st_size >= file_size) // Size ok?
				break;
		}

		sleep(1000);
		tries++;
	}

	// Open file
	FILE *fd = fopen(filename, "r");
	if (fd == NULL)
	{
		html_error(RFC_ERROR);
		return -1;
	}

	// Parse parameters
	parameter_t *params;
	if (read_parameters(fd, separator, &params)<0)
	{
		fclose(fd);
		html_error(RFC_ERROR);
		return -1;
	}

	fclose(fd);

	// Find parameter containing NVRAM reset flag
	parameter_t *find = find_parameter(params, "reset_rwfs");
	int reset_rwfs = 0;
	if (find != NULL)
	{
		if (find->value != NULL)
			reset_rwfs = (strcasecmp(find->value, "on")==0);
	}

	// Find parameter containing file
	find = find_parameter(params, "filename");
	if (find != NULL)
	{
		// Check if parameter is correct
		if (find->content_type == NULL)
		{
			html_error(RFC_ERROR);
			return -1;
		}
		if (!check_binary_content_type(find->content_type))
		{
			sprintf(err_msg, "Unsupported content-type for binary data: %s", find->content_type);
			html_error(err_msg);
			return -1;
		}

		file_begin = find->start_pos;
		file_end   = find->end_pos;
	}
	else
	{
		html_error("No firmware binary file");
		return -1;
	}

	release_parameters(params);

	// check image size
	if (!check(filename, (int)file_begin, (int)(file_end - file_begin), err_msg))
	{
		html_error(err_msg);
		return -1;
	}

	// firmware update timeouts
	// examination, reset NVRAM if needed
	// start web timer and crash rwfs BEFORE flash destroy
	if (reset_rwfs)
	{
		system("/bin/mtd_write erase RW-FS > /dev/null");
		html_success(18*(IMAGE1_SIZE/0x100000) + 60);
	} else
		html_success(18*(IMAGE1_SIZE/0x100000) + 50);

	// flash write
	if (mtd_write_firmware(filename, (int)file_begin, (file_end - file_begin)) == -1)
		return -1;

	sleep (3);
	reboot(RB_AUTOBOOT);
	return 0;
}