aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-28 00:21:39 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-28 00:21:39 +0000
commitfa6f95685b8311be52e32aebc4ac86e8470b1fa3 (patch)
tree8e30c7e13d76124ccafd39a580dd048eb55d22bf /src
parent3e6a8042cadb03776e153aa1d7acab42b70d0c23 (diff)
downloadmpd-fa6f95685b8311be52e32aebc4ac86e8470b1fa3.tar.gz
mpd-fa6f95685b8311be52e32aebc4ac86e8470b1fa3.tar.xz
mpd-fa6f95685b8311be52e32aebc4ac86e8470b1fa3.zip
getting closer to being done with initial config file rewrite
git-svn-id: https://svn.musicpd.org/mpd/branches/shank-rewrite-config@2372 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/interface.c81
-rw-r--r--src/main.c26
-rw-r--r--src/permission.c57
-rw-r--r--src/playerData.c40
-rw-r--r--src/playlist.c54
6 files changed, 157 insertions, 103 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 92966240d..286166237 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,7 +55,6 @@ mpd_headers = \
mpd_SOURCES = \
$(mpd_headers) \
$(mpd_inputPlugins) \
- conf.c \
audio.c \
audioOutput.c \
audioOutput_ao.c \
@@ -63,6 +62,7 @@ mpd_SOURCES = \
buffer2array.c \
charConv.c \
command.c \
+ conf.c \
decode.c \
directory.c \
inputPlugin.c \
diff --git a/src/interface.c b/src/interface.c
index 196ff7706..4282b89be 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -47,12 +47,18 @@
#define INTERFACE_LIST_MODE_BEGIN "command_list_begin"
#define INTERFACE_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define INTERFACE_LIST_MODE_END "command_list_end"
-#define INTERFACE_DEFAULT_OUT_BUFFER_SIZE 4096
-
-int interface_max_connections = 0;
-int interface_timeout;
-unsigned long long interface_max_command_list_size;
-unsigned long long interface_max_output_buffer_size;
+#define INTERFACE_DEFAULT_OUT_BUFFER_SIZE 4096
+#define INTERFACE_TIMEOUT_DEFAULT 60
+#define INTERFACE_MAX_CONNECTIONS_DEFAULT 10
+#define INTERFACE_MAX_COMMAND_LIST_DEFAULT (2048*1024)
+#define INTERFACE_MAX_OUTPUT_BUFFER_SIZE_DEFAULT (2048*1024)
+
+static int interface_max_connections = INTERFACE_MAX_CONNECTIONS_DEFAULT;
+static int interface_timeout = INTERFACE_TIMEOUT_DEFAULT;
+static size_t interface_max_command_list_size =
+ INTERFACE_MAX_COMMAND_LIST_DEFAULT;
+static size_t interface_max_output_buffer_size =
+ INTERFACE_MAX_OUTPUT_BUFFER_SIZE_DEFAULT;
typedef struct _Interface {
char buffer[INTERFACE_MAX_BUFFER_LENGTH+2];
@@ -420,33 +426,58 @@ int doIOForInterfaces() {
void initInterfaces() {
int i;
char * test;
+ ConfigParam * param;
- interface_timeout = strtol((getConf())[CONF_CONNECTION_TIMEOUT],&test,10);
- if(*test!='\0' || interface_timeout<=0) {
- ERROR("connection timeout \"%s\" is not a positive integer\n",(getConf())[CONF_CONNECTION_TIMEOUT]);
- exit(EXIT_FAILURE);
- }
+ param = getConfigParam(CONF_CONN_TIMEOUT);
- interface_max_connections = strtol((getConf())[CONF_MAX_CONNECTIONS],&test,10);
- if(*test!='\0' || interface_max_connections<=0) {
- ERROR("max connections \"%s\" is not a positive integer\n",(getConf())[CONF_MAX_CONNECTIONS]);
- exit(EXIT_FAILURE);
+ if(param) {
+ interface_timeout = strtol(param->value,&test,10);
+ if(*test!='\0' || interface_timeout<=0) {
+ ERROR("connection timeout \"%s\" is not a positive "
+ "integer, line %i\n", CONF_CONN_TIMEOUT,
+ param->line);
+ exit(EXIT_FAILURE);
+ }
}
- interface_max_command_list_size = strtoll((getConf())[CONF_MAX_COMMAND_LIST_SIZE],&test,10);
- if(*test!='\0' || interface_max_command_list_size<=0) {
- ERROR("max command list size \"%s\" is not a positive integer\n",(getConf())[CONF_MAX_COMMAND_LIST_SIZE]);
- exit(EXIT_FAILURE);
+ param = getConfigParam(CONF_MAX_CONN);
+
+ if(param) {
+ interface_max_connections = strtol(param->value, &test, 10);
+ if(*test!='\0' || interface_max_connections<=0) {
+ ERROR("max connections \"%s\" is not a positive integer"
+ ", line %i\n", param->value, param->line);
+ exit(EXIT_FAILURE);
+ }
}
- interface_max_output_buffer_size = strtoll((getConf())[CONF_MAX_OUTPUT_BUFFER_SIZE],&test,10);
- if(*test!='\0' || interface_max_output_buffer_size<=0) {
- ERROR("max output buffer size \"%s\" is not a positive integer\n",(getConf())[CONF_MAX_OUTPUT_BUFFER_SIZE]);
- exit(EXIT_FAILURE);
+ param = getConfigParam(CONF_MAX_COMMAND_LIST_SIZE);
+
+ if(param) {
+ interface_max_command_list_size = strtoll(param->value,
+ &test, 10);
+ if(*test!='\0' || interface_max_command_list_size<=0) {
+ ERROR("max command list size \"%s\" is not a positive "
+ "integer, line %i\n", param->value,
+ param->line);
+ exit(EXIT_FAILURE);
+ }
+ interface_max_command_list_size*=1024;
}
- interface_max_command_list_size*=1024;
- interface_max_output_buffer_size*=1024;
+ param = getConfigParam(CONF_MAX_OUTPUT_BUFFER_SIZE);
+
+ if(param) {
+ interface_max_output_buffer_size = strtoll(param->value, &test,
+ 10);
+ if(*test!='\0' || interface_max_output_buffer_size<=0) {
+ ERROR("max output buffer size \"%s\" is not a positive "
+ "integer, line %i\n", param->value,
+ param->line);
+ exit(EXIT_FAILURE);
+ }
+ interface_max_output_buffer_size*=1024;
+ }
interfaces = malloc(sizeof(Interface)*interface_max_connections);
diff --git a/src/main.c b/src/main.c
index ddde281a7..a73d778cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -166,7 +166,7 @@ void parseOptions(int argc, char ** argv, Options * options) {
}
else if(argcLeft<=2) {
char ** conf = NULL;
- if(argcLeft==2) conf = readConf(argv[argc-1]);
+ if(argcLeft==2) readConf(argv[argc-1]);
if(argcLeft==1) {
FILE * fp;
char * homedir = getenv("HOME");
@@ -179,22 +179,26 @@ void parseOptions(int argc, char ** argv, Options * options) {
}
if(strlen(userfile) && (fp=fopen(userfile,"r"))) {
fclose(fp);
- conf = readConf(userfile);
+ readConf(userfile);
}
else if((fp=fopen(SYSTEM_CONFIG_FILE_LOCATION,"r"))) {
fclose(fp);
- conf = readConf(SYSTEM_CONFIG_FILE_LOCATION);
+ readConf(SYSTEM_CONFIG_FILE_LOCATION);
}
}
if(conf) {
- options->portStr = conf[CONF_PORT];
- options->musicDirArg = conf[CONF_MUSIC_DIRECTORY];
- options->playlistDirArg = conf[CONF_PLAYLIST_DIRECTORY];
- options->logFile = conf[CONF_LOG_FILE];
- options->errorFile = conf[CONF_ERROR_FILE];
- options->usr = conf[CONF_USER];
- if(conf[CONF_DB_FILE]) {
- options->dbFile = conf[CONF_DB_FILE];
+ options->portStr = getConfigParamValue(CONF_PORT);
+ options->musicDirArg =
+ getConfigParamValue(CONF_MUSIC_DIR);
+ options->playlistDirArg =
+ getConfigParamValue(CONF_PLAYLIST_DIR);
+ options->logFile = getConfigParamValue(CONF_LOG_FILE);
+ options->errorFile =
+ getConfigParamValue(CONF_ERROR_FILE);
+ options->usr = getConfigParamValue(CONF_USER);
+ if(getConfigParamValue(CONF_DB_FILE)) {
+ options->dbFile =
+ getConfigParamValue(CONF_DB_FILE);
}
return;
}
diff --git a/src/permission.c b/src/permission.c
index e9e74ad7a..795fe577d 100644
--- a/src/permission.c
+++ b/src/permission.c
@@ -69,56 +69,53 @@ unsigned int parsePermissions(char * string) {
}
void initPermissions() {
- char * passwordSets;
- char * nextSet;
char * temp;
- char * cp1;
char * cp2;
char * password;
unsigned int * permission;
+ ConfigParam * param;
permission_passwords = makeList(free);
permission_default = PERMISSION_READ | PERMISSION_ADD |
PERMISSION_CONTROL | PERMISSION_ADMIN;
- if(getConf()[CONF_DEFAULT_PERMISSIONS]) {
- permission_default = parsePermissions(
- getConf()[CONF_DEFAULT_PERMISSIONS]);
- }
-
- if(!getConf()[CONF_PASSWORD]) return;
-
- if(!getConf()[CONF_DEFAULT_PERMISSIONS]) permission_default = 0;
+ param = getNextConfigParam(CONF_PASSWORD, NULL);
- passwordSets = strdup(getConf()[CONF_PASSWORD]);
+ if(param) {
+ permission_default = 0;
- nextSet = strtok_r(passwordSets,CONF_CAT_CHAR,&cp1);
- while(nextSet && strlen(nextSet)) {
- if(!strstr(nextSet,PERMISSION_PASSWORD_CHAR)) {
- ERROR("\"%s\" not found in password string \"%s\"\n",
+ do {
+ if(!strstr(param->value, PERMISSION_PASSWORD_CHAR)) {
+ ERROR("\"%s\" not found in password string "
+ "\"%s\", line %i\n",
PERMISSION_PASSWORD_CHAR,
- nextSet);
- exit(EXIT_FAILURE);
- }
+ param->value,
+ param->line);
+ exit(EXIT_FAILURE);
+ }
- if(!(temp = strtok_r(nextSet,PERMISSION_PASSWORD_CHAR,&cp2))) {
- ERROR("something weird just happend in permission.c\n");
- exit(EXIT_FAILURE);
- }
- password = temp;
+ if(!(temp = strtok_r(param->value,
+ PERMISSION_PASSWORD_CHAR,&cp2))) {
+ ERROR("something weird just happend in permission.c\n");
+ exit(EXIT_FAILURE);
+ }
- permission = malloc(sizeof(unsigned int));
- *permission = parsePermissions(strtok_r(NULL,"",&cp2));
+
+ password = temp;
- insertInList(permission_passwords,password,permission);
+ permission = malloc(sizeof(unsigned int));
+ *permission = parsePermissions(strtok_r(NULL,"",&cp2));
- nextSet = strtok_r(NULL,CONF_CAT_CHAR,&cp1);
+ insertInList(permission_passwords,password,permission);
+ } while((param = getNextConfigParam(CONF_PASSWORD, param)));
}
- sortList(permission_passwords);
+ param = getConfigParam(CONF_DEFAULT_PERMS);
- free(passwordSets);
+ if(param) permission_default = parsePermissions(param->value);
+
+ sortList(permission_passwords);
}
int getPermissionFromPassword(char * password, unsigned int * permission) {
diff --git a/src/playerData.c b/src/playerData.c
index 5804f306c..b851a99f9 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -30,23 +30,32 @@
int buffered_before_play;
int buffered_chunks;
+#define DEFAULT_BUFFER_SIZE 2048
+#define DEFAULT_BUFFER_BEFORE_PLAY 25
+
PlayerData * playerData_pd;
void initPlayerData() {
- float perc;
+ float perc = DEFAULT_BUFFER_BEFORE_PLAY;
char * test;
int shmid;
int crossfade = 0;
- size_t bufferSize;
+ size_t bufferSize = DEFAULT_BUFFER_SIZE;
size_t allocationSize;
OutputBuffer * buffer;
+ ConfigParam * param;
- bufferSize = strtol(getConf()[CONF_BUFFER_SIZE],&test,10);
- if(*test!='\0' || bufferSize<=0) {
- ERROR("buffer size \"%s\" is not a positive integer\n",
- getConf()[CONF_BUFFER_SIZE]);
- exit(EXIT_FAILURE);
+ param = getConfigParam(CONF_AUDIO_BUFFER_SIZE);
+
+ if(param) {
+ bufferSize = strtol(param->value, &test, 10);
+ if(*test!='\0' || bufferSize<=0) {
+ ERROR("buffer size \"%s\" is not a positive integer, "
+ "line %i\n", param->value, param->line);
+ exit(EXIT_FAILURE);
+ }
}
+
bufferSize*=1024;
buffered_chunks = bufferSize/CHUNK_SIZE;
@@ -56,13 +65,18 @@ void initPlayerData() {
exit(EXIT_FAILURE);
}
- perc = strtod((getConf())[CONF_BUFFER_BEFORE_PLAY],&test);
- if(*test!='%' || perc<0 || perc>100) {
- ERROR("buffered before play \"%s\" is not a positive "
- "percentage and less than 100 percent\n",
- (getConf())[CONF_BUFFER_BEFORE_PLAY]);
- exit(EXIT_FAILURE);
+ param = getConfigParam(CONF_BUFFER_BEFORE_PLAY);
+
+ if(param) {
+ perc = strtod(param->value, &test);
+ if(*test!='%' || perc<0 || perc>100) {
+ ERROR("buffered before play \"%s\" is not a positive "
+ "percentage and less than 100 percent, line %i"
+ "\n", param->value, param->line);
+ exit(EXIT_FAILURE);
+ }
}
+
buffered_before_play = (perc/100)*buffered_chunks;
if(buffered_before_play>buffered_chunks) {
buffered_before_play = buffered_chunks;
diff --git a/src/playlist.c b/src/playlist.c
index fd1873f93..74bb56116 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -60,6 +60,9 @@
#define PLAYLIST_HASH_MULT 4
+#define DEFAULT_PLAYLIST_MAX_LENGTH (1024*16)
+#define DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS 0
+
typedef struct _Playlist {
Song ** songs;
/* holds version a song was modified on */
@@ -77,13 +80,13 @@ typedef struct _Playlist {
static Playlist playlist;
static int playlist_state = PLAYLIST_STATE_STOP;
-static int playlist_max_length;
+static int playlist_max_length = DEFAULT_PLAYLIST_MAX_LENGTH;
static int playlist_stopOnError;
static int playlist_errorCount = 0;
static int playlist_queueError;
static int playlist_noGoToNext = 0;
-static int playlist_saveAbsolutePaths;
+static int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
static char * playlist_stateFile = NULL;
@@ -128,6 +131,7 @@ static void incrPlaylistCurrent() {
void initPlaylist() {
char * test;
int i;
+ ConfigParam * param;
playlist.length = 0;
playlist.repeat = 0;
@@ -136,26 +140,32 @@ void initPlaylist() {
playlist.queued = -1;
playlist.current = -1;
- playlist_max_length = strtol((getConf())[CONF_MAX_PLAYLIST_LENGTH],&test,10);
- if(*test!='\0') {
- ERROR("max playlist length \"%s\" is not an integer\n",
- (getConf())[CONF_MAX_PLAYLIST_LENGTH]);
- exit(EXIT_FAILURE);
- }
+ param = getConfigParam(CONF_MAX_PLAYLIST_LENGTH);
- if(strcmp("yes",(getConf())[CONF_SAVE_ABSOLUTE_PATHS_IN_PLAYLISTS])
- ==0) {
- playlist_saveAbsolutePaths = 1;
- }
- else if(strcmp("no",(getConf())[CONF_SAVE_ABSOLUTE_PATHS_IN_PLAYLISTS])
- ==0) {
- playlist_saveAbsolutePaths = 0;
+ if(param) {
+ playlist_max_length = strtol(param->value, &test, 10);
+ if(*test!='\0') {
+ ERROR("max playlist length \"%s\" is not an integer, "
+ "line %i\n", param->value, param->line);
+ exit(EXIT_FAILURE);
+ }
}
- else {
- ERROR("save_absolute_paths_in_playlist \"%s\" is not yes or "
- "no\n",
- (getConf())[CONF_SAVE_ABSOLUTE_PATHS_IN_PLAYLISTS]);
- exit(EXIT_FAILURE);
+
+ param = getConfigParam(CONF_SAVE_ABSOLUTE_PATHS);
+
+ if(param) {
+ if(0 == strcmp("yes", param->value) ) {
+ playlist_saveAbsolutePaths = 1;
+ }
+ else if(0 == strcmp("no", param->value) ) {
+ playlist_saveAbsolutePaths = 0;
+ }
+ else {
+ ERROR("%s \"%s\" is not yes or no, line %i"
+ CONF_SAVE_ABSOLUTE_PATHS,
+ param->value, param->line);
+ exit(EXIT_FAILURE);
+ }
}
playlist.songs = malloc(sizeof(Song *)*playlist_max_length);
@@ -169,9 +179,7 @@ void initPlaylist() {
srand(time(NULL));
- if(getConf()[CONF_STATE_FILE]) {
- playlist_stateFile = getConf()[CONF_STATE_FILE];
- }
+ playlist_stateFile = getConfigParamValue(CONF_STATE_FILE);
for(i=0; i<playlist_max_length*PLAYLIST_HASH_MULT; i++) {
playlist.idToPosition[i] = -1;