NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
zstrm.h File Reference

Zlib compression of network traffic. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mutt_zstrm_wrap_conn (struct Connection *conn)
 Wrap a compression layer around a Connection.
 

Detailed Description

Zlib compression of network traffic.

Authors
  • Fabian Groffen

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file zstrm.h.

Function Documentation

◆ mutt_zstrm_wrap_conn()

void mutt_zstrm_wrap_conn ( struct Connection conn)

Wrap a compression layer around a Connection.

Parameters
connConnection to wrap

Replace the read/write functions with our compression functions. After reading from the socket, we decompress and pass on the data. Before writing to a socket, we compress the data.

Definition at line 291 of file zstrm.c.

292{
293 struct ZstrmContext *zctx = MUTT_MEM_CALLOC(1, struct ZstrmContext);
294
295 /* store wrapped stream as next stream */
296 zctx->next_conn.fd = conn->fd;
297 zctx->next_conn.sockdata = conn->sockdata;
298 zctx->next_conn.open = conn->open;
299 zctx->next_conn.close = conn->close;
300 zctx->next_conn.read = conn->read;
301 zctx->next_conn.write = conn->write;
302 zctx->next_conn.poll = conn->poll;
303
304 /* replace connection with our wrappers, where appropriate */
305 conn->sockdata = zctx;
306 conn->open = zstrm_open;
307 conn->read = zstrm_read;
308 conn->write = zstrm_write;
309 conn->close = zstrm_close;
310 conn->poll = zstrm_poll;
311
312 /* allocate/setup (de)compression buffers */
313 zctx->read.len = 8192;
314 zctx->read.buf = MUTT_MEM_MALLOC(zctx->read.len, char);
315 zctx->read.pos = 0;
316 zctx->write.len = 8192;
317 zctx->write.buf = MUTT_MEM_MALLOC(zctx->write.len, char);
318 zctx->write.pos = 0;
319
320 /* initialise zlib for inflate and deflate for RFC4978 */
321 zctx->read.z.zalloc = zstrm_malloc;
322 zctx->read.z.zfree = zstrm_free;
323 zctx->read.z.opaque = NULL;
324 zctx->read.z.avail_out = zctx->read.len;
325 (void) inflateInit2(&zctx->read.z, -15);
326 zctx->write.z.zalloc = zstrm_malloc;
327 zctx->write.z.zfree = zstrm_free;
328 zctx->write.z.opaque = NULL;
329 zctx->write.z.avail_out = zctx->write.len;
330 (void) deflateInit2(&zctx->write.z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8,
331 Z_DEFAULT_STRATEGY);
332}
static int zstrm_close(struct Connection *conn)
Close a socket - Implements Connection::close() -.
Definition: zstrm.c:100
static int zstrm_open(struct Connection *conn)
Open a socket - Implements Connection::open() -.
Definition: zstrm.c:92
static int zstrm_poll(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition: zstrm.c:214
static int zstrm_read(struct Connection *conn, char *buf, size_t len)
Read compressed data from a socket - Implements Connection::read() -.
Definition: zstrm.c:132
static int zstrm_write(struct Connection *conn, const char *buf, size_t count)
Write compressed data to a socket - Implements Connection::write() -.
Definition: zstrm.c:231
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
#define MUTT_MEM_MALLOC(n, type)
Definition: memory.h:41
void * sockdata
Backend-specific socket data.
Definition: connection.h:55
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition: connection.h:105
int(* write)(struct Connection *conn, const char *buf, size_t count)
Definition: connection.h:92
int(* close)(struct Connection *conn)
Definition: connection.h:116
int(* open)(struct Connection *conn)
Definition: connection.h:66
int fd
Socket file descriptor.
Definition: connection.h:53
int(* read)(struct Connection *conn, char *buf, size_t count)
Definition: connection.h:79
Data compression layer.
Definition: zstrm.c:58
struct ZstrmDirection read
Data being read and de-compressed.
Definition: zstrm.c:59
struct ZstrmDirection write
Data being compressed and written.
Definition: zstrm.c:60
struct Connection next_conn
Underlying stream.
Definition: zstrm.c:61
unsigned int pos
Current position.
Definition: zstrm.c:49
unsigned int len
Length of data.
Definition: zstrm.c:48
z_stream z
zlib compression handle
Definition: zstrm.c:46
char * buf
Buffer for data being (de-)compressed.
Definition: zstrm.c:47
static void * zstrm_malloc(void *opaque, unsigned int items, unsigned int size)
Redirector function for zlib's malloc()
Definition: zstrm.c:71
static void zstrm_free(void *opaque, void *address)
Redirector function for zlib's free()
Definition: zstrm.c:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function: