jwCGI library

Related info

Download jwCGI
Documentation
Old releases
license
johnwiggins.net

CGI Related

APACHE
CGI specification
PHP
perl
python
java


SourceForge.net Logo

jwCGI on sourceforge

jwCGI is a C++ library for creating CGI (Common Gateway Interface) programs. The library comes with several example programs to help you get acquainted with its usage. If you are familiar with C/C++ it will be quick to learn. It also incooperates an xhtml class for displaying web content. If you need some kind of interpreted programming language (i.e. PHP or Perl) please see the links on the left of this page. jwCGI is free software subject to the terms of the GPL License.

How to uncompress and compile the library

To use the library, create a basic C++ file as below. In your main function just instantiate an instance of the CGI object class. One other caveat, we must close the http header to the browser, calling xhtml::pagebegin( ) accomplishes this for us. At this point any data sent to the xhtml object gets sent to the requesting browser. Here is code for the typical hello world programming example but in jwCGI speak.
#include <jwcgi/jwcgi.h>
using namespace jwcgi;
int main(int argc, char* argv[ ], char *envp[ ]) {
CGI cgi; // instantiate our CGI object
xhtml<std::ostream> p(std::cout); // encapsulates xhtml output
p.pagebegin("Hello World demo"); // call WepPage functions to send html to the browser
p.body( );
p.div( ); // keep well formed xhtml
p << "Hello World";
p.divend( );
return 0;
}
Once we have an instance of CGI we can use its member functions to extract data sent by browsers to the web server. Of course a form is needed for the user of the browser to inform us what data to process. In the case of the simpleform demo program the cgi program is also called to display this form. It is probably easier to use a program to specifically write form pages for us (i.e. wysiwyg html page editor). To make it easier for users of jwCGI to get up and running I have the demo programs display the forms needed by the CGI. Just compile the demo programs and browse to them from a web browser. Obviously your web server will have to have CGI enabled, with the correct file permissions set on the files for the cgi's to work. There are only a few functions in the interface to use:
bool GetValue(const string& valuename, vector<char>& filedata, string& data);
bool GetValue(const string& valuename, string& data);
and the CGI environment variable functions.
if we have a simple form on a web page e.g.
<form method="post" action="/cgi-bin/simpleform.cgi" enctype="application/x-www-form-urlencoded">
<input type="text" name="firstname">
<input type="submit" name="submit" value="Submit">
</form>
When the form is submitted we can use the GetValue( ) member of class CGI to retrieve the user entered data in the form:
string name;
cgi.GetValue("firstname", name);
name will now hold the value the user entered into the text field on the form if the form is submited.

Example demo/programs that are included with this library:
Programs that use jwCGI

Any BUG reports, things for further inclusion or general questions email: