/*****************************************************************************/
/*
                                  gzip.h

*/
/*****************************************************************************/

#ifndef GZIP_COMPRESS_DEFINED
#define GZIP_COMPRESS_DEFINED

/******************************/
/* define WASD GZIP structure */
/******************************/

/* this structure is especially included by WASD.H and PROXYSTRUCT.H */

#define BOOL int

typedef struct GzipCompressStruct GZIP_COMPRESS;

struct GzipCompressStruct
{
   BOOL  DeflateEndOfStream,
         DeflateFlushStream,
         DeflateStartStream,
         InflateEndOfStream,
         InflateStartStream;

   int  DeflateBufferCount,
        DeflateBufferSize,
        DeflateBytesIn,
        DeflateBytesOut,
        DeflateMemoryAllocated,
        FlushBytesOut,
        FlushTickSeconds,
        InflateAvailIn,
        InflateBufferCount,
        InflateBufferSize,
        InflateBytesIn,
        InflateBytesOut,
        InflateMemoryAllocated;

   char  *DeflateBufferPtr,
         *InflateBufferPtr;
         
   void  *DeflateZstreamPtr,
         *InflateZstreamPtr;
};
           

/***********************************/
/* WASD GZIP structure now defined */
/***********************************/

#endif /* GZIP_COMPRESS_DEFINED */

#ifndef GZIP_COMPRESS_ONLY

#ifndef GZIP_H_LOADED
#define GZIP_H_LOADED 1

/* number of bytes in the GZIP stream header */
#define GZIP_SIZE_OF_HEADER 10

/* minimum size in bytes before worrying about deflating */
#define GZIP_MIN_CONTENT_LENGTH 1400

/* maximum interval between GZIP buffer flushes (actual output) */
#define GZIP_DEFAULT_FLUSH_SECONDS 15

/* interval before initial GZIP buffer flush (get some output out there!) */
#define GZIP_INITIAL_FLUSH_SECONDS 3

/*********************/
/* ZLIB requirements */
/*********************/

/**
  Sufficient of ZLIB to build an interface to the shareable image.
  These (needless-to-say) have been (more-or-less) lifted from ZLIB.H
  version 1.2.1, November 17th, 2003
  Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler
**/

typedef struct z_stream_s 
{
    char           *next_in;   /* next input byte */
    unsigned int   avail_in;   /* number of bytes available at next_in */
    unsigned long  total_in;   /* total nb of input bytes read so far */

    char           *next_out;  /* next output byte should be put there */
    unsigned int   avail_out;  /* remaining free space at next_out */
    unsigned long  total_out;  /* total nb of bytes output so far */

    char           *msg;       /* last error message, NULL if no error */
    void           *state;     /* not visible by applications */

    void           *zalloc;    /* used to allocate the internal state */
    void           *zfree;     /* used to free the internal state */
    void           *opaque;    /* private data passed to zalloc and zfree */

    int            data_type;  /* best guess on data type: ascii or binary */
    unsigned long  adler;      /* adler32 value of the uncompressed data */
    unsigned long  reserved;   /* reserved for future use */
} z_stream;

#define ZLIB_VERSION "1.2.1"

#define Z_DEFAULT_COMPRESSION (-1)
#define Z_DEFAULT_STRATEGY 0
#define Z_DEFLATED 8

#define Z_NO_FLUSH 0
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4

#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_VERSION_ERROR (-6)

/***********************/
/* function prototypes */
/***********************/

int GzipInit ();
int GzipInitHandler ();

BOOL GzipDeflate (REQUEST_STRUCT*, GZIP_COMPRESS*, char**, int*, char**, int*);
BOOL GzipDeflateBegin (REQUEST_STRUCT*, GZIP_COMPRESS*, int);
BOOL GzipDeflateCache (REQUEST_STRUCT*, FILE_CENTRY*);
BOOL GzipDeflateEnd (REQUEST_STRUCT*, GZIP_COMPRESS*);
BOOL GzipShouldDeflate (REQUEST_STRUCT*, char*, int);
BOOL GzipInflate (REQUEST_STRUCT*, GZIP_COMPRESS*, char**, int*);
BOOL GzipInflateBegin (REQUEST_STRUCT*, GZIP_COMPRESS*, int);
BOOL GzipInflateEnd (REQUEST_STRUCT*, GZIP_COMPRESS*);

char* GzipZlibMsg (z_stream*, int);
char* GzipAlloc (REQUEST_STRUCT*, int, int);
GzipFree (REQUEST_STRUCT*, char*);

#endif /* GZIP_H_LOADED */

#endif /* GZIP_COMPRESS_ONLY */

/*****************************************************************************/

