~ubuntu-branches/ubuntu/lucid/openssl/lucid-security

« back to all changes in this revision

Viewing changes to crypto/comp/c_zlib.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2006-05-15 16:00:58 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20060515160058-pg6lnbkkpkwpdj2e
Tags: upstream-0.9.8b
ImportĀ upstreamĀ versionĀ 0.9.8b

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 * When OpenSSL is built on Windows, we do not want to require that
68
68
 * the ZLIB.DLL be available in order for the OpenSSL DLLs to
69
69
 * work.  Therefore, all ZLIB routines are loaded at run time
70
 
 * and we do not link to a .LIB file.
 
70
 * and we do not link to a .LIB file when ZLIB_SHARED is set.
71
71
 */
72
72
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
73
73
# include <windows.h>
74
 
 
75
 
# define Z_CALLCONV _stdcall
76
 
# ifndef ZLIB_SHARED
77
 
#  define ZLIB_SHARED
78
 
# endif
79
 
#else
80
 
# define Z_CALLCONV
81
74
#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
82
75
 
83
76
#ifdef ZLIB_SHARED
84
77
#include <openssl/dso.h>
85
78
 
86
 
/* Prototypes for built in stubs */
87
 
#if 0
88
 
static int stub_compress(Bytef *dest,uLongf *destLen,
89
 
        const Bytef *source, uLong sourceLen);
90
 
#endif
91
 
static int stub_inflateEnd(z_streamp strm);
92
 
static int stub_inflate(z_streamp strm, int flush);
93
 
static int stub_inflateInit_(z_streamp strm, const char * version,
94
 
        int stream_size);
95
 
static int stub_deflateEnd(z_streamp strm);
96
 
static int stub_deflate(z_streamp strm, int flush);
97
 
static int stub_deflateInit_(z_streamp strm, int level,
98
 
        const char * version, int stream_size);
99
 
 
100
79
/* Function pointers */
101
 
typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
 
80
typedef int (*compress_ft)(Bytef *dest,uLongf *destLen,
102
81
        const Bytef *source, uLong sourceLen);
103
 
typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
104
 
typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
105
 
typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
 
82
typedef int (*inflateEnd_ft)(z_streamp strm);
 
83
typedef int (*inflate_ft)(z_streamp strm, int flush);
 
84
typedef int (*inflateInit__ft)(z_streamp strm,
106
85
        const char * version, int stream_size);
107
 
typedef int (Z_CALLCONV *deflateEnd_ft)(z_streamp strm);
108
 
typedef int (Z_CALLCONV *deflate_ft)(z_streamp strm, int flush);
109
 
typedef int (Z_CALLCONV *deflateInit__ft)(z_streamp strm, int level,
 
86
typedef int (*deflateEnd_ft)(z_streamp strm);
 
87
typedef int (*deflate_ft)(z_streamp strm, int flush);
 
88
typedef int (*deflateInit__ft)(z_streamp strm, int level,
110
89
        const char * version, int stream_size);
111
90
static compress_ft      p_compress=NULL;
112
91
static inflateEnd_ft    p_inflateEnd=NULL;
119
98
static int zlib_loaded = 0;     /* only attempt to init func pts once */
120
99
static DSO *zlib_dso = NULL;
121
100
 
122
 
#define compress                stub_compress
123
 
#define inflateEnd              stub_inflateEnd
124
 
#define inflate                 stub_inflate
125
 
#define inflateInit_            stub_inflateInit_
126
 
#define deflateEnd              stub_deflateEnd
127
 
#define deflate                 stub_deflate
128
 
#define deflateInit_            stub_deflateInit_
 
101
#define compress                p_compress
 
102
#define inflateEnd              p_inflateEnd
 
103
#define inflate                 p_inflate
 
104
#define inflateInit_            p_inflateInit_
 
105
#define deflateEnd              p_deflateEnd
 
106
#define deflate                 p_deflate
 
107
#define deflateInit_            p_deflateInit_
129
108
#endif /* ZLIB_SHARED */
130
109
 
131
110
struct zlib_state
361
340
                {
362
341
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
363
342
                zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
364
 
                if (!zlib_dso)
365
 
                        {
366
 
                        zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
367
 
                        if (zlib_dso)
368
 
                                {
369
 
                                /* Clear the errors from the first failed
370
 
                                   DSO_load() */
371
 
                                ERR_clear_error();
372
 
                                }
373
 
                        }
374
343
#else
375
344
                zlib_dso = DSO_load(NULL, "z", NULL, 0);
376
345
#endif
397
366
                        p_deflateInit_
398
367
                                = (deflateInit__ft) DSO_bind_func(zlib_dso,
399
368
                                        "deflateInit_");
400
 
                        zlib_loaded++;
 
369
 
 
370
                        if (p_compress && p_inflateEnd && p_inflate
 
371
                                && p_inflateInit_ && p_deflateEnd
 
372
                                && p_deflate && p_deflateInit_)
 
373
                                zlib_loaded++;
401
374
                        }
402
375
                }
403
376
 
404
377
#endif
 
378
#ifdef ZLIB_SHARED
 
379
        if (zlib_loaded)
 
380
#endif
405
381
#if defined(ZLIB) || defined(ZLIB_SHARED)
406
 
        meth = &zlib_stateful_method;
 
382
                meth = &zlib_stateful_method;
407
383
#endif
408
384
 
409
385
        return(meth);
410
386
        }
411
387
 
412
 
#ifdef ZLIB_SHARED
413
 
#if 0
414
 
/* Stubs for each function to be dynamicly loaded */
415
 
static int 
416
 
stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
417
 
        {
418
 
        if (p_compress)
419
 
                return(p_compress(dest,destLen,source,sourceLen));
420
 
        else
421
 
                return(Z_MEM_ERROR);
422
 
        }
423
 
#endif
424
 
 
425
 
static int
426
 
stub_inflateEnd(z_streamp strm)
427
 
        {
428
 
        if ( p_inflateEnd )
429
 
                return(p_inflateEnd(strm));
430
 
        else
431
 
                return(Z_MEM_ERROR);
432
 
        }
433
 
 
434
 
static int
435
 
stub_inflate(z_streamp strm, int flush)
436
 
        {
437
 
        if ( p_inflate )
438
 
                return(p_inflate(strm,flush));
439
 
        else
440
 
                return(Z_MEM_ERROR);
441
 
        }
442
 
 
443
 
static int
444
 
stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
445
 
        {
446
 
        if ( p_inflateInit_ )
447
 
                return(p_inflateInit_(strm,version,stream_size));
448
 
        else
449
 
                return(Z_MEM_ERROR);
450
 
        }
451
 
 
452
 
static int
453
 
stub_deflateEnd(z_streamp strm)
454
 
        {
455
 
        if ( p_deflateEnd )
456
 
                return(p_deflateEnd(strm));
457
 
        else
458
 
                return(Z_MEM_ERROR);
459
 
        }
460
 
 
461
 
static int
462
 
stub_deflate(z_streamp strm, int flush)
463
 
        {
464
 
        if ( p_deflate )
465
 
                return(p_deflate(strm,flush));
466
 
        else
467
 
                return(Z_MEM_ERROR);
468
 
        }
469
 
 
470
 
static int
471
 
stub_deflateInit_(z_streamp strm, int level,
472
 
        const char * version, int stream_size)
473
 
        {
474
 
        if ( p_deflateInit_ )
475
 
                return(p_deflateInit_(strm,level,version,stream_size));
476
 
        else
477
 
                return(Z_MEM_ERROR);
478
 
        }
479
 
 
480
 
#endif /* ZLIB_SHARED */