/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CHttpParams.h  -  description
                             -------------------
    begin                : July 22 2003
    copyright            : (C) 2003 by Alexey Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

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

   This library 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 Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifndef __CHTTPPARAMS_H__
#define __CHTTPPARAMS_H__

#include <sptk3/sptk.h>
#include <sptk3/CBuffer.h>
#include <sptk3/istring.h>

#include <string>
#include <map>

namespace sptk {

   /// @addtogroup utility Utility Classes
   /// @{

   /// HTTP fields are implemented as case-insensitive map
	typedef std::map<istring,std::string> CStringHttpFieldMap;

   /// @brief HTTP params map
   ///
   /// Designed to hold HTTP parametrs in
   /// CHttpConnect and CCgiApplication. It is, basically, a string-to-string
   /// map with an addition of encode and decode functions for HTTP Mime.
	class CHttpParams : public CStringHttpFieldMap {
      /// Encodes a string into HTML parameters
		static std::string encodeString(std::string& str);

      /// Decodes a string from HTML parameters
		static std::string decodeString(std::string& str);
	public:
      /// Default constructor.
		CHttpParams() : CStringHttpFieldMap() {}

      /// Encodes HTTP parameters for sending to the server.
      /// @param result CBuffer&, output - encoded parameters string (if any) as the buffer.
		void encode(CBuffer& result);

      /// Decodes HTTP parameters that came from the server as a string
      /// into parameters map.
      /// @param paramString CBuffer, parameters string from HTTP server
      /// @param lowerCaseNames bool, true if you want to lower-case the parameter names
		void decode(const CBuffer& paramString,bool lowerCaseNames=false);
	};
   /// @}
}
#endif
