summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/comp/c_zlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/comp/c_zlib.c')
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c88
1 files changed, 72 insertions, 16 deletions
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index 5fcb521ffb..1bd2850d15 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -51,17 +51,30 @@ static COMP_METHOD zlib_method={
51 */ 51 */
52#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) 52#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
53# include <windows.h> 53# include <windows.h>
54
55# define Z_CALLCONV _stdcall
56# define ZLIB_SHARED
57#else
58# define Z_CALLCONV
54#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */ 59#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
55 60
56#ifdef ZLIB_SHARED 61#ifdef ZLIB_SHARED
57#include <openssl/dso.h> 62#include <openssl/dso.h>
58 63
64/* Prototypes for built in stubs */
65static int stub_compress(Bytef *dest,uLongf *destLen,
66 const Bytef *source, uLong sourceLen);
67static int stub_inflateEnd(z_streamp strm);
68static int stub_inflate(z_streamp strm, int flush);
69static int stub_inflateInit_(z_streamp strm, const char * version,
70 int stream_size);
71
59/* Function pointers */ 72/* Function pointers */
60typedef int (*compress_ft)(Bytef *dest,uLongf *destLen, 73typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
61 const Bytef *source, uLong sourceLen); 74 const Bytef *source, uLong sourceLen);
62typedef int (*inflateEnd_ft)(z_streamp strm); 75typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
63typedef int (*inflate_ft)(z_streamp strm, int flush); 76typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
64typedef int (*inflateInit__ft)(z_streamp strm, 77typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
65 const char * version, int stream_size); 78 const char * version, int stream_size);
66static compress_ft p_compress=NULL; 79static compress_ft p_compress=NULL;
67static inflateEnd_ft p_inflateEnd=NULL; 80static inflateEnd_ft p_inflateEnd=NULL;
@@ -71,10 +84,10 @@ static inflateInit__ft p_inflateInit_=NULL;
71static int zlib_loaded = 0; /* only attempt to init func pts once */ 84static int zlib_loaded = 0; /* only attempt to init func pts once */
72static DSO *zlib_dso = NULL; 85static DSO *zlib_dso = NULL;
73 86
74#define compress p_compress 87#define compress stub_compress
75#define inflateEnd p_inflateEnd 88#define inflateEnd stub_inflateEnd
76#define inflate p_inflate 89#define inflate stub_inflate
77#define inflateInit_ p_inflateInit_ 90#define inflateInit_ stub_inflateInit_
78#endif /* ZLIB_SHARED */ 91#endif /* ZLIB_SHARED */
79 92
80static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 93static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
@@ -178,6 +191,16 @@ COMP_METHOD *COMP_zlib(void)
178 { 191 {
179#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) 192#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
180 zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0); 193 zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
194 if (!zlib_dso)
195 {
196 zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
197 if (zlib_dso)
198 {
199 /* Clear the errors from the first failed
200 DSO_load() */
201 ERR_clear_error();
202 }
203 }
181#else 204#else
182 zlib_dso = DSO_load(NULL, "z", NULL, 0); 205 zlib_dso = DSO_load(NULL, "z", NULL, 0);
183#endif 206#endif
@@ -195,21 +218,54 @@ COMP_METHOD *COMP_zlib(void)
195 p_inflateInit_ 218 p_inflateInit_
196 = (inflateInit__ft) DSO_bind_func(zlib_dso, 219 = (inflateInit__ft) DSO_bind_func(zlib_dso,
197 "inflateInit_"); 220 "inflateInit_");
198 221 zlib_loaded++;
199 if (p_compress && p_inflateEnd && p_inflate
200 && p_inflateInit_)
201 zlib_loaded++;
202 } 222 }
203 } 223 }
204 224
205#endif 225#endif
206#ifdef ZLIB_SHARED
207 if (zlib_loaded)
208#endif
209#if defined(ZLIB) || defined(ZLIB_SHARED) 226#if defined(ZLIB) || defined(ZLIB_SHARED)
210 meth = &zlib_method; 227 meth = &zlib_method;
211#endif 228#endif
212 229
213 return(meth); 230 return(meth);
214 } 231 }
215 232
233#ifdef ZLIB_SHARED
234/* Stubs for each function to be dynamicly loaded */
235static int
236stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
237 {
238 if (p_compress)
239 return(p_compress(dest,destLen,source,sourceLen));
240 else
241 return(Z_MEM_ERROR);
242 }
243
244static int
245stub_inflateEnd(z_streamp strm)
246 {
247 if ( p_inflateEnd )
248 return(p_inflateEnd(strm));
249 else
250 return(Z_MEM_ERROR);
251 }
252
253static int
254stub_inflate(z_streamp strm, int flush)
255 {
256 if ( p_inflate )
257 return(p_inflate(strm,flush));
258 else
259 return(Z_MEM_ERROR);
260 }
261
262static int
263stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
264 {
265 if ( p_inflateInit_ )
266 return(p_inflateInit_(strm,version,stream_size));
267 else
268 return(Z_MEM_ERROR);
269 }
270
271#endif /* ZLIB_SHARED */