Avoid overriding the check-local rule, hushing automake warning
[gnash.git] / cygnal / crc.cpp
blob54b0e206eb75e1680b2f1347c81eb7260a46a9ba
1 // rc.cpp: "Run Command" configuration file, 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.
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
21 // This is generated by autoconf
22 #ifdef HAVE_CONFIG_H
23 # include "gnashconfig.h"
24 #endif
26 #include "StringPredicates.h"
27 #include "log.h"
28 #include "crc.h"
30 #ifdef HAVE_PWD_H
31 # include <pwd.h>
32 #endif
34 #include <sys/types.h>
35 #include "GnashSystemIOHeaders.h" // for getuid()
36 #include <sys/stat.h>
37 #include <boost/cstdint.hpp>
39 #include <cctype> // for toupper
40 #include <string>
41 #include <vector>
42 #include <iostream>
43 #include <fstream>
45 using namespace std;
46 using namespace gnash;
48 /// \namespace cygnal
49 /// This namespace is for all the Cygnal specific classes.
50 namespace cygnal {
52 /// \brief Return the default instance of RC file,
53 CRcInitFile&
54 CRcInitFile::getDefaultInstance()
56 // TODO: allocate on the heap and provide a destroyDefaultInstance,
57 // for finer control of destruction order
58 static CRcInitFile crcfile;
59 return crcfile;
62 CRcInitFile::CRcInitFile()
63 : _port_offset(0),
64 _testing(false),
65 _threading(false),
66 _fdthread(100),
67 _netdebug(false),
68 _admin(false),
69 _certfile("server.pem"),
70 _certdir("/etc/pki/tls")
72 // GNASH_REPORT_FUNCTION;
73 loadFiles();
76 //Never destroy (TODO: add a destroyDefaultInstance)
77 CRcInitFile::~CRcInitFile()
79 // GNASH_REPORT_FUNCTION;
82 /// \brief Load all the configuration files.
83 /// This includes parsing the default .gnashrc file for
84 /// Gnash settings that control the swf parser and virtual
85 /// machine. These setting can be overridden in the
86 /// .cygnalrc file, plus the Cygnal specific file has
87 /// options only used by Cygnal.
88 bool
89 CRcInitFile::loadFiles()
91 // GNASH_REPORT_FUNCTION;
93 // Check the default system location
94 string loadfile = "/etc/cygnalrc";
95 parseFile(loadfile);
97 // Check the default config location
98 loadfile = "/usr/local/etc/cygnalrc";
99 parseFile(loadfile);
101 // Check the users home directory
102 char *home = getenv("HOME");
103 if (home) {
104 loadfile = home;
105 loadfile += "/.cygnalrc";
106 parseFile(loadfile);
109 // Check the GNASHRC environment variable
110 char *cygnalrc = getenv("CYGNALRC");
111 if (cygnalrc) {
112 loadfile = cygnalrc;
113 return parseFile(loadfile);
116 return false;
119 /// \brief Parse and load configuration file
121 /// @param filespec The path and file name of the disk file to parse.
123 /// @return True if the file was parsed successfully, false if not.
124 bool
125 CRcInitFile::parseFile(const std::string& filespec)
127 // GNASH_REPORT_FUNCTION;
128 struct stat stats;
129 string action;
130 string variable;
131 string value;
132 ifstream in;
134 StringNoCaseEqual noCaseCompare;
136 // log_debug ("Seeing if %s exists", filespec);
137 if (filespec.size() == 0) {
138 return false;
141 if (stat(filespec.c_str(), &stats) == 0) {
142 in.open(filespec.c_str());
144 if (!in) {
145 log_error(_("Couldn't open file: %s"), filespec.c_str());
146 return false;
149 // Read in each line and parse it
150 do {
152 // Make sure action is empty, otherwise the last loop (with no new
153 // data) keeps action, variable and value from the previous loop. This
154 // causes problems if set blacklist or set whitelist are last, because
155 // value is erased while parsing and the lists are thus deleted.
156 action.clear();
158 // Get the first token
159 in >> action;
161 // Ignore comment lines
162 if (action[0] == '#') {
163 // suck up the rest of the line
164 char name[128];
165 in.getline(name, 128);
166 continue;
169 // Get second token
170 in >> variable;
172 // cout << "Parsing " << variable << endl;
174 // Read in rest of line for parsing.
175 getline(in, value);
177 // Erase leading spaces.
178 string::size_type position = value.find_first_not_of(' ');
179 if(position != string::npos) value.erase(0, position);
181 if (noCaseCompare(variable, "debuglog")) {
182 expandPath (value);
183 setDebugLog(value);
184 continue;
187 if (noCaseCompare(variable, "documentroot") ) {
188 setDocumentRoot(value);
189 continue;
192 if (noCaseCompare(variable, "cgiroot") ) {
193 setCgiRoot(value);
194 continue;
197 if (noCaseCompare(variable, "documentroot") ) {
198 _wwwroot = value;
199 continue;
202 if (noCaseCompare(variable, "CertDir") ) {
203 expandPath(value);
204 _certdir = value;
205 continue;
208 if (noCaseCompare(variable, "CertFile") ) {
209 expandPath(value);
210 _certfile = value;
211 continue;
214 bool test;
215 bool threads;
216 bool netdebug;
217 bool admin;
218 uint32_t num;
220 // Get the standard options inherited froom Gnash's config file
221 if ( extractSetting(test, "actionDump", variable, value) )
222 useParserDump(test);
223 else if ( extractSetting(test, "parserDump", variable, value) )
224 useActionDump(test);
225 else if ( extractNumber(num, "verbosity", variable, value) )
226 verbosityLevel(num);
228 // Get the options specific to Cygnal's config file.
229 else if ( extractSetting(admin, "admin", variable, value) )
230 setAdminFlag(admin);
231 else if ( extractSetting(netdebug, "netdebug", variable, value) )
232 setNetDebugFlag(netdebug);
233 else if ( extractSetting(test, "testing", variable, value) )
234 setTestingFlag(test);
235 else if ( extractSetting(threads, "threading", variable, value) )
236 setThreadingFlag(threads);
237 else if (extractNumber(num, "fdThread", variable, value) )
238 setFDThread(num);
239 else if (extractNumber(num, "portOffset", variable, value) )
240 setPortOffset(num);
242 } while (!in.eof());
244 } else {
245 if (in) {
246 in.close();
248 return false;
251 if (in) {
252 in.close();
255 return true;
258 /// \brief Dump the internal data of this class in a human readable form.
259 /// @remarks This should only be used for debugging purposes.
260 void
261 CRcInitFile::dump(std::ostream& os) const
263 os << endl << "Dump CRcInitFile:" << endl;
264 os << "\tVerbosity Level: " << _verbosity << endl;
265 os << "\tDump ActionScript processing: "
266 << ((_actionDump)?"enabled":"disabled") << endl;
267 os << "\tDump parser info: "
268 << ((_parserDump)?"enabled":"disabled") << endl;
269 os << "\tActionScript coding errors verbosity: "
270 << ((_verboseASCodingErrors)?"enabled":"disabled") << endl;
271 os << "\tPort Offset: " << _port_offset << endl;
272 os << "\tThreading support: "
273 << ((_threading)?"enabled":"disabled") << endl;
274 os << "\tSpecial Testing output for Gnash: "
275 << ((_testing)?"enabled":"disabled") << endl;
277 // RcInitFile::dump();
280 } // end of namespace cygnal
282 // local Variables:
283 // mode: C++
284 // indent-tabs-mode: t
285 // End: