Backslash ${prefix} for kde3 too...
[gnash.git] / libbase / rc.h
blob6e49f72bdbef63f6bb50d4608aa9fbe5ad099662
1 // rc.h: "Run Command" configuration file declarations, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef GNASH_RC_H
21 #define GNASH_RC_H
23 #include "dsodefs.h"
24 #include <string>
25 #include <vector>
26 #include <iosfwd>
27 #include <sstream>
28 #include <boost/cstdint.hpp>
29 #include <boost/tokenizer.hpp>
31 #include "StringPredicates.h"
33 #if !defined(_WIN32) && !defined(__HAIKU__) && !defined(ANDROID)
34 #include <sys/shm.h>
35 #else
36 #ifdef _WIN32
37 typedef boost::uint32_t key_t;
38 #endif // _WIN32
39 #endif // _WIN32 and __HAIKU__
41 namespace gnash {
43 class DSOEXPORT RcInitFile
45 public:
47 /// Return the default instance of RC file
48 static RcInitFile& getDefaultInstance();
50 /// Load and parse files, looking in the usual places
52 void loadFiles();
54 bool parseFile(const std::string& filespec);
56 /// \brief
57 /// Writes a valid gnashrc file. If the file already exists,
58 /// is is overwritten.
60 /// @param filespec the file to write
61 /// @return whether the file was successfully written.
62 bool updateFile(const std::string& filespec);
64 /// \brief Writes a gnashrc file to the file specified in the
65 /// GNASHRC environment variable OR to the user's home
66 /// directory.
68 /// @return whether the file was successfully written.
69 bool updateFile();
71 bool useSplashScreen() const { return _splashScreen; }
72 void useSplashScreen(bool value);
74 bool useActionDump() const { return _actionDump; }
75 void useActionDump(bool value);
77 bool useParserDump() const { return _parserDump; }
78 void useParserDump(bool value);
80 bool useWriteLog() const { return _writeLog; }
81 void useWriteLog(bool value);
83 int getTimerDelay() const { return _delay; }
84 void setTimerDelay(int x) { _delay = x; }
86 bool showASCodingErrors() const { return _verboseASCodingErrors; }
87 void showASCodingErrors(bool value);
89 bool showMalformedSWFErrors() const { return _verboseMalformedSWF; }
90 void showMalformedSWFErrors(bool value);
92 bool showMalformedAMFErrors() const { return _verboseMalformedAMF; }
93 void showMalformedAMFErrors(bool value);
95 int getMovieLibraryLimit() const { return _movieLibraryLimit; }
96 void setMovieLibraryLimit(int value) { _movieLibraryLimit = value; }
98 bool enableExtensions() const { return _extensionsEnabled; }
100 /// Return true if user is willing to start the gui in "stop" mode
102 /// defaults to false.
103 bool startStopped() const { return _startStopped; }
104 void startStopped(bool value) { _startStopped = value; }
106 bool insecureSSL() const { return _insecureSSL; }
107 void insecureSSL(bool value) { _insecureSSL = value; }
109 int qualityLevel() const { return _quality; }
110 void qualityLevel(int value) { _quality = value; }
112 int verbosityLevel() const { return _verbosity; }
113 void verbosityLevel(int value) { _verbosity = value; }
115 void setDebugLog(const std::string &x) { _log = x; }
116 const std::string& getDebugLog() const { return _log; }
118 void setDocumentRoot(const std::string &x) { _wwwroot = x; }
119 std::string getDocumentRoot() { return _wwwroot; }
121 bool useDebugger() const { return _debugger; }
122 void useDebugger(bool value) { _debugger = value; }
124 bool useSound() const { return _sound; }
125 void useSound(bool value) { _sound = value; }
127 // strk: I'd drop this, and allow an -f switch to select
128 // the gnashrc file to use instead
129 bool usePluginSound() const { return _pluginSound; }
130 void usePluginSound(bool value) { _pluginSound = value; }
132 bool popupMessages() const { return _popups; }
133 void interfacePopups(bool value) { _popups = value; }
135 bool useLocalDomain() const { return _localdomainOnly; }
136 void useLocalDomain(bool value);
138 /// Whether to restrict access to the local host
139 bool useLocalHost() const { return _localhostOnly; }
141 /// Set whether to restrict access to the local host
142 void useLocalHost(bool value);
144 typedef std::vector<std::string> PathList;
146 /// Get the current RcInitFile whitelist of domains to allow
148 /// @return a std::vector of strings containing allowed domains
149 const PathList& getWhiteList() const { return _whitelist; }
151 /// Sets the RcInitFile whitelist of domains to allow
153 /// @param list a std::vector of strings containing domains without protocol
154 void setWhitelist (const std::vector<std::string>& list) { _whitelist = list; }
156 /// Get the current RcInitFile blacklist of domains to block
158 /// @return a std::vector of strings containing blocked domains
159 const PathList& getBlackList() const { return _blacklist; }
161 /// Sets the RcInitFile blacklist of domains to block
163 /// @param list a std::vector of strings containing domains without protocol
164 void setBlacklist (const std::vector<std::string>& list) {
165 _blacklist = list;
168 /// Return the list of directories to be used as the 'local' sandbox
170 /// Local sendbox is the set of resources on the filesystem we want to
171 /// give the current movie access to.
173 const PathList& getLocalSandboxPath() const { return _localSandboxPath; }
175 /// Add a directory to the local sandbox list
176 void addLocalSandboxPath(const std::string& dir)
178 _localSandboxPath.push_back(dir);
181 /// Sets a list of sandbox paths. Gnash will only allow movies access
182 /// to files in these paths. The path of the movie playing is automatically
183 /// added.
185 /// @param list a std::vector of strings containing paths to allow
186 void setLocalSandboxPath(const PathList& path)
188 _localSandboxPath = path;
191 const std::string& getFlashVersionString() const {
192 return _flashVersionString;
195 void setFlashVersionString(const std::string& value) {
196 _flashVersionString = value;
199 const std::string& getFlashSystemOS() const {
200 return _flashSystemOS;
203 void setFlashSystemOS(const std::string& value) {
204 _flashSystemOS = value;
207 const std::string& getFlashSystemManufacturer() const {
208 return _flashSystemManufacturer;
211 void setFlashSystemManufacturer(const std::string& value) {
212 _flashSystemManufacturer = value;
215 const std::string& getGstAudioSink() const { return _gstaudiosink; }
217 void setGstAudioSink(const std::string& value) { _gstaudiosink = value; }
219 int getRetries() const { return _retries; }
221 void setRetries(int x) { _retries = x; }
223 /// The number of seconds of inactivity before timing out streams downloads
224 double getStreamsTimeout() const { return _streamsTimeout; }
226 /// Set seconds of inactivity before timing out streams downloads
227 void setStreamsTimeout(const double &x) { _streamsTimeout = x; }
229 /// Get the URL opener command format
231 /// The %u label will need to be substituted by the actual url
232 /// properly escaped.
234 const std::string &getURLOpenerFormat() const
236 return _urlOpenerFormat;
239 void setURLOpenerFormat(const std::string& value)
241 _urlOpenerFormat = value;
244 // Get the name of the hardware acclerator to use for video
245 const std::string &getHWAccel() const { return _hwaccel; }
247 // Set the name of the hardware acclerator to use for video
248 void setHWAccel(const std::string &x) { _hwaccel = x; }
250 // Get the name of the renderer to draw the display
251 const std::string& getRenderer() const { return _renderer; }
253 // Set the name of the renderer to draw the display
254 void setRenderer(const std::string& x) { _renderer = x; }
256 // Get the name of the media handler to use for video/audio
257 const std::string& getMediaHandler() const { return _mediahandler; }
259 // Set the name of the media handler to use for video/audio
260 void setMediaHandler(const std::string& x) { _mediahandler = x; }
262 // Get the location of the sandbox for .sol files
263 const std::string &getSOLSafeDir() const { return _solsandbox; }
265 // Set the location of the sandbox for .sol files
266 void setSOLSafeDir(const std::string &x) { _solsandbox = x; }
268 bool getSOLLocalDomain() const { return _sollocaldomain; }
270 void setSOLLocalDomain(bool x) { _sollocaldomain = x; }
272 bool getSOLReadOnly() const { return _solreadonly; }
274 void setSOLReadOnly(bool x) { _solreadonly = x; }
276 bool getLocalConnection() const { return _lcdisabled; }
278 void setLocalConnection(bool x) { _lcdisabled = x; }
280 /// \brief Enable tracing all LocalConnection traffic
281 bool getLCTrace() const { return _lctrace; }
283 void setLCTrace(bool x) { _lctrace = x; }
285 key_t getLCShmKey() const { return static_cast<key_t>(_lcshmkey); }
287 void setLCShmKey(bool x) { _lcshmkey = x; }
289 bool ignoreFSCommand() const { return _ignoreFSCommand; }
291 void ignoreFSCommand(bool value) { _ignoreFSCommand = value; }
293 void saveStreamingMedia(bool value) { _saveStreamingMedia = value; }
295 bool saveStreamingMedia() const { return _saveStreamingMedia; }
297 void saveLoadedMedia(bool value) { _saveLoadedMedia = value; }
299 bool saveLoadedMedia() const { return _saveLoadedMedia; }
301 void setMediaDir(const std::string& value) { _mediaCacheDir = value; }
303 const std::string& getMediaDir() const { return _mediaCacheDir; }
305 void setWebcamDevice(int value) {_webcamDevice = value;}
307 int getWebcamDevice() const {return _webcamDevice;}
309 void setAudioInputDevice(int value) {_microphoneDevice = value;}
311 int getAudioInputDevice() {return _microphoneDevice;}
313 /// \brief Get the Root SSL certificate
314 const std::string& getRootCert() const {
315 return _rootcert;
317 /// \brief Set the Root SSL certificate
318 void setRootCert(const std::string& value) {
319 _rootcert = value;
322 /// \brief Get the Client SSL certificate
323 const std::string& getCertFile() const {
324 return _certfile;
326 /// \brief Set the Client SSL certificate
327 void setCertFile(const std::string& value) {
328 _certfile = value;
331 /// \brief Get the directory for client SSL certificates
332 const std::string& getCertDir() const {
333 return _certdir;
335 /// \brief Set the directory for client SSL certificates
336 void setCertDir(const std::string& value) {
337 _certdir = value;
340 void ignoreShowMenu(bool value) { _ignoreShowMenu=value; }
342 bool ignoreShowMenu() const { return _ignoreShowMenu; }
344 void dump();
346 protected:
348 // A function only for writing path lists to an outstream.
349 void writeList(const PathList& list, std::ostream& o);
351 /// Construct only by getDefaultInstance()
352 RcInitFile();
354 /// Never destroy (TODO: add a destroyDefaultInstance)
355 ~RcInitFile();
357 /// Substitutes user's home directory for ~ on a path string
358 /// according to POSIX standard.
360 /// @param path the path to expand.
361 static void expandPath(std::string& path);
363 /// \brief
364 /// If variable matches pattern (case-insensitive)
365 /// set var according to value
367 /// @return true if variable matches pattern, false otherwise
368 /// @param var the variable to change
369 /// @param pattern the pattern for matching
370 /// @variable the variable to match to pattern
371 /// @value the value to adopt if variable matches pattern.
372 static bool extractSetting(bool &var, const std::string& pattern,
373 const std::string &variable, const std::string &value);
375 /// \brief
376 /// If variable matches pattern (case-insensitive)
377 /// set num according to value
379 /// @return true if variable matches pattern, false otherwise
380 /// @param num the variable to change
381 /// @param pattern the pattern for matching
382 /// @variable the variable to match to pattern
383 /// @value the value to adopt if variable matches pattern.
384 template<typename T>
385 static bool extractNumber(T& num, const std::string& pattern,
386 const std::string &variable, const std::string &value)
389 StringNoCaseEqual noCaseCompare;
391 if (noCaseCompare(variable, pattern)) {
392 std::istringstream in(value);
393 if (in >> num) return true;
395 num = 0;
396 return true;
399 return false;
402 /// \brief
403 /// If variable matches pattern (case-insensitive)
404 /// set out according to value
406 /// @return true if variable matches pattern, false otherwise
407 /// @param out the variable to change
408 /// @param pattern the pattern for matching
409 /// @variable the variable to match to pattern
410 /// @value the value to adopt if variable matches pattern.
411 static bool extractDouble(double &out, const std::string& pattern,
412 const std::string &variable, const std::string &value);
415 /// \brief parses a space-separated list into std::vector list
417 /// @param list the vector to modify or generate.
418 /// @param action either 'set' or 'append': whether to add to or
419 /// clear the vector.
420 /// @param items string of space-separated values. This gets nuked.
421 void parseList(std::vector<std::string>& list, const std::string &action,
422 const std::string &items);
424 typedef boost::char_separator<char> Sep;
425 typedef boost::tokenizer< Sep > Tok;
427 /// The timer delay
428 boost::uint32_t _delay;
430 /// Max number of movie clips to store in the library
431 boost::uint32_t _movieLibraryLimit;
433 /// Enable debugging of this class
434 bool _debug;
436 /// Enable the Flash movie debugger
437 bool _debugger;
439 /// Level of debugging output
440 boost::uint32_t _verbosity;
442 /// Command format to use to open urls
444 /// The %u label will need to be substituted by the url
445 /// (properly escaped)
447 std::string _urlOpenerFormat;
449 /// String to pass as $version in Actionscript
450 std::string _flashVersionString;
452 /// String representing the first GStreamer audio output pipeline to try
453 std::string _gstaudiosink;
455 /// \brief String to pass as System.capabilities.os
456 /// in Actionscript. If empty, leaves detection
457 /// to System.cpp (default).
458 std::string _flashSystemOS;
460 /// \brief String to pass as
461 /// System.capabilities.manufacturer
462 /// in Actionscript
463 std::string _flashSystemManufacturer;
465 /// Enable dumping actionscript classes
466 bool _actionDump;
468 /// Enable dumping parser data
469 bool _parserDump;
471 /// Enable ActionScript errors verbosity
472 bool _verboseASCodingErrors;
474 /// Enable Malformed SWF verbosity
475 bool _verboseMalformedSWF;
477 /// Enable Malformed AMF verbosity
478 bool _verboseMalformedAMF;
480 /// Display a splash screen when loading a movie
481 bool _splashScreen;
483 /// Only access network resources in the local domain
484 bool _localdomainOnly;
486 /// Only access network resources on the local host
487 bool _localhostOnly;
489 /// Allowed domains
490 PathList _whitelist;
492 /// Blocked Domains
493 PathList _blacklist;
495 /// The name of the debug log
496 std::string _log;
498 /// Enable writing the debug log to disk
499 bool _writeLog;
501 /// The root path for the streaming server
502 std::string _wwwroot;
504 /// the number of retries for a thread
505 int _retries;
507 /// Enable the sound handler at startup
508 bool _sound;
510 /// Enable sound for the plugin
511 bool _pluginSound;
513 /// Enable scanning plugin path for extensions
514 bool _extensionsEnabled;
516 /// Start the gui in "stop" mode
517 bool _startStopped;
519 /// Allow SSL connections without verifying the certificate
520 bool _insecureSSL;
522 /// The number of seconds of inactivity triggering download timeout
523 double _streamsTimeout;
525 /// \brief Local sandbox: the set of resources on the
526 /// filesystem we want to give the current movie access to.
527 PathList _localSandboxPath;
529 /// \brief SOL Sandbox: This is the only dir .sol (Shared Object)
530 /// files can be written in, or read from.
531 std::string _solsandbox;
533 /// Whether SOL files can be written
534 bool _solreadonly;
535 bool _sollocaldomain;
537 // Disable local connection
538 bool _lcdisabled;
540 /// Trace local connection activity (in log)
541 bool _lctrace;
543 /// Shared memory segment key (can be set for
544 /// compatibility with other players.)
545 boost::uint32_t _lcshmkey;
547 /// Whether the player should respond to fscommands
548 /// (showmenu, quit etc)
549 bool _ignoreFSCommand;
551 /// The quality to display SWFs in. -1 to allow the SWF to override.
552 int _quality;
554 bool _saveStreamingMedia;
556 bool _saveLoadedMedia;
558 std::string _mediaCacheDir;
560 bool _popups;
562 bool _useXv;
564 ///FIXME: this should probably eventually be changed to a more readable
565 ///config option instead of an integer
566 int _webcamDevice;
568 int _microphoneDevice;
570 /// \var _certfile
571 /// This is the name of the client certificate file
572 std::string _certfile;
574 /// \var _certdir
575 /// This is the path to the directory containing cert files
576 std::string _certdir;
578 /// \var _rootcert
579 /// This is the name of the root certificate
580 std::string _rootcert;
582 /// Whether the player will recognize changes to Stage.showMenu in AS
583 /// default value is true
584 bool _ignoreShowMenu;
586 /// Whether to use HW video decoding support, no value means disabled.
587 /// The only currently supported values are: none, vaapi, or xv. omap
588 /// support is coming.
589 std::string _hwaccel;
591 /// Which renderer backend to use, no value means use the default.
592 /// The currently supported values are agg, opengl, or cairo. AGG
593 /// being the default.
594 std::string _renderer;
596 /// Which media player backend to use, no value means use the default.
597 /// The default is set in the MediaFactory initialization table.
598 std::string _mediahandler;
601 // End of gnash namespace
604 #endif
607 // local Variables:
608 // mode: C++
609 // indent-tabs-mode: t
610 // End: