4 #include <openssl/objects.h>
5 #include <openssl/comp.h>
7 COMP_METHOD *COMP_zlib(void );
11 static COMP_METHOD zlib_method={
25 static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
26 unsigned int olen, unsigned char *in, unsigned int ilen);
27 static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
30 static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
33 static COMP_METHOD zlib_method={
43 static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen)
54 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
66 memcpy(&(out[1]),in,ilen);
69 fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib");
73 static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
74 unsigned int olen, unsigned char *in, unsigned int ilen)
82 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
88 memcpy(out,&(in[1]),ilen-1);
91 fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear");
95 static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
101 stream.next_in = (Bytef*)source;
102 stream.avail_in = (uInt)sourceLen;
103 /* Check for source > 64K on 16-bit machine: */
104 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
106 stream.next_out = dest;
107 stream.avail_out = (uInt)*destLen;
108 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
110 stream.zalloc = (alloc_func)0;
111 stream.zfree = (free_func)0;
113 err = inflateInit(&stream);
114 if (err != Z_OK) return err;
116 err = inflate(&stream, Z_FINISH);
117 if (err != Z_STREAM_END) {
121 *destLen = stream.total_out;
123 err = inflateEnd(&stream);
129 COMP_METHOD *COMP_zlib(void)
131 return(&zlib_method);