Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione P@rtners 2.0 patch 349 git-svn-id: svn://10.65.10.50/trunk@10573 c028cbd2-c16b-5b4b-a496-9718f37d4682
82 lines
1.7 KiB
C++
Executable File
82 lines
1.7 KiB
C++
Executable File
#include "BaseServ.h"
|
|
|
|
class TCoffeeServer : public TBaseServerApp
|
|
{
|
|
protected:
|
|
virtual const wxChar* GetAppName() const;
|
|
virtual void ProcessCommand(wxString cmd, wxSocketBase& outs);
|
|
|
|
public:
|
|
bool IsMagicName(wxString& strFilename) const;
|
|
void GenerateFile(wxString& strFilename);
|
|
};
|
|
|
|
// Implementare almeno queste due funzioni pure virtuali
|
|
|
|
const wxChar* TCoffeeServer::GetAppName() const
|
|
{
|
|
return "Coffee";
|
|
}
|
|
|
|
bool TCoffeeServer::IsMagicName(wxString& strFilename) const
|
|
{
|
|
wxString strName;
|
|
wxSplitPath(strFilename, NULL, &strName, NULL);
|
|
strName.MakeLower();
|
|
if (strName == "index")
|
|
{
|
|
strFilename = strName;
|
|
return true;
|
|
}
|
|
if (strName == "log")
|
|
{
|
|
strFilename = GetLogFileName();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void TCoffeeServer::GenerateFile(wxString& strFilename)
|
|
{
|
|
wxString strName;
|
|
wxSplitPath(strFilename, NULL, &strName, NULL);
|
|
strName.MakeLower();
|
|
if (strName == "index")
|
|
{
|
|
TXmlItem html;
|
|
TXmlItem& body = CreatePageBody(html);
|
|
|
|
TXmlItem& cen = body.AddChild("h1").AddChild("center");
|
|
cen << "Just Kidding :-)";
|
|
cen.AddChild("br");
|
|
cen.AddChild("img").SetAttr("src", GetConfigString("Icon"));
|
|
strFilename = GetTempFilename();
|
|
body.Save(strFilename);
|
|
}
|
|
if (strName == "log")
|
|
{
|
|
strFilename = GetLogFileName();
|
|
}
|
|
}
|
|
|
|
void TCoffeeServer::ProcessCommand(wxString cmd, wxSocketBase& outs)
|
|
{
|
|
if (cmd.StartsWith("GET "))
|
|
{
|
|
const int stop = cmd.Find(" HTTP");
|
|
wxString str = cmd.Mid(4, stop-4).Trim();
|
|
if (str == "/")
|
|
str += "index.htm";
|
|
wxString strFilename = GetDocumentRoot() + str;
|
|
|
|
if (IsMagicName(strFilename))
|
|
GenerateFile(strFilename);
|
|
|
|
SendFile(strFilename, outs);
|
|
}
|
|
}
|
|
|
|
// Istanziare l'applicazione principale
|
|
|
|
IMPLEMENT_APP(TCoffeeServer)
|