Skip to content

Commit 75e1c51

Browse files
committed
Pass context pointer to compression functions.
1 parent be9acef commit 75e1c51

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

ceshim.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct ceshim_info {
118118
int iv_sz; // IV blob size in bytes
119119

120120
// Pointers to custom compress functions implemented by the user
121+
void *pCtx;
121122
int (*xCompressBound)(void *pCtx, int nSrc);
122123
int (*xCompress)(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc);
123124
int (*xUncompress)(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc);
@@ -987,7 +988,7 @@ static int ceshimRead(
987988
);
988989

989990
if( ccStatus==kCCSuccess ){
990-
pInfo->xUncompress(NULL, pUncBuf, &iDstAmt, pCmpBuf, (int)tmp_csz);
991+
pInfo->xUncompress(pInfo->pCtx, pUncBuf, &iDstAmt, pCmpBuf, (int)tmp_csz);
991992
assert( iDstAmt==uppPgSz );
992993
u16 uBufOfst = iOfst % uppPgSz;
993994
memcpy(zBuf, pUncBuf+uBufOfst, iAmt);
@@ -1028,11 +1029,11 @@ static int ceshimWrite(
10281029

10291030
if( !p->bReadOnly ){
10301031
// compress
1031-
int pnDest = pInfo->xCompressBound(NULL, iAmt);
1032+
int pnDest = pInfo->xCompressBound(pInfo->pCtx, iAmt);
10321033
void* pCmpBuf = sqlite3_malloc(pnDest);
10331034
if( pCmpBuf ){
10341035
CeshimCmpOfst cmprPgOfst;
1035-
pInfo->xCompress(NULL, pCmpBuf, &pnDest, (void *)zBuf, iAmt);
1036+
pInfo->xCompress(pInfo->pCtx, pCmpBuf, &pnDest, (void *)zBuf, iAmt);
10361037

10371038
// encrypt
10381039
/* According to CCCryptor manpage: "For block ciphers, the output size will always be less than or
@@ -1700,17 +1701,17 @@ static int ceshimGetLastError(sqlite3_vfs *pVfs, int iErr, char *zErr){
17001701
}
17011702

17021703
/*
1703-
** Clients invoke this routine to construct a new ceshim.
1704+
** Clients invoke ceshim_register to construct a new ceshim.
17041705
**
17051706
** Return SQLITE_OK on success.
17061707
**
17071708
** SQLITE_NOMEM is returned in the case of a memory allocation error.
17081709
** SQLITE_NOTFOUND is returned if zOldVfsName does not exist.
17091710
*/
17101711
int _ceshim_register(
1711-
const char *zName, // Name of the newly constructed VFS
1712-
const char *zParent, // Name of the underlying VFS
1713-
void *pCtx, // Currently not used. Use to pass contectual data to cmpression routines
1712+
const char *zName,
1713+
const char *zParent,
1714+
void *pCtx,
17141715
int (*xCompressBound)(void *, int nSrc),
17151716
int (*xCompress)(void *, char *aDest, int *pnDest, char *aSrc, int nSrc),
17161717
int (*xUncompress)(void *, char *aDest, int *pnDest, char *aSrc, int nSrc),
@@ -1742,7 +1743,6 @@ int _ceshim_register(
17421743

17431744
// Intialize data
17441745
memcpy((char*)&pInfo[1], zName, nName+1);
1745-
pInfo->cerod_activated = cerodActivated;
17461746
pNew->iVersion = pRoot->iVersion;
17471747
pNew->szOsFile = pRoot->szOsFile + sizeof(ceshim_file);
17481748
pNew->mxPathname = pRoot->mxPathname;
@@ -1767,9 +1767,11 @@ int _ceshim_register(
17671767
pNew->xNextSystemCall = 0;
17681768
}
17691769
}
1770+
pInfo->cerod_activated = cerodActivated;
17701771
pInfo->pRootVfs = pRoot;
17711772
pInfo->zVfsName = pNew->zName;
17721773
pInfo->pCeshimVfs = pNew;
1774+
pInfo->pCtx = pCtx;
17731775
pInfo->xCompressBound = xCompressBound;
17741776
pInfo->xCompress = xCompress;
17751777
pInfo->xUncompress = xUncompress;
@@ -1781,9 +1783,9 @@ int _ceshim_register(
17811783
}
17821784

17831785
int ceshim_register(
1784-
const char *zName, /* Name of the newly constructed VFS */
1785-
const char *zParent, /* Name of the underlying VFS */
1786-
void *pCtx,
1786+
const char *zName, // Name of the newly constructed VFS
1787+
const char *zParent, // Name of the underlying VFS
1788+
void *pCtx, // Used to pass contextual data to compression routines
17871789
int (*xCompressBound)(void *, int nSrc),
17881790
int (*xCompress)(void *, char *aDest, int *pnDest, char *aSrc, int nSrc),
17891791
int (*xUncompress)(void *, char *aDest, int *pnDest, char *aSrc, int nSrc)
@@ -1801,11 +1803,11 @@ int ceshim_unregister(const char *zName){
18011803
return SQLITE_NOTFOUND;
18021804
}
18031805

1804-
int ceshimDefaultCompressBound(void *p, int nByte){
1806+
int ceshimDefaultCompressBound(void *pCtx, int nByte){
18051807
return (int)compressBound(nByte);
18061808
}
18071809

1808-
int ceshimDefaultCompress(void *p, char *aDest, int *pnDest, char *aSrc, int nSrc){
1810+
int ceshimDefaultCompress(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc){
18091811
uLongf n = *pnDest; /* In/out buffer size for compress() */
18101812
int rc; /* compress() return code */
18111813

@@ -1814,7 +1816,7 @@ int ceshimDefaultCompress(void *p, char *aDest, int *pnDest, char *aSrc, int nSr
18141816
return (rc==Z_OK ? SQLITE_OK : SQLITE_ERROR);
18151817
}
18161818

1817-
int ceshimDefaultUncompress(void *p, char *aDest, int *pnDest, char *aSrc, int nSrc){
1819+
int ceshimDefaultUncompress(void *pCtx, char *aDest, int *pnDest, char *aSrc, int nSrc){
18181820
uLongf n = *pnDest; /* In/out buffer size for uncompress() */
18191821
int rc; /* uncompress() return code */
18201822

0 commit comments

Comments
 (0)