#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)