This repository has been archived by the owner on Jun 17, 2019. It is now read-only.
/
config_manager.h
394 lines (346 loc) · 14.7 KB
/
config_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*MT*
MediaTomb - http://www.mediatomb.cc/
config_manager.h - this file is part of MediaTomb.
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
Copyright (C) 2006-2009 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>
MediaTomb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
MediaTomb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
version 2 along with MediaTomb; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
$Id$
*/
/// \file config_manager.h
///\brief Definitions of the ConfigManager class.
#ifndef __CONFIG_MANAGER_H__
#define __CONFIG_MANAGER_H__
#include "common.h"
#include "mxml/mxml.h"
#include "singleton.h"
#include "dictionary.h"
#include "object_dictionary.h"
#include "xpath.h"
#include "autoscan.h"
#include "config_options.h"
#ifdef EXTERNAL_TRANSCODING
#include "transcoding/transcoding.h"
#endif
#ifdef ONLINE_SERVICES
#include "online_service.h"
#endif
typedef enum
{
CFG_SERVER_PORT = 0,
CFG_SERVER_IP,
CFG_SERVER_NETWORK_INTERFACE,
CFG_SERVER_NAME,
CFG_SERVER_MANUFACTURER_URL,
CFG_SERVER_MODEL_NAME,
CFG_SERVER_MODEL_DESCRIPTION,
CFG_SERVER_MODEL_NUMBER,
CFG_SERVER_SERIAL_NUMBER,
CFG_SERVER_PRESENTATION_URL,
CFG_SERVER_APPEND_PRESENTATION_URL_TO,
CFG_SERVER_UDN,
CFG_SERVER_HOME,
CFG_SERVER_TMPDIR,
CFG_SERVER_WEBROOT,
CFG_SERVER_SERVEDIR,
CFG_SERVER_ALIVE_INTERVAL,
#ifdef EXTEND_PROTOCOLINFO
CFG_SERVER_EXTEND_PROTOCOLINFO,
#ifdef EXTERNAL_TRANSCODING
CFG_SERVER_EXTEND_PROTOCOLINFO_CL_HACK,
#endif
#endif//EXTEND_PROTOCOLINFO
CFG_SERVER_HIDE_PC_DIRECTORY,
CFG_SERVER_BOOKMARK_FILE,
CFG_SERVER_CUSTOM_HTTP_HEADERS,
CFG_SERVER_UPNP_TITLE_AND_DESC_STRING_LIMIT,
CFG_SERVER_UI_ENABLED,
CFG_SERVER_UI_POLL_INTERVAL,
CFG_SERVER_UI_POLL_WHEN_IDLE,
CFG_SERVER_UI_ACCOUNTS_ENABLED,
CFG_SERVER_UI_ACCOUNT_LIST,
CFG_SERVER_UI_SESSION_TIMEOUT,
CFG_SERVER_UI_DEFAULT_ITEMS_PER_PAGE,
CFG_SERVER_UI_ITEMS_PER_PAGE_DROPDOWN,
CFG_SERVER_UI_SHOW_TOOLTIPS,
CFG_SERVER_STORAGE_DRIVER,
CFG_SERVER_STORAGE_CACHING_ENABLED,
#ifdef HAVE_SQLITE3
CFG_SERVER_STORAGE_SQLITE_DATABASE_FILE,
CFG_SERVER_STORAGE_SQLITE_SYNCHRONOUS,
CFG_SERVER_STORAGE_SQLITE_RESTORE,
CFG_SERVER_STORAGE_SQLITE_BACKUP_ENABLED,
CFG_SERVER_STORAGE_SQLITE_BACKUP_INTERVAL,
#endif
#ifdef HAVE_MYSQL
CFG_SERVER_STORAGE_MYSQL_HOST,
CFG_SERVER_STORAGE_MYSQL_PORT,
CFG_SERVER_STORAGE_MYSQL_USERNAME,
CFG_SERVER_STORAGE_MYSQL_SOCKET,
CFG_SERVER_STORAGE_MYSQL_PASSWORD,
CFG_SERVER_STORAGE_MYSQL_DATABASE,
#endif
#if defined(HAVE_FFMPEG) && defined(HAVE_FFMPEGTHUMBNAILER)
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_ENABLED,
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_THUMBSIZE,
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_SEEK_PERCENTAGE,
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_FILMSTRIP_OVERLAY,
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_WORKAROUND_BUGS,
CFG_SERVER_EXTOPTS_FFMPEGTHUMBNAILER_IMAGE_QUALITY,
#endif
CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_ENABLED,
CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_STRING_MODE_PREPEND,
CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_STRING,
CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_SUPPRESS_CDS_UPDATES,
CFG_SERVER_EXTOPTS_MARK_PLAYED_ITEMS_CONTENT_LIST,
#ifdef HAVE_LASTFMLIB
CFG_SERVER_EXTOPTS_LASTFM_ENABLED,
CFG_SERVER_EXTOPTS_LASTFM_USERNAME,
CFG_SERVER_EXTOPTS_LASTFM_PASSWORD,
#endif
CFG_IMPORT_HIDDEN_FILES,
CFG_IMPORT_FILESYSTEM_CHARSET,
CFG_IMPORT_METADATA_CHARSET,
CFG_IMPORT_PLAYLIST_CHARSET,
#ifdef HAVE_JS
CFG_IMPORT_SCRIPTING_CHARSET,
CFG_IMPORT_SCRIPTING_COMMON_SCRIPT,
CFG_IMPORT_SCRIPTING_PLAYLIST_SCRIPT,
CFG_IMPORT_SCRIPTING_PLAYLIST_SCRIPT_LINK_OBJECTS,
CFG_IMPORT_SCRIPTING_IMPORT_SCRIPT,
#ifdef HAVE_LIBDVDNAV
CFG_IMPORT_SCRIPTING_DVD_SCRIPT,
#endif
#endif // JS
CFG_IMPORT_SCRIPTING_VIRTUAL_LAYOUT_TYPE,
#ifdef HAVE_MAGIC
CFG_IMPORT_MAGIC_FILE,
#endif
CFG_IMPORT_AUTOSCAN_TIMED_LIST,
#ifdef HAVE_INOTIFY
CFG_IMPORT_AUTOSCAN_USE_INOTIFY,
CFG_IMPORT_AUTOSCAN_INOTIFY_LIST,
#endif
CFG_IMPORT_MAPPINGS_IGNORE_UNKNOWN_EXTENSIONS,
CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_CASE_SENSITIVE,
CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_LIST,
CFG_IMPORT_MAPPINGS_MIMETYPE_TO_UPNP_CLASS_LIST,
CFG_IMPORT_MAPPINGS_MIMETYPE_TO_CONTENTTYPE_LIST,
#ifdef HAVE_LIBEXIF
CFG_IMPORT_LIBOPTS_EXIF_AUXDATA_TAGS_LIST,
#endif
#ifdef HAVE_LIBEXTRACTOR
CFG_IMPORT_LIBOPTS_EXTRACTOR_AUXDATA_TAGS_LIST,
#endif
#if defined(HAVE_ID3LIB) || defined(HAVE_TAGLIB)
CFG_IMPORT_LIBOPTS_ID3_AUXDATA_TAGS_LIST,
#endif
#ifdef EXTERNAL_TRANSCODING
CFG_TRANSCODING_PROFILE_LIST,
#ifdef HAVE_CURL
CFG_EXTERNAL_TRANSCODING_CURL_BUFFER_SIZE,
CFG_EXTERNAL_TRANSCODING_CURL_FILL_SIZE,
#endif//HAVE_CURL
#endif//EXTERNAL_TRANSCODING
#ifdef YOUTUBE
CFG_ONLINE_CONTENT_YOUTUBE_ENABLED,
CFG_ONLINE_CONTENT_YOUTUBE_FORMAT_MP4,
CFG_ONLINE_CONTENT_YOUTUBE_PREFER_HD,
CFG_ONLINE_CONTENT_YOUTUBE_RACY,
CFG_ONLINE_CONTENT_YOUTUBE_REFRESH,
CFG_ONLINE_CONTENT_YOUTUBE_UPDATE_AT_START,
CFG_ONLINE_CONTENT_YOUTUBE_PURGE_AFTER,
CFG_ONLINE_CONTENT_YOUTUBE_TASK_LIST,
#endif
#ifdef SOPCAST
CFG_ONLINE_CONTENT_SOPCAST_ENABLED,
CFG_ONLINE_CONTENT_SOPCAST_REFRESH,
CFG_ONLINE_CONTENT_SOPCAST_UPDATE_AT_START,
CFG_ONLINE_CONTENT_SOPCAST_PURGE_AFTER,
#endif
#ifdef WEBORAMA
CFG_ONLINE_CONTENT_WEBORAMA_ENABLED,
CFG_ONLINE_CONTENT_WEBORAMA_REFRESH,
CFG_ONLINE_CONTENT_WEBORAMA_UPDATE_AT_START,
CFG_ONLINE_CONTENT_WEBORAMA_PURGE_AFTER,
CFG_ONLINE_CONTENT_WEBORAMA_TASK_LIST,
#endif
#ifdef ATRAILERS
CFG_ONLINE_CONTENT_ATRAILERS_ENABLED,
CFG_ONLINE_CONTENT_ATRAILERS_REFRESH,
CFG_ONLINE_CONTENT_ATRAILERS_UPDATE_AT_START,
CFG_ONLINE_CONTENT_ATRAILERS_PURGE_AFTER,
CFG_ONLINE_CONTENT_ATRAILERS_RESOLUTION,
#endif
CFG_MAX
} config_option_t;
class ConfigManager : public Singleton<ConfigManager>
{
public:
ConfigManager();
virtual ~ConfigManager();
/// \brief Returns the name of the config file that was used to launch the server.
inline zmm::String getConfigFilename() { return filename; }
void load(zmm::String filename);
/// \brief returns a config option of type String
/// \param option option to retrieve.
zmm::String getOption(config_option_t option);
/// \brief returns a config option of type int
/// \param option option to retrieve.
int getIntOption(config_option_t option);
/// \brief returns a config option of type bool
/// \param option option to retrieve.
bool getBoolOption(config_option_t option);
/// \brief returns a config option of type Dictionary
/// \param option option to retrieve.
zmm::Ref<Dictionary> getDictionaryOption(config_option_t option);
/// \brief returns a config option of type Array of StringBase
/// \param option option to retrieve.
zmm::Ref<zmm::Array<zmm::StringBase> > getStringArrayOption(config_option_t option);
zmm::Ref<ObjectDictionary<zmm::Object> > getObjectDictionaryOption(config_option_t option);
#ifdef ONLINE_SERVICES
/// \brief returns a config option of type Array of Object
/// \param option option to retrieve.
zmm::Ref<zmm::Array<zmm::Object> > getObjectArrayOption(config_option_t option);
#endif
/// \brief returns a config option of type AutoscanList
/// \param option to retrieve
zmm::Ref<AutoscanList> getAutoscanListOption(config_option_t option);
#ifdef EXTERNAL_TRANSCODING
/// \brief returns a config option of type TranscodingProfileList
/// \param option to retrieve
zmm::Ref<TranscodingProfileList> getTranscodingProfileListOption(config_option_t option);
#endif
/// \brief sets static configuration parameters that will be used by
/// when the ConfigManager class initializes
static void setStaticArgs(zmm::String _filename, zmm::String _userhome,
zmm::String _config_dir = _(DEFAULT_CONFIG_HOME),
zmm::String _prefix_dir = _(PACKAGE_DATADIR),
zmm::String _magic = nil,
bool _debug_logging = false);
static bool isDebugLogging() { return debug_logging; };
/// \brief Creates a html file that is a redirector to the current server i
/// instance
void writeBookmark(zmm::String ip, zmm::String port);
protected:
// helper for extension to mimetype kind of mappings
zmm::Ref<mxml::Element> map_from_to(zmm::String from, zmm::String to);
zmm::Ref<mxml::Element> treat_as(zmm::String mimetype, zmm::String as);
zmm::Ref<mxml::Element> renderTranscodingSection();
zmm::Ref<mxml::Element> renderOnlineSection();
// creates a default config.xml file with the most necessary entries and returns the path
zmm::String createDefaultConfig(zmm::String userhome);
void save();
void save_text(zmm::String filename, zmm::String content);
void migrate();
void validate(zmm::String serverhome);
void prepare_udn();
zmm::String construct_path(zmm::String path);
void prepare_path(zmm::String path, bool needDir = false, bool existenceUnneeded = false);
static zmm::String filename;
static zmm::String userhome;
static zmm::String config_dir;
static zmm::String prefix_dir;
static zmm::String magic;
static bool debug_logging;
zmm::Ref<mxml::Element> root;
zmm::Ref<Dictionary> mime_content;
zmm::Ref<zmm::Array<ConfigOption> > options;
/// \brief Returns a config option with the given path, if option does not exist a default value is returned.
/// \param xpath option xpath
/// \param def default value if option not found
///
/// the name parameter has the XPath syntax.
/// Currently only two xpath constructs are supported:
/// "/path/to/option" will return the text value of the given "option" element
/// "/path/to/option/attribute::attr" will return the value of the attribute "attr"
zmm::String getOption(zmm::String xpath, zmm::String def);
/// \brief same as getOption but returns an integer value of the option
int getIntOption(zmm::String xpath, int def);
/// \brief Returns a config option with the given path, an exception is raised if option does not exist.
/// \param xpath option xpath.
///
/// The xpath parameter has XPath syntax.
/// Currently only two xpath constructs are supported:
/// "/path/to/option" will return the text value of the given "option" element
/// "/path/to/option/attribute::attr" will return the value of the attribute "attr"
zmm::String getOption(zmm::String xpath);
/// \brief same as getOption but returns an integer value of the option
int getIntOption(zmm::String xpath);
/// \brief Returns a config XML element with the given path, an exception is raised if element does not exist.
/// \param xpath option xpath.
///
/// The xpath parameter has XPath syntax.
/// "/path/to/element" will return the text value of the given "element" element
zmm::Ref<mxml::Element> getElement(zmm::String xpath);
/// \brief Checks if the string returned by getOption is valid.
/// \param xpath xpath expression to the XML node
zmm::String checkOptionString(zmm::String xpath);
/// \brief Creates a dictionary from an XML nodeset.
/// \param element starting element of the nodeset.
/// \param nodeName name of each node in the set
/// \param keyAttr attribute name to be used as a key
/// \param valAttr attribute name to be used as value
///
/// The basic idea is the following:
/// You have a piece of XML that looks like this
/// <some-section>
/// <map from="1" to="2"/>
/// <map from="3" to="4"/>
/// </some-section>
///
/// This function will create a dictionary with the following
/// key:value paris: "1":"2", "3":"4"
zmm::Ref<Dictionary> createDictionaryFromNodeset(zmm::Ref<mxml::Element> element, zmm::String nodeName, zmm::String keyAttr, zmm::String valAttr, bool tolower = false);
/// \brief Creates an aray of AutoscanDirectory objects from
/// an XML nodeset.
/// \param element starting element of the ndoeset.
/// \param scanmode add only directories with the specified scanmode to the array
zmm::Ref<AutoscanList> createAutoscanListFromNodeset(zmm::Ref<mxml::Element> element, scan_mode_t scanmode);
#ifdef EXTERNAL_TRANSCODING
/// \brief Creates ab aray of TranscodingProfile objects from an XML
/// nodeset.
/// \param element starting element of the nodeset.
zmm::Ref<TranscodingProfileList> createTranscodingProfileListFromNodeset(zmm::Ref<mxml::Element> element);
#endif
/// \brief Creates an array of strings from an XML nodeset.
/// \param element starting element of the nodeset.
/// \param nodeName name of each node in the set
/// \param attrName name of the attribute, the value of which shouldbe extracted
///
/// Similar to \fn createDictionaryFromNodeset() this one extracts
/// data from the following XML:
/// <some-section>
/// <tag attr="data"/>
/// <tag attr="otherdata"/>
/// <some-section>
///
/// This function will create an array like that: ["data", "otherdata"]
zmm::Ref<zmm::Array<zmm::StringBase> > createArrayFromNodeset(zmm::Ref<mxml::Element> element, zmm::String nodeName, zmm::String attrName);
void dumpOptions();
#ifdef ONLINE_SERVICES
/// \brief This functions activates the YouTube class and retrieves
/// lets it parse the options.
///
/// Note that usually the config manager does all the parsing, however
/// in the case of online services the tasklist is something very generic
/// and only the service class knows how to organize it. Since an
/// online service is controlled by an external authority, the API and
/// thus the options can change, for that reason we prefer keeping
/// absolutely all functionality related to the service inside the
/// service class.
zmm::Ref<zmm::Array<zmm::Object> > createServiceTaskList(service_type_t service, zmm::Ref<mxml::Element> element);
#endif
};
#endif // __CONFIG_MANAGER_H__