MPD
conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_CONF_H
21 #define MPD_CONF_H
22 
23 #include <stdbool.h>
24 #include <glib.h>
25 
26 #define CONF_MUSIC_DIR "music_directory"
27 #define CONF_PLAYLIST_DIR "playlist_directory"
28 #define CONF_FOLLOW_INSIDE_SYMLINKS "follow_inside_symlinks"
29 #define CONF_FOLLOW_OUTSIDE_SYMLINKS "follow_outside_symlinks"
30 #define CONF_DB_FILE "db_file"
31 #define CONF_STICKER_FILE "sticker_file"
32 #define CONF_LOG_FILE "log_file"
33 #define CONF_PID_FILE "pid_file"
34 #define CONF_STATE_FILE "state_file"
35 #define CONF_USER "user"
36 #define CONF_GROUP "group"
37 #define CONF_BIND_TO_ADDRESS "bind_to_address"
38 #define CONF_PORT "port"
39 #define CONF_LOG_LEVEL "log_level"
40 #define CONF_ZEROCONF_NAME "zeroconf_name"
41 #define CONF_ZEROCONF_ENABLED "zeroconf_enabled"
42 #define CONF_PASSWORD "password"
43 #define CONF_DEFAULT_PERMS "default_permissions"
44 #define CONF_AUDIO_OUTPUT "audio_output"
45 #define CONF_AUDIO_FILTER "filter"
46 #define CONF_AUDIO_OUTPUT_FORMAT "audio_output_format"
47 #define CONF_MIXER_TYPE "mixer_type"
48 #define CONF_REPLAYGAIN "replaygain"
49 #define CONF_REPLAYGAIN_PREAMP "replaygain_preamp"
50 #define CONF_REPLAYGAIN_MISSING_PREAMP "replaygain_missing_preamp"
51 #define CONF_REPLAYGAIN_LIMIT "replaygain_limit"
52 #define CONF_VOLUME_NORMALIZATION "volume_normalization"
53 #define CONF_SAMPLERATE_CONVERTER "samplerate_converter"
54 #define CONF_AUDIO_BUFFER_SIZE "audio_buffer_size"
55 #define CONF_BUFFER_BEFORE_PLAY "buffer_before_play"
56 #define CONF_HTTP_PROXY_HOST "http_proxy_host"
57 #define CONF_HTTP_PROXY_PORT "http_proxy_port"
58 #define CONF_HTTP_PROXY_USER "http_proxy_user"
59 #define CONF_HTTP_PROXY_PASSWORD "http_proxy_password"
60 #define CONF_CONN_TIMEOUT "connection_timeout"
61 #define CONF_MAX_CONN "max_connections"
62 #define CONF_MAX_PLAYLIST_LENGTH "max_playlist_length"
63 #define CONF_MAX_COMMAND_LIST_SIZE "max_command_list_size"
64 #define CONF_MAX_OUTPUT_BUFFER_SIZE "max_output_buffer_size"
65 #define CONF_FS_CHARSET "filesystem_charset"
66 #define CONF_ID3V1_ENCODING "id3v1_encoding"
67 #define CONF_METADATA_TO_USE "metadata_to_use"
68 #define CONF_SAVE_ABSOLUTE_PATHS "save_absolute_paths_in_playlists"
69 #define CONF_DECODER "decoder"
70 #define CONF_INPUT "input"
71 #define CONF_GAPLESS_MP3_PLAYBACK "gapless_mp3_playback"
72 #define CONF_PLAYLIST_PLUGIN "playlist_plugin"
73 #define CONF_AUTO_UPDATE "auto_update"
74 #define CONF_AUTO_UPDATE_DEPTH "auto_update_depth"
75 
76 #define DEFAULT_PLAYLIST_MAX_LENGTH (1024*16)
77 #define DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS false
78 
79 #define MAX_FILTER_CHAIN_LENGTH 255
80 
81 struct block_param {
82  char *name;
83  char *value;
84  int line;
85 
90  bool used;
91 };
92 
93 struct config_param {
94  char *value;
95  unsigned int line;
96 
98  unsigned num_block_params;
99 
104  bool used;
105 };
106 
111 static inline GQuark
113 {
114  return g_quark_from_static_string("config");
115 }
116 
117 void config_global_init(void);
118 void config_global_finish(void);
119 
124 void config_global_check(void);
125 
126 bool
127 config_read_file(const char *file, GError **error_r);
128 
129 /* don't free the returned value
130  set _last_ to NULL to get first entry */
131 G_GNUC_PURE
132 struct config_param *
133 config_get_next_param(const char *name, const struct config_param *last);
134 
135 G_GNUC_PURE
136 static inline struct config_param *
137 config_get_param(const char *name)
138 {
139  return config_get_next_param(name, NULL);
140 }
141 
142 /* Note on G_GNUC_PURE: Some of the functions declared pure are not
143  really pure in strict sense. They have side effect such that they
144  validate parameter's value and signal an error if it's invalid.
145  However, if the argument was already validated or we don't care
146  about the argument at all, this may be ignored so in the end, we
147  should be fine with calling those functions pure. */
148 
149 G_GNUC_PURE
150 const char *
151 config_get_string(const char *name, const char *default_value);
152 
158 /* We lie here really. This function is not pure as it has side
159  effects -- it parse the value and creates new string freeing
160  previous one. However, because this works the very same way each
161  time (ie. from the outside it appears as if function had no side
162  effects) we should be in the clear declaring it pure. */
163 G_GNUC_PURE
164 const char *
165 config_get_path(const char *name);
166 
167 G_GNUC_PURE
168 unsigned
169 config_get_unsigned(const char *name, unsigned default_value);
170 
171 G_GNUC_PURE
172 unsigned
173 config_get_positive(const char *name, unsigned default_value);
174 
175 G_GNUC_PURE
176 struct block_param *
177 config_get_block_param(const struct config_param *param, const char *name);
178 
179 G_GNUC_PURE
180 bool config_get_bool(const char *name, bool default_value);
181 
182 G_GNUC_PURE
183 const char *
184 config_get_block_string(const struct config_param *param, const char *name,
185  const char *default_value);
186 
187 static inline char *
188 config_dup_block_string(const struct config_param *param, const char *name,
189  const char *default_value)
190 {
191  return g_strdup(config_get_block_string(param, name, default_value));
192 }
193 
194 G_GNUC_PURE
195 unsigned
196 config_get_block_unsigned(const struct config_param *param, const char *name,
197  unsigned default_value);
198 
199 G_GNUC_PURE
200 bool
201 config_get_block_bool(const struct config_param *param, const char *name,
202  bool default_value);
203 
204 struct config_param *
205 config_new_param(const char *value, int line);
206 
207 bool
208 config_add_block_param(struct config_param * param, const char *name,
209  const char *value, int line, GError **error_r);
210 
211 #endif