summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2012-08-26 13:38:44 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2012-08-26 13:38:44 +0000
commit09feef509309fa1500dd65dfd016766811b2e824 (patch)
tree9c68d4491af541188daf326e6dbbc048c734c917 /usr.sbin
parenta10ddaa6927e9019fd1ac0a1c5de462b3b90427e (diff)
- use the same compression algorithm, gzip, for message file and envelopes
- rename compress_zlib.c to compress_gzip.c with this commit it is possible to inspect a compressed queue with gzcat :)
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/compress_backend.c8
-rw-r--r--usr.sbin/smtpd/compress_gzip.c (renamed from usr.sbin/smtpd/compress_zlib.c)96
-rw-r--r--usr.sbin/smtpd/parse.y4
-rw-r--r--usr.sbin/smtpd/smtpctl/Makefile4
-rw-r--r--usr.sbin/smtpd/smtpd/Makefile4
5 files changed, 76 insertions, 40 deletions
diff --git a/usr.sbin/smtpd/compress_backend.c b/usr.sbin/smtpd/compress_backend.c
index ba1774bd055..8f1c2e125c1 100644
--- a/usr.sbin/smtpd/compress_backend.c
+++ b/usr.sbin/smtpd/compress_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compress_backend.c,v 1.2 2012/08/26 10:17:13 chl Exp $ */
+/* $OpenBSD: compress_backend.c,v 1.3 2012/08/26 13:38:43 gilles Exp $ */
/*
* Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
@@ -31,13 +31,13 @@
#include "smtpd.h"
-extern struct compress_backend compress_zlib;
+extern struct compress_backend compress_gzip;
struct compress_backend *
compress_backend_lookup(const char *name)
{
- if (!strcmp(name, "zlib"))
- return &compress_zlib;
+ if (!strcmp(name, "gzip"))
+ return &compress_gzip;
/* if (!strcmp(name, "bzip")) */
/* return &compress_bzip; */
diff --git a/usr.sbin/smtpd/compress_zlib.c b/usr.sbin/smtpd/compress_gzip.c
index de7d8488449..e2b86b1b76d 100644
--- a/usr.sbin/smtpd/compress_zlib.c
+++ b/usr.sbin/smtpd/compress_gzip.c
@@ -1,6 +1,7 @@
-/* $OpenBSD: compress_zlib.c,v 1.4 2012/08/26 11:52:48 gilles Exp $ */
+/* $OpenBSD: compress_gzip.c,v 1.1 2012/08/26 13:38:43 gilles Exp $ */
/*
+ * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
* Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -38,25 +39,25 @@
#include "smtpd.h"
#include "log.h"
-#define ZLIB_BUFFER_SIZE 8192
+#define GZIP_BUFFER_SIZE 8192
-static int compress_file_zlib(int, int);
-static int uncompress_file_zlib(int, int);
-static size_t compress_buffer_zlib(const char *, size_t, char *, size_t);
-static size_t uncompress_buffer_zlib(const char *, size_t, char *, size_t);
+static int compress_file_gzip(int, int);
+static int uncompress_file_gzip(int, int);
+static size_t compress_buffer_gzip(const char *, size_t, char *, size_t);
+static size_t uncompress_buffer_gzip(const char *, size_t, char *, size_t);
-struct compress_backend compress_zlib = {
- compress_file_zlib,
- uncompress_file_zlib,
- compress_buffer_zlib,
- uncompress_buffer_zlib
+struct compress_backend compress_gzip = {
+ compress_file_gzip,
+ uncompress_file_gzip,
+ compress_buffer_gzip,
+ uncompress_buffer_gzip
};
static int
-compress_file_zlib(int fdin, int fdout)
+compress_file_gzip(int fdin, int fdout)
{
gzFile gzfd;
- char buf[ZLIB_BUFFER_SIZE];
+ char buf[GZIP_BUFFER_SIZE];
int r, w;
int ret = 0;
@@ -83,10 +84,10 @@ end:
}
static int
-uncompress_file_zlib(int fdin, int fdout)
+uncompress_file_gzip(int fdin, int fdout)
{
gzFile gzfd;
- char buf[ZLIB_BUFFER_SIZE];
+ char buf[GZIP_BUFFER_SIZE];
int r, w;
int ret = 0;
@@ -113,29 +114,64 @@ end:
}
static size_t
-compress_buffer_zlib(const char *inbuf, size_t inbuflen, char *outbuf, size_t outbuflen)
+compress_buffer_gzip(const char *in, size_t inlen, char *out, size_t outlen)
{
- uLong compress_bound;
- int ret;
-
- compress_bound = compressBound((uLongf) inbuflen);
+ z_stream strm;
+ size_t ret = 0;
- if (compress_bound > outbuflen)
- return (0);
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+
+ ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ (15+16), 8, Z_DEFAULT_STRATEGY);
+ if (ret != Z_OK)
+ return 0;
- ret = compress((Bytef *) outbuf, (uLongf *) &outbuflen,
- (const Bytef *) inbuf, (uLong) inbuflen);
+ strm.avail_in = inlen;
+ strm.next_in = in;
+ strm.avail_out = outlen;
+ strm.next_out = out;
+
+ ret = deflate(&strm, Z_FINISH);
+ if (ret != Z_STREAM_END)
+ goto end;
- return (ret == Z_OK ? outbuflen : 0);
+ ret = strm.total_out;
+
+end:
+ (void)deflateEnd(&strm);
+ return ret;
}
static size_t
-uncompress_buffer_zlib(const char *inbuf, size_t inbuflen, char *outbuf, size_t outbuflen)
+uncompress_buffer_gzip(const char *in, size_t inlen, char *out, size_t outlen)
{
- int ret;
+ z_stream strm;
+ size_t ret = 0;
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+
+ ret = inflateInit2(&strm, (15+16));
+ if (ret != Z_OK)
+ return ret;
+
+ strm.avail_in = inlen;
+ strm.next_in = in;
+ strm.avail_out = outlen;
+ strm.next_out = out;
+
+ ret = inflate(&strm, Z_FINISH);
+ if (ret != Z_STREAM_END)
+ goto end;
- ret = uncompress((Bytef *) outbuf, (uLongf *) &outbuflen,
- (const Bytef *) inbuf, (uLong) inbuflen);
+ ret = strm.total_out;
- return (ret == Z_OK ? outbuflen : 0);
+end:
+ (void)inflateEnd(&strm);
+ return ret;
}
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 1dcb6a2c31c..1f118f2e476 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.92 2012/08/25 23:35:09 chl Exp $ */
+/* $OpenBSD: parse.y,v 1.93 2012/08/26 13:38:43 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -310,7 +310,7 @@ compress : COMPRESS STRING {
$$ = $2;
}
| COMPRESS {
- $$ = "zlib";
+ $$ = "gzip";
}
| /* empty */ { $$ = NULL; }
;
diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile
index 3f93e4fed93..618d2f8a06a 100644
--- a/usr.sbin/smtpd/smtpctl/Makefile
+++ b/usr.sbin/smtpd/smtpctl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.24 2012/08/25 23:35:09 chl Exp $
+# $OpenBSD: Makefile,v 1.25 2012/08/26 13:38:43 gilles Exp $
.PATH: ${.CURDIR}/..
@@ -19,7 +19,7 @@ CFLAGS+= -Wsign-compare -Wbounded
SRCS= enqueue.c parser.c log.c envelope.c
SRCS+= queue_backend.c queue_fsqueue.c
SRCS+= smtpctl.c util.c
-SRCS+= compress_backend.c compress_zlib.c encrypt.c
+SRCS+= compress_backend.c compress_gzip.c encrypt.c
LDADD+= -lutil -lz
DPADD+= ${LIBUTIL} ${LIBEVENT}
diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile
index 407aabc48f4..ee59922e226 100644
--- a/usr.sbin/smtpd/smtpd/Makefile
+++ b/usr.sbin/smtpd/smtpd/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.48 2012/08/25 23:35:09 chl Exp $
+# $OpenBSD: Makefile,v 1.49 2012/08/26 13:38:43 gilles Exp $
.PATH: ${.CURDIR}/.. ${.CURDIR}/../../../lib/libc/asr
@@ -16,7 +16,7 @@ SRCS= aliases.c auth.c bounce.c compress_backend.c config.c \
# backends
SRCS+= auth_bsd.c
SRCS+= auth_pwd.c
-SRCS+= compress_zlib.c
+SRCS+= compress_gzip.c
SRCS+= delivery_filename.c
SRCS+= delivery_maildir.c
SRCS+= delivery_mbox.c