2003-01-28 14:27:05 +00:00
|
|
|
#include <wx/wxprec.h>
|
2002-10-24 10:47:49 +00:00
|
|
|
#include <wx/datetime.h>
|
2002-12-20 17:08:30 +00:00
|
|
|
#include <wx/snglinst.h>
|
2002-10-24 10:47:49 +00:00
|
|
|
#include <wx/socket.h>
|
|
|
|
#include <wx/wfstream.h>
|
2004-03-25 10:35:14 +00:00
|
|
|
#ifdef LINUX
|
|
|
|
#include <wx/app.h>
|
|
|
|
#endif
|
2003-05-16 09:24:31 +00:00
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
#include "xml.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// Utilities
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
wxString Date2String(const wxDateTime& date);
|
|
|
|
wxDateTime String2Date(const wxString& str);
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
wxSocketBase& operator<<(wxSocketBase& outf, const wxChar* str);
|
|
|
|
wxSocketBase& operator<<(wxSocketBase& outf, wxString str);
|
|
|
|
wxSocketBase& operator<<(wxSocketBase& outf, size_t num);
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// THashString
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class THashString : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxString m_str;
|
|
|
|
THashString(const wxChar* str) : m_str(str) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// THashTable
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class THashTable : public wxObject
|
|
|
|
{
|
|
|
|
wxHashTable m_Hash;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Put(const wxString& key, const wxString& value);
|
|
|
|
wxString Get(const wxChar* key) const;
|
|
|
|
int GetInt(const wxChar* key) const { return atoi(Get(key)); }
|
|
|
|
wxDateTime GetDate(const wxChar* key) const { return String2Date(Get(key)); }
|
|
|
|
|
|
|
|
size_t GetCount() const { return m_Hash.GetCount(); }
|
|
|
|
void BeginFind() { m_Hash.BeginFind(); }
|
2007-01-03 16:21:58 +00:00
|
|
|
wxHashTable::Node* Next() { return m_Hash.Next(); }
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
THashTable(size_t size = 13);
|
|
|
|
};
|
|
|
|
|
2003-05-16 09:24:31 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// TTaskbarIcon
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <wx/taskbar.h>
|
|
|
|
|
|
|
|
class TTaskBarIcon : public wxTaskBarIcon
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void OnTaskBarClick(wxTaskBarIconEvent& e);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void TTaskBarIcon::Init();
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
// TBaseServerApp
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Define a new application type
|
|
|
|
class TBaseServerApp : public wxApp
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
wxSocketServer* m_server;
|
|
|
|
wxFileOutputStream* m_log;
|
2006-01-23 15:47:36 +00:00
|
|
|
wxString m_strTempDir, m_strIni;
|
2002-10-24 10:47:49 +00:00
|
|
|
bool m_bRunning;
|
|
|
|
int m_nTmpCounter;
|
2003-05-16 09:24:31 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2003-09-11 07:16:13 +00:00
|
|
|
TTaskBarIcon* m_Tray;
|
2003-05-16 09:24:31 +00:00
|
|
|
#endif
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
protected:
|
2002-12-20 17:08:30 +00:00
|
|
|
wxSingleInstanceChecker* m_SingleInstance;
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
// Pure virtual functions!
|
|
|
|
virtual void ProcessCommand(wxString cmd, wxSocketBase& outs) = 0;
|
|
|
|
|
|
|
|
virtual bool CanProcessCommand(wxString& cmd, wxSocketBase& outs);
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
virtual wxString GetDocumentRoot() const;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
virtual TXmlItem& AddLogo(TXmlItem& td) const;
|
|
|
|
|
|
|
|
// Used by SendFile
|
|
|
|
void SendContent(wxFileInputStream& inf, wxSocketBase& sock);
|
|
|
|
void SendNotModifiedFile(wxSocketBase& sock);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Utilities
|
2003-05-16 09:24:31 +00:00
|
|
|
virtual const wxChar* GetAppName() const = 0;
|
2006-01-23 15:47:36 +00:00
|
|
|
virtual const wxString& GetConfigName() const;
|
2003-05-16 09:24:31 +00:00
|
|
|
virtual int GetDefaultPort() const; // Retrieves Port usig GetConfigInt
|
2002-10-24 10:47:49 +00:00
|
|
|
virtual void SetConfigString(const wxChar* key, const wxChar* val, const wxChar* app = NULL) const;
|
2002-12-20 17:08:30 +00:00
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
void SetConfigInt(const wxChar* key, int val, const wxChar* app = NULL) const;
|
|
|
|
virtual wxString GetConfigString(const wxChar* key, const wxChar* def = "", const wxChar* app = NULL) const;
|
|
|
|
int GetConfigInt(const wxChar* key, int def = 0, const wxChar* app = NULL) const; // Uses GetConfigString
|
|
|
|
bool GetConfigBool(const wxChar* key, bool def = false, const wxChar* app = NULL) const; // Uses GetConfigString
|
2002-12-20 17:08:30 +00:00
|
|
|
virtual wxString GetLogFileName() const;
|
|
|
|
|
2002-10-24 10:47:49 +00:00
|
|
|
wxString GetTempFilename();
|
|
|
|
TXmlItem& CreatePageBody(TXmlItem& html, wxString header = "") const;
|
|
|
|
TXmlItem& AddLinkButton(TXmlItem& body, const wxChar* strCaption, const wxChar* strHref) const;
|
|
|
|
|
2002-12-20 17:08:30 +00:00
|
|
|
void SendFile(wxString strFilename, wxSocketBase& sock);
|
|
|
|
void MessageBox(const wxChar* caption, const wxChar* msg, wxSocketBase& sock);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
|
|
|
wxString UnformatString(const wxString& strFormString) const;
|
|
|
|
int ParseArguments(wxString args, THashTable& hashArgs) const;
|
|
|
|
|
|
|
|
virtual void WriteLog(const wxChar* str) const; // Writes on log file if present
|
|
|
|
virtual bool Ok() const { return m_server->Ok(); }
|
|
|
|
virtual bool Initialization() { return true; }
|
|
|
|
virtual bool Deinitialization() { return true; }
|
|
|
|
|
|
|
|
// Initialization (Do NOT use nor reimplement!)
|
|
|
|
virtual bool OnInit();
|
|
|
|
virtual int OnExit();
|
|
|
|
void OnServerEvent(wxSocketEvent& event);
|
|
|
|
void OnSocketEvent(wxSocketEvent& event);
|
|
|
|
DECLARE_EVENT_TABLE();
|
|
|
|
};
|
|
|
|
|
|
|
|
TBaseServerApp& GetServerApp();
|