You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/17 09:09:26 UTC
svn commit: r804880 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.in Makefile.msc.in srclib/zlib/zdeflate.c srclib/zlib/zdeflate.h
Author: mturk
Date: Mon Aug 17 07:09:26 2009
New Revision: 804880
URL: http://svn.apache.org/viewvc?rev=804880&view=rev
Log:
Add deflate_global from OpenBSD sys/crypto
Added:
commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c (with props)
commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=804880&r1=804879&r2=804880&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Mon Aug 17 07:09:26 2009
@@ -207,6 +207,7 @@
$(SRCDIR)/srclib/zlib/inftrees.$(OBJ) \
$(SRCDIR)/srclib/zlib/trees.$(OBJ) \
$(SRCDIR)/srclib/zlib/uncompr.$(OBJ) \
+ $(SRCDIR)/srclib/zlib/zdeflate.$(OBJ) \
$(SRCDIR)/srclib/zlib/zutil.$(OBJ)
OPENSSL_OBJS=\
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=804880&r1=804879&r2=804880&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Aug 17 07:09:26 2009
@@ -129,6 +129,7 @@
$(SRCDIR)/srclib/zlib/inftrees.$(OBJ) \
$(SRCDIR)/srclib/zlib/trees.$(OBJ) \
$(SRCDIR)/srclib/zlib/uncompr.$(OBJ) \
+ $(SRCDIR)/srclib/zlib/zdeflate.$(OBJ) \
$(SRCDIR)/srclib/zlib/zutil.$(OBJ)
OPENSSL_OBJS=\
Added: commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c?rev=804880&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c Mon Aug 17 07:09:26 2009
@@ -0,0 +1,197 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org)
+ *
+ */
+
+/*
+ * This file contains a wrapper around the deflate algo compression
+ * functions using the zlib library (see net/zlib.{c,h})
+ */
+
+#include "zlib/zlib.h"
+#include "zlib/zutil.h"
+#include "zlib/zdeflate.h"
+
+#define Z_METHOD 8
+#define Z_MEMLEVEL 8
+#define ZBUF 10
+
+int window_inflate = -1 * MAX_WBITS;
+int window_deflate = -12;
+
+struct deflate_buf {
+ Byte *out;
+ uInt size;
+ int flag;
+};
+
+/*
+ * This function takes a block of data and (de)compress it using the deflate
+ * algorithm
+ */
+
+uInt
+acr_z_deflate_global(Byte *data, uInt size, int comp, Byte **out)
+{
+ /* comp indicates whether we compress (0) or decompress (1) */
+
+ z_stream zbuf;
+ Byte *output;
+ uInt count, result;
+ int error, i = 0, j;
+ struct deflate_buf buf[ZBUF];
+
+ memset(&zbuf, 0, sizeof(z_stream));
+ for (j = 0; j < ZBUF; j++)
+ buf[j].flag = 0;
+
+ zbuf.next_in = data; /* data that is going to be processed */
+ zbuf.zalloc = Z_NULL;
+ zbuf.zfree = Z_NULL;
+ zbuf.opaque = Z_NULL;
+ zbuf.avail_in = size; /* Total length of data to be processed */
+
+ if (comp == 0) {
+ buf[i].out = malloc((size_t)size);
+ if (buf[i].out == NULL) {
+ error = errno;
+ goto bad;
+ }
+ buf[i].size = size;
+ buf[i].flag = 1;
+ i++;
+ }
+ else {
+ /*
+ * Choose a buffer with 4x the size of the input buffer
+ * for the size of the output buffer in the case of
+ * decompression. If it's not sufficient, it will need to be
+ * updated while the decompression is going on
+ */
+ buf[i].out = malloc((size_t)(size * 4));
+ if (buf[i].out == NULL) {
+ error = errno;
+ goto bad;
+ }
+ buf[i].size = size * 4;
+ buf[i].flag = 1;
+ i++;
+ }
+
+ zbuf.next_out = buf[0].out;
+ zbuf.avail_out = buf[0].size;
+
+ error = comp ? inflateInit2(&zbuf, window_inflate) :
+ deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD,
+ window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY);
+
+ if (error != Z_OK)
+ goto bad;
+ for (;;) {
+ error = comp ? inflate(&zbuf, Z_PARTIAL_FLUSH) :
+ deflate(&zbuf, Z_PARTIAL_FLUSH);
+ if (error != Z_OK && error != Z_STREAM_END)
+ goto bad;
+ else if (zbuf.avail_in == 0 && zbuf.avail_out != 0)
+ goto end;
+ else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) {
+ /* we need more output space, allocate size */
+ buf[i].out = malloc((size_t)size);
+ if (buf[i].out == NULL) {
+ error = errno;
+ goto bad;
+ }
+ zbuf.next_out = buf[i].out;
+ buf[i].size = size;
+ buf[i].flag = 1;
+ zbuf.avail_out = buf[i].size;
+ i++;
+ }
+ else {
+ error = ENOSPC;
+ goto bad;
+ }
+ }
+
+end:
+ result = count = zbuf.total_out;
+
+ *out = malloc((size_t)result);
+ if (*out == NULL) {
+ error = errno;
+ goto bad;
+ }
+ if (comp)
+ inflateEnd(&zbuf);
+ else
+ deflateEnd(&zbuf);
+ output = *out;
+ for (j = 0; buf[j].flag != 0; j++) {
+ if (count > buf[j].size) {
+ memcpy(*out, buf[j].out, buf[j].size);
+ *out += buf[j].size;
+ free(buf[j].out);
+ count -= buf[j].size;
+ }
+ else {
+ /* it should be the last buffer */
+ memcpy(*out, buf[j].out, count);
+ *out += count;
+ free(buf[j].out);
+ count = 0;
+ }
+ }
+ *out = output;
+ return result;
+
+bad:
+ *out = NULL;
+ for (j = 0; buf[j].flag != 0; j++)
+ free(buf[j].out);
+ if (comp)
+ inflateEnd(&zbuf);
+ else
+ deflateEnd(&zbuf);
+ if (error < 0) {
+ switch (error) {
+ case Z_STREAM_ERROR:
+ errno = EBADF;
+ break;
+ case Z_DATA_ERROR:
+ errno = EILSEQ;
+ break;
+ case Z_MEM_ERROR:
+ errno = ENOMEM;
+ break;
+ case Z_BUF_ERROR:
+ errno = ENOSPC;
+ break;
+ case Z_VERSION_ERROR:
+ errno = EINVAL;
+ break;
+ default:
+ errno = EFAULT;
+ break;
+ }
+ }
+ else
+ errno = error;
+ return 0;
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h?rev=804880&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h Mon Aug 17 07:09:26 2009
@@ -0,0 +1,44 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org)
+ *
+ */
+
+/*
+ * Definition for the wrapper around the deflate compression
+ * algorithm
+ */
+
+#ifndef _ZDEFLATE_H_
+#define _ZDEFLATE_H_
+
+#include "zlib/zlib.h"
+
+/**
+ * This function takes a block of data and (de)compress it using the deflate
+ * algorithm.
+ * @param in Input data to compress/decompress
+ * @param size Inmput data length
+ * @param comp Indicates whether we compress (0) or decompress (1)
+ * @param out Output data buffer. Use free() when data is no longer needed.
+ * @return Output data length or 0 on failure.
+ */
+uInt acr_z_deflate_global(Byte *in, uInt size, int comp, Byte **out);
+
+#endif /* _ZDEFLATE_H_ */
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/srclib/zlib/zdeflate.h
------------------------------------------------------------------------------
svn:eol-style = native