additional database implementation; integrated blowfish

This commit is contained in:
Jack Andersen 2015-05-17 23:29:23 -10:00
parent 3cf64ed8da
commit e07ed779d6
13 changed files with 1291 additions and 35 deletions

228
hecl/extern/blowfish/BLOWFISH.C vendored Normal file
View File

@ -0,0 +1,228 @@
#ifdef little_endian /* Eg: Intel */
#include <dos.h>
#include <graphics.h>
#include <io.h>
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef little_endian /* Eg: Intel */
#include <alloc.h>
#endif
#include <ctype.h>
#ifdef little_endian /* Eg: Intel */
#include <dir.h>
#include <bios.h>
#endif
#ifdef big_endian
#include <Types.h>
#endif
#include "Blowfish.h"
#define N 16
#define noErr 0
#define DATAERROR -1
#define KEYBYTES 8
#define subkeyfilename "Blowfish.dat"
unsigned long P[N + 2];
unsigned long S[4][256];
FILE* SubkeyFile;
short opensubkeyfile(void) /* read only */
{
short error;
error = noErr;
if((SubkeyFile = fopen(subkeyfilename,"rb")) == NULL) {
error = DATAERROR;
}
return error;
}
unsigned long F(unsigned long x)
{
unsigned short a;
unsigned short b;
unsigned short c;
unsigned short d;
unsigned long y;
d = x & 0x00FF;
x >>= 8;
c = x & 0x00FF;
x >>= 8;
b = x & 0x00FF;
x >>= 8;
a = x & 0x00FF;
//y = ((S[0][a] + S[1][b]) ^ S[2][c]) + S[3][d];
y = S[0][a] + S[1][b];
y = y ^ S[2][c];
y = y + S[3][d];
return y;
}
void Blowfish_encipher(unsigned long *xl, unsigned long *xr)
{
unsigned long Xl;
unsigned long Xr;
unsigned long temp;
short i;
Xl = *xl;
Xr = *xr;
for (i = 0; i < N; ++i) {
Xl = Xl ^ P[i];
Xr = F(Xl) ^ Xr;
temp = Xl;
Xl = Xr;
Xr = temp;
}
temp = Xl;
Xl = Xr;
Xr = temp;
Xr = Xr ^ P[N];
Xl = Xl ^ P[N + 1];
*xl = Xl;
*xr = Xr;
}
void Blowfish_decipher(unsigned long *xl, unsigned long *xr)
{
unsigned long Xl;
unsigned long Xr;
unsigned long temp;
short i;
Xl = *xl;
Xr = *xr;
for (i = N + 1; i > 1; --i) {
Xl = Xl ^ P[i];
Xr = F(Xl) ^ Xr;
/* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
}
/* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
Xr = Xr ^ P[1];
Xl = Xl ^ P[0];
*xl = Xl;
*xr = Xr;
}
short InitializeBlowfish(char key[], short keybytes)
{
short i;
short j;
short k;
short error;
short numread;
unsigned long data;
unsigned long datal;
unsigned long datar;
/* First, open the file containing the array initialization data */
error = opensubkeyfile();
if (error == noErr) {
for (i = 0; i < N + 2; ++i) {
numread = fread(&data, 4, 1, SubkeyFile);
#ifdef little_endian /* Eg: Intel We want to process things in byte */
/* order, not as rearranged in a longword */
data = ((data & 0xFF000000) >> 24) |
((data & 0x00FF0000) >> 8) |
((data & 0x0000FF00) << 8) |
((data & 0x000000FF) << 24);
#endif
if (numread != 1) {
return DATAERROR;
} else {
P[i] = data;
}
}
for (i = 0; i < 4; ++i) {
for (j = 0; j < 256; ++j) {
numread = fread(&data, 4, 1, SubkeyFile);
#ifdef little_endian /* Eg: Intel We want to process things in byte */
/* order, not as rearranged in a longword */
data = ((data & 0xFF000000) >> 24) |
((data & 0x00FF0000) >> 8) |
((data & 0x0000FF00) << 8) |
((data & 0x000000FF) << 24);
#endif
if (numread != 1) {
return DATAERROR;
} else {
S[i][j] = data;
}
}
}
fclose(SubkeyFile);
j = 0;
for (i = 0; i < N + 2; ++i) {
data = 0x00000000;
for (k = 0; k < 4; ++k) {
data = (data << 8) | key[j];
j = j + 1;
if (j >= keybytes) {
j = 0;
}
}
P[i] = P[i] ^ data;
}
datal = 0x00000000;
datar = 0x00000000;
for (i = 0; i < N + 2; i += 2) {
Blowfish_encipher(&datal, &datar);
P[i] = datal;
P[i + 1] = datar;
}
for (i = 0; i < 4; ++i) {
for (j = 0; j < 256; j += 2) {
Blowfish_encipher(&datal, &datar);
S[i][j] = datal;
S[i][j + 1] = datar;
}
}
} else {
printf("Unable to open subkey initialization file : %d\n", error);
}
return error;
}

BIN
hecl/extern/blowfish/BLOWFISH.DAT vendored Normal file

Binary file not shown.

505
hecl/extern/blowfish/BLOWFISH.DAT.c vendored Normal file
View File

@ -0,0 +1,505 @@
#include <stdlib.h>
size_t BLOWFISH_DAT_SZ = 5006;
char BLOWFISH_DAT[] = {
0x24,0x3F,0x6A,0x88,0x85,0xA3,0x08,0xD3,0x13,0x19,
0x8A,0x2E,0x03,0x70,0x73,0x44,0xA4,0x09,0x38,0x22,
0x29,0x9F,0x31,0xD0,0x08,0x2E,0xFA,0x98,0xEC,0x4E,
0x6C,0x89,0x45,0x28,0x21,0xE6,0x38,0xD0,0x13,0x77,
0xBE,0x54,0x66,0xCF,0x34,0xE9,0x0C,0x6C,0xC0,0xAC,
0x29,0xB7,0xC9,0x7C,0x50,0xDD,0x3F,0x84,0xD5,0xB5,
0xB5,0x47,0x09,0x17,0x92,0x16,0xD5,0xD9,0x89,0x79,
0xFB,0x1B,0xD1,0x31,0x0B,0xA6,0x98,0xDF,0xB5,0xAC,
0x2F,0xFD,0x72,0xDB,0xD0,0x1A,0xDF,0xB7,0xB8,0xE1,
0xAF,0xED,0x6A,0x26,0x7E,0x96,0xBA,0x7C,0x90,0x45,
0xF1,0x2C,0x7F,0x99,0x24,0xA1,0x99,0x47,0xB3,0x91,
0x6C,0xF7,0x08,0x01,0xF2,0xE2,0x85,0x8E,0xFC,0x16,
0x63,0x69,0x20,0xD8,0x71,0x57,0x4E,0x69,0xA4,0x58,
0xFE,0xA3,0xF4,0x93,0x3D,0x7E,0x0D,0x95,0x74,0x8F,
0x72,0x8E,0xB6,0x58,0x71,0x8B,0xCD,0x58,0x82,0x15,
0x4A,0xEE,0x7B,0x54,0xA4,0x1D,0xC2,0x5A,0x59,0xB5,
0x9C,0x30,0xD5,0x39,0x2A,0xF2,0x60,0x13,0xC5,0xD1,
0xB0,0x23,0x28,0x60,0x85,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x3C,0x63,0xAD,
0x45,0x6E,0xDF,0x5F,0x45,0x7A,0x81,0x45,0x51,0x87,
0x5A,0x64,0xCD,0x30,0x99,0xF1,0x69,0xB5,0xF1,0x8A,
0x8C,0x73,0xEE,0x0B,0x5E,0x57,0x36,0x8F,0x6C,0x79,
0xF4,0xBB,0x7A,0x59,0x59,0x26,0xAA,0xB4,0x9E,0xC6,
0x8A,0xC8,0xFC,0xFB,0x80,0x00,
0x0};

8
hecl/extern/blowfish/BLOWFISH.H vendored Normal file
View File

@ -0,0 +1,8 @@
#define MAXKEYBYTES 56 /* 448 bits */
// #define little_endian 1 /* Eg: Intel */
#define big_endian 1 /* Eg: Motorola */
short opensubkeyfile(void);
unsigned long F(unsigned long x);
void Blowfish_encipher(unsigned long *xl, unsigned long *xr);
void Blowfish_decipher(unsigned long *xl, unsigned long *xr);

16
hecl/extern/blowfish/cme.py vendored Normal file
View File

@ -0,0 +1,16 @@
import struct
with open('BLOWFISH.DAT', 'rb') as fin:
with open('BLOWFISH.DAT.c', 'w') as fout:
fout.write('#include <stdlib.h>\n')
fin.seek(0, 2)
sz = fin.tell()
fout.write('size_t BLOWFISH_DAT_SZ = %u;\n' % sz)
fout.write('char BLOWFISH_DAT[] = {')
fin.seek(0)
rb = fin.read(1)
for i in range(sz):
if not i%10:
fout.write('\n ')
fout.write('0x%02X,' % struct.unpack("B", rb)[0])
rb = fin.read(1)
fout.write('\n0x0};\n')

View File

@ -3,12 +3,47 @@
#include <iterator> #include <iterator>
#include <string> #include <string>
#include <functional>
#include <stdint.h>
namespace HECLDatabase namespace HECLDatabase
{ {
class IDatabase; class IDatabase;
/**
* @brief FourCC representation used within HECL's database
*
* FourCCs are efficient, mnemonic four-char-sequences used to represent types
* while fitting comfortably in a 32-bit word. HECL uses a four-char array
* to remain endian-independent
*/
struct FourCC
{
union
{
char fcc[4];
uint32_t num;
};
FourCC(const char* name)
: num(*(uint32_t*)name) {}
};
/**
* @brief Hash representation used for all storable and comparable objects
*
* Hashes are used within HECL to avoid redundant storage of objects;
* providing a rapid mechanism to compare for equality.
*/
class ObjectHash
{
uint64_t hash;
ObjectHash(const void* buf, size_t len)
{
std::hash<std::string> hashfn;
}
};
/** /**
* @brief The IDataObject class * @brief The IDataObject class
* *
@ -22,7 +57,7 @@ public:
* @brief Data-key of object * @brief Data-key of object
* @return Primary key * @return Primary key
*/ */
virtual std::size_t id() const=0; virtual size_t id() const=0;
/** /**
* @brief Textual name of object * @brief Textual name of object
@ -34,7 +69,7 @@ public:
* @brief Data-hash of object * @brief Data-hash of object
* @return Object hash truncated to system's size-type * @return Object hash truncated to system's size-type
*/ */
virtual std::size_t hash() const=0; virtual size_t hash() const=0;
/** /**
* @brief Retrieve the database this object is stored within * @brief Retrieve the database this object is stored within
@ -53,21 +88,21 @@ public:
* @brief Count of objects in the group * @brief Count of objects in the group
* @return object count * @return object count
*/ */
virtual std::size_t length() const=0; virtual size_t length() const=0;
/** /**
* @brief Alias of length() * @brief Alias of length()
* @return object count * @return object count
*/ */
inline std::size_t size() const {return length();} inline size_t size() const {return length();}
/** /**
* @brief Retrieve object at specified internal index within the group * @brief Retrieve object at specified internal index within the group
* @param idx internal index of object to fetch (range [0,length()-1]) * @param idx internal index of object to fetch (range [0,length()-1])
* @return object or nullptr * @return object or nullptr
*/ */
virtual const IDataObject* at(std::size_t idx) const=0; virtual const IDataObject* at(size_t idx) const=0;
inline const IDataObject* operator[](std::size_t idx) {return at(idx);} inline const IDataObject* operator[](size_t idx) {return at(idx);}
/** /**
* @brief Simple IDataDependencyGroup iterator * @brief Simple IDataDependencyGroup iterator
@ -78,7 +113,7 @@ public:
{ {
friend class IDataDependencyGroup; friend class IDataDependencyGroup;
const IDataDependencyGroup& m_grp; const IDataDependencyGroup& m_grp;
std::size_t m_idx = 0; size_t m_idx = 0;
inline iterator(const IDataDependencyGroup& grp) : m_grp(grp) {} inline iterator(const IDataDependencyGroup& grp) : m_grp(grp) {}
public: public:
inline bool operator!=(const iterator& other) inline bool operator!=(const iterator& other)
@ -99,13 +134,13 @@ public:
* @brief Accesses the length of the object (in bytes) * @brief Accesses the length of the object (in bytes)
* @return Data length * @return Data length
*/ */
virtual std::size_t length() const=0; virtual size_t length() const=0;
/** /**
* @brief Alias for the length() function * @brief Alias for the length() function
* @return Data length * @return Data length
*/ */
inline std::size_t size() const {return length();} inline size_t size() const {return length();}
/** /**
* @brief Accesses the object's data * @brief Accesses the object's data
@ -155,7 +190,7 @@ public:
* @param id Primary-key of object * @param id Primary-key of object
* @return Data object * @return Data object
*/ */
virtual const IDataObject* lookupObject(std::size_t id) const=0; virtual const IDataObject* lookupObject(size_t id) const=0;
/** /**
* @brief Lookup object by name * @brief Lookup object by name
@ -171,7 +206,7 @@ public:
* @param length Size of object data to copy * @param length Size of object data to copy
* @return New data object * @return New data object
*/ */
virtual const IDataObject* addDataBlob(const std::string& name, const void* data, std::size_t length)=0; virtual const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)=0;
/** /**
* @brief Insert Data-blob object into a database with read/write access * @brief Insert Data-blob object into a database with read/write access
@ -179,7 +214,7 @@ public:
* @param length size of object data to copy * @param length size of object data to copy
* @return New data object * @return New data object
*/ */
virtual const IDataObject* addDataBlob(const void* data, std::size_t length)=0; virtual const IDataObject* addDataBlob(const void* data, size_t length)=0;
/** /**
* @brief Write a full copy of the database to another type/path * @brief Write a full copy of the database to another type/path

View File

@ -2,6 +2,8 @@
#error This file must only be included from HECLDatabase.cpp #error This file must only be included from HECLDatabase.cpp
#endif #endif
#include <stdio.h>
#include "HECLDatabase.hpp" #include "HECLDatabase.hpp"
#include "CSQLite.hpp" #include "CSQLite.hpp"
@ -34,7 +36,7 @@ public:
return m_access; return m_access;
} }
const IDataObject* lookupObject(std::size_t id) const const IDataObject* lookupObject(size_t id) const
{ {
} }
@ -42,16 +44,26 @@ public:
{ {
} }
const IDataObject* addDataBlob(const std::string& name, const void* data, std::size_t length) const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)
{ {
} }
const IDataObject* addDataBlob(const void* data, std::size_t length) const IDataObject* addDataBlob(const void* data, size_t length)
{ {
} }
bool writeDatabase(IDatabase::Type type, const std::string& path) const bool writeDatabase(IDatabase::Type type, const std::string& path) const
{ {
if (type == PACKED)
{
size_t bufSz;
void* buf = m_sql.fillDBBuffer(bufSz);
FILE* fp = fopen(path.c_str(), "wb");
fwrite(buf, 1, bufSz, fp);
return true;
}
return false;
} }
}; };

View File

@ -14,7 +14,7 @@ class CMemoryDatabase final : public IDatabase
Access m_access; Access m_access;
public: public:
CMemoryDatabase(Access access) CMemoryDatabase(Access access)
: m_sql(":memory:"), m_access(access) : m_sql(":memory:", (m_access == READONLY) ? true : false), m_access(access)
{ {
} }
@ -34,7 +34,7 @@ public:
return m_access; return m_access;
} }
const IDataObject* lookupObject(std::size_t id) const const IDataObject* lookupObject(size_t id) const
{ {
} }
@ -42,11 +42,11 @@ public:
{ {
} }
const IDataObject* addDataBlob(const std::string& name, const void* data, std::size_t length) const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)
{ {
} }
const IDataObject* addDataBlob(const void* data, std::size_t length) const IDataObject* addDataBlob(const void* data, size_t length)
{ {
} }

View File

@ -13,7 +13,7 @@ class CPackedDatabase final : public IDatabase
CSQLite m_sql; CSQLite m_sql;
public: public:
CPackedDatabase(const std::string& path) CPackedDatabase(const std::string& path)
: m_sql(path.c_str(), (m_access == READONLY) ? true : false) : m_sql(path.c_str(), true)
{ {
} }
@ -33,7 +33,7 @@ public:
return READONLY; return READONLY;
} }
const IDataObject* lookupObject(std::size_t id) const const IDataObject* lookupObject(size_t id) const
{ {
} }
@ -41,11 +41,11 @@ public:
{ {
} }
const IDataObject* addDataBlob(const std::string& name, const void* data, std::size_t length) const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)
{ {
} }
const IDataObject* addDataBlob(const void* data, std::size_t length) const IDataObject* addDataBlob(const void* data, size_t length)
{ {
} }

View File

@ -5,6 +5,9 @@
#include <stdexcept> #include <stdexcept>
#include <functional> #include <functional>
#include "HECLDatabase.hpp"
#include "sqlite_hecl_vfs.h"
namespace HECLDatabase namespace HECLDatabase
{ {
@ -36,21 +39,35 @@ if (sqlite3_prepare_v2(m_db, stmtSrc, 0, &outVar, NULL) != SQLITE_OK)\
class CSQLite class CSQLite
{ {
sqlite3* m_db; sqlite3* m_db;
sqlite3_stmt* m_selObjects; sqlite3_stmt* m_selObjects;
sqlite3_stmt* m_selObjectByName; sqlite3_stmt* m_selObjectByName;
sqlite3_stmt* m_selDistictDepGroups; sqlite3_stmt* m_selDistictDepGroups;
sqlite3_stmt* m_selDepGroupObjects; sqlite3_stmt* m_selDepGroupObjects;
sqlite3_stmt* m_insObject;
struct SCloseBuf
{
void* buf = NULL;
size_t sz = 0;
};
static void _vfsClose(void* buf, size_t bufSz, SCloseBuf* ctx)
{
ctx->buf = buf;
ctx->sz = bufSz;
}
public: public:
CSQLite(const char* path, bool readonly) CSQLite(const char* path, bool readonly)
{ {
/* Open database connection */ /* Open database connection */
if (sqlite3_open_v2(path, &m_db, readonly ? int errCode = 0;
if ((errCode = sqlite3_open_v2(path, &m_db, readonly ?
SQLITE_OPEN_READONLY : SQLITE_OPEN_READONLY :
SQLITE_OPEN_READWRITE | SQLITE_OPEN_READWRITE |
SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) SQLITE_OPEN_CREATE, NULL)) != SQLITE_OK)
{ {
throw std::runtime_error(sqlite3_errmsg(m_db)); throw std::runtime_error(sqlite3_errstr(errCode));
sqlite3_close(m_db); sqlite3_close(m_db);
return; return;
} }
@ -71,6 +88,7 @@ public:
PREPSTMT("SELECT rowid FROM objects WHERE name=?1", m_selObjectByName); PREPSTMT("SELECT rowid FROM objects WHERE name=?1", m_selObjectByName);
PREPSTMT("SELECT DISTINCT groupId FROM deplinks", m_selDistictDepGroups); PREPSTMT("SELECT DISTINCT groupId FROM deplinks", m_selDistictDepGroups);
PREPSTMT("SELECT DISTINCT objId FROM deplinks WHERE groupId=?1", m_selDepGroupObjects); PREPSTMT("SELECT DISTINCT objId FROM deplinks WHERE groupId=?1", m_selDepGroupObjects);
PREPSTMT("INSERT INTO objects(name,type4cc,hash64,compLen,decompLen) VALUES (?1,?2,?3,?4,?5)", m_insObject);
} }
~CSQLite() ~CSQLite()
@ -79,19 +97,21 @@ public:
sqlite3_finalize(m_selObjectByName); sqlite3_finalize(m_selObjectByName);
sqlite3_finalize(m_selDistictDepGroups); sqlite3_finalize(m_selDistictDepGroups);
sqlite3_finalize(m_selDepGroupObjects); sqlite3_finalize(m_selDepGroupObjects);
sqlite3_finalize(m_insObject);
sqlite3_close(m_db); sqlite3_close(m_db);
} }
void buildMemoryIndex(const std::function<void(std::size_t&&, // id void buildMemoryIndex(const std::function<void(size_t&&, // id
const std::string&&, // name const std::string&&, // name
uint32_t&&, // type4cc uint32_t&&, // type4cc
uint64_t&&, // hash64 uint64_t&&, // hash64
std::size_t&&, // compLen size_t&&, // compLen
std::size_t&&)>& // decompLen size_t&&)>& // decompLen
objectAdder) objectAdder)
{ {
while (sqlite3_step(m_selObjects) == SQLITE_ROW) while (sqlite3_step(m_selObjects) == SQLITE_ROW)
{ {
/* <3 Move Lambdas!! */
objectAdder(sqlite3_column_int64(m_selObjects, 0), objectAdder(sqlite3_column_int64(m_selObjects, 0),
(const char*)sqlite3_column_text(m_selObjects, 1), (const char*)sqlite3_column_text(m_selObjects, 1),
sqlite3_column_int(m_selObjects, 2), sqlite3_column_int(m_selObjects, 2),
@ -102,16 +122,68 @@ public:
sqlite3_reset(m_selObjects); sqlite3_reset(m_selObjects);
} }
std::size_t objectIdFromName(const std::string& name) size_t objectIdFromName(const std::string& name)
{ {
sqlite3_bind_text(m_selObjectByName, 1, name.c_str(), name.length(), NULL); sqlite3_bind_text(m_selObjectByName, 1, name.c_str(), name.length(), NULL);
std::size_t retval = 0; size_t retval = 0;
if (sqlite3_step(m_selObjectByName) == SQLITE_ROW) if (sqlite3_step(m_selObjectByName) == SQLITE_ROW)
retval = sqlite3_column_int64(m_selObjectByName, 0); retval = sqlite3_column_int64(m_selObjectByName, 0);
sqlite3_reset(m_selObjectByName); sqlite3_reset(m_selObjectByName);
return retval; return retval;
} }
bool insertObject(const std::string& name, const FourCC& type, const ObjectHash& hash, size_t compLen, size_t decompLen)
{
}
void* fillDBBuffer(size_t& bufSzOut) const
{
/* Instructs vfs that a close operation is premature and buffer should be freed */
sqlite_hecl_mem_vfs_register(NULL, NULL);
/* Open pure-memory DB */
sqlite3* memDb;
int errCode;
if ((errCode = sqlite3_open_v2("", &memDb, SQLITE_OPEN_READWRITE, "hecl_mem")) != SQLITE_OK)
{
throw std::runtime_error(sqlite3_errstr(errCode));
sqlite3_close(memDb);
return NULL;
}
/* Perform backup (row copy) */
sqlite3_backup* backup = sqlite3_backup_init(memDb, "main", m_db, "main");
if (!backup)
{
throw std::runtime_error(sqlite3_errmsg(memDb));
sqlite3_close(memDb);
return NULL;
}
sqlite3_backup_step(backup, -1);
sqlite3_backup_finish(backup);
/* Now a close operation is useful; register close callback */
SCloseBuf closeBuf;
sqlite_hecl_mem_vfs_register((TCloseCallback)_vfsClose, &closeBuf);
sqlite3_close(memDb);
/* This should be set by close callback */
if (!closeBuf.buf)
{
throw std::runtime_error("close operation did not write buffer");
return NULL;
}
/* All good! */
bufSzOut = closeBuf.sz;
return closeBuf.buf;
}
static void freeDBBuffer(void* buf)
{
sqlite3_free(buf);
}
}; };
} }

