FBB::CGI

libbobcat1-dev_3.01.00-x.tar.gz

2005-2012


FBB::CGI(3bobcat)

FBB::CGI(3bobcat)

libbobcat1-dev_3.01.00-x.tar.gz CGI interface

2005-2012

NAME

FBB::CGI - handles GET and POST submitted form data

SYNOPSIS

#include <bobcat/cgi>
Linking option: -lbobcat

DESCRIPTION

The class CGI offers an interface to data submitted by web-forms. The data is sent to a script handling the data using a <form action="/path/to/form/script"> stanza. Very often this is indeed a script, like a Perl script, but there is no need to use a scripting language. The class CGI allows C++ programmers to process the form by an executable usually resulting in faster processing and in construction time benefits from the type safety offered by C++. The class CGI handles data submitted using the GET method as well as data submitted using the POST method automatically.

By default the class's constructor writes the customary Content-type header lines to the standard output stream. Additional (html) output of a reply page must be provided by other code. Therefore, a program processing an uploaded form will have an organization comparable to the following basic setup:


    // assume includes and namespace std/FBB were defined
    int main()
    {
        CGI cgi;
        cout << "<html><body>\n";
        if (parametersOK(cgi))
        {
            process(cgi);     
            generateReplyPage();
        }
        else
            generateErrorPage();
        cout << "</body></html>\n;
    }
        

When errors in the received form-data are detected an error message is written to the standard output stream and an FBB::Errno exception is thrown.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

TYPEDEF

ENUMERATIONS

The CGI::Method enumeration specifies values indicating the way the form's data were submitted:

The CGI::Create enumeration is used to request or suppress creation of the directory to contain any file uploaded by a form:

CONSTRUCTORS

The copy and move constructors are available.

OERLOADED OPERATORS

Note: the following three insertion operators defining sets of characters that should be escaped can only be used until the first time one of the param(), begin() or end() members is called. Once one of these latter three members has been called the set of characters to be escaped is fixed and attempts to modify them will fail silently.

The copy and move assignment operators are available.

MEMBER FUNCTIONS

STATIC MEMBERS

EXAMPLE


#include <fstream>
#include <iostream>

#include <bobcat/errno>
#ifdef BOBCAT
    #include <bobcat/cidr>
#else
    #include "cidr"
#endif

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
{
    enum Spec
    {
        NONE,
        FILE,
        CIN
    };
    
    Spec spec = CIN;
    ifstream in;

    if (argc > 1)
    {
        Errno::open(in, argv[1]);       // file containing cidr-specs
        spec = FILE;
    }
    
    while (true)
    {
        string cidrSpec;
        if (spec == CIN)
        {
            cout << "Specify cidr (empty to quit): ";
            if (!getline(cin, cidrSpec) || cidrSpec.empty())
                break;
        }
        try
        {
            Cidr cidr;

            switch (spec)
            {
                case NONE:
                return 0;

                case FILE:
                    cidr.setCidr(in);
                    spec = NONE;
                break;

                case CIN:
                    cidr.setCidr(cidrSpec);
            }
        
            while (true)
            {
                cout << "Specify address to test (empty to " <<
                    (spec == CIN ? "respec. CIDR" : "quit") << "): ";
                string address;
                if (!getline(cin, address) || address.empty())
                    break;
            
                if (!cidr.match(address))
                {
                    cout << "Address " << address << " not in ";
                    if (spec == CIN)
                        cout << cidrSpec << '\n';
                    else
                        cout << "specifications in " << argv[1] << '\n';
                }
                else
                    cout << "Address " << address << " in " << cidr.cidr() << 
                                                                        "\n"
                        "Lowest address: " << cidr.first() << "\n"
                        "Highest address: " << cidr.last() << "\n"
                        "CIDR mask: " << cidr.mask() << "\n"
                        "Address: " << cidr.address() << '\n';
            }
        }
        catch (Errno const &err)
        {
            cout << "Oops... " << err.why() << "\n"
                    "Try again...\n";
        }
    }
}


FILES

bobcat/cidr - defines the class interface

SEE ALSO

bobcat(7)

BUGS

Members of Cidr use static data. The current implementation of Cidr is therefore not thread-safe.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).

./usr/share/doc/libbobcat3-dev/man/cgi.3.html0000644000000000000000000004534112022673332017524 0ustar rootroot FBB::CGI


FBB::CGI

libbobcat1-dev_3.01.00-x.tar.gz

2005-2012


FBB::CGI(3bobcat)

FBB::CGI(3bobcat)

libbobcat1-dev_3.01.00-x.tar.gz CGI interface

2005-2012

NAME

FBB::CGI - handles GET and POST submitted form data

SYNOPSIS

#include <bobcat/cgi>
Linking option: -lbobcat

DESCRIPTION

The class CGI offers an interface to data submitted by web-forms. The data is sent to a script handling the data using a <form action="/path/to/form/script"> stanza. Very often this is indeed a script, like a Perl script, but there is no need to use a scripting language. The class CGI allows C++ programmers to process the form by an executable usually resulting in faster processing and in construction time benefits from the type safety offered by C++. The class CGI handles data submitted using the GET method as well as data submitted using the POST method automatically.

By default the class's constructor writes the customary Content-type header lines to the standard output stream. Additional (html) output of a reply page must be provided by other code. Therefore, a program processing an uploaded form will have an organization comparable to the following basic setup:


    // assume includes and namespace std/FBB were defined
    int main()
    {
        CGI cgi;
        cout << "<html><body>\n";
        if (parametersOK(cgi))
        {
            process(cgi);     
            generateReplyPage();
        }
        else
            generateErrorPage();
        cout << "</body></html>\n;
    }
        

When errors in the received form-data are detected an error message is written to the standard output stream and an FBB::Errno exception is thrown.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

TYPEDEF