Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Aug 2013 10:30:54 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r255876 - in soc2013/dpl: . head/lib/libzcap head/lib/libzcap/zlibworker
Message-ID:  <201308131030.r7DAUstj030195@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Tue Aug 13 10:30:53 2013
New Revision: 255876
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255876

Log:
  Writing the skeleton to start porting all the deflate related functions.
  

Deleted:
  soc2013/dpl/datapasstest.c
Modified:
  soc2013/dpl/head/lib/libzcap/adler32.c
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/crc32.c
  soc2013/dpl/head/lib/libzcap/deflate.c
  soc2013/dpl/head/lib/libzcap/gzguts.h
  soc2013/dpl/head/lib/libzcap/gzlib.c
  soc2013/dpl/head/lib/libzcap/gzread.c
  soc2013/dpl/head/lib/libzcap/gzwrite.c
  soc2013/dpl/head/lib/libzcap/zlibworker/comands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c

Modified: soc2013/dpl/head/lib/libzcap/adler32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/adler32.c	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/adler32.c	Tue Aug 13 10:30:53 2013	(r255876)
@@ -68,16 +68,18 @@
     const Bytef *buf;
     uInt len;
 {
-	/* Send packets of 100kb size at most. */
-	if ((sizeof(*buf)*len) > (5*1024)) {
- 		while( (len -= (5*1024)) > 0) {
- 			buf += (5*1024)/sizeof(*buf);
-			adler = zcapcmd_adler32(adler, buf, len);
-		}
-	} else {
-		adler = zcapcmd_adler32( adler, buf, len);
+#define MAX (5*1024)
+	int ret = 0;
+	/* We have to send the buffers value back and forth */
+	/* Send packets of 5kb size at most. */
+	while(len > MAX) {
+		ret += zcapcmd_adler32(file, buf, MAX);
+		buf += MAX;
+		len -= MAX;
 	}
-	return adler;
+	ret += zcapcmd_adler32(file, buf, len);
+
+	return ret;
 }
 
 /* ========================================================================= */

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Tue Aug 13 10:30:53 2013	(r255876)
@@ -41,11 +41,57 @@
 #include <string.h>
 
 
+/* Basic functions */
+int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits,
+                        int memLevel, int strategy, const char * version,
+                        int stream_size);
+int zcapcmd_deflate(z_streamp strm, int flush);
+int zcapcmd_deflateEnd(z_streamp strm);
+int zcapcmd_inflateInit(z_streamp strm);
+int zcapcmd_inflate(z_streamp strm, int flush);
+int zcapcmd_inflateEnd(z_streamp strm);
+
+/* Advanced functions */
+int zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
+                                 uInt  dictLength);
+int zcapcmd_deflateCopy(z_streamp dest, z_streamp source);
+int zcapcmd_deflateReset(z_streamp strm);
+int zcapcmd_deflateParams(z_streamp strm, int level, int strategy);
+int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy,
+                                        int nice_length, int max_chain);
+int zcapcmd_deflateBound(z_streamp strm, uLong sourceLen);
+int zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits);
+int zcapcmd_deflatePrime(z_streamp strm, int bits, int value);
+int zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head);
+
+int zcapcmd_inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
+                                 uInt dictLength);
+int zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary,
+                                 uInt dictLength);
+int zcapcmd_inflateSync(z_streamp strm);
+int zcapcmd_inflateCopy(z_streamp strm, z_streamp source);
+int zcapcmd_inflateReset(z_streamp strm);
+int zcapcmd_inflateReset2(z_streamp strm, int windowBits);
+int zcapcmd_inflatePrime(z_streamp strm, int bits, int value);
+int zcapcmd_inflateMark(z_streamp strm);
+int zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head);
+int zcapcmd_inflateBackInit(z_streamp strm, int windowBits,
+                            unsigned char *window);
+int zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc,
+                        out_func out, void *out_desc);
+int zcapcmd_inflateBackEnd(z_streamp strm);
+int zcapcmd_zlibCompileFlags(z_streamp strm);
+
+/* Utility functions */
 uLong zcapcmd_compressBound(uLong sourceLen);
 
+/* gzip file functions */
 gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode);
 int zcapcmd_gzbuffer(gzFile file, unsigned size);
 int zcapcmd_gzsetparams(gzFile file, int level, int strategy);
+int zcapcmd_gzread(gzFile file, voidp buf, unsigned len);
+int zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len);
+int zcapcmd_gzprintf(gzFile file, const char *format, ...);
 int zcapcmd_gzputs(gzFile file, const char *s);
 char *zcapcmd_gzgets(gzFile file, char *buf, int len);
 int zcapcmd_gzputc(gzFile file, int c);
@@ -55,6 +101,7 @@
 int zcapcmd_simplecommand(gzFile file, int command);
 char * zcapcmd_gzerror(gzFile file, int *errnum);
 
+/* checksum functions */
 uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len);
 uLong zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 );
 uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len);
@@ -62,8 +109,116 @@
 
 extern pid_t pid;
 extern nvlist_t *sendCommand(nvlist_t *);
+extern void * data;
+
 size_t gzFilesize = sizeof(struct gzFile_s);
+size_t zstreamsize = sizeof(z_stream);
+
+uLong
+zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits,
+                    int memLevel, int strategy, const char * version,
+                    int stream_size)
+{
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
+	zstream * dataplace;
+	
+	if (pid == 0)
+		startChild();
+
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+	nvlist_add_binary(args, "strm", *strm, zstreamsize);
+	nvlist_add_number(args, "level", level);
+	nvlist_add_number(args, "method", method);
+	nvlist_add_number(args, "windowBits", windowBits);
+	nvlist_add_number(args, "memLevel", memLevel);
+	nvlist_add_number(args, "strategy", strategy);
+	nvlist_add_string(args, "version", version);
+	nvlist_add_number(args, "stream_size", stream_size);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	ret = nvlist_take_number(result, "result");
+	/* We take the "good" struct from the worker.
+	   Here we have the good internal_state.
+	   When we work on the data now, we have to pass it in 
+	   buffers, and sync: next_in, avail_in, total_in, next_out,
+	   avail_out, total_out. */
+	if (ret == Z_OK)
+		dataplace = malloc(zstreamsize);
+	z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize);
+	memcpy(dataplace, strm, zstreamsize);
+	nvlist_destroy(result);
+	return(ret);
+}
+
+int
+zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
+{
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
+	zstream * dataplace;
+	
+	if (pid == 0)
+		startChild();
 
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY);
+	nvlist_add_binary(args, "dictionary", *dictionary, dictLength);
+	nvlist_add_number(args, "dictLength", dictLength);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	ret = nvlist_take_number(result, "result");
+	if (ret == Z_OK)
+		dataplace = malloc(zstreamsize);
+	z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize);
+	nvlist_destroy(result);
+	return(ret);
+}
+
+int
+zcapcmd_deflateCopy(z_streamp dest, z_streamp source)
+{
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
+	zstream * dataplace;
+	
+	if (pid == 0)
+		startChild();
+
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY);
+	nvlist_add_binary(args, "dest", *dest, zstreamsize);
+	nvlist_add_binary(args, "source", *source, zstreamsize);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	/* The two z_streamp are now copied at the worker. */
+	result = sendCommand(nvl);
+
+	ret = nvlist_take_number(result, "result");
+	z_stream strm = nvlist_take_binary(result, "dest", zstreamsize);
+	if (ret == Z_OK)
+		dataplace = malloc(zstreamsize);
+		memcpy(dataplace, strm, zstreamsize);
+	nvlist_destroy(result);
+	return(ret);
+}
 
 uLong
 zcapcmd_compressBound(uLong sourceLen)
@@ -170,11 +325,86 @@
 	return(ret);
 }
 
-/* XXX
-zcapcmd_gzread(file, s);
-zcapcmd_gzwrite(file, s);
-zcapcmd_gzprintf(file, s);
-*/
+int
+zcapcmd_gzread(gzFile file, voidp buf, unsigned len)
+{
+	nvlist_t *nvl, *args, *result;
+	void * data;
+	
+	if (pid == 0)
+		startChild();
+
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_GZREAD);
+	nvlist_add_binary(args, "file", file, gzFilesize);
+	nvlist_add_number(args, "len", len);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	int ret = nvlist_take_number(result, "result");
+	data = nvlist_take_binary(result, "data", len);
+	memcpy(buf, data, (size_t)len);
+	nvlist_destroy(result);
+	return(ret);
+}
+
+int
+zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len)
+{
+	nvlist_t *nvl, *args, *result;
+	void * data;
+	
+	if (pid == 0)
+		startChild();
+
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_GZWRITE);
+	nvlist_add_binary(args, "file", file, gzFilesize);
+	nvlist_add_binary(args, "data", buf, len);
+	nvlist_add_number(args, "len", len);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	int ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
+}
+
+int
+zcapcmd_gzprintf(gzFile file, char * str)
+{
+	nvlist_t *nvl, *args, *result;
+	void * data;
+	
+	if (pid == 0)
+		startChild();
+
+	if( (args = nvlist_create(0)) == NULL ||
+		(nvl = nvlist_create(0)) == NULL ) {
+		perror("nvlist_create");
+		return(0);
+	}
+	nvlist_add_number(nvl, "command", ZCAPCMD_GZPRINTF);
+	nvlist_add_binary(args, "file", file, gzFilesize);
+	nvlist_add_string(args, "str", str);
+	nvlist_add_nvlist(nvl, "args", args);
+
+	result = sendCommand(nvl);
+
+	int ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
+}
 
 int
 zcapcmd_gzputs(gzFile file, const char *s)

Modified: soc2013/dpl/head/lib/libzcap/crc32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/crc32.c	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/crc32.c	Tue Aug 13 10:30:53 2013	(r255876)
@@ -207,18 +207,18 @@
     const unsigned char FAR *buf;
     uInt len;
 {
-    if (buf == Z_NULL) return 0UL;
-
-	/* Send packets of 100kb size at most. */
-	if ((sizeof(*buf)*len) > (5*1024)) {
- 		while( (len -= (5*1024)) > 0) {
- 			buf += (5*1024)/sizeof(*buf);
-			crc = zcapcmd_crc32(crc, buf, len);
-		}
-	} else {
-		crc = zcapcmd_crc32( crc, buf, len);
+#define MAX (5*1024)
+	int ret = 0;
+	/* We have to send the buffers value back and forth */
+	/* Send packets of 5kb size at most. */
+	while(len > MAX) {
+		ret += zcapcmd_crc32(file, buf, MAX);
+		buf += MAX;
+		len -= MAX;
 	}
-	return crc;
+	ret += zcapcmd_crc32(file, buf, len);
+
+	return ret;
 }
 
 #ifdef BYFOUR

Modified: soc2013/dpl/head/lib/libzcap/deflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/deflate.c	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/deflate.c	Tue Aug 13 10:30:53 2013	(r255876)
@@ -210,6 +210,7 @@
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateInit();
 int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
                   version, stream_size)
     z_streamp strm;
@@ -221,313 +222,81 @@
     const char *version;
     int stream_size;
 {
-    deflate_state *s;
-    int wrap = 1;
-    static const char my_version[] = ZLIB_VERSION;
-
-    ushf *overlay;
-    /* We overlay pending_buf and d_buf+l_buf. This works since the average
-     * output size for (length,distance) codes is <= 24 bits.
-     */
-
-    if (version == Z_NULL || version[0] != my_version[0] ||
-        stream_size != sizeof(z_stream)) {
-        return Z_VERSION_ERROR;
-    }
-    if (strm == Z_NULL) return Z_STREAM_ERROR;
-
-    strm->msg = Z_NULL;
-    if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
-        return Z_STREAM_ERROR;
-#else
-        strm->zalloc = zcalloc;
-        strm->opaque = (voidpf)0;
-#endif
-    }
-    if (strm->zfree == (free_func)0)
-#ifdef Z_SOLO
-        return Z_STREAM_ERROR;
-#else
-        strm->zfree = zcfree;
-#endif
-
-#ifdef FASTEST
-    if (level != 0) level = 1;
-#else
-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
-#endif
-
-    if (windowBits < 0) { /* suppress zlib wrapper */
-        wrap = 0;
-        windowBits = -windowBits;
-    }
-#ifdef GZIP
-    else if (windowBits > 15) {
-        wrap = 2;       /* write gzip wrapper instead */
-        windowBits -= 16;
-    }
-#endif
-    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
-        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
-        strategy < 0 || strategy > Z_FIXED) {
-        return Z_STREAM_ERROR;
-    }
-    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
-    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
-    if (s == Z_NULL) return Z_MEM_ERROR;
-    strm->state = (struct internal_state FAR *)s;
-    s->strm = strm;
-
-    s->wrap = wrap;
-    s->gzhead = Z_NULL;
-    s->w_bits = windowBits;
-    s->w_size = 1 << s->w_bits;
-    s->w_mask = s->w_size - 1;
-
-    s->hash_bits = memLevel + 7;
-    s->hash_size = 1 << s->hash_bits;
-    s->hash_mask = s->hash_size - 1;
-    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-
-    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
-    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
-    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
-
-    s->high_water = 0;      /* nothing written to s->window yet */
-
-    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
-
-    overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
-    s->pending_buf = (uchf *) overlay;
-    s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
-
-    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
-        s->pending_buf == Z_NULL) {
-        s->status = FINISH_STATE;
-        strm->msg = ERR_MSG(Z_MEM_ERROR);
-        deflateEnd (strm);
-        return Z_MEM_ERROR;
-    }
-    s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
-    s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
-
-    s->level = level;
-    s->strategy = strategy;
-    s->method = (Byte)method;
-
-    return deflateReset(strm);
+	return zcapcmd_deflateInit(strm, level, method, windowBits,
+                               memLevel, strategy, version, stream_size);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateSetDictionary();
 int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
     z_streamp strm;
     const Bytef *dictionary;
     uInt  dictLength;
 {
-    deflate_state *s;
-    uInt str, n;
-    int wrap;
-    unsigned avail;
-    z_const unsigned char *next;
+#define MAX (5*1024)
+	int ret = 0;
+	/* XXX - This won't work so easily. */
+	/* We have to send the buffers value back and forth */
+	/* Send packets of 5kb size at most. */
+	while(dictLength > MAX) {
+		ret += zcapcmd_crc32(strm, dictionary, MAX);
+		dictionary += MAX;
+		dictLength -= MAX;
+	}
+	ret += zcapcmd_crc32(strm, dictionary, dictLength);
 
-    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
-        return Z_STREAM_ERROR;
-    s = strm->state;
-    wrap = s->wrap;
-    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
-        return Z_STREAM_ERROR;
-
-    /* when using zlib wrappers, compute Adler-32 for provided dictionary */
-    if (wrap == 1)
-        strm->adler = adler32(strm->adler, dictionary, dictLength);
-    s->wrap = 0;                    /* avoid computing Adler-32 in read_buf */
-
-    /* if dictionary would fill window, just replace the history */
-    if (dictLength >= s->w_size) {
-        if (wrap == 0) {            /* already empty otherwise */
-            CLEAR_HASH(s);
-            s->strstart = 0;
-            s->block_start = 0L;
-            s->insert = 0;
-        }
-        dictionary += dictLength - s->w_size;  /* use the tail */
-        dictLength = s->w_size;
-    }
-
-    /* insert dictionary into window and hash */
-    avail = strm->avail_in;
-    next = strm->next_in;
-    strm->avail_in = dictLength;
-    strm->next_in = (z_const Bytef *)dictionary;
-    fill_window(s);
-    while (s->lookahead >= MIN_MATCH) {
-        str = s->strstart;
-        n = s->lookahead - (MIN_MATCH-1);
-        do {
-            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
-#ifndef FASTEST
-            s->prev[str & s->w_mask] = s->head[s->ins_h];
-#endif
-            s->head[s->ins_h] = (Pos)str;
-            str++;
-        } while (--n);
-        s->strstart = str;
-        s->lookahead = MIN_MATCH-1;
-        fill_window(s);
-    }
-    s->strstart += s->lookahead;
-    s->block_start = (long)s->strstart;
-    s->insert = s->lookahead;
-    s->lookahead = 0;
-    s->match_length = s->prev_length = MIN_MATCH-1;
-    s->match_available = 0;
-    strm->next_in = next;
-    strm->avail_in = avail;
-    s->wrap = wrap;
-    return Z_OK;
-}
-
-/* ========================================================================= */
-int ZEXPORT deflateResetKeep (strm)
-    z_streamp strm;
-{
-    deflate_state *s;
-
-    if (strm == Z_NULL || strm->state == Z_NULL ||
-        strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
-        return Z_STREAM_ERROR;
-    }
-
-    strm->total_in = strm->total_out = 0;
-    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
-    strm->data_type = Z_UNKNOWN;
-
-    s = (deflate_state *)strm->state;
-    s->pending = 0;
-    s->pending_out = s->pending_buf;
-
-    if (s->wrap < 0) {
-        s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
-    }
-    s->status = s->wrap ? INIT_STATE : BUSY_STATE;
-    strm->adler =
-#ifdef GZIP
-        s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
-#endif
-        adler32(0L, Z_NULL, 0);
-    s->last_flush = Z_NO_FLUSH;
-
-    _tr_init(s);
-
-    return Z_OK;
+	return ret;
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateReset();
 int ZEXPORT deflateReset (strm)
     z_streamp strm;
 {
-    int ret;
-
-    ret = deflateResetKeep(strm);
-    if (ret == Z_OK)
-        lm_init(strm->state);
-    return ret;
+	return zcapcmd_deflateReset(strm);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateSetHeader();
 int ZEXPORT deflateSetHeader (strm, head)
     z_streamp strm;
     gz_headerp head;
 {
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    if (strm->state->wrap != 2) return Z_STREAM_ERROR;
-    strm->state->gzhead = head;
-    return Z_OK;
+	return zcapcmd_deflateSetHeader(strm);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflatePending();
 int ZEXPORT deflatePending (strm, pending, bits)
     unsigned *pending;
     int *bits;
     z_streamp strm;
 {
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    if (pending != Z_NULL)
-        *pending = strm->state->pending;
-    if (bits != Z_NULL)
-        *bits = strm->state->bi_valid;
-    return Z_OK;
+	return zcapcmd_deflatePending(strm, pending, bits);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflatePrime();
 int ZEXPORT deflatePrime (strm, bits, value)
     z_streamp strm;
     int bits;
     int value;
 {
-    deflate_state *s;
-    int put;
-
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    s = strm->state;
-    if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
-        return Z_BUF_ERROR;
-    do {
-        put = Buf_size - s->bi_valid;
-        if (put > bits)
-            put = bits;
-        s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
-        s->bi_valid += put;
-        _tr_flush_bits(s);
-        value >>= put;
-        bits -= put;
-    } while (bits);
-    return Z_OK;
+	return zcapcmd_deflatePrime(strm, bits, value);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateParams();
 int ZEXPORT deflateParams(strm, level, strategy)
     z_streamp strm;
     int level;
     int strategy;
 {
-    deflate_state *s;
-    compress_func func;
-    int err = Z_OK;
-
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    s = strm->state;
-
-#ifdef FASTEST
-    if (level != 0) level = 1;
-#else
-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
-#endif
-    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
-        return Z_STREAM_ERROR;
-    }
-    func = configuration_table[s->level].func;
-
-    if ((strategy != s->strategy || func != configuration_table[level].func) &&
-        strm->total_in != 0) {
-        /* Flush the last buffer: */
-        err = deflate(strm, Z_BLOCK);
-        if (err == Z_BUF_ERROR && s->pending == 0)
-            err = Z_OK;
-    }
-    if (s->level != level) {
-        s->level = level;
-        s->max_lazy_match   = configuration_table[level].max_lazy;
-        s->good_match       = configuration_table[level].good_length;
-        s->nice_match       = configuration_table[level].nice_length;
-        s->max_chain_length = configuration_table[level].max_chain;
-    }
-    s->strategy = strategy;
-    return err;
+	return zcapcmd_deflateParams(strm, level, strategy);
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflateTune();
 int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
     z_streamp strm;
     int good_length;
@@ -535,15 +304,7 @@
     int nice_length;
     int max_chain;
 {
-    deflate_state *s;
-
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    s = strm->state;
-    s->good_match = good_length;
-    s->max_lazy_match = max_lazy;
-    s->nice_match = nice_length;
-    s->max_chain_length = max_chain;
-    return Z_OK;
+	return zcapcmd_deflateTune(strm, good_length, max_lazy, nice_length, max_chain);
 }
 
 /* =========================================================================
@@ -563,61 +324,12 @@
  * upper bound of about 14% expansion does not seem onerous for output buffer
  * allocation.
  */
+extern int zcapcmd_deflateBound();
 uLong ZEXPORT deflateBound(strm, sourceLen)
     z_streamp strm;
     uLong sourceLen;
 {
-    deflate_state *s;
-    uLong complen, wraplen;
-    Bytef *str;
-
-    /* conservative upper bound for compressed data */
-    complen = sourceLen +
-              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
-
-    /* if can't get parameters, return conservative bound plus zlib wrapper */
-    if (strm == Z_NULL || strm->state == Z_NULL)
-        return complen + 6;
-
-    /* compute wrapper length */
-    s = strm->state;
-    switch (s->wrap) {
-    case 0:                                 /* raw deflate */
-        wraplen = 0;
-        break;
-    case 1:                                 /* zlib wrapper */
-        wraplen = 6 + (s->strstart ? 4 : 0);
-        break;
-    case 2:                                 /* gzip wrapper */
-        wraplen = 18;
-        if (s->gzhead != Z_NULL) {          /* user-supplied gzip header */
-            if (s->gzhead->extra != Z_NULL)
-                wraplen += 2 + s->gzhead->extra_len;
-            str = s->gzhead->name;
-            if (str != Z_NULL)
-                do {
-                    wraplen++;
-                } while (*str++);
-            str = s->gzhead->comment;
-            if (str != Z_NULL)
-                do {
-                    wraplen++;
-                } while (*str++);
-            if (s->gzhead->hcrc)
-                wraplen += 2;
-        }
-        break;
-    default:                                /* for compiler happiness */
-        wraplen = 6;
-    }
-
-    /* if not default parameters, return conservative bound */
-    if (s->w_bits != 15 || s->hash_bits != 8 + 7)
-        return complen + wraplen;
-
-    /* default settings: return tight bound for that case */
-    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
-           (sourceLen >> 25) + 13 - 6 + wraplen;
+	return zcapcmd_deflateBound(strm, sourceLen);
 }
 
 /* =========================================================================
@@ -662,6 +374,7 @@
 }
 
 /* ========================================================================= */
+extern int zcapcmd_deflate();
 int ZEXPORT deflate (strm, flush)
     z_streamp strm;
     int flush;
@@ -673,7 +386,6 @@
         flush > Z_BLOCK || flush < 0) {
         return Z_STREAM_ERROR;
     }
-    s = strm->state;
 
     if (strm->next_out == Z_NULL ||
         (strm->next_in == Z_NULL && strm->avail_in != 0) ||
@@ -682,6 +394,7 @@
     }
     if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
 
+    s = strm->state;
     s->strm = strm; /* just in case */
     old_flush = s->last_flush;
     s->last_flush = flush;
@@ -976,34 +689,12 @@
 }
 
 /* ========================================================================= */
+int zcapcmd_deflateEnd();
 int ZEXPORT deflateEnd (strm)
     z_streamp strm;
 {
-    int status;
-
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-
-    status = strm->state->status;
-    if (status != INIT_STATE &&
-        status != EXTRA_STATE &&
-        status != NAME_STATE &&
-        status != COMMENT_STATE &&
-        status != HCRC_STATE &&
-        status != BUSY_STATE &&
-        status != FINISH_STATE) {
-      return Z_STREAM_ERROR;
-    }
-
-    /* Deallocate in reverse order of allocations: */
-    TRY_FREE(strm, strm->state->pending_buf);
-    TRY_FREE(strm, strm->state->head);
-    TRY_FREE(strm, strm->state->prev);
-    TRY_FREE(strm, strm->state->window);
-
-    ZFREE(strm, strm->state);
-    strm->state = Z_NULL;
-
-    return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
+	retrurn zcapcmd_deflateEnd(strm);
 }
 
 /* =========================================================================
@@ -1011,6 +702,7 @@
  * To simplify the source, this is not supported for 16-bit MSDOS (which
  * doesn't have enough memory anyway to duplicate compression states).
  */
+extern zcapcmd_deflateCopy();
 int ZEXPORT deflateCopy (dest, source)
     z_streamp dest;
     z_streamp source;
@@ -1018,51 +710,7 @@
 #ifdef MAXSEG_64K
     return Z_STREAM_ERROR;
 #else
-    deflate_state *ds;
-    deflate_state *ss;
-    ushf *overlay;
-
-
-    if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
-        return Z_STREAM_ERROR;
-    }
-
-    ss = source->state;
-
-    zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
-
-    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
-    if (ds == Z_NULL) return Z_MEM_ERROR;
-    dest->state = (struct internal_state FAR *) ds;
-    zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
-    ds->strm = dest;
-
-    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
-    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
-    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
-    overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
-    ds->pending_buf = (uchf *) overlay;
-
-    if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
-        ds->pending_buf == Z_NULL) {
-        deflateEnd (dest);
-        return Z_MEM_ERROR;
-    }
-    /* following zmemcpy do not work for 16-bit MSDOS */
-    zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
-    zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
-    zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
-    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
-
-    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
-    ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
-    ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
-
-    ds->l_desc.dyn_tree = ds->dyn_ltree;
-    ds->d_desc.dyn_tree = ds->dyn_dtree;
-    ds->bl_desc.dyn_tree = ds->bl_tree;
-
-    return Z_OK;
+	return zcapcmd_deflateCopy(dest, source);
 #endif /* MAXSEG_64K */
 }
 

