Esempio n. 1
0
static int
isplaylist(url_t *u, char *mime, char *name)
{
    char buf[1024], buf1[1024];
    struct stat st;
    uint64_t pos;
    char *p, *q;

    if(strcmp(mime, "text/plain"))
        return 0;

    pos = u->tell(u);
    p = url_gets(buf, sizeof(buf), u);
    u->seek(u, pos, SEEK_SET);
    if(!p)
        return 0;

    p = strchr(buf, ':');
    if(p){
        for(q = buf; q < p; q++){
            if(*q >= 'a' && *q <= 'z')
                continue;
            if(isdigit(*q))
                continue;
            if(*q == '-' || *q == '+' || *q == '.')
                continue;
            break;
        }
        if(p == q)
            return 1;
    }

    p = strchr(buf, 0);
    if(p > buf && *--p == '\n')
        *p = 0;
    if(p > buf && *--p == '\r')
        *p = 0;

    if(buf[0] != '/' && name){
        strncpy(buf1, name, sizeof(buf1));
        p = strrchr(buf1, '/');
        if(p)
            p++;
        else
            p = buf1;
        strncpy(p, buf, sizeof(buf1) - (p - buf1));
        p = buf1;
    } else {
        p = buf;
    }

    if(stat(p, &st))
        return 0;
    return 1;
}
Esempio n. 2
0
void ScanDirectoryFiles(char *basedir,
						int (* file_proc)(char *pathname, /* (const) */
										  void *user_val),
						void *user_val)
{
	char baselen;
	URL dir;

	static int depth = 0;
    static int stop_flag;	/* Stop scanning if true */
    static int error_disp;	/* Whether error is displayed or not */
	static char pathbuf[MAXPATH]; /* pathname buffer */

	if(depth == 0) /* Initialize variables at first recursive */
	{
		stop_flag = 0;
		error_disp = 0;
		strcpy(pathbuf, basedir);
	}
	else if(depth > SCANDIR_MAX_DEPTH) /* Avoid infinite recursive */
	{
		if(!error_disp)
		{
			/* Display this message at once */
			ctl->cmsg(CMSG_WARNING, VERB_NORMAL,
					  "%s: Directory is too deep",
					  basedir);
			error_disp = 1;
		}
		return; /* Skip scanning this directory */
	}

	directory_form(pathbuf);
	baselen = strlen(pathbuf);
	if(baselen > sizeof(pathbuf) - 16)
	{
		/* Ignore too long file name */
		return;
	}

	if((dir = url_dir_open(pathbuf)) == NULL)
	{
	    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: Can't open directory", pathbuf);
		return;
	}

	if(file_proc(pathbuf, user_val))
	{
	    stop_flag = 1; /* Terminate */
		return;
	}

	while(!stop_flag &&
		  url_gets(dir, pathbuf + baselen, sizeof(pathbuf) - baselen - 1))
	{
		if(strcmp(pathbuf + baselen, ".") == 0 ||
		   strcmp(pathbuf + baselen, "..") == 0)
			continue;
		if(file_proc(pathbuf, user_val))
		{
			stop_flag = 1; /* Terminate */
			break;
		}
		if(is_directory(pathbuf))
		{
			/* into subdirectory */
			depth++;
			ScanDirectoryFiles(pathbuf, file_proc, user_val);
			depth--;
		}
	}
	url_close(dir);
}
Esempio n. 3
0
static int
pl_addlist(tcvp_playlist_t *tpl, char *file, int pos)
{
    url_t *plf = url_open(file, "r");
    char buf[1024], *line = alloca(1024), **lp = &line;
    char *d, *l;
    int n = 0;

    tc2_print("PLAYLIST", TC2_PRINT_DEBUG, "adding list %s\n", file);

    if(!plf)
        return -1;

    if(pos < 0)
        pos = tpl->nf + pos + 1;
    if(pos < 0)
        pos = 0;

    l = strdup(file);
    d = strrchr(l, '/');
    if(d && !*(d + 1)){
        *d = 0;
        d = strrchr(l, '/');
    }
    if(d){
        *d = 0;
        d = l;
    } else {
        d = ".";
    }

    while(url_gets(buf, 1024, plf)){
        int bl;

        if(buf[0] == '#')
            continue;

        bl = strlen(buf);
        if(bl == 0)
            continue;

        bl--;
        while(bl > 0 && (buf[bl] == '\n' || buf[bl] == '\r'))
            buf[bl--] = 0;

        if(buf[0] == 0)
            continue;

        if(buf[0] == '/' || strchr(buf, ':')){
            strncpy(line, buf, 1024);
            line[1023] = 0;
        } else {
            snprintf(line, 1024, "%s/%s", d, buf);
        }

        n += pl_addauto_unlocked(tpl, lp, 1, pos + n);
    }

    free(l);
    plf->close(plf);

    return n;
}
Esempio n. 4
0
char *tf_gets(char *buff, int n, struct timidity_file *tf)
{
    return url_gets(tf->url, buff, n);
}