Download, Installation, Configuration:
Download: ftp://ftp.gnu.org/gnu/cgicc/
Unpack: tar xzf cgicc-X.X.X.tar.gz
Build Libraries:
- cd cgicc-X.X.X/
- ./configure --prefix=/usr (Default or /opt. Make sure you have write priviges to the directory.)
If compiling to create a 32 bit library on a 64 bit Athelon:
CXXFLAGS="-m32" CFLAGS="-m32" LDFLAGS="-m32"
If installed in /opt then you will need to include:
- Include path defined in the compile statement: -I/opt/include
- Link command reference: -L/opt/lib
or use LD_RUN_PATH or /etc/ld.so.conf
Installing into /usr may eliminate the configuration headaches but will not isolate your development libraries from the distribution libraries.
- make install
[Potential Pitfall]: If cgicc does not build on your version and flavor of Linux, try a different version.
When using older versions of Linux, try an older and contemporary version of cgicc.
The build and installation will create and install include files, documentation and libraries:
Example:
The Web Page:
HTML Form Source:
02 | < head >< title >Test CGIcc form</ title ></ head > |
03 | < body bgcolor = "#cccccc" text = "#000000" > |
04 | < h2 >Test CGIcc form</ h2 > |
06 | < form method = "post" action = "/cgi-bin/testcgi" > |
08 | < input type = "text" name = "value1" > |
12 | < option value = "option1" >Option 1 |
13 | < option value = "option2" >Option 2 |
14 | < option value = "option3" >Option 3 |
18 | < input type = "radio" name = "value3" value = "button1" checked = "checked" >Button1 |
19 | < input type = "radio" name = "value3" value = "button2" >Button2 |
21 | < input type = "hidden" name = "value4" value = "data4" > |
23 | < input type = "submit" value = "Submit" > |
C++ CGI Source:
05 | #include "cgicc/CgiDefs.h" |
06 | #include "cgicc/Cgicc.h" |
07 | #include "cgicc/HTTPHTMLHeader.h" |
08 | #include "cgicc/HTMLClasses.h" |
16 | int main( int argc, char **argv) |
22 | cout << HTTPHTMLHeader() << endl; |
25 | cout << HTMLDoctype(HTMLDoctype::eStrict) << endl; |
28 | cout << html().set( "lang" , "EN" ).set( "dir" , "LTR" ) << endl; |
31 | cout << html() << head() << title( "Cgicc example" ) << head() << endl; |
32 | cout << body().set( "bgcolor" , "#cccccc" ).set( "text" , "#000000" ).set( "link" , "#0000ff" ).set( "vlink" , "#000080" ) << endl; |
34 | cout << h1( "This is a demonstration of the GNU CgiCC library" ) << endl; |
36 | form_iterator fvalue1 = formData.getElement( "value1" ); |
37 | if ( !fvalue1->isEmpty() && fvalue1 != (*formData).end()) { |
38 | cout << "Value1: " << **fvalue1 << endl; |
41 | cout << "No text entered for value1" << endl; |
45 | form_iterator fvalue2 = formData.getElement( "value2" ); |
46 | if ( !fvalue2->isEmpty() && fvalue2 != (*formData).end()) { |
49 | cout << "Value2: " << (**fvalue2).c_str() << endl; |
54 | form_iterator fvalue3 = formData.getElement( "value3" ); |
55 | if ( !fvalue3->isEmpty() && fvalue3 != (*formData).end()) { |
56 | cout << "Value3: " << **fvalue3 << endl; |
61 | form_iterator fvalue4 = formData.getElement( "value4" ); |
62 | if ( !fvalue4->isEmpty() && fvalue4 != (*formData).end()) { |
63 | cout << "Value4: " << **fvalue4 << endl; |
67 | cout << body() << html(); |
71 | cout << "ERROR!!" << endl; |
Compile:
- Compile and static link: (size: 1063688)
- If installed in /opt/: g++ -o testcgi -I/opt/include testcgi.cpp /opt/lib/libcgicc.a
- If installed in /usr/: g++ -o testcgi testcgi.cpp /usr/lib/libcgicc.a
- Dynamic Link (at run time): (size: 48465)
- If installed in /opt/: g++ -o testcgi -I/opt/include testcgi.cpp -L/opt/lib -lcgicc
- If installed in /usr/: g++ -o testcgi testcgi.cpp -lcgicc
Run:
The following paths are for a Red Hat 7.x installation.
- Place web page in: /var/www/html/testcgi.html
- Place cgi in: /var/www/cgi-bin/testcgi
- Start Apache: service httpd start
- Test: http://localhost/testcgi.html
Debugging:
Debugging a "POST" method CGI:
- Print environment for transaction:
Code snipet to include in cgicc CGI program:
02 | void dumpEnvironment( const CgiEnvironment& env); |
05 | const CgiEnvironment& env = cgi.getEnvironment(); |
07 | cout << env.getRequestMethod() << endl; |
08 | ... env.getPathInfo() ... |
09 | ... env.getPathTranslated() |
11 | env.getContentLength() |
Also: env.getRequestMethod(), env.getPathInfo(),
env.getPathTranslated(), env.getReferrer(), env.getContentLength(),
env.getPostData(), env.getRemoteHost(), env.getRemoteAddr(),
env.getAuthType(), env.getRemoteUser(), env.getRemoteIdent(),
env.getContentType(), env.getAccept(), env.getUserAgent(),
env.getServerSoftware(), env.getServerName(),
env.getGatewayInterface(), env.getServerProtocol(),
env.getServerPort(), env.usingHTTPS(), env.getRedirectRequest(),
env.getRedirectURL(), env.getRedirectStatus(), env.getCookies(),
env.getQueryString(), env.getScriptName().
- Set environment variables: . debug-env
File: debug-env
export HTTP_USER_AGENT="Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.3) Gecko/20041020"
export SERVER_PORT=80
export HTTP_HOST=localhost
export DOCUMENT_ROOT="/var/www/html"
export HTTP_ACCEPT_CHARSET="iso-8859-1,*,utf-8"
export SCRIPT_FILENAME="/var/www/cgi-bin/env.sh"
export REQUEST_URI="/cgi-bin/env.sh"
export SCRIPT_NAME="/cgi-bin/program.cgi"
export HTTP_REFERRER="http://localhost/web-page.html"
export HTTP_CONNECTION=Keep-Alive""
export REMOTE_PORT=32984
export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PWD="/var/www/cgi-bin"
export SERVER_ADMIN="root@localhost"
export HTTP_ACCEPT_LANGUAGE=en
export HTTP_ACCEPT='text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
export REMOTE_ADDR='127.0.0.1'
export SHLVL=1
export SERVER_NAME=localhost
export SERVER_SOFTWARE='Apache/2.0.52 (Fedora)'
export QUERY_STRING=
export SERVER_ADDR='127.0.0.1'
export GATEWAY_INTERFACE='CGI/1.1'
export SERVER_PROTOCOL='HTTP/1.1'
export HTTP_ACCEPT_ENCODING=gzip
export REQUEST_METHOD=POST
export CONTENT_LENGTH=47
export CONTENT_TYPE='application/x-www-form-urlencoded'
export POST_DATA='formval1=VALUE1&formval2=VALUE2&formval3=VALUE3'
- Create file for (standard input) stdin: echo $POST_DATA > debug-stdin
- Run in dbx:
- dbx program.cgi
- break ##### (Set breakpoints)
- run < debug-stdin
OR
If not debugging, just run: echo $POST_DATA | ./program.cgi
Links:

Books: