/******************************************************************** // // maingate.cpp: a demo program for CGate CGI class. // // CC maingate.cpp gate.cpp -o gate.cgi // // // If using as CGI ( testOnline() ). // Change the permission on 'gate.cgi' so that // it is executable by the server. // // And use the following HTML form at the client side.
DEMO FOR THE gate CGI PROGRAM
USER: AGE:
// // kishan@hackorama.com http://www.hackorama.com // // Thu Nov 4 19:56:03 PST 1999 // // Online Demo and code at http://www.hackorama.com/gate // *********************************************************************/ #include #include #include #include #include #include "gate.h" void testOnline(); void testOffline(); int main() { //Online testing as a CGI program using the sample HTML FORM listed above testOnline(); //Offline testing with hard coded NAME-VALUE pairs //testOffline(); return 0; } void testOnline() { //Just create the class, which will get the //posted data from the form and proces it CGate* mygate = new CGate(); //*----------------------------------------------- // Now use CGate::gGetValueFor("XXXX") // to get the posted value from the HTML Form // // For Eg: To get the submitted value // for the textboxs named USER // and AGE we will use: // // mygate->gGetValueFor("USER") // // mygate->gGetValueFor("AGE") // // and we will print these values out // with a few html formating to the browser , // for displaying. //----------------------------------------------*/ //Print the html header to the browser first mygate->gPrintHeader(); //Followed by the HTML cout << "" << "" << endl; cout << "
" << endl ; cout << "YOU ENTERED" << "
" << "
" << endl ; cout << "USER :" << mygate->gGetValueFor("USER") << "
" << endl; cout << "AGE :" << mygate->gGetValueFor("AGE") << "
" << endl; cout << "
" << endl ; cout << "" << endl; //*------------------------------------ //CGate::gLog("filname") //This is a utility function which will log the //Client information each time this script was accessed //It creates a file and appends the data with a time stamp //--------------------------------------*/ //mygate->gLog("gate.log"); //*------------------------------------ //If you want to process the posted strings //easiest way is to just define //a char * ptr and get the pointer //But if you want you can also copy the string //which requires another memory //allocation and deletion //-----------------------------------*/ //Easy way - just getting the ptr //char* pMyAge = mygate->gGetValueFor("AGE"); //Copying - rerquires mem allocation and deletion //char* pMyUser = new char[ strlen( mygate->gGetValueFor("USER") ) + 1 ]; //strcpy( pMyUser , mygate->gGetValueFor("USER") ); //delete[] pMyUser; // once we are done release all memory delete mygate; // and exit gracefully exit(0); } void testOffline() { //For testing offline send in some formatted name value pairs CGate* mygate = new CGate("USER=Trinity&AGE=23"); cout << endl ; cout << "YOU ENTERED:" << endl << endl ; cout << "USER :" << mygate->gGetValueFor("USER") << endl; cout << "AGE :" << mygate->gGetValueFor("AGE") << endl; //*------------------------------------ //Calll CGate::gVerify() //Utility function if you want to //see all the name value pairs for //verfication while running offline //-----------------------------------*/ mygate->gVerify(); //*------------------------------------ //If you want to process the posted strings //easiest way is to just define //a char * ptr and get the pointer //But if you want you can also copy the string //which requires another memory //allocation and deletion //-----------------------------------*/ //Easy way - just getting the ptr char* pMyAge = mygate->gGetValueFor("AGE"); //Copying - rerquires mem allocation and deletion char* pMyUser = new char[ strlen( mygate->gGetValueFor("USER") ) + 1 ]; strcpy( pMyUser , mygate->gGetValueFor("USER") ); cout << endl << "ONCE AGIN" << endl ; cout << "AGE :" << pMyAge << endl ; cout << "ONCE AGIN" << endl ; cout << "USER :" << pMyUser << endl ; cout << endl ; delete[] pMyUser; // once we are done release all memory delete mygate; // and exit gracefully exit(0); }