This document shows the contents of user.cpp if you are starting the tutorial in Part 6. Managing Configuration Files through Part 8. Defining the View Function for Reviewers.
IString User::Action() {
IString Action=IString::lowerCase(Req->GetValue("op"));
if (Action=="") return Error("No Action Specified", "The CGI call did not specify an op= argument.");
switch (Action[1]) {
case 'a':
if (Action=="add") return Add();
break;
case 'c':
if (Action=="complete") return Complete();
break;
case 's':
if (Action=="showadd") return ShowAdd();
break;
case 'v':
if (Action=="view") return View();
}
return Error("Unknown Action Specified","The CGI call requested an unknown action, "+Action);
}
IString Reader::View() {
// Call ReadFile to read the file pointed to by Request::FilePath
IString Result=ReadFile(Req->GetFilepath());
if (Result=="")
return Error("Could Not Read File",
"The file you requested, "
+Req->GetFilename()
+", was empty, or could not be read.");
// Find the first href= attribute.
int href=Result.indexOf("href=");
// Return if there are no href= tags to fix
if (href==0) return Result;
// Substitute the executable name and necessary arguments
// in all href= calls. EXE must be defined in macros.hpp
IString LinkInsert=EXE+"?Op=View+Key="+Req->GetKey()+"+file=";
// Allocate a new IString large enough to contain the new string,
// by determining the number of inserts to do.
int NewLength=Result.occurrencesOf("href=")
*LinkInsert.length()
+Result.length()+1;
char* NewResult=new char[NewLength];
NewResult[0]='\0';
int last=0;
while (href>0) {
// Write from last position written up to past the href=,
// and add the link insertion text
strcat(NewResult,
Result.subString(last+1,href+5-last)+
LinkInsert);
last=href+5;
href=Result.indexOf("href=",last);
}
if (last>0) strcat(NewResult,Result.subString(last+1));
return NewResult; // Automatically converted to an IString
}
IString Reviewer::Add() {
return Error("Unimplemented","Reviewer::Add is not yet implemented");
}
IString Reviewer::ShowAdd() {
return Error("Unimplemented","Reviewer::ShowAdd is not yet implemented");
}
IString Reviewer::View() {
return Error("Unimplemented","Reviewer::View is not yet implemented");
}
IString Author::View() {
return Error("Unimplemented","Author::View is not yet implemented");
}
IString Author::Complete() {
return Error("Unimplemented","Author::Complete is not yet implemented");
}
