Skip to content

Commit 70f2c43

Browse files
committed
Move files into its own folder and add Xcode project for development.
Use size_t for size parameters in custom xFunctions and resolve Xcode warnings.
1 parent 60c7ad7 commit 70f2c43

File tree

6 files changed

+374
-54
lines changed

6 files changed

+374
-54
lines changed

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SQLite source files
2+
/cevfs/sqlite/*
3+
!readme.md
4+
5+
# OSX
6+
#
7+
.DS_Store
8+
9+
# Xcode
10+
#
11+
build/
12+
*.pbxuser
13+
!default.pbxuser
14+
*.mode1v3
15+
!default.mode1v3
16+
*.mode2v3
17+
!default.mode2v3
18+
*.perspectivev3
19+
!default.perspectivev3
20+
xcuserdata
21+
*.xccheckout
22+
*.moved-aside
23+
DerivedData
24+
*.hmap
25+
*.ipa
26+
*.xcuserstate
27+
project.xcworkspace
28+
29+
# Android/IJ
30+
#
31+
.idea
32+
.gradle
33+
local.properties

cevfs/cevfs-all.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// cevfs-all.c
3+
// cevfs
4+
//
5+
// Created by Ryan Homer on 26/6/2016.
6+
// Copyright © 2016 Murage Inc. All rights reserved.
7+
//
8+
9+
#include "sqlite/sqlite3-all.c"
10+
#include "cevfs.c"

cevfs.c renamed to cevfs/cevfs.c

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct cevfs_file {
132132
unsigned char zDbHeader[100]; // Sqlite3 DB header
133133
cevfs_header cevfsHeader; // Cevfs header with page mapping data
134134
CevfsMethods vfsMethods; // Custom methods for compression/enctyption
135-
int nEncIvSz; // IV blob size in bytes for encryption/decryption routines
135+
size_t nEncIvSz; // IV blob size in bytes for encryption/decryption routines
136136

137137
// map
138138
CevfsMMTblEntry *mmTbl; // The master mapping table
@@ -150,13 +150,13 @@ struct cevfs_file {
150150
u32 pageSize; // Page size of the lower pager
151151
u32 usableSize; // Number of usable bytes on each page
152152
u8 nTransactions; // Number of open transactions on the pager
153-
153+
154154
// bools
155155
u8 bPgMapDirty:1; // Curr page map needs to be persisted
156156
u8 bReadOnly:1; // True when db was open for read-only
157157
u8 bCompressionEnabled:1;
158158
u8 bEncryptionEnabled:1;
159-
159+
160160
};
161161

162162
/*
@@ -609,19 +609,19 @@ static int cevfsNewDatabase(cevfs_file *pFile){
609609

610610
if( (rc = cevfsPagerWrite(pFile, pP1->pDbPage))==SQLITE_OK ){
611611
// since we are using a secondary pager, set up a proper pager header (see btree.c:1898)
612-
612+
613613
// Set first 16 characters (including NULL terminator)
614614
// to the name of the VFS prefixed with CEVFS-
615615
// This leaves the user with 10 characters to identify the VFS.
616616
const char *prefix = "CEVFS-";
617-
const int iLen1 = strlen(prefix);
618-
const int iLen2 = 15-iLen1;
619-
const int iNameLen = strlen(pInfo->zVfsName);
617+
const size_t iLen1 = strlen(prefix);
618+
const size_t iLen2 = 15-iLen1;
619+
const size_t iNameLen = strlen(pInfo->zVfsName);
620620
memset(data, 0, 16);
621621
memcpy(data, prefix, iLen1);
622622
memcpy(data+iLen1, pInfo->zVfsName, iNameLen > iLen2 ? iLen2 : iNameLen);
623-
assert( strlen(data)<16 );
624-
623+
assert( strlen((const char *)data)<16 );
624+
625625
data[16] = (u8)((pFile->pageSize>>8)&0xff);
626626
data[17] = (u8)((pFile->pageSize>>16)&0xff);
627627
data[18] = 1;
@@ -944,8 +944,8 @@ static int cevfsRead(
944944
pInfo->zVfsName, p->zFName, uppPgno, mappedPgno, iOfst, cmprPgOfst, iAmt, uCmpPgSz
945945
);
946946
assert( uCmpPgSz > 0 );
947-
int iDstAmt = uppPgSz;
948-
void *pUncBuf = sqlite3_malloc(iDstAmt);
947+
size_t iDstAmt = uppPgSz;
948+
void *pUncBuf = sqlite3_malloc((int)iDstAmt);
949949
void *pCmpBuf = sqlite3_malloc(uCmpPgSz);
950950
int bSuccess = 0;
951951

@@ -960,8 +960,8 @@ static int cevfsRead(
960960
// decrypt
961961
if( p->bEncryptionEnabled ){
962962
void *srcData = iv+p->nEncIvSz;
963-
int nDataInSize = uCmpPgSz-p->nEncIvSz;
964-
int nFinalSz;
963+
size_t nDataInSize = uCmpPgSz-p->nEncIvSz;
964+
size_t nFinalSz;
965965

966966
bSuccess = p->vfsMethods.xDecrypt(
967967
pInfo->pCtx,
@@ -972,7 +972,7 @@ static int cevfsRead(
972972
uCmpPgSz, // The size of the dataOut buffer in bytes
973973
&nFinalSz // On successful return, the number of bytes written to dataOut.
974974
);
975-
975+
976976
if( bSuccess ){
977977
uCmpPgSz = nFinalSz;
978978
}
@@ -1030,18 +1030,18 @@ static int cevfsWrite(
10301030

10311031
if( !p->bReadOnly ){
10321032
// compress
1033-
int nDest = p->vfsMethods.xCompressBound(pInfo->pCtx, iAmt);
1034-
void *pCmpBuf = sqlite3_malloc(nDest);
1033+
size_t nDest = p->vfsMethods.xCompressBound(pInfo->pCtx, iAmt);
1034+
void *pCmpBuf = sqlite3_malloc((int)nDest);
10351035
if( pCmpBuf ){
10361036
CevfsCmpOfst cmprPgOfst;
10371037
p->vfsMethods.xCompress(pInfo->pCtx, pCmpBuf, &nDest, (void *)zBuf, iAmt);
10381038

10391039
// encrypt
10401040
void *pEncBuf = NULL;
1041-
size_t tmp_csz;
1041+
size_t tmp_csz = 0;
10421042
int bSuccess = 0;
10431043

1044-
void *iv = sqlite3_malloc(p->nEncIvSz);
1044+
void *iv = sqlite3_malloc((int)p->nEncIvSz);
10451045
if( p->bEncryptionEnabled ){
10461046
bSuccess = p->vfsMethods.xEncrypt(
10471047
pInfo->pCtx,
@@ -1055,7 +1055,7 @@ static int cevfsWrite(
10551055

10561056
if( bSuccess && pEncBuf ){
10571057
// Join IV and pEncBuf. If IV is greater than pInfo->nEncIvSz, it will be truncated.
1058-
void *pIvEncBuf = sqlite3_realloc(iv, p->nEncIvSz+tmp_csz);
1058+
void *pIvEncBuf = sqlite3_realloc(iv, (int)(p->nEncIvSz+tmp_csz));
10591059
memcpy(pIvEncBuf+p->nEncIvSz, pEncBuf, tmp_csz);
10601060

10611061
CevfsCmpSize uIvEncSz = tmp_csz + p->nEncIvSz;
@@ -1376,32 +1376,6 @@ static void cevfsPageReinit(DbPage *pData){
13761376

13771377
}
13781378

1379-
static int cevfsSetKey(char **pKey, const char *pExpr){
1380-
int i, n;
1381-
int rc = SQLITE_OK;
1382-
const char *z;
1383-
1384-
if( (pExpr[0]=='x' || pExpr[0]=='X') && pExpr[1]=='\'' ){
1385-
z = &pExpr[2];
1386-
if( *pKey ){
1387-
sqlite3_free(pKey);
1388-
*pKey = NULL;
1389-
}
1390-
n = sqlite3Strlen30(z) - 1;
1391-
if( z[n]=='\'' ){
1392-
*pKey = (char *)sqlite3_malloc(n/2 + 1);
1393-
n--;
1394-
if( *pKey ){
1395-
for(i=0; i<n; i+=2){
1396-
(*pKey)[i/2] = (sqlite3HexToInt(z[i])<<4) | sqlite3HexToInt(z[i+1]);
1397-
}
1398-
(*pKey)[i/2] = 0;
1399-
}else rc = SQLITE_NOMEM;
1400-
}else rc = CEVFS_ERROR_MALFORMED_KEY;
1401-
}else rc = CEVFS_ERROR_MALFORMED_KEY;
1402-
return rc;
1403-
}
1404-
14051379
/*
14061380
** Open a cevfs file handle.
14071381
*/
@@ -1512,7 +1486,7 @@ static int cevfsOpen(
15121486

15131487
// Call user xAutoDetect to set up VFS methods
15141488
if (pInfo->xAutoDetect) {
1515-
pInfo->xAutoDetect(pInfo->pCtx, _zName, p->zDbHeader+6, &p->nEncIvSz, &p->vfsMethods);
1489+
pInfo->xAutoDetect(pInfo->pCtx, _zName, (const char *)p->zDbHeader+6, &p->nEncIvSz, &p->vfsMethods);
15161490
if (p->vfsMethods.xCompressBound && p->vfsMethods.xCompress && p->vfsMethods.xUncompress)
15171491
p->bCompressionEnabled = true;
15181492
if (p->vfsMethods.xEncrypt && p->vfsMethods.xDecrypt)

cevfs.h renamed to cevfs/cevfs.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,34 @@
2020
#define CEVFS_ERROR_DECRYPTION_FAILED (CEVFS_ERROR | (8<<8))
2121

2222
struct CevfsMethods {
23-
const char *zHdr;
2423
void *pCtx;
25-
int (*xCompressBound)(void *pCtx, int nSrc);
26-
int (*xCompress)(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc);
27-
int (*xUncompress)(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc);
28-
int (*xCompressClose)(void*);
29-
int (*xEncrypt)(void *pCtx, const void *pDataIn, int nDataInSize, void *pIvOut, void **pDataOut, size_t *nDataSizeOut);
30-
int (*xDecrypt)(void *pCtx, const void *pDataIn, int nDataInSize, const void *pIvIn, void *pDataOut, size_t nDataBufferSizeOut, size_t *nDataSizeOut);
24+
25+
int (*xCompressBound)(void *pCtx, size_t nDataInSize);
26+
int (*xCompress) (void *pCtx, char *aDest, size_t *pnDataOutSize, char *aSrc, size_t nDataInSize);
27+
int (*xUncompress)(void *pCtx, char *aDest, size_t *pnDataOutSize, char *aSrc, size_t nDataInSize);
28+
29+
int (*xEncrypt)(
30+
void *pCtx,
31+
const void *pDataIn,
32+
size_t nDataInSize,
33+
void *pIvOut,
34+
void **pDataOut,
35+
size_t *nDataSizeOut
36+
);
37+
38+
int (*xDecrypt)(
39+
void *pCtx,
40+
const void *pDataIn,
41+
size_t nDataInSize,
42+
const void *pIvIn,
43+
void *pDataOut,
44+
size_t nDataBufferSizeOut,
45+
size_t *nDataSizeOut
46+
);
3147
};
3248
typedef struct CevfsMethods CevfsMethods;
3349

34-
typedef int (*t_xAutoDetect)(void *pCtx, const char *zFile, const char *zHdr, int *pEncIvSz, CevfsMethods*);
50+
typedef int (*t_xAutoDetect)(void *pCtx, const char *zFile, const char *zHdr, size_t *pEncIvSz, CevfsMethods*);
3551

3652
int cevfs_create_vfs(
3753
char const *zName, // Name of the newly constructed VFS.

0 commit comments

Comments
 (0)