Exemple #1
0
int savePlaylist(FILE * fp, char * utf8file) {
	FILE * fileP;
	int i;
	struct stat st;
	char * file;
	char * rfile;
	char * actualFile;

	if(strstr(utf8file,"/")) {
		commandError(fp, ACK_ERROR_ARG,
                                "cannot save \"%s\", saving playlists to "
				"subdirectories is not supported", utf8file);
		return -1;
	}

	file = strdup(utf8ToFsCharset(utf8file));

	rfile = malloc(strlen(file)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);

	strcpy(rfile,file);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	free(file);

	actualFile = rpp2app(rfile);

	free(rfile);

	if(0==stat(actualFile,&st)) {
		commandError(fp, ACK_ERROR_EXIST, "a file or directory already " 
                                "exists with the name \"%s\"", utf8file);
		return -1;
	}

	while(!(fileP = fopen(actualFile,"w")) && errno==EINTR);
	if(fileP==NULL) {
		commandError(fp, ACK_ERROR_SYSTEM, "problems opening file", 
				NULL);
		return -1;
	}

	for(i=0;i<playlist.length;i++) {
		if(playlist_saveAbsolutePaths && 
				playlist.songs[i]->type==SONG_TYPE_FILE) 
		{
			myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset((
				        getSongUrl(playlist.songs[i])))));
		}
		else myfprintf(fileP,"%s\n",
				utf8ToFsCharset(getSongUrl(playlist.songs[i])));
	}

	while(fclose(fileP) && errno==EINTR);

	return 0;
}
Exemple #2
0
int deletePlaylist(FILE * fp, char * utf8file) {
	char * file = utf8ToFsCharset(utf8file);
	char * rfile = malloc(strlen(file)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);
	char * actualFile;

	strcpy(rfile,file);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile);
	else {
		free(rfile);
		commandError(fp, ACK_ERROR_NO_EXIST, 
                                "playlist \"%s\" not found", utf8file);
		return -1;
	}

	if(unlink(actualFile)<0) {
		commandError(fp, ACK_ERROR_SYSTEM,
                                "problems deleting file", NULL);
		return -1;
	}

	return 0;
}
Exemple #3
0
int myStat(char * utf8file, struct stat * st) {
	char * file = utf8ToFsCharset(utf8file);
	char * actualFile = file;

	if(actualFile[0]!='/') actualFile = rmp2amp(file);

	return stat(actualFile,st);
}
Exemple #4
0
void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
        int ret;
        InputStream inStream;
        InputPlugin * plugin = NULL;
        char * path;

        if(isRemoteUrl(pc->utf8url)) {
                path = utf8StrToLatin1Dup(pc->utf8url);
        }
	else path = strdup(rmp2amp(utf8ToFsCharset(pc->utf8url)));

	if(!path) {
		dc->error = DECODE_ERROR_FILE;
		dc->state = DECODE_STATE_STOP;
		dc->start = 0;
                return;
	}

	copyMpdTagToOutputBuffer(cb, NULL);

        strncpy(dc->utf8url, pc->utf8url, MAXPATHLEN);
	dc->utf8url[MAXPATHLEN] = '\0';

        if(openInputStream(&inStream, path) < 0) {
		dc->error = DECODE_ERROR_FILE;
		dc->state = DECODE_STATE_STOP;
		dc->start = 0;
		free(path);
                return;
        }

        dc->seekable = inStream.seekable;
        dc->state = DECODE_STATE_START;
	dc->start = 0;

        while(!inputStreamAtEOF(&inStream) && bufferInputStream(&inStream) < 0
                        && !dc->stop)
	{
		/* sleep so we don't consume 100% of the cpu */
//		fprintf(stderr,"In decode.c decodeParent decode start func\r\n");
	//	my_usleep(1000);
	}

        if(dc->stop) {
                dc->state = DECODE_STATE_STOP;
                dc->stop = 0;
		free(path);
                return;
        }

        /*if(inStream.metaName) {
		MpdTag * tag = newMpdTag();
		tag->name = strdup(inStream.metaName);
		copyMpdTagToOutputBuffer(cb, tag);
		freeMpdTag(tag);
        }*/

	/* reset Metadata in OutputBuffer */

        ret = DECODE_ERROR_UNKTYPE;
	if(isRemoteUrl(dc->utf8url)) {
		cb->acceptMetadata = 1;
		plugin = getInputPluginFromMimeType(inStream.mime);
                if(plugin == NULL) {
                        plugin = getInputPluginFromSuffix(
                                        getSuffix(dc->utf8url));
                }
                /* this is needed for bastard streams that don't have a suffix
                                or set the mimeType */
                if(plugin == NULL) {
                        plugin = getInputPluginFromName("mp3");
                }
                if(plugin && (plugin->streamTypes & INPUT_PLUGIN_STREAM_URL) &&
                                plugin->streamDecodeFunc) 
                {
                        ret = plugin->streamDecodeFunc(cb, dc, &inStream);
                }
	}
        else {
		cb->acceptMetadata = 0;
                plugin = getInputPluginFromSuffix(getSuffix(dc->utf8url));
                if(plugin && (plugin->streamTypes && INPUT_PLUGIN_STREAM_FILE))
                {
                        if(plugin->streamDecodeFunc) {
                                ret = plugin->streamDecodeFunc(cb, dc, 
                                                &inStream);
                        }
                        else if(plugin->fileDecodeFunc) {
                                closeInputStream(&inStream);
                                ret = plugin->fileDecodeFunc(cb, dc, path);
                        }
                }
        }

	if(ret<0 || ret == DECODE_ERROR_UNKTYPE) {
		strncpy(pc->erroredUrl, dc->utf8url, MAXPATHLEN);
		pc->erroredUrl[MAXPATHLEN] = '\0';
		if(ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE;
                else {
                        dc->error = DECODE_ERROR_UNKTYPE;
                        closeInputStream(&inStream);
                }
		dc->stop = 0;
		dc->state = DECODE_STATE_STOP;
	}

	free(path);
}
Exemple #5
0
int loadPlaylist(FILE * fp, char * utf8file) {
	FILE * fileP;
	char s[MAXPATHLEN+1];
	int slength = 0;
	char * temp = strdup(utf8ToFsCharset(utf8file));
	char * rfile = malloc(strlen(temp)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);
	char * actualFile;
	char * parent = parentPath(temp);
	int parentlen = strlen(parent);
	char * erroredFile = NULL;
	int tempInt;
	int commentCharFound = 0;

	strcpy(rfile,temp);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	free(temp);

	if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile);
	else {
		free(rfile);
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "playlist \"%s\" not found", utf8file);
		return -1;
	}

	while(!(fileP = fopen(actualFile,"r")) && errno==EINTR);
	if(fileP==NULL) {
		commandError(fp, ACK_ERROR_SYSTEM,
                                "problems opening file \"%s\"", utf8file);
		return -1;
	}

	while((tempInt = fgetc(fileP))!=EOF) {
		s[slength] = tempInt;
		if(s[slength]=='\n' || s[slength]=='\0') {
			commentCharFound = 0;
			s[slength] = '\0';
			if(s[0]==PLAYLIST_COMMENT) {
				commentCharFound = 1;
			}
			if(strncmp(s,musicDir,strlen(musicDir))==0) {
				strcpy(s,&(s[strlen(musicDir)]));
			}
			else if(parentlen) {
				temp = strdup(s);
				memset(s,0,MAXPATHLEN+1);
				strcpy(s,parent);
				strncat(s,"/",MAXPATHLEN-parentlen);
				strncat(s,temp,MAXPATHLEN-parentlen-1);
				if(strlen(s)>=MAXPATHLEN) {
					commandError(fp, 
                                                        ACK_ERROR_PLAYLIST_LOAD,
                                                        "\"%s\" too long",
                                                        temp);
					free(temp);
					while(fclose(fileP) && errno==EINTR);
					if(erroredFile) free(erroredFile);
					return -1;
				}
				free(temp);
			}
			slength = 0;
			temp = fsCharsetToUtf8(s);
			if(!temp) continue;
			temp = strdup(temp);
			if(commentCharFound && !getSongFromDB(temp)
					&& !isRemoteUrl(temp)) 
			{
				free(temp);
				continue;
			}
			if((addToPlaylist(stderr,temp))<0) {
				if(!erroredFile) erroredFile = strdup(temp);
			}
			free(temp);
		}
		else if(slength==MAXPATHLEN) {
			s[slength] = '\0';
			commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
                                        "line in \"%s\" is too long", utf8file);
			ERROR("line \"%s\" in playlist \"%s\" is too long\n",
				s, utf8file);
			while(fclose(fileP) && errno==EINTR);
			if(erroredFile) free(erroredFile);
			return -1;
		}
		else if(s[slength]!='\r') slength++;
	}

	while(fclose(fileP) && errno==EINTR);

	if(erroredFile) {
		commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
                                "can't add file \"%s\"", erroredFile);
		free(erroredFile);
		return -1;
	}

	return 0;
}
Exemple #6
0
int lsPlaylists(FILE * fp, char * utf8path) {
	DIR * dir;
	struct stat st;
	struct dirent * ent;
	char * dup;
	char * utf8;
	char s[MAXPATHLEN+1];
	List * list = NULL;
	ListNode * node = NULL;
	char * path = strdup(utf8ToFsCharset(utf8path));
	char * actualPath = rpp2app(path);
	int actlen = strlen(actualPath)+1;
	int maxlen = MAXPATHLEN-actlen;
	int suflen = strlen(PLAYLIST_FILE_SUFFIX)+1;
	int suff;

	if(actlen>MAXPATHLEN-1 || (dir = opendir(actualPath))==NULL) {
		free(path);
		return 0;
	}

	s[MAXPATHLEN] = '\0';
	/* this is safe, notice actlen > MAXPATHLEN-1 above */
	strcpy(s,actualPath);
	strcat(s,"/");

	while((ent = readdir(dir))) {
		dup = ent->d_name;
		if(dup[0]!='.' && 
				(suff=strlen(dup)-suflen)>0 && 
				dup[suff]=='.' &&
				strcmp(dup+suff+1,PLAYLIST_FILE_SUFFIX)==0) 
		{
			strncpy(s+actlen,ent->d_name,maxlen);
			if(stat(s,&st)==0) {
				if(S_ISREG(st.st_mode)) {
					if(list==NULL) list = makeList(NULL, 1);
					dup = strdup(ent->d_name);
					dup[suff] = '\0';
					if((utf8 = fsCharsetToUtf8(dup))) {
						insertInList(list,utf8,NULL);
					}
					free(dup);
				}
			}
		}
	}
	
	closedir(dir);
	free(path);

	if(list) {
		int i;
		sortList(list);

		dup = malloc(strlen(utf8path)+2);
		strcpy(dup,utf8path);
		for(i = strlen(dup)-1; i >= 0 && dup[i]=='/'; i--) {
			dup[i] = '\0';
		}
		if(strlen(dup)) strcat(dup,"/");

		node = list->firstNode;
		while(node!=NULL) {
                        if(!strchr(node->key, '\n')) {
			        myfprintf(fp,"playlist: %s%s\n",dup,node->key);
                        }
			node = node->nextNode;
		}

		freeList(list);
		free(dup);
	}

	return 0;
}