socsvn commit: r256157 - in soc2013/dpl/head/lib/libzcap: . test zlibworker

dpl at FreeBSD.org dpl at FreeBSD.org
Mon Aug 19 16:40:11 UTC 2013


Author: dpl
Date: Mon Aug 19 16:40:10 2013
New Revision: 256157
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256157

Log:
  Updated version. Things start to work.
  

Added:
  soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c
Deleted:
  soc2013/dpl/head/lib/libzcap/test/functionstest.c
  soc2013/dpl/head/lib/libzcap/zlib.3
Modified:
  soc2013/dpl/head/lib/libzcap/capsicum.c
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/deflate.c
  soc2013/dpl/head/lib/libzcap/gzlib.c
  soc2013/dpl/head/lib/libzcap/inflate.c
  soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c

Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -12,7 +12,7 @@
 
 #define SUM 0
 
-pid_t pid  = 0;
+pid_t pid = 0;
 int sv[2];
 
 int startChild(void);
@@ -23,28 +23,32 @@
 startChild(void)
 {
 	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 )
-		perror("socketpair");
+		perror("zcaplib: socketpair");
 
 	if( (pid = fork()) == 0 ){
-		close(STDIN_FILENO);
+		cap_rights_limit(STDIN_FILENO, CAP_WRITE);
 		cap_rights_limit(STDOUT_FILENO, CAP_READ);
 		cap_rights_limit(STDERR_FILENO, CAP_WRITE);
 
-		dup(sv[1]); /* 3 is now the socket */
 		close(sv[0]);
-		close(sv[1]);
+		dup2(sv[1] , 3); /* 3 is now the socket */
+		close(4);
 		
-		/* open and fexec() listener */
+		/* open and execl() 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");
+			perror("zcaplib: zlibworker:");
 			exit (-1);
 		}
 	
-		execl("/usr/libexec/zlibworker", "");
+		if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) <0 ) {
+			perror("zcaplib: zlibworker:");
+			exit (-1);
+		}
 		exit(0);
-	} else
+	} else {
+		close(sv[1]);
 		atexit(killChild);
+	}
 
 	return pid;
 }
@@ -53,21 +57,19 @@
 sendCommand( nvlist_t *nvl )
 {
 	if( nvlist_send(sv[0], nvl) != 0 ) {
-		perror("nvlist_send()");
+		perror("zcaplib: nvlist_send()");
 		return NULL;
 	}
-	nvlist_destroy(nvl);
 
 	/* recv results */
-	if ((nvl = nvlist_recv(sv[0])) != NULL) {
-		perror("nvlist_send()");
+	if ((nvl = nvlist_recv(sv[0])) == NULL) {
+		perror("zcaplib: nvlist_recv()");
 		return NULL;
 	}
-	printf("done sending/recving\n");
 
 	return (nvl);
 }
 
-void killChild(void){
+void killChild(void) {
 	kill(pid, SIGKILL);
 }
\ No newline at end of file

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -113,7 +113,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -154,7 +154,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -181,7 +181,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -208,7 +208,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -239,7 +239,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -265,7 +265,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
@@ -293,7 +293,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETDICTIONARY);
@@ -319,7 +319,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY);
@@ -346,7 +346,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATERESET);
@@ -374,7 +374,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPARAMS);
@@ -403,7 +403,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATETUNE);
@@ -432,7 +432,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEBOUND);
@@ -458,7 +458,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPENDING);
@@ -486,7 +486,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME);
@@ -515,7 +515,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER);
@@ -544,7 +544,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY);
@@ -570,7 +570,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETDICTIONARY);
@@ -595,7 +595,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESYNC);
@@ -620,7 +620,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATECOPY);
@@ -647,7 +647,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET);
@@ -674,7 +674,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET2);
@@ -702,7 +702,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEPRIME);
@@ -729,7 +729,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEMARK);
@@ -755,7 +755,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETHEADER);
@@ -785,7 +785,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKINIT);
@@ -815,7 +815,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACK);
@@ -840,7 +840,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKEND);
@@ -865,12 +865,13 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_ZLIBCOMPILEFLAGS);
 
 	result = sendCommand(nvl);
+	printf("after sendCommand()\n");
 
 	ret = nvlist_take_number(result, "result");
 	destroy();
@@ -887,7 +888,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_COMPRESSBOUND);
@@ -910,7 +911,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return (NULL);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZOPEN);
@@ -937,7 +938,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZBUFFER);
@@ -960,7 +961,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZSETPARAMS);
@@ -985,7 +986,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZREAD);
@@ -1009,7 +1010,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZWRITE);
@@ -1032,7 +1033,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPRINTF);
@@ -1055,7 +1056,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTS);
@@ -1078,7 +1079,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return (NULL);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZGETS);
@@ -1105,7 +1106,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
@@ -1128,7 +1129,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZUNGETC);
@@ -1151,7 +1152,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZFLUSH);
@@ -1174,7 +1175,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZSEEK);
@@ -1202,7 +1203,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", command);
@@ -1224,7 +1225,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
@@ -1250,7 +1251,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32);
@@ -1274,7 +1275,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32_COMBINE);
@@ -1298,7 +1299,7 @@
 	checkChild();
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_CRC32);
@@ -1323,7 +1324,7 @@
 
 	if( (args = nvlist_create(0)) == NULL ||
 		(nvl = nvlist_create(0)) == NULL ) {
-		perror("nvlist_create");
+		perror("zcaplib: nvlist_create");
 		return(0);
 	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_CRC32_COMBINE);

Modified: soc2013/dpl/head/lib/libzcap/deflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/deflate.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/deflate.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -3,50 +3,6 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/*
- *  ALGORITHM
- *
- *      The "deflation" process depends on being able to identify portions
- *      of the input text which are identical to earlier input (within a
- *      sliding window trailing behind the input currently being processed).
- *
- *      The most straightforward technique turns out to be the fastest for
- *      most input files: try all possible matches and select the longest.
- *      The key feature of this algorithm is that insertions into the string
- *      dictionary are very simple and thus fast, and deletions are avoided
- *      completely. Insertions are performed at each input character, whereas
- *      string matches are performed only when the previous match ends. So it
- *      is preferable to spend more time in matches to allow very fast string
- *      insertions and avoid deletions. The matching algorithm for small
- *      strings is inspired from that of Rabin & Karp. A brute force approach
- *      is used to find longer strings when a small match has been found.
- *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
- *      (by Leonid Broukhis).
- *         A previous version of this file used a more sophisticated algorithm
- *      (by Fiala and Greene) which is guaranteed to run in linear amortized
- *      time, but has a larger average cost, uses more memory and is patented.
- *      However the F&G algorithm may be faster for some highly redundant
- *      files if the parameter max_chain_length (described below) is too large.
- *
- *  ACKNOWLEDGEMENTS
- *
- *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
- *      I found it in 'freeze' written by Leonid Broukhis.
- *      Thanks to many people for bug reports and testing.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- *      Available in http://tools.ietf.org/html/rfc1951
- *
- *      A description of the Rabin and Karp algorithm is given in the book
- *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
- *
- *      Fiala,E.R., and Greene,D.H.
- *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
- *
- */
-
 /* @(#) $Id$ */
 
 #include "deflate.h"
@@ -79,6 +35,10 @@
     const char *version;
     int stream_size;
 {
+	/* The other process can't use this process functions. */
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateInit(strm, level, method, windowBits,
                                memLevel, strategy, version, stream_size);
 }
@@ -90,6 +50,9 @@
     const Bytef *dictionary;
     uInt  dictLength;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	int ret = 0;
 	/* We can send all the dictionary data, but it doesn't seem a good idea. */
 	/* We also can send the last 5kb, but that would make the lib slower. */
@@ -110,6 +73,9 @@
 int ZEXPORT deflateReset (strm)
     z_streamp strm;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateReset(strm);
 }
 
@@ -119,6 +85,9 @@
     z_streamp strm;
     gz_headerp head;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateSetHeader(strm, head);
 }
 
@@ -129,6 +98,9 @@
     unsigned *pending;
     int *bits;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflatePending(strm, pending, bits);
 }
 
@@ -139,6 +111,9 @@
     int bits;
     int value;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflatePrime(strm, bits, value);
 }
 
@@ -149,6 +124,9 @@
     int level;
     int strategy;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateParams(strm, level, strategy);
 }
 
@@ -161,6 +139,9 @@
     int nice_length;
     int max_chain;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateTune(strm, good_length, max_lazy, nice_length, max_chain);
 }
 
@@ -170,6 +151,9 @@
     z_streamp strm;
     uLong sourceLen;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateBound(strm, sourceLen);
 }
 
@@ -179,6 +163,9 @@
     z_streamp strm;
     int flush;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflate(strm, flush);
 }
 
@@ -187,7 +174,9 @@
 int ZEXPORT deflateEnd (strm)
     z_streamp strm;
 {
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_deflateEnd(strm);
 }
 
@@ -197,6 +186,12 @@
     z_streamp dest;
     z_streamp source;
 {
+	dest->zalloc = Z_NULL;
+	dest->zfree = Z_NULL;
+	dest->opaque = Z_NULL;
+	source->zalloc = Z_NULL;
+	source->zfree = Z_NULL;
+	source->opaque = Z_NULL;
 #ifdef MAXSEG_64K
     return Z_STREAM_ERROR;
 #else

Modified: soc2013/dpl/head/lib/libzcap/gzlib.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzlib.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/gzlib.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -68,7 +68,7 @@
 #endif
 
 	if ((fd = open(path, oflag)) < 0) {
-		perror("Couldn't open");
+		perror("zcaplib: Couldn't open");
 		abort();
 	}
 		

Modified: soc2013/dpl/head/lib/libzcap/inflate.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/inflate.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/inflate.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -29,6 +29,9 @@
     const char *version;
     int stream_size;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateInit(strm, windowBits, version, stream_size);
 }
 
@@ -36,6 +39,9 @@
 int ZEXPORT inflateEnd(strm)
     z_streamp strm;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateEnd(strm);
 }
 
@@ -46,6 +52,9 @@
     uInt dictLength;
 {
 	/* XXX This ain't working yet. */
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateSetDictionary(strm, dictionary, dictLength);
 }
 
@@ -56,6 +65,9 @@
     uInt *dictLength;
 {
 	/* XXX This ain't working yet. */
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateGetDictionary(strm, dictionary, dictLength);
 }
 
@@ -63,6 +75,9 @@
 int ZEXPORT inflateSync(strm)
     z_streamp strm;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateSync(strm);
 }
 
@@ -71,6 +86,12 @@
     z_streamp dest;
     z_streamp source;
 {
+	dest->zalloc = Z_NULL;
+	dest->zfree = Z_NULL;
+	dest->opaque = Z_NULL;
+	source->zalloc = Z_NULL;
+	source->zfree = Z_NULL;
+	source->opaque = Z_NULL;
 	return zcapcmd_inflateCopy(dest, source);
 }
 
@@ -78,6 +99,9 @@
 int ZEXPORT inflateReset(strm)
     z_streamp strm;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
     return zcapcmd_inflateReset(strm);
 }
 
@@ -86,6 +110,9 @@
     z_streamp strm;
     int windowBits;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
     return zcapcmd_inflateReset2(strm, windowBits);
 }
 
@@ -95,6 +122,9 @@
     int bits;
     int value;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflatePrime(strm, bits, value);
 }
 
@@ -102,6 +132,9 @@
 long ZEXPORT inflateMark(strm)
     z_streamp strm;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return zcapcmd_inflateMark(strm);
 }
 
@@ -111,7 +144,10 @@
     gz_headerp head;
 {
 	/* XXX Do I really have to compartmentalize this??? */
-    struct inflate_state FAR *state;
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
+   struct inflate_state FAR *state;
 
     /* check state */
     if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
@@ -128,5 +164,8 @@
     z_streamp strm;
     int flush;
 {
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
 	return -1;
 }

Added: soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -0,0 +1,149 @@
+#include <zlib.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void testzlibVersion(void);
+void testdeflateInit(z_streamp strm);
+void testdeflateEnd(z_streamp strm);
+void testinflateInit(z_streamp strm);
+void testinflateEnd(z_streamp strm);
+
+void testzlibCompileFlags(void);
+
+void testCompressBound(void);
+
+void testchecksums(void);
+
+int i;
+char *data;
+z_streamp strm;
+
+int
+main() {
+
+	if ( (strm = malloc(sizeof (z_stream))) == NULL) {
+		printf("zcaplibtest: malloc()");
+		abort();
+	}
+
+	if ( (data = malloc(10*1024)) == NULL) {
+		printf("zcaplibtest: malloc()");
+		abort();
+	}
+
+	for (i=0; i<(10*1024); i++) {
+		data[i] = rand();
+	}
+
+	printf("This is a zcaplib program tester.\n");
+	printf("I will now test all the zcaplib functions.\n\n");
+
+/*	testdeflateInit(strm);*/
+/*	testdeflateEnd(strm);*/
+/*	testinflateInit(strm);*/
+/*	testinflateEnd(strm);*/
+
+	testzlibCompileFlags();
+/*	testCompressBound();*/
+
+	testchecksums();
+	return 0;
+}
+
+void
+testdeflateInit(z_streamp strm)
+{
+	printf("deflateInit()\t...\t");
+
+	return;
+}
+
+void
+testdeflateEnd(z_streamp strm)
+{
+	printf("deflateEnd()\t...\t");
+
+	return;
+}
+
+void
+testinflateInit(z_streamp strm)
+{
+	printf("inflateInit()\t...\t");
+
+	return;
+}
+
+void
+testinflateEnd(z_streamp strm)
+{
+	printf("inflateEnd()\t...\t");
+
+	return;
+}
+
+void
+testzlibCompileFlags(void)
+{
+	uLong ret = 0;
+	printf("zlibCompileFlags()\t...\t");
+
+	if ( (ret = zlibCompileFlags()) > 0)
+		printf("OK\n");
+	else
+		printf("Error\n");
+	printf("zlibCompileFlags: %lu\n", ret);
+	
+	return;
+}
+
+void
+testCompressBound(void)
+{
+	printf("compressBound()\t...\t");
+	return;
+}
+
+void
+testchecksums(void)
+{
+	long data[2];
+
+	uLong first = 0;
+	uLong second = 0;
+	uLong all = 0;
+	uLong combined = 0;
+	int lsize = sizeof(long);
+
+	data[0] = random();
+	data[1] = random();
+
+	first = adler32(0, (void *)data, sizeof(long));
+	printf("adler32(0, %ld, %d): %ld\n", data[0], sizeof(long), first );
+
+	printf("adler32\t...\t");
+	if (first != 0)
+		printf("OK\n");
+	else
+		printf("Error\n");
+
+	second = adler32(0, (void *)(data+lsize), sizeof(long));
+	printf("adler32(0, %ld, %d): %ld\n", data[1], sizeof(long), second );
+
+	combined = adler32_combine(first, second, sizeof(long));
+	printf("adler32_combine(%ld, %ld, %d): %ld\n", first, second, sizeof(long), combined );
+
+	all = adler32(0L, (void *)data, 2*sizeof(long));
+	printf("adler32(0, %ld, %d): %ld\n", data[0], 2*sizeof(long), all );
+
+
+	printf("adler32_combine()\t...\t");
+	if (all == combined)
+		printf("OK\n");
+	else
+		printf("Error\n");
+
+
+	return;
+}
\ No newline at end of file

Modified: soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/commands.c	Mon Aug 19 15:58:39 2013	(r256156)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/commands.c	Mon Aug 19 16:40:10 2013	(r256157)
@@ -19,7 +19,7 @@
 
 	if ((args = nvlist_take_nvlist(nvl, "args")) == NULL) {
 		memcpy(stream,
-               nvlist_take_binary(args, "strm", &zstreamsize), zstreamsize);
+		nvlist_take_binary(args, "strm", &zstreamsize), zstreamsize);
 		ret = deflateInit2_(stream,
 		 		nvlist_take_number(args, "level"),
 		 		nvlist_take_number(args, "method"),
@@ -255,9 +255,9 @@
 {
 	int ret = -1;
 	int len = 0;
-	void * data;
+	void * data = NULL;
 
-	if ((args = nvlist_take_nvlist(nvl, "args")) != NULL)
+	if ((args = nvlist_take_nvlist(nvl, "args")) != NULL) {
 		len = nvlist_take_number(args, "len");

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


More information about the svn-soc-all mailing list