/* Cfour (C++ Common Console Classes) CgiParser
 * Copyright (C)2001, (C)2002 Jeffrey Bakker

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser 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


 *  Author:              Jeffrey Bakker <jefskey@yahoo.com>
 *  Filename:            cgiparser.h
 *  File version:        1.0.0
 *
 *  REMARK ====================================================================
 *  ===========================================================================

        This is the definition file for the CgiParser class. CgiParser is a Cgi
        parser library written in C++, which can be used as a stream class,
        thanks to operator overloading.

        CgiParser supports both GET and POST methods, and does so automatically
        just as it does for everything else.

        All one has to do to write cgi programs using this library is the
        include this header, and create an object of this class. The object can
        be used with the << operator to print variables from HTML forms.

 *  CHANGELOG =================================================================
 *  ===========================================================================
 *
 *  Created on:         October 10th, 2002
 *
 *  Last Modified on:   December 27th, 2002
 *
 *      - The methods InitData(), get_query(), get_stdin(), parse_spaces(),
 *        decode_hex(), split_data(), & asmhex() are now all protected, since
 *        they shall never be called by the programmer.
 *
 *  ===========================================================================
 * _______. ..
 */

#ifndef _C4_CGI_PARSER_H 
#define _C4_CGI_PARSER_H 

#define  BLANK "\0" 

#ifndef  DEBUG_CGI_TRACE 
#define  DEBUG_CGI_TRACE false 
#endif   // DEBUG_CGI_TRACE 

#include <vector> 
#include <string> 
#include <cstdlib> 
#include <iostream> 

using namespace std;
/*
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
*/
struct DataPair
{
	string	Name;
	string	Value;
};

class CgiParser {

 public:
	CgiParser();

	// Useful methods to be called by the programmer -----------------------------
	bool	is_empty();
	string	get_value(string);
	void	print_error(string,string);

	// Use as a stream class to easily print form variables
	CgiParser& operator<<(string name);
	CgiParser& operator>>(string &name);

	// Overload output stream on other data types
	CgiParser& operator<<(int    data) {cout<<data;return *this;}
	CgiParser& operator<<(long   data) {cout<<data;return *this;}
	CgiParser& operator<<(float  data) {cout<<data;return *this;}
	CgiParser& operator<<(double data) {cout<<data;return *this;}
	CgiParser& operator<<(char   data) {cout<<data;return *this;}
	// ---------------------------------------------------------------------------

 protected:

	// Automatically called ------------------------------------------------------
	bool	InitData();		// these
	void	get_query();		// methods
	void	get_stdin();		// should
	void	parse_spaces();		// never
	void	decode_hex(string&);	// be
	void	split_data();		// called
	inline	char asmhex(char);	// manually
	// for cgi decoding ----------------------------------------------------------


	vector<DataPair> CgiData;	// decoded name/value pairs
	string QStr;			// query string

	bool first_print;		// print 'Content-type' flag
};

#endif  // _C4_CGI_PARSER_H 




w e b c p p
web c plus plus