mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 14:25:38 +03:00
Fix for nvault not loading on some Linux servers - nvault no longer uses exceptions, so libstdc++ is no longer needed
This commit is contained in:
parent
b0286c9c4d
commit
69a8a86ff6
@ -14,51 +14,66 @@ bool BinaryWriter::WriteAddr(void *buffer, size_t size)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteUInt32(uint32_t num)
|
bool BinaryWriter::WriteUInt32(uint32_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(uint32_t)) )
|
if ( !WriteAddr(&num, sizeof(uint32_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteInt32(int32_t num)
|
bool BinaryWriter::WriteInt32(int32_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(int32_t)) )
|
if ( !WriteAddr(&num, sizeof(int32_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteUInt16(uint16_t num)
|
bool BinaryWriter::WriteUInt16(uint16_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(uint16_t)) )
|
if ( !WriteAddr(&num, sizeof(uint16_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteInt16(int16_t num)
|
bool BinaryWriter::WriteInt16(int16_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(int16_t)) )
|
if ( !WriteAddr(&num, sizeof(int16_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteUInt8(uint8_t num)
|
bool BinaryWriter::WriteUInt8(uint8_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(uint8_t)) )
|
if ( !WriteAddr(&num, sizeof(uint8_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteInt8(int8_t num)
|
bool BinaryWriter::WriteInt8(int8_t num)
|
||||||
{
|
{
|
||||||
if ( !WriteAddr(&num, sizeof(int8_t)) )
|
if ( !WriteAddr(&num, sizeof(int8_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::WriteChars(const char buffer[], size_t chars)
|
bool BinaryWriter::WriteChars(const char buffer[], size_t chars)
|
||||||
{
|
{
|
||||||
if (!chars)
|
if (!chars)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
if (fwrite(buffer, sizeof(char), chars, m_Fp) != chars)
|
if (fwrite(buffer, sizeof(char), chars, m_Fp) != chars)
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BinaryReader::BinaryReader(FILE *fp)
|
BinaryReader::BinaryReader(FILE *fp)
|
||||||
{
|
{
|
||||||
m_Fp = fp;
|
m_Fp = fp;
|
||||||
@ -71,74 +86,62 @@ bool BinaryReader::ReadAddr(void *buffer, size_t size)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool BinaryReader::ReadUInt32(uint32_t& num)
|
||||||
uint32_t BinaryReader::ReadUInt32()
|
|
||||||
{
|
{
|
||||||
uint32_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(uint32_t)) )
|
if ( !ReadAddr(&num, sizeof(uint32_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t BinaryReader::ReadInt32()
|
bool BinaryReader::ReadInt32(int32_t& num)
|
||||||
{
|
{
|
||||||
int32_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(int32_t)) )
|
if ( !ReadAddr(&num, sizeof(int32_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t BinaryReader::ReadUInt16()
|
bool BinaryReader::ReadUInt16(uint16_t& num)
|
||||||
{
|
{
|
||||||
uint16_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(uint16_t)) )
|
if ( !ReadAddr(&num, sizeof(uint16_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t BinaryReader::ReadInt16()
|
bool BinaryReader::ReadInt16(int16_t& num)
|
||||||
{
|
{
|
||||||
int16_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(int16_t)) )
|
if ( !ReadAddr(&num, sizeof(int16_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BinaryReader::ReadUInt8()
|
bool BinaryReader::ReadUInt8(uint8_t& num)
|
||||||
{
|
{
|
||||||
uint8_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(uint8_t)) )
|
if ( !ReadAddr(&num, sizeof(uint8_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t BinaryReader::ReadInt8()
|
bool BinaryReader::ReadInt8(int8_t& num)
|
||||||
{
|
{
|
||||||
int8_t num;
|
|
||||||
|
|
||||||
if ( !ReadAddr(&num, sizeof(int8_t)) )
|
if ( !ReadAddr(&num, sizeof(int8_t)) )
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return num;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *BinaryReader::ReadChars(char buffer[], size_t chars)
|
bool BinaryReader::ReadChars(char buffer[], size_t chars)
|
||||||
{
|
{
|
||||||
if (!chars)
|
if (!chars)
|
||||||
return buffer;
|
return true;
|
||||||
|
|
||||||
if (fread(buffer, sizeof(char), chars, m_Fp) != chars)
|
if (fread(buffer, sizeof(char), chars, m_Fp) != chars)
|
||||||
throw -1;
|
return false;
|
||||||
|
|
||||||
return buffer;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@ public:
|
|||||||
BinaryReader(FILE *fp);
|
BinaryReader(FILE *fp);
|
||||||
//~BinaryReader();
|
//~BinaryReader();
|
||||||
public:
|
public:
|
||||||
uint32_t ReadUInt32();
|
bool ReadUInt32(uint32_t& num);
|
||||||
int32_t ReadInt32();
|
bool ReadInt32(int32_t& num);
|
||||||
uint16_t ReadUInt16();
|
bool ReadUInt16(uint16_t& num);
|
||||||
int16_t ReadInt16();
|
bool ReadInt16(int16_t& num);
|
||||||
uint8_t ReadUInt8();
|
bool ReadUInt8(uint8_t& num);
|
||||||
int8_t ReadInt8();
|
bool ReadInt8(int8_t& num);
|
||||||
char *ReadChars(char buffer[], size_t chars);
|
bool ReadChars(char buffer[], size_t chars);
|
||||||
private:
|
private:
|
||||||
bool ReadAddr(void *buffer, size_t size);
|
bool ReadAddr(void *buffer, size_t size);
|
||||||
private:
|
private:
|
||||||
@ -31,13 +31,13 @@ public:
|
|||||||
BinaryWriter(FILE *fp);
|
BinaryWriter(FILE *fp);
|
||||||
public:
|
public:
|
||||||
void SetFilePtr(FILE *fp) { m_Fp = fp; }
|
void SetFilePtr(FILE *fp) { m_Fp = fp; }
|
||||||
void WriteUInt32(uint32_t num);
|
bool WriteUInt32(uint32_t num);
|
||||||
void WriteInt32(int32_t num);
|
bool WriteInt32(int32_t num);
|
||||||
void WriteUInt16(uint16_t num);
|
bool WriteUInt16(uint16_t num);
|
||||||
void WriteInt16(int16_t num);
|
bool WriteInt16(int16_t num);
|
||||||
void WriteUInt8(uint8_t num);
|
bool WriteUInt8(uint8_t num);
|
||||||
void WriteInt8(int8_t num);
|
bool WriteInt8(int8_t num);
|
||||||
void WriteChars(const char buffer[], size_t chars);
|
bool WriteChars(const char buffer[], size_t chars);
|
||||||
private:
|
private:
|
||||||
bool WriteAddr(void *buffer, size_t size);
|
bool WriteAddr(void *buffer, size_t size);
|
||||||
private:
|
private:
|
||||||
|
@ -34,29 +34,47 @@ int Journal::Replay(VaultMap *pMap)
|
|||||||
time_t stamp;
|
time_t stamp;
|
||||||
JOp op;
|
JOp op;
|
||||||
int ops = 0;
|
int ops = 0;
|
||||||
|
uint8_t temp8;
|
||||||
|
|
||||||
try
|
uint32_t itemp;
|
||||||
{
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
op = static_cast<JOp>(br.ReadUInt8());
|
if (!br.ReadUInt8(temp8)) goto fail;
|
||||||
|
op = static_cast<JOp>(temp8);
|
||||||
if (op == Journal_Clear)
|
if (op == Journal_Clear)
|
||||||
{
|
{
|
||||||
pMap->Clear();
|
pMap->Clear();
|
||||||
} else if (op == Journal_Prune) {
|
} else if (op == Journal_Prune) {
|
||||||
time_t start;
|
time_t start;
|
||||||
time_t end;
|
time_t end;
|
||||||
start = static_cast<time_t>(br.ReadUInt32());
|
|
||||||
end = static_cast<time_t>(br.ReadUInt32());
|
if (!br.ReadUInt32(itemp)) goto fail;
|
||||||
|
start = static_cast<time_t>(itemp);
|
||||||
|
|
||||||
|
if (!br.ReadUInt32(itemp)) goto fail;
|
||||||
|
end = static_cast<time_t>(itemp);
|
||||||
|
|
||||||
pMap->Prune(start, end);
|
pMap->Prune(start, end);
|
||||||
|
|
||||||
} else if (op == Journal_Insert) {
|
} else if (op == Journal_Insert) {
|
||||||
stamp = static_cast<time_t>(br.ReadUInt32());
|
|
||||||
len8 = br.ReadUInt8();
|
|
||||||
|
if (!br.ReadUInt32(itemp)) goto fail;
|
||||||
|
stamp = static_cast<time_t>(itemp);
|
||||||
|
|
||||||
|
if (!br.ReadUInt8(len8)) goto fail;
|
||||||
|
|
||||||
key = new char[len8+1];
|
key = new char[len8+1];
|
||||||
br.ReadChars(key, len8);
|
if (!br.ReadChars(key, len8)) goto fail;
|
||||||
len16 = br.ReadUInt16();
|
|
||||||
|
if (!br.ReadUInt16(len16)) goto fail;
|
||||||
val = new char[len16+1];
|
val = new char[len16+1];
|
||||||
br.ReadChars(val, len16);
|
|
||||||
|
if (!br.ReadChars(val, len16)) goto fail;
|
||||||
|
|
||||||
key[len8] = '\0';
|
key[len8] = '\0';
|
||||||
val[len16] = '\0';
|
val[len16] = '\0';
|
||||||
sKey.assign(key);
|
sKey.assign(key);
|
||||||
@ -68,16 +86,21 @@ int Journal::Replay(VaultMap *pMap)
|
|||||||
delete [] val;
|
delete [] val;
|
||||||
val = NULL;
|
val = NULL;
|
||||||
} else if (op == Journal_Remove) {
|
} else if (op == Journal_Remove) {
|
||||||
len8 = br.ReadUInt8();
|
|
||||||
|
if (!br.ReadUInt8(len8)) goto fail;
|
||||||
|
|
||||||
key = new char[len8+1];
|
key = new char[len8+1];
|
||||||
br.ReadChars(key, len8);
|
if (!br.ReadChars(key, len8)) goto fail;
|
||||||
key[len8] = '\0';
|
key[len8] = '\0';
|
||||||
sKey.assign(key);
|
sKey.assign(key);
|
||||||
pMap->Remove(sKey);
|
pMap->Remove(sKey);
|
||||||
}
|
}
|
||||||
ops++;
|
ops++;
|
||||||
} while (op < Journal_TotalOps && op);
|
} while (op < Journal_TotalOps && op);
|
||||||
} catch (...) {
|
goto success;
|
||||||
|
// } catch (...) {
|
||||||
|
|
||||||
|
fail:
|
||||||
//journal is done
|
//journal is done
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
@ -89,8 +112,9 @@ int Journal::Replay(VaultMap *pMap)
|
|||||||
delete [] val;
|
delete [] val;
|
||||||
val = NULL;
|
val = NULL;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
success:
|
||||||
fclose(m_fp);
|
fclose(m_fp);
|
||||||
|
|
||||||
return ops;
|
return ops;
|
||||||
@ -112,73 +136,81 @@ bool Journal::End()
|
|||||||
|
|
||||||
bool Journal::Write_Clear()
|
bool Journal::Write_Clear()
|
||||||
{
|
{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
WriteOp(Journal_Clear);
|
if (!WriteOp(Journal_Clear)) goto fail;
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
// } catch (...) {
|
||||||
|
fail:
|
||||||
return false;
|
return false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Journal::Write_Insert(const char *key, const char *val, time_t stamp)
|
bool Journal::Write_Insert(const char *key, const char *val, time_t stamp)
|
||||||
{
|
{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
WriteOp(Journal_Insert);
|
if (!WriteOp(Journal_Insert)) goto fail;
|
||||||
WriteInt32(static_cast<int32_t>(stamp));
|
if (!WriteInt32(static_cast<int32_t>(stamp))) goto fail;
|
||||||
WriteString(key, Encode_Small);
|
if (!WriteString(key, Encode_Small)) goto fail;
|
||||||
WriteString(val, Encode_Medium);
|
if (!WriteString(val, Encode_Medium)) goto fail;
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
// } catch (...) {
|
||||||
|
fail:
|
||||||
return false;
|
return false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Journal::Write_Prune(time_t start, time_t end)
|
bool Journal::Write_Prune(time_t start, time_t end)
|
||||||
{
|
{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
WriteOp(Journal_Prune);
|
if (!WriteOp(Journal_Prune)) goto fail;
|
||||||
WriteInt32(static_cast<int32_t>(start));
|
if (!WriteInt32(static_cast<int32_t>(start))) goto fail;
|
||||||
WriteInt32(static_cast<int32_t>(end));
|
if (!WriteInt32(static_cast<int32_t>(end))) goto fail;
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
// } catch (...) {
|
||||||
|
|
||||||
|
fail:
|
||||||
return false;
|
return false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Journal::Write_Remove(const char *key)
|
bool Journal::Write_Remove(const char *key)
|
||||||
{
|
{
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
WriteOp(Journal_Remove);
|
if (!WriteOp(Journal_Remove)) goto fail;
|
||||||
WriteString(key, Encode_Small);
|
if (!WriteString(key, Encode_Small)) goto fail;
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
// } catch (...) {
|
||||||
|
|
||||||
|
fail:
|
||||||
return false;
|
return false;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Journal::WriteInt32(int num)
|
bool Journal::WriteInt32(int num)
|
||||||
{
|
{
|
||||||
m_Bw.WriteInt32(num);
|
return m_Bw.WriteInt32(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Journal::WriteOp(JOp op)
|
bool Journal::WriteOp(JOp op)
|
||||||
{
|
{
|
||||||
m_Bw.WriteUInt8(static_cast<uint8_t>(op));
|
return m_Bw.WriteUInt8(static_cast<uint8_t>(op));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Journal::WriteString(const char *str, Encode enc)
|
bool Journal::WriteString(const char *str, Encode enc)
|
||||||
{
|
{
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
if (enc == Encode_Small)
|
if (enc == Encode_Small)
|
||||||
{
|
{
|
||||||
m_Bw.WriteUInt8(static_cast<uint8_t>(len));
|
if (!m_Bw.WriteUInt8(static_cast<uint8_t>(len))) return false;
|
||||||
} else if (enc == Encode_Medium) {
|
} else if (enc == Encode_Medium) {
|
||||||
m_Bw.WriteUInt16(static_cast<uint16_t>(len));
|
if (!m_Bw.WriteUInt16(static_cast<uint16_t>(len))) return false;
|
||||||
}
|
}
|
||||||
m_Bw.WriteChars(str, len);
|
return m_Bw.WriteChars(str, len);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ public:
|
|||||||
bool Write_Insert(const char *key, const char *val, time_t stamp);
|
bool Write_Insert(const char *key, const char *val, time_t stamp);
|
||||||
bool Write_Remove(const char *key);
|
bool Write_Remove(const char *key);
|
||||||
private:
|
private:
|
||||||
void WriteOp(JOp op);
|
bool WriteOp(JOp op);
|
||||||
void WriteInt32(int num);
|
bool WriteInt32(int num);
|
||||||
void WriteString(const char *str, Encode enc);
|
bool WriteString(const char *str, Encode enc);
|
||||||
private:
|
private:
|
||||||
String m_File;
|
String m_File;
|
||||||
FILE *m_fp;
|
FILE *m_fp;
|
||||||
|
@ -8,7 +8,7 @@ MM_ROOT = ../../metamod/metamod
|
|||||||
|
|
||||||
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -fomit-frame-pointer
|
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -fomit-frame-pointer
|
||||||
DEBUG_FLAGS = -g -ggdb3
|
DEBUG_FLAGS = -g -ggdb3
|
||||||
CPP = gcc-3.3
|
CPP = gcc-4.1
|
||||||
NAME = nvault
|
NAME = nvault
|
||||||
|
|
||||||
BIN_SUFFIX_32 = amxx_i386.so
|
BIN_SUFFIX_32 = amxx_i386.so
|
||||||
@ -16,7 +16,8 @@ BIN_SUFFIX_64 = amxx_amd64.so
|
|||||||
|
|
||||||
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp Binary.cpp Journal.cpp NVault.cpp
|
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp Binary.cpp Journal.cpp NVault.cpp
|
||||||
|
|
||||||
LINK = /lib/libgcc_eh-3.3.a /lib/libstdc++-3.3-pic.a
|
#LINK = /lib/libgcc_eh.a /lib/libstdc++-3.4.a
|
||||||
|
LINK =
|
||||||
|
|
||||||
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \
|
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \
|
||||||
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk
|
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk
|
||||||
@ -35,7 +36,7 @@ else
|
|||||||
CFLAGS = $(OPT_FLAGS)
|
CFLAGS = $(OPT_FLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -DNDEBUG -fPIC -Wall -Werror -fexceptions -DHAVE_STDINT_H -fno-rtti -static-libgcc
|
CFLAGS += -DNDEBUG -fPIC -Wall -Werror -DHAVE_STDINT_H -fno-rtti -static-libgcc -fno-exceptions
|
||||||
|
|
||||||
ifeq "$(AMD64)" "true"
|
ifeq "$(AMD64)" "true"
|
||||||
BINARY = $(NAME)_$(BIN_SUFFIX_64)
|
BINARY = $(NAME)_$(BIN_SUFFIX_64)
|
||||||
|
@ -45,10 +45,12 @@ NVault::NVault(const char *file)
|
|||||||
fp = fopen(m_File.c_str(), "wb");
|
fp = fopen(m_File.c_str(), "wb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
throw Vault_NoFile;
|
this->m_Valid = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->m_Valid = true;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,20 +84,36 @@ VaultError NVault::_ReadFromFile()
|
|||||||
String sKey;
|
String sKey;
|
||||||
String sVal;
|
String sVal;
|
||||||
|
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
int32_t magic = br.ReadUInt32();
|
uint32_t magic;
|
||||||
|
if (!br.ReadUInt32(magic)) goto fail;
|
||||||
|
|
||||||
if (magic != VAULT_MAGIC)
|
if (magic != VAULT_MAGIC)
|
||||||
return Vault_BadFile;
|
return Vault_BadFile;
|
||||||
int16_t version = br.ReadUInt16();
|
|
||||||
|
|
||||||
|
uint16_t version;
|
||||||
|
if (!br.ReadUInt16(version)) goto fail;
|
||||||
|
|
||||||
if (version != VAULT_VERSION)
|
if (version != VAULT_VERSION)
|
||||||
return Vault_OldFile;
|
return Vault_OldFile;
|
||||||
int32_t entries = br.ReadUInt32();
|
|
||||||
|
int32_t entries;
|
||||||
|
|
||||||
|
if (!br.ReadInt32(entries)) goto fail;
|
||||||
|
|
||||||
|
|
||||||
|
int32_t temp;
|
||||||
for (int32_t i=0; i<entries; i++)
|
for (int32_t i=0; i<entries; i++)
|
||||||
{
|
{
|
||||||
stamp = static_cast<time_t>(br.ReadInt32());
|
if (!br.ReadInt32(temp)) goto fail;
|
||||||
keylen = br.ReadUInt8();
|
|
||||||
vallen = br.ReadUInt16();
|
stamp = static_cast<time_t>(temp);
|
||||||
|
|
||||||
|
if (!br.ReadUInt8(keylen)) goto fail;
|
||||||
|
if (!br.ReadUInt16(vallen)) goto fail;
|
||||||
|
|
||||||
if (keylen > oldkeylen)
|
if (keylen > oldkeylen)
|
||||||
{
|
{
|
||||||
if (key)
|
if (key)
|
||||||
@ -110,15 +128,21 @@ VaultError NVault::_ReadFromFile()
|
|||||||
val = new char[vallen + 1];
|
val = new char[vallen + 1];
|
||||||
oldvallen = vallen;
|
oldvallen = vallen;
|
||||||
}
|
}
|
||||||
br.ReadChars(key, keylen);
|
|
||||||
br.ReadChars(val, vallen);
|
if (!br.ReadChars(key, keylen)) goto fail;
|
||||||
|
if (!br.ReadChars(val, vallen)) goto fail;
|
||||||
|
|
||||||
key[keylen] = '\0';
|
key[keylen] = '\0';
|
||||||
val[vallen] = '\0';
|
val[vallen] = '\0';
|
||||||
sKey.assign(key);
|
sKey.assign(key);
|
||||||
sVal.assign(val);
|
sVal.assign(val);
|
||||||
m_Hash.Insert(sKey, sVal, stamp);
|
m_Hash.Insert(sKey, sVal, stamp);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
|
// } catch (...) {
|
||||||
|
|
||||||
|
goto success;
|
||||||
|
fail:
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
delete [] key;
|
delete [] key;
|
||||||
@ -131,8 +155,9 @@ VaultError NVault::_ReadFromFile()
|
|||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return Vault_Read;
|
return Vault_Read;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
success:
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return Vault_Ok;
|
return Vault_Ok;
|
||||||
@ -149,37 +174,44 @@ bool NVault::_SaveToFile()
|
|||||||
|
|
||||||
BinaryWriter bw(fp);
|
BinaryWriter bw(fp);
|
||||||
|
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
int32_t magic = VAULT_MAGIC;
|
uint32_t magic = VAULT_MAGIC;
|
||||||
int16_t version = VAULT_VERSION;
|
uint16_t version = VAULT_VERSION;
|
||||||
|
|
||||||
bw.WriteUInt32(magic);
|
|
||||||
bw.WriteUInt16(version);
|
|
||||||
|
|
||||||
bw.WriteUInt32( m_Hash.Size() );
|
|
||||||
|
|
||||||
time_t stamp;
|
time_t stamp;
|
||||||
String key;
|
String key;
|
||||||
String val;
|
String val;
|
||||||
|
|
||||||
THash<String,String>::iterator iter = m_Hash.begin();
|
THash<String,String>::iterator iter = m_Hash.begin();
|
||||||
|
|
||||||
|
if (!bw.WriteUInt32(magic)) goto fail;
|
||||||
|
if (!bw.WriteUInt16(version)) goto fail;
|
||||||
|
|
||||||
|
if (!bw.WriteUInt32( m_Hash.Size() )) goto fail;
|
||||||
|
|
||||||
while (iter != m_Hash.end())
|
while (iter != m_Hash.end())
|
||||||
{
|
{
|
||||||
key = (*iter).key;
|
key = (*iter).key;
|
||||||
val = (*iter).val;
|
val = (*iter).val;
|
||||||
stamp = (*iter).stamp;
|
stamp = (*iter).stamp;
|
||||||
bw.WriteInt32(static_cast<int32_t>(stamp));
|
|
||||||
bw.WriteUInt8( key.size() );
|
if (!bw.WriteInt32(static_cast<int32_t>(stamp))) goto fail;;
|
||||||
bw.WriteUInt16( val.size() );
|
if (!bw.WriteUInt8( key.size() )) goto fail;
|
||||||
bw.WriteChars( key.c_str(), key.size() );
|
if (!bw.WriteUInt16( val.size() )) goto fail;
|
||||||
bw.WriteChars( val.c_str(), val.size() );
|
if (!bw.WriteChars( key.c_str(), key.size() )) goto fail;
|
||||||
|
if (!bw.WriteChars( val.c_str(), val.size() )) goto fail;
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
|
goto success;
|
||||||
|
// } catch (...) {
|
||||||
|
|
||||||
|
fail:
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return false;
|
return false;
|
||||||
}
|
// }
|
||||||
|
success:
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
@ -324,10 +356,14 @@ bool NVault::GetValue(const char *key, time_t &stamp, char buffer[], size_t len)
|
|||||||
IVault *VaultMngr::OpenVault(const char *file)
|
IVault *VaultMngr::OpenVault(const char *file)
|
||||||
{
|
{
|
||||||
NVault *pVault;
|
NVault *pVault;
|
||||||
try
|
//try
|
||||||
{
|
//{
|
||||||
pVault = new NVault(file);
|
pVault = new NVault(file);
|
||||||
} catch (...) {
|
|
||||||
|
// } catch (...) {
|
||||||
|
if (!pVault->isValid())
|
||||||
|
{
|
||||||
|
delete pVault;
|
||||||
pVault = NULL;
|
pVault = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@ private:
|
|||||||
THash<String, String> m_Hash;
|
THash<String, String> m_Hash;
|
||||||
Journal *m_Journal;
|
Journal *m_Journal;
|
||||||
bool m_Open;
|
bool m_Open;
|
||||||
|
|
||||||
|
bool m_Valid;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool isValid() { return m_Valid; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class VaultMngr : public IVaultMngr
|
class VaultMngr : public IVaultMngr
|
||||||
|
@ -22,6 +22,12 @@ CQueue<int> g_OldVaults;
|
|||||||
|
|
||||||
VaultMngr g_VaultMngr;
|
VaultMngr g_VaultMngr;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
extern "C" void __cxa_pure_virtual(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static cell nvault_open(AMX *amx, cell *params)
|
static cell nvault_open(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
int len, id=-1;
|
int len, id=-1;
|
||||||
|
Loading…
Reference in New Issue
Block a user