Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Aug 2013 10:49:21 GMT
From:      dpl@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r255527 - in soc2013/dpl/head/lib/libzcap: . zlibworker
Message-ID:  <201308051049.r75AnLxt086242@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dpl
Date: Mon Aug  5 10:49:20 2013
New Revision: 255527
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255527

Log:
  I'm writing the worker process here. It will wait for commands, and execute them.
  

Added:
  soc2013/dpl/head/lib/libzcap/zlibworker/
  soc2013/dpl/head/lib/libzcap/zlibworker/Makefile
  soc2013/dpl/head/lib/libzcap/zlibworker/comands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
Modified:
  soc2013/dpl/head/lib/libzcap/Makefile
  soc2013/dpl/head/lib/libzcap/adler32.c
  soc2013/dpl/head/lib/libzcap/capsicum.c
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/commands.h
  soc2013/dpl/head/lib/libzcap/compress.c
  soc2013/dpl/head/lib/libzcap/crc32.c
  soc2013/dpl/head/lib/libzcap/deflate.c

Modified: soc2013/dpl/head/lib/libzcap/Makefile
==============================================================================
--- soc2013/dpl/head/lib/libzcap/Makefile	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/Makefile	Mon Aug  5 10:49:20 2013	(r255527)
@@ -5,10 +5,10 @@
 #TODEL
 CFLAGS+= -Wall -g -fno-color-diagnostics
 
-LIB=		z
+LIB=		zcap
 SHLIBDIR?=	/lib
 SHLIB_MAJOR=	6
-MAN=		zlib.3
+MAN=		zcaplib.3
 
 #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
 #CFLAGS=-g -DDEBUG
@@ -37,6 +37,7 @@
 SRCS+=		zopen.c
 SRCS+=		zutil.c
 SRCS+=		capsicum.c
+SRCS+=		commands.c
 
 #.if ${MACHINE_ARCH} == "i386" && ${MACHINE_CPU:M*i686*}
 #.PATH:		${.CURDIR}/contrib/asm686

Modified: soc2013/dpl/head/lib/libzcap/adler32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/adler32.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/adler32.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -62,103 +62,32 @@
 #endif
 
 /* ========================================================================= */
+uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len);
 uLong ZEXPORT adler32(adler, buf, len)
     uLong adler;
     const Bytef *buf;
     uInt len;
 {
-    unsigned long sum2;
-    unsigned n;
-
-    /* split Adler-32 into component sums */
-    sum2 = (adler >> 16) & 0xffff;
-    adler &= 0xffff;
-
-    /* in case user likes doing a byte at a time, keep it fast */
-    if (len == 1) {
-        adler += buf[0];
-        if (adler >= BASE)
-            adler -= BASE;
-        sum2 += adler;
-        if (sum2 >= BASE)
-            sum2 -= BASE;
-        return adler | (sum2 << 16);
-    }
-
-    /* initial Adler-32 value (deferred check for len == 1 speed) */
-    if (buf == Z_NULL)
-        return 1L;
-
-    /* in case short lengths are provided, keep it somewhat fast */
-    if (len < 16) {
-        while (len--) {
-            adler += *buf++;
-            sum2 += adler;
-        }
-        if (adler >= BASE)
-            adler -= BASE;
-        MOD28(sum2);            /* only added so many BASE's */
-        return adler | (sum2 << 16);
-    }
-
-    /* do length NMAX blocks -- requires just one modulo operation */
-    while (len >= NMAX) {
-        len -= NMAX;
-        n = NMAX / 16;          /* NMAX is divisible by 16 */
-        do {
-            DO16(buf);          /* 16 sums unrolled */
-            buf += 16;
-        } while (--n);
-        MOD(adler);
-        MOD(sum2);
-    }
-
-    /* do remaining bytes (less than NMAX, still just one modulo) */
-    if (len) {                  /* avoid modulos if none remaining */
-        while (len >= 16) {
-            len -= 16;
-            DO16(buf);
-            buf += 16;
-        }
-        while (len--) {
-            adler += *buf++;
-            sum2 += adler;
-        }
-        MOD(adler);
-        MOD(sum2);
-    }
-
-    /* return recombined sums */
-    return adler | (sum2 << 16);
+	/* Send packets of 1MB size at most. */
+	if ((sizeof(*buf)*len) > (1024*1024)) {
+ 		while( (len -= (1024*1024)) > 0) {
+ 			buf += (1024*1024)/sizeof(*buf);
+			adler = zcapcmd_adler32(adler, buf, len);
+		}
+	} else {
+		adler = zcapcmd_adler32( adler, buf, len);
+	}
+	return adler;
 }
 
 /* ========================================================================= */
