/*
	ZazouMiniWebServer

	Copyright (C) 2003-2011 Xavier Garreau <xavier@xgarreau.org>

	This file is part of ZazouMiniWebServer.

    ZazouMiniWebServer is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    ZazouMiniWebServer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ZazouMiniWebServer; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
	
#ifndef _ZMWS_CONFFILEPARSER_H
#define _ZMWS_CONFFILEPARSER_H 1

#include <vector>
#include <string>
#include <fstream>
#include "ZMWSConfig.h"
#include "ZMWSmime.h"

class ZMWSConfFileParser
{
	std::ifstream conf_file;
	std::string curr_config_context;

	void PrintError(const std::string& option, const std::string& error_text);
	void PrintWarning(const std::string& warning_text);

	BOOL GetConfigVar(std::string& var, std::string& val);
	BOOL HandleVar(ZMWSConfig& config, ZMWSMIME& mime_manager, std::string& var, std::string& val);

	BOOL MainApplyVar(ZMWSConfig& config, const std::string& var, const std::string& val);
	BOOL MimeApplyVar(ZMWSMIME& mime_manager, const std::string& var, const std::string& val);
	BOOL HandlerApplyVar(ZMWSConfig& config, const std::string& var, const std::string& val);
	BOOL TRUECGIHandlerApplyVar(ZMWSConfig& config, const std::string& var, const std::string& val);
	BOOL ZMWSSAPIHandlerApplyVar(ZMWSConfig& config, const std::string& var, const std::string& val);
	BOOL VHostApplyVar(ZMWSConfig& config, const std::string& vhost, const std::string& var, const std::string& val);
	BOOL PerUrlApplyVar(ZMWSConfig& config, const std::string& url, const std::string& var, const std::string& val);

public: 
	ZMWSConfFileParser() {};
	~ZMWSConfFileParser() {};
	BOOL Parse(ZMWSConfig& config, ZMWSMIME& mime_manager, const char* filepath = NULL);
};

#endif

