diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/comp/c_zlib.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/comp/c_zlib.c')
-rw-r--r-- | src/lib/libcrypto/comp/c_zlib.c | 141 |
1 files changed, 134 insertions, 7 deletions
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c index 6684ab4841..cd2f8a491b 100644 --- a/src/lib/libcrypto/comp/c_zlib.c +++ b/src/lib/libcrypto/comp/c_zlib.c | |||
@@ -6,11 +6,10 @@ | |||
6 | 6 | ||
7 | COMP_METHOD *COMP_zlib(void ); | 7 | COMP_METHOD *COMP_zlib(void ); |
8 | 8 | ||
9 | #ifndef ZLIB | 9 | static COMP_METHOD zlib_method_nozlib={ |
10 | |||
11 | static COMP_METHOD zlib_method={ | ||
12 | NID_undef, | 10 | NID_undef, |
13 | "(null)", | 11 | "(undef)", |
12 | NULL, | ||
14 | NULL, | 13 | NULL, |
15 | NULL, | 14 | NULL, |
16 | NULL, | 15 | NULL, |
@@ -18,6 +17,8 @@ static COMP_METHOD zlib_method={ | |||
18 | NULL, | 17 | NULL, |
19 | }; | 18 | }; |
20 | 19 | ||
20 | #ifndef ZLIB | ||
21 | #undef ZLIB_SHARED | ||
21 | #else | 22 | #else |
22 | 23 | ||
23 | #include <zlib.h> | 24 | #include <zlib.h> |
@@ -38,8 +39,56 @@ static COMP_METHOD zlib_method={ | |||
38 | zlib_compress_block, | 39 | zlib_compress_block, |
39 | zlib_expand_block, | 40 | zlib_expand_block, |
40 | NULL, | 41 | NULL, |
42 | NULL, | ||
41 | }; | 43 | }; |
42 | 44 | ||
45 | /* | ||
46 | * When OpenSSL is built on Windows, we do not want to require that | ||
47 | * the ZLIB.DLL be available in order for the OpenSSL DLLs to | ||
48 | * work. Therefore, all ZLIB routines are loaded at run time | ||
49 | * and we do not link to a .LIB file. | ||
50 | */ | ||
51 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) | ||
52 | # include <windows.h> | ||
53 | |||
54 | # define Z_CALLCONV _stdcall | ||
55 | # define ZLIB_SHARED | ||
56 | #else | ||
57 | # define Z_CALLCONV | ||
58 | #endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */ | ||
59 | |||
60 | #ifdef ZLIB_SHARED | ||
61 | #include <openssl/dso.h> | ||
62 | |||
63 | /* Prototypes for built in stubs */ | ||
64 | static int stub_compress(Bytef *dest,uLongf *destLen, | ||
65 | const Bytef *source, uLong sourceLen); | ||
66 | static int stub_inflateEnd(z_streamp strm); | ||
67 | static int stub_inflate(z_streamp strm, int flush); | ||
68 | static int stub_inflateInit_(z_streamp strm, const char * version, | ||
69 | int stream_size); | ||
70 | |||
71 | /* Function pointers */ | ||
72 | typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen, | ||
73 | const Bytef *source, uLong sourceLen); | ||
74 | typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm); | ||
75 | typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush); | ||
76 | typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm, | ||
77 | const char * version, int stream_size); | ||
78 | static compress_ft p_compress=NULL; | ||
79 | static inflateEnd_ft p_inflateEnd=NULL; | ||
80 | static inflate_ft p_inflate=NULL; | ||
81 | static inflateInit__ft p_inflateInit_=NULL; | ||
82 | |||
83 | static int zlib_loaded = 0; /* only attempt to init func pts once */ | ||
84 | static DSO *zlib_dso = NULL; | ||
85 | |||
86 | #define compress stub_compress | ||
87 | #define inflateEnd stub_inflateEnd | ||
88 | #define inflate stub_inflate | ||
89 | #define inflateInit_ stub_inflateInit_ | ||
90 | #endif /* ZLIB_SHARED */ | ||
91 | |||
43 | static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, | 92 | static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, |
44 | unsigned int olen, unsigned char *in, unsigned int ilen) | 93 | unsigned int olen, unsigned char *in, unsigned int ilen) |
45 | { | 94 | { |
@@ -66,7 +115,10 @@ static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, | |||
66 | memcpy(&(out[1]),in,ilen); | 115 | memcpy(&(out[1]),in,ilen); |
67 | l=ilen+1; | 116 | l=ilen+1; |
68 | } | 117 | } |
69 | fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib"); | 118 | #ifdef DEBUG_ZLIB |
119 | fprintf(stderr,"compress(%4d)->%4d %s\n", | ||
120 | ilen,(int)l,(clear)?"clear":"zlib"); | ||
121 | #endif | ||
70 | return((int)l); | 122 | return((int)l); |
71 | } | 123 | } |
72 | 124 | ||
@@ -88,7 +140,10 @@ static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, | |||
88 | memcpy(out,&(in[1]),ilen-1); | 140 | memcpy(out,&(in[1]),ilen-1); |
89 | l=ilen-1; | 141 | l=ilen-1; |
90 | } | 142 | } |
91 | fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear"); | 143 | #ifdef DEBUG_ZLIB |
144 | fprintf(stderr,"expand (%4d)->%4d %s\n", | ||
145 | ilen,(int)l,in[0]?"zlib":"clear"); | ||
146 | #endif | ||
92 | return((int)l); | 147 | return((int)l); |
93 | } | 148 | } |
94 | 149 | ||
@@ -128,6 +183,78 @@ static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, | |||
128 | 183 | ||
129 | COMP_METHOD *COMP_zlib(void) | 184 | COMP_METHOD *COMP_zlib(void) |
130 | { | 185 | { |
131 | return(&zlib_method); | 186 | COMP_METHOD *meth = &zlib_method_nozlib; |
187 | |||
188 | #ifdef ZLIB_SHARED | ||
189 | if (!zlib_loaded) | ||
190 | { | ||
191 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) | ||
192 | zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0); | ||
193 | #else | ||
194 | zlib_dso = DSO_load(NULL, "z", NULL, 0); | ||
195 | #endif | ||
196 | if (zlib_dso != NULL) | ||
197 | { | ||
198 | p_compress | ||
199 | = (compress_ft) DSO_bind_func(zlib_dso, | ||
200 | "compress"); | ||
201 | p_inflateEnd | ||
202 | = (inflateEnd_ft) DSO_bind_func(zlib_dso, | ||
203 | "inflateEnd"); | ||
204 | p_inflate | ||
205 | = (inflate_ft) DSO_bind_func(zlib_dso, | ||
206 | "inflate"); | ||
207 | p_inflateInit_ | ||
208 | = (inflateInit__ft) DSO_bind_func(zlib_dso, | ||
209 | "inflateInit_"); | ||
210 | zlib_loaded++; | ||
211 | meth = &zlib_method; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | #elif defined(ZLIB) | ||
216 | meth = &zlib_method; | ||
217 | #endif | ||
218 | |||
219 | return(meth); | ||
220 | } | ||
221 | |||
222 | #ifdef ZLIB_SHARED | ||
223 | /* Stubs for each function to be dynamicly loaded */ | ||
224 | static int | ||
225 | stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen) | ||
226 | { | ||
227 | if (p_compress) | ||
228 | return(p_compress(dest,destLen,source,sourceLen)); | ||
229 | else | ||
230 | return(Z_MEM_ERROR); | ||
231 | } | ||
232 | |||
233 | static int | ||
234 | stub_inflateEnd(z_streamp strm) | ||
235 | { | ||
236 | if ( p_inflateEnd ) | ||
237 | return(p_inflateEnd(strm)); | ||
238 | else | ||
239 | return(Z_MEM_ERROR); | ||
240 | } | ||
241 | |||
242 | static int | ||
243 | stub_inflate(z_streamp strm, int flush) | ||
244 | { | ||
245 | if ( p_inflate ) | ||
246 | return(p_inflate(strm,flush)); | ||
247 | else | ||
248 | return(Z_MEM_ERROR); | ||
249 | } | ||
250 | |||
251 | static int | ||
252 | stub_inflateInit_(z_streamp strm, const char * version, int stream_size) | ||
253 | { | ||
254 | if ( p_inflateInit_ ) | ||
255 | return(p_inflateInit_(strm,version,stream_size)); | ||
256 | else | ||
257 | return(Z_MEM_ERROR); | ||
132 | } | 258 | } |
133 | 259 | ||
260 | #endif /* ZLIB_SHARED */ | ||