+uLong zcapcmd_adler32_combine(uLong, uLong, z_off64_t);
 local uLong adler32_combine_(adler1, adler2, len2)
     uLong adler1;
     uLong adler2;
     z_off64_t len2;
 {
-    unsigned long sum1;
-    unsigned long sum2;
-    unsigned rem;
-
-    /* for negative len, return invalid adler32 as a clue for debugging */
-    if (len2 < 0)
-        return 0xffffffffUL;
-
-    /* the derivation of this formula is left as an exercise for the reader */
-    MOD63(len2);                /* assumes len2 >= 0 */
-    rem = (unsigned)len2;
-    sum1 = adler1 & 0xffff;
-    sum2 = rem * sum1;
-    MOD(sum2);
-    sum1 += (adler2 & 0xffff) + BASE - 1;
-    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
-    if (sum1 >= BASE) sum1 -= BASE;
-    if (sum1 >= BASE) sum1 -= BASE;
-    if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
-    if (sum2 >= BASE) sum2 -= BASE;
-    return sum1 | (sum2 << 16);
+	return (zcapcmd_adler32_combine(adler1, adler2, len2));
 }
 
 /* ========================================================================= */

Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -1,6 +1,4 @@
 #include "capsicum.h"
-
-#if defined(CAPSICUM)
 #include "zlib.h"
 
 #define SUM 0
@@ -10,7 +8,6 @@
 
 int startChild(void);
 void killChild(void);
-nvlist_t * command(int command, int args, ... );
 
 int
 startChild()
@@ -19,11 +16,21 @@
 		perror("socketpair");
 
 	if( (pid = fork()) == 0 ){
-		cap_rights_limit(STDOUT_FILENO, CAP_WRITE);
 		close(STDIN_FILENO);
-		close(STDERR_FILENO);
-		cap_enter();
-		/* Exec listener */
+		close(STDOUT_FILENO);
+
+		dup(sv[1]); /* stdin is now the socket */
+		close(sv[0]);
+		close(sv[1]);
+		
+		/* open and fexec() listener */
+		if (access("/usr/libexec/zlibworker", X_OK) < 0) {
+			fprintf(stderr, "zlibworker doesn't exist, or can't be executed.\n")
+			fprintf(stderr, "You should compile and install it.\n");
+			exit (-1);
+		}
+	
+		execve("/usr/libexec/zlibworker", "", "");
 		exit(0);
 	} else
 		atexit(killChild);
@@ -31,67 +38,19 @@
 	return pid;
 }
 
-/*
- * Wait for commands, and execute them
- * This code really pertains to the listener program
-
-void
-waitCommand()
-{
-	nvlist_t *nvl, *args;
-	
-	while(1) {
-		while(1){
-			if  ((nvl = nvlist_recv(sv[1])) != NULL)
-				if (nvlist_exists(nvl, "command"))
-					if (nvlist_exists(nvl, "args"))
-						break;
-			;
-		}
-
-		// Switch for "command"
-		// Get args, and call the real lib.
-		int com = nvlist_take_number(nvl, "command");
-		if (com == SUM) {
-				if ((args = nvlist_take_nvlist(nvl, "args")) == NULL) {
-					perror("CHILD: nvlist_take_nvlist(nvl, 'args')");
-					break;
-				}
-				nvlist_add_number(nvl, "result", 0 );
-		}
-		
-		while(1){
-			if( nvlist_send(sv[1], nvl) == 0 )
-				break;
-			;
-		}
-		;
-	}
-}
-
-*/
-
 nvlist_t *
-sendCommand( nvlist_t *nvl)
+sendCommand( nvlist_t *nvl )
 {
-	while(1){
-		if( nvlist_send(sv[0], nvl) == 0 )
-			break;
-		;
-	}
+	if( nvlist_send(sv[0], nvl) == 0 )
+		continue;
+	nvlist_destroy(nvl);
 
 	/* recv results */
-	while(1){
-		if ((nvl = nvlist_recv(sv[0])) != NULL)
-			if (nvlist_exists(nvl, "result"))
-				break;
-		;
-	}
+	if ((nvl = nvlist_recv(sv[0])) != NULL)
+		continue;
 	return (nvl);
 }
 
 void killChild(){
 	kill(pid, SIGKILL);
-}
-
-#endif /* CAPSICUM */
\ No newline at end of file
+}
\ No newline at end of file

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -1,10 +1,11 @@
 /*
 	This is just a template of the capsicumized functions.
 
-nvlist_t *
-zcapcmd_command( args )
+datatype
+zcapcmd_function( real func args )
 {
-	nvlist_t *nvl, *args, *results;
+	nvlist_t *nvl, *args, *result;
+	datatype ret;
 	
 	if (pid == 0)
 		startChild();
@@ -14,57 +15,36 @@
 		perror("nvlist_create");
 		return (NULL);
 	}
-	nvlist_add_number(nvl, "command", ZCAPCMD_);
+	nvlist_add_number(nvl, "command", ZCAPCMD_COMMAND);
+	nvlist_add_number(args, "crc1", crc1);
+	nvlist_add_number(args, "crc2", crc2);
+	nvlist_add_number(args, "len2", len2);
+	nvlist_add_nvlist(nvl, "args", args);
 
+	result = sendCommand(nvl);
 
-	results = sendCommand(nvl);
+	ret = nvlist_take_datatypenvl(result, "result")
+	
 	nvlist_destroy(args);
 	nvlist_destroy(nvl);
+	nvlist_destroy(result);
 
+	return(ret);
 }
 
 */
 
-extern pid;
+#include "capsicum.c"
 
-
-/* basic functions */
-nvlist_t *
-zcapcmd_deflateInit( z_streamp strm, int level,int method, int windowBits,
-	int strategy, const char *version, int stream_size )
-{
-	nvlist_t *nvl, *args, *results;
-	
-	if (pid == 0)
-		startChild();
-
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
-		return (NULL);
-	}
-	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-
-	nvlist_add_binary(args, "strm", strm, sizeof(z_streamp));
-	nvlist_add_number(args, "level", level);
-	nvlist_add_number(args, "method", method);
-	nvlist_add_number(args, "windowBits", windowBits);
-	nvlist_add_string(args, "version", version);
-	nvlist_add_number(args, "stream_size", stream_size);
-	nvlist_add_nvlist(nvl, "args", args);
-
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
-	
-	int result = nvlist_take_number(nvlresults, "result");
-	nvlist_delete(nvlresults);
-}
+extern pid;
+extern nvlist_t *sendCommand(nvlist_t *);
 
 int
-zcapcmd_deflate( z_streamp strm, int flush )
+zcapcmd_deflate( strm, flush )
+z_streamp strm;
+int flush;
 {
-	nvlist_t *nvl, *args, *results;
+	nvlist_t *nvl, *args, *result;
 	
 	if (pid == 0)
 		startChild();
@@ -80,18 +60,20 @@
 	nvlist_add_number(args, "flush", flush);
 	nvlist_add_nvlist(nvl, "args", args);
 
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
-
-	int result = nvlist_take_number(nvlresults, "result");
-	nvlist_delete(nvlresults);
+	result = sendCommand(nvl);
+	int ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret)
 }
 
-nvlist_t *
-zcapcmd_deflateEnd(z_streamp strm)
+uLong
+zcapcmd_compressBound( adler1, adler2, len2 )
+	uLong adler1;
+	uLong adler2;
+	z_off_t len2;
 {
-	nvlist_t *nvl, *args, *nvlresults;
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
 	
 	if (pid == 0)
 		startChild();
@@ -101,49 +83,56 @@
 		perror("nvlist_create");
 		return (NULL);
 	}
-	nvlist_add_number(nvl, "command", ZLIBCMD_VAR);
-	
-	nvlist_add_binary(args, "strm", strm, sizeof(z_streamp));
+	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32_COMBINE);
+	nvlist_add_number(args, "adler2", adler2);
+	nvlist_add_number(args, "adler2", adler2);
+	nvlist_add_number(args, "len2", len2);
 	nvlist_add_nvlist(nvl, "args", args);
 
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
+	result = sendCommand(nvl);
 
-	int result = nvlist_take_number(nvlresults, "result");
-	nvlist_delete(nvlresults);
-	
-	return( result);
+	ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
 }
 
-nvlist_t *
-zcapcmd_inflateInit( args )
+uLong
+zcapcmd_adler32(adler, buf, len)
+	uLong adler;
+	const Bytef *buf;
+	uInt len;
 {
-	nvlist_t *nvl, *args, *results;
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
 	
 	if (pid == 0)
 		startChild();
-
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
 		perror("nvlist_create");
 		return (NULL);
 	}
-	nvlist_add_number(nvl, "command", ZLIBCMD_VAR);
-
-	/* set args */
+	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32);
+	nvlist_add_number(args, "adler", adler);
+	nvlist_add_binary(args, "buf", *buf, len);
+	nvlist_add_number(args, "len", len);
+	nvlist_add_nvlist(nvl, "args", args);
 
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
+	result = sendCommand(nvl);
 
-	/* Get result */
+	ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
 }
 
-nvlist_t *
-zcapcmd_inflate( args )
+uLong
+zcapcmd_adler32_combine( adler1, adler2, len2 )
+	uLong adler1;
+	uLong adler2;
+	z_off_t len2
 {
-	nvlist_t *nvl, *args, *results;
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
 	
 	if (pid == 0)
 		startChild();
@@ -153,25 +142,28 @@
 		perror("nvlist_create");
 		return (NULL);
 	}
-	nvlist_add_number(nvl, "command", ZLIBCMD_VAR);
-
-	/* set args */
-
+	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32_COMBINE);
+	nvlist_add_number(args, "adler2", adler2);
+	nvlist_add_number(args, "adler2", adler2);
+	nvlist_add_number(args, "len2", len2);
+	nvlist_add_nvlist(nvl, "args", args);
 
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
+	result = sendCommand(nvl);
 
-	/* Get result */
+	ret = nvlist_take_number(result, "result");
+	nvlist_destroy(result);
+	return(ret);
 }
 
-nvlist_t *
-zcapcmd_inflateEnd( args )
+uLong
+zcapcmd_adler32_combine( crc1, crc2, len2 )
+	uLong crc1;
+	uLong crc2;
+	z_off64_t len2;
 {
-	nvlist_t *nvl, *args, *results;
+	nvlist_t *nvl, *args, *result;
+	uLong ret;
 	
-	/* If the child is not executing, do it. */
-	/* It _should_ only be tested once.
 	if (pid == 0)
 		startChild();
 
@@ -180,15 +172,14 @@
 		perror("nvlist_create");
 		return (NULL);
 	}
-	nvlist_add_number(nvl, "command", ZLIBCMD_VAR);
-
-	/* set args */
-
-
-	results = sendCommand(nvl);
-	nvlist_destroy(args);
-	nvlist_destroy(nvl);
-
-	/* Get result */
-}
+	nvlist_add_number(nvl, "command", ZCAPCMD_CRC32_COMBINE);
+	nvlist_add_number(args, "crc1", crc1);
+	nvlist_add_number(args, "crc2", crc2);
+	nvlist_add_number(args, "len2", len2);
+	nvlist_add_nvlist(nvl, "args", args);
 
+	result = sendCommand(nvl);
+	ret = nvlist_take_number(result, "result")
+	nvlist_destroy(result);
+	return(ret);
+}
\ No newline at end of file

Modified: soc2013/dpl/head/lib/libzcap/commands.h
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.h	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/commands.h	Mon Aug  5 10:49:20 2013	(r255527)
@@ -7,88 +7,15 @@
 	zlib listening through a program, and it will recognize them.
 	Also, the defines have been checked for not being duplicates.
 
-	// basic functions
-	zlibVersion // Not capsicumized
-	deflateInit 
-	deflate 
-	deflateEnd 
-	inflateInit 
-	inflate 
-	inflateEnd 
-
-	// Advanced functions
-	deflateInit2
-	deflateSetDictionary
-	deflateCopy
-	deflateReset
-	deflateParams
-	deflateTune
-	deflateBound
-	deflatePending
-	deflatePrime
-	deflateSetHeader
-	inflateInit2
-	inflateSetDictionary
-	inflateGetDictionary
-	inflateSync
-	inflateCopy
-	inflateReset
-	inflateReset2
-	inflatePrime
-	inflateMark
-	inflateGetHeader
-	inflateBackInit
-	inflateBack
-	inflateBackEnd
-	zlibCompileFlags
-
-	// utility functions
-	compress
-	compress2
-	compressBound
-	uncompress
-
-	// gzip file access functions
-	gzopen
-	gzdopen
-	gzbuffer
-	gzsetparams
-	gzread
-	gzwrite
-	gzprintf
-	gzputs
-	gzgets
-	gzputc
-	gzgetc
-	gzungetc
-	gzflush
-	gzseek
-	gzrewind
-	gztell
-	gzoffset
-	gzeof
-	gzdirect
-	gzclose
-	gzclose_r
-	gzclose_w
-	gzerror
-	gzclearerr
-
-	// checksum functions
-	adler32 
-	adler32_combine 
-	crc32   
-	crc32_combine
+	Since the only things that we can Capsicumize are: deflate()
+	and inflate(), we only have to care about sending those to 
+	commands (related to the basic functions, and utility functions.
+
 */
 
 
-/* basic functions */
-#define ZCAPCMD_DEFLATEINIT			0
-#define ZCAPCMD_DEFLATE				1
-#define ZCAPCMD_DEFLATEEND			2
-#define ZCAPCMD_INFLATEINIT			3
-#define ZCAPCMD_INFLATE				4
-#define ZCAPCMD_INFLATEEND			5
+#define ZCAPCMD_DEFLATE				0
+#define ZCAPCMD_INFLATE				1
 
 /* Advanced functions */
 #define ZCAPCMD_DEFLATESETDICTIONARY 	6
@@ -116,39 +43,35 @@
 #define ZCAPCMD_ZLIBCOMPILEFLAGS		28
 
 /* utility functions */
-#define ZCAPCMD_COMPRESS				29
-#define ZCAPCMD_COMPRESS2			30
-#define ZCAPCMD_COMPRESSBOUND		31
-#define ZCAPCMD_UNCOMPRESS			32
+#define ZCAPCMD_COMPRESSBOUND		30
 
 /* gzip file access functions */
-#define ZCAPCMD_GZOPEN				33
-#define ZCAPCMD_GZDOPEN				34
-#define ZCAPCMD_GZBUFFER				35
-#define ZCAPCMD_GZSETPARAMS			36
-#define ZCAPCMD_GZREAD				37
-#define ZCAPCMD_GZWRITE				38
-#define ZCAPCMD_GZPRINTF				39
-#define ZCAPCMD_GZPUTS				40
-#define ZCAPCMD_GZGETS				50
-#define ZCAPCMD_GZPUTC				51
-#define ZCAPCMD_GZGETC				52
-#define ZCAPCMD_GZUNGETC				53
-#define ZCAPCMD_GZFLUSH				54
-#define ZCAPCMD_GZSEEK				55
-#define ZCAPCMD_GZREWIND				56
-#define ZCAPCMD_GZTELL				57
-#define ZCAPCMD_GZOFFSET				58
-#define ZCAPCMD_GZEOF				59
-#define ZCAPCMD_GZDIRECT				60
-#define ZCAPCMD_GZCLOSE				61
-#define ZCAPCMD_GZCLOSE_R			62
-#define ZCAPCMD_GZCLOSE_W			63
-#define ZCAPCMD_GZERROR				64
-#define ZCAPCMD_GZCLEARERR			65
+#define ZCAPCMD_GZ_OPEN				32
+#define ZCAPCMD_GZBUFFER				34
+#define ZCAPCMD_GZSETPARAMS			35
+#define ZCAPCMD_GZREAD				36
+#define ZCAPCMD_GZWRITE				37
+#define ZCAPCMD_GZPRINTF				38
+#define ZCAPCMD_GZPUTS				39
+#define ZCAPCMD_GZGETS				49
+#define ZCAPCMD_GZPUTC				50
+#define ZCAPCMD_GZGETC				51
+#define ZCAPCMD_GZUNGETC				52
+#define ZCAPCMD_GZFLUSH				53
+#define ZCAPCMD_GZSEEK				54
+#define ZCAPCMD_GZREWIND				55
+#define ZCAPCMD_GZTELL				56
+#define ZCAPCMD_GZOFFSET				57
+#define ZCAPCMD_GZEOF				58
+#define ZCAPCMD_GZDIRECT				59
+#define ZCAPCMD_GZCLOSE				60
+#define ZCAPCMD_GZCLOSE_R			61
+#define ZCAPCMD_GZCLOSE_W			62
+#define ZCAPCMD_GZERROR				63
+#define ZCAPCMD_GZCLEARERR			64
 
 /* checksum functions */
-#define ZCAPCMD_ADLER32				66
-#define ZCAPCMD_ADLER32_COMBINE		67
-#define ZCAPCMD_CRC32				68
-#define ZCAPCMD_CRC32_COMBINE		69
+#define ZCAPCMD_ADLER32				65
+#define ZCAPCMD_ADLER32_COMBINE		66
+#define ZCAPCMD_CRC32				67
+#define ZCAPCMD_CRC32_COMBINE		68

Modified: soc2013/dpl/head/lib/libzcap/compress.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/compress.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/compress.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -72,9 +72,10 @@
      If the default memLevel or windowBits for deflateInit() is changed, then
    this function needs to be updated.
  */
+uLong zcapcmd_compressBound(uLong);
+
 uLong ZEXPORT compressBound (sourceLen)
     uLong sourceLen;
 {
-    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
-           (sourceLen >> 25) + 13;
+    return (zcapcmd_compressBound(sourceLen));
 }

Modified: soc2013/dpl/head/lib/libzcap/crc32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/crc32.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/crc32.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -352,59 +352,13 @@
 }
 
 /* ========================================================================= */
+uLong zcapcmd_crc32_combine(uLong, uLong, z_off64_t);
 local uLong crc32_combine_(crc1, crc2, len2)
     uLong crc1;
     uLong crc2;
     z_off64_t len2;
 {
-    int n;
-    unsigned long row;
-    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */
-    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */
-
-    /* degenerate case (also disallow negative lengths) */
-    if (len2 <= 0)
-        return crc1;
-
-    /* put operator for one zero bit in odd */
-    odd[0] = 0xedb88320UL;          /* CRC-32 polynomial */
-    row = 1;
-    for (n = 1; n < GF2_DIM; n++) {
-        odd[n] = row;
-        row <<= 1;
-    }
-
-    /* put operator for two zero bits in even */
-    gf2_matrix_square(even, odd);
-
-    /* put operator for four zero bits in odd */
-    gf2_matrix_square(odd, even);
-
-    /* apply len2 zeros to crc1 (first square will put the operator for one
-       zero byte, eight zero bits, in even) */
-    do {
-        /* apply zeros operator for this bit of len2 */
-        gf2_matrix_square(even, odd);
-        if (len2 & 1)
-            crc1 = gf2_matrix_times(even, crc1);
-        len2 >>= 1;
-
-        /* if no more bits set, then done */
-        if (len2 == 0)
-            break;
-
-        /* another iteration of the loop with odd and even swapped */
-        gf2_matrix_square(odd, even);
-        if (len2 & 1)
-            crc1 = gf2_matrix_times(odd, crc1);
-        len2 >>= 1;
-
-        /* if no more bits set, then done */
-    } while (len2 != 0);
-
-    /* return combined crc */
-    crc1 ^= crc2;
-    return crc1;
+	return (zcapcmd_crc32_combine(crc1, crc2, len2));
 }
 
 /* ========================================================================= */

Modified: soc2013/dpl/head/lib/libzcap/deflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/deflate.c	Mon Aug  5 10:48:12 2013	(r255526)
+++ soc2013/dpl/head/lib/libzcap/deflate.c	Mon Aug  5 10:49:20 2013	(r255527)
@@ -221,8 +221,102 @@
     const char *version;
     int stream_size;
 {
-    return zcapcmd_deflateInit(strm, level, method, windowBits, 
-		memLevel, strategy, version, 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);
 }
 
 /* ========================================================================= */
@@ -572,14 +666,344 @@
     z_streamp strm;
     int flush;
 {
-    return zcapcmd_deflate(strm, flush);
+    int old_flush; /* value of flush param for previous deflate call */
+    deflate_state *s;
+
+    if (strm == Z_NULL || strm->state == Z_NULL ||
+        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) ||
+        (s->status == FINISH_STATE && flush != Z_FINISH)) {
+        ERR_RETURN(strm, Z_STREAM_ERROR);
+    }
+    if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
+
+    s->strm = strm; /* just in case */
+    old_flush = s->last_flush;
+    s->last_flush = flush;
+
+    /* Write the header */
+    if (s->status == INIT_STATE) {
+#ifdef GZIP
+        if (s->wrap == 2) {
+            strm->adler = crc32(0L, Z_NULL, 0);
+            put_byte(s, 31);
+            put_byte(s, 139);
+            put_byte(s, 8);
+            if (s->gzhead == Z_NULL) {
+                put_byte(s, 0);
+                put_byte(s, 0);
+                put_byte(s, 0);
+                put_byte(s, 0);
+                put_byte(s, 0);
+                put_byte(s, s->level == 9 ? 2 :
+                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+                             4 : 0));
+                put_byte(s, OS_CODE);
+                s->status = BUSY_STATE;
+            }
+            else {
+                put_byte(s, (s->gzhead->text ? 1 : 0) +
+                            (s->gzhead->hcrc ? 2 : 0) +
+                            (s->gzhead->extra == Z_NULL ? 0 : 4) +
+                            (s->gzhead->name == Z_NULL ? 0 : 8) +
+                            (s->gzhead->comment == Z_NULL ? 0 : 16)
+                        );
+                put_byte(s, (Byte)(s->gzhead->time & 0xff));
+                put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
+                put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
+                put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
+                put_byte(s, s->level == 9 ? 2 :
+                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+                             4 : 0));
+                put_byte(s, s->gzhead->os & 0xff);
+                if (s->gzhead->extra != Z_NULL) {
+                    put_byte(s, s->gzhead->extra_len & 0xff);
+                    put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
+                }
+                if (s->gzhead->hcrc)
+                    strm->adler = crc32(strm->adler, s->pending_buf,
+                                        s->pending);
+                s->gzindex = 0;
+                s->status = EXTRA_STATE;
+            }
+        }
+        else
+#endif
+        {
+            uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+            uInt level_flags;
+
+            if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+                level_flags = 0;
+            else if (s->level < 6)
+                level_flags = 1;
+            else if (s->level == 6)
+                level_flags = 2;
+            else
+                level_flags = 3;
+            header |= (level_flags << 6);
+            if (s->strstart != 0) header |= PRESET_DICT;
+            header += 31 - (header % 31);
+
+            s->status = BUSY_STATE;
+            putShortMSB(s, header);
+
+            /* Save the adler32 of the preset dictionary: */
+            if (s->strstart != 0) {
+                putShortMSB(s, (uInt)(strm->adler >> 16));
+                putShortMSB(s, (uInt)(strm->adler & 0xffff));
+            }
+            strm->adler = adler32(0L, Z_NULL, 0);
+        }
+    }
+#ifdef GZIP
+    if (s->status == EXTRA_STATE) {
+        if (s->gzhead->extra != Z_NULL) {
+            uInt beg = s->pending;  /* start of bytes to update crc */
+
+            while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
+                if (s->pending == s->pending_buf_size) {
+                    if (s->gzhead->hcrc && s->pending > beg)
+                        strm->adler = crc32(strm->adler, s->pending_buf + beg,
+                                            s->pending - beg);
+                    flush_pending(strm);
+                    beg = s->pending;
+                    if (s->pending == s->pending_buf_size)
+                        break;
+                }

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



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