1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#ifndef MAINTENANCE_H_
#define MAINTENANCE_H_
#include "config.h"
#include "meta.h"
#include "sockio.h"
#include "acbuf.h"
#ifdef DEBUG
#define MTLOGDEBUG(x) { SendFmt << x << "\n<br>\n"; }
#define MTLOGASSERT(x, y) {if(!(x)) SendFmt << "<div class=\"ERROR\">" << y << "</div>\n<br>\n";}
//#define MTLOGVERIFY(x, y) MTLOGASSERT(x, y)
#else
#define MTLOGASSERT(x, y) {}
#define MTLOGDEBUG(x) {}
//#define MTLOGVERIFY(x, y) x
#endif
#define MAINT_PFX "maint_"
namespace acng
{
class tSpecialRequest
{
public:
enum eMaintWorkType : char
{
workNotSpecial =0,
// expiration types
workExExpire,
workExList,
workExPurge,
workExListDamaged,
workExPurgeDamaged,
workExTruncDamaged,
//workBGTEST,
workUSERINFO,
workMAINTREPORT,
workAUTHREQUEST,
workAUTHREJECT,
workIMPORT,
workMIRROR,
workDELETE,
workDELETECONFIRM,
workCOUNTSTATS,
workSTYLESHEET,
workTraceStart,
workTraceEnd,
// workJStats, // disabled, probably useless
workTRUNCATE,
workTRUNCATECONFIRM
};
struct tRunParms
{
int fd;
tSpecialRequest::eMaintWorkType type;
cmstring cmd;
};
/*!
* @brief Main execution method for maintenance tasks.
*/
virtual void Run() =0;
tSpecialRequest(const tRunParms& parms);
virtual ~tSpecialRequest();
protected:
inline void SendChunk(const mstring &x) { SendChunk(x.data(), x.size()); }
void SendChunk(const char *data, size_t size);
void SendChunkRemoteOnly(const char *data, size_t size);
inline void SendChunk(const char *x) { SendChunk(x, x?strlen(x):0); }
inline void SendChunk(const tSS &x){ SendChunk(x.data(), x.length()); }
// for customization in base classes
virtual void SendChunkLocalOnly(const char* /*data*/, size_t /*size*/) {};
bool SendRawData(const char *data, size_t len, int flags);
mstring & GetHostname();
void SendChunkedPageHeader(const char *httpstatus, const char *mimetype);
LPCSTR m_szDecoFile = nullptr;
LPCSTR GetTaskName();
tRunParms m_parms;
private:
tSpecialRequest(const tSpecialRequest&);
tSpecialRequest& operator=(const tSpecialRequest&);
mstring m_sHostname;
bool m_bChunkHeaderSent=false;
public:
// dirty little RAII helper to send data after formating it, uses a shared buffer presented
// to the user via macro
class tFmtSendObj
{
public:
inline tFmtSendObj(tSpecialRequest *p, bool remoteOnly)
: m_parent(*p), m_bRemoteOnly(remoteOnly) { }
inline ~tFmtSendObj()
{
if (!m_parent.m_fmtHelper.empty())
{
if(m_bRemoteOnly)
m_parent.SendChunkRemoteOnly(m_parent.m_fmtHelper.data(), m_parent.m_fmtHelper.size());
else
m_parent.SendChunk(m_parent.m_fmtHelper);
m_parent.m_fmtHelper.clear();
}
}
tSpecialRequest &m_parent;
private:
tFmtSendObj operator=(const tSpecialRequest::tFmtSendObj&);
bool m_bRemoteOnly;
};
#define SendFmt tFmtSendObj(this, false).m_parent.m_fmtHelper
#define SendFmtRemote tFmtSendObj(this, true).m_parent.m_fmtHelper
#define SendChunkSZ(x) SendChunk(WITHLEN(x))
tSS m_fmtHelper;
static eMaintWorkType DispatchMaintWork(cmstring &cmd, const char *auth);
static void RunMaintWork(eMaintWorkType jobType, cmstring& cmd, int fd);
protected:
static tSpecialRequest* MakeMaintWorker(const tRunParms& parms);
};
}
#endif /*MAINTENANCE_H_*/
|