aboutsummaryrefslogtreecommitdiff
path: root/lzo.c
diff options
context:
space:
mode:
Diffstat (limited to 'lzo.c')
-rw-r--r--lzo.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/lzo.c b/lzo.c
index 6ea0d03..3d6aa5a 100644
--- a/lzo.c
+++ b/lzo.c
@@ -32,6 +32,8 @@
#include "memdbg.h"
+#ifndef LZO_STUB
+
static bool
lzo_adaptive_compress_test (struct lzo_adaptive_compress *ac)
{
@@ -79,6 +81,8 @@ lzo_adaptive_compress_data (struct lzo_adaptive_compress *ac, int n_total, int n
ac->n_comp += n_comp;
}
+#endif /* LZO_STUB */
+
void lzo_adjust_frame_parameters (struct frame *frame)
{
/* Leave room for our one-byte compressed/didn't-compress prefix byte. */
@@ -94,14 +98,18 @@ lzo_compress_init (struct lzo_compress_workspace *lzowork, unsigned int flags)
{
CLEAR (*lzowork);
- lzowork->wmem_size = LZO_WORKSPACE;
lzowork->flags = flags;
+#ifndef LZO_STUB
+ lzowork->wmem_size = LZO_WORKSPACE;
if (lzo_init () != LZO_E_OK)
msg (M_FATAL, "Cannot initialize LZO compression library");
lzowork->wmem = (lzo_voidp) lzo_malloc (lzowork->wmem_size);
check_malloc_return (lzowork->wmem);
- msg (M_INFO, "LZO compression initialized");
+ msg (D_INIT_MEDIUM, "LZO compression initialized");
+#else
+ msg (D_INIT_MEDIUM, "LZO stub compression initialized");
+#endif
lzowork->defined = true;
}
@@ -111,8 +119,10 @@ lzo_compress_uninit (struct lzo_compress_workspace *lzowork)
if (lzowork)
{
ASSERT (lzowork->defined);
+#ifndef LZO_STUB
lzo_free (lzowork->wmem);
lzowork->wmem = NULL;
+#endif
lzowork->defined = false;
}
}
@@ -120,6 +130,7 @@ lzo_compress_uninit (struct lzo_compress_workspace *lzowork)
static inline bool
lzo_compression_enabled (struct lzo_compress_workspace *lzowork)
{
+#ifndef LZO_STUB
if ((lzowork->flags & (LZO_SELECTED|LZO_ON)) == (LZO_SELECTED|LZO_ON))
{
if (lzowork->flags & LZO_ADAPTIVE)
@@ -127,6 +138,7 @@ lzo_compression_enabled (struct lzo_compress_workspace *lzowork)
else
return true;
}
+#endif
return false;
}
@@ -139,15 +151,18 @@ lzo_compress (struct buffer *buf, struct buffer work,
struct lzo_compress_workspace *lzowork,
const struct frame* frame)
{
+#ifndef LZO_STUB
lzo_uint zlen = 0;
int err;
bool compressed = false;
+#endif
ASSERT (lzowork->defined);
if (buf->len <= 0)
return;
+#ifndef LZO_STUB
/*
* In order to attempt compression, length must be at least COMPRESS_THRESHOLD,
* and our adaptive level must give the OK.
@@ -193,6 +208,7 @@ lzo_compress (struct buffer *buf, struct buffer work,
*buf = work;
}
else
+#endif
{
uint8_t *header = buf_prepend (buf, 1);
*header = NO_COMPRESS;
@@ -204,9 +220,11 @@ lzo_decompress (struct buffer *buf, struct buffer work,
struct lzo_compress_workspace *lzowork,
const struct frame* frame)
{
+#ifndef LZO_STUB
lzo_uint zlen = EXPANDED_SIZE (frame);
- uint8_t c; /* flag indicating whether or not our peer compressed */
int err;
+#endif
+ uint8_t c; /* flag indicating whether or not our peer compressed */
ASSERT (lzowork->defined);
@@ -220,6 +238,7 @@ lzo_decompress (struct buffer *buf, struct buffer work,
if (c == YES_COMPRESS) /* packet was compressed */
{
+#ifndef LZO_STUB
ASSERT (buf_safe (&work, zlen));
err = LZO_DECOMPRESS (BPTR (buf), BLEN (buf), BPTR (&work), &zlen,
lzowork->wmem);
@@ -238,6 +257,11 @@ lzo_decompress (struct buffer *buf, struct buffer work,
lzowork->post_decompress += work.len;
*buf = work;
+#else
+ dmsg (D_COMP_ERRORS, "LZO decompression error: LZO capability not compiled");
+ buf->len = 0;
+ return;
+#endif
}
else if (c == NO_COMPRESS) /* packet was not compressed */
{
@@ -264,10 +288,12 @@ void lzo_print_stats (const struct lzo_compress_workspace *lzo_compwork, struct
{
ASSERT (lzo_compwork->defined);
+#ifndef LZO_STUB
status_printf (so, "pre-compress bytes," counter_format, lzo_compwork->pre_compress);
status_printf (so, "post-compress bytes," counter_format, lzo_compwork->post_compress);
status_printf (so, "pre-decompress bytes," counter_format, lzo_compwork->pre_decompress);
status_printf (so, "post-decompress bytes," counter_format, lzo_compwork->post_decompress);
+#endif
}
#else