1 /* $OpenBSD: compress_backend.c,v 1.9 2015/01/20 17:37:54 deraadt Exp $ */
2
3 /*
4 * Copyright (c) 2012 Charles Longeau <chl@openbsd.org>
5 * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include "includes.h"
21
22 #include <sys/types.h>
23 #include <sys/queue.h>
24 #include <sys/tree.h>
25 #include <sys/socket.h>
26 #include <sys/stat.h>
27
28 #include <imsg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <limits.h>
34
35 #include "smtpd.h"
36
37 #define BUFFER_SIZE 16364
38
39 extern struct compress_backend compress_gzip;
40
41 struct compress_backend *
compress_backend_lookup(const char * name)42 compress_backend_lookup(const char *name)
43 {
44 if (!strcmp(name, "gzip"))
45 return &compress_gzip;
46
47 return NULL;
48 }
49
50 size_t
compress_chunk(void * ib,size_t ibsz,void * ob,size_t obsz)51 compress_chunk(void *ib, size_t ibsz, void *ob, size_t obsz)
52 {
53 return (env->sc_comp->compress_chunk(ib, ibsz, ob, obsz));
54 }
55
56 size_t
uncompress_chunk(void * ib,size_t ibsz,void * ob,size_t obsz)57 uncompress_chunk(void *ib, size_t ibsz, void *ob, size_t obsz)
58 {
59 return (env->sc_comp->uncompress_chunk(ib, ibsz, ob, obsz));
60 }
61
62 int
compress_file(FILE * ifile,FILE * ofile)63 compress_file(FILE *ifile, FILE *ofile)
64 {
65 return (env->sc_comp->compress_file(ifile, ofile));
66 }
67
68 int
uncompress_file(FILE * ifile,FILE * ofile)69 uncompress_file(FILE *ifile, FILE *ofile)
70 {
71 return (env->sc_comp->uncompress_file(ifile, ofile));
72 }
73