Update with current status
[gnash.git] / libbase / rc.h
blob34b3ce1f6479e6e0c08b4f8c7726700c135cbafc
1 // rc.h: "Run Command" configuration file declarations, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software 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 <cstdint>
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 std::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 /// Whether to forcibly show the mouse pointer even if the SWF file
162 /// disables it. THis allows touchscreen based SWF files to
163 /// work on a normal non-touchscreen desktop.
164 bool showMouse() const { return _showMouse; }
166 /// Sets the RcInitFile blacklist of domains to block
168 /// @param list a std::vector of strings containing domains without protocol
169 void setBlacklist (const std::vector<std::string>& list) {
170 _blacklist = list;
173 /// Return the list of directories to be used as the 'local' sandbox
175 /// Local sendbox is the set of resources on the filesystem we want to
176 /// give the current movie access to.
178 const PathList& getLocalSandboxPath() const { return _localSandboxPath; }
180 /// Add a directory to the local sandbox list
181 void addLocalSandboxPath(const std::string& dir)
183 _localSandboxPath.push_back(dir);
186 /// Sets a list of sandbox paths. Gnash will only allow movies access
187 /// to files in these paths. The path of the movie playing is automatically
188 /// added.
190 /// @param list a std::vector of strings containing paths to allow
191 void setLocalSandboxPath(const PathList& path)
193 _localSandboxPath = path;
196 const std::string& getFlashVersionString() const {
197 return _flashVersionString;
200 void setFlashVersionString(const std::string& value) {
201 _flashVersionString = value;
204 const std::string& getFlashSystemOS() const {
205 return _flashSystemOS;
208 void setFlashSystemOS(const std::string& value) {
209 _flashSystemOS = value;
212 const std::string& getFlashSystemManufacturer() const {
213 return _flashSystemManufacturer;
216 void setFlashSystemManufacturer(const std::string& value) {
217 _flashSystemManufacturer = value;
220 const std::string& getGstAudioSink() const { return _gstaudiosink; }
222 void setGstAudioSink(const std::string& value) { _gstaudiosink = value; }
224 int getRetries() const { return _retries; }
226 void setRetries(int x) { _retries = x; }
228 /// The number of seconds of inactivity before timing out streams downloads
229 double getStreamsTimeout() const { return _streamsTimeout; }
231 /// Set seconds of inactivity before timing out streams downloads
232 void setStreamsTimeout(const double &x) { _streamsTimeout = x; }
234 /// Get the URL opener command format
236 /// The %u label will need to be substituted by the actual url
237 /// properly escaped.
239 const std::string &getURLOpenerFormat() const
241 return _urlOpenerFormat;
244 void setURLOpenerFormat(const std::string& value)
246 _urlOpenerFormat = value;
249 // Get the name of the hardware acclerator to use for video
250 const std::string &getHWAccel() const { return _hwaccel; }
252 // Set the name of the hardware acclerator to use for video
253 void setHWAccel(const std::string &x) { _hwaccel = x; }
255 // Get the name of the renderer to draw the display
256 const std::string& getRenderer() const { return _renderer; }
258 // Set the name of the renderer to draw the display
259 void setRenderer(const std::string& x) { _renderer = x; }
261 // Get the name of the media handler to use for video/audio
262 const std::string& getMediaHandler() const { return _mediahandler; }
264 // Set the name of the media handler to use for video/audio
265 void setMediaHandler(const std::string& x) { _mediahandler = x; }
267 // Get the location of the sandbox for .sol files
268 const std::string &getSOLSafeDir() const { return _solsandbox; }
270 // Set the location of the sandbox for .sol files
271 void setSOLSafeDir(const std::string &x) { _solsandbox = x; }
273 bool getSOLLocalDomain() const { return _sollocaldomain; }
275 void setSOLLocalDomain(bool x) { _sollocaldomain = x; }
277 bool getSOLReadOnly() const { return _solreadonly; }
279 void setSOLReadOnly(bool x) { _solreadonly = x; }
281 bool getLocalConnection() const { return _lcdisabled; }
283 void setLocalConnection(bool x) { _lcdisabled = x; }
285 /// \brief Enable tracing all LocalConnection traffic
286 bool getLCTrace() const { return _lctrace; }
288 void setLCTrace(bool x) { _lctrace = x; }
290 key_t getLCShmKey() const { return static_cast<key_t>(_lcshmkey); }
292 void setLCShmKey(bool x) { _lcshmkey = x; }
294 bool ignoreFSCommand() const { return _ignoreFSCommand; }
296 void ignoreFSCommand(bool value) { _ignoreFSCommand = value; }
298 void saveStreamingMedia(bool value) { _saveStreamingMedia = value; }
300 bool saveStreamingMedia() const { return _saveStreamingMedia; }
302 void saveLoadedMedia(bool value) { _saveLoadedMedia = value; }
304 bool saveLoadedMedia() const { return _saveLoadedMedia; }
306 void setMediaDir(const std::string& value) { _mediaCacheDir = value; }
308 const std::string& getMediaDir() const { return _mediaCacheDir; }
310 void setWebcamDevice(int value) {_webcamDevice = value;}
312 int getWebcamDevice() const {return _webcamDevice;}
314 void setAudioInputDevice(int value) {_microphoneDevice = value;}
316 int getAudioInputDevice() {return _microphoneDevice;}
318 /// \brief Get the Root SSL certificate
319 const std::string& getRootCert() const {
320 return _rootcert;
322 /// \brief Set the Root SSL certificate
323 void setRootCert(const std::string& value) {
324 _rootcert = value;
327 /// \brief Get the Client SSL certificate
328 const std::string& getCertFile() const {
329 return _certfile;
331 /// \brief Set the Client SSL certificate
332 void setCertFile(const std::string& value) {
333 _certfile = value;
336 /// \brief Get the directory for client SSL certificates
337 const std::string& getCertDir() const {
338 return _certdir;
340 /// \brief Set the directory for client SSL certificates
341 void setCertDir(const std::string& value) {
342 _certdir = value;
345 void ignoreShowMenu(bool value) { _ignoreShowMenu=value; }
347 bool ignoreShowMenu() const { return _ignoreShowMenu; }
349 int getScriptsTimeout() const { return _scriptsTimeout; }
351 void setScriptsTimeout(int x) { _scriptsTimeout = x; }
353 int getScriptsRecursionLimit() const { return _scriptsRecursionLimit; }
355 void setScriptsRecursionLimit(int x) { _scriptsRecursionLimit = x; }
357 void lockScriptLimits(bool x) { _lockScriptLimits = x; }
359 bool lockScriptLimits() const { return _lockScriptLimits; }
361 void dump();
363 protected:
365 // A function only for writing path lists to an outstream.
366 void writeList(const PathList& list, std::ostream& o);
368 /// Construct only by getDefaultInstance()
369 RcInitFile();
371 /// Never destroy (TODO: add a destroyDefaultInstance)
372 ~RcInitFile();
374 /// Substitutes user's home directory for ~ on a path string
375 /// according to POSIX standard.
377 /// @param path the path to expand.
378 static void expandPath(std::string& path);
380 /// \brief
381 /// If variable matches pattern (case-insensitive)
382 /// set var according to value
384 /// @return true if variable matches pattern, false otherwise
385 /// @param var the variable to change
386 /// @param pattern the pattern for matching
387 /// @variable the variable to match to pattern
388 /// @value the value to adopt if variable matches pattern.
389 static bool extractSetting(bool &var, const std::string& pattern,
390 const std::string &variable, const std::string &value);
392 /// \brief
393 /// If variable matches pattern (case-insensitive)
394 /// set num according to value
396 /// @return true if variable matches pattern, false otherwise
397 /// @param num the variable to change
398 /// @param pattern the pattern for matching
399 /// @variable the variable to match to pattern
400 /// @value the value to adopt if variable matches pattern.
401 template<typename T>
402 static bool extractNumber(T& num, const std::string& pattern,
403 const std::string &variable, const std::string &value)
406 StringNoCaseEqual noCaseCompare;
408 if (noCaseCompare(variable, pattern)) {
409 std::istringstream in(value);
410 if (in >> num) return true;
412 num = 0;
413 return true;
416 return false;
419 /// \brief
420 /// If variable matches pattern (case-insensitive)
421 /// set out according to value
423 /// @return true if variable matches pattern, false otherwise
424 /// @param out the variable to change
425 /// @param pattern the pattern for matching
426 /// @variable the variable to match to pattern
427 /// @value the value to adopt if variable matches pattern.
428 static bool extractDouble(double &out, const std::string& pattern,
429 const std::string &variable, const std::string &value);
432 /// \brief parses a space-separated list into std::vector list
434 /// @param list the vector to modify or generate.
435 /// @param action either 'set' or 'append': whether to add to or
436 /// clear the vector.
437 /// @param items string of space-separated values. This gets nuked.
438 void parseList(std::vector<std::string>& list, const std::string &action,
439 const std::string &items);
441 typedef boost::char_separator<char> Sep;
442 typedef boost::tokenizer< Sep > Tok;
444 /// The timer delay
445 std::uint32_t _delay;
447 /// Max number of movie clips to store in the library
448 std::uint32_t _movieLibraryLimit;
450 /// Enable debugging of this class
451 bool _debug;
453 /// Enable the Flash movie debugger
454 bool _debugger;
456 /// Level of debugging output
457 std::uint32_t _verbosity;
459 /// Command format to use to open urls
461 /// The %u label will need to be substituted by the url
462 /// (properly escaped)
464 std::string _urlOpenerFormat;
466 /// String to pass as $version in Actionscript
467 std::string _flashVersionString;
469 /// String representing the first GStreamer audio output pipeline to try
470 std::string _gstaudiosink;
472 /// \brief String to pass as System.capabilities.os
473 /// in Actionscript. If empty, leaves detection
474 /// to System.cpp (default).
475 std::string _flashSystemOS;
477 /// \brief String to pass as
478 /// System.capabilities.manufacturer
479 /// in Actionscript
480 std::string _flashSystemManufacturer;
482 /// Enable dumping actionscript classes
483 bool _actionDump;
485 /// Enable dumping parser data
486 bool _parserDump;
488 /// Enable ActionScript errors verbosity
489 bool _verboseASCodingErrors;
491 /// Enable Malformed SWF verbosity
492 bool _verboseMalformedSWF;
494 /// Enable Malformed AMF verbosity
495 bool _verboseMalformedAMF;
497 /// Display a splash screen when loading a movie
498 bool _splashScreen;
500 /// Only access network resources in the local domain
501 bool _localdomainOnly;
503 /// Only access network resources on the local host
504 bool _localhostOnly;
506 /// Show the mouse pointer
507 bool _showMouse;
509 /// Allowed domains
510 PathList _whitelist;
512 /// Blocked Domains
513 PathList _blacklist;
515 /// The name of the debug log
516 std::string _log;
518 /// Enable writing the debug log to disk
519 bool _writeLog;
521 /// The root path for the streaming server
522 std::string _wwwroot;
524 /// the number of retries for a thread
525 int _retries;
527 /// Enable the sound handler at startup
528 bool _sound;
530 /// Enable sound for the plugin
531 bool _pluginSound;
533 /// Enable scanning plugin path for extensions
534 bool _extensionsEnabled;
536 /// Start the gui in "stop" mode
537 bool _startStopped;
539 /// Allow SSL connections without verifying the certificate
540 bool _insecureSSL;
542 /// The number of seconds of inactivity triggering download timeout
543 double _streamsTimeout;
545 /// \brief Local sandbox: the set of resources on the
546 /// filesystem we want to give the current movie access to.
547 PathList _localSandboxPath;
549 /// \brief SOL Sandbox: This is the only dir .sol (Shared Object)
550 /// files can be written in, or read from.
551 std::string _solsandbox;
553 /// Whether SOL files can be written
554 bool _solreadonly;
555 bool _sollocaldomain;
557 // Disable local connection
558 bool _lcdisabled;
560 /// Trace local connection activity (in log)
561 bool _lctrace;
563 /// Shared memory segment key (can be set for
564 /// compatibility with other players.)
565 std::uint32_t _lcshmkey;
567 /// Whether the player should respond to fscommands
568 /// (showmenu, quit etc)
569 bool _ignoreFSCommand;
571 /// The quality to display SWFs in. -1 to allow the SWF to override.
572 int _quality;
574 bool _saveStreamingMedia;
576 bool _saveLoadedMedia;
578 std::string _mediaCacheDir;
580 bool _popups;
582 ///FIXME: this should probably eventually be changed to a more readable
583 ///config option instead of an integer
584 int _webcamDevice;
586 int _microphoneDevice;
588 /// \var _certfile
589 /// This is the name of the client certificate file
590 std::string _certfile;
592 /// \var _certdir
593 /// This is the path to the directory containing cert files
594 std::string _certdir;
596 /// \var _rootcert
597 /// This is the name of the root certificate
598 std::string _rootcert;
600 /// Whether the player will recognize changes to Stage.showMenu in AS
601 /// default value is true
602 bool _ignoreShowMenu;
604 /// Whether to use HW video decoding support, no value means disabled.
605 /// The only currently supported values are: none or vaapi
606 /// support is coming.
607 std::string _hwaccel;
609 /// Which renderer backend to use, no value means use the default.
610 /// The currently supported values are agg, opengl, or cairo. AGG
611 /// being the default.
612 std::string _renderer;
614 /// Which media player backend to use, no value means use the default.
615 /// The default is set in the MediaFactory initialization table.
616 std::string _mediahandler;
618 /// The number of seconds after which action execution is
619 /// considered to be slow enough to prompt the user for aborting
620 int _scriptsTimeout;
622 /// The max actionscript function call stack depth
623 int _scriptsRecursionLimit;
625 /// Whether to ignore SWF ScriptLimits tags
626 bool _lockScriptLimits;
629 // End of gnash namespace
632 #endif
635 // local Variables:
636 // mode: C++
637 // indent-tabs-mode: t
638 // End: