Macros | Functions
COMPR: COMPRESS extension for NNTP

This module provides optional support for data compression and decompression according to RFC 8054. More...

Macros

#define MAIN_ERR_PREFIX   "COMPR: "
 Message prefix for COMPRESSION module.
 
#define CMPR_DEBUG   0
 Print debug messages to stdout if nonzero.
 
#define CMPR_BUFSIZE   (size_t) 32768
 Size of internal data buffers. More...
 
#define CMPR_ZLIB_WINDOW_BITS   -15
 Window size for DEFLATE algorithm. More...
 
#define CMPR_ZLIB_MEM_LEVEL   9
 Memory usage for DEFLATE algorithm. More...
 

Functions

posix_ssize_t cmpr_send (void *stream, const void *buf, size_t len)
 Send data. More...
 
int cmpr_flush (void *stream)
 Flush TX direction. More...
 
int cmpr_terminate (void *stream)
 Flush TX direction and terminate data stream. More...
 
posix_ssize_t cmpr_recv (void *stream, void *buf, size_t len, int peek)
 Receive data. More...
 
struct cmpr_stream * cmpr_stream_constructor (unsigned int alg, int sd, ssize_t(*tx_send)(int, const void *, size_t, int), ssize_t(*rx_recv)(int, void *, size_t, int))
 Compressed data stream object constructor. More...
 
void cmpr_stream_destructor (void *stream)
 Destroy compressed data stream object allocated by compression module. More...
 
int cmpr_init (void)
 Initialize compression module.
 
void cmpr_exit (void)
 Shutdown compress module.
 

Flush options for TX direction of compressed data streams

The flags can be bitwise ORed together.

#define CMPR_FLUSH_NO   0
 
#define CMPR_FLUSH_YES   1
 
#define CMPR_FLUSH_END   2
 

Compression algorithms

#define CMPR_ALG_DEFLATE   0x0001U
 DEFLATE according to RFC 1951.
 

Detailed Description

This module provides optional support for data compression and decompression according to RFC 8054.

Currently the following algorithms are supported:

Note
This module currently works only if the zlib library is available.

Macro Definition Documentation

◆ CMPR_BUFSIZE

#define CMPR_BUFSIZE   (size_t) 32768

Size of internal data buffers.

Attention
The zlib data type uInt must be capable of holding this value.

Definition at line 94 of file compression.c.

◆ CMPR_ZLIB_MEM_LEVEL

#define CMPR_ZLIB_MEM_LEVEL   9

Memory usage for DEFLATE algorithm.

Speed vs. memory usage tradeoff for zlib (integer value from 1 to 9)
1: Minimum memory usage for minimum speed
9: Maximum memory usage for maximum speed

Definition at line 124 of file compression.c.

◆ CMPR_ZLIB_WINDOW_BITS

#define CMPR_ZLIB_WINDOW_BITS   -15

Window size for DEFLATE algorithm.

Compression ratio vs. memory usage tradeoff (integer value from -8 to -15). Negative base two logarithm of the window size (size of the history buffer) for zlib. The negative sign selects raw data without container.
-8: Worst compression and minimum memory usage (256 Byte)
-15: Best compression and maximum memory usage (32 KiByte)

Attention
Don't change this value until you know what you are doing. It must match the setup of the peer.

Definition at line 114 of file compression.c.

Function Documentation

◆ cmpr_flush()

int cmpr_flush ( void *  stream)

Flush TX direction.

Parameters
[in]streamPointer to stream object pointer
Returns
  • 0 on success
  • -1 on error

Definition at line 384 of file compression.c.

References MAIN_ERR_PREFIX.

◆ cmpr_recv()

posix_ssize_t cmpr_recv ( void *  stream,
void *  buf,
size_t  len,
int  peek 
)

Receive data.

Parameters
[in]streamPointer to stream object pointer
[out]bufPointer to data buffer
[in]lenNumber of octets to receive
[in]peekData should stay available for reading if nonzero
Attention
A nonzero value must be used for the len parameter!
Returns
  • Number of bytes received
  • 0 if underlaying protocol lost connection
  • -1 on error

Definition at line 443 of file compression.c.

References CMPR_ALG_DEFLATE, CMPR_BUFSIZE, MAIN_ERR_PREFIX, and PRINT_ERROR.

◆ cmpr_send()

posix_ssize_t cmpr_send ( void *  stream,
const void *  buf,
size_t  len 
)

Send data.

Parameters
[in]streamPointer to stream object pointer
[in]bufPointer to data buffer
[in]lenNumber of octets to send
Returns
  • Number of bytes sent
  • -1 on error

Definition at line 362 of file compression.c.

References MAIN_ERR_PREFIX.

◆ cmpr_stream_constructor()

struct cmpr_stream* cmpr_stream_constructor ( unsigned int  alg,
int  sd,
ssize_t(*)(int, const void *, size_t, int)  tx_send,
ssize_t(*)(int, void *, size_t, int)  rx_recv 
)

Compressed data stream object constructor.

Parameters
[in]algCompression algorithm (use CMPR_ALG_xxx constants)
[in]sdSocket descriptor or stream handle of undelaying protocol
[in]tx_sendSend function to underlaying protocol
[in]rx_recvReceive function for underlaying protocol
Attention
The functions to access the undelaying protocol tx_send() and rx_recv() are expected to behave like send() and recv() defined by POSIX.1-2001 with compatibility to the 4.2BSD implementation regarding flags).
Returns
  • Pointer to constructed object on success
  • NULL on error

Definition at line 615 of file compression.c.

References CMPR_ALG_DEFLATE, CMPR_BUFSIZE, and PRINT_ERROR.

◆ cmpr_stream_destructor()

void cmpr_stream_destructor ( void *  stream)

Destroy compressed data stream object allocated by compression module.

Parameters
[in]streamPointer to object
Note
The pointer p is allowed to be NULL and no operation is performed in this case.

Definition at line 768 of file compression.c.

References CMPR_ALG_DEFLATE, and PRINT_ERROR.

◆ cmpr_terminate()

int cmpr_terminate ( void *  stream)

Flush TX direction and terminate data stream.

Parameters
[in]streamPointer to stream object pointer
Returns
  • 0 on success
  • -1 on error

Definition at line 410 of file compression.c.

References MAIN_ERR_PREFIX.


Generated at 2024-04-27 using  doxygen