2014-08-04 14:38:42 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// NVault Module
|
|
|
|
//
|
|
|
|
|
2005-07-31 10:07:48 +04:00
|
|
|
#ifndef _INCLUDE_JOURNAL_H
|
|
|
|
#define _INCLUDE_JOURNAL_H
|
|
|
|
|
|
|
|
#include "Binary.h"
|
2014-08-10 18:57:53 +04:00
|
|
|
#include <am-linkedlist.h>
|
|
|
|
#include <sm_stringhashmap.h>
|
|
|
|
#include <am-string.h>
|
|
|
|
|
2005-07-31 10:07:48 +04:00
|
|
|
enum JOp
|
|
|
|
{
|
|
|
|
Journal_Nop=0, //no operation
|
|
|
|
Journal_Clear, //clears, no parameters
|
|
|
|
Journal_Prune, //prunes, two params (start, end, 32bit both)
|
|
|
|
Journal_Insert, //inserts stamp (32), key (8+[]), val (16+[])
|
|
|
|
Journal_Remove, //removes key(8+[])
|
|
|
|
Journal_TotalOps,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Encode
|
|
|
|
{
|
|
|
|
Encode_Small,
|
|
|
|
Encode_Medium,
|
|
|
|
};
|
|
|
|
|
2014-08-10 18:57:53 +04:00
|
|
|
struct ArrayInfo
|
|
|
|
{
|
|
|
|
ke::AString value;
|
|
|
|
time_t stamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef StringHashMap<ArrayInfo> VaultMap;
|
2005-07-31 10:07:48 +04:00
|
|
|
|
|
|
|
class Journal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Journal(const char *file);
|
|
|
|
public:
|
|
|
|
bool Begin();
|
|
|
|
bool End();
|
|
|
|
int Replay(VaultMap *pMap);
|
|
|
|
bool Erase();
|
|
|
|
public:
|
|
|
|
bool Write_Clear();
|
|
|
|
bool Write_Prune(time_t start, time_t end);
|
|
|
|
bool Write_Insert(const char *key, const char *val, time_t stamp);
|
|
|
|
bool Write_Remove(const char *key);
|
|
|
|
private:
|
2008-03-04 22:06:39 +03:00
|
|
|
bool WriteOp(JOp op);
|
|
|
|
bool WriteInt32(int num);
|
|
|
|
bool WriteString(const char *str, Encode enc);
|
2005-07-31 10:07:48 +04:00
|
|
|
private:
|
2014-08-10 18:57:53 +04:00
|
|
|
ke::AString m_File;
|
2005-07-31 10:07:48 +04:00
|
|
|
FILE *m_fp;
|
|
|
|
BinaryWriter m_Bw;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_INCLUDE_JOURNAL_H
|
|
|
|
|