X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=modules%2Fdeflate.c;h=f65273ca96713208a5b5f0fd37de2600faa8678c;hp=67c6c16b71ea35dd6cc918693f2f3ab95237b59d;hb=a25ab4af5d8ea4f1760b5db5f5ee5b65bbfcd53b;hpb=1e1a4695859cbe84201bb8da80bc8b59b5b4a1df diff --git a/modules/deflate.c b/modules/deflate.c index 67c6c16..f65273c 100644 --- a/modules/deflate.c +++ b/modules/deflate.c @@ -27,7 +27,7 @@ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, * OR MODIFICATIONS. * - * $Id: deflate.c,v 1.6 1997/11/27 06:05:17 paulus Exp $ + * $Id: deflate.c,v 1.8 1998/03/24 23:52:31 paulus Exp $ */ #ifdef AIX4 @@ -45,7 +45,7 @@ #ifdef __osf__ #include "zlib.h" #else -#include "common/zlib.h" +#include "../common/zlib.h" #endif #if DO_DEFLATE @@ -89,7 +89,7 @@ static void z_decomp_reset __P((void *state)); static void z_comp_stats __P((void *state, struct compstat *stats)); /* - * Procedures exported to if_ppp.c. + * Procedures exported to ppp_comp.c. */ struct compressor ppp_deflate = { CI_DEFLATE, /* compress_proto */ @@ -108,6 +108,23 @@ struct compressor ppp_deflate = { z_comp_stats, /* decomp_stat */ }; +struct compressor ppp_deflate_draft = { + CI_DEFLATE_DRAFT, /* compress_proto */ + z_comp_alloc, /* comp_alloc */ + z_comp_free, /* comp_free */ + z_comp_init, /* comp_init */ + z_comp_reset, /* comp_reset */ + z_compress, /* compress */ + z_comp_stats, /* comp_stat */ + 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 */ +}; + #define DECOMP_CHUNK 512 /* @@ -178,7 +195,8 @@ z_comp_alloc(options, opt_len) struct deflate_state *state; int w_size; - if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len != CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || options[3] != DEFLATE_CHK_SEQUENCE) @@ -230,7 +248,8 @@ z_comp_init(arg, options, opt_len, unit, hdrlen, debug) { struct deflate_state *state = (struct deflate_state *) arg; - if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len < CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || DEFLATE_SIZE(options[2]) != state->w_size @@ -286,8 +305,15 @@ z_compress(arg, mret, mp, orig_len, maxolen) /* Allocate one mblk initially. */ if (maxolen > orig_len) maxolen = orig_len; - wspace = maxolen < 4096? maxolen: 4096; - m = allocb(wspace, BPRI_MED); + if (maxolen <= PPP_HDRLEN + 2) { + wspace = 0; + m = NULL; + } else { + wspace = maxolen + state->hdrlen; + if (wspace > 4096) + wspace = 4096; + m = allocb(wspace, BPRI_MED); + } if (m != NULL) { *mret = m; if (state->hdrlen + PPP_HDRLEN + 2 < wspace) { @@ -343,11 +369,16 @@ z_compress(arg, mret, mp, orig_len, maxolen) m->b_wptr += wspace; olen += wspace; wspace = maxolen - olen; - if (wspace < 32) - wspace = 32; - else if (wspace > 4096) - wspace = 4096; - m->b_cont = allocb(wspace, BPRI_MED); + if (wspace <= 0) { + wspace = 0; + m->b_cont = NULL; + } else { + if (wspace < 32) + wspace = 32; + else if (wspace > 4096) + wspace = 4096; + m->b_cont = allocb(wspace, BPRI_MED); + } m = m->b_cont; if (m != NULL) { state->strm.next_out = m->b_wptr; @@ -360,8 +391,10 @@ z_compress(arg, mret, mp, orig_len, maxolen) } } } - m->b_wptr += wspace - state->strm.avail_out; - olen += wspace - state->strm.avail_out; + if (m != NULL) { + m->b_wptr += wspace - state->strm.avail_out; + olen += wspace - state->strm.avail_out; + } /* * See if we managed to reduce the size of the packet. @@ -414,7 +447,8 @@ z_decomp_alloc(options, opt_len) struct deflate_state *state; int w_size; - if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len != CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || options[3] != DEFLATE_CHK_SEQUENCE) @@ -463,7 +497,8 @@ z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug) { struct deflate_state *state = (struct deflate_state *) arg; - if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len < CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || DEFLATE_SIZE(options[2]) != state->w_size