00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "ServerHandler.h"
00026
00027
00028
00029
00030 ServerHandler::ServerHandler(const std::string& filename)
00031 :SocketHandler()
00032 ,m_config(filename)
00033 ,m_db(GetString("database/host"),GetString("database/user"),GetString("database/password"),GetString("database/database"))
00034 ,m_mime(GetString("mime/filename"))
00035 {
00036 }
00037
00038
00039 ServerHandler::~ServerHandler()
00040 {
00041 }
00042
00043
00044 int ServerHandler::GetInt(const std::string& path)
00045 {
00046 xmlNodePtr p = m_config.Find(m_config.GetRootElement(),path);
00047 if (p)
00048 {
00049 m_config.SetCurrent(p);
00050 std::string str = m_config.GetProperty("value");
00051 return atoi(str.c_str());
00052 }
00053 else
00054 {
00055 fprintf(stderr,"config path not found: %s\n",path.c_str());
00056 }
00057 return 0;
00058 }
00059
00060
00061 std::string ServerHandler::GetString(const std::string& path)
00062 {
00063 xmlNodePtr p = m_config.Find(m_config.GetRootElement(),path);
00064 if (p)
00065 {
00066 m_config.SetCurrent(p);
00067 std::string str = m_config.GetProperty("value");
00068 return str;
00069 }
00070 fprintf(stderr,"config path not found: %s\n",path.c_str());
00071 return "";
00072 }
00073
00074
00075 bool ServerHandler::GetBoolean(const std::string& path)
00076 {
00077 xmlNodePtr p = m_config.Find(m_config.GetRootElement(),path);
00078 std::string str;
00079 if (p)
00080 {
00081 m_config.SetCurrent(p);
00082 str = m_config.GetProperty("value");
00083 if (str.size() && (str[0] == '1' ||
00084 str[0] == 'y' || str[0] == 'Y' ||
00085 str[0] == 't' || str[0] == 'T'))
00086 {
00087 return true;
00088 }
00089 return false;
00090 }
00091 fprintf(stderr,"config path not found: %s\n",path.c_str());
00092 return false;
00093 }
00094
00095
00096 std::string ServerHandler::GetMimetype(const std::string& ext)
00097 {
00098 return m_mime.GetMimeFromExtension(ext);
00099 }
00100
00101