/*
* ppp_deflate.c - interface the zlib procedures for Deflate compression
* and decompression (as used by gzip) to the PPP code.
*
* Copyright (c) 1994 The Australian National University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies. This software is provided without any
* warranty, express or implied. The Australian National University
* makes no representations about the suitability of this software for
* any purpose.
*
* IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
* PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
* THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
* OR MODIFICATIONS.
*
* $Id: deflate.c,v 1.3 1999/04/16 11:35:59 paulus Exp $
*/
#include <stddef.h>
#include <stdlib.h>
#ifdef PPP_DEFS_IN_NET
#include <net/ppp_defs.h>
#else
#include "ppp_defs.h"
#endif
#include "ppp-comp.h"
#include "zlib.h"
#if DO_DEFLATE
/*
* State for a Deflate (de)compressor.
*/
struct deflate_state {
int seqno;
int w_size;
int unit;
int hdrlen;
int mru;
int debug;
};
/*
* Procedures exported to if_ppp.c.
*/
CI_DEFLATE, /* compress_proto */
z_decomp_alloc, /* decomp_alloc */
z_decomp_free, /* decomp_free */
z_decomp_init, /* decomp_init */
z_decomp_reset, /* decomp_reset */
z_decompress, /* decompress */
z_incomp, /* incomp */
z_comp_stats, /* decomp_stat */
};
/*
* Space allocation and freeing routines for use by zlib routines.
*/
static void *
void *notused;
{
}
static void
void *notused;
void *ptr;
{
}
static void
void *arg;
{
else
out >>= 8;
if (out != 0)
}
/*
* Allocate space for a decompressor.
*/
static void *
int opt_len;
{
int w_size;
return NULL;
return NULL;
return NULL;
return NULL;
}
return (void *) state;
}
static void
void *arg;
{
}
static int
void *arg;
{
return 0;
return 1;
}
static void
void *arg;
{
}
/*
* Decompress a Deflate-compressed packet.
*
* Because of patent problems, we return DECOMP_ERROR for errors
* found by inspecting the input data and for system problems, but
* DECOMP_FATALERROR for any errors which could possibly be said to
* be being detected "after" decompression. For DECOMP_ERROR,
* we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
* infringing a patent of Motorola's if we do, so we take CCP down
* instead.
*
* Given that the frame has the correct sequence number and a good FCS,
* errors such as invalid codes in the input most likely indicate a
* bug, so we return DECOMP_FATALERROR for them in order to turn off
* compression, even though they are detected by inspecting the input.
*/
static int
void *arg;
{
if (*rptr == 0)
++rptr;
++rptr;
/* Check the sequence number. */
rptr += 2;
#if !DEFLATE_DEBUG
#endif
printf("z_decompress%d: bad seq # %d, expected %d\n",
return DECOMP_ERROR;
}
/*
* Set up to call inflate.
*/
if (r != Z_OK) {
#if !DEFLATE_DEBUG
#endif
printf("z_decompress%d: inflate returned %d (%s)\n",
return DECOMP_FATALERROR;
}
if ((wptr[0] & 1) != 0)
++olen; /* for suppressed protocol high byte */
#if DEFLATE_DEBUG
printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
#endif
return DECOMP_OK;
}
/*
* Incompressible data has arrived - add it to the history.
*/
static void
void *arg;
int mlen;
{
/*
* Check that the protocol is one we handle.
*/
if ((proto & 1) == 0)
return;
if (rptr[0] == 0)
++rptr;
if (r != Z_OK) {
/* gak! */
#if !DEFLATE_DEBUG
#endif
printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
return;
}
/*
* Update stats.
*/
if (proto <= 0xff)
++rlen;
rlen += 2;
}
#endif /* DO_DEFLATE */