[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2816] refactored configuration file loading methods
From: |
Daniele Perrone |
Subject: |
[myserver-commit] [2816] refactored configuration file loading methods |
Date: |
Sun, 14 Sep 2008 22:00:20 +0000 |
Revision: 2816
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2816
Author: dperrone
Date: 2008-09-14 22:00:18 +0000 (Sun, 14 Sep 2008)
Log Message:
-----------
refactored configuration file loading methods
Modified Paths:
--------------
trunk/myserver/include/server/server.h
trunk/myserver/src/server/server.cpp
Modified: trunk/myserver/include/server/server.h
===================================================================
--- trunk/myserver/include/server/server.h 2008-09-14 21:14:44 UTC (rev
2815)
+++ trunk/myserver/include/server/server.h 2008-09-14 22:00:18 UTC (rev
2816)
@@ -224,6 +224,11 @@
int freeHashedData();
u_long connectionTimeout;
u_long maxLogFileSize;
+ int loadMainConfFilesLocation();
+ int loadVHostConfFilesLocation();
+ int loadMimeConfFilesLocation();
+ int loadExternalPath();
+ int loadLanguagesPath();
int loadConfFilesLocation();
Mutex* connectionsMutex;
u_long nStaticThreads;
Modified: trunk/myserver/src/server/server.cpp
===================================================================
--- trunk/myserver/src/server/server.cpp 2008-09-14 21:14:44 UTC (rev
2815)
+++ trunk/myserver/src/server/server.cpp 2008-09-14 22:00:18 UTC (rev
2816)
@@ -1535,20 +1535,15 @@
}
/*!
- *Load the configuration files locations.
+ *Load the main configuration files locations.
*Return nonzero on errors.
*/
-int Server::loadConfFilesLocation()
+int Server::loadMainConfFilesLocation()
{
- string strCPU;
- char buffer[512];
- u_long nbr, nbw;
- char* data;
int ret;
-
try
{
- if(mainConfigurationFile)
+ if (mainConfigurationFile)
delete mainConfigurationFile;
mainConfigurationFile = new string();
@@ -1561,39 +1556,38 @@
*3) /etc/myserver/
*4) default files will be copied in myserver executable working
*/
- if(FilesUtility::fileExists("myserver.xml"))
+ if (FilesUtility::fileExists("myserver.xml"))
{
mainConfigurationFile->assign("myserver.xml");
}
- else if(FilesUtility::fileExists("~/.myserver/myserver.xml"))
+ else if (FilesUtility::fileExists("~/.myserver/myserver.xml"))
{
mainConfigurationFile->assign("~/.myserver/myserver.xml");
}
- else if(FilesUtility::fileExists("/etc/myserver/myserver.xml"))
+ else if (FilesUtility::fileExists("/etc/myserver/myserver.xml"))
{
mainConfigurationFile->assign("/etc/myserver/myserver.xml");
}
else
#endif
/* If the myserver.xml files doesn't exist copy it from the default one.
*/
- if(mainConfigurationFile->length() == 0)
+ if (mainConfigurationFile->length() == 0)
{
mainConfigurationFile->assign("myserver.xml");
File inputF;
File outputF;
- ret = inputF.openFile("myserver.xml.default",
- File::MYSERVER_OPEN_READ |
- File::MYSERVER_OPEN_IFEXISTS);
- if(ret)
+ ret = inputF.openFile("myserver.xml.default", File::MYSERVER_OPEN_READ
+ | File::MYSERVER_OPEN_IFEXISTS);
+ if (ret)
{
logPreparePrintError();
logWriteln("Error loading configuration file\n");
logEndPrintError();
return -1;
}
- ret = outputF.openFile("myserver.xml", File::MYSERVER_OPEN_WRITE |
- File::MYSERVER_OPEN_ALWAYS);
- if(ret)
+ ret = outputF.openFile("myserver.xml", File::MYSERVER_OPEN_WRITE
+ | File::MYSERVER_OPEN_ALWAYS);
+ if (ret)
{
logPreparePrintError();
logWriteln("Error loading configuration file\n");
@@ -1601,7 +1595,7 @@
return -1;
}
- FilesUtility::copyFile(inputF,outputF);
+ FilesUtility::copyFile(inputF, outputF);
inputF.closeFile();
outputF.closeFile();
@@ -1610,8 +1604,24 @@
{
mainConfigurationFile->assign("myserver.xml");
}
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
- if(mimeConfigurationFile)
+
+/*!
+ *Load the mime configuration files locations.
+ *Return nonzero on errors.
+ */
+int Server::loadMimeConfFilesLocation()
+{
+ int ret;
+ try
+ {
+ if (mimeConfigurationFile)
delete mimeConfigurationFile;
mimeConfigurationFile = new string();
@@ -1624,21 +1634,67 @@
*3) /etc/myserver/
*4) default files will be copied in myserver executable working
*/
- if(FilesUtility::fileExists("MIMEtypes.xml"))
+ if (FilesUtility::fileExists("MIMEtypes.xml"))
{
mimeConfigurationFile->assign("MIMEtypes.xml");
}
- else if(FilesUtility::fileExists("~/.myserver/MIMEtypes.xml"))
+ else if (FilesUtility::fileExists("~/.myserver/MIMEtypes.xml"))
{
mimeConfigurationFile->assign("~/.myserver/MIMEtypes.xml");
}
- else if(FilesUtility::fileExists("/etc/myserver/MIMEtypes.xml"))
+ else if (FilesUtility::fileExists("/etc/myserver/MIMEtypes.xml"))
{
mimeConfigurationFile->assign("/etc/myserver/MIMEtypes.xml");
}
+ else
#endif
+ /*
+ *If the MIMEtypes.xml files doesn't exist copy it
+ *from the default one.
+ */
+ if (mimeConfigurationFile->length() == 0)
+ {
+ File inputF;
+ File outputF;
+ mimeConfigurationFile->assign("MIMEtypes.xml");
+ ret = inputF.openFile("MIMEtypes.xml.default", File::MYSERVER_OPEN_READ
+ | File::MYSERVER_OPEN_IFEXISTS);
+ if (ret)
+ {
+ logPreparePrintError();
+ logWriteln(languageParser.getValue("ERR_LOADMIME"));
+ logEndPrintError();
+ return -1;
+ }
+ ret = outputF.openFile("MIMEtypes.xml", File::MYSERVER_OPEN_WRITE
+ | File::MYSERVER_OPEN_ALWAYS);
+ if (ret)
+ return -1;
- if(vhostConfigurationFile)
+ FilesUtility::copyFile(inputF, outputF);
+
+ inputF.closeFile();
+ outputF.closeFile();
+ }
+
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
+
+
+/*!
+ *Load the vhost configuration files locations.
+ *Return nonzero on errors.
+ */
+int Server::loadVHostConfFilesLocation()
+{
+ int ret;
+ try
+ {
+ if (vhostConfigurationFile)
delete vhostConfigurationFile;
vhostConfigurationFile = new string();
@@ -1651,33 +1707,77 @@
*3) /etc/myserver/
*4) default files will be copied in myserver executable working
*/
- if(FilesUtility::fileExists("virtualhosts.xml"))
+ if (FilesUtility::fileExists("virtualhosts.xml"))
{
vhostConfigurationFile->assign("virtualhosts.xml");
}
- else if(FilesUtility::fileExists("~/.myserver/virtualhosts.xml"))
+ else if (FilesUtility::fileExists("~/.myserver/virtualhosts.xml"))
{
vhostConfigurationFile->assign("~/.myserver/virtualhosts.xml");
}
- else if(FilesUtility::fileExists("/etc/myserver/virtualhosts.xml"))
+ else if (FilesUtility::fileExists("/etc/myserver/virtualhosts.xml"))
{
vhostConfigurationFile->assign("/etc/myserver/virtualhosts.xml");
}
+ else
#endif
+ /*
+ *If the virtualhosts.xml file doesn't exist copy it
+ *from the default one.
+ */
+ if (vhostConfigurationFile->length() == 0)
+ {
+ File inputF;
+ File outputF;
- if(externalPath)
+ vhostConfigurationFile->assign("virtualhosts.xml");
+ ret = inputF.openFile("virtualhosts.xml.default",
+ File::MYSERVER_OPEN_READ | File::MYSERVER_OPEN_IFEXISTS);
+ if (ret)
+ {
+ logPreparePrintError();
+ logWriteln(languageParser.getValue("ERR_LOADVHOSTS"));
+ logEndPrintError();
+ return -1;
+ }
+ ret = outputF.openFile("virtualhosts.xml", File::MYSERVER_OPEN_WRITE
+ | File::MYSERVER_OPEN_ALWAYS);
+ if (ret)
+ return -1;
+
+ FilesUtility::copyFile(inputF, outputF);
+
+ inputF.closeFile();
+ outputF.closeFile();
+ }
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
+
+/*!
+ *Load the external path.
+ *Return nonzero on errors.
+ */
+int Server::loadExternalPath()
+{
+ try
+ {
+ if (externalPath)
delete externalPath;
externalPath = new string();
#ifdef NOT_WIN
if(FilesUtility::fileExists("plugins"))
- externalPath->assign("plugins");
+ externalPath->assign("plugins");
else
{
#ifdef PREFIX
externalPath->assign(PREFIX);
externalPath->append("/lib/myserver/plugins");
- #else
+#else
externalPath->assign("/usr/lib/myserver/plugins");
#endif
}
@@ -1687,127 +1787,88 @@
#ifdef WIN32
externalPath->assign("plugins");
#endif
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
- /*
- *If the MIMEtypes.xml files doesn't exist copy it
- *from the default one.
- */
- if(mimeConfigurationFile->length() == 0)
- {
- File inputF;
- File outputF;
- mimeConfigurationFile->assign("MIMEtypes.xml");
- ret = inputF.openFile("MIMEtypes.xml.default",
- File::MYSERVER_OPEN_READ |
- File::MYSERVER_OPEN_IFEXISTS);
- if(ret)
- {
- logPreparePrintError();
- logWriteln(languageParser.getValue("ERR_LOADMIME"));
- logEndPrintError();
- return -1;
- }
- ret = outputF.openFile("MIMEtypes.xml", File::MYSERVER_OPEN_WRITE|
- File::MYSERVER_OPEN_ALWAYS);
- if(ret)
- return -1;
- for(;;)
- {
- ret = inputF.readFromFile(buffer, 512, &nbr );
- if(ret)
- return -1;
- if(nbr == 0)
- break;
- ret = outputF.writeToFile(buffer, nbr, &nbw);
- if(ret)
- return -1;
- }
- inputF.closeFile();
- outputF.closeFile();
- }
+/*!
+ *Load the languages path.
+ *Return nonzero on errors.
+ */
+int Server::loadLanguagesPath()
+{
+ try
+ {
+ if (languagesPath)
+ delete languagesPath;
+ languagesPath = new string();
+
+#ifndef WIN32
/*
- *If the virtualhosts.xml file doesn't exist copy it
- *from the default one.
+ *Do not use the files in the directory /usr/share/myserver/languages
+ *if exists a local directory.
*/
- if(vhostConfigurationFile->length() == 0)
+ if (FilesUtility::fileExists("languages"))
{
- File inputF;
- File outputF;
- vhostConfigurationFile->assign("virtualhosts.xml");
- ret = inputF.openFile("virtualhosts.xml.default",
- File::MYSERVER_OPEN_READ |
- File::MYSERVER_OPEN_IFEXISTS );
- if(ret)
- {
- logPreparePrintError();
- logWriteln(languageParser.getValue("ERR_LOADVHOSTS"));
- logEndPrintError();
- return -1;
- }
- ret = outputF.openFile("virtualhosts.xml",
- File::MYSERVER_OPEN_WRITE |
- File::MYSERVER_OPEN_ALWAYS);
- if(ret)
- return -1;
- for(;;)
- {
- ret = inputF.readFromFile(buffer, 512, &nbr );
- if(ret)
- return -1;
- if(!nbr)
- break;
- ret = outputF.writeToFile(buffer, nbr, &nbw);
- if(ret)
- return -1;
- }
-
- inputF.closeFile();
- outputF.closeFile();
+ languagesPath->assign(getdefaultwd(0, 0));
+ languagesPath->append("/languages/");
}
-
-
- if(languagesPath)
- delete languagesPath;
-
- languagesPath = new string();
-
-#ifndef WIN32
- /*
- *Do not use the files in the directory /usr/share/myserver/languages
- *if exists a local directory.
- */
- if(FilesUtility::fileExists("languages"))
- {
- languagesPath->assign(getdefaultwd(0, 0) );
- languagesPath->append("/languages/");
- }
- else
- {
+ else
+ {
#ifdef PREFIX
- languagesPath->assign(PREFIX);
- languagesPath->append("/share/myserver/languages/");
+ languagesPath->assign(PREFIX);
+ languagesPath->append("/share/myserver/languages/");
#else
/* Default PREFIX is /usr/. */
- languagesPath->assign("/usr/share/myserver/languages/");
+ languagesPath->assign("/usr/share/myserver/languages/");
#endif
}
#endif
#ifdef WIN32
- languagesPath->assign( "languages/" );
+ languagesPath->assign( "languages/" );
#endif
-
}
- catch(...){}
+ catch (...)
+ {
+ }
return 0;
}
/*!
+ *Load the configuration files locations.
+ *Return nonzero on errors.
+ */
+int Server::loadConfFilesLocation()
+{
+ if (loadMainConfFilesLocation())
+ return -1;
+
+ if (loadMimeConfFilesLocation())
+ return -1;
+
+ if (loadVHostConfFilesLocation())
+ return -1;
+
+ if (loadExternalPath())
+ return -1;
+
+ if (loadLanguagesPath())
+ return -1;
+
+ return 0;
+}
+
+
+/*!
*If specified set the uid/gid for the process.
*/
void Server::setProcessPermissions()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2816] refactored configuration file loading methods,
Daniele Perrone <=