// Copyright (c) 1999-2001 David Muse
// See the COPYING file for more information

#ifndef CGI_H
#define CGI_H

#include <inputoutput.h>
#include <http.h>
#include <private/cookieentry.h>
#include <private/formentry.h>
#include <private/fileentry.h>

// The cgi class provides functions to access cgi environment variables,
// form variables, cookies and multipart form submissions as well as
// the sending of a standard text/html header.

// CGI 1.1
class   cgi : public inputoutput {
        public:
                        cgi(void *apistruct);
                        // form entries, cookies and uploaded files 
                        // are put into lists and copies of the 
                        // uploaded files are saved into a tempdir
                virtual ~cgi();

                // convenience functions
                void    sendHeader();
                                // sends Content type: text/html
                
                // form entry handling functions
                char    *formEntry(char *name);
                                // returns the value of form entry: name
                void    writeFormEntry(char *name);
                                // writes form entry: name to the browser
                void    formEntriesGetString(strstream *container, ...);
                                // Returns all form entries formatted as an
                                // escaped get string into "container" with the 
                                // exception of a NULL terminated list of 
                                // exceptions.
                                // If "container" is NULL, the list is written
                                // to the browser.
                                // "container" is not NULL terminated.
                void    formEntriesHiddenVariables(strstream *container, ...);
                                // Returns all form entries formatted as a
                                // list of hidden variables into "container"
                                // with the exception of a NULL terminated 
                                // list of exceptions passed in after
                                // "container".
                                // If "container" is NULL, the list is written
                                // to the browser.
                                // "container" is not NULL terminated.
                char    **formEntryVariables();
                                // Returns a null terminated list of form 
                                // entry variables.  The order of the list is
                                // the order the variables were received in.
                char    **formEntryValues();
                                // Returns a null terminated list of form 
                                // entry values corresponding to the variables
                                // returned from formEntryVariables().
                char    *fileEntryFilename(char *name);
                                // returns the filename passed in from 
                                // file form entry "name"
                char    *fileEntryTempFilename(char *name);
                                // returns the filename of the local file
                                // created when file form entry "name" was
                                // passed in
                void    dumpVariables();
                                // dumps all environment variable, form entries,
                                // file entries, and cookies to the browser
                void    newFormEntry(char *name, char *value);
                                // create a new form entry with
                                // name: "name" and value: "value"
                int     changeFormEntry(char *name, char *value);
                                // change existing form entry: "name" to have
                                // value: "value"
                                // if the form entry exists, 1 is returned
                                // otherwise 0 is returned
                void    newFileEntry(char *name, char *filename, 
                                                char *tempfilename);
                                // create a new file form entry with
                                // name: "name", filename: "filename", and 
                                // temporary filename: "tempfilename"
                                // if the form entry doesn't already exist,
                                // no action is taken
                void    newCookieEntry(char *name, char *value);
                                // create a new cookie entry with
                                // name: "name" and value: "value"
                char    *cookieEntry(char *name);
                                // returns the value of cookie entry: "name"
                void    writeCookieEntry(char *name);
                                // writes cookie entry: "name" to the browser

                int     formEntryCount();
                                // returns the number of form entries
                int     fileCount();
                                // returns the number of posted files
                int     cookieCount();
                                // returns the number of cookies collected

        private:
                #include <private/cgi.h>
};


#endif