Import upstream 0.7.1
[manu/suphp.git] / src / Configuration.cpp
index f75170b..280af5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
+    suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
 
     This file is part of suPHP.
 
@@ -33,51 +33,51 @@ bool suPHP::Configuration::strToBool(const std::string& bstr) const
     std::string str = bstr;
     // Convert upper characters to lower characters
     for (int i=0; i<str.size(); i++) {
-       if (str[i] >= 65 && str[i] <= 90)
-           str[i] += 32;
+        if (str[i] >= 65 && str[i] <= 90)
+            str[i] += 32;
     }
 
     if (str == std::string("true")) {
-       return true;
+        return true;
     } else if (str == std::string("yes")) {
-       return true;
+        return true;
     } else if (str == std::string("on")) {
-       return true;
+        return true;
     } else if (str == std::string("enabled")) {
-       return true;
+        return true;
     } else if (str == std::string("1")) {
-       return true;
+        return true;
     } else if (str == std::string("false")) {
-       return false;
+        return false;
     } else if (str == std::string("no")) {
-       return false;
+        return false;
     } else if (str == std::string("off")) {
-       return false;
+        return false;
     } else if (str == std::string("disabled")) {
-       return false;
+        return false;
     } else if (str == std::string("0")) {
-       return false;
+        return false;
     } else {
-       throw ParsingException("\"" + str + "\" is not a valid boolean value",
-                              __FILE__, __LINE__);
+        throw ParsingException("\"" + str + "\" is not a valid boolean value",
+                               __FILE__, __LINE__);
     }
