- unsigned int olen, unsigned char *in, unsigned int ilen)
- {
- int err = Z_OK;
-
- struct zlib_state *state =
- (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
- zlib_stateful_ex_idx);
-
- if (state == NULL)
- return 0;
-
- state->istream.next_in = in;
- state->istream.avail_in = ilen;
- state->istream.next_out = out;
- state->istream.avail_out = olen;
- if (ilen > 0)
- err = inflate(&state->istream, Z_SYNC_FLUSH);
- if (err != Z_OK)
- return -1;
-#ifdef DEBUG_ZLIB
- fprintf(stderr,"expand(%4d)->%4d %s\n",
- ilen,olen - state->istream.avail_out,
- (ilen != olen - state->istream.avail_out)?"zlib":"clear");
-#endif
- return olen - state->istream.avail_out;
- }
-
-#if 0
-static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in, unsigned int ilen)
- {
- unsigned long l;
- int i;
- int clear=1;
-
- if (ilen > 128)
- {
- out[0]=1;
- l=olen-1;
- i=compress(&(out[1]),&l,in,(unsigned long)ilen);
- if (i != Z_OK)
- return(-1);
- if (ilen > l)
- {
- clear=0;
- l++;
- }
- }
- if (clear)
- {
- out[0]=0;
- memcpy(&(out[1]),in,ilen);
- l=ilen+1;
- }
-#ifdef DEBUG_ZLIB
- fprintf(stderr,"compress(%4d)->%4d %s\n",
- ilen,(int)l,(clear)?"clear":"zlib");
-#endif
- return((int)l);
- }
-
-static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
- unsigned int olen, unsigned char *in, unsigned int ilen)
- {
- unsigned long l;
- int i;
-
- if (in[0])
- {
- l=olen;
- i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
- if (i != Z_OK)
- return(-1);
- }
- else
- {
- memcpy(out,&(in[1]),ilen-1);
- l=ilen-1;
- }
-#ifdef DEBUG_ZLIB
- fprintf(stderr,"expand (%4d)->%4d %s\n",
- ilen,(int)l,in[0]?"zlib":"clear");
-#endif
- return((int)l);
- }
-
-static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
- uLong sourceLen)