View File

@ -2,7 +2,9 @@ HEADERS += \
$$PWD/CPackedDatabase.hpp \ $$PWD/CPackedDatabase.hpp \
$$PWD/CMemoryDatabase.hpp \ $$PWD/CMemoryDatabase.hpp \
$$PWD/CLooseDatabase.hpp \ $$PWD/CLooseDatabase.hpp \
$$PWD/CSQLite.hpp $$PWD/CSQLite.hpp \
$$PWD/sqlite_hecl_vfs.h
SOURCES += \ SOURCES += \
$$PWD/HECLDatabase.cpp $$PWD/HECLDatabase.cpp \
$$PWD/sqlite_hecl_mem_vfs.c

View File

@ -0,0 +1,361 @@
#include "sqlite_hecl_vfs.h"
#include "sqlite3.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/*
* Modified test_onefile.c VFS for sqlite3
*
* This VFS gets registered with sqlite to access an in-memory,
* block-compressed LBA. It's designed for read-only access of
* a packed object-database.
*
* Journal and temp read/write is unsupported and will call abort
* if attempted.
*/
/*
* App-supplied callback called when file is closed (ready to access)
*/
static TCloseCallback CLOSE_CALLBACK = NULL;
static void* CLOSE_CTX = NULL;
typedef struct mem_file mem_file;
struct mem_file {
sqlite3_file base;
int nSize;
int nAlloc;
char *zAlloc;
};
/*
** Method declarations for mem_file.
*/
static int memClose(sqlite3_file*);
static int memRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
static int memWrite(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
static int memTruncate(sqlite3_file*, sqlite3_int64 size);
static int memSync(sqlite3_file*, int flags);
static int memFileSize(sqlite3_file*, sqlite3_int64 *pSize);
static int memLock(sqlite3_file*, int);
static int memUnlock(sqlite3_file*, int);
static int memCheckReservedLock(sqlite3_file*, int *pResOut);
static int memFileControl(sqlite3_file*, int op, void *pArg);
static int memSectorSize(sqlite3_file*);
static int memDeviceCharacteristics(sqlite3_file*);
/*
** Method declarations for fs_vfs.
*/
static int memOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int memDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int memAccess(sqlite3_vfs*, const char *zName, int flags, int *);
static int memFullPathname(sqlite3_vfs*, const char *zName, int nOut,char *zOut);
static void *memDlOpen(sqlite3_vfs*, const char *zFilename);
static void memDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
static void (*memDlSym(sqlite3_vfs*,void*, const char *zSymbol))(void);
static void memDlClose(sqlite3_vfs*, void*);
static int memRandomness(sqlite3_vfs*, int nByte, char *zOut);
static int memSleep(sqlite3_vfs*, int microseconds);
static int memCurrentTime(sqlite3_vfs*, double*);
static sqlite3_vfs mem_vfs = {
1, /* iVersion */
0, /* szOsFile */
0, /* mxPathname */
0, /* pNext */
"hecl_mem", /* zName */
0, /* pAppData */
memOpen, /* xOpen */
memDelete, /* xDelete */
memAccess, /* xAccess */
memFullPathname, /* xFullPathname */
memDlOpen, /* xDlOpen */
memDlError, /* xDlError */
memDlSym, /* xDlSym */
memDlClose, /* xDlClose */
memRandomness, /* xRandomness */
memSleep, /* xSleep */
memCurrentTime, /* xCurrentTime */
0 /* xCurrentTimeInt64 */
};
static sqlite3_io_methods mem_io_methods = {
1, /* iVersion */
memClose, /* xClose */
memRead, /* xRead */
memWrite, /* xWrite */
memTruncate, /* xTruncate */
memSync, /* xSync */
memFileSize, /* xFileSize */
memLock, /* xLock */
memUnlock, /* xUnlock */
memCheckReservedLock, /* xCheckReservedLock */
memFileControl, /* xFileControl */
memSectorSize, /* xSectorSize */
memDeviceCharacteristics, /* xDeviceCharacteristics */
0, /* xShmMap */
0, /* xShmLock */
0, /* xShmBarrier */
0, /* xShmUnmap */
0,
0
};
/* Useful macros used in several places */
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
/*
** Close a mem-file.
*/
static int memClose(sqlite3_file *pFile){
mem_file *pTmp = (mem_file *)pFile;
if (CLOSE_CALLBACK)
CLOSE_CALLBACK(pTmp->zAlloc, pTmp->nSize, CLOSE_CTX);
else
sqlite3_free(pTmp->zAlloc);
return SQLITE_OK;
}
/*
** Read data from a mem-file.
*/
static int memRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
mem_file *pTmp = (mem_file *)pFile;
if( (iAmt+iOfst)>pTmp->nSize ){
return SQLITE_IOERR_SHORT_READ;
}
memcpy(zBuf, &pTmp->zAlloc[iOfst], iAmt);
return SQLITE_OK;
}
/*
** Write data to a mem-file.
*/
static int memWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
mem_file *pTmp = (mem_file *)pFile;
if( (iAmt+iOfst)>pTmp->nAlloc ){
int nNew = (int)(2*(iAmt+iOfst+pTmp->nAlloc));
char *zNew = sqlite3_realloc(pTmp->zAlloc, nNew);
if( !zNew ){
return SQLITE_NOMEM;
}
pTmp->zAlloc = zNew;
pTmp->nAlloc = nNew;
}
memcpy(&pTmp->zAlloc[iOfst], zBuf, iAmt);
pTmp->nSize = (int)MAX(pTmp->nSize, iOfst+iAmt);
return SQLITE_OK;
}
/*
** Truncate a mem-file.
*/
static int memTruncate(sqlite3_file *pFile, sqlite_int64 size){
mem_file *pTmp = (mem_file *)pFile;
pTmp->nSize = (int)MIN(pTmp->nSize, size);
return SQLITE_OK;
}
/*
** Sync a mem-file.
*/
static int memSync(sqlite3_file *pFile, int flags){
return SQLITE_OK;
}
/*
** Return the current file-size of a mem-file.
*/
static int memFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
mem_file *pTmp = (mem_file *)pFile;
*pSize = pTmp->nSize;
return SQLITE_OK;
}
/*
** Lock a mem-file.
*/
static int memLock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
/*
** Unlock a mem-file.
*/
static int memUnlock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
/*
** Check if another file-handle holds a RESERVED lock on a mem-file.
*/
static int memCheckReservedLock(sqlite3_file *pFile, int *pResOut){
*pResOut = 0;
return SQLITE_OK;
}
/*
** File control method. For custom operations on a mem-file.
*/
static int memFileControl(sqlite3_file *pFile, int op, void *pArg){
return SQLITE_OK;
}
/*
** Return the sector-size in bytes for a mem-file.
*/
static int memSectorSize(sqlite3_file *pFile){
return 0;
}
/*
** Return the device characteristic flags supported by a mem-file.
*/
static int memDeviceCharacteristics(sqlite3_file *pFile){
return 0;
}
/*
** Open an mem file handle.
*/
static int memOpen(
sqlite3_vfs *pVfs,
const char *zName,
sqlite3_file *pFile,
int flags,
int *pOutFlags
){
if (flags != SQLITE_OPEN_MAIN_DB)
{
fprintf(stderr, "the sqlite hecl mem VFS only supports main-db writing\n");
abort();
}
mem_file *p2 = (mem_file *)pFile;
memset(p2, 0, sizeof(*p2));
p2->base.pMethods = &mem_io_methods;
return SQLITE_OK;
}
/*
** Delete the file located at zPath. If the dirSync argument is true,
** ensure the file-system modifications are synced to disk before
** returning.
*/
static int memDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
return SQLITE_OK;
}
/*
** Test for access permissions. Return true if the requested permission
** is available, or false otherwise.
*/
static int memAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
if (flags & SQLITE_ACCESS_READ | SQLITE_ACCESS_READWRITE)
return 1;
return 0;
}
/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (FS_MAX_PATHNAME+1) bytes.
*/
static int memFullPathname(
sqlite3_vfs *pVfs, /* Pointer to vfs object */
const char *zPath, /* Possibly relative input path */
int nOut, /* Size of output buffer in bytes */
char *zOut /* Output buffer */
){
strncpy(zOut, zPath, nOut);
return SQLITE_OK;
}
/*
** Open the dynamic library located at zPath and return a handle.
*/
static void *memDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return NULL;
}
/*
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
** utf-8 string describing the most recent error encountered associated
** with dynamic libraries.
*/
static void memDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
}
/*
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
*/
static void (*memDlSym(sqlite3_vfs *pVfs, void *pH, const char *zSym))(void){
}
/*
** Close the dynamic library handle pHandle.
*/
static void memDlClose(sqlite3_vfs *pVfs, void *pHandle){
}
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of
** random data.
*/
static int memRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
for (int i=0 ; i<nByte ; ++i)
zBufOut[i] = rand();
return nByte;
}
/*
** Sleep for nMicro microseconds. Return the number of microseconds
** actually slept.
*/
static int memSleep(sqlite3_vfs *pVfs, int nMicro){
int seconds = (nMicro+999999)/1000000;
sleep(seconds);
return seconds*1000000;
}
/*
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int memCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
*pTimeOut = 0.0;
return 0;
}
/*
** This procedure registers the mem vfs with SQLite. If the argument is
** true, the mem vfs becomes the new default vfs. It is the only publicly
** available function in this file.
*/
int sqlite_hecl_mem_vfs_register(TCloseCallback closeCb, void* ctx){
CLOSE_CALLBACK = closeCb;
CLOSE_CTX = ctx;
if (mem_vfs.szOsFile) return SQLITE_OK;
mem_vfs.szOsFile = sizeof(mem_file);
return sqlite3_vfs_register(&mem_vfs, 0);
}

View File

@ -0,0 +1,17 @@
#ifndef SQLITE_HECL_VFS
#define SQLITE_HECL_VFS
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
typedef void(*TCloseCallback)(void* buf, size_t bufLen, void* ctx);
int sqlite_hecl_mem_vfs_register(TCloseCallback closeCb, void* ctx);
int sqlite_hecl_memlba_vfs_register(TCloseCallback closeCb, void* ctx);
#ifdef __cplusplus
}
#endif
#endif // SQLITE_HECL_VFS