socsvn commit: r255937 - in soc2013/dpl/head/lib/libzcap: . zlibworker
dpl at FreeBSD.org
dpl at FreeBSD.org
Wed Aug 14 17:01:17 UTC 2013
Author: dpl
Date: Wed Aug 14 17:01:17 2013
New Revision: 255937
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255937
Log:
Adapted many functions to be executed on the worker.
We now have to finish adapting all the left funtions and adapt the worker functions.
Modified:
soc2013/dpl/head/lib/libzcap/commands.c
soc2013/dpl/head/lib/libzcap/deflate.c
soc2013/dpl/head/lib/libzcap/infback.c
soc2013/dpl/head/lib/libzcap/inflate.c
soc2013/dpl/head/lib/libzcap/inftrees.c
soc2013/dpl/head/lib/libzcap/zlibworker/comands.c
soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
soc2013/dpl/head/lib/libzcap/zutil.c
Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c Wed Aug 14 16:15:14 2013 (r255936)
+++ soc2013/dpl/head/lib/libzcap/commands.c Wed Aug 14 17:01:17 2013 (r255937)
@@ -1,130 +1,803 @@
/*
- This is just a template of the capsicumized functions.
+ * Here live the capsicumed functions of this library.
+ */
+
+#include "zlib.h"
+#include "capsicum.c"
+#include "commands.h"
+
+#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);
+uLong zcapcmd_zlibCompileFlags(void);
+
+/* 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);
+int zcapcmd_gzungetc(int c, gzFile file);
+int zcapcmd_gzflush(gzFile file, int flush);
+z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence);
+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);
+uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2);
+
+extern pid_t pid;
+extern nvlist_t *sendCommand(nvlist_t *);
+extern void * data;
+
+nvlist_t *nvl, *args, *result;
+size_t gzfilesize = sizeof(struct gzFile_s);
+size_t gzheadersize = sizeof(struct gz_header_s);
+size_t zstreamsize = sizeof(z_stream);
+
+void checkChild(void) {
+ if (pid == 0)
+ startChild();
+}
+
+void
+destroy(void) {
+ nvlist_destroy(nvl);
+ nvlist_destroy(args);
+ nvlist_destroy(result);
+}
+
+int
+zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits,
+ int memLevel, int strategy, const char * version, int stream_size)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ /* No worries here */
+ 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. */
+ /* Supposing there's already space reserved for z_stream */
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateEnd(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ /* Supposing there's already space reserved for z_stream */
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateInit(z_streamp strm, int windowBits,
+ const char *version, int stream_size)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ /* No worries here */
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ 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);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateEnd(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+/* Advanced functions */
+int
+zcapcmd_deflateSetDictionary(z_streamp strm,
+ const Bytef *dictionary, uInt dictLength)
+{
+ /* XXX */
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateGetDictionary(z_streamp strm,
+ const Bytef *dictionary, uInt *dictLength)
+{
+ /* XXX */
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateCopy(z_streamp dest, z_streamp source)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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 *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateReset(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ /* Save the reseted strm. */
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateParams(z_streamp strm, int level, int int strategy)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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, "strm", *strm, zstreamsize);
+ nvlist_add_number(args, "level", level);
+ nvlist_add_number(args, "strategy", strategy);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ /* Overwrite the old streamp */
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy,
+ int nice_length, int max_chain)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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, "strm", *strm, zstreamsize);
+ nvlist_add_number(args, "good_length", good_length);
+ nvlist_add_number(args, "max_lazy", max_lazy);
+ nvlist_add_number(args, "nice_length", nice_length);
+ nvlist_add_number(args, "max_chain", max_chain);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateBound(z_streamp strm, uLong sourceLen)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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, "strm", *strm, zstreamsize);
+ nvlist_add_number(args, "sourceLen", sourceLen);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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, "strm", *strm, zstreamsize);
+ /* Will get malloc()ed at the worker. */
+ nvlist_add_number(args, "pending", *pending);
+ nvlist_add_number(args, "bits", *bits);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflatePrime(z_streamp strm, int bits, int value)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_number(args, "bits", bits);
+ nvlist_add_number(args, "value", value);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head)
+{
+ /* XXX: Beware of gz_headerp extra */
+ /* What happens with header->extra??? */
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_binary(args, "head", *head, gzheadersize);
+ nvlist_add_string(nvl, "name", head->name);
+ nvlist_add_string(nvl, "comment", head->comment);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateSetDictionary(z_streamp strm,
+ const Bytef *dictionary, uInt dictLength)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateSync(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateCopy(z_streamp dest, z_streamp source)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ 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 *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflateReset(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
+ return(ret);
+}
-datatype
-zcapcmd_function( real func args )
+int
+zcapcmd_inflateReset2(z_streamp strm, int windowBits)
{
- nvlist_t *nvl, *args, *result;
- datatype ret;
+ uLong ret;
+ zstream * dataplace;
- if (pid == 0)
- startChild();
+ checkChild();
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
- 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_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_number(nvl, "windowBits", windowBits);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_datatypenvl(result, "result")
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
+ return(ret);
+}
+
+int
+zcapcmd_inflatePrime(z_streamp strm, int bits, int value)
+{
+ uLong ret;
+ zstream * dataplace;
- nvlist_destroy(args);
- nvlist_destroy(nvl);
- nvlist_destroy(result);
+ checkChild();
+
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_number(args, "bits", bits);
+ nvlist_add_number(args, "value", value);
+ nvlist_add_nvlist(nvl, "args", args);
+
+ result = sendCommand(nvl);
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
return(ret);
}
-*/
+long
+zcapcmd_inflateMark(z_streamp strm)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
-#include "zlib.h"
-#include "capsicum.c"
-#include "commands.h"
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_nvlist(nvl, "args", args);
-#include <string.h>
+ result = sendCommand(nvl);
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
+ return(ret);
+}
-/* 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);
+int
+zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head)
+{
+ /* XXX: Beware of gz_headerp extra */
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
-/* 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);
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
+ nvlist_add_binary(args, "head", *head, gzheadersize);
+ nvlist_add_nvlist(nvl, "args", args);
-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);
+ result = sendCommand(nvl);
-/* Utility functions */
-uLong zcapcmd_compressBound(uLong sourceLen);
+ ret = nvlist_take_number(result, "result");
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ gz_headerp newhead = nvlist_take_binary(result, "newhead", gzheadersize);
+ head->done = newhead->done;
+ destroy();
+ return(ret);
+}
-/* 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);
-int zcapcmd_gzungetc(int c, gzFile file);
-int zcapcmd_gzflush(gzFile file, int flush);
-z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence);
-int zcapcmd_simplecommand(gzFile file, int command);
-char * zcapcmd_gzerror(gzFile file, int *errnum);
+uLong
+zcapcmd_zlibCompileFlags(z_streamp strm, gz_headerp head)
+{
+ uLong ret;
+ zstream * dataplace;
+
+ checkChild();
-/* 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);
-uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2);
+ if( (args = nvlist_create(0)) == NULL ||
+ (nvl = nvlist_create(0)) == NULL ) {
+ perror("nvlist_create");
+ return(0);
+ }
+ nvlist_add_number(nvl, "command", ZCAPCMD_ZLIBCOMPILEFLAGS);
+ nvlist_add_nvlist(nvl, "args", args);
-extern pid_t pid;
-extern nvlist_t *sendCommand(nvlist_t *);
-extern void * data;
+ result = sendCommand(nvl);
-size_t gzFilesize = sizeof(struct gzFile_s);
-size_t zstreamsize = sizeof(z_stream);
+ ret = nvlist_take_number(result, "result");
+ destroy();
+ return(ret);
+}
-uLong
-zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits,
- int memLevel, int strategy, const char * version,
- int stream_size)
+int
+zcapcmd_inflateBackInit(z_streamp strm, int windowBits, unsigned char *window
+ const char *version, int stream_size)
{
- nvlist_t *nvl, *args, *result;
+ /* window has to be a pointer to at least a 32kb buffer */
uLong ret;
zstream * dataplace;
- if (pid == 0)
- startChild();
+ checkChild();
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
@@ -132,12 +805,9 @@
return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ /* No worries here */
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);
@@ -145,89 +815,74 @@
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);
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ char *msg = nvlist_take_string(result, "msg");
+ memcpy(strm->msg, msg, strlen(msg)+1);
+ destroy();
return(ret);
}
int
-zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
+zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc,
+ out_func out, void *out_desc)
{
- nvlist_t *nvl, *args, *result;
uLong ret;
zstream * dataplace;
- if (pid == 0)
- startChild();
+ checkChild();
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_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
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);
+ z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize);
+ memcpy(strm, newstrm, zstreamsize);
+ destroy();
return(ret);
}
int
-zcapcmd_deflateCopy(z_streamp dest, z_streamp source)
+zcapcmd_inflateBackEnd(z_streamp strm)
{
- nvlist_t *nvl, *args, *result;
uLong ret;
zstream * dataplace;
- if (pid == 0)
- startChild();
+ checkChild();
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_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+ nvlist_add_binary(args, "strm", *strm, zstreamsize);
nvlist_add_nvlist(nvl, "args", args);
- /* The two z_streamp are now copied at the worker. */
result = sendCommand(nvl);
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-soc-all
mailing list