aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-03-18 04:01:37 +0000
committerEric Wong <normalperson@yhbt.net>2006-03-18 04:01:37 +0000
commit0e793b510a2a61759cccf4caa38d9651eae1018b (patch)
treefd23fef78584a66ca6852895ecbd827ab8de68ab
parent17d3ccbaa3f22c4c0f8a86515d71fc017a451bbd (diff)
downloadmpd-svn/oggflac.tar.gz
mpd-svn/oggflac.tar.xz
mpd-svn/oggflac.zip
merge up to r3928, branch should be closeable unless there aresvn/oggflac
major issues that need to be addressed. git-svn-id: https://svn.musicpd.org/mpd/branches/oggflac@3929 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--doc/COMMANDS2
-rw-r--r--src/audio.c193
-rw-r--r--src/audio.h2
-rw-r--r--src/audioOutputs/audioOutput_shout.c4
-rw-r--r--src/command.c8
-rw-r--r--src/conf.c8
-rw-r--r--src/inputStream_http.c8
-rw-r--r--src/list.c1
-rw-r--r--src/ls.c2
-rw-r--r--src/main.c6
-rw-r--r--src/permission.c4
-rw-r--r--src/playerData.c2
12 files changed, 111 insertions, 129 deletions
diff --git a/doc/COMMANDS b/doc/COMMANDS
index 02238d8c9..d11dcd4f2 100644
--- a/doc/COMMANDS
+++ b/doc/COMMANDS
@@ -113,7 +113,7 @@ next
pause <bool pause>
toggle pause/resume playing
_pause_ is required and should be 0 or 1
- NOTE: use of pause command w/o the _pause_ argument is depricated
+ NOTE: use of pause command w/o the _pause_ argument is deprecated
password <string password>
this is used for authentication with the server.
diff --git a/src/audio.c b/src/audio.c
index 8f7200d46..dfc209b32 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -34,18 +34,10 @@
#include <errno.h>
#include <unistd.h>
-
-/* crappy code by qball */
-#define AUDIO_STATE_FILE_DEVICE_START "audio_device_start"
-#define AUDIO_STATE_FILE_DEVICE_ID "audio_device_id: "
-#define AUDIO_STATE_FILE_DEVICE_ENABLED "audio_device_enabled: "
-#define AUDIO_STATE_FILE_DEVICE_NAME "audio_device_name: "
-#define AUDIO_STATE_FILE_DEVICE_END "audio_device_end"
-
+#define AUDIO_DEVICE_STATE "audio_device_state:"
+#define AUDIO_DEVICE_STATE_LEN 19 /* strlen(AUDIO_DEVICE_STATE) */
#define AUDIO_BUFFER_SIZE 2*MAXPATHLEN
-/* /crappy code */
-
-
+static void saveAudioDevicesState();
static AudioFormat audio_format;
@@ -104,6 +96,9 @@ void initAudioDriver() {
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
do {
+ AudioOutput *output;
+ int j;
+
if(audioOutputArraySize == AUDIO_MAX_DEVICES) {
ERROR("only up to 255 audio output devices are "
"supported");
@@ -114,14 +109,25 @@ void initAudioDriver() {
audioOutputArray = realloc(audioOutputArray,
audioOutputArraySize*sizeof(AudioOutput *));
-
- audioOutputArray[i] = newAudioOutput(param);
- if(!audioOutputArray[i] && param) {
+ output = newAudioOutput(param);
+ if(!output && param) {
ERROR("problems configuring output device defined at "
"line %i\n", param->line);
exit(EXIT_FAILURE);
}
+
+ /* require output names to be unique: */
+ for (j = i - 1; j >= 0; --j) {
+ if ( !strcmp( output->name,
+ audioOutputArray[j]->name) ) {
+ ERROR("output devices with identical "
+ "names: %s\n",
+ output->name);
+ exit(EXIT_FAILURE);
+ }
+ }
+ audioOutputArray[i] = output;
} while((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param)));
}
@@ -221,6 +227,7 @@ void finishAudioConfig() {
void finishAudioDriver() {
int i;
+ saveAudioDevicesState();
for(i = 0; i < audioOutputArraySize; i++) {
finishAudioOutput(audioOutputArray[i]);
}
@@ -415,115 +422,97 @@ void printAudioDevices(FILE * fp) {
}
}
-
-/* more qball crappy code */
-
static char * getStateFile() {
ConfigParam * param = parseConfigFilePath(CONF_STATE_FILE, 0);
-
+
if(!param) return NULL;
return param->value;
}
+static void saveAudioDevicesState() {
+ char *stateFile;
+ FILE *fp;
+ int i;
+ if (!(stateFile = getStateFile()))
+ return;
-void saveAudioDevicesState() {
- int i;
- char * stateFile = getStateFile();
-
- if(stateFile) {
- FILE * fp;
-
- while(!(fp = fopen(stateFile,"a")) && errno==EINTR);
- if(!fp) {
- ERROR("problems opening state file \"%s\" for "
- "writing: %s\n", stateFile,
- strerror(errno));
- return;
- }
- for(i = 0; i < audioOutputArraySize; i++) {
- myfprintf(fp, "%s\n", AUDIO_STATE_FILE_DEVICE_START);
- myfprintf(fp, "%s%i\n", AUDIO_STATE_FILE_DEVICE_ID, i);
- myfprintf(fp, "%s%s\n", AUDIO_STATE_FILE_DEVICE_NAME, audioOutputArray[i]->name);
- myfprintf(fp, "%s%i\n", AUDIO_STATE_FILE_DEVICE_ENABLED,(int)pdAudioDevicesEnabled[i]);
- myfprintf(fp, "%s\n", AUDIO_STATE_FILE_DEVICE_END);
- }
- while(fclose(fp) && errno==EINTR);
+ while(!(fp = fopen(stateFile,"a")) && errno==EINTR);
+ if(!fp) {
+ ERROR("problems opening state file \"%s\" for "
+ "writing: %s\n", stateFile, strerror(errno));
+ return;
+ }
+
+ assert(audioOutputArraySize != 0);
+ for (i = audioOutputArraySize - 1; i >= 0; --i) {
+ myfprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
+ (int)pdAudioDevicesEnabled[i],
+ audioOutputArray[i]->name);
}
+ while(fclose(fp) && errno==EINTR);
}
-void readAudioDevicesState() {
- char * stateFile = getStateFile();
- FILE *fp;
- struct stat st;
- if(stateFile) {
- char buffer[AUDIO_BUFFER_SIZE];
+static void parse_audio_device_state(FILE *fp)
+{
+ char buffer[AUDIO_BUFFER_SIZE];
+ int i;
+ assert(audioOutputArraySize != 0);
+ while (myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
+ char *c, *name;
+ if (strncmp(buffer,AUDIO_DEVICE_STATE,AUDIO_DEVICE_STATE_LEN))
+ continue;
- if(stat(stateFile,&st)<0) {
- DEBUG("failed to stat state file\n");
- return;
- }
- if(!S_ISREG(st.st_mode)) {
- ERROR("state file \"%s\" is not a regular "
- "file\n",stateFile);
- exit(EXIT_FAILURE);
- }
+ c = strchr(buffer,':');
+ if (!c || !(++c))
+ goto errline;
- fp = fopen(stateFile,"r");
- if(!fp) {
- ERROR("problems opening state file \"%s\" for "
- "reading: %s\n", stateFile,
- strerror(errno));
- exit(EXIT_FAILURE);
- }
+ name = strchr(c,':');
+ if (!name || !(++name))
+ goto errline;
- while(myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
- if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_START, strlen(AUDIO_STATE_FILE_DEVICE_START))==0) {
- char *name = NULL;
- int id = -1;
- int enabled = 1;
- if(!myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n", stateFile);
- exit(EXIT_FAILURE);
- }
- while(strcmp(buffer,AUDIO_STATE_FILE_DEVICE_END)) {
- if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_ID, strlen(AUDIO_STATE_FILE_DEVICE_ID)) == 0 ) {
- if(strlen(buffer) > strlen(AUDIO_STATE_FILE_DEVICE_ID))
- {
- id = atoi(&buffer[strlen(AUDIO_STATE_FILE_DEVICE_ID)]);
- }
- }
- if(strncmp(buffer,AUDIO_STATE_FILE_DEVICE_ENABLED, strlen(AUDIO_STATE_FILE_DEVICE_ENABLED)) == 0 ) {
- if(strlen(buffer) > strlen(AUDIO_STATE_FILE_DEVICE_ENABLED))
- {
- enabled = atoi(&buffer[strlen(AUDIO_STATE_FILE_DEVICE_ENABLED)]);
- }
- }
- if(!myFgets(buffer,AUDIO_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n", stateFile);
- exit(EXIT_FAILURE);
- }
- }
- if(id != -1)
- {
- /* search for same name here, can we trust id? */
- if(id < audioOutputArraySize)
- {
- pdAudioDevicesEnabled[id] = enabled;
- }
- }
- if(name != NULL)
- {
- free(name);
- }
+ for (i = audioOutputArraySize - 1; i >= 0; --i) {
+ if (!strcmp(name, audioOutputArray[i]->name)) {
+ pdAudioDevicesEnabled[i] = atoi(c);
+ break;
}
}
+ continue;
+errline:
+ /* nonfatal */
+ ERROR("invalid line in state_file: %s\n", buffer);
+ }
+}
+
+void readAudioDevicesState() {
+ char *stateFile;
+ FILE *fp;
+ struct stat st;
- fclose(fp);
+ if (!(stateFile = getStateFile()))
+ return;
+ if(stat(stateFile,&st)<0) {
+ DEBUG("failed to stat state file\n");
+ return;
+ }
+ if(!S_ISREG(st.st_mode)) {
+ ERROR("state file \"%s\" is not a regular file\n",
+ stateFile);
+ exit(EXIT_FAILURE);
+ }
+
+ fp = fopen(stateFile,"r");
+ if(!fp) {
+ ERROR("problems opening state file \"%s\" for "
+ "reading: %s\n", stateFile,
+ strerror(errno));
+ exit(EXIT_FAILURE);
}
+ parse_audio_device_state(fp);
+ fclose(fp);
}
diff --git a/src/audio.h b/src/audio.h
index f1a63ee69..e7c846a60 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -75,8 +75,6 @@ int disableAudioDevice(FILE * fp, int device);
void printAudioDevices(FILE * fp);
-/* qball's crappy code */
void readAudioDevicesState();
-void saveAudioDevicesState();
#endif
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index d705eefe1..6bd418f9b 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -170,7 +170,7 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
if(*test != '\0' || sd->quality < 0.0 || sd->quality > 10.0) {
ERROR("shout quality \"%s\" is not a number in the "
- "rage 0-10, line %i\n", blockParam->value,
+ "range 0-10, line %i\n", blockParam->value,
blockParam->line);
exit(EXIT_FAILURE);
}
@@ -196,7 +196,7 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
sd->bitrate = strtol(blockParam->value, &test, 10);
if(*test != '\0' || sd->bitrate <= 0) {
- ERROR("bitrate at line %i should be a positve integer "
+ ERROR("bitrate at line %i should be a positive integer "
"\n", blockParam->line);
exit(EXIT_FAILURE);
}
diff --git a/src/command.c b/src/command.c
index 0179f9865..156e02197 100644
--- a/src/command.c
+++ b/src/command.c
@@ -237,13 +237,13 @@ int commandStatus(FILE * fp, unsigned int * permission, int argArrayLength,
playPlaylistIfPlayerStopped();
switch(getPlayerState()) {
case PLAYER_STATE_STOP:
- state = strdup(COMMAND_STOP);
+ state = COMMAND_STOP;
break;
case PLAYER_STATE_PAUSE:
- state = strdup(COMMAND_PAUSE);
+ state = COMMAND_PAUSE;
break;
case PLAYER_STATE_PLAY:
- state = strdup(COMMAND_PLAY);
+ state = COMMAND_PLAY;
break;
}
@@ -277,8 +277,6 @@ int commandStatus(FILE * fp, unsigned int * permission, int argArrayLength,
myfprintf(fp,"%s: %s\n",COMMAND_STATUS_ERROR,getPlayerErrorStr());
}
- free(state);
-
return 0;
}
diff --git a/src/conf.c b/src/conf.c
index 0fd3dda95..756fef9f9 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -215,7 +215,7 @@ static ConfigParam * readConfigBlock(FILE * fp, int * count, char * string) {
{
ERROR("improperly formatted config file at line %i:"
" %s\n", count, string);
- ERROR("in block begging at line %i\n", ret->line);
+ ERROR("in block begining at line %i\n", ret->line);
exit(EXIT_FAILURE);
}
@@ -268,7 +268,7 @@ void readConf(char * file) {
}
if(!findInList(configEntriesList, array[0], &voidPtr)) {
- ERROR("unrecognized paramater in config file at line "
+ ERROR("unrecognized parameter in config file at line "
"%i: %s\n", count, string);
exit(EXIT_FAILURE);
}
@@ -279,7 +279,7 @@ void readConf(char * file) {
entry->configParamList->numberOfNodes)
{
param = entry->configParamList->firstNode->data;
- ERROR("config paramter \"%s\" is first defined on line "
+ ERROR("config parameter \"%s\" is first defined on line "
"%i and redefined on line %i\n",
array[0], param->line, count);
exit(EXIT_FAILURE);
@@ -416,7 +416,7 @@ ConfigParam * parseConfigFilePath(char * name, int force) {
for(;*ch!='\0' && *ch!='/';ch++);
if(*ch=='/') foundSlash = 1;
* ch = '\0';
- pos+= ch-path+1;
+ pos+= ch-path-1;
if((pwd = getpwnam(path+1)) == NULL) {
ERROR("user \"%s\" not found at line %i\n",
path+1, param->line);
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index d3303eb87..9781b1b7a 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -100,7 +100,7 @@ void inputStream_initHttp() {
param = getConfigParam(CONF_HTTP_PROXY_PASSWORD);
if(!param) {
- ERROR("%s specifid but not %s\n",
+ ERROR("%s specified but not %s\n",
CONF_HTTP_PROXY_USER,
CONF_HTTP_PROXY_PASSWORD);
exit(EXIT_FAILURE);
@@ -112,7 +112,7 @@ void inputStream_initHttp() {
param = getConfigParam(CONF_HTTP_PROXY_PASSWORD);
if(param) {
- ERROR("%s specifid but not %s\n",
+ ERROR("%s specified but not %s\n",
CONF_HTTP_PROXY_PASSWORD, CONF_HTTP_PROXY_USER);
exit(EXIT_FAILURE);
}
@@ -143,7 +143,7 @@ void inputStream_initHttp() {
if(bufferSize <= 0 || *test != '\0') {
ERROR("\"%s\" specified for %s at line %i is not a "
- "positivie intenger\n",
+ "positive integer\n",
param->value, CONF_HTTP_BUFFER_SIZE,
param->line);
exit(EXIT_FAILURE);
@@ -161,7 +161,7 @@ void inputStream_initHttp() {
if(prebufferSize <= 0 || *test != '\0') {
ERROR("\"%s\" specified for %s at line %i is not a "
- "positivie intenger\n",
+ "positive integer\n",
param->value, CONF_HTTP_PREBUFFER_SIZE,
param->line);
exit(EXIT_FAILURE);
diff --git a/src/list.c b/src/list.c
index 9161acdf2..e7e4a5899 100644
--- a/src/list.c
+++ b/src/list.c
@@ -51,6 +51,7 @@ List * makeList(ListFreeDataFunc * freeDataFunc, int strdupKeys) {
assert(list!=NULL);
+ list->sorted = 0;
list->firstNode = NULL;
list->lastNode = NULL;
list->freeDataFunc = freeDataFunc;
diff --git a/src/ls.c b/src/ls.c
index f913ff2d3..8ff396835 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -155,12 +155,10 @@ int lsPlaylists(FILE * fp, char * utf8path) {
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);
}
}
}
diff --git a/src/main.c b/src/main.c
index 7b05e7c14..2f0bf870a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -220,7 +220,7 @@ void changeToUser() {
* (must be done before we change our uid)
*/
if (initgroups(param->value, userpwd->pw_gid) == -1) {
- WARNING("cannot init suplementary groups "
+ WARNING("cannot init supplementary groups "
"of user \"%s\" at line %i: %s\n",
param->value, param->line,
strerror(errno));
@@ -300,7 +300,6 @@ void startMainProcess() {
if(pid>0) {
initInputStream();
initReplayGainState();
- /* qball crappy code */
readAudioDevicesState();
/* free stuff we don't need */
@@ -317,9 +316,6 @@ void startMainProcess() {
finishAudioConfig();
finishAudioDriver();
- /* qball crappy code */
- saveAudioDevicesState();
-
finishPaths();
kill(mainPid, SIGTERM);
diff --git a/src/permission.c b/src/permission.c
index 00b754555..e44415d40 100644
--- a/src/permission.c
+++ b/src/permission.c
@@ -58,7 +58,7 @@ unsigned int parsePermissions(char * string) {
permission |= PERMISSION_ADMIN;
}
else {
- ERROR("uknown permission \"%s\"\n",temp);
+ ERROR("unknown permission \"%s\"\n",temp);
exit(EXIT_FAILURE);
}
@@ -97,7 +97,7 @@ void initPermissions() {
if(!(temp = strtok_r(param->value,
PERMISSION_PASSWORD_CHAR,&cp2))) {
- ERROR("something weird just happend in permission.c\n");
+ ERROR("something weird just happened in permission.c\n");
exit(EXIT_FAILURE);
}
diff --git a/src/playerData.c b/src/playerData.c
index 060227f4b..cbf18ff9f 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -131,6 +131,7 @@ void initPlayerData() {
buffered_chunks*sizeof(mpd_sint16));
buffer->times = (float *)(((char *)buffer->metaChunk)+
buffered_chunks*sizeof(mpd_sint8));
+ buffer->acceptMetadata = 0;
playerData_pd->playerControl.stop = 0;
playerData_pd->playerControl.pause = 0;
@@ -142,6 +143,7 @@ void initPlayerData() {
playerData_pd->playerControl.queueState = PLAYER_QUEUE_BLANK;
playerData_pd->playerControl.queueLockState = PLAYER_QUEUE_UNLOCKED;
playerData_pd->playerControl.seek = 0;
+ playerData_pd->playerControl.closeAudio = 0;
memset(playerData_pd->playerControl.utf8url, 0, MAXPATHLEN+1);
memset(playerData_pd->playerControl.erroredUrl, 0, MAXPATHLEN+1);
memset(playerData_pd->playerControl.currentUrl, 0, MAXPATHLEN+1);