int main(int argc, char *argv[]){ putenv("REQUEST_METHOD=GET"); putenv("QUERY_STRING=?test=fun%7B&name=Jake+Ailor&team=true&EUID=12343"); putenv("CONTENT_LENGTH=49"); std::cout << CGI::getEnvStr("QUERY_STRING") << std::endl; CGI enviornment; std::cout << "test (fun): " << enviornment.get("test") << std::endl; std::cout << "name (jake): " << enviornment.get("name") << std::endl; std::cout << "team (true): " << enviornment.get("team") << std::endl; std::cout << "EUID (12343): " << enviornment.get("EUID") << std::endl; return EXIT_SUCCESS; }
int SearchHandler::process(char *recvdata, int datalen) { CGI cgi; char *query=0; int searchMode = 0; // 2007.10 resStr.init (10*1024); cgi.parse(recvdata); resStr.add("METHOD = %s\n", cgi.method() ); query = cgi.getVal("query"); searchMode = cgi.getIntVal("mode"); resStr.add("QUERY = %s\n", query ); resStr.add("MODE = %d\n", searchMode ); //cgi.print( resStr ); if (strcmp(cgi.method(), "search")==0) { Search::search(query , resStr, searchMode); } else { Search::dict(query , resStr); } ACE_DEBUG ((LM_DEBUG,"%s\n", resStr.str() )); sendRes(); return 0; }
int main(int argc, char**argv) { extern char **environ; char **it; CGI cgiconv; cgiconv.processCGIData(); printf("Content-type: text/html\n\n"); printf("<H1>Arguments: (count = %d)</H1>\n", argc); for (it = argv; *it; it++) printf("%s ", *it); printf("\n"); printf("<H1>Environment</H1>\n"); printf("<PRE>\n"); for (it = environ; *it ; it++) printf("%s\n", *it); printf("</PRE>\n"); printf("<H1>CGI Post Data</H1>\n"); printf("%s\n", (const char*)cgiconv.getQueryString()); #ifdef CGI_TEST_SAVE_DATA FILE* test = fopen("/tmp/testdata.txt", "w"); fprintf(test, "%s", (const char*)cgiconv.getQueryString()); fclose(test); #endif printf("<H1>CGI Test</H1>\n"); printf("<PRE>\n"); int i, count; printf("Number of Parameters: %d\n", cgiconv.getParamCount()); printf("name='%s'\n", (const char*)cgiconv.getParamValue("name")); printf("address='%s'\n", (const char*)cgiconv.getParamValue("address")); count = cgiconv.getParamNameCount("flavors"); printf("# of flavors = %d\n", count); for (i = 0; i < count; i++) printf("flavors[%d]='%s'\n", i, (const char*)cgiconv.getParamValue("flavors", i)); printf("</PRE>\n"); }
int main(int argc, char *argv[]) { // open the output data stream Q3TextStream out(stdout, QIODevice::WriteOnly); const char* header = "Content-type: text/html; charset=iso-8859-1\n\n" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" "<HTML>\n" " <HEAD>\n" " <TITLE>ShowEQ Item Display</TITLE>\n" " <style type=\"text/css\">\n" " <!--\n" " table { border: black 2px solid }\n" " td { border: black 1px solid }\n" " th { border: black 1px solid }\n" " span.head { color: black }\n" " span.known1 { color: green }\n" " span.known2 { color: blue }\n" " span.varies { color: purple }\n" " span.unknown { color: red }\n" " b.warning { color: red }\n" " -->\n" " </style>\n" " </HEAD>\n" " <BODY>\n"; /* Print HTML header */ out << header; const char* footer = " </BODY>\n" "</HTML>\n"; // number of item to display QString itemNumber; // should binary data be displayed (default = false) bool displayBinaryData = false; // should the icon be displayed bool displayIcon = DISPLAY_ICONS; // CGI Convenience class CGI cgiconv; // process any CGI data cgiconv.processCGIData(); // If there are form parameters use them if (cgiconv.getParamCount() != 0) { itemNumber = cgiconv.getParamValue("item"); if (cgiconv.getParamValue("displayBinary") == "y") displayBinaryData = true; else if (cgiconv.getParamValue("displayBinary") == "n") displayBinaryData = false; if (cgiconv.getParamValue("showIcon") == "y") displayIcon = true; else if (cgiconv.getParamValue("hideIcon") == "y") displayIcon = false; } else if (argc == 2) { // use argument for item number itemNumber = argv[1]; } else if (argc > 2) { out << "<H1>Error: " << argv[0] << " called with " << argc << " arguments!</H1>\n"; out << "Format: " << argv[0] << "?<ItemID>\n"; out << footer; exit(-1); } if (itemNumber.isNull()) itemNumber = ""; // check for browser type QString userAgent = cgiconv.getHTTPUserAgent(); out << " <!-- Output for UserAgent: " << userAgent << "-->\n"; // beware Netscape4 style sheet brain death bool isNetscape4 = false; if ((userAgent.contains("Mozilla/4.") == 1) && (userAgent.contains("MSIE") == 0)) isNetscape4 = true; // display form to allow user to select an item or display the binary data out << " <FORM method=\"POST\" action=\"" << cgiconv.getScriptName() << "\">\n"; if (isNetscape4) out << " <TABLE border cellspacing=0 cellpadding=2>\n"; else out << " <TABLE cellspacing=0 cellpadding=2>\n"; out << " <TR><TH>Item ID:</TH><TH>Binary Data</TH><TH>Icon</TH>" "<TD><INPUT type=\"reset\" value=\"Reset\"/></TD></TR>\n" " <TR>\n"; out << " <TD><INPUT type=\"text\" name=\"item\" value=\"" << itemNumber << "\" size=\"5\"/></TD>\n"; out << " <TD>" "<INPUT type=\"checkbox\" name=\"displayBinary\" value=\"y\""; if (displayBinaryData) out << " checked"; out << "/>Display</TD>\n"; out << " <TD>"; if (displayIcon) out << "<INPUT type=\"checkbox\" name=\"hideIcon\" value=\"y\" unchecked>" << "Hide</TD>\n"; else out << "<INPUT type=\"hidden\" name=\"hideIcon\" value=\"y\">" << "<INPUT type=\"checkbox\" name=\"showIcon\" value=\"y\" unchecked>" << "Show</TD>\n"; // Submission button out << " <TD>" "<INPUT type=\"submit\" value=\"Search\"/></TD>\n"; out << " </TR>\n"; out << " </TABLE>\n"; out << " </FORM>\n"; // if no item number was passed in, then just return if (itemNumber.isEmpty()) { // ask the user to enter an ItemID out << "<H1>Please Enter an ItemID!</H1>\n"; // close the document out << footer; return 0; } // convert the passed in item number to a short uint16_t currentItemNr = itemNumber.toShort(); EQItemDB* itemDB = new EQItemDB; QString nameString; QString loreString; bool hasEntry = false; EQItemDBEntry* entry = NULL; hasEntry = itemDB->GetItemData(currentItemNr, &entry); out << "<H1>Information on ItemID: " << currentItemNr << "</H1>\n"; if (hasEntry) { loreString = entry->GetLoreName(); nameString = entry->GetName(); if (displayIcon) out << "<P><IMG src=\"" << ICON_DIR << entry->GetIconNr() << ".png\" alt=\"Icon: " << entry->GetIconNr() << "\"/></P>"; if (!nameString.isEmpty()) { out << "<H2>" << nameString << "</H2>\n"; out << "<P><B>Lore:</B> " << loreString << "<BR></P>\n"; } else { out << "<H2>Lore: " << loreString << "</H2>\n"; } out << "<P>\n"; time_t updated = entry->GetUpdated(); out << "<B>Last Updated:</B> " << ctime(&updated) << "<BR>\n"; out << "<B>Icon Number:</B> " << entry->GetIconNr() << "<BR>\n"; out << "<B>Model:</B> " << entry->GetIdFile() << "<BR>\n"; out << "<B>ItemType:</B> " << QString::number(entry->GetItemType()) << "<BR>\n"; out << "<B>Weight:</B> " << (int)entry->GetWeight() << "<BR>\n"; out << "<B>Flags:</B> "; if (entry->IsBook()) out << " BOOK"; if (entry->IsContainer()) out << " CONTAINER"; if (entry->GetNoDrop() == 0) out << " NO-DROP"; if (entry->GetNoRent() == 0) out << " NO-RENT"; if (entry->GetMagic() == 1) out << " MAGIC"; if (entry->GetLoreFlag()) out << " LORE"; else if (entry->GetSummonedFlag()) out << " SUMMONED"; else if (entry->GetArtifactFlag()) out << " ARTIFACT"; else if (entry->GetPendingLoreFlag()) out << " PENDING-LORE"; out << "<BR>\n"; out << "<B>Size:</B> " << size_name(entry->GetSize()) << "<BR>\n"; out << "<B>Slots:</B> " << print_slot(entry->GetSlots()) << "<BR>\n"; out << "<B>Base Price:</B> " << reformatMoney(entry->GetCost()) << "<BR>\n"; if (entry->GetSTR()) out << "<B>Str:</B> " << (int)entry->GetSTR() << "<BR>\n"; if (entry->GetSTA()) out << "<B>Sta:</B> " << (int)entry->GetSTA() << "<BR>\n"; if (entry->GetCHA()) out << "<B>Cha:</B> " << (int)entry->GetCHA() << "<BR>\n"; if (entry->GetDEX()) out << "<B>Dex:</B> " << (int)entry->GetDEX() << "<BR>\n"; if (entry->GetINT()) out << "<B>Int:</B> " << (int)entry->GetINT() << "<BR>\n"; if (entry->GetAGI()) out << "<B>Agi:</B> " << (int)entry->GetAGI() << "<BR>\n"; if (entry->GetWIS()) out << "<B>Wis:</B> " << (int)entry->GetWIS() << "<BR>\n"; if (entry->GetMR()) out << "<B>Magic:</B> " << (int)entry->GetMR() << "<BR>\n"; if (entry->GetFR()) out << "<B>Fire:</B> " << (int)entry->GetFR() << "<BR>\n"; if (entry->GetCR()) out << "<B>Cold:</B> " << (int)entry->GetCR() << "<BR>\n"; if (entry->GetDR()) out << "<B>Disease:</B> " << (int)entry->GetDR() << "<BR>\n"; if (entry->GetPR()) out << "<B>Poison:</B> " << (int)entry->GetPR() << "<BR>\n"; if (entry->GetHP()) out << "<B>HP:</B> " << (int)entry->GetHP() << "<BR>\n"; if (entry->GetMana()) out << "<B>Mana:</B> " << (int)entry->GetMana() << "<BR>\n"; if (entry->GetAC()) out << "<B>AC:</B> " << (int)entry->GetAC() << "<BR>\n"; if (entry->GetLight()) out << "<B>Light:</B> " << (int)entry->GetLight() << "<BR>\n"; if (entry->GetDelay()) out << "<B>Delay:</B> " << (int)entry->GetDelay() << "<BR>\n"; if (entry->GetDamage()) { out << "<B>Damage:</B> " << (int)entry->GetDamage() << "<BR>\n"; QString qsTemp = print_skill (entry->GetSkill()); out << "<B>Skill:</B> "; if (qsTemp.find("U0x") == -1) out << qsTemp << "<BR>\n"; else out << "Unknown (ID: " << qsTemp << ")<BR>\n"; } if (entry->GetRange()) out << "<B>Range:</B> " << (int)entry->GetRange() << "<BR>\n"; if (entry->GetMaterial()) { out << "<B>Material:</B> " << QString::number(entry->GetMaterial(), 16) << " (" << print_material (entry->GetMaterial()) << ")<BR>\n"; out << "<B>Color:</B> " << QString::number(entry->GetColor(), 16) << "<BR>\n"; out << ((entry->GetColor()) ? (QString("<TABLE><TR><TD bgcolor=\"#%1\">").arg(entry->GetColor(), 6, 16)) : ("<TABLE><TR><TD bgcolor=\"#ffffff\">")) << " ### SAMPLE ###  </TD></TR></TABLE>\n"; } else out << "<B>Material:</B> 0 (None)<BR>\n"; if (entry->GetStackable() != -1) out << "<B>Stackable:</B> " << ((entry->GetStackable() == 1) ? "yes" : "no?") << "<BR>\n"; if (entry->GetEffectType() != -1) out << "<B>Effect Type:</B> " << entry->GetEffectTypeString() << "<BR>\n"; if (entry->GetSpellId() != ITEM_SPELLID_NOSPELL) { out << "<B>Spell Effect:</B> " << spell_name (entry->GetSpellId()) << "<BR>\n"; if (entry->GetLevel()) out << "<B>Casting Level:</B> " << (int)entry->GetLevel() << "<BR>\n"; if (entry->GetCharges()) { out << "<B>Charges:</B> "; if (entry->GetCharges() == -1) out << "Unlimited<BR>\n"; else out << (int)entry->GetCharges() << "<BR>\n"; } if (entry->GetCastTime()) out << "<B>Casting Time:</B> " << (int)entry->GetCastTime() << "<BR>\n"; } out << "<B>Class:</B> " << print_classes (entry->GetClasses()) << "<BR>\n"; out << "<B>Race:</B> " << print_races (entry->GetRaces()) << "<BR>\n"; if (entry->GetSkillModId()) out << "<B>Skill Modifier:</B> " << skill_name(entry->GetSkillModId()) << " " << (int)entry->GetSkillModPercent() << "% <BR>\n"; if (entry->IsContainer()) { if (entry->GetNumSlots()) out << "<B>Container Slots:</B> " << (int)entry->GetNumSlots() << "<BR>\n"; if (entry->GetSizeCapacity()) out << "<B>Size Capacity:</B> " << size_name(entry->GetSizeCapacity()) << "<BR>\n"; if (entry->GetWeightReduction()) out << "<B>% Weight Reduction:</B> " << (int)entry->GetWeightReduction() << "<BR>\n"; } out << "</P>\n"; } int size = 0; if (displayBinaryData) { time_t updated; char* rawData = NULL; size = itemDB->GetItemRawData(currentItemNr, updated, &rawData); if ((size > 0) && (rawData != NULL)) { out << "<P><B>Raw data: (" << size << " octets) last updated: " << ctime(&updated) << "</B></P>\n"; out << "</P>"; out << "<PRE>\n"; printdata (out, size, rawData); out << "</PRE>\n"; delete [] rawData; } } if (!hasEntry && nameString.isEmpty() && loreString.isEmpty() && (size == 0)) out << "<P>Item " << currentItemNr << " not found</P>\n"; // close the document with the footer out << footer; // delete DB entry delete entry; // shutdown the ItemDB instance itemDB->Shutdown(); // delete the ItemDB instance delete itemDB; return 0; }
int main (int argc, char *argv[]) { // CGI Convenience class CGI cgiconv; // state variables // assume the user didn't pass any map name bool drawMap = false; // name of the map to display if any QString mapName; // process any CGI data cgiconv.processCGIData(); /* Check if we were passed a map to read */ if (argc == 2) { drawMap = true; mapName = argv[1]; } else if (cgiconv.getParamCount() != 0) { mapName = cgiconv.getParamValue("map"); drawMap = (cgiconv.getParamValue("draw") == "y"); } // if in drawmap mode, then that's all that's done if (drawMap) { QRegExp slashExp("/"); mapName.replace(slashExp, "_"); mapName.prepend(MAPDIR "/"); loadFileMap ((const char*)mapName); paintMap(); } else { // open the output data stream QTextStream out(stdout, IO_WriteOnly); out.setEncoding(QTextStream::Latin1); out.flags(QTextStream::showbase | QTextStream::dec); const char* header = "Content-type: text/html; charset=iso-8859-1\n\n" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" "<HTML>\n" " <HEAD>\n" " <TITLE>ShowEQ Map Display</TITLE>\n" " <style type=\"text/css\">\n" " <!--\n" " table { border: black 2px solid }\n" " td { border: black 1px solid }\n" " th { border: black 1px solid }\n" " -->\n" " </style>\n" " </HEAD>\n" " <BODY>\n"; /* Print HTML header */ out << header; const char* footer = " </BODY>\n" "</HTML>\n"; // otherwise display an HTML form to allow the user to choose a map QDir mapDir(MAPDIR, "*.map", (QDir::Name | QDir::IgnoreCase), (QDir::Files | QDir::Readable)); if (!mapDir.exists()) { out << "<H1>The map directory '" MAPDIR "' doesn't exist!</H1>\n"; out << footer; return 0; } QString userAgent = cgiconv.getHTTPUserAgent(); out << "<FORM method=\"POST\" action=\"" << cgiconv.getScriptName() << "\">\n"; // beware Netscape 4.x style sheet brain death if ((userAgent.contains("Mozilla/4.") == 1) && (userAgent.contains("MSIE") == 0)) out << "<TABLE border=2 cellspacing=0 cellpadding=2>\n"; else out << "<TABLE cellspacing=0 cellpadding=2>\n"; out << "<TR>"; out << " <TH>Map Name</TH>"; out << " <TD><INPUT type=\"reset\" value=\"Reset\"/></TD>\n"; out << "</TR>"; out << "<TR>"; out << "<TD><SELECT name=\"map\" size=\"1\">\n"; // create a file info list const QFileInfoList *list = mapDir.entryInfoList(); // create an iterator over the list QFileInfoListIterator it( *list ); // pointer to the file info for the current file QFileInfo *fi; while ( (fi=it.current()) ) { out << "<OPTION value=\"" << fi->fileName() << "\""; if (mapName == fi->fileName()) out << " selected"; out << ">" << fi->baseName() << "</OPTION>\n"; // goto next element from list ++it; } out << "</SELECT></TD>\n"; // Submission button out << "<TD><INPUT type=\"submit\" value=\"Display\"/></TD>\n"; out << "</TR>" "</TABLE>" "</FORM>"; if (!mapName.isEmpty()) { out << "<H1>Map: " << mapName << "</H1>\n"; out << "<DIV><IMG src=\"" << cgiconv.getScriptName() << "?map=" << mapName << ";draw=y\" alt=\"Map: " << mapName << "\"/></DIV>\n"; } out << footer; } return 0; }
int main (int argc, char *argv[]) { FILE *sdb; struct dbSpawnStruct dbSpawn; int counter=0; // CGI Convenience class CGI cgiconv; // search variables QString searchName = ""; QString searchZone = ""; int searchLevel = 0; QString searchRace = ""; int searchClass = 0; // are we performing a serch (default = false) bool doSearch = false; // process any CGI data cgiconv.processCGIData(); // If there are form parameters use them for searching if (cgiconv.getParamCount() != 0) { searchName = cgiconv.getParamValue("name"); searchZone = cgiconv.getParamValue("zone"); searchLevel = cgiconv.getParamValue("level").toInt(); searchRace = cgiconv.getParamValue("race"); searchClass = cgiconv.getParamValue("class").toInt(); if (!searchName.isEmpty() || !searchZone.isEmpty() || !searchRace.isEmpty() || (searchLevel != 0) || (searchClass != 0)) doSearch = true; } else if (argc == 2) { // use the argument for the name search searchName = argv[1]; // note that a search is being done. doSearch = true; } // open the output data stream Q3TextStream out(stdout, QIODevice::WriteOnly); out.setEncoding(Q3TextStream::Latin1); out.flags(Q3TextStream::showbase | Q3TextStream::dec); const char* header = "Content-type: text/html; charset=iso-8859-1\n\n" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" "<HTML>\n" " <HEAD>\n" " <TITLE>ShowEQ Spawn List</TITLE>\n" " <style type=\"text/css\">\n" " <!--\n" " table { border: black 2px solid }\n" " td { border: black 1px solid }\n" " th { border: black 1px solid }\n" " -->\n" " </style>\n" " </HEAD>\n" " <BODY>\n"; /* Print HTML header */ out << header; const char* footer = " </BODY>\n" "</HTML>\n"; // check for browser type QString userAgent = cgiconv.getHTTPUserAgent(); out << " <!-- Output for UserAgent: " << userAgent << "-->\n"; out << "<FORM method=\"POST\" action=\"" << cgiconv.getScriptName() << "\">\n"; // beware Netscape 4.x style sheet brain death if ((userAgent.contains("Mozilla/4.") == 1) && (userAgent.contains("MSIE") == 0)) out << "<TABLE border=2 cellspacing=0 cellpadding=2>\n"; else out << "<TABLE cellspacing=0 cellpadding=2>\n"; out << "<TR>" "<TH>Name</TH><TH>Zone</TH><TH>Level</TH><TH>Race</TH><TH>Class</TH>\n" "<TD><INPUT type=\"reset\" value=\"Reset\"/></TD>\n" "</TR>\n"; out << "<TR>"; // name field out << "<TD><INPUT type=\"text\" name=\"name\" value=\"" << searchName << "\"/></TD>\n"; // zone field out << "<TD><INPUT type=\"text\" name=\"zone\" value=\"" << searchZone << "\"/></TD>\n"; // level field out << "<TD><INPUT type=\"text\" name=\"level\" size=\"2\" maxlength=\"2\"" " value=\""; if (searchLevel) out << searchLevel; out << "\"/></TD>\n"; // race field out << "<TD><INPUT type=\"text\" name=\"race\" value=\"" << searchRace << "\"/></TD>\n"; // Class field out << "<TD><SELECT name=\"class\" size=\"1\">\n"; out << "<OPTION value=\"0\""; if (searchClass == 0) out << " selected"; out << ">Any</OPTION>\n"; Spawn fake(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // start at class value 1, and go until maximum known class value for (int i = 1; i <= 32; ++i) { fake.setClassVal(i); out << "<OPTION value=\"" << i << "\""; if (searchClass == i) out << " selected"; out << ">" << fake.classString() << "</OPTION>\n"; } out << "</SELECT></TD>\n"; // Submission button out << "<TD><INPUT type=\"submit\" value=\"Search\"/></TD>\n"; // close the form out << "</TR>\n" "</TABLE>\n" "</FORM>\n"; ///////////////////// // on with the search sdb = fopen (SPAWNFILE, "r"); if (sdb == NULL) { // display the error out << "<H1>Unable to open file '" SPAWNFILE "' (errno = " << errno << ")</H1>\n"; // close the document out << footer; // nothing more can be done exit(1); } // start the result table // beware Netscape 4.x style sheet brain death if ((userAgent.contains("Mozilla/4.") == 1) && (userAgent.contains("MSIE") == 0)) out << "<TABLE border=2 cellspacing=0 cellpadding=2>\n"; else out << "<TABLE cellspacing=0 cellpadding=2>\n"; out << "<TR>\n" "<TD align=center><STRONG>Short Name</STRONG></TD>\n" "<TD align=center><STRONG>Long Name</STRONG></TD>\n" "<TD align=center><STRONG>Zone Name</STRONG></TD>\n" "<TD align=center><STRONG>Level</STRONG></TD>\n" "<TD align=center><STRONG>HP</STRONG></TD>\n" "<TD align=center><STRONG>Race</STRONG></TD>\n" "<TD align=center><STRONG>Class</STRONG></TD>\n" "</TR>\n"; QString spawnName; QRegExp stripExp("[0-9]"); // iterate over the contents of the spawn database while (fread (&dbSpawn, sizeof(dbSpawnStruct), 1, sdb)) { Spawn spawn(&dbSpawn.spawn); // stash the name for later use and cooking spawnName = spawn.name(); // is a search being performed, then do it already... if (doSearch) { // is it a name search, if so do we have a match if ((!searchName.isEmpty()) && (spawnName.find(searchName, 0, false) == -1)) continue; // nope, you are the weakest link, good bye... // is it a zone search, if so check if ((!searchZone.isEmpty()) && (QString(dbSpawn.zoneName).find(searchZone, 0, false) == -1)) continue; // is it a level search, if so check if ((searchLevel != 0) && (searchLevel != spawn.level())) continue; // is it a race search, if so check if ((!searchRace.isEmpty()) && (spawn.raceString().find(searchRace, 0, false) == -1)) continue; // is it a class search, if so check if ((searchClass != 0) && (searchClass != spawn.classVal())) continue; } // strip the numbers off the spawn name spawnName.replace(stripExp, ""); // display the spawn's data out << "<TR>\n"; out << "<TD><A HREF=\"showspawn.cgi?name=" << spawnName << "\">" << spawnName << "</A></TD>\n"; out << "<TD>" << spawn.realName() << "</TD>\n"; out << "<TD>" << dbSpawn.zoneName << "</TD>\n"; out << "<TD align=right>" << spawn.level() << "</TD>\n"; out << "<TD align=right>" << spawn.HP() << "/" << spawn.maxHP() << "</TD>\n"; out << "<TD>" << spawn.raceString() << "</TD>\n"; out << "<TD>" << spawn.classString() << "</TD>\n"; out << "</TR>\n"; // increment the count counter++; } // close the table out << "</TABLE>\n"; // display the number of matches out << "<P>" << counter << " matches found</P>\n"; // close the document out << footer; // close the spawn database fclose (sdb); }
int main() { //The CGI Parser CGI cgi; //check here for posted information if (cgi.exists("initialparameter")) { //we have posted information. Lets first fetch the information //Firstly the very basic information int nc, nu, noseg; float spanbeam; nc= atoi(cgi.value("nc")); nu= atoi(cgi.value("nu")); spanbeam = atof(cgi.value("spanbeam")); noseg = atoi(cgi.value("noseg")); //cout<<nc<<endl<<nu<<endl<<spanbeam<<endl<<noseg; //Now the dependent information float conLoadInten[10], conLoadA[10], uniIntensity[10], udlStartPos[10], lenUDL[10]; if (nc>0) { for (int i=1; i<=nc; i++) { conLoadInten[i] = atof(cgi.value("p",i-1)); conLoadA[i] = atof(cgi.value("ac", i-1)); //cout<<conLoadA[i]<<endl<<conLoadInten[i]<<endl; } } if (nu>0) { for (int i=1; i<=nu; i++) { uniIntensity[i] = atof(cgi.value("wu",i-1)); udlStartPos[i] = atof(cgi.value("au", i-1)); lenUDL[i] = atof(cgi.value("lu", i-1)); //cout<<uniIntensity[i]<<endl<<udlStartPos[i]<<endl<<lenUDL[i]<<endl; } } //Create a file for the output FILE* fbm; FILE* fsf; fbm = fopen(FILENAME_SF, "w"); fsf = fopen(FILENAME_BM, "w"); //Now do the processing and output we have skipped the input part cantBMProcess(conLoadInten, conLoadA, uniIntensity, udlStartPos, lenUDL, fbm, fsf, spanbeam, noseg, nc, nu); printf("Location: index.sh\n\n"); } header(); //displaying the html header displayFile("header.html"); if (cgi.exists("secondaryparameter")) { displayFile("output.html"); displayFile("footer.html"); return 0; } //displaying the main form displayFile("form.html"); //Display the footer file displayFile("footer.html"); return 0; }
int main() { //The very first and basic step of CGI to output Content-Type header(); //The database connection holder sqlite3* db; //Open the connection to database int ret=sqlite3_open("photo.db",&db); if (ret!=SQLITE_OK) { cout<<"Database cannot be establishment"; return 1; } //Library to parse GET, POST and FILE Data CGI cgi; //MainApp object that controls the object MainApp app(db); //Display the header file displayFile("header.html"); //The container to output the content cout<<"<div class='container-fluid' style='text-align:center;" <<"background-color:#dceaf4; margin-left:3%;" <<" margin-right:3%'>"<<endl; //Display appropriate Buttons cout<<"<div class='btn-group' style='margin:2%; text-align:center" <<"'>" <<"<a class='btn' href='main.cgi'>Home</a>" <<"<a class='btn' href='main.cgi?action=createalbum'>" <<"Create Album</a>"; //Show content according to the action value if (strcmp(cgi.value("action"),"viewalbum")==0) { //Display the album displayAlbum(app,db,cgi,cgi.value("id")); } else if (strcmp(cgi.value("action"),"viewphoto")==0) { //Display the given photo displayPhoto(db, cgi.value("id"),cgi); } else if (strcmp(cgi.value("action"),"createalbum")==0) { //Display the form to create album createAlbum(); } else if (strcmp(cgi.value("action"),"deletephoto")==0) { //Delete the given photo deletePhoto(cgi,db,cgi.value("id")); } else if (strcmp(cgi.value("editalbum-action"),"1")==0) { //This is initiated when Form to edit album is submitted stringstream sql; sql<<"update album set albumname='"<<cgi.value("albumname") <<"' where id="<<cgi.value("id"); //Close the Button Group Division cout<<"</div>"; //IF sql was successful then if (sqlite3_exec(db,sql.str().c_str(),NULL,NULL,NULL) ==SQLITE_OK) { cout<<"<script type='text/javascript'>" <<"window.location='main.cgi'</script>"; } else //If there is an error { cout<<"<div class='alert alert-error'>" <<"Cannot Update name in database."; } } else if (strcmp(cgi.value("action"),"editalbum")==0) { //Display the form to edit album editAlbum(cgi,db); } else if (strcmp(cgi.value("action"),"deletealbum")==0) { //Delete the given album and all its photos deleteAlbum(db,cgi.value("id")); } else if (strcmp(cgi.value("createalbum-action"),"1")==0) { //This is initiated when create album form is posted //Close the btn group division cout<<"</div>"; //Add the album if (app.addAlbum(cgi.value("albumname"))) { cout<<"<div class='alert alert-success'>" <<"Album Successful Created</div>"; } else { cout<<"<div class='alert alert-error'>" <<"Error Occured while creating album</div>"; } } else { //The default section which is executed when none of //above option is selected displayAlbumLinks(db); } //Close the btn group div as all the options has been added cout<<"</div>"; //Display the Footer HTML displayFile("footer.html"); return 0; }