-       
+        
 }
 
 
 LogLevel suPHP::Configuration::strToLogLevel(const std::string& str) const
     throw (ParsingException) {
     if (str == "none")
-       return LOGLEVEL_NONE;
+        return LOGLEVEL_NONE;
     else if (str == "error")
-       return LOGLEVEL_ERROR;
+        return LOGLEVEL_ERROR;
     else if (str == "warn")
-       return LOGLEVEL_WARN;
+        return LOGLEVEL_WARN;
     else if (str == "info")
-       return LOGLEVEL_INFO;
+        return LOGLEVEL_INFO;
     else
-       throw ParsingException("\"" + str + "\" is not a valid log level",
-                              __FILE__, __LINE__);
+        throw ParsingException("\"" + str + "\" is not a valid log level",
+                               __FILE__, __LINE__);
 }
 
 suPHP::Configuration::Configuration() {
@@ -87,7 +87,7 @@ suPHP::Configuration::Configuration() {
 #else
     this->webserver_user = "wwwrun";
 #endif
-    this->docroot = "/";
+    this->docroots.push_back("/");
     this->allow_file_group_writeable = false;
     this->allow_directory_group_writeable = false;
     this->allow_file_others_writeable = false;
@@ -119,64 +119,64 @@ void suPHP::Configuration::readFromFile(File& file)
     IniFile ini;
     ini.parse(file);
     if (ini.hasSection("global")) {
-       IniSection& sect = ini.getSection("global");
-       std::vector<std::string> keys = sect.getKeys();
-       std::vector<std::string>::iterator i;
-       for (i = keys.begin(); i < keys.end(); i++) {
-           std::string key = *i;
-           std::string value = sect.getValue(key);
-
-           if (key == "logfile")
-               this->logfile = value;
-           else if (key == "webserver_user")
-               this->webserver_user = value;
-           else if (key == "docroot")
-               this->docroot = value;
-           else if (key == "allow_file_group_writeable")
-               this->allow_file_group_writeable = this->strToBool(value);
-           else if (key == "allow_directory_group_writeable")
-               this->allow_directory_group_writeable = this->strToBool(value);
-           else if (key == "allow_file_others_writeable")
-               this->allow_file_others_writeable = this->strToBool(value);
-           else if (key == "allow_directory_others_writeable")
-               this->allow_directory_others_writeable = 
-                   this->strToBool(value);
-           else if (key == "check_vhost_docroot")
-               this->check_vhost_docroot = this->strToBool(value);
-           else if (key == "errors_to_browser")
-               this->errors_to_browser = this->strToBool(value);
-           else if (key == "env_path")
-               this->env_path = value;
-           else if (key == "loglevel")
-               this->loglevel = this->strToLogLevel(value);
-           else if (key == "min_uid")
-               this->min_uid = Util::strToInt(value);
-           else if (key == "min_gid")
-               this->min_gid = Util::strToInt(value);
-           else if (key == "umask")
-               this->umask = Util::octalStrToInt(value);
-           else if (key == "chroot")
-               this->chroot_path = value;
-           else 
-               throw ParsingException("Unknown option \"" + key + 
-                                      "\" in section [global]", 
-                                      __FILE__, __LINE__);
-       }
+        const IniSection& sect = ini.getSection("global");
+        const std::vector<std::string> keys = sect.getKeys();
+        std::vector<std::string>::const_iterator i;
+        for (i = keys.begin(); i < keys.end(); i++) {
+            std::string key = *i;
+            std::string value = sect.getValue(key);
+
+            if (key == "logfile")
+                this->logfile = value;
+            else if (key == "webserver_user")
+                this->webserver_user = value;
+            else if (key == "docroot") {
+                this->docroots = sect.getValues(key);
+            } else if (key == "allow_file_group_writeable")
+                this->allow_file_group_writeable = this->strToBool(value);
+            else if (key == "allow_directory_group_writeable")
+                this->allow_directory_group_writeable = this->strToBool(value);
+            else if (key == "allow_file_others_writeable")
+                this->allow_file_others_writeable = this->strToBool(value);
+            else if (key == "allow_directory_others_writeable")
+                this->allow_directory_others_writeable = 
+                    this->strToBool(value);
+            else if (key == "check_vhost_docroot")
+                this->check_vhost_docroot = this->strToBool(value);
+            else if (key == "errors_to_browser")
+                this->errors_to_browser = this->strToBool(value);
+            else if (key == "env_path")
+                this->env_path = value;
+            else if (key == "loglevel")
+                this->loglevel = this->strToLogLevel(value);
+            else if (key == "min_uid")
+                this->min_uid = Util::strToInt(value);
+            else if (key == "min_gid")
+                this->min_gid = Util::strToInt(value);
+            else if (key == "umask")
+                this->umask = Util::octalStrToInt(value);
+            else if (key == "chroot")
+                this->chroot_path = value;
+            else 
+                throw ParsingException("Unknown option \"" + key + 
+                                       "\" in section [global]", 
+                                       __FILE__, __LINE__);
+        }
     }
     
     // Get handlers / interpreters
     if (ini.hasSection("handlers")) {
-       IniSection sect = ini.getSection("handlers");
-       std::vector<std::string> keys = sect.getKeys();
-       std::vector<std::string>::iterator i;
-       for (i = keys.begin(); i < keys.end(); i++) {
-           std::string key = *i;
-           std::string value = sect.getValue(key);
-           std::pair<std::string, std::string> p;
-           p.first = key;
-           p.second = value;
-           this->handlers.insert(p);
-       }
+        IniSection sect = ini.getSection("handlers");
+        const std::vector<std::string> keys = sect.getKeys();
+        std::vector<std::string>::const_iterator i;
+        for (i = keys.begin(); i < keys.end(); i++) {
+            std::string key = *i;
+            std::string value = sect.getValue(key);
+            std::pair<std::string, std::string> p;
+            p.first = key;
+            p.second = value;
+            this->handlers.insert(p);
+        }
     }
     
 }
@@ -193,8 +193,8 @@ std::string suPHP::Configuration::getWebserverUser() const {
     return this->webserver_user;
 }
 
-std::string suPHP::Configuration::getDocroot() const {
-    return this->docroot;
+const std::vector<std::string>& suPHP::Configuration::getDocroots() const {
+    return this->docroots;
 }
 
 bool suPHP::Configuration::getCheckVHostDocroot() const {
@@ -228,10 +228,10 @@ std::string suPHP::Configuration::getEnvPath() const {
 std::string suPHP::Configuration::getInterpreter(std::string handler) const 
     throw (KeyNotFoundException) {
     if (this->handlers.find(handler) != this->handlers.end()) {
-       return this->handlers.find(handler) -> second;
+        return this->handlers.find(handler) -> second;
     } else {
-       throw KeyNotFoundException("Handler \"" + handler + "\" not found",
-                                  __FILE__, __LINE__);
+        throw KeyNotFoundException("Handler \"" + handler + "\" not found",
+                                   __FILE__, __LINE__);
     }
 }