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
19 
20 #ifndef GNASH_RC_H
21 #define GNASH_RC_H
22 
23 #include "dsodefs.h"
24 #include <string>
25 #include <vector>
26 #include <iosfwd>
27 #include <sstream>
28 #include <cstdint>
29 #include <boost/tokenizer.hpp>
30 
31 #include "StringPredicates.h"
32 
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__
40 
41 namespace gnash {
42 
43 class DSOEXPORT RcInitFile
44 {
45 public:
46 
47     /// Return the default instance of RC file
48     static RcInitFile& getDefaultInstance();
49 
50     /// Load and parse files, looking in the usual places
51     //
52     void loadFiles();
53 
54     bool parseFile(const std::string& filespec);
55 
56     /// \brief
57     /// Writes a valid gnashrc file. If the file already exists,
58     /// is is overwritten.
59     //
60     /// @param filespec the file to write
61     /// @return whether the file was successfully written.
62     bool updateFile(const std::string& filespec);
63 
64     /// \brief Writes a gnashrc file to the file specified in the
65     /// GNASHRC environment variable OR to the user's home
66     /// directory.
67     //
68     /// @return whether the file was successfully written.
69     bool updateFile();
70 
useSplashScreen()71     bool useSplashScreen() const { return _splashScreen; }
72     void useSplashScreen(bool value);
73 
useActionDump()74     bool useActionDump() const { return _actionDump; }
75     void useActionDump(bool value);
76 
useParserDump()77     bool useParserDump() const { return _parserDump; }
78     void useParserDump(bool value);
79 
useWriteLog()80     bool useWriteLog() const { return _writeLog; }
81     void useWriteLog(bool value);
82 
getTimerDelay()83     int getTimerDelay() const { return _delay; }
setTimerDelay(int x)84     void setTimerDelay(int x) { _delay = x; }
85 
showASCodingErrors()86     bool showASCodingErrors() const { return _verboseASCodingErrors; }
87     void showASCodingErrors(bool value);
88 
showMalformedSWFErrors()89     bool showMalformedSWFErrors() const { return _verboseMalformedSWF; }
90     void showMalformedSWFErrors(bool value);
91 
showMalformedAMFErrors()92     bool showMalformedAMFErrors() const { return _verboseMalformedAMF; }
93     void showMalformedAMFErrors(bool value);
94 
getMovieLibraryLimit()95     int getMovieLibraryLimit() const { return _movieLibraryLimit; }
setMovieLibraryLimit(int value)96     void setMovieLibraryLimit(int value) { _movieLibraryLimit = value; }
97 
enableExtensions()98     bool enableExtensions() const { return _extensionsEnabled; }
99 
100     /// Return true if user is willing to start the gui in "stop" mode
101     //
102     /// defaults to false.
startStopped()103     bool startStopped() const { return _startStopped; }
startStopped(bool value)104     void startStopped(bool value) { _startStopped = value; }
105 
insecureSSL()106     bool insecureSSL() const { return _insecureSSL; }
insecureSSL(bool value)107     void insecureSSL(bool value) { _insecureSSL = value; }
108 
qualityLevel()109     int qualityLevel() const { return _quality; }
qualityLevel(int value)110     void qualityLevel(int value) { _quality = value; }
111 
verbosityLevel()112     int verbosityLevel() const { return _verbosity; }
verbosityLevel(int value)113     void verbosityLevel(int value) { _verbosity = value; }
114 
setDebugLog(const std::string & x)115     void setDebugLog(const std::string &x) { _log = x; }
getDebugLog()116     const std::string& getDebugLog() const { return _log; }
117 
setDocumentRoot(const std::string & x)118     void setDocumentRoot(const std::string &x) { _wwwroot = x; }
getDocumentRoot()119     std::string getDocumentRoot() { return _wwwroot; }
120 
useDebugger()121     bool useDebugger() const { return _debugger; }
useDebugger(bool value)122     void useDebugger(bool value) { _debugger = value; }
123 
useSound()124     bool useSound() const { return _sound; }
useSound(bool value)125     void useSound(bool value) { _sound = value; }
126 
127     // strk: I'd drop this, and allow an -f switch to select
128     //       the gnashrc file to use instead
usePluginSound()129     bool usePluginSound() const { return _pluginSound; }
usePluginSound(bool value)130     void usePluginSound(bool value) { _pluginSound = value; }
131 
popupMessages()132     bool popupMessages() const { return _popups; }
interfacePopups(bool value)133     void interfacePopups(bool value) { _popups = value; }
134 
useLocalDomain()135     bool useLocalDomain() const { return _localdomainOnly; }
136     void useLocalDomain(bool value);
137 
138     /// Whether to restrict access to the local host
useLocalHost()139     bool useLocalHost() const { return _localhostOnly; }
140 
141     /// Set whether to restrict access to the local host
142     void useLocalHost(bool value);
143 
144     typedef std::vector<std::string> PathList;
145 
146     /// Get the current RcInitFile whitelist of domains to allow
147     //
148     /// @return a std::vector of strings containing allowed domains
getWhiteList()149     const PathList& getWhiteList() const { return _whitelist; }
150 
151     /// Sets the RcInitFile whitelist of domains to allow
152     //
153     /// @param list a std::vector of strings containing domains without protocol
setWhitelist(const std::vector<std::string> & list)154     void setWhitelist (const std::vector<std::string>& list) { _whitelist = list; }
155 
156     /// Get the current RcInitFile blacklist of domains to block
157     //
158     /// @return a std::vector of strings containing blocked domains
getBlackList()159     const PathList& getBlackList() const { return _blacklist; }
160 
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.
showMouse()164     bool showMouse() const { return _showMouse; }
165 
166     /// Sets the RcInitFile blacklist of domains to block
167     //
168     /// @param list a std::vector of strings containing domains without protocol
setBlacklist(const std::vector<std::string> & list)169     void setBlacklist (const std::vector<std::string>& list) {
170         _blacklist = list;
171     }
172 
173     /// Return the list of directories to be used as the 'local' sandbox
174     //
175     /// Local sendbox is the set of resources on the filesystem we want to
176     /// give the current movie access to.
177     ///
getLocalSandboxPath()178     const PathList& getLocalSandboxPath() const { return _localSandboxPath; }
179 
180     /// Add a directory to the local sandbox list
addLocalSandboxPath(const std::string & dir)181     void addLocalSandboxPath(const std::string& dir)
182     {
183         _localSandboxPath.push_back(dir);
184     }
185 
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.
189     //
190     /// @param list a std::vector of strings containing paths to allow
setLocalSandboxPath(const PathList & path)191     void setLocalSandboxPath(const PathList& path)
192     {
193         _localSandboxPath = path;
194     }
195 
getFlashVersionString()196     const std::string& getFlashVersionString() const {
197         return _flashVersionString;
198     }
199 
setFlashVersionString(const std::string & value)200     void setFlashVersionString(const std::string& value) {
201         _flashVersionString = value;
202     }
203 
getFlashSystemOS()204     const std::string& getFlashSystemOS() const {
205         return _flashSystemOS;
206     }
207 
setFlashSystemOS(const std::string & value)208     void setFlashSystemOS(const std::string& value) {
209         _flashSystemOS = value;
210     }
211 
getFlashSystemManufacturer()212     const std::string& getFlashSystemManufacturer() const {
213         return _flashSystemManufacturer;
214     }
215 
setFlashSystemManufacturer(const std::string & value)216     void setFlashSystemManufacturer(const std::string& value) {
217         _flashSystemManufacturer = value;
218     }
219 
getGstAudioSink()220     const std::string& getGstAudioSink() const { return _gstaudiosink; }
221 
setGstAudioSink(const std::string & value)222     void setGstAudioSink(const std::string& value) { _gstaudiosink = value; }
223 
getRetries()224     int getRetries() const { return _retries; }
225 
setRetries(int x)226     void setRetries(int x) { _retries = x; }
227 
228     /// The number of seconds of inactivity before timing out streams downloads
getStreamsTimeout()229     double getStreamsTimeout() const { return _streamsTimeout; }
230 
231     /// Set seconds of inactivity before timing out streams downloads
setStreamsTimeout(const double & x)232     void setStreamsTimeout(const double &x) { _streamsTimeout = x; }
233 
234     /// Get the URL opener command format
235     //
236     /// The %u label will need to be substituted by the actual url
237     /// properly escaped.
238     ///
getURLOpenerFormat()239     const std::string &getURLOpenerFormat() const
240     {
241         return _urlOpenerFormat;
242     }
243 
setURLOpenerFormat(const std::string & value)244     void setURLOpenerFormat(const std::string& value)
245     {
246         _urlOpenerFormat = value;
247     }
248 
249     // Get the name of the hardware acclerator to use for video
getHWAccel()250     const std::string &getHWAccel() const { return _hwaccel; }
251 
252     // Set the name of the hardware acclerator to use for video
setHWAccel(const std::string & x)253     void setHWAccel(const std::string &x) { _hwaccel = x; }
254 
255     // Get the name of the renderer to draw the display
getRenderer()256     const std::string& getRenderer() const { return _renderer; }
257 
258     // Set the name of the renderer to draw the display
setRenderer(const std::string & x)259     void setRenderer(const std::string& x) { _renderer = x; }
260 
261     // Get the name of the media handler to use for video/audio
getMediaHandler()262     const std::string& getMediaHandler() const { return _mediahandler; }
263 
264     // Set the name of the media handler to use for video/audio
setMediaHandler(const std::string & x)265     void setMediaHandler(const std::string& x) { _mediahandler = x; }
266 
267     // Get the location of the sandbox for .sol files
getSOLSafeDir()268     const std::string &getSOLSafeDir() const { return _solsandbox; }
269 
270     // Set the location of the sandbox for .sol files
setSOLSafeDir(const std::string & x)271     void setSOLSafeDir(const std::string &x) { _solsandbox = x; }
272 
getSOLLocalDomain()273     bool getSOLLocalDomain() const { return _sollocaldomain; }
274 
setSOLLocalDomain(bool x)275     void setSOLLocalDomain(bool x) { _sollocaldomain = x; }
276 
getSOLReadOnly()277     bool getSOLReadOnly() const { return _solreadonly; }
278 
setSOLReadOnly(bool x)279     void setSOLReadOnly(bool x) { _solreadonly = x; }
280 
getLocalConnection()281     bool getLocalConnection() const { return _lcdisabled; }
282 
setLocalConnection(bool x)283     void setLocalConnection(bool x) { _lcdisabled = x; }
284 
285     /// \brief Enable tracing all LocalConnection traffic
getLCTrace()286     bool getLCTrace() const { return _lctrace; }
287 
setLCTrace(bool x)288     void setLCTrace(bool x) { _lctrace = x; }
289 
getLCShmKey()290     key_t getLCShmKey() const { return static_cast<key_t>(_lcshmkey); }
291 
setLCShmKey(bool x)292     void setLCShmKey(bool x) { _lcshmkey = x; }
293 
ignoreFSCommand()294     bool ignoreFSCommand() const { return _ignoreFSCommand; }
295 
ignoreFSCommand(bool value)296     void ignoreFSCommand(bool value) { _ignoreFSCommand = value; }
297 
saveStreamingMedia(bool value)298     void saveStreamingMedia(bool value) { _saveStreamingMedia = value; }
299 
saveStreamingMedia()300     bool saveStreamingMedia() const { return _saveStreamingMedia; }
301 
saveLoadedMedia(bool value)302     void saveLoadedMedia(bool value) { _saveLoadedMedia = value; }
303 
saveLoadedMedia()304     bool saveLoadedMedia() const { return _saveLoadedMedia; }
305 
setMediaDir(const std::string & value)306     void setMediaDir(const std::string& value) { _mediaCacheDir = value; }
307 
getMediaDir()308     const std::string& getMediaDir() const { return _mediaCacheDir; }
309 
setWebcamDevice(int value)310     void setWebcamDevice(int value) {_webcamDevice = value;}
311 
getWebcamDevice()312     int getWebcamDevice() const {return _webcamDevice;}
313 
setAudioInputDevice(int value)314     void setAudioInputDevice(int value) {_microphoneDevice = value;}
315 
getAudioInputDevice()316     int getAudioInputDevice() {return _microphoneDevice;}
317 
318     /// \brief Get the Root SSL certificate
getRootCert()319     const std::string& getRootCert() const {
320         return _rootcert;
321     }
322     /// \brief Set the Root SSL certificate
setRootCert(const std::string & value)323     void setRootCert(const std::string& value) {
324         _rootcert = value;
325     }
326 
327     /// \brief Get the Client SSL certificate
getCertFile()328     const std::string& getCertFile() const {
329         return _certfile;
330     }
331     /// \brief Set the Client SSL certificate
setCertFile(const std::string & value)332     void setCertFile(const std::string& value) {
333         _certfile = value;
334     }
335 
336     /// \brief Get the directory for client SSL certificates
getCertDir()337     const std::string& getCertDir() const {
338         return _certdir;
339     }
340     /// \brief Set the directory for client SSL certificates
setCertDir(const std::string & value)341     void setCertDir(const std::string& value) {
342         _certdir = value;
343     }
344 
ignoreShowMenu(bool value)345     void ignoreShowMenu(bool value) { _ignoreShowMenu=value; }
346 
ignoreShowMenu()347     bool ignoreShowMenu() const { return _ignoreShowMenu; }
348 
getScriptsTimeout()349     int getScriptsTimeout() const { return _scriptsTimeout; }
350 
setScriptsTimeout(int x)351     void setScriptsTimeout(int x) { _scriptsTimeout = x; }
352 
getScriptsRecursionLimit()353     int getScriptsRecursionLimit() const { return _scriptsRecursionLimit; }
354 
setScriptsRecursionLimit(int x)355     void setScriptsRecursionLimit(int x) { _scriptsRecursionLimit = x; }
356 
lockScriptLimits(bool x)357     void lockScriptLimits(bool x) { _lockScriptLimits = x; }
358 
lockScriptLimits()359     bool lockScriptLimits() const { return _lockScriptLimits; }
360 
361     void dump();
362 
363 protected:
364 
365     // A function only for writing path lists to an outstream.
366     void writeList(const PathList& list, std::ostream& o);
367 
368     /// Construct only by getDefaultInstance()
369     RcInitFile();
370 
371     /// Never destroy (TODO: add a destroyDefaultInstance)
372     ~RcInitFile();
373 
374     /// Substitutes user's home directory for ~ on a path string
375     /// according to POSIX standard.
376     ///
377     /// @param path the path to expand.
378     static void expandPath(std::string& path);
379 
380     /// \brief
381     /// If variable matches pattern (case-insensitive)
382     /// set var according to value
383     //
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);
391 
392     /// \brief
393     /// If variable matches pattern (case-insensitive)
394     /// set num according to value
395     //
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>
extractNumber(T & num,const std::string & pattern,const std::string & variable,const std::string & value)402     static bool extractNumber(T& num, const std::string& pattern,
403                         const std::string &variable, const std::string &value)
404     {
405 
406         StringNoCaseEqual noCaseCompare;
407 
408         if (noCaseCompare(variable, pattern)) {
409             std::istringstream in(value);
410             if (in >> num) return true;
411 
412             num = 0;
413             return true;
414         }
415 
416         return false;
417     }
418 
419     /// \brief
420     /// If variable matches pattern (case-insensitive)
421     /// set out according to value
422     //
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);
430 
431 
432     /// \brief parses a space-separated list into std::vector list
433     //
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);
440 
441     typedef boost::char_separator<char> Sep;
442     typedef boost::tokenizer< Sep > Tok;
443 
444     /// The timer delay
445     std::uint32_t  _delay;
446 
447     /// Max number of movie clips to store in the library
448     std::uint32_t  _movieLibraryLimit;
449 
450     /// Enable debugging of this class
451     bool _debug;
452 
453     /// Enable the Flash movie debugger
454     bool _debugger;
455 
456     /// Level of debugging output
457     std::uint32_t  _verbosity;
458 
459     /// Command format to use to open urls
460     //
461     /// The %u label will need to be substituted by the url
462     /// (properly escaped)
463     ///
464     std::string  _urlOpenerFormat;
465 
466     /// String to pass as $version in Actionscript
467     std::string  _flashVersionString;
468 
469     /// String representing the first GStreamer audio output pipeline to try
470     std::string _gstaudiosink;
471 
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;
476 
477     /// \brief String to pass as
478     /// System.capabilities.manufacturer
479     /// in Actionscript
480     std::string  _flashSystemManufacturer;
481 
482     /// Enable dumping actionscript classes
483     bool _actionDump;
484 
485     /// Enable dumping parser data
486     bool _parserDump;
487 
488     /// Enable ActionScript errors verbosity
489     bool _verboseASCodingErrors;
490 
491     /// Enable Malformed SWF verbosity
492     bool _verboseMalformedSWF;
493 
494     /// Enable Malformed AMF verbosity
495     bool _verboseMalformedAMF;
496 
497     /// Display a splash screen when loading a movie
498     bool _splashScreen;
499 
500     /// Only access network resources in the local domain
501     bool _localdomainOnly;
502 
503     /// Only access network resources on the local host
504     bool _localhostOnly;
505 
506     /// Show the mouse pointer
507     bool _showMouse;
508 
509     /// Allowed domains
510     PathList _whitelist;
511 
512     /// Blocked Domains
513     PathList _blacklist;
514 
515     /// The name of the debug log
516     std::string _log;
517 
518     /// Enable writing the debug log to disk
519     bool _writeLog;
520 
521     /// The root path for the streaming server
522     std::string _wwwroot;
523 
524     /// the number of retries for a thread
525     int _retries;
526 
527     /// Enable the sound handler at startup
528     bool _sound;
529 
530     /// Enable sound for the plugin
531     bool _pluginSound;
532 
533     /// Enable scanning plugin path for extensions
534     bool _extensionsEnabled;
535 
536     /// Start the gui in "stop" mode
537     bool _startStopped;
538 
539     /// Allow SSL connections without verifying the certificate
540     bool _insecureSSL;
541 
542     /// The number of seconds of inactivity triggering download timeout
543     double _streamsTimeout;
544 
545     /// \brief Local sandbox: the set of resources on the
546     /// filesystem we want to give the current movie access to.
547     PathList _localSandboxPath;
548 
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;
552 
553     /// Whether SOL files can be written
554     bool _solreadonly;
555     bool _sollocaldomain;
556 
557     // Disable local connection
558     bool _lcdisabled;
559 
560     /// Trace local connection activity (in log)
561     bool _lctrace;
562 
563     /// Shared memory segment key (can be set for
564     /// compatibility with other players.)
565     std::uint32_t _lcshmkey;
566 
567     /// Whether the player should respond to fscommands
568     /// (showmenu, quit etc)
569     bool _ignoreFSCommand;
570 
571     /// The quality to display SWFs in. -1 to allow the SWF to override.
572     int _quality;
573 
574     bool _saveStreamingMedia;
575 
576     bool _saveLoadedMedia;
577 
578     std::string _mediaCacheDir;
579 
580     bool _popups;
581 
582     ///FIXME: this should probably eventually be changed to a more readable
583     ///config option instead of an integer
584     int _webcamDevice;
585 
586     int _microphoneDevice;
587 
588     /// \var _certfile
589     ///		This is the name of the client certificate file
590     std::string _certfile;
591 
592     /// \var _certdir
593     ///		This is the path to the directory containing cert files
594     std::string _certdir;
595 
596     /// \var _rootcert
597     ///		This is the name of the root certificate
598     std::string _rootcert;
599 
600     /// Whether the player will recognize changes to Stage.showMenu in AS
601     /// default value is true
602     bool _ignoreShowMenu;
603 
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;
608 
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;
613 
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;
617 
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;
621 
622     /// The max actionscript function call stack depth
623     int _scriptsRecursionLimit;
624 
625     /// Whether to ignore SWF ScriptLimits tags
626     bool _lockScriptLimits;
627 };
628 
629 // End of gnash namespace
630 }
631 
632 #endif
633 
634 
635 // local Variables:
636 // mode: C++
637 // indent-tabs-mode: t
638 // End:
639