Modified: soc2013/dpl/head/lib/libzcap/gzguts.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzguts.h	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/gzguts.h	Tue Aug 13 10:30:53 2013	(r255876)
@@ -192,12 +192,6 @@
 } gz_state;
 typedef gz_state FAR *gz_statep;
 
-/* shared functions */
-void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
-#if defined UNDER_CE
-char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
-#endif
-
 /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
    value -- needed when comparing unsigned to z_off64_t, which is signed
    (possible z_off64_t types off_t, off64_t, and long are all signed) */

Modified: soc2013/dpl/head/lib/libzcap/gzlib.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzlib.c	Tue Aug 13 09:58:27 2013	(r255875)
+++ soc2013/dpl/head/lib/libzcap/gzlib.c	Tue Aug 13 10:30:53 2013	(r255876)
@@ -19,264 +19,14 @@
 #endif
 #endif
 
-/* Local functions */
-local void gz_reset OF((gz_statep));
-local gzFile gz_open OF((const void *, int, const char *));
-
-#if defined UNDER_CE
-
-/* Map the Windows error number in ERROR to a locale-dependent error message
-   string and return a pointer to it.  Typically, the values for ERROR come
-   from GetLastError.
-
-   The string pointed to shall not be modified by the application, but may be
-   overwritten by a subsequent call to gz_strwinerror
-
-   The gz_strwinerror function does not change the current setting of
-   GetLastError. */
-char ZLIB_INTERNAL *gz_strwinerror (error)
-     DWORD error;
-{
-    static char buf[1024];
-
-    wchar_t *msgbuf;
-    DWORD lasterr = GetLastError();
-    DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
-        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
-        NULL,
-        error,
-        0, /* Default language */
-        (LPVOID)&msgbuf,
-        0,
-        NULL);
-    if (chars != 0) {
-        /* If there is an \r\n appended, zap it.  */
-        if (chars >= 2
-            && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') {
-            chars -= 2;
-            msgbuf[chars] = 0;
-        }
-
-        if (chars > sizeof (buf) - 1) {
-            chars = sizeof (buf) - 1;
-            msgbuf[chars] = 0;
-        }
-
-        wcstombs(buf, msgbuf, chars + 1);
-        LocalFree(msgbuf);
-    }
-    else {
-        sprintf(buf, "unknown win32 error (%ld)", error);
-    }
-
-    SetLastError(lasterr);
-    return buf;
-}
-
-#endif /* UNDER_CE */
-
-/* Reset gzip file state */
-local void gz_reset(state)
-    gz_statep state;
-{
-    state->x.have = 0;              /* no output data available */
-    if (state->mode == GZ_READ) {   /* for reading ... */
-        state->eof = 0;             /* not at end of file */
-        state->past = 0;            /* have not read past end yet */
-        state->how = LOOK;          /* look for gzip header */
-    }
-    state->seek = 0;                /* no seek request pending */
-    gz_error(state, Z_OK, NULL);    /* clear error */
-    state->x.pos = 0;               /* no uncompressed data yet */
-    state->strm.avail_in = 0;       /* no input data yet */
-}
-
-/* Open a gzip file either by name or file descriptor. */
-local gzFile gz_open(path, fd, mode)
-    const void *path;
-    int fd;
-    const char *mode;
-{
-    gz_statep state;
-    size_t len;
-    int oflag;
-#ifdef O_CLOEXEC
-    int cloexec = 0;
-#endif
-#ifdef O_EXCL
-    int exclusive = 0;
-#endif

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308131030.r7DAUstj030195>