NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
decompress()

Decompress header cache data. More...

+ Collaboration diagram for decompress():

Functions

static void * compr_lz4_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 
static void * compr_zlib_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 
static void * compr_zstd_decompress (ComprHandle *handle, const char *cbuf, size_t clen)
 Decompress header cache data - Implements ComprOps::decompress() -.
 

Detailed Description

Decompress header cache data.

Parameters
[in]handleCompression handle
[in]cbufData to be decompressed
[in]clenLength of the compressed input data
Return values
ptrSuccess, pointer to decompressed data
NULLOtherwise
Note
This function returns a pointer to data, which will be freed by the close() function.

Function Documentation

◆ compr_lz4_decompress()

static void * compr_lz4_decompress ( ComprHandle handle,
const char *  cbuf,
size_t  clen 
)
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 138 of file lz4.c.

139{
140 if (!handle)
141 return NULL;
142
143 // Decloak an opaque pointer
144 struct Lz4ComprData *cdata = handle;
145
146 /* first 4 bytes store the size */
147 const unsigned char *cs = (const unsigned char *) cbuf;
148 if (clen < 4)
149 return NULL;
150 size_t ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((size_t) cs[3] << 24);
151 if (ulen > INT_MAX)
152 return NULL; // LCOV_EXCL_LINE
153 if (ulen == 0)
154 return (void *) cbuf;
155
156 mutt_mem_realloc(&cdata->buf, ulen);
157 void *ubuf = cdata->buf;
158 const char *data = cbuf;
159 int rc = LZ4_decompress_safe(data + 4, ubuf, clen - 4, ulen);
160 if (rc < 0)
161 return NULL;
162
163 return ubuf;
164}
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
Private Lz4 Compression Data.
Definition: lz4.c:47
void * buf
Temporary buffer.
Definition: lz4.c:48
+ Here is the call graph for this function:

◆ compr_zlib_decompress()

static void * compr_zlib_decompress ( ComprHandle handle,
const char *  cbuf,
size_t  clen 
)
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 135 of file zlib.c.

136{
137 if (!handle)
138 return NULL;
139
140 // Decloak an opaque pointer
141 struct ZlibComprData *cdata = handle;
142
143 /* first 4 bytes store the size */
144 const unsigned char *cs = (const unsigned char *) cbuf;
145 if (clen < 4)
146 return NULL;
147 uLong ulen = cs[0] + (cs[1] << 8) + (cs[2] << 16) + ((uLong) cs[3] << 24);
148 if (ulen == 0)
149 return NULL;
150
151 mutt_mem_realloc(&cdata->buf, ulen);
152 Bytef *ubuf = cdata->buf;
153 cs = (const unsigned char *) cbuf;
154 int rc = uncompress(ubuf, &ulen, cs + 4, clen - 4);
155 if (rc != Z_OK)
156 return NULL;
157
158 return ubuf;
159}
Private Zlib Compression Data.
Definition: zlib.c:47
void * buf
Temporary buffer.
Definition: zlib.c:48
+ Here is the call graph for this function:

◆ compr_zstd_decompress()

static void * compr_zstd_decompress ( ComprHandle handle,
const char *  cbuf,
size_t  clen 
)
static

Decompress header cache data - Implements ComprOps::decompress() -.

Definition at line 139 of file zstd.c.

140{
141 if (!handle)
142 return NULL;
143
144 // Decloak an opaque pointer
145 struct ZstdComprData *cdata = handle;
146
147 unsigned long long len = ZSTD_getFrameContentSize(cbuf, clen);
148 if (len == ZSTD_CONTENTSIZE_UNKNOWN)
149 return NULL; // LCOV_EXCL_LINE
150 else if (len == ZSTD_CONTENTSIZE_ERROR)
151 return NULL;
152 else if (len == 0)
153 return NULL; // LCOV_EXCL_LINE
154 mutt_mem_realloc(&cdata->buf, len);
155
156 size_t rc = ZSTD_decompressDCtx(cdata->dctx, cdata->buf, len, cbuf, clen);
157 if (ZSTD_isError(rc))
158 return NULL; // LCOV_EXCL_LINE
159
160 return cdata->buf;
161}
Private Zstandard Compression Data.
Definition: zstd.c:46
ZSTD_DCtx * dctx
Decompression context.
Definition: zstd.c:51
void * buf
Temporary buffer.
Definition: zstd.c:47
+ Here is the call graph for this function: