aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-27 22:40:59 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-27 22:40:59 +0000
commit6237195faba7064df2496d410d9a615471b65807 (patch)
tree37a7ac1de869f12091c9d345fe5ff3972b8729b6
parentc5310c33f54603d623b76fa5eb4f19edeb25be77 (diff)
downloadmpd-6237195faba7064df2496d410d9a615471b65807.tar.gz
mpd-6237195faba7064df2496d410d9a615471b65807.tar.xz
mpd-6237195faba7064df2496d410d9a615471b65807.zip
more config file rewrite actions happening
git-svn-id: https://svn.musicpd.org/mpd/branches/shank-rewrite-config@2364 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/audio.c107
-rw-r--r--src/audioOutput.c40
-rw-r--r--src/audioOutput.h8
-rw-r--r--src/audioOutput_ao.c41
-rw-r--r--src/conf.c177
-rw-r--r--src/conf.h4
6 files changed, 235 insertions, 142 deletions
diff --git a/src/audio.c b/src/audio.c
index 653fb55f5..7f04ea2df 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -31,9 +31,6 @@ static AudioFormat audio_format;
static AudioFormat * audio_configFormat = NULL;
-static AudioOutput * aoOutput = NULL;
-static AudioOutput * shoutOutput = NULL;
-
void copyAudioFormat(AudioFormat * dest, AudioFormat * src) {
if(!src) return;
@@ -42,17 +39,34 @@ void copyAudioFormat(AudioFormat * dest, AudioFormat * src) {
dest->channels = src->channels;
}
+static AudioOutput ** audioOutputArray = NULL;
+static int audioOutputArraySize = 0;
+
extern AudioOutputPlugin aoPlugin;
extern AudioOutputPlugin shoutPlugin;
void initAudioDriver() {
+ ConfigParam * param = NULL;
+ int i;
+
initAudioOutputPlugins();
loadAudioOutputPlugin(&aoPlugin);
loadAudioOutputPlugin(&shoutPlugin);
- aoOutput = newAudioOutput("ao");
- assert(aoOutput);
- shoutOutput = newAudioOutput("shout");
+ while((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param))) {
+ i = audioOutputArraySize++;
+
+ audioOutputArray = realloc(audioOutputArray,
+ audioOutputArraySize*sizeof(AudioOutput *));
+
+ audioOutputArray[i] = newAudioOutput(param);
+
+ if(!audioOutputArray[i]) {
+ ERROR("problems configuring output device defined at "
+ "line %i\n", param->line);
+ exit(EXIT_FAILURE);
+ }
+ }
}
void getOutputAudioFormat(AudioFormat * inAudioFormat,
@@ -65,13 +79,17 @@ void getOutputAudioFormat(AudioFormat * inAudioFormat,
}
void initAudioConfig() {
- char * conf = getConf()[CONF_AUDIO_OUTPUT_FORMAT];
+ ConfigParam * param = getConfigParam(CONF_AUDIO_OUTPUT_FORMAT);
- if(NULL == conf) return;
+ if(NULL == param || NULL == param->value) return;
audio_configFormat = malloc(sizeof(AudioFormat));
- if(0 != parseAudioConfig(audio_configFormat, conf)) exit(EXIT_FAILURE);
+ if(0 != parseAudioConfig(audio_configFormat, param->value)) {
+ ERROR("error parsing \"%s\" at line %i\n",
+ CONF_AUDIO_OUTPUT_FORMAT, param->line);
+ exit(EXIT_FAILURE);
+ }
}
int parseAudioConfig(AudioFormat * audioFormat, char * conf) {
@@ -145,10 +163,15 @@ void finishAudioConfig() {
}
void finishAudioDriver() {
- finishAudioOutput(aoOutput);
- if(shoutOutput) finishAudioOutput(shoutOutput);
- shoutOutput = NULL;
- aoOutput = NULL;
+ int i;
+
+ for(i = 0; i < audioOutputArraySize; i++) {
+ finishAudioOutput(audioOutputArray[i]);
+ }
+
+ free(audioOutputArray);
+ audioOutputArray = NULL;
+ audioOutputArraySize = 0;
}
int isCurrentAudioFormat(AudioFormat * audioFormat) {
@@ -160,29 +183,65 @@ int isCurrentAudioFormat(AudioFormat * audioFormat) {
}
int openAudioDevice(AudioFormat * audioFormat) {
- if(!aoOutput->open || !isCurrentAudioFormat(audioFormat)) {
- if(audioFormat) copyAudioFormat(&audio_format, audioFormat);
- if(shoutOutput) openAudioOutput(shoutOutput, &audio_format);
- return openAudioOutput(aoOutput, &audio_format);
+ int isCurrentFormat = isCurrentAudioFormat(audioFormat);
+ int ret = -1;
+ int i;
+
+ if(!audioOutputArray) return -1;
+
+ if(!isCurrentFormat) {
+ copyAudioFormat(&audio_format, audioFormat);
}
- return 0;
+ for(i = 0; i < audioOutputArraySize; i++) {
+ if(!audioOutputArray[i]->open || !isCurrentFormat) {
+ if(0 == openAudioOutput(audioOutputArray[i],
+ &audio_format))
+ {
+ ret = 0;
+ }
+ }
+ }
+
+ return ret;
}
int playAudio(char * playChunk, int size) {
- if(shoutOutput) playAudioOutput(shoutOutput, playChunk, size);
- return playAudioOutput(aoOutput, playChunk, size);
+ int ret = -1;
+ int i;
+
+ for(i = 0; i < audioOutputArraySize; i++) {
+ if(0 == playAudioOutput(audioOutputArray[i], playChunk, size)) {
+ ret = 0;
+ }
+ }
+
+ return ret;
}
int isAudioDeviceOpen() {
- return aoOutput->open;
+ int ret = 0;
+ int i;
+
+ for(i = 0; i < audioOutputArraySize; i++) {
+ ret &= audioOutputArray[i]->open;
+ }
+
+ return ret;
}
void closeAudioDevice() {
- if(shoutOutput) closeAudioOutput(shoutOutput);
- closeAudioOutput(aoOutput);
+ int i;
+
+ for(i = 0; i < audioOutputArraySize; i++) {
+ closeAudioOutput(audioOutputArray[i]);
+ }
}
void sendMetadataToAudioDevice(MpdTag * tag) {
- if(shoutOutput) sendMetadataToAudioOutput(shoutOutput, tag);
+ int i;
+
+ for(i = 0; i < audioOutputArraySize; i++) {
+ sendMetadataToAudioOutput(audioOutputArray[i], tag);
+ }
}
diff --git a/src/audioOutput.c b/src/audioOutput.c
index d85b9d978..0175ed04f 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -1,6 +1,12 @@
-#include <audioOutput.h>
+#include "audioOutput.h"
-#include <list.h>
+#include "list.h"
+#include "log.h"
+
+#include <string.h>
+
+#define AUDIO_OUTPUT_TYPE "type"
+#define AUDIO_OUTPUT_NAME "name"
static List * audioOutputPluginList;
@@ -21,13 +27,32 @@ void finishAudioOutputPlugins() {
freeList(audioOutputPluginList);
}
-AudioOutput * newAudioOutput(char * name) {
+#define getBlockParam(name, str) { \
+ BlockParam * bp; \
+ bp = getBlockParam(param, name); \
+ if(bp == NULL) { \
+ ERROR("couldn't find parameter \"%s\" in audio output " \
+ "definition begining at %i\n", \
+ name, param->line); \
+ exit(EXIT_FAILURE); \
+ } \
+ str = bp->value; \
+}
+
+AudioOutput * newAudioOutput(ConfigParam * param) {
AudioOutput * ret = NULL;
void * data = NULL;
+ char * name = NULL;
+ char * type = NULL;
+
+ getBlockParam(AUDIO_OUTPUT_NAME, name);
+ getBlockParam(AUDIO_OUTPUT_TYPE, type);
- if(findInList(audioOutputPluginList, name, &data)) {
+ if(findInList(audioOutputPluginList, type, &data)) {
AudioOutputPlugin * plugin = (AudioOutputPlugin *) data;
ret = malloc(sizeof(AudioOutput));
+ ret->name = strdup(name);
+ ret->type = strdup(type);
ret->finishDriverFunc = plugin->finishDriverFunc;
ret->openDeviceFunc = plugin->openDeviceFunc;
ret->playFunc = plugin->playFunc;
@@ -35,11 +60,16 @@ AudioOutput * newAudioOutput(char * name) {
ret->sendMetdataFunc = plugin->sendMetdataFunc;
ret->open = 0;
- if(plugin->initDriverFunc(ret) != 0) {
+ if(plugin->initDriverFunc(ret, param) != 0) {
free(ret);
ret = NULL;
}
}
+ else {
+ ERROR("couldn't find audio output plugin for type \"%s\" at "
+ "line %i", type, param->line);
+ exit(EXIT_FAILURE);
+ }
return ret;
}
diff --git a/src/audioOutput.h b/src/audioOutput.h
index ec43e9e7c..49c7110f9 100644
--- a/src/audioOutput.h
+++ b/src/audioOutput.h
@@ -24,12 +24,14 @@
#include "mpd_types.h"
#include "audio.h"
#include "tag.h"
+#include "conf.h"
#define AUDIO_AO_DRIVER_DEFAULT "default"
typedef struct _AudioOutput AudioOutput;
-typedef int (* AudioOutputInitDriverFunc) (AudioOutput * audioOutput);
+typedef int (* AudioOutputInitDriverFunc) (AudioOutput * audioOutput,
+ ConfigParam * param);
typedef void (* AudioOutputFinishDriverFunc) (AudioOutput * audioOutput);
@@ -46,6 +48,8 @@ typedef void (* AudioOutputSendMetadataFunc) (AudioOutput * audioOutput,
struct _AudioOutput {
int open;
+ char * name;
+ char * type;
AudioOutputFinishDriverFunc finishDriverFunc;
AudioOutputOpenDeviceFunc openDeviceFunc;
@@ -73,7 +77,7 @@ void finishAudioOutputPlugins();
void loadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin);
void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin);
-AudioOutput * newAudioOutput(char * name);
+AudioOutput * newAudioOutput(ConfigParam * param);
int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat);
int playAudioOutput(AudioOutput * audioOutput, char * playChunk, int size);
void closeAudioOutput(AudioOutput * audioOutput);
diff --git a/src/audioOutput_ao.c b/src/audioOutput_ao.c
index 7c997c99e..60c4ea402 100644
--- a/src/audioOutput_ao.c
+++ b/src/audioOutput_ao.c
@@ -56,7 +56,9 @@ static void audioOutputAo_error() {
}
}
-static int audioOutputAo_initDriver(AudioOutput * audioOutput) {
+static int audioOutputAo_initDriver(AudioOutput * audioOutput,
+ ConfigParam * param)
+{
ao_info * ai;
char * dup;
char * stk1;
@@ -66,38 +68,51 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput) {
char * value;
char * test;
AoData * ad = newAoData();
+ BlockParam * blockParam;
audioOutput->data = ad;
- ad->writeSize = strtol((getConf())[CONF_AUDIO_WRITE_SIZE],&test,10);
- if (*test!='\0') {
- ERROR("\"%s\" is not a valid write size\n",
- (getConf())[CONF_AUDIO_WRITE_SIZE]);
- exit(EXIT_FAILURE);
+ if((blockParam = getBlockParam(param, "write_size"))) {
+ ad->writeSize = strtol(blockParam->value, &test, 10);
+ if (*test!='\0') {
+ ERROR("\"%s\" is not a valid write size at line %i\n",
+ blockParam->value, blockParam->line);
+ exit(EXIT_FAILURE);
+ }
}
+ else ad->writeSize = 1024;
if(driverInitCount == 0) {
ao_initialize();
}
driverInitCount++;
-
- if(strcmp(AUDIO_AO_DRIVER_DEFAULT,(getConf())[CONF_AO_DRIVER])==0) {
+
+ blockParam = getBlockParam(param, "driver");
+
+ if(!blockParam || 0 == strcmp(blockParam->value,"default")) {
ad->driverId = ao_default_driver_id();
}
else if((ad->driverId =
- ao_driver_id((getConf())[CONF_AO_DRIVER]))<0) {
- ERROR("\"%s\" is not a valid ao driver\n",
- (getConf())[CONF_AO_DRIVER]);
+ ao_driver_id(blockParam->value))<0) {
+ ERROR("\"%s\" is not a valid ao driver at line %i\n",
+ blockParam->value, blockParam->line);
exit(EXIT_FAILURE);
}
if((ai = ao_driver_info(ad->driverId))==NULL) {
- ERROR("problems getting ao_driver_info\n");
+ ERROR("problems getting driver info for device defined at "
+ "line %i\n", param->line);
ERROR("you may not have permission to the audio device\n");
exit(EXIT_FAILURE);
}
- dup = strdup((getConf())[CONF_AO_DRIVER_OPTIONS]);
+ blockParam = getBlockParam(param, "options");
+
+ if(blockParam) {
+ dup = strdup(blockParam->value);
+ }
+ else dup = strdup("");
+
if(strlen(dup)) {
stk1 = NULL;
n1 = strtok_r(dup,";",&stk1);
diff --git a/src/conf.c b/src/conf.c
index a00a02caa..32f3f57a7 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -48,25 +48,13 @@ typedef struct _configEntry {
static List * configEntriesList = NULL;
-static BlockParam * newBlockParam(char * name, char * value) {
- BlockParam * ret = malloc(sizeof(BlockParam));
-
- ret->name = strdup(name);
- ret->value = strdup(value);
-
- return ret;
-}
-
-static void freeBlockParam(BlockParam * param) {
- free(param->name);
- free(param->value);
- free(param);
-}
-
-static ConfigParam * newConfigParam(char * value) {
+static ConfigParam * newConfigParam(char * value, int line) {
ConfigParam * ret = malloc(sizeof(ConfigParam));
- if(value) ret->value = NULL;
+ if(!value) ret->value = NULL;
+ else ret->value = strdup(value);
+
+ ret->line = line;
ret->numberOfBlockParams = 0;
ret->blockParams = NULL;
@@ -77,12 +65,19 @@ static ConfigParam * newConfigParam(char * value) {
static void freeConfigParam(ConfigParam * param) {
int i;
- free(param->value);
+ if(param->value) free(param->value);
for(i=0; i<param->numberOfBlockParams; i++) {
- freeBlockParam(param->blockParams+i);
+ if(param->blockParams[i].name) {
+ free(param->blockParams[i].name);
+ }
+ if(param->blockParams[i].value) {
+ free(param->blockParams[i].value);
+ }
}
+ if(param->numberOfBlockParams) free(param->blockParams);
+
free(param);
}
@@ -155,9 +150,22 @@ void initConf() {
registerConfigParam(CONF_ID3V1_ENCODING, 0, 0);
}
-ConfigParam * readConfigBlock(FILE * fp, int * count, char * string,
- char * name, char * value)
+static void addBlockParam(ConfigParam * param, char * name, char * value,
+ int line)
{
+ param->numberOfBlockParams++;
+
+ param->blockParams = realloc(param->blockParams,
+ param->numberOfBlockParams*sizeof(BlockParam));
+
+ param->blockParams[param->numberOfBlockParams-1].name = strdup(name);
+ param->blockParams[param->numberOfBlockParams-1].value = strdup(value);
+ param->blockParams[param->numberOfBlockParams-1].line = line;
+}
+
+static ConfigParam * readConfigBlock(FILE * fp, int * count, char * string) {
+ ConfigParam * ret = newConfigParam(NULL, *count);
+
char ** array;
int i;
int numberOfArgs;
@@ -176,39 +184,35 @@ ConfigParam * readConfigBlock(FILE * fp, int * count, char * string,
if(0 == argsMinusComment) continue;
+ if(1 == argsMinusComment &&
+ 0 == strcmp(array[0], CONF_BLOCK_END))
+ {
+ break;
+ }
+
if(2 != argsMinusComment) {
ERROR("improperly formated config file at line %i:"
" %s\n", count, string);
exit(EXIT_FAILURE);
}
- if(!findInList(configEntriesList, array[0], &voidPtr)) {
- ERROR("unrecognized paramater in config file at line "
- "%i: %s\n", count, string);
- exit(EXIT_FAILURE);
- }
-
- entry = (ConfigEntry *) voidPtr;
-
- if( !(entry->mask & CONF_REPEATABLE_MASK) &&
- entry->configParamList->numberOfNodes)
+ if(0 == strcmp(array[0], CONF_BLOCK_BEGIN) ||
+ 0 == strcmp(array[1], CONF_BLOCK_BEGIN) ||
+ 0 == strcmp(array[0], CONF_BLOCK_END) ||
+ 0 == strcmp(array[1], CONF_BLOCK_END))
{
- param = entry->configParamList->firstNode->data;
- ERROR("config paramter \"%s\" is first defined on line "
- "%i and redefined on line %i\n",
- array[0], param->line, count);
+ ERROR("improperly formated config file at line %i:"
+ " %s\n", count, string);
+ ERROR("in block begging at line %i\n", ret->line);
exit(EXIT_FAILURE);
}
- if(entry->mask & CONF_BLOCK_MASK) {
- param = readConfigBlock(fp, &count, string, array[0], array[1]);
- }
- else param = newConfigParam(array[1]);
-
- addConfigParamToEntry(entry, param);
+ addBlockParam(ret, array[0], array[1], *count);
- freeArgArray(&array, numberOfArgs);
+ freeArgArray(array, numberOfArgs);
}
+
+ return ret;
}
void readConf(char * file) {
@@ -266,65 +270,49 @@ void readConf(char * file) {
}
if(entry->mask & CONF_BLOCK_MASK) {
- param = readConfigBlock(fp, &count, string, array[0], array[1]);
- }
- else {
+ if(0 != strcmp(array[1], CONF_BLOCK_BEGIN)) {
+ ERROR("improperly formated config file at "
+ "line %i: %s\n", count, string);
+ exit(EXIT_FAILURE);
+ }
+ param = readConfigBlock(fp, &count, string);
}
+ else param = newConfigParam(array[1], count);
- freeArgArray(&array, numberOfArgs);
+ insertInListWithoutKey(entry->configParamList, param);
+
+ freeArgArray(array, numberOfArgs);
}
}
+ConfigParam * getNextConfigParam(char * name, ConfigParam * last) {
+ void * voidPtr;
+ ConfigEntry * entry;
+ ListNode * node;
+ ConfigParam * param;
-//////// OLD CODE
- while(myFgets(string,sizeof(string),fp)) {
- count++;
+ if(!findInList(configEntriesList, name, &voidPtr)) return NULL;
- if(string[0]==CONF_COMMENT) continue;
- numberOfArgs = buffer2array(string,&array);
- if(numberOfArgs==0) continue;
- if(2!=numberOfArgs) {
- ERROR("improperly formated config file at line %i: %s\n",count,string);
- exit(EXIT_FAILURE);
- }
- i = 0;
- while(i<CONF_NUMBER_OF_PARAMS && 0!=strcmp(conf_strings[i],array[0])) i++;
- if(i>=CONF_NUMBER_OF_PARAMS) {
- ERROR("unrecognized paramater in conf at line %i: %s\n",count,string);
- exit(EXIT_FAILURE);
- }
-
- if(conf_params[i]!=NULL) {
- if(allowCat[i]) {
- conf_params[i] = realloc(conf_params[i],
- strlen(conf_params[i])+
- strlen(CONF_CAT_CHAR)+
- strlen(array[1])+1);
- strcat(conf_params[i],CONF_CAT_CHAR);
- strcat(conf_params[i],array[1]);
- }
- else {
- free(conf_params[i]);
- conf_params[i] = strdup(array[1]);
- }
- }
- else conf_params[i] = strdup(array[1]);
- free(array[0]);
- free(array[1]);
- free(array);
- }
+ entry = voidPtr;
- fclose(fp);
+ node = entry->configParamList->firstNode;
- for(i=0;i<CONF_NUMBER_OF_REQUIRED;i++) {
- if(conf_params[conf_required[i]] == NULL) {
- ERROR("%s is unassigned in conf file\n",
- conf_strings[conf_required[i]]);
- exit(EXIT_FAILURE);
+ if(last) {
+ while(node!=NULL) {
+ param = node->data;
+ node = node->nextNode;
+ if(param == last) break;
}
}
- for(i=0;i<CONF_NUMBER_OF_PATHS;i++) {
+ if(node == NULL) return NULL;
+
+ param = node->data;
+
+ return param;
+}
+
+ /*for(i=0;i<CONF_NUMBER_OF_PATHS;i++) {
if(conf_params[conf_absolutePaths[i]] &&
conf_params[conf_absolutePaths[i]][0]!='/' &&
conf_params[conf_absolutePaths[i]][0]!='~')
@@ -333,7 +321,7 @@ void readConf(char * file) {
conf_params[conf_absolutePaths[i]]);
exit(EXIT_FAILURE);
}
- /* Parse ~ in path */
+ // Parse ~ in path
else if(conf_params[conf_absolutePaths[i]] &&
conf_params[conf_absolutePaths[i]][0]=='~')
{
@@ -391,11 +379,4 @@ void readConf(char * file) {
free(conf_params[conf_absolutePaths[i]]);
conf_params[conf_absolutePaths[i]] = path;
}
- }
-
- return conf_params;
-}
-
-char ** getConf() {
- return conf_params;
-}
+ }*/
diff --git a/src/conf.h b/src/conf.h
index eba5e47da..e3e1fb7b9 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -77,6 +77,10 @@ void readConf(char * file);
set _last_ to NULL to get first entry */
ConfigParam * getNextConfigParam(char * name, ConfigParam * last);
+#define getConfigParam(name) getNextConfigParam(name, NULL);
+
void registerConfigParam(char * name, int repeats, int block);
+BlockParam * getBlockParam(ConfigParam * param, char * name);
+
#endif