Logo
~Sockets~
~Examples~
~Contact~


ServerHandler.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 //#include <stdio.h>
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 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4