aboutsummaryrefslogtreecommitdiff
path: root/dep
diff options
context:
space:
mode:
Diffstat (limited to 'dep')
-rw-r--r--dep/PackageList.txt12
-rw-r--r--dep/bzip2/LICENSE42
-rw-r--r--dep/bzip2/README215
-rw-r--r--dep/bzip2/blocksort.c4
-rw-r--r--dep/bzip2/bzip2.c2034
-rw-r--r--dep/bzip2/bzip2recover.c514
-rw-r--r--dep/bzip2/bzlib.c4
-rw-r--r--dep/bzip2/bzlib.h4
-rw-r--r--dep/bzip2/bzlib_private.h6
-rw-r--r--dep/bzip2/compress.c4
-rw-r--r--dep/bzip2/crctable.c4
-rw-r--r--dep/bzip2/decompress.c24
-rw-r--r--dep/bzip2/huffman.c4
-rw-r--r--dep/bzip2/randtable.c4
-rw-r--r--dep/g3dlite/include/G3D/AABox.h3
-rw-r--r--dep/g3dlite/include/G3D/Any.h125
-rw-r--r--dep/g3dlite/include/G3D/PointHashGrid.h6
-rw-r--r--dep/g3dlite/include/G3D/Quat.inl36
-rw-r--r--dep/g3dlite/include/G3D/Sphere.h1
-rw-r--r--dep/g3dlite/include/G3D/Table.h5
-rw-r--r--dep/g3dlite/include/G3D/Vector2.inl18
-rw-r--r--dep/g3dlite/include/G3D/Vector3.inl249
-rw-r--r--dep/g3dlite/include/G3D/Vector4.inl191
-rw-r--r--dep/g3dlite/include/G3D/g3dmath.inl288
-rw-r--r--dep/g3dlite/include/G3D/platform.h4
-rw-r--r--dep/g3dlite/source/AABox.cpp4
-rw-r--r--dep/g3dlite/source/Log.cpp14
-rw-r--r--dep/g3dlite/source/RegistryUtil.cpp2
-rw-r--r--dep/g3dlite/source/System.cpp95
-rw-r--r--dep/g3dlite/source/TextInput.cpp28
-rw-r--r--dep/g3dlite/source/g3dmath.cpp2
-rw-r--r--dep/gsoap/gsoap.stub1
-rw-r--r--dep/gsoap/soapC.cpp97
-rw-r--r--dep/gsoap/soapH.h11
-rw-r--r--dep/gsoap/soapServer.cpp14
-rw-r--r--dep/gsoap/soapStub.h15
-rw-r--r--dep/gsoap/stdsoap2.cpp1672
-rw-r--r--dep/gsoap/stdsoap2.h248
-rw-r--r--dep/gsoap/tc_upgrades.txt12
-rw-r--r--dep/utf8cpp/utf8/checked.h118
-rw-r--r--dep/utf8cpp/utf8/core.h209
-rw-r--r--dep/utf8cpp/utf8/unchecked.h44
-rw-r--r--dep/zlib/adler32.c68
-rw-r--r--dep/zlib/crc32.c83
-rw-r--r--dep/zlib/crc32.h2
-rw-r--r--dep/zlib/deflate.c259
-rw-r--r--dep/zlib/deflate.h10
-rw-r--r--dep/zlib/gzguts.h87
-rw-r--r--dep/zlib/gzlib.c165
-rw-r--r--dep/zlib/gzread.c418
-rw-r--r--dep/zlib/gzwrite.c146
-rw-r--r--dep/zlib/infback.c14
-rw-r--r--dep/zlib/inffixed.h6
-rw-r--r--dep/zlib/inflate.c90
-rw-r--r--dep/zlib/inftrees.c46
-rw-r--r--dep/zlib/trees.c40
-rw-r--r--dep/zlib/zconf.h196
-rw-r--r--dep/zlib/zlib.h309
-rw-r--r--dep/zlib/zutil.c24
-rw-r--r--dep/zlib/zutil.h98
60 files changed, 5753 insertions, 2695 deletions
diff --git a/dep/PackageList.txt b/dep/PackageList.txt
index 7744e9474c9..f9befe50710 100644
--- a/dep/PackageList.txt
+++ b/dep/PackageList.txt
@@ -6,15 +6,15 @@ ACE (ADAPTIVE Communication Environment)
bzip2 (a freely available, patent free, high-quality data compressor)
http://www.bzip.org/
- Version: 1.0.5
+ Version: 1.0.6
G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License)
http://g3d.sourceforge.net/
- Version: 8.0-Release
+ Version: 8.01-Release
jemalloc (a general-purpose scalable concurrent malloc-implementation)
http://www.canonware.com/jemalloc/
- Version: 2.2.5
+ Version: 2.1.0
libMPQ (a library for reading MPQ files)
https://libmpq.org/
@@ -30,15 +30,15 @@ SFMT (SIMD-oriented Fast Mersenne Twister)
utf8-cpp (UTF-8 with C++ in a Portable Way)
http://utfcpp.sourceforge.net/
- Version: 2.3
+ Version: 2.3.2
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
http://www.zlib.net/
- Version: 1.2.5
+ Version: 1.2.7
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
http://gsoap2.sourceforge.net/
- Version: 2.8.2
+ Version: 2.8.10
recastnavigation (Recast is state of the art navigation mesh construction toolset for games)
http://code.google.com/p/recastnavigation/
diff --git a/dep/bzip2/LICENSE b/dep/bzip2/LICENSE
new file mode 100644
index 00000000000..cc614178cf7
--- /dev/null
+++ b/dep/bzip2/LICENSE
@@ -0,0 +1,42 @@
+
+--------------------------------------------------------------------------
+
+This program, "bzip2", the associated library "libbzip2", and all
+documentation, are copyright (C) 1996-2010 Julian R Seward. All
+rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Julian Seward, jseward@bzip.org
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
+
+--------------------------------------------------------------------------
diff --git a/dep/bzip2/README b/dep/bzip2/README
new file mode 100644
index 00000000000..9fb0f636013
--- /dev/null
+++ b/dep/bzip2/README
@@ -0,0 +1,215 @@
+
+This is the README for bzip2/libzip2.
+This version is fully compatible with the previous public releases.
+
+------------------------------------------------------------------
+This file is part of bzip2/libbzip2, a program and library for
+lossless, block-sorting data compression.
+
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
+Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
+
+Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
+
+This program is released under the terms of the license contained
+in the file LICENSE.
+------------------------------------------------------------------
+
+Complete documentation is available in Postscript form (manual.ps),
+PDF (manual.pdf) or html (manual.html). A plain-text version of the
+manual page is available as bzip2.txt.
+
+
+HOW TO BUILD -- UNIX
+
+Type 'make'. This builds the library libbz2.a and then the programs
+bzip2 and bzip2recover. Six self-tests are run. If the self-tests
+complete ok, carry on to installation:
+
+To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
+/usr/local/include, type
+
+ make install
+
+To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
+
+ make install PREFIX=/xxx/yyy
+
+If you are (justifiably) paranoid and want to see what 'make install'
+is going to do, you can first do
+
+ make -n install or
+ make -n install PREFIX=/xxx/yyy respectively.
+
+The -n instructs make to show the commands it would execute, but not
+actually execute them.
+
+
+HOW TO BUILD -- UNIX, shared library libbz2.so.
+
+Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for
+Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims
+that it works for any other platform, though I suspect it probably
+will work for most platforms employing both ELF and gcc.
+
+bzip2-shared, a client of the shared library, is also built, but not
+self-tested. So I suggest you also build using the normal Makefile,
+since that conducts a self-test. A second reason to prefer the
+version statically linked to the library is that, on x86 platforms,
+building shared objects makes a valuable register (%ebx) unavailable
+to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
+
+Important note for people upgrading .so's from 0.9.0/0.9.5 to version
+1.0.X. All the functions in the library have been renamed, from (eg)
+bzCompress to BZ2_bzCompress, to avoid namespace pollution.
+Unfortunately this means that the libbz2.so created by
+Makefile-libbz2_so will not work with any program which used an older
+version of the library. I do encourage library clients to make the
+effort to upgrade to use version 1.0, since it is both faster and more
+robust than previous versions.
+
+
+HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
+
+It's difficult for me to support compilation on all these platforms.
+My approach is to collect binaries for these platforms, and put them
+on the master web site (http://www.bzip.org). Look there. However
+(FWIW), bzip2-1.0.X is very standard ANSI C and should compile
+unmodified with MS Visual C. If you have difficulties building, you
+might want to read README.COMPILATION.PROBLEMS.
+
+At least using MS Visual C++ 6, you can build from the unmodified
+sources by issuing, in a command shell:
+
+ nmake -f makefile.msc
+
+(you may need to first run the MSVC-provided script VCVARS32.BAT
+ so as to set up paths to the MSVC tools correctly).
+
+
+VALIDATION
+
+Correct operation, in the sense that a compressed file can always be
+decompressed to reproduce the original, is obviously of paramount
+importance. To validate bzip2, I used a modified version of Mark
+Nelson's churn program. Churn is an automated test driver which
+recursively traverses a directory structure, using bzip2 to compress
+and then decompress each file it encounters, and checking that the
+decompressed data is the same as the original.
+
+
+
+Please read and be aware of the following:
+
+WARNING:
+
+ This program and library (attempts to) compress data by
+ performing several non-trivial transformations on it.
+ Unless you are 100% familiar with *all* the algorithms
+ contained herein, and with the consequences of modifying them,
+ you should NOT meddle with the compression or decompression
+ machinery. Incorrect changes can and very likely *will*
+ lead to disastrous loss of data.
+
+
+DISCLAIMER:
+
+ I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
+ USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
+
+ Every compression of a file implies an assumption that the
+ compressed file can be decompressed to reproduce the original.
+ Great efforts in design, coding and testing have been made to
+ ensure that this program works correctly. However, the complexity
+ of the algorithms, and, in particular, the presence of various
+ special cases in the code which occur with very low but non-zero
+ probability make it impossible to rule out the possibility of bugs
+ remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
+ PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
+ SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
+
+ That is not to say this program is inherently unreliable.
+ Indeed, I very much hope the opposite is true. bzip2/libbzip2
+ has been carefully constructed and extensively tested.
+
+
+PATENTS:
+
+ To the best of my knowledge, bzip2/libbzip2 does not use any
+ patented algorithms. However, I do not have the resources
+ to carry out a patent search. Therefore I cannot give any
+ guarantee of the above statement.
+
+
+
+WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
+
+ * Approx 10% faster compression, 30% faster decompression
+ * -t (test mode) is a lot quicker
+ * Can decompress concatenated compressed files
+ * Programming interface, so programs can directly read/write .bz2 files
+ * Less restrictive (BSD-style) licensing
+ * Flag handling more compatible with GNU gzip
+ * Much more documentation, i.e., a proper user manual
+ * Hopefully, improved portability (at least of the library)
+
+WHAT'S NEW IN 0.9.5 ?
+
+ * Compression speed is much less sensitive to the input
+ data than in previous versions. Specifically, the very
+ slow performance caused by repetitive data is fixed.
+ * Many small improvements in file and flag handling.
+ * A Y2K statement.
+
+WHAT'S NEW IN 1.0.0 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.2 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.3 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.4 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.5 ?
+
+ See the CHANGES file.
+
+WHAT'S NEW IN 1.0.6 ?
+
+ See the CHANGES file.
+
+
+I hope you find bzip2 useful. Feel free to contact me at
+ jseward@bzip.org
+if you have any suggestions or queries. Many people mailed me with
+comments, suggestions and patches after the releases of bzip-0.15,
+bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
+1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
+feedback. I thank you for your comments.
+
+bzip2's "home" is http://www.bzip.org/
+
+Julian Seward
+jseward@bzip.org
+Cambridge, UK.
+
+18 July 1996 (version 0.15)
+25 August 1996 (version 0.21)
+ 7 August 1997 (bzip2, version 0.1)
+29 August 1997 (bzip2, version 0.1pl2)
+23 August 1998 (bzip2, version 0.9.0)
+ 8 June 1999 (bzip2, version 0.9.5)
+ 4 Sept 1999 (bzip2, version 0.9.5d)
+ 5 May 2000 (bzip2, version 1.0pre8)
+30 December 2001 (bzip2, version 1.0.2pre1)
+15 February 2005 (bzip2, version 1.0.3)
+20 December 2006 (bzip2, version 1.0.4)
+10 December 2007 (bzip2, version 1.0.5)
+ 6 Sept 2010 (bzip2, version 1.0.6)
diff --git a/dep/bzip2/blocksort.c b/dep/bzip2/blocksort.c
index bd2dec157fa..d0d662cd4e9 100644
--- a/dep/bzip2/blocksort.c
+++ b/dep/bzip2/blocksort.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/bzip2.c b/dep/bzip2/bzip2.c
new file mode 100644
index 00000000000..6de9d1d1488
--- /dev/null
+++ b/dep/bzip2/bzip2.c
@@ -0,0 +1,2034 @@
+
+/*-----------------------------------------------------------*/
+/*--- A block-sorting, lossless compressor bzip2.c ---*/
+/*-----------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+
+/* Place a 1 beside your platform, and 0 elsewhere.
+ Generic 32-bit Unix.
+ Also works on 64-bit Unix boxes.
+ This is the default.
+*/
+#define BZ_UNIX 1
+
+/*--
+ Win32, as seen by Jacob Navia's excellent
+ port of (Chris Fraser & David Hanson)'s excellent
+ lcc compiler. Or with MS Visual C.
+ This is selected automatically if compiled by a compiler which
+ defines _WIN32, not including the Cygwin GCC.
+--*/
+#define BZ_LCCWIN32 0
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#undef BZ_LCCWIN32
+#define BZ_LCCWIN32 1
+#undef BZ_UNIX
+#define BZ_UNIX 0
+#endif
+
+
+/*---------------------------------------------*/
+/*--
+ Some stuff for all platforms.
+--*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <math.h>
+#include <errno.h>
+#include <ctype.h>
+#include "bzlib.h"
+
+#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
+#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
+#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
+
+
+/*---------------------------------------------*/
+/*--
+ Platform-specific stuff.
+--*/
+
+#if BZ_UNIX
+# include <fcntl.h>
+# include <sys/types.h>
+# include <utime.h>
+# include <unistd.h>
+# include <sys/stat.h>
+# include <sys/times.h>
+
+# define PATH_SEP '/'
+# define MY_LSTAT lstat
+# define MY_STAT stat
+# define MY_S_ISREG S_ISREG
+# define MY_S_ISDIR S_ISDIR
+
+# define APPEND_FILESPEC(root, name) \
+ root=snocString((root), (name))
+
+# define APPEND_FLAG(root, name) \
+ root=snocString((root), (name))
+
+# define SET_BINARY_MODE(fd) /**/
+
+# ifdef __GNUC__
+# define NORETURN __attribute__ ((noreturn))
+# else
+# define NORETURN /**/
+# endif
+
+# ifdef __DJGPP__
+# include <io.h>
+# include <fcntl.h>
+# undef MY_LSTAT
+# undef MY_STAT
+# define MY_LSTAT stat
+# define MY_STAT stat
+# undef SET_BINARY_MODE
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+# endif
+
+# ifdef __CYGWIN__
+# include <io.h>
+# include <fcntl.h>
+# undef SET_BINARY_MODE
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+# endif
+#endif /* BZ_UNIX */
+
+
+
+#if BZ_LCCWIN32
+# include <io.h>
+# include <fcntl.h>
+# include <sys\stat.h>
+
+# define NORETURN /**/
+# define PATH_SEP '\\'
+# define MY_LSTAT _stat
+# define MY_STAT _stat
+# define MY_S_ISREG(x) ((x) & _S_IFREG)
+# define MY_S_ISDIR(x) ((x) & _S_IFDIR)
+
+# define APPEND_FLAG(root, name) \
+ root=snocString((root), (name))
+
+# define APPEND_FILESPEC(root, name) \
+ root = snocString ((root), (name))
+
+# define SET_BINARY_MODE(fd) \
+ do { \
+ int retVal = setmode ( fileno ( fd ), \
+ O_BINARY ); \
+ ERROR_IF_MINUS_ONE ( retVal ); \
+ } while ( 0 )
+
+#endif /* BZ_LCCWIN32 */
+
+
+/*---------------------------------------------*/
+/*--
+ Some more stuff for all platforms :-)
+--*/
+
+typedef char Char;
+typedef unsigned char Bool;
+typedef unsigned char UChar;
+typedef int Int32;
+typedef unsigned int UInt32;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#define True ((Bool)1)
+#define False ((Bool)0)
+
+/*--
+ IntNative is your platform's `native' int size.
+ Only here to avoid probs with 64-bit platforms.
+--*/
+typedef int IntNative;
+
+
+/*---------------------------------------------------*/
+/*--- Misc (file handling) data decls ---*/
+/*---------------------------------------------------*/
+
+Int32 verbosity;
+Bool keepInputFiles, smallMode, deleteOutputOnInterrupt;
+Bool forceOverwrite, testFailsExist, unzFailsExist, noisy;
+Int32 numFileNames, numFilesProcessed, blockSize100k;
+Int32 exitValue;
+
+/*-- source modes; F==file, I==stdin, O==stdout --*/
+#define SM_I2O 1
+#define SM_F2O 2
+#define SM_F2F 3
+
+/*-- operation modes --*/
+#define OM_Z 1
+#define OM_UNZ 2
+#define OM_TEST 3
+
+Int32 opMode;
+Int32 srcMode;
+
+#define FILE_NAME_LEN 1034
+
+Int32 longestFileName;
+Char inName [FILE_NAME_LEN];
+Char outName[FILE_NAME_LEN];
+Char tmpName[FILE_NAME_LEN];
+Char *progName;
+Char progNameReally[FILE_NAME_LEN];
+FILE *outputHandleJustInCase;
+Int32 workFactor;
+
+static void panic ( const Char* ) NORETURN;
+static void ioError ( void ) NORETURN;
+static void outOfMemory ( void ) NORETURN;
+static void configError ( void ) NORETURN;
+static void crcError ( void ) NORETURN;
+static void cleanUpAndFail ( Int32 ) NORETURN;
+static void compressedStreamEOF ( void ) NORETURN;
+
+static void copyFileName ( Char*, Char* );
+static void* myMalloc ( Int32 );
+static void applySavedFileAttrToOutputFile ( IntNative fd );
+
+
+
+/*---------------------------------------------------*/
+/*--- An implementation of 64-bit ints. Sigh. ---*/
+/*--- Roll on widespread deployment of ANSI C9X ! ---*/
+/*---------------------------------------------------*/
+
+typedef
+ struct { UChar b[8]; }
+ UInt64;
+
+
+static
+void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
+{
+ n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
+ n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
+ n->b[5] = (UChar)((hi32 >> 8) & 0xFF);
+ n->b[4] = (UChar) (hi32 & 0xFF);
+ n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
+ n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
+ n->b[1] = (UChar)((lo32 >> 8) & 0xFF);
+ n->b[0] = (UChar) (lo32 & 0xFF);
+}
+
+
+static
+double uInt64_to_double ( UInt64* n )
+{
+ Int32 i;
+ double base = 1.0;
+ double sum = 0.0;
+ for (i = 0; i < 8; i++) {
+ sum += base * (double)(n->b[i]);
+ base *= 256.0;
+ }
+ return sum;
+}
+
+
+static
+Bool uInt64_isZero ( UInt64* n )
+{
+ Int32 i;
+ for (i = 0; i < 8; i++)
+ if (n->b[i] != 0) return 0;
+ return 1;
+}
+
+
+/* Divide *n by 10, and return the remainder. */
+static
+Int32 uInt64_qrm10 ( UInt64* n )
+{
+ UInt32 rem, tmp;
+ Int32 i;
+ rem = 0;
+ for (i = 7; i >= 0; i--) {
+ tmp = rem * 256 + n->b[i];
+ n->b[i] = tmp / 10;
+ rem = tmp % 10;
+ }
+ return rem;
+}
+
+
+/* ... and the Whole Entire Point of all this UInt64 stuff is
+ so that we can supply the following function.
+*/
+static
+void uInt64_toAscii ( char* outbuf, UInt64* n )
+{
+ Int32 i, q;
+ UChar buf[32];
+ Int32 nBuf = 0;
+ UInt64 n_copy = *n;
+ do {
+ q = uInt64_qrm10 ( &n_copy );
+ buf[nBuf] = q + '0';
+ nBuf++;
+ } while (!uInt64_isZero(&n_copy));
+ outbuf[nBuf] = 0;
+ for (i = 0; i < nBuf; i++)
+ outbuf[i] = buf[nBuf-i-1];
+}
+
+
+/*---------------------------------------------------*/
+/*--- Processing of complete files and streams ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+Bool myfeof ( FILE* f )
+{
+ Int32 c = fgetc ( f );
+ if (c == EOF) return True;
+ ungetc ( c, f );
+ return False;
+}
+
+
+/*---------------------------------------------*/
+static
+void compressStream ( FILE *stream, FILE *zStream )
+{
+ BZFILE* bzf = NULL;
+ UChar ibuf[5000];
+ Int32 nIbuf;
+ UInt32 nbytes_in_lo32, nbytes_in_hi32;
+ UInt32 nbytes_out_lo32, nbytes_out_hi32;
+ Int32 bzerr, bzerr_dummy, ret;
+
+ SET_BINARY_MODE(stream);
+ SET_BINARY_MODE(zStream);
+
+ if (ferror(stream)) goto errhandler_io;
+ if (ferror(zStream)) goto errhandler_io;
+
+ bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
+ blockSize100k, verbosity, workFactor );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ if (verbosity >= 2) fprintf ( stderr, "\n" );
+
+ while (True) {
+
+ if (myfeof(stream)) break;
+ nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
+ if (ferror(stream)) goto errhandler_io;
+ if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ }
+
+ BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
+ &nbytes_in_lo32, &nbytes_in_hi32,
+ &nbytes_out_lo32, &nbytes_out_hi32 );
+ if (bzerr != BZ_OK) goto errhandler;
+
+ if (ferror(zStream)) goto errhandler_io;
+ ret = fflush ( zStream );
+ if (ret == EOF) goto errhandler_io;
+ if (zStream != stdout) {
+ Int32 fd = fileno ( zStream );
+ if (fd < 0) goto errhandler_io;
+ applySavedFileAttrToOutputFile ( fd );
+ ret = fclose ( zStream );
+ outputHandleJustInCase = NULL;
+ if (ret == EOF) goto errhandler_io;
+ }
+ outputHandleJustInCase = NULL;
+ if (ferror(stream)) goto errhandler_io;
+ ret = fclose ( stream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (verbosity >= 1) {
+ if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
+ fprintf ( stderr, " no data compressed.\n");
+ } else {
+ Char buf_nin[32], buf_nout[32];
+ UInt64 nbytes_in, nbytes_out;
+ double nbytes_in_d, nbytes_out_d;
+ uInt64_from_UInt32s ( &nbytes_in,
+ nbytes_in_lo32, nbytes_in_hi32 );
+ uInt64_from_UInt32s ( &nbytes_out,
+ nbytes_out_lo32, nbytes_out_hi32 );
+ nbytes_in_d = uInt64_to_double ( &nbytes_in );
+ nbytes_out_d = uInt64_to_double ( &nbytes_out );
+ uInt64_toAscii ( buf_nin, &nbytes_in );
+ uInt64_toAscii ( buf_nout, &nbytes_out );
+ fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
+ "%5.2f%% saved, %s in, %s out.\n",
+ nbytes_in_d / nbytes_out_d,
+ (8.0 * nbytes_out_d) / nbytes_in_d,
+ 100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
+ buf_nin,
+ buf_nout
+ );
+ }
+ }
+
+ return;
+
+ errhandler:
+ BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
+ &nbytes_in_lo32, &nbytes_in_hi32,
+ &nbytes_out_lo32, &nbytes_out_hi32 );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_MEM_ERROR:
+ outOfMemory (); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ default:
+ panic ( "compress:unexpected error" );
+ }
+
+ panic ( "compress:end" );
+ /*notreached*/
+}
+
+
+
+/*---------------------------------------------*/
+static
+Bool uncompressStream ( FILE *zStream, FILE *stream )
+{
+ BZFILE* bzf = NULL;
+ Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
+ UChar obuf[5000];
+ UChar unused[BZ_MAX_UNUSED];
+ Int32 nUnused;
+ void* unusedTmpV;
+ UChar* unusedTmp;
+
+ nUnused = 0;
+ streamNo = 0;
+
+ SET_BINARY_MODE(stream);
+ SET_BINARY_MODE(zStream);
+
+ if (ferror(stream)) goto errhandler_io;
+ if (ferror(zStream)) goto errhandler_io;
+
+ while (True) {
+
+ bzf = BZ2_bzReadOpen (
+ &bzerr, zStream, verbosity,
+ (int)smallMode, unused, nUnused
+ );
+ if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+ streamNo++;
+
+ while (bzerr == BZ_OK) {
+ nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+ if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
+ if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
+ fwrite ( obuf, sizeof(UChar), nread, stream );
+ if (ferror(stream)) goto errhandler_io;
+ }
+ if (bzerr != BZ_STREAM_END) goto errhandler;
+
+ BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+ if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+
+ unusedTmp = (UChar*)unusedTmpV;
+ for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+
+ BZ2_bzReadClose ( &bzerr, bzf );
+ if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
+
+ if (nUnused == 0 && myfeof(zStream)) break;
+ }
+
+ closeok:
+ if (ferror(zStream)) goto errhandler_io;
+ if (stream != stdout) {
+ Int32 fd = fileno ( stream );
+ if (fd < 0) goto errhandler_io;
+ applySavedFileAttrToOutputFile ( fd );
+ }
+ ret = fclose ( zStream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (ferror(stream)) goto errhandler_io;
+ ret = fflush ( stream );
+ if (ret != 0) goto errhandler_io;
+ if (stream != stdout) {
+ ret = fclose ( stream );
+ outputHandleJustInCase = NULL;
+ if (ret == EOF) goto errhandler_io;
+ }
+ outputHandleJustInCase = NULL;
+ if (verbosity >= 2) fprintf ( stderr, "\n " );
+ return True;
+
+ trycat:
+ if (forceOverwrite) {
+ rewind(zStream);
+ while (True) {
+ if (myfeof(zStream)) break;
+ nread = fread ( obuf, sizeof(UChar), 5000, zStream );
+ if (ferror(zStream)) goto errhandler_io;
+ if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
+ if (ferror(stream)) goto errhandler_io;
+ }
+ goto closeok;
+ }
+
+ errhandler:
+ BZ2_bzReadClose ( &bzerr_dummy, bzf );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ case BZ_DATA_ERROR:
+ crcError();
+ case BZ_MEM_ERROR:
+ outOfMemory();
+ case BZ_UNEXPECTED_EOF:
+ compressedStreamEOF();
+ case BZ_DATA_ERROR_MAGIC:
+ if (zStream != stdin) fclose(zStream);
+ if (stream != stdout) fclose(stream);
+ if (streamNo == 1) {
+ return False;
+ } else {
+ if (noisy)
+ fprintf ( stderr,
+ "\n%s: %s: trailing garbage after EOF ignored\n",
+ progName, inName );
+ return True;
+ }
+ default:
+ panic ( "decompress:unexpected error" );
+ }
+
+ panic ( "decompress:end" );
+ return True; /*notreached*/
+}
+
+
+/*---------------------------------------------*/
+static
+Bool testStream ( FILE *zStream )
+{
+ BZFILE* bzf = NULL;
+ Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
+ UChar obuf[5000];
+ UChar unused[BZ_MAX_UNUSED];
+ Int32 nUnused;
+ void* unusedTmpV;
+ UChar* unusedTmp;
+
+ nUnused = 0;
+ streamNo = 0;
+
+ SET_BINARY_MODE(zStream);
+ if (ferror(zStream)) goto errhandler_io;
+
+ while (True) {
+
+ bzf = BZ2_bzReadOpen (
+ &bzerr, zStream, verbosity,
+ (int)smallMode, unused, nUnused
+ );
+ if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
+ streamNo++;
+
+ while (bzerr == BZ_OK) {
+ nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
+ if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
+ }
+ if (bzerr != BZ_STREAM_END) goto errhandler;
+
+ BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
+ if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+
+ unusedTmp = (UChar*)unusedTmpV;
+ for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
+
+ BZ2_bzReadClose ( &bzerr, bzf );
+ if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
+ if (nUnused == 0 && myfeof(zStream)) break;
+
+ }
+
+ if (ferror(zStream)) goto errhandler_io;
+ ret = fclose ( zStream );
+ if (ret == EOF) goto errhandler_io;
+
+ if (verbosity >= 2) fprintf ( stderr, "\n " );
+ return True;
+
+ errhandler:
+ BZ2_bzReadClose ( &bzerr_dummy, bzf );
+ if (verbosity == 0)
+ fprintf ( stderr, "%s: %s: ", progName, inName );
+ switch (bzerr) {
+ case BZ_CONFIG_ERROR:
+ configError(); break;
+ case BZ_IO_ERROR:
+ errhandler_io:
+ ioError(); break;
+ case BZ_DATA_ERROR:
+ fprintf ( stderr,
+ "data integrity (CRC) error in data\n" );
+ return False;
+ case BZ_MEM_ERROR:
+ outOfMemory();
+ case BZ_UNEXPECTED_EOF:
+ fprintf ( stderr,
+ "file ends unexpectedly\n" );
+ return False;
+ case BZ_DATA_ERROR_MAGIC:
+ if (zStream != stdin) fclose(zStream);
+ if (streamNo == 1) {
+ fprintf ( stderr,
+ "bad magic number (file not created by bzip2)\n" );
+ return False;
+ } else {
+ if (noisy)
+ fprintf ( stderr,
+ "trailing garbage after EOF ignored\n" );
+ return True;
+ }
+ default:
+ panic ( "test:unexpected error" );
+ }
+
+ panic ( "test:end" );
+ return True; /*notreached*/
+}
+
+
+/*---------------------------------------------------*/
+/*--- Error [non-] handling grunge ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static
+void setExit ( Int32 v )
+{
+ if (v > exitValue) exitValue = v;
+}
+
+
+/*---------------------------------------------*/
+static
+void cadvise ( void )
+{
+ if (noisy)
+ fprintf (
+ stderr,
+ "\nIt is possible that the compressed file(s) have become corrupted.\n"
+ "You can use the -tvv option to test integrity of such files.\n\n"
+ "You can use the `bzip2recover' program to attempt to recover\n"
+ "data from undamaged sections of corrupted files.\n\n"
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void showFileNames ( void )
+{
+ if (noisy)
+ fprintf (
+ stderr,
+ "\tInput file = %s, output file = %s\n",
+ inName, outName
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void cleanUpAndFail ( Int32 ec )
+{
+ IntNative retVal;
+ struct MY_STAT statBuf;
+
+ if ( srcMode == SM_F2F
+ && opMode != OM_TEST
+ && deleteOutputOnInterrupt ) {
+
+ /* Check whether input file still exists. Delete output file
+ only if input exists to avoid loss of data. Joerg Prante, 5
+ January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean
+ this is less likely to happen. But to be ultra-paranoid, we
+ do the check anyway.) */
+ retVal = MY_STAT ( inName, &statBuf );
+ if (retVal == 0) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Deleting output file %s, if it exists.\n",
+ progName, outName );
+ if (outputHandleJustInCase != NULL)
+ fclose ( outputHandleJustInCase );
+ retVal = remove ( outName );
+ if (retVal != 0)
+ fprintf ( stderr,
+ "%s: WARNING: deletion of output file "
+ "(apparently) failed.\n",
+ progName );
+ } else {
+ fprintf ( stderr,
+ "%s: WARNING: deletion of output file suppressed\n",
+ progName );
+ fprintf ( stderr,
+ "%s: since input file no longer exists. Output file\n",
+ progName );
+ fprintf ( stderr,
+ "%s: `%s' may be incomplete.\n",
+ progName, outName );
+ fprintf ( stderr,
+ "%s: I suggest doing an integrity test (bzip2 -tv)"
+ " of it.\n",
+ progName );
+ }
+ }
+
+ if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
+ fprintf ( stderr,
+ "%s: WARNING: some files have not been processed:\n"
+ "%s: %d specified on command line, %d not processed yet.\n\n",
+ progName, progName,
+ numFileNames, numFileNames - numFilesProcessed );
+ }
+ setExit(ec);
+ exit(exitValue);
+}
+
+
+/*---------------------------------------------*/
+static
+void panic ( const Char* s )
+{
+ fprintf ( stderr,
+ "\n%s: PANIC -- internal consistency error:\n"
+ "\t%s\n"
+ "\tThis is a BUG. Please report it to me at:\n"
+ "\tjseward@bzip.org\n",
+ progName, s );
+ showFileNames();
+ cleanUpAndFail( 3 );
+}
+
+
+/*---------------------------------------------*/
+static
+void crcError ( void )
+{
+ fprintf ( stderr,
+ "\n%s: Data integrity error when decompressing.\n",
+ progName );
+ showFileNames();
+ cadvise();
+ cleanUpAndFail( 2 );
+}
+
+
+/*---------------------------------------------*/
+static
+void compressedStreamEOF ( void )
+{
+ if (noisy) {
+ fprintf ( stderr,
+ "\n%s: Compressed file ends unexpectedly;\n\t"
+ "perhaps it is corrupted? *Possible* reason follows.\n",
+ progName );
+ perror ( progName );
+ showFileNames();
+ cadvise();
+ }
+ cleanUpAndFail( 2 );
+}
+
+
+/*---------------------------------------------*/
+static
+void ioError ( void )
+{
+ fprintf ( stderr,
+ "\n%s: I/O or other error, bailing out. "
+ "Possible reason follows.\n",
+ progName );
+ perror ( progName );
+ showFileNames();
+ cleanUpAndFail( 1 );
+}
+
+
+/*---------------------------------------------*/
+static
+void mySignalCatcher ( IntNative n )
+{
+ fprintf ( stderr,
+ "\n%s: Control-C or similar caught, quitting.\n",
+ progName );
+ cleanUpAndFail(1);
+}
+
+
+/*---------------------------------------------*/
+static
+void mySIGSEGVorSIGBUScatcher ( IntNative n )
+{
+ if (opMode == OM_Z)
+ fprintf (
+ stderr,
+ "\n%s: Caught a SIGSEGV or SIGBUS whilst compressing.\n"
+ "\n"
+ " Possible causes are (most likely first):\n"
+ " (1) This computer has unreliable memory or cache hardware\n"
+ " (a surprisingly common problem; try a different machine.)\n"
+ " (2) A bug in the compiler used to create this executable\n"
+ " (unlikely, if you didn't compile bzip2 yourself.)\n"
+ " (3) A real bug in bzip2 -- I hope this should never be the case.\n"
+ " The user's manual, Section 4.3, has more info on (1) and (2).\n"
+ " \n"
+ " If you suspect this is a bug in bzip2, or are unsure about (1)\n"
+ " or (2), feel free to report it to me at: jseward@bzip.org.\n"
+ " Section 4.3 of the user's manual describes the info a useful\n"
+ " bug report should have. If the manual is available on your\n"
+ " system, please try and read it before mailing me. If you don't\n"
+ " have the manual or can't be bothered to read it, mail me anyway.\n"
+ "\n",
+ progName );
+ else
+ fprintf (
+ stderr,
+ "\n%s: Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
+ "\n"
+ " Possible causes are (most likely first):\n"
+ " (1) The compressed data is corrupted, and bzip2's usual checks\n"
+ " failed to detect this. Try bzip2 -tvv my_file.bz2.\n"
+ " (2) This computer has unreliable memory or cache hardware\n"
+ " (a surprisingly common problem; try a different machine.)\n"
+ " (3) A bug in the compiler used to create this executable\n"
+ " (unlikely, if you didn't compile bzip2 yourself.)\n"
+ " (4) A real bug in bzip2 -- I hope this should never be the case.\n"
+ " The user's manual, Section 4.3, has more info on (2) and (3).\n"
+ " \n"
+ " If you suspect this is a bug in bzip2, or are unsure about (2)\n"
+ " or (3), feel free to report it to me at: jseward@bzip.org.\n"
+ " Section 4.3 of the user's manual describes the info a useful\n"
+ " bug report should have. If the manual is available on your\n"
+ " system, please try and read it before mailing me. If you don't\n"
+ " have the manual or can't be bothered to read it, mail me anyway.\n"
+ "\n",
+ progName );
+
+ showFileNames();
+ if (opMode == OM_Z)
+ cleanUpAndFail( 3 ); else
+ { cadvise(); cleanUpAndFail( 2 ); }
+}
+
+
+/*---------------------------------------------*/
+static
+void outOfMemory ( void )
+{
+ fprintf ( stderr,
+ "\n%s: couldn't allocate enough memory\n",
+ progName );
+ showFileNames();
+ cleanUpAndFail(1);
+}
+
+
+/*---------------------------------------------*/
+static
+void configError ( void )
+{
+ fprintf ( stderr,
+ "bzip2: I'm not configured correctly for this platform!\n"
+ "\tI require Int32, Int16 and Char to have sizes\n"
+ "\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
+ "\tProbably you can fix this by defining them correctly,\n"
+ "\tand recompiling. Bye!\n" );
+ setExit(3);
+ exit(exitValue);
+}
+
+
+/*---------------------------------------------------*/
+/*--- The main driver machinery ---*/
+/*---------------------------------------------------*/
+
+/* All rather crufty. The main problem is that input files
+ are stat()d multiple times before use. This should be
+ cleaned up.
+*/
+
+/*---------------------------------------------*/
+static
+void pad ( Char *s )
+{
+ Int32 i;
+ if ( (Int32)strlen(s) >= longestFileName ) return;
+ for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
+ fprintf ( stderr, " " );
+}
+
+
+/*---------------------------------------------*/
+static
+void copyFileName ( Char* to, Char* from )
+{
+ if ( strlen(from) > FILE_NAME_LEN-10 ) {
+ fprintf (
+ stderr,
+ "bzip2: file name\n`%s'\n"
+ "is suspiciously (more than %d chars) long.\n"
+ "Try using a reasonable file name instead. Sorry! :-)\n",
+ from, FILE_NAME_LEN-10
+ );
+ setExit(1);
+ exit(exitValue);
+ }
+
+ strncpy(to,from,FILE_NAME_LEN-10);
+ to[FILE_NAME_LEN-10]='\0';
+}
+
+
+/*---------------------------------------------*/
+static
+Bool fileExists ( Char* name )
+{
+ FILE *tmp = fopen ( name, "rb" );
+ Bool exists = (tmp != NULL);
+ if (tmp != NULL) fclose ( tmp );
+ return exists;
+}
+
+
+/*---------------------------------------------*/
+/* Open an output file safely with O_EXCL and good permissions.
+ This avoids a race condition in versions < 1.0.2, in which
+ the file was first opened and then had its interim permissions
+ set safely. We instead use open() to create the file with
+ the interim permissions required. (--- --- rw-).
+
+ For non-Unix platforms, if we are not worrying about
+ security issues, simple this simply behaves like fopen.
+*/
+static
+FILE* fopen_output_safely ( Char* name, const char* mode )
+{
+# if BZ_UNIX
+ FILE* fp;
+ IntNative fh;
+ fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
+ if (fh == -1) return NULL;
+ fp = fdopen(fh, mode);
+ if (fp == NULL) close(fh);
+ return fp;
+# else
+ return fopen(name, mode);
+# endif
+}
+
+
+/*---------------------------------------------*/
+/*--
+ if in doubt, return True
+--*/
+static
+Bool notAStandardFile ( Char* name )
+{
+ IntNative i;
+ struct MY_STAT statBuf;
+
+ i = MY_LSTAT ( name, &statBuf );
+ if (i != 0) return True;
+ if (MY_S_ISREG(statBuf.st_mode)) return False;
+ return True;
+}
+
+
+/*---------------------------------------------*/
+/*--
+ rac 11/21/98 see if file has hard links to it
+--*/
+static
+Int32 countHardLinks ( Char* name )
+{
+ IntNative i;
+ struct MY_STAT statBuf;
+
+ i = MY_LSTAT ( name, &statBuf );
+ if (i != 0) return 0;
+ return (statBuf.st_nlink - 1);
+}
+
+
+/*---------------------------------------------*/
+/* Copy modification date, access date, permissions and owner from the
+ source to destination file. We have to copy this meta-info off
+ into fileMetaInfo before starting to compress / decompress it,
+ because doing it afterwards means we get the wrong access time.
+
+ To complicate matters, in compress() and decompress() below, the
+ sequence of tests preceding the call to saveInputFileMetaInfo()
+ involves calling fileExists(), which in turn establishes its result
+ by attempting to fopen() the file, and if successful, immediately
+ fclose()ing it again. So we have to assume that the fopen() call
+ does not cause the access time field to be updated.
+
+ Reading of the man page for stat() (man 2 stat) on RedHat 7.2 seems
+ to imply that merely doing open() will not affect the access time.
+ Therefore we merely need to hope that the C library only does
+ open() as a result of fopen(), and not any kind of read()-ahead
+ cleverness.
+
+ It sounds pretty fragile to me. Whether this carries across
+ robustly to arbitrary Unix-like platforms (or even works robustly
+ on this one, RedHat 7.2) is unknown to me. Nevertheless ...
+*/
+#if BZ_UNIX
+static
+struct MY_STAT fileMetaInfo;
+#endif
+
+static
+void saveInputFileMetaInfo ( Char *srcName )
+{
+# if BZ_UNIX
+ IntNative retVal;
+ /* Note use of stat here, not lstat. */
+ retVal = MY_STAT( srcName, &fileMetaInfo );
+ ERROR_IF_NOT_ZERO ( retVal );
+# endif
+}
+
+
+static
+void applySavedTimeInfoToOutputFile ( Char *dstName )
+{
+# if BZ_UNIX
+ IntNative retVal;
+ struct utimbuf uTimBuf;
+
+ uTimBuf.actime = fileMetaInfo.st_atime;
+ uTimBuf.modtime = fileMetaInfo.st_mtime;
+
+ retVal = utime ( dstName, &uTimBuf );
+ ERROR_IF_NOT_ZERO ( retVal );
+# endif
+}
+
+static
+void applySavedFileAttrToOutputFile ( IntNative fd )
+{
+# if BZ_UNIX
+ IntNative retVal;
+
+ retVal = fchmod ( fd, fileMetaInfo.st_mode );
+ ERROR_IF_NOT_ZERO ( retVal );
+
+ (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
+ /* chown() will in many cases return with EPERM, which can
+ be safely ignored.
+ */
+# endif
+}
+
+
+/*---------------------------------------------*/
+static
+Bool containsDubiousChars ( Char* name )
+{
+# if BZ_UNIX
+ /* On unix, files can contain any characters and the file expansion
+ * is performed by the shell.
+ */
+ return False;
+# else /* ! BZ_UNIX */
+ /* On non-unix (Win* platforms), wildcard characters are not allowed in
+ * filenames.
+ */
+ for (; *name != '\0'; name++)
+ if (*name == '?' || *name == '*') return True;
+ return False;
+# endif /* BZ_UNIX */
+}
+
+
+/*---------------------------------------------*/
+#define BZ_N_SUFFIX_PAIRS 4
+
+const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
+ = { ".bz2", ".bz", ".tbz2", ".tbz" };
+const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
+ = { "", "", ".tar", ".tar" };
+
+static
+Bool hasSuffix ( Char* s, const Char* suffix )
+{
+ Int32 ns = strlen(s);
+ Int32 nx = strlen(suffix);
+ if (ns < nx) return False;
+ if (strcmp(s + ns - nx, suffix) == 0) return True;
+ return False;
+}
+
+static
+Bool mapSuffix ( Char* name,
+ const Char* oldSuffix,
+ const Char* newSuffix )
+{
+ if (!hasSuffix(name,oldSuffix)) return False;
+ name[strlen(name)-strlen(oldSuffix)] = 0;
+ strcat ( name, newSuffix );
+ return True;
+}
+
+
+/*---------------------------------------------*/
+static
+void compress ( Char *name )
+{
+ FILE *inStr;
+ FILE *outStr;
+ Int32 n, i;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "compress: bad modes\n" );
+
+ switch (srcMode) {
+ case SM_I2O:
+ copyFileName ( inName, (Char*)"(stdin)" );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ case SM_F2F:
+ copyFileName ( inName, name );
+ copyFileName ( outName, name );
+ strcat ( outName, ".bz2" );
+ break;
+ case SM_F2O:
+ copyFileName ( inName, name );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ }
+
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
+ if (hasSuffix(inName, zSuffix[i])) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Input file %s already has %s suffix.\n",
+ progName, inName, zSuffix[i] );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+ if (noisy)
+ fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode == SM_F2F && fileExists ( outName ) ) {
+ if (forceOverwrite) {
+ remove(outName);
+ } else {
+ fprintf ( stderr, "%s: Output file %s already exists.\n",
+ progName, outName );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite &&
+ (n=countHardLinks ( inName )) > 0) {
+ fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
+ progName, inName, n, n > 1 ? "s" : "" );
+ setExit(1);
+ return;
+ }
+
+ if ( srcMode == SM_F2F ) {
+ /* Save the file's meta-info before we open it. Doing it later
+ means we mess up the access times. */
+ saveInputFileMetaInfo ( inName );
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ inStr = stdin;
+ outStr = stdout;
+ if ( isatty ( fileno ( stdout ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't write compressed data to a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2O:
+ inStr = fopen ( inName, "rb" );
+ outStr = stdout;
+ if ( isatty ( fileno ( stdout ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't write compressed data to a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ };
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ outStr = fopen_output_safely ( outName, "wb" );
+ if ( outStr == NULL) {
+ fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
+ progName, outName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ }
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ if ( outStr != NULL ) fclose ( outStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "compress: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input and output handles are sane. Do the Biz. ---*/
+ outputHandleJustInCase = outStr;
+ deleteOutputOnInterrupt = True;
+ compressStream ( inStr, outStr );
+ outputHandleJustInCase = NULL;
+
+ /*--- If there was an I/O error, we won't get here. ---*/
+ if ( srcMode == SM_F2F ) {
+ applySavedTimeInfoToOutputFile ( outName );
+ deleteOutputOnInterrupt = False;
+ if ( !keepInputFiles ) {
+ IntNative retVal = remove ( inName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+
+ deleteOutputOnInterrupt = False;
+}
+
+
+/*---------------------------------------------*/
+static
+void uncompress ( Char *name )
+{
+ FILE *inStr;
+ FILE *outStr;
+ Int32 n, i;
+ Bool magicNumberOK;
+ Bool cantGuess;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "uncompress: bad modes\n" );
+
+ cantGuess = False;
+ switch (srcMode) {
+ case SM_I2O:
+ copyFileName ( inName, (Char*)"(stdin)" );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ case SM_F2F:
+ copyFileName ( inName, name );
+ copyFileName ( outName, name );
+ for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
+ if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
+ goto zzz;
+ cantGuess = True;
+ strcat ( outName, ".out" );
+ break;
+ case SM_F2O:
+ copyFileName ( inName, name );
+ copyFileName ( outName, (Char*)"(stdout)" );
+ break;
+ }
+
+ zzz:
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+ if (noisy)
+ fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
+ if (noisy)
+ fprintf ( stderr,
+ "%s: Can't guess original name for %s -- using %s\n",
+ progName, inName, outName );
+ /* just a warning, no return */
+ }
+ if ( srcMode == SM_F2F && fileExists ( outName ) ) {
+ if (forceOverwrite) {
+ remove(outName);
+ } else {
+ fprintf ( stderr, "%s: Output file %s already exists.\n",
+ progName, outName );
+ setExit(1);
+ return;
+ }
+ }
+ if ( srcMode == SM_F2F && !forceOverwrite &&
+ (n=countHardLinks ( inName ) ) > 0) {
+ fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
+ progName, inName, n, n > 1 ? "s" : "" );
+ setExit(1);
+ return;
+ }
+
+ if ( srcMode == SM_F2F ) {
+ /* Save the file's meta-info before we open it. Doing it later
+ means we mess up the access times. */
+ saveInputFileMetaInfo ( inName );
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ inStr = stdin;
+ outStr = stdout;
+ if ( isatty ( fileno ( stdin ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't read compressed data from a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2O:
+ inStr = fopen ( inName, "rb" );
+ outStr = stdout;
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
+ progName, inName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ outStr = fopen_output_safely ( outName, "wb" );
+ if ( outStr == NULL) {
+ fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
+ progName, outName, strerror(errno) );
+ if ( inStr != NULL ) fclose ( inStr );
+ setExit(1);
+ return;
+ }
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
+ progName, inName, strerror(errno) );
+ if ( outStr != NULL ) fclose ( outStr );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "uncompress: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input and output handles are sane. Do the Biz. ---*/
+ outputHandleJustInCase = outStr;
+ deleteOutputOnInterrupt = True;
+ magicNumberOK = uncompressStream ( inStr, outStr );
+ outputHandleJustInCase = NULL;
+
+ /*--- If there was an I/O error, we won't get here. ---*/
+ if ( magicNumberOK ) {
+ if ( srcMode == SM_F2F ) {
+ applySavedTimeInfoToOutputFile ( outName );
+ deleteOutputOnInterrupt = False;
+ if ( !keepInputFiles ) {
+ IntNative retVal = remove ( inName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+ } else {
+ unzFailsExist = True;
+ deleteOutputOnInterrupt = False;
+ if ( srcMode == SM_F2F ) {
+ IntNative retVal = remove ( outName );
+ ERROR_IF_NOT_ZERO ( retVal );
+ }
+ }
+ deleteOutputOnInterrupt = False;
+
+ if ( magicNumberOK ) {
+ if (verbosity >= 1)
+ fprintf ( stderr, "done\n" );
+ } else {
+ setExit(2);
+ if (verbosity >= 1)
+ fprintf ( stderr, "not a bzip2 file.\n" ); else
+ fprintf ( stderr,
+ "%s: %s is not a bzip2 file.\n",
+ progName, inName );
+ }
+
+}
+
+
+/*---------------------------------------------*/
+static
+void testf ( Char *name )
+{
+ FILE *inStr;
+ Bool allOK;
+ struct MY_STAT statBuf;
+
+ deleteOutputOnInterrupt = False;
+
+ if (name == NULL && srcMode != SM_I2O)
+ panic ( "testf: bad modes\n" );
+
+ copyFileName ( outName, (Char*)"(none)" );
+ switch (srcMode) {
+ case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
+ case SM_F2F: copyFileName ( inName, name ); break;
+ case SM_F2O: copyFileName ( inName, name ); break;
+ }
+
+ if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
+ if (noisy)
+ fprintf ( stderr, "%s: There are no files matching `%s'.\n",
+ progName, inName );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
+ fprintf ( stderr, "%s: Can't open input %s: %s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ }
+ if ( srcMode != SM_I2O ) {
+ MY_STAT(inName, &statBuf);
+ if ( MY_S_ISDIR(statBuf.st_mode) ) {
+ fprintf( stderr,
+ "%s: Input file %s is a directory.\n",
+ progName,inName);
+ setExit(1);
+ return;
+ }
+ }
+
+ switch ( srcMode ) {
+
+ case SM_I2O:
+ if ( isatty ( fileno ( stdin ) ) ) {
+ fprintf ( stderr,
+ "%s: I won't read compressed data from a terminal.\n",
+ progName );
+ fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
+ progName, progName );
+ setExit(1);
+ return;
+ };
+ inStr = stdin;
+ break;
+
+ case SM_F2O: case SM_F2F:
+ inStr = fopen ( inName, "rb" );
+ if ( inStr == NULL ) {
+ fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
+ progName, inName, strerror(errno) );
+ setExit(1);
+ return;
+ };
+ break;
+
+ default:
+ panic ( "testf: bad srcMode" );
+ break;
+ }
+
+ if (verbosity >= 1) {
+ fprintf ( stderr, " %s: ", inName );
+ pad ( inName );
+ fflush ( stderr );
+ }
+
+ /*--- Now the input handle is sane. Do the Biz. ---*/
+ outputHandleJustInCase = NULL;
+ allOK = testStream ( inStr );
+
+ if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
+ if (!allOK) testFailsExist = True;
+}
+
+
+/*---------------------------------------------*/
+static
+void license ( void )
+{
+ fprintf ( stderr,
+
+ "bzip2, a block-sorting file compressor. "
+ "Version %s.\n"
+ " \n"
+ " Copyright (C) 1996-2010 by Julian Seward.\n"
+ " \n"
+ " This program is free software; you can redistribute it and/or modify\n"
+ " it under the terms set out in the LICENSE file, which is included\n"
+ " in the bzip2-1.0.6 source distribution.\n"
+ " \n"
+ " This program is distributed in the hope that it will be useful,\n"
+ " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ " LICENSE file for more details.\n"
+ " \n",
+ BZ2_bzlibVersion()
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void usage ( Char *fullProgName )
+{
+ fprintf (
+ stderr,
+ "bzip2, a block-sorting file compressor. "
+ "Version %s.\n"
+ "\n usage: %s [flags and input files in any order]\n"
+ "\n"
+ " -h --help print this message\n"
+ " -d --decompress force decompression\n"
+ " -z --compress force compression\n"
+ " -k --keep keep (don't delete) input files\n"
+ " -f --force overwrite existing output files\n"
+ " -t --test test compressed file integrity\n"
+ " -c --stdout output to standard out\n"
+ " -q --quiet suppress noncritical error messages\n"
+ " -v --verbose be verbose (a 2nd -v gives more)\n"
+ " -L --license display software version & license\n"
+ " -V --version display software version & license\n"
+ " -s --small use less memory (at most 2500k)\n"
+ " -1 .. -9 set block size to 100k .. 900k\n"
+ " --fast alias for -1\n"
+ " --best alias for -9\n"
+ "\n"
+ " If invoked as `bzip2', default action is to compress.\n"
+ " as `bunzip2', default action is to decompress.\n"
+ " as `bzcat', default action is to decompress to stdout.\n"
+ "\n"
+ " If no file names are given, bzip2 compresses or decompresses\n"
+ " from standard input to standard output. You can combine\n"
+ " short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
+# if BZ_UNIX
+ "\n"
+# endif
+ ,
+
+ BZ2_bzlibVersion(),
+ fullProgName
+ );
+}
+
+
+/*---------------------------------------------*/
+static
+void redundant ( Char* flag )
+{
+ fprintf (
+ stderr,
+ "%s: %s is redundant in versions 0.9.5 and above\n",
+ progName, flag );
+}
+
+
+/*---------------------------------------------*/
+/*--
+ All the garbage from here to main() is purely to
+ implement a linked list of command-line arguments,
+ into which main() copies argv[1 .. argc-1].
+
+ The purpose of this exercise is to facilitate
+ the expansion of wildcard characters * and ? in
+ filenames for OSs which don't know how to do it
+ themselves, like MSDOS, Windows 95 and NT.
+
+ The actual Dirty Work is done by the platform-
+ specific macro APPEND_FILESPEC.
+--*/
+
+typedef
+ struct zzzz {
+ Char *name;
+ struct zzzz *link;
+ }
+ Cell;
+
+
+/*---------------------------------------------*/
+static
+void *myMalloc ( Int32 n )
+{
+ void* p;
+
+ p = malloc ( (size_t)n );
+ if (p == NULL) outOfMemory ();
+ return p;
+}
+
+
+/*---------------------------------------------*/
+static
+Cell *mkCell ( void )
+{
+ Cell *c;
+
+ c = (Cell*) myMalloc ( sizeof ( Cell ) );
+ c->name = NULL;
+ c->link = NULL;
+ return c;
+}
+
+
+/*---------------------------------------------*/
+static
+Cell *snocString ( Cell *root, Char *name )
+{
+ if (root == NULL) {
+ Cell *tmp = mkCell();
+ tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
+ strcpy ( tmp->name, name );
+ return tmp;
+ } else {
+ Cell *tmp = root;
+ while (tmp->link != NULL) tmp = tmp->link;
+ tmp->link = snocString ( tmp->link, name );
+ return root;
+ }
+}
+
+
+/*---------------------------------------------*/
+static
+void addFlagsFromEnvVar ( Cell** argList, Char* varName )
+{
+ Int32 i, j, k;
+ Char *envbase, *p;
+
+ envbase = getenv(varName);
+ if (envbase != NULL) {
+ p = envbase;
+ i = 0;
+ while (True) {
+ if (p[i] == 0) break;
+ p += i;
+ i = 0;
+ while (isspace((Int32)(p[0]))) p++;
+ while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
+ if (i > 0) {
+ k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
+ for (j = 0; j < k; j++) tmpName[j] = p[j];
+ tmpName[k] = 0;
+ APPEND_FLAG(*argList, tmpName);
+ }
+ }
+ }
+}
+
+
+/*---------------------------------------------*/
+#define ISFLAG(s) (strcmp(aa->name, (s))==0)
+
+IntNative main ( IntNative argc, Char *argv[] )
+{
+ Int32 i, j;
+ Char *tmp;
+ Cell *argList;
+ Cell *aa;
+ Bool decode;
+
+ /*-- Be really really really paranoid :-) --*/
+ if (sizeof(Int32) != 4 || sizeof(UInt32) != 4 ||
+ sizeof(Int16) != 2 || sizeof(UInt16) != 2 ||
+ sizeof(Char) != 1 || sizeof(UChar) != 1)
+ configError();
+
+ /*-- Initialise --*/
+ outputHandleJustInCase = NULL;
+ smallMode = False;
+ keepInputFiles = False;
+ forceOverwrite = False;
+ noisy = True;
+ verbosity = 0;
+ blockSize100k = 9;
+ testFailsExist = False;
+ unzFailsExist = False;
+ numFileNames = 0;
+ numFilesProcessed = 0;
+ workFactor = 30;
+ deleteOutputOnInterrupt = False;
+ exitValue = 0;
+ i = j = 0; /* avoid bogus warning from egcs-1.1.X */
+
+ /*-- Set up signal handlers for mem access errors --*/
+ signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
+# if BZ_UNIX
+# ifndef __DJGPP__
+ signal (SIGBUS, mySIGSEGVorSIGBUScatcher);
+# endif
+# endif
+
+ copyFileName ( inName, (Char*)"(none)" );
+ copyFileName ( outName, (Char*)"(none)" );
+
+ copyFileName ( progNameReally, argv[0] );
+ progName = &progNameReally[0];
+ for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
+ if (*tmp == PATH_SEP) progName = tmp + 1;
+
+
+ /*-- Copy flags from env var BZIP2, and
+ expand filename wildcards in arg list.
+ --*/
+ argList = NULL;
+ addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
+ addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
+ for (i = 1; i <= argc-1; i++)
+ APPEND_FILESPEC(argList, argv[i]);
+
+
+ /*-- Find the length of the longest filename --*/
+ longestFileName = 7;
+ numFileNames = 0;
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFileNames++;
+ if (longestFileName < (Int32)strlen(aa->name) )
+ longestFileName = (Int32)strlen(aa->name);
+ }
+
+
+ /*-- Determine source modes; flag handling may change this too. --*/
+ if (numFileNames == 0)
+ srcMode = SM_I2O; else srcMode = SM_F2F;
+
+
+ /*-- Determine what to do (compress/uncompress/test/cat). --*/
+ /*-- Note that subsequent flag handling may change this. --*/
+ opMode = OM_Z;
+
+ if ( (strstr ( progName, "unzip" ) != 0) ||
+ (strstr ( progName, "UNZIP" ) != 0) )
+ opMode = OM_UNZ;
+
+ if ( (strstr ( progName, "z2cat" ) != 0) ||
+ (strstr ( progName, "Z2CAT" ) != 0) ||
+ (strstr ( progName, "zcat" ) != 0) ||
+ (strstr ( progName, "ZCAT" ) != 0) ) {
+ opMode = OM_UNZ;
+ srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
+ }
+
+
+ /*-- Look at the flags. --*/
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) break;
+ if (aa->name[0] == '-' && aa->name[1] != '-') {
+ for (j = 1; aa->name[j] != '\0'; j++) {
+ switch (aa->name[j]) {
+ case 'c': srcMode = SM_F2O; break;
+ case 'd': opMode = OM_UNZ; break;
+ case 'z': opMode = OM_Z; break;
+ case 'f': forceOverwrite = True; break;
+ case 't': opMode = OM_TEST; break;
+ case 'k': keepInputFiles = True; break;
+ case 's': smallMode = True; break;
+ case 'q': noisy = False; break;
+ case '1': blockSize100k = 1; break;
+ case '2': blockSize100k = 2; break;
+ case '3': blockSize100k = 3; break;
+ case '4': blockSize100k = 4; break;
+ case '5': blockSize100k = 5; break;
+ case '6': blockSize100k = 6; break;
+ case '7': blockSize100k = 7; break;
+ case '8': blockSize100k = 8; break;
+ case '9': blockSize100k = 9; break;
+ case 'V':
+ case 'L': license(); break;
+ case 'v': verbosity++; break;
+ case 'h': usage ( progName );
+ exit ( 0 );
+ break;
+ default: fprintf ( stderr, "%s: Bad flag `%s'\n",
+ progName, aa->name );
+ usage ( progName );
+ exit ( 1 );
+ break;
+ }
+ }
+ }
+ }
+
+ /*-- And again ... --*/
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) break;
+ if (ISFLAG("--stdout")) srcMode = SM_F2O; else
+ if (ISFLAG("--decompress")) opMode = OM_UNZ; else
+ if (ISFLAG("--compress")) opMode = OM_Z; else
+ if (ISFLAG("--force")) forceOverwrite = True; else
+ if (ISFLAG("--test")) opMode = OM_TEST; else
+ if (ISFLAG("--keep")) keepInputFiles = True; else
+ if (ISFLAG("--small")) smallMode = True; else
+ if (ISFLAG("--quiet")) noisy = False; else
+ if (ISFLAG("--version")) license(); else
+ if (ISFLAG("--license")) license(); else
+ if (ISFLAG("--exponential")) workFactor = 1; else
+ if (ISFLAG("--repetitive-best")) redundant(aa->name); else
+ if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
+ if (ISFLAG("--fast")) blockSize100k = 1; else
+ if (ISFLAG("--best")) blockSize100k = 9; else
+ if (ISFLAG("--verbose")) verbosity++; else
+ if (ISFLAG("--help")) { usage ( progName ); exit ( 0 ); }
+ else
+ if (strncmp ( aa->name, "--", 2) == 0) {
+ fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name );
+ usage ( progName );
+ exit ( 1 );
+ }
+ }
+
+ if (verbosity > 4) verbosity = 4;
+ if (opMode == OM_Z && smallMode && blockSize100k > 2)
+ blockSize100k = 2;
+
+ if (opMode == OM_TEST && srcMode == SM_F2O) {
+ fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
+ progName );
+ exit ( 1 );
+ }
+
+ if (srcMode == SM_F2O && numFileNames == 0)
+ srcMode = SM_I2O;
+
+ if (opMode != OM_Z) blockSize100k = 0;
+
+ if (srcMode == SM_F2F) {
+ signal (SIGINT, mySignalCatcher);
+ signal (SIGTERM, mySignalCatcher);
+# if BZ_UNIX
+ signal (SIGHUP, mySignalCatcher);
+# endif
+ }
+
+ if (opMode == OM_Z) {
+ if (srcMode == SM_I2O) {
+ compress ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ compress ( aa->name );
+ }
+ }
+ }
+ else
+
+ if (opMode == OM_UNZ) {
+ unzFailsExist = False;
+ if (srcMode == SM_I2O) {
+ uncompress ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ uncompress ( aa->name );
+ }
+ }
+ if (unzFailsExist) {
+ setExit(2);
+ exit(exitValue);
+ }
+ }
+
+ else {
+ testFailsExist = False;
+ if (srcMode == SM_I2O) {
+ testf ( NULL );
+ } else {
+ decode = True;
+ for (aa = argList; aa != NULL; aa = aa->link) {
+ if (ISFLAG("--")) { decode = False; continue; }
+ if (aa->name[0] == '-' && decode) continue;
+ numFilesProcessed++;
+ testf ( aa->name );
+ }
+ }
+ if (testFailsExist && noisy) {
+ fprintf ( stderr,
+ "\n"
+ "You can use the `bzip2recover' program to attempt to recover\n"
+ "data from undamaged sections of corrupted files.\n\n"
+ );
+ setExit(2);
+ exit(exitValue);
+ }
+ }
+
+ /* Free the argument list memory to mollify leak detectors
+ (eg) Purify, Checker. Serves no other useful purpose.
+ */
+ aa = argList;
+ while (aa != NULL) {
+ Cell* aa2 = aa->link;
+ if (aa->name != NULL) free(aa->name);
+ free(aa);
+ aa = aa2;
+ }
+
+ return exitValue;
+}
+
+
+/*-----------------------------------------------------------*/
+/*--- end bzip2.c ---*/
+/*-----------------------------------------------------------*/
diff --git a/dep/bzip2/bzip2recover.c b/dep/bzip2/bzip2recover.c
new file mode 100644
index 00000000000..f9de0496abf
--- /dev/null
+++ b/dep/bzip2/bzip2recover.c
@@ -0,0 +1,514 @@
+/*-----------------------------------------------------------*/
+/*--- Block recoverer program for bzip2 ---*/
+/*--- bzip2recover.c ---*/
+/*-----------------------------------------------------------*/
+
+/* ------------------------------------------------------------------
+ This file is part of bzip2/libbzip2, a program and library for
+ lossless, block-sorting data compression.
+
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
+
+ Please read the WARNING, DISCLAIMER and PATENTS sections in the
+ README file.
+
+ This program is released under the terms of the license contained
+ in the file LICENSE.
+ ------------------------------------------------------------------ */
+
+/* This program is a complete hack and should be rewritten properly.
+ It isn't very complicated. */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* This program records bit locations in the file to be recovered.
+ That means that if 64-bit ints are not supported, we will not
+ be able to recover .bz2 files over 512MB (2^32 bits) long.
+ On GNU supported platforms, we take advantage of the 64-bit
+ int support to circumvent this problem. Ditto MSVC.
+
+ This change occurred in version 1.0.2; all prior versions have
+ the 512MB limitation.
+*/
+#ifdef __GNUC__
+ typedef unsigned long long int MaybeUInt64;
+# define MaybeUInt64_FMT "%Lu"
+#else
+#ifdef _MSC_VER
+ typedef unsigned __int64 MaybeUInt64;
+# define MaybeUInt64_FMT "%I64u"
+#else
+ typedef unsigned int MaybeUInt64;
+# define MaybeUInt64_FMT "%u"
+#endif
+#endif
+
+typedef unsigned int UInt32;
+typedef int Int32;
+typedef unsigned char UChar;
+typedef char Char;
+typedef unsigned char Bool;
+#define True ((Bool)1)
+#define False ((Bool)0)
+
+
+#define BZ_MAX_FILENAME 2000
+
+Char inFileName[BZ_MAX_FILENAME];
+Char outFileName[BZ_MAX_FILENAME];
+Char progName[BZ_MAX_FILENAME];
+
+MaybeUInt64 bytesOut = 0;
+MaybeUInt64 bytesIn = 0;
+
+
+/*---------------------------------------------------*/
+/*--- Header bytes ---*/
+/*---------------------------------------------------*/
+
+#define BZ_HDR_B 0x42 /* 'B' */
+#define BZ_HDR_Z 0x5a /* 'Z' */
+#define BZ_HDR_h 0x68 /* 'h' */
+#define BZ_HDR_0 0x30 /* '0' */
+
+
+/*---------------------------------------------------*/
+/*--- I/O errors ---*/
+/*---------------------------------------------------*/
+
+/*---------------------------------------------*/
+static void readError ( void )
+{
+ fprintf ( stderr,
+ "%s: I/O error reading `%s', possible reason follows.\n",
+ progName, inFileName );
+ perror ( progName );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void writeError ( void )
+{
+ fprintf ( stderr,
+ "%s: I/O error reading `%s', possible reason follows.\n",
+ progName, inFileName );
+ perror ( progName );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void mallocFail ( Int32 n )
+{
+ fprintf ( stderr,
+ "%s: malloc failed on request for %d bytes.\n",
+ progName, n );
+ fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+/*---------------------------------------------*/
+static void tooManyBlocks ( Int32 max_handled_blocks )
+{
+ fprintf ( stderr,
+ "%s: `%s' appears to contain more than %d blocks\n",
+ progName, inFileName, max_handled_blocks );
+ fprintf ( stderr,
+ "%s: and cannot be handled. To fix, increase\n",
+ progName );
+ fprintf ( stderr,
+ "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
+ progName );
+ exit ( 1 );
+}
+
+
+
+/*---------------------------------------------------*/
+/*--- Bit stream I/O ---*/
+/*---------------------------------------------------*/
+
+typedef
+ struct {
+ FILE* handle;
+ Int32 buffer;
+ Int32 buffLive;
+ Char mode;
+ }
+ BitStream;
+
+
+/*---------------------------------------------*/
+static BitStream* bsOpenReadStream ( FILE* stream )
+{
+ BitStream *bs = malloc ( sizeof(BitStream) );
+ if (bs == NULL) mallocFail ( sizeof(BitStream) );
+ bs->handle = stream;
+ bs->buffer = 0;
+ bs->buffLive = 0;
+ bs->mode = 'r';
+ return bs;
+}
+
+
+/*---------------------------------------------*/
+static BitStream* bsOpenWriteStream ( FILE* stream )
+{
+ BitStream *bs = malloc ( sizeof(BitStream) );
+ if (bs == NULL) mallocFail ( sizeof(BitStream) );
+ bs->handle = stream;
+ bs->buffer = 0;
+ bs->buffLive = 0;
+ bs->mode = 'w';
+ return bs;
+}
+
+
+/*---------------------------------------------*/
+static void bsPutBit ( BitStream* bs, Int32 bit )
+{
+ if (bs->buffLive == 8) {
+ Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
+ if (retVal == EOF) writeError();
+ bytesOut++;
+ bs->buffLive = 1;
+ bs->buffer = bit & 0x1;
+ } else {
+ bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
+ bs->buffLive++;
+ };
+}
+
+
+/*---------------------------------------------*/
+/*--
+ Returns 0 or 1, or 2 to indicate EOF.
+--*/
+static Int32 bsGetBit ( BitStream* bs )
+{
+ if (bs->buffLive > 0) {
+ bs->buffLive --;
+ return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
+ } else {
+ Int32 retVal = getc ( bs->handle );
+ if ( retVal == EOF ) {
+ if (errno != 0) readError();
+ return 2;
+ }
+ bs->buffLive = 7;
+ bs->buffer = retVal;
+ return ( ((bs->buffer) >> 7) & 0x1 );
+ }
+}
+
+
+/*---------------------------------------------*/
+static void bsClose ( BitStream* bs )
+{
+ Int32 retVal;
+
+ if ( bs->mode == 'w' ) {
+ while ( bs->buffLive < 8 ) {
+ bs->buffLive++;
+ bs->buffer <<= 1;
+ };
+ retVal = putc ( (UChar) (bs->buffer), bs->handle );
+ if (retVal == EOF) writeError();
+ bytesOut++;
+ retVal = fflush ( bs->handle );
+ if (retVal == EOF) writeError();
+ }
+ retVal = fclose ( bs->handle );
+ if (retVal == EOF) {
+ if (bs->mode == 'w') writeError(); else readError();
+ }
+ free ( bs );
+}
+
+
+/*---------------------------------------------*/
+static void bsPutUChar ( BitStream* bs, UChar c )
+{
+ Int32 i;
+ for (i = 7; i >= 0; i--)
+ bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
+}
+
+
+/*---------------------------------------------*/
+static void bsPutUInt32 ( BitStream* bs, UInt32 c )
+{
+ Int32 i;
+
+ for (i = 31; i >= 0; i--)
+ bsPutBit ( bs, (c >> i) & 0x1 );
+}
+
+
+/*---------------------------------------------*/
+static Bool endsInBz2 ( Char* name )
+{
+ Int32 n = strlen ( name );
+ if (n <= 4) return False;
+ return
+ (name[n-4] == '.' &&
+ name[n-3] == 'b' &&
+ name[n-2] == 'z' &&
+ name[n-1] == '2');
+}
+
+
+/*---------------------------------------------------*/
+/*--- ---*/
+/*---------------------------------------------------*/
+
+/* This logic isn't really right when it comes to Cygwin. */
+#ifdef _WIN32
+# define BZ_SPLIT_SYM '\\' /* path splitter on Windows platform */
+#else
+# define BZ_SPLIT_SYM '/' /* path splitter on Unix platform */
+#endif
+
+#define BLOCK_HEADER_HI 0x00003141UL
+#define BLOCK_HEADER_LO 0x59265359UL
+
+#define BLOCK_ENDMARK_HI 0x00001772UL
+#define BLOCK_ENDMARK_LO 0x45385090UL
+
+/* Increase if necessary. However, a .bz2 file with > 50000 blocks
+ would have an uncompressed size of at least 40GB, so the chances
+ are low you'll need to up this.
+*/
+#define BZ_MAX_HANDLED_BLOCKS 50000
+
+MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS];
+MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS];
+
+Int32 main ( Int32 argc, Char** argv )
+{
+ FILE* inFile;
+ FILE* outFile;
+ BitStream* bsIn, *bsWr;
+ Int32 b, wrBlock, currBlock, rbCtr;
+ MaybeUInt64 bitsRead;
+
+ UInt32 buffHi, buffLo, blockCRC;
+ Char* p;
+
+ strcpy ( progName, argv[0] );
+ inFileName[0] = outFileName[0] = 0;
+
+ fprintf ( stderr,
+ "bzip2recover 1.0.6: extracts blocks from damaged .bz2 files.\n" );
+
+ if (argc != 2) {
+ fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
+ progName, progName );
+ switch (sizeof(MaybeUInt64)) {
+ case 8:
+ fprintf(stderr,
+ "\trestrictions on size of recovered file: None\n");
+ break;
+ case 4:
+ fprintf(stderr,
+ "\trestrictions on size of recovered file: 512 MB\n");
+ fprintf(stderr,
+ "\tto circumvent, recompile with MaybeUInt64 as an\n"
+ "\tunsigned 64-bit int.\n");
+ break;
+ default:
+ fprintf(stderr,
+ "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
+ "configuration error.\n");
+ break;
+ }
+ exit(1);
+ }
+
+ if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
+ fprintf ( stderr,
+ "%s: supplied filename is suspiciously (>= %d chars) long. Bye!\n",
+ progName, (int)strlen(argv[1]) );
+ exit(1);
+ }
+
+ strcpy ( inFileName, argv[1] );
+
+ inFile = fopen ( inFileName, "rb" );
+ if (inFile == NULL) {
+ fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
+ exit(1);
+ }
+
+ bsIn = bsOpenReadStream ( inFile );
+ fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
+
+ bitsRead = 0;
+ buffHi = buffLo = 0;
+ currBlock = 0;
+ bStart[currBlock] = 0;
+
+ rbCtr = 0;
+
+ while (True) {
+ b = bsGetBit ( bsIn );
+ bitsRead++;
+ if (b == 2) {
+ if (bitsRead >= bStart[currBlock] &&
+ (bitsRead - bStart[currBlock]) >= 40) {
+ bEnd[currBlock] = bitsRead-1;
+ if (currBlock > 0)
+ fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
+ " to " MaybeUInt64_FMT " (incomplete)\n",
+ currBlock, bStart[currBlock], bEnd[currBlock] );
+ } else
+ currBlock--;
+ break;
+ }
+ buffHi = (buffHi << 1) | (buffLo >> 31);
+ buffLo = (buffLo << 1) | (b & 1);
+ if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
+ && buffLo == BLOCK_HEADER_LO)
+ ||
+ ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
+ && buffLo == BLOCK_ENDMARK_LO)
+ ) {
+ if (bitsRead > 49) {
+ bEnd[currBlock] = bitsRead-49;
+ } else {
+ bEnd[currBlock] = 0;
+ }
+ if (currBlock > 0 &&
+ (bEnd[currBlock] - bStart[currBlock]) >= 130) {
+ fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
+ " to " MaybeUInt64_FMT "\n",
+ rbCtr+1, bStart[currBlock], bEnd[currBlock] );
+ rbStart[rbCtr] = bStart[currBlock];
+ rbEnd[rbCtr] = bEnd[currBlock];
+ rbCtr++;
+ }
+ if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
+ tooManyBlocks(BZ_MAX_HANDLED_BLOCKS);
+ currBlock++;
+
+ bStart[currBlock] = bitsRead;
+ }
+ }
+
+ bsClose ( bsIn );
+
+ /*-- identified blocks run from 1 to rbCtr inclusive. --*/
+
+ if (rbCtr < 1) {
+ fprintf ( stderr,
+ "%s: sorry, I couldn't find any block boundaries.\n",
+ progName );
+ exit(1);
+ };
+
+ fprintf ( stderr, "%s: splitting into blocks\n", progName );
+
+ inFile = fopen ( inFileName, "rb" );
+ if (inFile == NULL) {
+ fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName );
+ exit(1);
+ }
+ bsIn = bsOpenReadStream ( inFile );
+
+ /*-- placate gcc's dataflow analyser --*/
+ blockCRC = 0; bsWr = 0;
+
+ bitsRead = 0;
+ outFile = NULL;
+ wrBlock = 0;
+ while (True) {
+ b = bsGetBit(bsIn);
+ if (b == 2) break;
+ buffHi = (buffHi << 1) | (buffLo >> 31);
+ buffLo = (buffLo << 1) | (b & 1);
+ if (bitsRead == 47+rbStart[wrBlock])
+ blockCRC = (buffHi << 16) | (buffLo >> 16);
+
+ if (outFile != NULL && bitsRead >= rbStart[wrBlock]
+ && bitsRead <= rbEnd[wrBlock]) {
+ bsPutBit ( bsWr, b );
+ }
+
+ bitsRead++;
+
+ if (bitsRead == rbEnd[wrBlock]+1) {
+ if (outFile != NULL) {
+ bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
+ bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
+ bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
+ bsPutUInt32 ( bsWr, blockCRC );
+ bsClose ( bsWr );
+ }
+ if (wrBlock >= rbCtr) break;
+ wrBlock++;
+ } else
+ if (bitsRead == rbStart[wrBlock]) {
+ /* Create the output file name, correctly handling leading paths.
+ (31.10.2001 by Sergey E. Kusikov) */
+ Char* split;
+ Int32 ofs, k;
+ for (k = 0; k < BZ_MAX_FILENAME; k++)
+ outFileName[k] = 0;
+ strcpy (outFileName, inFileName);
+ split = strrchr (outFileName, BZ_SPLIT_SYM);
+ if (split == NULL) {
+ split = outFileName;
+ } else {
+ ++split;
+ }
+ /* Now split points to the start of the basename. */
+ ofs = split - outFileName;
+ sprintf (split, "rec%5d", wrBlock+1);
+ for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
+ strcat (outFileName, inFileName + ofs);
+
+ if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
+
+ fprintf ( stderr, " writing block %d to `%s' ...\n",
+ wrBlock+1, outFileName );
+
+ outFile = fopen ( outFileName, "wb" );
+ if (outFile == NULL) {
+ fprintf ( stderr, "%s: can't write `%s'\n",
+ progName, outFileName );
+ exit(1);
+ }
+ bsWr = bsOpenWriteStream ( outFile );
+ bsPutUChar ( bsWr, BZ_HDR_B );
+ bsPutUChar ( bsWr, BZ_HDR_Z );
+ bsPutUChar ( bsWr, BZ_HDR_h );
+ bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
+ bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
+ bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
+ bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
+ }
+ }
+
+ fprintf ( stderr, "%s: finished\n", progName );
+ return 0;
+}
+
+
+
+/*-----------------------------------------------------------*/
+/*--- end bzip2recover.c ---*/
+/*-----------------------------------------------------------*/
diff --git a/dep/bzip2/bzlib.c b/dep/bzip2/bzlib.c
index ef86c91e695..bd358a793b8 100644
--- a/dep/bzip2/bzlib.c
+++ b/dep/bzip2/bzlib.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/bzlib.h b/dep/bzip2/bzlib.h
index c5b75d6d8ff..8277123da8c 100644
--- a/dep/bzip2/bzlib.h
+++ b/dep/bzip2/bzlib.h
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/bzlib_private.h b/dep/bzip2/bzlib_private.h
index 23427879b18..5d0217f4635 100644
--- a/dep/bzip2/bzlib_private.h
+++ b/dep/bzip2/bzlib_private.h
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -36,7 +36,7 @@
/*-- General stuff. --*/
-#define BZ_VERSION "1.0.5, 10-Dec-2007"
+#define BZ_VERSION "1.0.6, 6-Sept-2010"
typedef char Char;
typedef unsigned char Bool;
diff --git a/dep/bzip2/compress.c b/dep/bzip2/compress.c
index 8c80a079700..caf7696011b 100644
--- a/dep/bzip2/compress.c
+++ b/dep/bzip2/compress.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/crctable.c b/dep/bzip2/crctable.c
index 215687b2c05..1fea7e946c5 100644
--- a/dep/bzip2/crctable.c
+++ b/dep/bzip2/crctable.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/decompress.c b/dep/bzip2/decompress.c
index bba5e0fa36d..311f5668f9a 100644
--- a/dep/bzip2/decompress.c
+++ b/dep/bzip2/decompress.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -381,6 +381,13 @@ Int32 BZ2_decompress ( DState* s )
es = -1;
N = 1;
do {
+ /* Check that N doesn't get too big, so that es doesn't
+ go negative. The maximum value that can be
+ RUNA/RUNB encoded is equal to the block size (post
+ the initial RLE), viz, 900k, so bounding N at 2
+ million should guard against overflow without
+ rejecting any legitimate inputs. */
+ if (N >= 2*1024*1024) RETURN(BZ_DATA_ERROR);
if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
if (nextSym == BZ_RUNB) es = es + (1+1) * N;
N = N * 2;
@@ -485,15 +492,28 @@ Int32 BZ2_decompress ( DState* s )
RETURN(BZ_DATA_ERROR);
/*-- Set up cftab to facilitate generation of T^(-1) --*/
+ /* Check: unzftab entries in range. */
+ for (i = 0; i <= 255; i++) {
+ if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
+ RETURN(BZ_DATA_ERROR);
+ }
+ /* Actually generate cftab. */
s->cftab[0] = 0;
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
+ /* Check: cftab entries in range. */
for (i = 0; i <= 256; i++) {
if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
/* s->cftab[i] can legitimately be == nblock */
RETURN(BZ_DATA_ERROR);
}
}
+ /* Check: cftab entries non-descending. */
+ for (i = 1; i <= 256; i++) {
+ if (s->cftab[i-1] > s->cftab[i]) {
+ RETURN(BZ_DATA_ERROR);
+ }
+ }
s->state_out_len = 0;
s->state_out_ch = 0;
diff --git a/dep/bzip2/huffman.c b/dep/bzip2/huffman.c
index 87e79e38af0..2283fdbc5a1 100644
--- a/dep/bzip2/huffman.c
+++ b/dep/bzip2/huffman.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/bzip2/randtable.c b/dep/bzip2/randtable.c
index 068b76367bc..6d624599061 100644
--- a/dep/bzip2/randtable.c
+++ b/dep/bzip2/randtable.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/dep/g3dlite/include/G3D/AABox.h b/dep/g3dlite/include/G3D/AABox.h
index 2e8da1f6098..d57320d73eb 100644
--- a/dep/g3dlite/include/G3D/AABox.h
+++ b/dep/g3dlite/include/G3D/AABox.h
@@ -20,6 +20,7 @@
#include "G3D/debug.h"
#include "G3D/Array.h"
#include "G3D/Plane.h"
+#include "G3D/Sphere.h"
namespace G3D {
@@ -259,6 +260,8 @@ public:
void getBounds(AABox& out) const {
out = *this;
}
+
+ void getBounds(Sphere& out) const;
};
}
diff --git a/dep/g3dlite/include/G3D/Any.h b/dep/g3dlite/include/G3D/Any.h
index c267eedd22f..e2d0fbe7e62 100644
--- a/dep/g3dlite/include/G3D/Any.h
+++ b/dep/g3dlite/include/G3D/Any.h
@@ -17,7 +17,9 @@
#include "G3D/platform.h"
#include "G3D/Table.h"
#include "G3D/Array.h"
+#include "G3D/Set.h"
#include "G3D/AtomicInt32.h"
+#include "G3D/stringutils.h"
#include <string>
// needed for Token
@@ -448,7 +450,6 @@ public:
*/
std::string resolveStringAsFilename() const;
-
/** If this is named ARRAY or TABLE, returns the name. */
const std::string& name() const;
@@ -518,7 +519,7 @@ public:
// Needed to prevent the operator[](int) overload from catching
// string literals
- inline const Any& operator[](const char* key) const {
+ const Any& operator[](const char* key) const {
return operator[](std::string(key));
}
@@ -548,7 +549,7 @@ public:
Any& operator[](const std::string& key);
/** \copydoc Any::operator[](const std::string&) */
- inline Any& operator[](const char* key) {
+ Any& operator[](const char* key) {
return operator[](std::string(key));
}
@@ -636,6 +637,124 @@ private:
}; // class Any
+
+/**
+ Convenient iteration over the keys of a Any::TABLE, usually
+ for implementing construction of an object from an Any.
+
+ Getting an element using either iteration or explicit requests
+ consumes that element from the iterator (but not from the Any!)
+ It is an error to consume the same element more than once from
+ the same iterator.
+
+ <pre>
+ AnyKeyIterator r(a);
+ r.getIfPresent("enabled", enabled);
+ r.getIfPresent("showSamples", showSamples);
+ r.getIfPresent("showTiles", showTiles);
+
+ r.verifyDone();
+ </pre>
+
+ \beta
+*/
+class AnyTableReader {
+private:
+ Any m_any;
+ Set<std::string> m_alreadyRead;
+public:
+
+ /** Verifies that \a is a TABLE with the given \a name. */
+ AnyTableReader(const std::string& name, const Any& a) : m_any(a) {
+ try {
+ m_any.verifyType(Any::TABLE);
+ m_any.verifyName(name);
+ } catch (const ParseError& e) {
+ // If an exception is thrown, the destructors will not be
+ // invoked automatically.
+ m_any.~Any();
+ m_alreadyRead.~Set();
+ throw e;
+ }
+ }
+
+ /** Verifies that \a is a TABLE. */
+ AnyTableReader(const Any& a) : m_any(a) {
+ try {
+ m_any.verifyType(Any::TABLE);
+ } catch (const ParseError& e) {
+ // If an exception is thrown, the destructors will not be
+ // invoked automatically.
+ m_any.~Any();
+ m_alreadyRead.~Set();
+ throw e;
+ }
+ }
+
+ bool hasMore() const {
+ return m_any.size() > m_alreadyRead.size();
+ }
+
+ /** Verifies that all keys have been read. */
+ void verifyDone() const {
+ if (hasMore()) {
+ // Generate all keys
+ // Remove the ones we've read
+ // Assert the rest
+ // any.verify("");
+ }
+ }
+
+#if 0
+ /** Returns the current key */
+ const std::string& key() const;
+
+ /** Returns the current value */
+ const Any& value() const;
+
+ AnyKeyIterator& operator++();
+#endif
+
+ /** If key \s appears in the any, reads its value into \a v and
+ removes that key from the ones available to iterate over.
+
+ If key \s does not appear in the any, throws a G3D::ParseError.
+
+ Assumes that if key \s appears in the any it has not already been extracted
+ by this iterator. If it has been read before, an assertion will fail in debug mode.
+
+ */
+ template<class ValueType>
+ void get(const std::string& s, ValueType& v) {
+ v = m_any[s];
+ m_alreadyRead.insert(toLower(s));
+ }
+
+ /** Get the value associated with a key only if the key is actually present.
+
+ If key \s appears in the any, reads its value into \a v and
+ removes that key from the ones available to iterate over.
+
+ If key \s does not appear in the any, does nothing.
+
+ Assumes that if key \s appears in the any it has not already been extracted
+ by this iterator. If it has been read before, an assertion will fail in debug mode.
+
+ \return True if the value was read.
+ */
+ template<class ValueType>
+ bool getIfPresent(const std::string& s, ValueType& v) {
+ if (m_any.containsKey(s)) {
+ debugAssertM(! m_alreadyRead.contains(toLower(s)), "read twice");
+
+ get(s, v);
+ return true;
+ } else {
+ return false;
+ }
+ }
+};
+
} // namespace G3D
#endif
diff --git a/dep/g3dlite/include/G3D/PointHashGrid.h b/dep/g3dlite/include/G3D/PointHashGrid.h
index 5b128d1b5d9..d0b60a88ae5 100644
--- a/dep/g3dlite/include/G3D/PointHashGrid.h
+++ b/dep/g3dlite/include/G3D/PointHashGrid.h
@@ -360,7 +360,7 @@ public:
m_arrayIndex(0), m_epoch(0) {}
Iterator(const ThisType* grid) :
- m_isEnd(false),
+ m_isEnd(grid->size() == 0),
m_grid(grid),
m_tableIterator( grid->m_data.begin() ),
m_arrayIndex(0),
@@ -387,6 +387,10 @@ public:
}
}
+ bool hasMore() const {
+ return ! m_isEnd;
+ }
+
bool operator==(const Iterator& other) const {
return !(*this != other);
}
diff --git a/dep/g3dlite/include/G3D/Quat.inl b/dep/g3dlite/include/G3D/Quat.inl
deleted file mode 100644
index 9e4c861d93b..00000000000
--- a/dep/g3dlite/include/G3D/Quat.inl
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- Quat.inl
-
- @cite Quaternion implementation based on Watt & Watt page 363.
- Thanks to Max McGuire for slerp optimizations.
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
- @created 2002-01-23
- @edited 2004-03-04
- */
-
-namespace G3D {
-
-inline float& Quat::operator[] (int i) {
- debugAssert(i >= 0);
- debugAssert(i < 4);
- return ((float*)this)[i];
-}
-
-inline const float& Quat::operator[] (int i) const {
- debugAssert(i >= 0);
- debugAssert(i < 4);
- return ((float*)this)[i];
-}
-
-inline Quat Quat::operator-(const Quat& other) const {
- return Quat(x - other.x, y - other.y, z - other.z, w - other.w);
-}
-
-inline Quat Quat::operator+(const Quat& other) const {
- return Quat(x + other.x, y + other.y, z + other.z, w + other.w);
-}
-
-}
-
diff --git a/dep/g3dlite/include/G3D/Sphere.h b/dep/g3dlite/include/G3D/Sphere.h
index 595b61c4bf1..d1448261d9f 100644
--- a/dep/g3dlite/include/G3D/Sphere.h
+++ b/dep/g3dlite/include/G3D/Sphere.h
@@ -15,7 +15,6 @@
#include "G3D/platform.h"
#include "G3D/Vector3.h"
#include "G3D/Array.h"
-#include "G3D/Sphere.h"
namespace G3D {
diff --git a/dep/g3dlite/include/G3D/Table.h b/dep/g3dlite/include/G3D/Table.h
index 896a5a2a08a..ab0b114b1c4 100644
--- a/dep/g3dlite/include/G3D/Table.h
+++ b/dep/g3dlite/include/G3D/Table.h
@@ -86,12 +86,11 @@ namespace G3D {
<PRE>
template<> struct HashTrait<MyEnum> {
- static size_t equals(const MyEnum& key) const { return reinterpret_cast<size_t>( key ); }
+ static size_t hashCode(const MyEnum& key) const { return reinterpret_cast<size_t>( key ); }
};
</PRE>
- And rely on the default enum operator==.
-
+ and rely on the default enum operator==.
Periodically check that debugGetLoad() is low (> 0.1). When it gets near
1.0 your hash function is badly designed and maps too many inputs to
diff --git a/dep/g3dlite/include/G3D/Vector2.inl b/dep/g3dlite/include/G3D/Vector2.inl
deleted file mode 100644
index 4f7c55a39cf..00000000000
--- a/dep/g3dlite/include/G3D/Vector2.inl
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- @file Vector2.inl
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
- @cite Portions by Laura Wollstadt, graphics3d.com
-
- @cite Portions based on Dave Eberly'x Magic Software Library
- at http://www.magic-software.com
-
- @created 2001-06-02
- @edited 2006-01-14
-
- Copyright 2000-2006, Morgan McGuire.
- All rights reserved.
- */
-
-}
-
diff --git a/dep/g3dlite/include/G3D/Vector3.inl b/dep/g3dlite/include/G3D/Vector3.inl
deleted file mode 100644
index 9211c2a70fd..00000000000
--- a/dep/g3dlite/include/G3D/Vector3.inl
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- @file Vector3.inl
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
- @cite Portions based on Dave Eberly's Magic Software Library at http://www.magic-software.com
-
- @created 2001-06-02
- @edited 2004-05-21
- Copyright 2000-2004, Morgan McGuire.
- All rights reserved.
- */
-
-//----------------------------------------------------------------------------
-#ifdef SSE
- // If you receive an error on this line, it is because you do not have the file
- // xmmintrin.h needed for MMX & SSE extensions. Download and install
- //
- // http://download.microsoft.com/download/vstudio60ent/SP5/Wideband-Full/WIN98Me/EN-US/vs6sp5.exe
- // and
- // http://download.microsoft.com/download/vb60ent/Update/6/W9X2KXP/EN-US/vcpp5.exe
- //
- // to get this file.
-# include <xmmintrin.h>
-#endif
-
-inline unsigned int hashCode(const G3D::Vector3& v) {
- return v.hashCode();
-}
-
-namespace G3D {
-
-//----------------------------------------------------------------------------
-inline Vector3::Vector3() : x(0.0f), y(0.0f), z(0.0f) {
-}
-
-//----------------------------------------------------------------------------
-
-inline Vector3::Vector3 (float fX, float fY, float fZ) : x(fX), y(fY), z(fZ) {
-}
-
-//----------------------------------------------------------------------------
-inline Vector3::Vector3 (float V[3]) : x(V[0]), y(V[1]), z(V[2]){
-}
-//----------------------------------------------------------------------------
-inline Vector3::Vector3 (double V[3]) : x((float)V[0]), y((float)V[1]), z((float)V[2]){
-}
-
-//----------------------------------------------------------------------------
-inline Vector3::Vector3 (const Vector3& V) : x(V.x), y(V.y), z(V.z) {
-}
-
-//----------------------------------------------------------------------------
-
-//inline Vector3::Vector3 (const __m128& m) {
- // Cast from SSE packed floats
-// *this = *(Vector3*)&m;
-//}
-
-//----------------------------------------------------------------------------
-inline const float& Vector3::operator[] (int i) const {
- return ((float*)this)[i];
-}
-
-inline float& Vector3::operator[] (int i) {
- return ((float*)this)[i];
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator= (const Vector3& rkVector) {
- x = rkVector.x;
- y = rkVector.y;
- z = rkVector.z;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector3::fuzzyEq(const Vector3& other) const {
- return G3D::fuzzyEq((*this - other).squaredMagnitude(), 0);
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector3::fuzzyNe(const Vector3& other) const {
- return G3D::fuzzyNe((*this - other).squaredMagnitude(), 0);
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector3::isFinite() const {
- return G3D::isFinite(x) && G3D::isFinite(y) && G3D::isFinite(z);
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector3::operator== (const Vector3& rkVector) const {
- return ( x == rkVector.x && y == rkVector.y && z == rkVector.z );
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector3::operator!= (const Vector3& rkVector) const {
- return ( x != rkVector.x || y != rkVector.y || z != rkVector.z );
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::operator+ (const Vector3& rkVector) const {
- return Vector3(x + rkVector.x, y + rkVector.y, z + rkVector.z);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::operator- (const Vector3& rkVector) const {
- return Vector3(x - rkVector.x, y - rkVector.y, z - rkVector.z);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::operator* (const Vector3& rkVector) const {
- return Vector3(x * rkVector.x, y * rkVector.y, z * rkVector.z);
-}
-
-inline Vector3 Vector3::operator*(float f) const {
- return Vector3(x * f, y * f, z * f);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::operator/ (const Vector3& rkVector) const {
- return Vector3(x / rkVector.x, y / rkVector.y, z / rkVector.z);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::operator- () const {
- return Vector3(-x, -y, -z);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator+= (const Vector3& rkVector) {
- x += rkVector.x;
- y += rkVector.y;
- z += rkVector.z;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator-= (const Vector3& rkVector) {
- x -= rkVector.x;
- y -= rkVector.y;
- z -= rkVector.z;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator*= (float fScalar) {
- x *= fScalar;
- y *= fScalar;
- z *= fScalar;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator*= (const Vector3& rkVector) {
- x *= rkVector.x;
- y *= rkVector.y;
- z *= rkVector.z;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3& Vector3::operator/= (const Vector3& rkVector) {
- x /= rkVector.x;
- y /= rkVector.y;
- z /= rkVector.z;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline float Vector3::squaredMagnitude () const {
- return x*x + y*y + z*z;
-}
-
-//----------------------------------------------------------------------------
-inline float Vector3::squaredLength () const {
- return squaredMagnitude();
-}
-
-//----------------------------------------------------------------------------
-inline float Vector3::magnitude() const {
- return sqrtf(x*x + y*y + z*z);
-}
-
-//----------------------------------------------------------------------------
-inline float Vector3::length() const {
- return magnitude();
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::direction () const {
- float lenSquared = squaredMagnitude();
- float invSqrt = 1.0f / sqrtf(lenSquared);
- return Vector3(x * invSqrt, y * invSqrt, z * invSqrt);
-}
-
-//----------------------------------------------------------------------------
-
-inline Vector3 Vector3::fastDirection () const {
- float lenSquared = x * x + y * y + z * z;
- float invSqrt = rsq(lenSquared);
- return Vector3(x * invSqrt, y * invSqrt, z * invSqrt);
-}
-
-//----------------------------------------------------------------------------
-inline float Vector3::dot (const Vector3& rkVector) const {
- return x*rkVector.x + y*rkVector.y + z*rkVector.z;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::cross (const Vector3& rkVector) const {
- return Vector3(y*rkVector.z - z*rkVector.y, z*rkVector.x - x*rkVector.z,
- x*rkVector.y - y*rkVector.x);
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::unitCross (const Vector3& rkVector) const {
- Vector3 kCross(y*rkVector.z - z*rkVector.y, z*rkVector.x - x*rkVector.z,
- x*rkVector.y - y*rkVector.x);
- kCross.unitize();
- return kCross;
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::min(const Vector3 &v) const {
- return Vector3(G3D::min(v.x, x), G3D::min(v.y, y), G3D::min(v.z, z));
-}
-
-//----------------------------------------------------------------------------
-inline Vector3 Vector3::max(const Vector3 &v) const {
- return Vector3(G3D::max(v.x, x), G3D::max(v.y, y), G3D::max(v.z, z));
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector3::isZero() const {
- return G3D::fuzzyEq(squaredMagnitude(), 0.0f);
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector3::isUnit() const {
- return G3D::fuzzyEq(squaredMagnitude(), 1.0f);
-}
-
-} // namespace
diff --git a/dep/g3dlite/include/G3D/Vector4.inl b/dep/g3dlite/include/G3D/Vector4.inl
deleted file mode 100644
index 576cca83b56..00000000000
--- a/dep/g3dlite/include/G3D/Vector4.inl
+++ /dev/null
@@ -1,191 +0,0 @@
-/**
- @file Vector4.inl
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
- @created 2002-07-09
- @edited 2003-02-10
- */
-
-//----------------------------------------------------------------------------
-
-inline unsigned int hashCode(const G3D::Vector4& v) {
- return v.hashCode();
-}
-
-namespace G3D {
-
-//----------------------------------------------------------------------------
-inline Vector4::Vector4() {
- x = y = z = w = 0;
-}
-
-//----------------------------------------------------------------------------
-
-inline Vector4::Vector4 (float fX, float fY, float fZ, float fW) {
- x = fX;
- y = fY;
- z = fZ;
- w = fW;
-}
-
-//----------------------------------------------------------------------------
-inline Vector4::Vector4 (float afCoordinate[4]) {
- x = afCoordinate[0];
- y = afCoordinate[1];
- z = afCoordinate[2];
- w = afCoordinate[3];
-}
-
-//----------------------------------------------------------------------------
-inline Vector4::Vector4(const Vector4& rkVector) {
- x = rkVector.x;
- y = rkVector.y;
- z = rkVector.z;
- w = rkVector.w;
-}
-//----------------------------------------------------------------------------
-inline Vector4::Vector4(const Vector3& rkVector, float fW) {
- x = rkVector.x;
- y = rkVector.y;
- z = rkVector.z;
- w = fW;
-}
-
-//----------------------------------------------------------------------------
-inline float& Vector4::operator[] (int i) {
- return ((float*)this)[i];
-}
-
-//----------------------------------------------------------------------------
-inline const float& Vector4::operator[] (int i) const {
- return ((float*)this)[i];
-}
-
-//----------------------------------------------------------------------------
-inline Vector4::operator float* () {
- return (float*)this;
-}
-
-inline Vector4::operator const float* () const {
- return (float*)this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector4& Vector4::operator= (const Vector4& rkVector) {
- x = rkVector.x;
- y = rkVector.y;
- z = rkVector.z;
- w = rkVector.w;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector4::operator== (const Vector4& rkVector) const {
- return ( (x == rkVector.x) && (y == rkVector.y) && (z == rkVector.z) && (w == rkVector.w));
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector4::operator!= (const Vector4& rkVector) const {
- return ( x != rkVector.x || y != rkVector.y || z != rkVector.z || w != rkVector.w);
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::operator+ (const Vector4& rkVector) const {
- return Vector4(x + rkVector.x, y + rkVector.y, z + rkVector.z, w + rkVector.w);
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::operator- (const Vector4& rkVector) const {
- return Vector4(x - rkVector.x, y - rkVector.y, z - rkVector.z, w - rkVector.w);
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::operator* (float fScalar) const {
- return Vector4(fScalar*x, fScalar*y, fScalar*z, fScalar*w);
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::operator- () const {
- return Vector4( -x, -y, -z, -w);
-}
-
-//----------------------------------------------------------------------------
-inline Vector4& Vector4::operator+= (const Vector4& rkVector) {
- x += rkVector.x;
- y += rkVector.y;
- z += rkVector.z;
- w += rkVector.w;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline Vector4& Vector4::operator-= (const Vector4& rkVector) {
- x -= rkVector.x;
- y -= rkVector.y;
- z -= rkVector.z;
- w -= rkVector.w;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-
-inline Vector4 Vector4::lerp(const Vector4& v, float alpha) const {
- return (*this) + (v - *this) * alpha;
-}
-
-//----------------------------------------------------------------------------
-inline Vector4& Vector4::operator*= (float fScalar) {
- x *= fScalar;
- y *= fScalar;
- z *= fScalar;
- w *= fScalar;
- return *this;
-}
-
-//----------------------------------------------------------------------------
-inline float Vector4::dot(const Vector4& rkVector) const {
- return x*rkVector.x + y*rkVector.y + z*rkVector.z + w*rkVector.w;
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::min(const Vector4 &v) const {
- return Vector4(G3D::min(v.x, x), G3D::min(v.y, y), G3D::min(v.z, z), G3D::min(v.w, w));
-}
-
-//----------------------------------------------------------------------------
-inline Vector4 Vector4::max(const Vector4 &v) const {
- return Vector4(G3D::max(v.x, x), G3D::max(v.y, y), G3D::max(v.z, z), G3D::max(v.w, w));
-}
-
-//----------------------------------------------------------------------------
-inline bool Vector4::isZero() const {
- return (x == 0.0f) && (y == 0.0f) && (z == 0.0f) && (w == 0.0f);
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector4::isFinite() const {
- return G3D::isFinite(x) && G3D::isFinite(y) && G3D::isFinite(z) && G3D::isFinite(w);
-}
-
-//----------------------------------------------------------------------------
-
-inline bool Vector4::isUnit() const {
- return squaredLength() == 1.0;
-}
-
-//----------------------------------------------------------------------------
-
-inline float Vector4::length() const {
- return sqrtf(squaredLength());
-}
-
-//----------------------------------------------------------------------------
-
-inline float Vector4::squaredLength() const {
- return x * x + y * y + z * z + w * w;
-}
-
-}
-
diff --git a/dep/g3dlite/include/G3D/g3dmath.inl b/dep/g3dlite/include/G3D/g3dmath.inl
deleted file mode 100644
index 9bf661a7ebc..00000000000
--- a/dep/g3dlite/include/G3D/g3dmath.inl
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- @file g3dmath.inl
-
- @maintainer Morgan McGuire, matrix@graphics3d.com
-
- @created 2001-06-02
- @edited 2006-01-14
- */
-
-#include <stdlib.h>
-
-#ifdef _MSC_VER
-// Disable conditional expression is constant, which occurs incorrectly on inlined functions
-# pragma warning (push)
-# pragma warning( disable : 4127 )
-#endif
-
-namespace G3D {
-
-inline bool isNaN(double x) {
- bool b1 = (x < 0.0);
- bool b2 = (x >= 0.0);
- bool b3 = !(b1 || b2);
- return b3;
-}
-
-inline bool isFinite(double x) {
- return ! isNaN(x) && (x < G3D::inf()) && (x > -G3D::inf());
-}
-
-//----------------------------------------------------------------------------
-inline int iAbs (int iValue) {
- return ( iValue >= 0 ? iValue : -iValue );
-}
-
-//----------------------------------------------------------------------------
-inline int iCeil (double fValue) {
- return int(::ceil(fValue));
-}
-
-//----------------------------------------------------------------------------
-
-inline int iClamp(int val, int low, int hi) {
- debugAssert(low <= hi);
- if (val <= low) {
- return low;
- } else if (val >= hi) {
- return hi;
- } else {
- return val;
- }
-}
-
-//----------------------------------------------------------------------------
-
-inline double clamp(double val, double low, double hi) {
- debugAssert(low <= hi);
- if (val <= low) {
- return low;
- } else if (val >= hi) {
- return hi;
- } else {
- return val;
- }
-}
-
-inline float clamp(float val, float low, float hi) {
- debugAssert(low <= hi);
- if (val <= low) {
- return low;
- } else if (val >= hi) {
- return hi;
- } else {
- return val;
- }
-}
-//----------------------------------------------------------------------------
-
-inline int iWrap(int val, int hi) {
- if (val < 0) {
- return ((val % hi) + hi) % hi;
- } else {
- return val % hi;
- }
-}
-
-//----------------------------------------------------------------------------
-inline int iFloor (double fValue) {
- return int(::floor(fValue));
-}
-
-//----------------------------------------------------------------------------
-inline int iSign (int iValue) {
- return ( iValue > 0 ? + 1 : ( iValue < 0 ? -1 : 0 ) );
-}
-
-inline int iSign (double fValue) {
- return ( fValue > 0.0 ? + 1 : ( fValue < 0.0 ? -1 : 0 ) );
-}
-
-//----------------------------------------------------------------------------
-inline double abs (double fValue) {
- return double(::fabs(fValue));
-}
-
-//----------------------------------------------------------------------------
-inline double aCos (double fValue) {
- if ( -1.0 < fValue ) {
- if ( fValue < 1.0 )
- return double(::acos(fValue));
- else
- return 0.0;
- } else {
- return G3D_PI;
- }
-}
-
-//----------------------------------------------------------------------------
-inline double aSin (double fValue) {
- if ( -1.0 < fValue ) {
- if ( fValue < 1.0 ) {
- return double(::asin(fValue));
- } else {
- return -G3D_HALF_PI;
- }
- } else {
- return G3D_HALF_PI;
- }
-}
-
-//----------------------------------------------------------------------------
-inline double aTan (double fValue) {
- return double(::atan(fValue));
-}
-
-//----------------------------------------------------------------------------
-inline double aTan2 (double fY, double fX) {
- return double(::atan2(fY, fX));
-}
-
-//----------------------------------------------------------------------------
-inline double sign (double fValue) {
- if (fValue > 0.0) {
- return 1.0;
- }
-
- if (fValue < 0.0) {
- return -1.0;
- }
-
- return 0.0;
-}
-
-inline double G3D_DEPRECATED unitRandom () {
- return double(::rand()) / double(RAND_MAX);
-}
-
-inline float uniformRandom(float low, float hi) {
- return (hi - low) * float(::rand()) / float(RAND_MAX) + low;
-}
-
-//----------------------------------------------------------------------------
-inline double G3D_DEPRECATED symmetricRandom () {
- return 2.0 * double(::rand()) / double(RAND_MAX) - 1.0;
-}
-
-//----------------------------------------------------------------------------
-inline double square(double x) {
- return x * x;
-}
-
-//----------------------------------------------------------------------------
-inline double sumSquares(double x, double y) {
- return x*x + y*y;
-}
-
-//----------------------------------------------------------------------------
-inline double sumSquares(double x, double y, double z) {
- return x*x + y*y + z*z;
-}
-
-//----------------------------------------------------------------------------
-inline double distance(double x, double y) {
- return sqrt(sumSquares(x, y));
-}
-
-//----------------------------------------------------------------------------
-inline double distance(double x, double y, double z) {
- return sqrt(sumSquares(x, y, z));
-}
-
-//----------------------------------------------------------------------------
-
-/** @deprecated use G3D::min */
-inline int iMin(int x, int y) {
- return (x >= y) ? y : x;
-}
-
-//----------------------------------------------------------------------------
-/** @deprecated use G3D::min */
-inline int iMax(int x, int y) {
- return (x >= y) ? x : y;
-}
-
-//----------------------------------------------------------------------------
-inline int ceilPow2(unsigned int in) {
- in -= 1;
-
- in |= in >> 16;
- in |= in >> 8;
- in |= in >> 4;
- in |= in >> 2;
- in |= in >> 1;
-
- return in + 1;
-}
-
-inline bool isPow2(int num) {
- return ((num & -num) == num);
-}
-
-inline bool isOdd(int num) {
- return (num & 1) == 1;
-}
-
-inline bool isEven(int num) {
- return (num & 1) == 0;
-}
-
-inline double toRadians(double deg) {
- return deg * G3D_PI / 180.0;
-}
-
-inline double toDegrees(double rad) {
- return rad * 180.0 / G3D_PI;
-}
-
-/**
- Computes an appropriate epsilon for comparing a and b.
- */
-inline double eps(double a, double b) {
- // For a and b to be nearly equal, they must have nearly
- // the same magnitude. This means that we can ignore b
- // since it either has the same magnitude or the comparison
- // will fail anyway.
- (void)b;
- const double aa = abs(a) + 1;
- if (aa == inf()) {
- return fuzzyEpsilon;
- } else {
- return fuzzyEpsilon * aa;
- }
-}
-
-inline bool fuzzyEq(double a, double b) {
- return (a == b) || (abs(a - b) <= eps(a, b));
-}
-
-inline bool fuzzyNe(double a, double b) {
- return ! fuzzyEq(a, b);
-}
-
-inline bool fuzzyGt(double a, double b) {
- return a > b + eps(a, b);
-}
-
-inline bool fuzzyGe(double a, double b) {
- return a > b - eps(a, b);
-}
-
-inline bool fuzzyLt(double a, double b) {
- return a < b - eps(a, b);
-}
-
-inline bool fuzzyLe(double a, double b) {
- return a < b + eps(a, b);
-}
-
-inline int iMod3(int x) {
- return x % 3;
-}
-
-} // namespace G3D
-
-#ifdef _MSC_VER
-// Disable conditional expression is constant, which occurs incorrectly on inlined functions
-# pragma warning (pop)
-#endif
diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h
index d399135101b..c8d2f0b6534 100644
--- a/dep/g3dlite/include/G3D/platform.h
+++ b/dep/g3dlite/include/G3D/platform.h
@@ -6,7 +6,7 @@
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2003-06-09
- @edited 2010-01-11
+ @edited 2010-08-11
*/
#ifndef G3D_platform_h
@@ -16,7 +16,7 @@
The version number of G3D in the form: MmmBB ->
version M.mm [beta BB]
*/
-#define G3D_VER 80000
+#define G3D_VER 80100
// fatal error for unsupported architectures
#if defined(__powerpc__)
diff --git a/dep/g3dlite/source/AABox.cpp b/dep/g3dlite/source/AABox.cpp
index 035497aa3c4..8e66456c013 100644
--- a/dep/g3dlite/source/AABox.cpp
+++ b/dep/g3dlite/source/AABox.cpp
@@ -282,6 +282,10 @@ bool AABox::culledBy(
return false;
}
+void AABox::getBounds(Sphere& s) const {
+ s.center = center();
+ s.radius = extent().length() / 2;
+}
bool AABox::intersects(const class Sphere& sphere) const {
double d = 0;
diff --git a/dep/g3dlite/source/Log.cpp b/dep/g3dlite/source/Log.cpp
index d44d88d0242..f437351cfbd 100644
--- a/dep/g3dlite/source/Log.cpp
+++ b/dep/g3dlite/source/Log.cpp
@@ -23,23 +23,23 @@
namespace G3D {
void logPrintf(const char* fmt, ...) {
- va_list arg_list;
- va_start(arg_list, fmt);
+ va_list arg_list;
+ va_start(arg_list, fmt);
Log::common()->vprintf(fmt, arg_list);
va_end(arg_list);
}
void logLazyPrintf(const char* fmt, ...) {
- va_list arg_list;
- va_start(arg_list, fmt);
+ va_list arg_list;
+ va_start(arg_list, fmt);
Log::common()->lazyvprintf(fmt, arg_list);
va_end(arg_list);
}
Log* Log::commonLog = NULL;
-Log::Log(const std::string& filename, int stripFromStackBottom) :
+Log::Log(const std::string& filename, int stripFromStackBottom) :
stripFromStackBottom(stripFromStackBottom) {
this->filename = filename;
@@ -50,7 +50,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) :
std::string drive, base, ext;
Array<std::string> path;
parseFilename(filename, drive, path, base, ext);
- std::string logName = base + ((ext != "") ? ("." + ext) : "");
+ std::string logName = base + ((ext != "") ? ("." + ext) : "");
// Write time is greater than 1ms. This may be a network drive.... try another file.
#ifdef G3D_WIN32
@@ -80,7 +80,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) :
Log::~Log() {
section("Shutdown");
println("Closing log file");
-
+
// Make sure we don't leave a dangling pointer
if (Log::commonLog == this) {
Log::commonLog = NULL;
diff --git a/dep/g3dlite/source/RegistryUtil.cpp b/dep/g3dlite/source/RegistryUtil.cpp
index fc4cebc2ee5..28ff6955d9b 100644
--- a/dep/g3dlite/source/RegistryUtil.cpp
+++ b/dep/g3dlite/source/RegistryUtil.cpp
@@ -257,7 +257,7 @@ bool RegistryUtil::writeString(const std::string& key, const std::string& value,
// static helpers
-static HKEY getRootKeyFromString(const char* str, size_t length) {
+static HKEY getRootKeyFromString(const char* str, uint32 length) {
debugAssert(str);
if (str) {
diff --git a/dep/g3dlite/source/System.cpp b/dep/g3dlite/source/System.cpp
index 5170ba44941..809f05c0ab4 100644
--- a/dep/g3dlite/source/System.cpp
+++ b/dep/g3dlite/source/System.cpp
@@ -920,9 +920,12 @@ RealTime System::time() {
////////////////////////////////////////////////////////////////
-#define REALPTR_TO_USERPTR(x) ((uint8*)(x) + sizeof (void *))
-#define USERPTR_TO_REALPTR(x) ((uint8*)(x) - sizeof (void *))
-#define REALBLOCK_SIZE(x) ((x) + sizeof (void *))
+
+#define REALPTR_TO_USERPTR(x) ((uint8*)(x) + sizeof(uint32))
+#define USERPTR_TO_REALPTR(x) ((uint8*)(x) - sizeof(uint32))
+#define USERSIZE_TO_REALSIZE(x) ((x) + sizeof(uint32))
+#define REALSIZE_FROM_USERPTR(u) (*(uint32*)USERPTR_TO_REALPTR(ptr) + sizeof(uint32))
+#define USERSIZE_FROM_USERPTR(u) (*(uint32*)USERPTR_TO_REALPTR(ptr))
class BufferPool {
public:
@@ -947,13 +950,19 @@ public:
private:
+ /** Pointer given to the program. Unless in the tiny heap, the user size of the block is stored right in front of the pointer as a uint32.*/
+ typedef void* UserPtr;
+
+ /** Actual block allocated on the heap */
+ typedef void* RealPtr;
+
class MemBlock {
public:
- void* ptr;
- size_t bytes;
+ UserPtr ptr;
+ size_t bytes;
inline MemBlock() : ptr(NULL), bytes(0) {}
- inline MemBlock(void* p, size_t b) : ptr(p), bytes(b) {}
+ inline MemBlock(UserPtr p, size_t b) : ptr(p), bytes(b) {}
};
MemBlock smallPool[maxSmallBuffers];
@@ -1010,13 +1019,13 @@ private:
/**
Malloc out of the tiny heap. Returns NULL if allocation failed.
*/
- inline void* tinyMalloc(size_t bytes) {
+ inline UserPtr tinyMalloc(size_t bytes) {
// Note that we ignore the actual byte size
// and create a constant size block.
(void)bytes;
assert(tinyBufferSize >= bytes);
- void* ptr = NULL;
+ UserPtr ptr = NULL;
if (tinyPoolSize > 0) {
--tinyPoolSize;
@@ -1040,20 +1049,20 @@ private:
}
/** Returns true if this is a pointer into the tiny heap. */
- bool inTinyHeap(void* ptr) {
+ bool inTinyHeap(UserPtr ptr) {
return
(ptr >= tinyHeap) &&
(ptr < (uint8*)tinyHeap + maxTinyBuffers * tinyBufferSize);
}
- void tinyFree(void* ptr) {
+ void tinyFree(UserPtr ptr) {
assert(ptr);
assert(tinyPoolSize < maxTinyBuffers);
// "Tried to free a tiny pool buffer when the tiny pool freelist is full.");
# ifdef G3D_DEBUG
if (tinyPoolSize > 0) {
- void* prevOnHeap = tinyPool[tinyPoolSize - 1];
+ UserPtr prevOnHeap = tinyPool[tinyPoolSize - 1];
assert(prevOnHeap != ptr);
// "System::malloc heap corruption detected: "
// "the last two pointers on the freelist are identical (during tinyFree).");
@@ -1070,7 +1079,8 @@ private:
void flushPool(MemBlock* pool, int& poolSize) {
for (int i = 0; i < poolSize; ++i) {
- ::free(pool[i].ptr);
+ bytesAllocated -= USERSIZE_TO_REALSIZE(pool[i].bytes);
+ ::free(USERPTR_TO_REALPTR(pool[i].ptr));
pool[i].ptr = NULL;
pool[i].bytes = 0;
}
@@ -1078,24 +1088,23 @@ private:
}
- /** Allocate out of a specific pool-> Return NULL if no suitable
- memory was found.
-
- */
- void* malloc(MemBlock* pool, int& poolSize, size_t bytes) {
+ /** Allocate out of a specific pool. Return NULL if no suitable
+ memory was found. */
+ UserPtr malloc(MemBlock* pool, int& poolSize, size_t bytes) {
// OPT: find the smallest block that satisfies the request.
- // See if there's something we can use in the buffer pool->
+ // See if there's something we can use in the buffer pool.
// Search backwards since usually we'll re-use the last one.
for (int i = (int)poolSize - 1; i >= 0; --i) {
if (pool[i].bytes >= bytes) {
- // We found a suitable entry in the pool->
+ // We found a suitable entry in the pool.
// No need to offset the pointer; it is already offset
- void* ptr = pool[i].ptr;
+ UserPtr ptr = pool[i].ptr;
- // Remove this element from the pool
+ // Remove this element from the pool, replacing it with
+ // the one from the end (same as Array::fastRemove)
--poolSize;
pool[i] = pool[poolSize];
@@ -1159,6 +1168,8 @@ public:
~BufferPool() {
::free(tinyHeap);
+ flushPool(smallPool, smallPoolSize);
+ flushPool(medPool, medPoolSize);
#if 0 //-------------------------------- old mutex
# ifdef G3D_WIN32
DeleteCriticalSection(&mutex);
@@ -1169,7 +1180,7 @@ public:
}
- void* realloc(void* ptr, size_t bytes) {
+ UserPtr realloc(UserPtr ptr, size_t bytes) {
if (ptr == NULL) {
return malloc(bytes);
}
@@ -1181,7 +1192,7 @@ public:
} else {
// Free the old pointer and malloc
- void* newPtr = malloc(bytes);
+ UserPtr newPtr = malloc(bytes);
System::memcpy(newPtr, ptr, tinyBufferSize);
tinyFree(ptr);
return newPtr;
@@ -1191,28 +1202,28 @@ public:
// In one of our heaps.
// See how big the block really was
- size_t realSize = *(uint32*)USERPTR_TO_REALPTR(ptr);
- if (bytes <= realSize) {
+ size_t userSize = USERSIZE_FROM_USERPTR(ptr);
+ if (bytes <= userSize) {
// The old block was big enough.
return ptr;
}
- // Need to reallocate
- void* newPtr = malloc(bytes);
- System::memcpy(newPtr, ptr, realSize);
+ // Need to reallocate and move
+ UserPtr newPtr = malloc(bytes);
+ System::memcpy(newPtr, ptr, userSize);
free(ptr);
return newPtr;
}
}
- void* malloc(size_t bytes) {
+ UserPtr malloc(size_t bytes) {
lock();
++totalMallocs;
if (bytes <= tinyBufferSize) {
- void* ptr = tinyMalloc(bytes);
+ UserPtr ptr = tinyMalloc(bytes);
if (ptr) {
++mallocsFromTinyPool;
@@ -1226,7 +1237,7 @@ public:
// through to a small buffer
if (bytes <= smallBufferSize) {
- void* ptr = malloc(smallPool, smallPoolSize, bytes);
+ UserPtr ptr = malloc(smallPool, smallPoolSize, bytes);
if (ptr) {
++mallocsFromSmallPool;
@@ -1239,7 +1250,7 @@ public:
// through into a medium allocation because that would
// waste the medium buffer's resources.
- void* ptr = malloc(medPool, medPoolSize, bytes);
+ UserPtr ptr = malloc(medPool, medPoolSize, bytes);
if (ptr) {
++mallocsFromMedPool;
@@ -1249,37 +1260,37 @@ public:
}
}
- bytesAllocated += REALBLOCK_SIZE(bytes);
+ bytesAllocated += USERSIZE_TO_REALSIZE(bytes);
unlock();
// Heap allocate
// Allocate 4 extra bytes for our size header (unfortunate,
// since malloc already added its own header).
- void* ptr = ::malloc(REALBLOCK_SIZE(bytes));
+ RealPtr ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
if (ptr == NULL) {
// Flush memory pools to try and recover space
flushPool(smallPool, smallPoolSize);
flushPool(medPool, medPoolSize);
- ptr = ::malloc(REALBLOCK_SIZE(bytes));
+ ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
}
if (ptr == NULL) {
if ((System::outOfMemoryCallback() != NULL) &&
- (System::outOfMemoryCallback()(REALBLOCK_SIZE(bytes), true) == true)) {
+ (System::outOfMemoryCallback()(USERSIZE_TO_REALSIZE(bytes), true) == true)) {
// Re-attempt the malloc
- ptr = ::malloc(REALBLOCK_SIZE(bytes));
+ ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
}
}
if (ptr == NULL) {
if (System::outOfMemoryCallback() != NULL) {
// Notify the application
- System::outOfMemoryCallback()(REALBLOCK_SIZE(bytes), false);
+ System::outOfMemoryCallback()(USERSIZE_TO_REALSIZE(bytes), false);
}
# ifdef G3D_DEBUG
- debugPrintf("::malloc(%d) returned NULL\n", (int)REALBLOCK_SIZE(bytes));
+ debugPrintf("::malloc(%d) returned NULL\n", (int)USERSIZE_TO_REALSIZE(bytes));
# endif
debugAssertM(ptr != NULL,
"::malloc returned NULL. Either the "
@@ -1294,7 +1305,7 @@ public:
}
- void free(void* ptr) {
+ void free(UserPtr ptr) {
if (ptr == NULL) {
// Free does nothing on null pointers
return;
@@ -1309,7 +1320,7 @@ public:
return;
}
- uint32 bytes = *(uint32*)USERPTR_TO_REALPTR(ptr);
+ uint32 bytes = USERSIZE_FROM_USERPTR(ptr);
lock();
if (bytes <= smallBufferSize) {
@@ -1327,7 +1338,7 @@ public:
return;
}
}
- bytesAllocated -= REALBLOCK_SIZE(bytes);
+ bytesAllocated -= USERSIZE_TO_REALSIZE(bytes);
unlock();
// Free; the buffer pools are full or this is too big to store.
diff --git a/dep/g3dlite/source/TextInput.cpp b/dep/g3dlite/source/TextInput.cpp
index 09abacc7391..354d0de13c0 100644
--- a/dep/g3dlite/source/TextInput.cpp
+++ b/dep/g3dlite/source/TextInput.cpp
@@ -128,32 +128,34 @@ Token TextInput::read() {
}
-std::string TextInput::readUntilNewlineAsString() {
- // Go to the front of the next token
- Token t = read();
- // Reset the position to the start of this token
+std::string TextInput::readUntilNewlineAsString() {
+/*
+ // Reset the read position back to the start of that token
currentCharOffset = t.bytePosition();
+ lineNumber = t.line();
+ charNumber = t.character();
stack.clear();
if (currentCharOffset == buffer.size()) {
// End of file
return "";
}
-
+ */
std::string s;
// Read until newline or eof
char c = '\0';
do {
- c = buffer[currentCharOffset];
- if (c == '\r' || c == '\n') {
- // Done
- break;
- } else {
- s += c;
- ++currentCharOffset;
- }
+ c = buffer[currentCharOffset];
+ if (c == '\r' || c == '\n') {
+ // Done
+ break;
+ } else {
+ s += c;
+ ++currentCharOffset;
+ ++charNumber;
+ }
} while (currentCharOffset < buffer.size());
return s;
diff --git a/dep/g3dlite/source/g3dmath.cpp b/dep/g3dlite/source/g3dmath.cpp
index e846f8c6080..84e8345bff4 100644
--- a/dep/g3dlite/source/g3dmath.cpp
+++ b/dep/g3dlite/source/g3dmath.cpp
@@ -41,7 +41,7 @@ double inf() {
}
bool isNaN(float x) {
- static const float n = fnan();
+ static const float n = nan();
return memcmp(&x, &n, sizeof(float)) == 0;
}
diff --git a/dep/gsoap/gsoap.stub b/dep/gsoap/gsoap.stub
new file mode 100644
index 00000000000..be215b46655
--- /dev/null
+++ b/dep/gsoap/gsoap.stub
@@ -0,0 +1 @@
+int ns1__executeCommand(char* command, char** result);
diff --git a/dep/gsoap/soapC.cpp b/dep/gsoap/soapC.cpp
index 7fefc27f5d1..2c675cc339d 100644
--- a/dep/gsoap/soapC.cpp
+++ b/dep/gsoap/soapC.cpp
@@ -1,8 +1,11 @@
/* soapC.cpp
- Generated by gSOAP 2.8.2 from stub.h
- Copyright(C) 2000-2011, Robert van Engelen, Genivia Inc. All Rights Reserved.
- The generated code is released under one of the following licenses:
- GPL OR Genivia's license for commercial use.
+ Generated by gSOAP 2.8.10 from gsoap.stub
+
+Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved.
+The generated code is released under one of the following licenses:
+1) GPL or 2) Genivia's license for commercial use.
+This program is released under the GPL with the additional exemption that
+compiling, linking, and/or using OpenSSL is allowed.
*/
#if defined(__BORLANDC__)
@@ -12,15 +15,17 @@
#include "soapH.h"
-SOAP_SOURCE_STAMP("@(#) soapC.cpp ver 2.8.2 2011-04-26 21:49:07 GMT")
+SOAP_SOURCE_STAMP("@(#) soapC.cpp ver 2.8.10 2012-09-02 20:48:00 GMT")
#ifndef WITH_NOGLOBAL
-SOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap)
+SOAP_FMAC3 int SOAP_FMAC4 soap_getheader(struct soap *soap)
{
- if (soap->header)
- soap_serialize_SOAP_ENV__Header(soap, soap->header);
+ soap->part = SOAP_IN_HEADER;
+ soap->header = soap_in_SOAP_ENV__Header(soap, "SOAP-ENV:Header", soap->header, NULL);
+ soap->part = SOAP_END_HEADER;
+ return soap->header == NULL;
}
SOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap *soap)
@@ -34,12 +39,10 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_putheader(struct soap *soap)
return SOAP_OK;
}
-SOAP_FMAC3 int SOAP_FMAC4 soap_getheader(struct soap *soap)
+SOAP_FMAC3 void SOAP_FMAC4 soap_serializeheader(struct soap *soap)
{
- soap->part = SOAP_IN_HEADER;
- soap->header = soap_in_SOAP_ENV__Header(soap, "SOAP-ENV:Header", NULL, NULL);
- soap->part = SOAP_END_HEADER;
- return soap->header == NULL;
+ if (soap->header)
+ soap_serialize_SOAP_ENV__Header(soap, soap->header);
}
SOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap *soap)
@@ -90,7 +93,7 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_getfault(struct soap *soap)
SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultcode(struct soap *soap)
{
soap_fault(soap);
- if (soap->version == 2)
+ if (soap->version == 2 && soap->fault->SOAP_ENV__Code)
return (const char**)&soap->fault->SOAP_ENV__Code->SOAP_ENV__Value;
return (const char**)&soap->fault->faultcode;
}
@@ -108,6 +111,17 @@ SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultsubcode(struct soap *soap)
return (const char**)&soap->fault->faultcode;
}
+SOAP_FMAC3 const char * SOAP_FMAC4 soap_check_faultsubcode(struct soap *soap)
+{
+ soap_fault(soap);
+ if (soap->version == 2)
+ { if (soap->fault->SOAP_ENV__Code && soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode && soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode)
+ return soap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value;
+ return NULL;
+ }
+ return soap->fault->faultcode;
+}
+
SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultstring(struct soap *soap)
{
soap_fault(soap);
@@ -133,6 +147,16 @@ SOAP_FMAC3 const char ** SOAP_FMAC4 soap_faultdetail(struct soap *soap)
return (const char**)&soap->fault->SOAP_ENV__Detail->__any;
}
+SOAP_FMAC3 const char * SOAP_FMAC4 soap_check_faultdetail(struct soap *soap)
+{
+ soap_fault(soap);
+ if (soap->version == 2 && soap->fault->SOAP_ENV__Detail)
+ return soap->fault->SOAP_ENV__Detail->__any;
+ if (soap->fault->detail)
+ return soap->fault->detail->__any;
+ return NULL;
+}
+
#endif
#ifndef WITH_NOIDREF
@@ -158,7 +182,7 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap *soap)
extern "C" {
#endif
SOAP_FMAC3 void * SOAP_FMAC4 soap_getelement(struct soap *soap, int *type)
-{
+{ (void)type;
if (soap_peek_element(soap))
return NULL;
if (!*soap->id || !(*type = soap_lookup_type(soap, soap->id)))
@@ -280,7 +304,7 @@ SOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap *soap)
extern "C" {
#endif
SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap *soap, const void *ptr, const char *tag, int id, int type)
-{
+{ (void)tag;
switch (type)
{
case SOAP_TYPE_byte:
@@ -340,7 +364,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap *soap, const void *ptr,
#endif
SOAP_FMAC3 void * SOAP_FMAC4 soap_instantiate(struct soap *soap, int t, const char *type, const char *arrayType, size_t *n)
-{
+{ (void)type;
switch (t)
{
case SOAP_TYPE_ns1__executeCommandResponse:
@@ -446,7 +470,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_byte(struct soap *soap, char *a)
}
SOAP_FMAC3 int SOAP_FMAC4 soap_out_byte(struct soap *soap, const char *tag, int id, const char *a, const char *type)
-{
+{ (void)soap; (void)type; (void)tag; (void)id;
return soap_outbyte(soap, tag, id, a, type, SOAP_TYPE_byte);
}
@@ -483,7 +507,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_default_int(struct soap *soap, int *a)
}
SOAP_FMAC3 int SOAP_FMAC4 soap_out_int(struct soap *soap, const char *tag, int id, const int *a, const char *type)
-{
+{ (void)soap; (void)type; (void)tag; (void)id;
return soap_outint(soap, tag, id, a, type, SOAP_TYPE_int);
}
@@ -542,13 +566,14 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Fault(struct soap *soap, con
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Fault(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Fault *a, const char *type)
{
const char *soap_tmp_faultcode = soap_QName2s(soap, a->faultcode);
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Fault), type))
return soap->error;
if (soap_out__QName(soap, "faultcode", -1, (char*const*)&soap_tmp_faultcode, ""))
return soap->error;
- if (soap_out_string(soap, "faultstring", -1, &a->faultstring, "xsd:string"))
+ if (soap_out_string(soap, "faultstring", -1, &a->faultstring, ""))
return soap->error;
- if (soap_out_string(soap, "faultactor", -1, &a->faultactor, "xsd:string"))
+ if (soap_out_string(soap, "faultactor", -1, &a->faultactor, ""))
return soap->error;
if (soap_out_PointerToSOAP_ENV__Detail(soap, "detail", -1, &a->detail, ""))
return soap->error;
@@ -692,7 +717,7 @@ SOAP_FMAC1 struct SOAP_ENV__Fault * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Fault(
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Fault(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct SOAP_ENV__Fault %p -> %p\n", q, p));
*(struct SOAP_ENV__Fault*)p = *(struct SOAP_ENV__Fault*)q;
}
@@ -715,6 +740,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Reason(struct soap *soap, co
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Reason(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Reason *a, const char *type)
{
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Reason), type))
return soap->error;
if (soap->lang)
@@ -803,7 +829,7 @@ SOAP_FMAC1 struct SOAP_ENV__Reason * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Reaso
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Reason(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct SOAP_ENV__Reason %p -> %p\n", q, p));
*(struct SOAP_ENV__Reason*)p = *(struct SOAP_ENV__Reason*)q;
}
@@ -828,6 +854,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Detail(struct soap *soap, co
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Detail(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Detail *a, const char *type)
{
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Detail), type))
return soap->error;
soap_outliteral(soap, "-any", &a->__any, NULL);
@@ -921,7 +948,7 @@ SOAP_FMAC1 struct SOAP_ENV__Detail * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Detai
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Detail(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct SOAP_ENV__Detail %p -> %p\n", q, p));
*(struct SOAP_ENV__Detail*)p = *(struct SOAP_ENV__Detail*)q;
}
@@ -947,6 +974,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Code(struct soap *soap, cons
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Code(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Code *a, const char *type)
{
const char *soap_tmp_SOAP_ENV__Value = soap_QName2s(soap, a->SOAP_ENV__Value);
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Code), type))
return soap->error;
if (soap_out__QName(soap, "SOAP-ENV:Value", -1, (char*const*)&soap_tmp_SOAP_ENV__Value, ""))
@@ -1041,7 +1069,7 @@ SOAP_FMAC1 struct SOAP_ENV__Code * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Code(st
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Code(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct SOAP_ENV__Code %p -> %p\n", q, p));
*(struct SOAP_ENV__Code*)p = *(struct SOAP_ENV__Code*)q;
}
@@ -1062,6 +1090,7 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_SOAP_ENV__Header(struct soap *soap, co
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Header(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Header *a, const char *type)
{
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Header), type))
return soap->error;
return soap_element_end_out(soap, tag);
@@ -1140,7 +1169,7 @@ SOAP_FMAC1 struct SOAP_ENV__Header * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Heade
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_SOAP_ENV__Header(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct SOAP_ENV__Header %p -> %p\n", q, p));
*(struct SOAP_ENV__Header*)p = *(struct SOAP_ENV__Header*)q;
}
@@ -1161,9 +1190,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommand(struct soap *soap,
SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommand(struct soap *soap, const char *tag, int id, const struct ns1__executeCommand *a, const char *type)
{
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_ns1__executeCommand), type))
return soap->error;
- if (soap_out_string(soap, "command", -1, &a->command, "xsd:string"))
+ if (soap_out_string(soap, "command", -1, &a->command, ""))
return soap->error;
return soap_element_end_out(soap, tag);
}
@@ -1247,7 +1277,7 @@ SOAP_FMAC1 struct ns1__executeCommand * SOAP_FMAC2 soap_instantiate_ns1__execute
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommand(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct ns1__executeCommand %p -> %p\n", q, p));
*(struct ns1__executeCommand*)p = *(struct ns1__executeCommand*)q;
}
@@ -1266,9 +1296,10 @@ SOAP_FMAC3 void SOAP_FMAC4 soap_serialize_ns1__executeCommandResponse(struct soa
SOAP_FMAC3 int SOAP_FMAC4 soap_out_ns1__executeCommandResponse(struct soap *soap, const char *tag, int id, const struct ns1__executeCommandResponse *a, const char *type)
{
+ (void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_ns1__executeCommandResponse), type))
return soap->error;
- if (soap_out_PointerTostring(soap, "result", -1, &a->result, "xsd:string"))
+ if (soap_out_PointerTostring(soap, "result", -1, &a->result, ""))
return soap->error;
return soap_element_end_out(soap, tag);
}
@@ -1352,7 +1383,7 @@ SOAP_FMAC1 struct ns1__executeCommandResponse * SOAP_FMAC2 soap_instantiate_ns1_
SOAP_FMAC3 void SOAP_FMAC4 soap_copy_ns1__executeCommandResponse(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{
- (void)soap; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
+ (void)soap; (void)tt; (void)st; (void)len; (void)n; /* appease -Wall -Werror */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying struct ns1__executeCommandResponse %p -> %p\n", q, p));
*(struct ns1__executeCommandResponse*)p = *(struct ns1__executeCommandResponse*)q;
}
@@ -1383,6 +1414,8 @@ SOAP_FMAC3 struct SOAP_ENV__Reason ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Reas
*a = NULL;
if (!soap->null && *soap->href != '#')
{ soap_revert(soap);
+ *a = (struct SOAP_ENV__Reason *)soap_malloc(soap, sizeof(struct SOAP_ENV__Reason));
+ soap_default_SOAP_ENV__Reason(soap, *a);
if (!(*a = soap_in_SOAP_ENV__Reason(soap, tag, *a, type)))
return NULL;
}
@@ -1438,6 +1471,8 @@ SOAP_FMAC3 struct SOAP_ENV__Detail ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Deta
*a = NULL;
if (!soap->null && *soap->href != '#')
{ soap_revert(soap);
+ *a = (struct SOAP_ENV__Detail *)soap_malloc(soap, sizeof(struct SOAP_ENV__Detail));
+ soap_default_SOAP_ENV__Detail(soap, *a);
if (!(*a = soap_in_SOAP_ENV__Detail(soap, tag, *a, type)))
return NULL;
}
@@ -1493,6 +1528,8 @@ SOAP_FMAC3 struct SOAP_ENV__Code ** SOAP_FMAC4 soap_in_PointerToSOAP_ENV__Code(s
*a = NULL;
if (!soap->null && *soap->href != '#')
{ soap_revert(soap);
+ *a = (struct SOAP_ENV__Code *)soap_malloc(soap, sizeof(struct SOAP_ENV__Code));
+ soap_default_SOAP_ENV__Code(soap, *a);
if (!(*a = soap_in_SOAP_ENV__Code(soap, tag, *a, type)))
return NULL;
}
diff --git a/dep/gsoap/soapH.h b/dep/gsoap/soapH.h
index e51d3defaaf..06e9ec21239 100644
--- a/dep/gsoap/soapH.h
+++ b/dep/gsoap/soapH.h
@@ -1,8 +1,11 @@
/* soapH.h
- Generated by gSOAP 2.8.2 from stub.h
- Copyright(C) 2000-2011, Robert van Engelen, Genivia Inc. All Rights Reserved.
- The generated code is released under one of the following licenses:
- GPL OR Genivia's license for commercial use.
+ Generated by gSOAP 2.8.10 from gsoap.stub
+
+Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved.
+The generated code is released under one of the following licenses:
+1) GPL or 2) Genivia's license for commercial use.
+This program is released under the GPL with the additional exemption that
+compiling, linking, and/or using OpenSSL is allowed.
*/
#ifndef soapH_H
diff --git a/dep/gsoap/soapServer.cpp b/dep/gsoap/soapServer.cpp
index 8c8206fb3ef..b6304a3e525 100644
--- a/dep/gsoap/soapServer.cpp
+++ b/dep/gsoap/soapServer.cpp
@@ -1,8 +1,11 @@
/* soapServer.cpp
- Generated by gSOAP 2.8.2 from stub.h
- Copyright(C) 2000-2011, Robert van Engelen, Genivia Inc. All Rights Reserved.
- The generated code is released under one of the following licenses:
- GPL OR Genivia's license for commercial use.
+ Generated by gSOAP 2.8.10 from gsoap.stub
+
+Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved.
+The generated code is released under one of the following licenses:
+1) GPL or 2) Genivia's license for commercial use.
+This program is released under the GPL with the additional exemption that
+compiling, linking, and/or using OpenSSL is allowed.
*/
#if defined(__BORLANDC__)
@@ -11,7 +14,7 @@
#endif
#include "soapH.h"
-SOAP_SOURCE_STAMP("@(#) soapServer.cpp ver 2.8.2 2011-04-26 21:49:07 GMT")
+SOAP_SOURCE_STAMP("@(#) soapServer.cpp ver 2.8.10 2012-09-02 20:48:00 GMT")
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap)
@@ -67,6 +70,7 @@ SOAP_FMAC5 int SOAP_FMAC6 soap_serve_ns1__executeCommand(struct soap *soap)
soap_tmp_string = NULL;
soap_tmp_ns1__executeCommandResponse.result = &soap_tmp_string;
soap_default_ns1__executeCommand(soap, &soap_tmp_ns1__executeCommand);
+ soap->encodingStyle = NULL;
if (!soap_get_ns1__executeCommand(soap, &soap_tmp_ns1__executeCommand, "ns1:executeCommand", NULL))
return soap->error;
if (soap_body_end_in(soap)
diff --git a/dep/gsoap/soapStub.h b/dep/gsoap/soapStub.h
index 85f3119b9ff..fbdd170e0f4 100644
--- a/dep/gsoap/soapStub.h
+++ b/dep/gsoap/soapStub.h
@@ -1,13 +1,20 @@
/* soapStub.h
- Generated by gSOAP 2.8.2 from stub.h
- Copyright(C) 2000-2011, Robert van Engelen, Genivia Inc. All Rights Reserved.
- The generated code is released under one of the following licenses:
- GPL OR Genivia's license for commercial use.
+ Generated by gSOAP 2.8.10 from gsoap.stub
+
+Copyright(C) 2000-2012, Robert van Engelen, Genivia Inc. All Rights Reserved.
+The generated code is released under one of the following licenses:
+1) GPL or 2) Genivia's license for commercial use.
+This program is released under the GPL with the additional exemption that
+compiling, linking, and/or using OpenSSL is allowed.
*/
#ifndef soapStub_H
#define soapStub_H
#include "stdsoap2.h"
+#if GSOAP_VERSION != 20810
+# error "GSOAP VERSION MISMATCH IN GENERATED CODE: PLEASE REINSTALL PACKAGE"
+#endif
+
/******************************************************************************\
* *
diff --git a/dep/gsoap/stdsoap2.cpp b/dep/gsoap/stdsoap2.cpp
index ed0922d86f2..36a8901dcab 100644
--- a/dep/gsoap/stdsoap2.cpp
+++ b/dep/gsoap/stdsoap2.cpp
@@ -1,17 +1,17 @@
/*
- stdsoap2.c[pp] 2.8.2
+ stdsoap2.c[pp] 2.8.10
gSOAP runtime engine
gSOAP XML Web services tools
-Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc., All Rights Reserved.
+Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved.
This part of the software is released under ONE of the following licenses:
GPL, or the gSOAP public license, or Genivia's license for commercial use.
--------------------------------------------------------------------------------
Contributors:
Wind River Systems Inc., for the following additions under gSOAP public license:
- - vxWorks compatible
+ - vxWorks compatible options
--------------------------------------------------------------------------------
gSOAP public license.
@@ -24,7 +24,7 @@ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc., All Rights Reserved.
+Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved.
--------------------------------------------------------------------------------
GPL license.
@@ -49,25 +49,18 @@ compiling, linking, and/or using OpenSSL is allowed.
--------------------------------------------------------------------------------
A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
-
-Installation note:
-
-Win32 build needs "ws2_32.lib"
-To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"
-tab (the project file needs to be selected in the file view) and add
-"ws2_32.lib" to the "Object/library modules" entry
-
-On Mac OS X with gcc (GCC) 3.1 20020420 (prerelease) you MUST compile with
--fstack_check when using -O2 because gcc 3.1 has a bug that smashes the stack
-when locally allocated data exceeds 64K.
-
*/
+#define GSOAP_LIB_VERSION 20810
+
#ifdef AS400
# pragma convert(819) /* EBCDIC to ASCII */
#endif
#include "stdsoap2.h"
+#if GSOAP_VERSION != GSOAP_LIB_VERSION
+# error "GSOAP VERSION MISMATCH IN LIBRARY: PLEASE REINSTALL PACKAGE"
+#endif
#ifdef __BORLANDC__
# pragma warn -8060
@@ -83,10 +76,10 @@ when locally allocated data exceeds 64K.
#endif
#ifdef __cplusplus
-SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.2 2011-04-17 00:00:00 GMT")
+SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.8.10 2012-08-16 00:00:00 GMT")
extern "C" {
#else
-SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.2 2011-04-17 00:00:00 GMT")
+SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.10 2012-08-16 00:00:00 GMT")
#endif
/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */
@@ -101,7 +94,7 @@ SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.8.2 2011-04-17 00:00:00 GMT")
#define SOAP_QT (soap_wchar)(-5) /* XML-specific '"' */
#define SOAP_AP (soap_wchar)(-6) /* XML-specific ''' */
-#define soap_blank(c) ((c) >= 0 && (c) <= 32)
+#define soap_blank(c) ((c)+1 > 0 && (c) <= 32)
#define soap_notblank(c) ((c) > 32)
#if defined(WIN32) && !defined(UNDER_CE)
@@ -138,8 +131,10 @@ static int soap_isxdigit(int);
static void *fplugin(struct soap*, const char*);
static size_t soap_count_attachments(struct soap *soap);
static int soap_try_connect_command(struct soap*, int http_command, const char *endpoint, const char *action);
+#ifdef WITH_NTLM
+static int soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const char *host, int port);
+#endif
#ifndef WITH_NOIDREF
-static void soap_update_ptrs(struct soap*, char*, char*, char*, char*);
static int soap_has_copies(struct soap*, const char*, const char*);
static void soap_init_iht(struct soap*);
static void soap_free_iht(struct soap*);
@@ -152,7 +147,7 @@ static void soap_free_pht(struct soap*);
static const char *soap_set_validation_fault(struct soap*, const char*, const char*);
static int soap_isnumeric(struct soap*, const char*);
static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized);
-static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n);
+static void soap_utilize_ns(struct soap *soap, const char *tag);
#endif
#ifndef WITH_LEANER
@@ -208,9 +203,9 @@ static const char *soap_decode(char*, size_t, const char*, const char*);
#ifndef PALM_1
static soap_wchar soap_getchunkchar(struct soap*);
static const char *http_error(struct soap*, int);
-static int http_put(struct soap*);
static int http_get(struct soap*);
static int http_405(struct soap*);
+static int http_200(struct soap*);
static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
static int http_send_header(struct soap*, const char*);
static int http_post_header(struct soap*, const char*, const char*);
@@ -538,6 +533,7 @@ extern int h_errno;
static int
fsend(struct soap *soap, const char *s, size_t n)
{ register int nwritten, err;
+ SOAP_SOCKET sk;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->os)
{ soap->os->write(s, (std::streamsize)n);
@@ -547,23 +543,26 @@ fsend(struct soap *soap, const char *s, size_t n)
return SOAP_EOF;
}
#endif
+ sk = soap->sendsk;
+ if (!soap_valid_socket(sk))
+ sk = soap->socket;
while (n)
- { if (soap_valid_socket(soap->socket))
+ { if (soap_valid_socket(sk))
{
if (soap->send_timeout)
{ for (;;)
{ register int r;
#ifdef WITH_OPENSSL
if (soap->ssl)
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ALL, soap->send_timeout);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
#ifdef WITH_GNUTLS
if (soap->session)
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ALL, soap->send_timeout);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_ALL, soap->send_timeout);
else
#endif
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout);
if (r > 0)
break;
if (!r)
@@ -590,25 +589,25 @@ fsend(struct soap *soap, const char *s, size_t n)
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
{ if (soap->peerlen)
- nwritten = sendto(soap->socket, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
+ nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
- nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
+ nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
/* retry and back-off algorithm */
/* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */
if (nwritten < 0)
{ int udp_repeat;
int udp_delay;
if ((soap->connect_flags & SO_BROADCAST))
- udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */
+ udp_repeat = 2; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */
else
udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */
udp_delay = ((unsigned int)soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */
do
- { tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ERR, -1000 * udp_delay);
+ { tcp_select(soap, sk, SOAP_TCP_SELECT_ERR, -1000 * udp_delay);
if (soap->peerlen)
- nwritten = sendto(soap->socket, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
+ nwritten = sendto(sk, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
else
- nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
+ nwritten = send(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
udp_delay <<= 1;
if (udp_delay > 500) /* UDP_UPPER_DELAY */
udp_delay = 500;
@@ -619,14 +618,14 @@ fsend(struct soap *soap, const char *s, size_t n)
else
#endif
#if !defined(PALM) && !defined(AS400)
- nwritten = send(soap->socket, s, (int)n, soap->socket_flags);
+ nwritten = send(sk, s, (int)n, soap->socket_flags);
#else
- nwritten = send(soap->socket, (void*)s, n, soap->socket_flags);
+ nwritten = send(sk, (void*)s, n, soap->socket_flags);
#endif
if (nwritten <= 0)
{
register int r = 0;
- err = soap_socket_errno(soap->socket);
+ err = soap_socket_errno(sk);
#ifdef WITH_OPENSSL
if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE)
{ soap->errnum = err;
@@ -645,14 +644,14 @@ fsend(struct soap *soap, const char *s, size_t n)
{
#if defined(WITH_OPENSSL)
if (soap->ssl && r == SSL_ERROR_WANT_READ)
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#elif defined(WITH_GNUTLS)
if (soap->session && !gnutls_record_get_direction(soap->session))
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
else
#endif
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
if (!r && soap->send_timeout)
return SOAP_EOF;
if (r < 0 && soap->errnum != SOAP_EINTR)
@@ -775,7 +774,7 @@ soap_flush(struct soap *soap)
do
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream->avail_in));
if (deflate(soap->d_stream, Z_NO_FLUSH) != Z_OK)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
return soap->error = SOAP_ZLIB_ERROR;
}
if (!soap->d_stream->avail_out)
@@ -870,6 +869,7 @@ static size_t
frecv(struct soap *soap, char *s, size_t n)
{ register int r;
register int retries = 100; /* max 100 retries with non-blocking sockets */
+ SOAP_SOCKET sk;
soap->errnum = 0;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
if (soap->is)
@@ -878,7 +878,10 @@ frecv(struct soap *soap, char *s, size_t n)
return 0;
}
#endif
- if (soap_valid_socket(soap->socket))
+ sk = soap->recvsk;
+ if (!soap_valid_socket(sk))
+ sk = soap->socket;
+ if (soap_valid_socket(sk))
{ for (;;)
{
#ifdef WITH_OPENSSL
@@ -890,7 +893,7 @@ frecv(struct soap *soap, char *s, size_t n)
if (soap->recv_timeout)
#endif
{ for (;;)
- { r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout);
+ { r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout);
if (r > 0)
break;
if (!r)
@@ -930,7 +933,7 @@ frecv(struct soap *soap, char *s, size_t n)
if ((soap->omode & SOAP_IO_UDP))
{ SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
- r = recvfrom(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
+ r = recvfrom(sk, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
soap->peerlen = (size_t)k;
#ifndef WITH_IPV6
soap->ip = ntohl(soap->peer.sin_addr.s_addr);
@@ -938,13 +941,13 @@ frecv(struct soap *soap, char *s, size_t n)
}
else
#endif
- r = recv(soap->socket, s, (int)n, soap->socket_flags);
+ r = recv(sk, s, (int)n, soap->socket_flags);
#ifdef PALM
/* CycleSyncDisplay(curStatusMsg); */
#endif
if (r >= 0)
return (size_t)r;
- r = soap_socket_errno(soap->socket);
+ r = soap_socket_errno(sk);
if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK)
{ soap->errnum = r;
return 0;
@@ -952,14 +955,14 @@ frecv(struct soap *soap, char *s, size_t n)
}
#if defined(WITH_OPENSSL)
if (soap->ssl && err == SSL_ERROR_WANT_WRITE)
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#elif defined(WITH_GNUTLS)
if (soap->session && gnutls_record_get_direction(soap->session))
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
else
#endif
- r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->recv_timeout ? soap->recv_timeout : 5);
if (!r && soap->recv_timeout)
return 0;
if (r < 0)
@@ -970,7 +973,7 @@ frecv(struct soap *soap, char *s, size_t n)
if (retries-- <= 0)
return 0;
#ifdef PALM
- r = soap_socket_errno(soap->socket);
+ r = soap_socket_errno(sk);
if (r != SOAP_EINTR && retries-- <= 0)
{ soap->errnum = r;
return 0;
@@ -1076,10 +1079,9 @@ soap_recv_raw(struct soap *soap)
}
}
else if (r != Z_BUF_ERROR)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
soap->d_stream->next_out = Z_NULL;
- soap->error = SOAP_ZLIB_ERROR;
- return EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
}
}
zlib_again:
@@ -1110,7 +1112,9 @@ zlib_again:
DBGMSG(RECV, soap->buf, ret);
soap->bufidx = 0;
if (!ret)
- return soap->ahead = EOF;
+ { soap->ahead = EOF;
+ return EOF;
+ }
}
else
soap->bufidx = soap->buflen;
@@ -1118,7 +1122,9 @@ zlib_again:
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
{ if ((int)c == EOF)
- return soap->ahead = EOF;
+ { soap->ahead = EOF;
+ return EOF;
+ }
}
do
*t++ = (char)c;
@@ -1126,7 +1132,9 @@ zlib_again:
while ((int)c != EOF && c != '\n')
c = soap_getchunkchar(soap);
if ((int)c == EOF)
- return soap->ahead = EOF;
+ { soap->ahead = EOF;
+ return EOF;
+ }
*t = '\0';
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunk size = %s (hex)\n", tmp));
soap->chunksize = (size_t)soap_strtoul(tmp, &t, 16);
@@ -1194,10 +1202,9 @@ zlib_again:
#endif
}
else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
soap->d_stream->next_out = Z_NULL;
- soap->error = SOAP_ZLIB_ERROR;
- return EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
}
}
#endif
@@ -1283,19 +1290,22 @@ soap_recv(struct soap *soap)
}
}
while (soap->ffilterrecv)
- { int err = soap->filterstop;
- if (err)
+ { int err, last = soap->filterstop;
+ if (last)
soap->bufidx = soap->buflen = 0;
- else
- err = soap_recv_raw(soap); /* do not call again after EOF */
- if ((soap->error = soap->ffilterrecv(soap, soap->buf, &soap->buflen, sizeof(soap->buf))))
- return soap->error;
+ if ((err = soap->ffilterrecv(soap, soap->buf, &soap->buflen, sizeof(soap->buf))))
+ return soap->error = err;
if (soap->buflen)
- { soap->filterstop = err;
+ { soap->bufidx = 0;
+ soap->filterstop = last;
return SOAP_OK;
}
- if (err)
- return err;
+ if (last)
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Returning postponed error %d\n", last));
+ soap->filterstop = SOAP_OK;
+ return last;
+ }
+ soap->filterstop = soap_recv_raw(soap); /* do not call again after EOF */
}
#endif
return soap_recv_raw(soap);
@@ -1505,7 +1515,7 @@ soap_get(struct soap *soap)
{ c = soap_get0(soap);
if (c == '>')
{ soap->cdata = 0;
- soap_get1(soap);
+ c = soap_get1(soap);
c = soap_get1(soap);
}
else
@@ -1702,12 +1712,11 @@ SOAP_FMAC2
soap_getutf8(struct soap *soap)
{ register soap_wchar c, c1, c2, c3, c4;
c = soap->ahead;
- if (c > 0x7F)
- { soap->ahead = 0;
- return c;
- }
- c = soap_get(soap);
- if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN))
+ if (c)
+ soap->ahead = 0;
+ else
+ c = soap_get(soap);
+ if (c < 0x80 || c > 0xFF || (soap->mode & SOAP_ENC_LATIN))
return c;
c1 = soap_get1(soap);
if (c1 < 0x80)
@@ -1896,7 +1905,7 @@ SOAP_FMAC1
unsigned char*
SOAP_FMAC2
soap_getbase64(struct soap *soap, int *n, int malloc_flag)
-{
+{ (void)malloc_flag;
#ifdef WITH_DOM
if ((soap->mode & SOAP_XML_DOM) && soap->dom)
{ soap->dom->data = soap_string_in(soap, 0, -1, -1);
@@ -1921,6 +1930,8 @@ soap_getbase64(struct soap *soap, int *n, int malloc_flag)
register int j = 0;
do
{ register soap_wchar c = soap_get(soap);
+ if (c < SOAP_AP)
+ c &= 0x7FFFFFFF;
if (c == '=' || c < 0)
{ unsigned char *p;
switch (j)
@@ -2037,14 +2048,13 @@ SOAP_FMAC2
soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options)
{ /* Check MTOM xop:Include element (within hex/base64Binary) */
/* TODO: this code to be obsoleted with new import/xop.h conventions */
- int body = soap->body; /* should save type too? */
+ short body = soap->body; /* should save type too? */
if (!soap_peek_element(soap))
{ if (!soap_element_begin_in(soap, "xop:Include", 0, NULL))
- { if (soap_dime_forward(soap, ptr, size, id, type, options))
+ { if (soap_dime_forward(soap, ptr, size, id, type, options)
+ || (soap->body && soap_element_end_in(soap, "xop:Include")))
return soap->error;
}
- if (soap->body && soap_element_end_in(soap, NULL))
- return soap->error;
}
soap->body = body;
return SOAP_OK;
@@ -2176,11 +2186,14 @@ soap_pop_block(struct soap *soap, struct soap_blist *b)
#endif
/******************************************************************************/
-#ifndef WITH_NOIDREF
#ifndef PALM_1
-static void
-soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2)
-{ int i;
+SOAP_FMAC1
+void
+SOAP_FMAC2
+soap_update_pointers(struct soap *soap, char *start, char *end, char *p1, char *p2)
+{
+#ifndef WITH_NOIDREF
+ int i;
register struct soap_ilist *ip = NULL;
register struct soap_flist *fp = NULL;
#ifndef WITH_LEANER
@@ -2218,7 +2231,7 @@ soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2)
#ifndef WITH_LEANER
for (xp = soap->xlist; xp; xp = xp->next)
{ if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:SOAP_STR_EOS, xp->ptr, (char*)xp->ptr + (p1-p2)));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id ? xp->id : SOAP_STR_EOS, xp->ptr, (char*)xp->ptr + (p1-p2)));
xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2));
xp->size = (int*)((char*)xp->size + (p1-p2));
xp->type = (char**)((char*)xp->type + (p1-p2));
@@ -2226,8 +2239,10 @@ soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2)
}
}
#endif
-}
+#else
+ (void)soap; (void)start; (void)end; (void)p1; (void)p2;
#endif
+}
#endif
/******************************************************************************/
@@ -2469,11 +2484,11 @@ soap_save_block(struct soap *soap, struct soap_blist *b, char *p, int flag)
if (p)
{ for (s = p, q = soap_first_block(soap, b); q; q = soap_next_block(soap, b))
{ n = soap_block_size(soap, b);
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
#ifndef WITH_NOIDREF
if (flag)
- soap_update_ptrs(soap, q, q + n, s, q);
+ soap_update_pointers(soap, q, q + n, s, q);
#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
memcpy(s, q, n);
s += n;
}
@@ -2701,12 +2716,7 @@ soap_push_namespace(struct soap *soap, const char *id, const char *ns)
if (p)
{ for (i = 0; p->id; p++, i++)
{ if (p->ns && !strcmp(ns, p->ns))
- { if (p->out)
- { SOAP_FREE(soap, p->out);
- p->out = NULL;
- }
break;
- }
if (p->out)
{ if (!strcmp(ns, p->out))
break;
@@ -2733,10 +2743,10 @@ soap_push_namespace(struct soap *soap, const char *id, const char *ns)
soap->nlist = np;
np->level = soap->level;
np->index = i;
- strcpy(np->id, id);
+ strcpy((char*)np->id, id);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
if (i < 0)
- { np->ns = strcpy(np->id + n + 1, ns);
+ { np->ns = strcpy((char*)np->id + n + 1, ns);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
}
else
@@ -3067,6 +3077,7 @@ soap_ssl_init()
#ifdef WITH_OPENSSL
SSL_library_init();
OpenSSL_add_all_algorithms(); /* 2.8.1 change (wsseapi.c) */
+ OpenSSL_add_all_digests();
#ifndef WITH_LEAN
SSL_load_error_strings();
#endif
@@ -3122,7 +3133,11 @@ soap_ssl_error(struct soap *soap, int ret)
strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");
break;
case -1:
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Error observed by underlying BIO: %s", strerror(errno));
+#else
sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));
+#endif
break;
}
}
@@ -3333,12 +3348,22 @@ ssl_verify_callback(int ok, X509_STORE_CTX *store)
#ifdef SOAP_DEBUG
if (!ok)
{ char buf[1024];
+ int err = X509_STORE_CTX_get_error(store);
X509 *cert = X509_STORE_CTX_get_current_cert(store);
- fprintf(stderr, "SSL verify error or warning with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(X509_STORE_CTX_get_error(store)));
+ fprintf(stderr, "SSL verify error or warning with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(err));
X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
fprintf(stderr, "certificate issuer %s\n", buf);
X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));
fprintf(stderr, "certificate subject %s\n", buf);
+ /* accept self signed certificates and certificates out of date */
+ switch (err)
+ { case X509_V_ERR_CERT_NOT_YET_VALID:
+ case X509_V_ERR_CERT_HAS_EXPIRED:
+ case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+ case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
+ X509_STORE_CTX_set_error(store, X509_V_OK);
+ ok = 1;
+ }
}
#endif
/* Note: return 1 to continue, but unsafe progress will be terminated by OpenSSL */
@@ -3353,13 +3378,16 @@ ssl_verify_callback(int ok, X509_STORE_CTX *store)
static int
ssl_verify_callback_allow_expired_certificate(int ok, X509_STORE_CTX *store)
{ ok = ssl_verify_callback(ok, store);
- if (ok == 0 && X509_STORE_CTX_get_error(store) == X509_V_ERR_CERT_HAS_EXPIRED)
- {
-#ifdef SOAP_DEBUG
- fprintf(stderr, "ignoring certificate expiration\n");
-#endif
- X509_STORE_CTX_set_error(store, X509_V_OK);
- ok = 1;
+ if (!ok)
+ { /* accept self signed certificates and certificates out of date */
+ switch (X509_STORE_CTX_get_error(store))
+ { case X509_V_ERR_CERT_NOT_YET_VALID:
+ case X509_V_ERR_CERT_HAS_EXPIRED:
+ case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
+ case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
+ X509_STORE_CTX_set_error(store, X509_V_OK);
+ ok = 1;
+ }
}
/* Note: return 1 to continue, but unsafe progress will be terminated by SSL */
return ok;
@@ -3414,11 +3442,11 @@ SOAP_FMAC1
int
SOAP_FMAC2
soap_ssl_accept(struct soap *soap)
-{ SOAP_SOCKET fd = soap->socket;
+{ SOAP_SOCKET sk = soap->socket;
#ifdef WITH_OPENSSL
BIO *bio;
int retries, r, s;
- if (!soap_valid_socket(fd))
+ if (!soap_valid_socket(sk))
return soap_set_receiver_error(soap, "SSL/TLS error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
soap->ssl_flags &= ~SOAP_SSL_CLIENT;
if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
@@ -3430,12 +3458,12 @@ soap_ssl_accept(struct soap *soap)
}
else
SSL_clear(soap->ssl);
- bio = BIO_new_socket((int)fd, BIO_NOCLOSE);
+ bio = BIO_new_socket((int)sk, BIO_NOCLOSE);
SSL_set_bio(soap->ssl, bio, bio);
/* Set SSL sockets to non-blocking */
retries = 0;
if (soap->accept_timeout)
- { SOAP_SOCKNONBLOCK(fd)
+ { SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->accept_timeout;
}
if (retries <= 0)
@@ -3447,14 +3475,14 @@ soap_ssl_accept(struct soap *soap)
err = SSL_get_error(soap->ssl, r);
if (err == SSL_ERROR_WANT_ACCEPT || err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
{ if (err == SSL_ERROR_WANT_READ)
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0 && soap->errnum != SOAP_EINTR)
break;
}
else
- { soap->errnum = soap_socket_errno(fd);
+ { soap->errnum = soap_socket_errno(sk);
break;
}
}
@@ -3480,17 +3508,17 @@ soap_ssl_accept(struct soap *soap)
#endif
#ifdef WITH_GNUTLS
int retries = 0, r;
- if (!soap_valid_socket(fd))
+ if (!soap_valid_socket(sk))
return soap_set_receiver_error(soap, "SSL/TLS error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
soap->ssl_flags &= ~SOAP_SSL_CLIENT;
if (!soap->session && (soap->error = soap->fsslauth(soap)))
{ soap_closesock(soap);
return soap->error;
}
- gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)fd);
+ gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)sk);
/* Set SSL sockets to non-blocking */
if (soap->accept_timeout)
- { SOAP_SOCKNONBLOCK(fd)
+ { SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->accept_timeout;
}
if (retries <= 0)
@@ -3502,14 +3530,14 @@ soap_ssl_accept(struct soap *soap)
break;
if (r == GNUTLS_E_AGAIN || r == GNUTLS_E_INTERRUPTED)
{ if (!gnutls_record_get_direction(soap->session))
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0 && soap->errnum != SOAP_EINTR)
break;
}
else
- { soap->errnum = soap_socket_errno(fd);
+ { soap->errnum = soap_socket_errno(sk);
break;
}
}
@@ -3526,9 +3554,9 @@ soap_ssl_accept(struct soap *soap)
}
#endif
if (soap->recv_timeout || soap->send_timeout)
- SOAP_SOCKNONBLOCK(fd)
+ SOAP_SOCKNONBLOCK(sk)
else
- SOAP_SOCKBLOCK(fd)
+ SOAP_SOCKBLOCK(sk)
soap->imode |= SOAP_ENC_SSL;
soap->omode |= SOAP_ENC_SSL;
return SOAP_OK;
@@ -3672,7 +3700,7 @@ tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
#ifdef WITH_IPV6
struct addrinfo hints, *res, *ressave;
#endif
- SOAP_SOCKET fd;
+ SOAP_SOCKET sk;
int err = 0;
#ifndef WITH_LEAN
#ifndef WIN32
@@ -3714,7 +3742,7 @@ tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
}
ressave = res;
again:
- fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ sk = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
soap->errmode = 0;
#else
#ifndef WITH_LEAN
@@ -3722,12 +3750,12 @@ again:
#endif
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
- fd = socket(AF_INET, SOCK_DGRAM, 0);
+ sk = socket(AF_INET, SOCK_DGRAM, 0);
else
#endif
- fd = socket(AF_INET, SOCK_STREAM, 0);
+ sk = socket(AF_INET, SOCK_STREAM, 0);
#endif
- if (!soap_valid_socket(fd))
+ if (!soap_valid_socket(sk))
{
#ifdef WITH_IPV6
if (res->ai_next)
@@ -3735,7 +3763,7 @@ again:
goto again;
}
#endif
- soap->errnum = soap_socket_errno(fd);
+ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
@@ -3745,10 +3773,10 @@ again:
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
+ SetHandleInformation((HANDLE)sk, HANDLE_FLAG_INHERIT, 0);
#endif
#else
- fcntl(fd, F_SETFD, 1);
+ fcntl(sk, F_SETFD, 1);
#endif
#endif
#ifndef WITH_LEAN
@@ -3757,57 +3785,57 @@ again:
memset((void*)&linger, 0, sizeof(linger));
linger.l_onoff = 1;
linger.l_linger = soap->linger_time;
- if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno(fd);
+ if (setsockopt(sk, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
}
- else if (soap->connect_flags && setsockopt(fd, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ else if (soap->connect_flags && setsockopt(sk, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
- if ((soap->keep_alive || soap->tcp_keep_alive) && setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if ((soap->keep_alive || soap->tcp_keep_alive) && setsockopt(sk, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
- if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (setsockopt(sk, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
- if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (setsockopt(sk, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
return SOAP_INVALID_SOCKET;
}
#ifdef TCP_KEEPIDLE
- if (soap->tcp_keep_idle && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPIDLE, (char*)&(soap->tcp_keep_idle), sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (soap->tcp_keep_idle && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPIDLE, (char*)&(soap->tcp_keep_idle), sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPIDLE failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
+ soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3815,10 +3843,10 @@ again:
}
#endif
#ifdef TCP_KEEPINTVL
- if (soap->tcp_keep_intvl && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPINTVL, (char*)&(soap->tcp_keep_intvl), sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (soap->tcp_keep_intvl && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPINTVL, (char*)&(soap->tcp_keep_intvl), sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPINTVL failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
+ soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3826,10 +3854,10 @@ again:
}
#endif
#ifdef TCP_KEEPCNT
- if (soap->tcp_keep_cnt && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPCNT, (char*)&(soap->tcp_keep_cnt), sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (soap->tcp_keep_cnt && setsockopt((SOAP_SOCKET)sk, IPPROTO_TCP, TCP_KEEPCNT, (char*)&(soap->tcp_keep_cnt), sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPCNT failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
+ soap->fclosesocket(soap, (SOAP_SOCKET)sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3837,10 +3865,10 @@ again:
}
#endif
#ifdef TCP_NODELAY
- if (!(soap->omode & SOAP_IO_UDP) && setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno(fd);
+ if (!(soap->omode & SOAP_IO_UDP) && setsockopt(sk, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3857,29 +3885,29 @@ again:
if ((soap->omode & SOAP_IO_UDP))
{ if (soap->ipv4_multicast_ttl)
{ unsigned char ttl = soap->ipv4_multicast_ttl;
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl)))
- { soap->errnum = soap_socket_errno(fd);
+ if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_TTL failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
if ((soap->omode & SOAP_IO_UDP) && soap->ipv4_multicast_if && !soap->ipv6_multicast_if)
- { if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
+ { if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
#ifndef WINDOWS
- { soap->errnum = soap_socket_errno(fd);
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_IF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
#else
#ifndef IP_MULTICAST_IF
#define IP_MULTICAST_IF 2
#endif
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
- { soap->errnum = soap_socket_errno(fd);
+ if (setsockopt(sk, IPPROTO_IP, IP_MULTICAST_IF, (char*)soap->ipv4_multicast_if, sizeof(struct in_addr)))
+ { soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "setsockopt IP_MULTICAST_IF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
#endif
@@ -3887,7 +3915,7 @@ again:
}
#endif
#endif
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port));
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", sk, host, port));
#ifndef WITH_IPV6
soap->peerlen = sizeof(soap->peer);
memset((void*)&soap->peer, 0, sizeof(soap->peer));
@@ -3896,7 +3924,7 @@ again:
if (soap->proxy_host)
{ if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr))
{ soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->peer.sin_port = htons((short)soap->proxy_port);
@@ -3904,7 +3932,7 @@ again:
else
{ if (soap->fresolve(soap, host, &soap->peer.sin_addr))
{ soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
soap->peer.sin_port = htons((short)port);
@@ -3912,34 +3940,34 @@ again:
soap->errmode = 0;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
- return fd;
+ return sk;
#endif
#else
if ((soap->omode & SOAP_IO_UDP))
{ memcpy(&soap->peer, res->ai_addr, res->ai_addrlen);
soap->peerlen = res->ai_addrlen;
freeaddrinfo(ressave);
- return fd;
+ return sk;
}
#endif
#ifndef WITH_LEAN
if (soap->connect_timeout)
- SOAP_SOCKNONBLOCK(fd)
+ SOAP_SOCKNONBLOCK(sk)
else
- SOAP_SOCKBLOCK(fd)
+ SOAP_SOCKBLOCK(sk)
retries = 10;
#endif
for (;;)
{
#ifdef WITH_IPV6
- if (connect(fd, res->ai_addr, (int)res->ai_addrlen))
+ if (connect(sk, res->ai_addr, (int)res->ai_addrlen))
#else
- if (connect(fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer)))
+ if (connect(sk, (struct sockaddr*)&soap->peer, sizeof(soap->peer)))
#endif
- { err = soap_socket_errno(fd);
+ { err = soap_socket_errno(sk);
#ifndef WITH_LEAN
if (err == SOAP_EADDRINUSE)
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
if (retries-- > 0)
goto again;
}
@@ -3948,13 +3976,13 @@ again:
SOAP_SOCKLEN_T k;
for (;;)
{ register int r;
- r = tcp_select(soap, fd, SOAP_TCP_SELECT_SND, soap->connect_timeout);
+ r = tcp_select(soap, sk, SOAP_TCP_SELECT_SND, soap->connect_timeout);
if (r > 0)
break;
if (!r)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
soap_set_sender_error(soap, "Timeout", "connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3964,7 +3992,7 @@ again:
if (r != SOAP_EINTR)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3972,13 +4000,13 @@ again:
}
}
k = (SOAP_SOCKLEN_T)sizeof(soap->errnum);
- if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
+ if (!getsockopt(sk, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
break;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
if (!soap->errnum)
- soap->errnum = soap_socket_errno(fd);
+ soap->errnum = soap_socket_errno(sk);
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -3988,7 +4016,7 @@ again:
#ifdef WITH_IPV6
if (res->ai_next)
{ res = res->ai_next;
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
goto again;
}
#endif
@@ -3996,7 +4024,7 @@ again:
{ soap->errnum = err;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
#ifdef WITH_IPV6
freeaddrinfo(ressave);
#endif
@@ -4010,7 +4038,7 @@ again:
soap->peerlen = 0; /* IPv6: already connected so use send() */
freeaddrinfo(ressave);
#endif
- soap->socket = fd;
+ soap->socket = sk;
soap->imode &= ~SOAP_ENC_SSL;
soap->omode &= ~SOAP_ENC_SSL;
if (!soap_tag_cmp(endpoint, "https:*"))
@@ -4025,46 +4053,45 @@ again:
soap_mode om = soap->omode; /* make sure we only parse HTTP */
size_t n = soap->count; /* save the content length */
const char *userid, *passwd;
+ int status = soap->status; /* save the current status/command */
+ short keep_alive = soap->keep_alive; /* save the KA status */
soap->omode &= ~SOAP_ENC; /* mask IO and ENC */
soap->omode |= SOAP_IO_BUFFER;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server\n", soap->proxy_http_version));
- sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->proxy_http_version);
- if (soap_begin_send(soap)
- || (soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- { soap->fclosesocket(soap, fd);
- return SOAP_INVALID_SOCKET;
- }
-#ifndef WITH_LEAN
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- { soap->fclosesocket(soap, fd);
+#ifdef WITH_NTLM
+ if (soap->ntlm_challenge)
+ { if (soap_ntlm_handshake(soap, SOAP_CONNECT, endpoint, host, port))
return soap->error;
- }
}
#endif
- if ((soap->error = soap->fposthdr(soap, NULL, NULL))
- || soap_flush(soap))
- { soap->fclosesocket(soap, fd);
+ if (soap_begin_send(soap))
+ { soap->fclosesocket(soap, sk);
+ return SOAP_INVALID_SOCKET;
+ }
+ soap->status = SOAP_CONNECT;
+ soap->keep_alive = 1;
+ if ((soap->error = soap->fpost(soap, endpoint, host, port, NULL, NULL, 0))
+ || soap_end_send(soap))
+ { soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
+ soap->keep_alive = keep_alive;
soap->omode = om;
om = soap->imode;
soap->imode &= ~SOAP_ENC; /* mask IO and ENC */
userid = soap->userid; /* preserve */
passwd = soap->passwd; /* preserve */
if ((soap->error = soap->fparse(soap)))
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
+ soap->status = status; /* restore */
soap->userid = userid; /* restore */
soap->passwd = passwd; /* restore */
soap->imode = om; /* restore */
soap->count = n; /* restore */
if (soap_begin_send(soap))
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (endpoint)
@@ -4074,13 +4101,15 @@ again:
#ifdef WITH_OPENSSL
soap->ssl_flags |= SOAP_SSL_CLIENT;
if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- { soap->fclosesocket(soap, fd);
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL required, but no ctx set\n"));
+ soap->fclosesocket(soap, sk);
+ soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
}
if (!soap->ssl)
{ soap->ssl = SSL_new(soap->ctx);
if (!soap->ssl)
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
}
@@ -4095,16 +4124,16 @@ again:
}
soap->imode |= SOAP_ENC_SSL;
soap->omode |= SOAP_ENC_SSL;
- bio = BIO_new_socket((int)fd, BIO_NOCLOSE);
+ bio = BIO_new_socket((int)sk, BIO_NOCLOSE);
SSL_set_bio(soap->ssl, bio, bio);
/* Connect timeout: set SSL sockets to non-blocking */
retries = 0;
if (soap->connect_timeout)
- { SOAP_SOCKNONBLOCK(fd)
+ { SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->connect_timeout;
}
else
- SOAP_SOCKBLOCK(fd)
+ SOAP_SOCKBLOCK(sk)
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
/* Try connecting until success or timeout (when nonblocking) */
@@ -4114,37 +4143,37 @@ again:
if (err == SSL_ERROR_WANT_CONNECT || err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
{ register int s;
if (err == SSL_ERROR_WANT_READ)
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0 && soap->errnum != SOAP_EINTR)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL_connect/select error in tcp_connect\n"));
soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL_connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (s == 0 && retries-- <= 0)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "SSL/TLS connect timeout\n"));
soap_set_sender_error(soap, "Timeout", "SSL_connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
else
{ soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL_connect error in tcp_connect()", SOAP_SSL_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
} while (!SSL_is_init_finished(soap->ssl));
/* Set SSL sockets to nonblocking */
- SOAP_SOCKNONBLOCK(fd)
+ SOAP_SOCKNONBLOCK(sk)
/* Check server credentials when required */
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION))
{ int err;
if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
{ soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL/TLS certificate presented by peer cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK))
@@ -4155,7 +4184,7 @@ again:
peer = SSL_get_peer_certificate(soap->ssl);
if (!peer)
{ soap_set_sender_error(soap, "SSL/TLS error", "No SSL/TLS certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
ext_count = X509_get_ext_count(peer);
@@ -4249,7 +4278,7 @@ again:
X509_free(peer);
if (!ok)
{ soap_set_sender_error(soap, "SSL/TLS error", "SSL/TLS certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
}
@@ -4258,17 +4287,17 @@ again:
#ifdef WITH_GNUTLS
soap->ssl_flags |= SOAP_SSL_CLIENT;
if (!soap->session && (soap->error = soap->fsslauth(soap)))
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
- gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)fd);
+ gnutls_transport_set_ptr(soap->session, (gnutls_transport_ptr_t)(long)sk);
/* Set SSL sockets to non-blocking */
if (soap->connect_timeout)
- { SOAP_SOCKNONBLOCK(fd)
+ { SOAP_SOCKNONBLOCK(sk)
retries = 10*soap->connect_timeout;
}
else
- SOAP_SOCKBLOCK(fd)
+ SOAP_SOCKBLOCK(sk)
if (retries <= 0)
retries = 100; /* timeout: 10 sec retries, 100 times 0.1 sec */
while ((r = gnutls_handshake(soap->session)))
@@ -4278,42 +4307,42 @@ again:
break;
if (r == GNUTLS_E_AGAIN || r == GNUTLS_E_INTERRUPTED)
{ if (!gnutls_record_get_direction(soap->session))
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, -100000);
else
- s = tcp_select(soap, fd, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
+ s = tcp_select(soap, sk, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, -100000);
if (s < 0 && soap->errnum != SOAP_EINTR)
break;
}
else
- { soap->errnum = soap_socket_errno(fd);
+ { soap->errnum = soap_socket_errno(sk);
break;
}
}
if (r)
{ soap_set_sender_error(soap, soap_ssl_error(soap, r), "SSL/TLS handshake failed", SOAP_SSL_ERROR);
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
return SOAP_INVALID_SOCKET;
}
if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION))
{ const char *err = ssl_verify(soap, host);
if (err)
- { soap->fclosesocket(soap, fd);
+ { soap->fclosesocket(soap, sk);
soap->error = soap_set_sender_error(soap, "SSL/TLS error", err, SOAP_SSL_ERROR);
return SOAP_INVALID_SOCKET;
}
}
#endif
#else
- soap->fclosesocket(soap, fd);
+ soap->fclosesocket(soap, sk);
soap->error = SOAP_SSL_ERROR;
return SOAP_INVALID_SOCKET;
#endif
}
if (soap->recv_timeout || soap->send_timeout)
- SOAP_SOCKNONBLOCK(fd)
+ SOAP_SOCKNONBLOCK(sk)
else
- SOAP_SOCKBLOCK(fd)
- return fd;
+ SOAP_SOCKBLOCK(sk)
+ return sk;
}
#endif
#endif
@@ -4322,7 +4351,7 @@ again:
#ifndef WITH_NOIO
#ifndef PALM_1
static int
-tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
+tcp_select(struct soap *soap, SOAP_SOCKET sk, int flags, int timeout)
{ register int r;
struct timeval tv;
fd_set fd[3], *rfd, *sfd, *efd;
@@ -4333,12 +4362,12 @@ tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
if (1)
#else
/* if fd max set size exceeded, use poll() */
- if ((int)s >= (int)FD_SETSIZE)
+ if ((int)sk >= (int)FD_SETSIZE)
#endif
#ifdef HAVE_POLL
{ struct pollfd pollfd;
int retries = 0;
- pollfd.fd = (int)s;
+ pollfd.fd = (int)sk;
pollfd.events = 0;
if (flags & SOAP_TCP_SELECT_RCV)
pollfd.events |= POLLIN;
@@ -4379,17 +4408,17 @@ tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
if (flags & SOAP_TCP_SELECT_RCV)
{ rfd = &fd[0];
FD_ZERO(rfd);
- FD_SET(s, rfd);
+ FD_SET(sk, rfd);
}
if (flags & SOAP_TCP_SELECT_SND)
{ sfd = &fd[1];
FD_ZERO(sfd);
- FD_SET(s, sfd);
+ FD_SET(sk, sfd);
}
if (flags & SOAP_TCP_SELECT_ERR)
{ efd = &fd[2];
FD_ZERO(efd);
- FD_SET(s, efd);
+ FD_SET(sk, efd);
}
if (timeout >= 0)
{ tv.tv_sec = timeout;
@@ -4399,14 +4428,14 @@ tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
{ tv.tv_sec = -timeout / 1000000;
tv.tv_usec = -timeout % 1000000;
}
- r = select((int)s + 1, rfd, sfd, efd, &tv);
+ r = select((int)sk + 1, rfd, sfd, efd, &tv);
if (r > 0)
{ r = 0;
- if ((flags & SOAP_TCP_SELECT_RCV) && FD_ISSET(s, rfd))
+ if ((flags & SOAP_TCP_SELECT_RCV) && FD_ISSET(sk, rfd))
r |= SOAP_TCP_SELECT_RCV;
- if ((flags & SOAP_TCP_SELECT_SND) && FD_ISSET(s, sfd))
+ if ((flags & SOAP_TCP_SELECT_SND) && FD_ISSET(sk, sfd))
r |= SOAP_TCP_SELECT_SND;
- if ((flags & SOAP_TCP_SELECT_ERR) && FD_ISSET(s, efd))
+ if ((flags & SOAP_TCP_SELECT_ERR) && FD_ISSET(sk, efd))
r |= SOAP_TCP_SELECT_ERR;
}
else if (r < 0)
@@ -4421,18 +4450,19 @@ tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
#ifndef PALM_1
static SOAP_SOCKET
tcp_accept(struct soap *soap, SOAP_SOCKET s, struct sockaddr *a, int *n)
-{ SOAP_SOCKET fd;
- fd = accept(s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
+{ SOAP_SOCKET sk;
+ (void)soap;
+ sk = accept(s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */
#ifdef SOCKET_CLOSE_ON_EXEC
#ifdef WIN32
#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
+ SetHandleInformation((HANDLE)sk, HANDLE_FLAG_INHERIT, 0);
#endif
#else
- fcntl(fd, F_SETFD, FD_CLOEXEC);
+ fcntl(sk, F_SETFD, FD_CLOEXEC);
#endif
#endif
- return fd;
+ return sk;
}
#endif
#endif
@@ -4533,9 +4563,10 @@ tcp_disconnect(struct soap *soap)
#ifndef WITH_NOIO
#ifndef PALM_1
static int
-tcp_closesocket(struct soap *soap, SOAP_SOCKET fd)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd));
- return soap_closesocket(fd);
+tcp_closesocket(struct soap *soap, SOAP_SOCKET sk)
+{ (void)soap;
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)sk));
+ return soap_closesocket(sk);
}
#endif
#endif
@@ -4544,9 +4575,10 @@ tcp_closesocket(struct soap *soap, SOAP_SOCKET fd)
#ifndef WITH_NOIO
#ifndef PALM_1
static int
-tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, how));
- return shutdown(fd, how);
+tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET sk, int how)
+{ (void)soap;
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)sk, how));
+ return shutdown(sk, how);
}
#endif
#endif
@@ -4569,7 +4601,7 @@ soap_bind(struct soap *soap, const char *host, int port, int backlog)
#endif
#endif
#ifndef WITH_LEAN
-#ifndef WITH_WIN32
+#ifndef WIN32
int len = SOAP_BUFLEN;
#else
int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
@@ -4623,6 +4655,7 @@ soap_bind(struct soap *soap, const char *host, int port, int backlog)
soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
+ soap->port = port;
#ifndef WITH_LEAN
if ((soap->omode & SOAP_IO_UDP))
soap->socket = soap->master;
@@ -4642,7 +4675,7 @@ soap_bind(struct soap *soap, const char *host, int port, int backlog)
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
- if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
+ if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && (!((soap->imode | soap->omode) & SOAP_IO_UDP)) && setsockopt(soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
@@ -4669,14 +4702,14 @@ soap_bind(struct soap *soap, const char *host, int port, int backlog)
#ifdef WITH_IPV6_V6ONLY
if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&set, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt set IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
#ifdef WITH_NO_IPV6_V6ONLY
if (setsockopt(soap->master, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&unset, sizeof(int)))
{ soap->errnum = soap_socket_errno(soap->master);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt unset IPV6_V6ONLY failed in soap_bind()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
#endif
@@ -4784,8 +4817,9 @@ SOAP_SOCKET
SOAP_FMAC2
soap_accept(struct soap *soap)
{ int n = (int)sizeof(soap->peer);
+ register int err;
#ifndef WITH_LEAN
-#ifndef WITH_WIN32
+#ifndef WIN32
int len = SOAP_BUFLEN;
#else
int len = SOAP_BUFLEN + 1; /* speeds up windows xfer */
@@ -4793,124 +4827,123 @@ soap_accept(struct soap *soap)
int set = 1;
#endif
soap->error = SOAP_OK;
-#ifndef WITH_LEAN
- if ((soap->omode & SOAP_IO_UDP))
- return soap->socket = soap->master;
-#endif
memset((void*)&soap->peer, 0, sizeof(soap->peer));
soap->socket = SOAP_INVALID_SOCKET;
soap->errmode = 0;
soap->keep_alive = 0;
- if (soap_valid_socket(soap->master))
- { register int err;
- for (;;)
- { if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout)
- { for (;;)
- { register int r;
- r = tcp_select(soap, soap->master, SOAP_TCP_SELECT_ALL, soap->accept_timeout ? soap->accept_timeout : 60);
- if (r > 0)
- break;
- if (!r && soap->accept_timeout)
- { soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR);
+ if (!soap_valid_socket(soap->master))
+ { soap->errnum = 0;
+ soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR);
+ return SOAP_INVALID_SOCKET;
+ }
+#ifndef WITH_LEAN
+ if ((soap->omode & SOAP_IO_UDP))
+ return soap->socket = soap->master;
+#endif
+ for (;;)
+ { if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout)
+ { for (;;)
+ { register int r;
+ r = tcp_select(soap, soap->master, SOAP_TCP_SELECT_ALL, soap->accept_timeout ? soap->accept_timeout : 60);
+ if (r > 0)
+ break;
+ if (!r && soap->accept_timeout)
+ { soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR);
+ return SOAP_INVALID_SOCKET;
+ }
+ if (r < 0)
+ { r = soap->errnum;
+ if (r != SOAP_EINTR)
+ { soap_closesock(soap);
+ soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
return SOAP_INVALID_SOCKET;
}
- if (r < 0)
- { r = soap->errnum;
- if (r != SOAP_EINTR)
- { soap_closesock(soap);
- soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
- return SOAP_INVALID_SOCKET;
- }
- }
}
}
- if (soap->accept_timeout)
- SOAP_SOCKNONBLOCK(soap->master)
- else
- SOAP_SOCKBLOCK(soap->master)
- soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n);
- soap->peerlen = (size_t)n;
- if (soap_valid_socket(soap->socket))
- {
+ }
+ if (soap->accept_timeout)
+ SOAP_SOCKNONBLOCK(soap->master)
+ else
+ SOAP_SOCKBLOCK(soap->master)
+ soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n);
+ soap->peerlen = (size_t)n;
+ if (soap_valid_socket(soap->socket))
+ {
#ifdef WITH_IPV6
-/* Use soap->host to store the numeric form of the remote host */
- getnameinfo((struct sockaddr*)&soap->peer, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d from %s\n", soap->socket, soap->host));
- soap->ip = 0; /* info stored in soap->peer and soap->host */
- soap->port = 0; /* info stored in soap->peer and soap->host */
+ unsigned int ip1, ip2, ip3, ip4;
+ char port[16];
+ getnameinfo((struct sockaddr*)&soap->peer, n, soap->host, sizeof(soap->host), port, 16, NI_NUMERICHOST | NI_NUMERICSERV);
+ sscanf(soap->host, "%u.%u.%u.%u", &ip1, &ip2, &ip3, &ip4);
+ soap->ip = (unsigned long)ip1 << 24 | (unsigned long)ip2 << 16 | (unsigned long)ip3 << 8 | (unsigned long)ip4;
+ soap->port = soap_strtol(port, NULL, 10);
#else
- soap->ip = ntohl(soap->peer.sin_addr.s_addr);
- soap->port = (int)ntohs(soap->peer.sin_port); /* does not return port number on some systems */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d at port %d from IP %d.%d.%d.%d\n", soap->socket, soap->port, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF));
+ soap->ip = ntohl(soap->peer.sin_addr.s_addr);
+ sprintf(soap->host, "%u.%u.%u.%u", (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
+ soap->port = (int)ntohs(soap->peer.sin_port); /* does not return port number on some systems */
#endif
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d at port %d from IP %s\n", soap->socket, soap->port, soap->host));
#ifndef WITH_LEAN
- if (soap->accept_flags == SO_LINGER)
- { struct linger linger;
- memset((void*)&linger, 0, sizeof(linger));
- linger.l_onoff = 1;
- linger.l_linger = soap->linger_time;
- if (setsockopt(soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
- soap_closesock(soap);
- return SOAP_INVALID_SOCKET;
- }
- }
- else if (soap->accept_flags && setsockopt(soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int)))
+ if (soap->accept_flags == SO_LINGER)
+ { struct linger linger;
+ memset((void*)&linger, 0, sizeof(linger));
+ linger.l_onoff = 1;
+ linger.l_linger = soap->linger_time;
+ if (setsockopt(soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
{ soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
- soap_closesock(soap);
- return SOAP_INVALID_SOCKET;
- }
- if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
- soap_closesock(soap);
- return SOAP_INVALID_SOCKET;
- }
- if (setsockopt(soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
- soap_closesock(soap);
- return SOAP_INVALID_SOCKET;
- }
- if (setsockopt(soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
+ }
+ else if (soap->accept_flags && setsockopt(soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(soap->socket);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_closesock(soap);
+ return SOAP_INVALID_SOCKET;
+ }
+ if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(soap->socket);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_closesock(soap);
+ return SOAP_INVALID_SOCKET;
+ }
+ if (setsockopt(soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
+ { soap->errnum = soap_socket_errno(soap->socket);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_closesock(soap);
+ return SOAP_INVALID_SOCKET;
+ }
+ if (setsockopt(soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
+ { soap->errnum = soap_socket_errno(soap->socket);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_closesock(soap);
+ return SOAP_INVALID_SOCKET;
+ }
#ifdef TCP_NODELAY
- if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno(soap->socket);
- soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
- soap_closesock(soap);
- return SOAP_INVALID_SOCKET;
- }
-#endif
-#endif
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
- if (soap->send_timeout || soap->recv_timeout)
- SOAP_SOCKNONBLOCK(soap->socket)
- else
- SOAP_SOCKBLOCK(soap->socket)
- return soap->socket;
- }
- err = soap_socket_errno(soap->socket);
- if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host));
- soap->errnum = err;
- soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
+ if (setsockopt(soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
+ { soap->errnum = soap_socket_errno(soap->socket);
+ soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
soap_closesock(soap);
return SOAP_INVALID_SOCKET;
}
+#endif
+#endif
+ soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
+ if (soap->send_timeout || soap->recv_timeout)
+ SOAP_SOCKNONBLOCK(soap->socket)
+ else
+ SOAP_SOCKBLOCK(soap->socket)
+ return soap->socket;
+ }
+ err = soap_socket_errno(soap->socket);
+ if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
+ { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host));
+ soap->errnum = err;
+ soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR);
+ soap_closesock(soap);
+ return SOAP_INVALID_SOCKET;
}
}
- else
- { soap->errnum = 0;
- soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR);
- return SOAP_INVALID_SOCKET;
- }
}
#endif
#endif
@@ -4949,6 +4982,19 @@ soap_closesock(struct soap *soap)
#endif
/******************************************************************************/
+#ifndef PALM_1
+SOAP_FMAC1
+int
+SOAP_FMAC2
+soap_force_closesock(struct soap *soap)
+{ soap->keep_alive = 0;
+ if (soap_valid_socket(soap->socket))
+ return soap_closesocket(soap->socket);
+ return SOAP_OK;
+}
+#endif
+
+/******************************************************************************/
#ifndef WITH_NOIO
#ifndef PALM_2
SOAP_FMAC1
@@ -5004,11 +5050,11 @@ soap_done(struct soap *soap)
soap->fmalloc = NULL;
#ifndef WITH_NOHTTP
soap->fpost = http_post;
- soap->fput = http_put;
soap->fget = http_get;
+ soap->fput = http_405;
soap->fdel = http_405;
- soap->fopt = http_405;
- soap->fhead = http_405;
+ soap->fopt = http_200;
+ soap->fhead = http_200;
soap->fform = NULL;
soap->fposthdr = http_post_header;
soap->fresponse = http_response;
@@ -5106,7 +5152,11 @@ soap_done(struct soap *soap)
}
#endif
#ifdef WITH_C_LOCALE
+# ifdef WIN32
+ _free_locale(soap->c_locale);
+# else
freelocale(soap->c_locale);
+# endif
#endif
#ifdef WITH_ZLIB
if (soap->d_stream)
@@ -5147,16 +5197,24 @@ soap_done(struct soap *soap)
int
http_parse(struct soap *soap)
{ char header[SOAP_HDRLEN], *s;
- unsigned short httpcmd = 0, status = 0;
+ unsigned short httpcmd = 0;
+ int status = 0;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n"));
*soap->endpoint = '\0';
soap->length = 0;
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->action = NULL;
- soap->authrealm = NULL;
+#ifdef WITH_NTLM
+ if (!soap->ntlm_challenge)
+#endif
+ { soap->userid = NULL;
+ soap->passwd = NULL;
+ soap->authrealm = NULL;
+ }
+#ifdef WITH_NTLM
+ soap->ntlm_challenge = NULL;
+#endif
soap->proxy_from = NULL;
soap->http_content = NULL;
+ soap->action = NULL;
soap->status = 0;
do
{ if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
@@ -5245,6 +5303,8 @@ http_parse(struct soap *soap)
n = sizeof(soap->endpoint) - 1;
strncpy(soap->path, soap->msgbuf + l, n - m);
soap->path[n - m] = '\0';
+ if (*soap->path && *soap->path != '/')
+ *soap->endpoint = '\0';
strcat(soap->endpoint, soap->path);
DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
if (httpcmd > 1)
@@ -5277,7 +5337,7 @@ http_parse(struct soap *soap)
may not have a body. When content length, content type, or chunking is
used assume there is a message to parse, either XML or HTTP.
*/
- if (soap->length > 0 || (soap->http_content && soap->recv_timeout) || (soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
+ if (soap->length > 0 || (soap->http_content && (!soap->keep_alive || soap->recv_timeout)) || (soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
{ if ((soap->status > 200 && soap->status <= 299)
|| soap->status == 400
|| soap->status == 500)
@@ -5392,8 +5452,14 @@ http_parse_header(struct soap *soap, const char *key, const char *val)
}
}
}
- else if (!soap_tag_cmp(key, "WWW-Authenticate"))
- { soap->authrealm = soap_strdup(soap, soap_get_header_attribute(soap, val + 6, "realm"));
+ else if (!soap_tag_cmp(key, "WWW-Authenticate") || !soap_tag_cmp(key, "Proxy-Authenticate"))
+ {
+#ifdef WITH_NTLM
+ if (!soap_tag_cmp(val, "NTLM*"))
+ soap->ntlm_challenge = soap_strdup(soap, val + 4);
+ else
+#endif
+ soap->authrealm = soap_strdup(soap, soap_get_header_attribute(soap, val + 6, "realm"));
}
else if (!soap_tag_cmp(key, "Expect"))
{ if (!soap_tag_cmp(val, "100-continue"))
@@ -5522,6 +5588,7 @@ soap_decode(char *buf, size_t len, const char *val, const char *sep)
static const char*
http_error(struct soap *soap, int status)
{ register const char *msg = SOAP_STR_EOS;
+ (void)soap;
#ifndef WITH_LEAN
msg = soap_code_str(h_http_error_codes, status);
if (!msg)
@@ -5533,21 +5600,25 @@ http_error(struct soap *soap, int status)
#endif
/******************************************************************************/
+
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
-http_put(struct soap *soap)
-{ return http_parse(soap);
+http_get(struct soap *soap)
+{ (void)soap;
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP GET request\n"));
+ return SOAP_GET_METHOD;
}
#endif
#endif
-/******************************************************************************/
+/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
-http_get(struct soap *soap)
-{ return SOAP_GET_METHOD;
+http_405(struct soap *soap)
+{ return 405;
+ (void)soap;
}
#endif
#endif
@@ -5556,8 +5627,8 @@ http_get(struct soap *soap)
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
-http_405(struct soap *soap)
-{ return 405;
+http_200(struct soap *soap)
+{ return soap_send_empty_response(soap, 200);
}
#endif
#endif
@@ -5569,10 +5640,23 @@ static int
http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
{ register const char *s;
register int err;
- if (soap->status == SOAP_GET)
- s = "GET";
- else
- s = "POST";
+ switch (soap->status)
+ { case SOAP_GET:
+ s = "GET";
+ break;
+ case SOAP_PUT:
+ s = "PUT";
+ break;
+ case SOAP_DEL:
+ s = "DELETE";
+ break;
+ case SOAP_CONNECT:
+ s = "CONNECT";
+ break;
+ default:
+ s = "POST";
+ }
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "HTTP %s to %s\n", s, endpoint ? endpoint : "(null)"));
#ifdef PALM
if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
#else
@@ -5580,24 +5664,30 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c
#endif
return SOAP_OK;
if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80)
- return soap->error = SOAP_EOM;
- if (soap->proxy_host && soap_tag_cmp(endpoint, "https:*"))
+ return soap->error = SOAP_EOM; /* prevent overrun */
+ if (soap->status == SOAP_CONNECT)
+ sprintf(soap->tmpbuf, "%s %s:%d HTTP/%s", s, soap->host, soap->port, soap->http_version);
+ else if (soap->proxy_host && endpoint)
sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
else
sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version);
if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
return err;
#ifdef WITH_OPENSSL
- if ((soap->ssl && soap->port != 443) || (!soap->ssl && soap->port != 80))
- sprintf(soap->tmpbuf, "%s:%d", host, port);
- else
- strcpy(soap->tmpbuf, host);
+ if ((soap->ssl && port != 443) || (!soap->ssl && port != 80))
#else
if (port != 80)
- sprintf(soap->tmpbuf, "%s:%d", host, port);
+#endif
+ {
+#ifdef WITH_IPV6
+ if (*host != '[' && strchr(host, ':'))
+ sprintf(soap->tmpbuf, "[%s]:%d", host, port); /* RFC 2732 */
+ else
+#endif
+ sprintf(soap->tmpbuf, "%s:%d", host, port);
+ }
else
strcpy(soap->tmpbuf, host);
-#endif
if ((err = soap->fposthdr(soap, "Host", soap->tmpbuf)))
return err;
if ((err = soap->fposthdr(soap, "User-Agent", "gSOAP/2.8")))
@@ -5614,16 +5704,30 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c
#endif
#ifndef WITH_LEAN
if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
+ {
+#ifdef WITH_NTLM
+ if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf))
+ sprintf(soap->tmpbuf, "NTLM %s", soap->ntlm_challenge);
+ else
+#endif
+ { strcpy(soap->tmpbuf, "Basic ");
+ sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
+ soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
+ }
if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
return err;
}
if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
+ {
+#ifdef WITH_NTLM
+ if (soap->ntlm_challenge && strlen(soap->ntlm_challenge) + 6 < sizeof(soap->tmpbuf))
+ sprintf(soap->tmpbuf, "NTLM %s", soap->ntlm_challenge);
+ else
+#endif
+ { strcpy(soap->tmpbuf, "Basic ");
+ sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
+ soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, (int)strlen(soap->tmpbuf + 262));
+ }
if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
return err;
}
@@ -5637,7 +5741,7 @@ http_post(struct soap *soap, const char *endpoint, const char *host, int port, c
return soap->error;
#endif
#endif
- if (soap->status != SOAP_GET && soap->version == 1)
+ if (action && soap->status != SOAP_GET && soap->status != SOAP_DEL)
{ sprintf(soap->tmpbuf, "\"%s\"", action && strlen(action) < sizeof(soap->tmpbuf) - 3 ? action : SOAP_STR_EOS);
if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
return err;
@@ -5699,7 +5803,7 @@ http_response(struct soap *soap, int status, size_t count)
if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK))
s = "200 OK";
else
- s = "202 ACCEPTED";
+ s = "202 Accepted";
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Status = %s\n", s));
#ifdef WMW_RPM_IO
if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
@@ -5842,9 +5946,9 @@ soap_cookie(struct soap *soap, const char *name, const char *domain, const char
path = SOAP_STR_EOS;
else if (*path == '/')
path++;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain?domain:"(null)", path?path:"(null)"));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain ? domain : "(null)", path ? path : "(null)"));
for (p = soap->cookies; p; p = p->next)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->env));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->env));
if (!strcmp(p->name, name)
&& p->domain
&& p->path
@@ -5871,7 +5975,7 @@ soap_set_cookie(struct soap *soap, const char *name, const char *value, const ch
else if (*path == '/')
path++;
q = soap_cookie(soap, name, domain, path);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s=%s domain=%s path=%s\n", q ? SOAP_STR_EOS : "new ", name, value?value:"(null)", domain?domain:"(null)", path?path:"(null)"));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s=%s domain=%s path=%s\n", q ? SOAP_STR_EOS : "new ", name, value ? value : "(null)", domain ? domain : "(null)", path ? path : "(null)"));
if (!q)
{ if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie))))
{ if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1)))
@@ -5940,13 +6044,13 @@ soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const c
if (!domain)
domain = soap->cookie_domain;
if (!domain)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name?name:"(null)"));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name ? name : "(null)"));
return;
}
if (!path)
path = soap->cookie_path;
if (!path)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name?name:"(null)"));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name ? name : "(null)"));
return;
}
if (*path == '/')
@@ -6006,7 +6110,7 @@ int
SOAP_FMAC2
soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
{ struct soap_cookie *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain?domain:"(null)", path?path:"(null)"));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain ? domain : "(null)", path ? path : "(null)"));
if ((p = soap_cookie(soap, name, domain, path)))
{ p->maxage = expire;
p->modified = 1;
@@ -6123,6 +6227,9 @@ soap_putcookies(struct soap *soap, const char *domain, const char *path, int sec
unsigned int version = 0;
time_t now = time(NULL);
char *s, tmp[4096];
+ if (!domain || !path)
+ return SOAP_OK;
+ s = tmp;
p = &soap->cookies;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path));
if (*path == '/')
@@ -6169,30 +6276,53 @@ soap_putcookies(struct soap *soap, const char *domain, const char *path, int sec
if (flag
&& (!q->path || !strncmp(q->path, path, strlen(q->path)))
&& (!q->secure || secure))
- { s = tmp;
+ { size_t n = 12;
+ if (q->name)
+ n += 3*strlen(q->name);
+ if (q->value && *q->value)
+ n += 3*strlen(q->value) + 1;
+ if (q->path && *q->path)
+ n += strlen(q->path) + 9;
+ if (q->domain)
+ n += strlen(q->domain) + 11;
+ if (tmp - s + n > sizeof(tmp))
+ { if (s == tmp)
+ return SOAP_OK; /* HTTP header size overflow */
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
+ if ((soap->error = soap->fposthdr(soap, "Cookie", tmp)))
+ return soap->error;
+ s = tmp;
+ }
+ else if (s != tmp)
+ { strcat(s, " ");
+ s++;
+ }
if (q->version != version)
{ sprintf(s, "$Version=%u;", q->version);
version = q->version;
+ s += strlen(s);
}
if (q->name)
- s += soap_encode_cookie(q->name, s, tmp-s+4080);
+ s += soap_encode_cookie(q->name, s, tmp+sizeof(tmp)-s-16);
if (q->value && *q->value)
{ *s++ = '=';
- s += soap_encode_cookie(q->value, s, tmp-s+4080);
+ s += soap_encode_cookie(q->value, s, tmp+sizeof(tmp)-s-16);
}
- if (q->path && *q->path && (int)strlen(q->path) < tmp-s+4080)
+ if (q->path)
{ sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : q->path));
s += strlen(s);
}
- if (q->domain && (int)strlen(q->domain) < tmp-s+4080)
- sprintf(s, ";$Domain=\"%s\"", q->domain);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
- if ((soap->error = soap->fposthdr(soap, "Cookie", tmp)))
- return soap->error;
+ if (q->domain)
+ { sprintf(s, ";$Domain=\"%s\"", q->domain);
+ s += strlen(s);
+ }
}
p = &q->next;
}
}
+ if (s != tmp)
+ if ((soap->error = soap->fposthdr(soap, "Cookie", tmp)))
+ return soap->error;
return SOAP_OK;
}
@@ -6322,7 +6452,7 @@ soap_getcookies(struct soap *soap, const char *val)
p->secure = 1;
else
{ if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->expire, p->secure));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure));
if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
{ q->version = p->version;
q->expire = p->expire;
@@ -6374,7 +6504,7 @@ soap_getcookies(struct soap *soap, const char *val)
}
}
if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->expire, p->secure));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value ? p->value : "(null)", p->domain ? p->domain : "(null)", p->path ? p->path : "(null)", p->expire, p->secure));
if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
{ q->version = p->version;
q->expire = p->expire;
@@ -6506,30 +6636,10 @@ soap_init_pht(struct soap *soap)
SOAP_FMAC1
struct soap*
SOAP_FMAC2
-soap_new1(soap_mode mode)
-{ return soap_new2(mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new()
-{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new2(soap_mode imode, soap_mode omode)
+soap_versioning(soap_new)(soap_mode imode, soap_mode omode)
{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap));
if (soap)
- soap_init2(soap, imode, omode);
+ soap_versioning(soap_init)(soap, imode, omode);
return soap;
}
#endif
@@ -6597,6 +6707,7 @@ soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n,
soap_set_embedded(soap, pp);
}
return i;
+ (void)soap;
}
#endif
#endif
@@ -6649,7 +6760,7 @@ soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a,
h = soap_hash_ptr(a->__ptr);
else
h = soap_hash_ptr(p);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pointer enter location=%p array=%p size=%d dim=%d type=%d id=%d\n", p, a?a->__ptr:NULL, a?a->__size:0, n, type, soap->idnum+1));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pointer enter location=%p array=%p size=%d dim=%d type=%d id=%d\n", p, a ? a->__ptr : NULL, a ? a->__size : 0, n, type, soap->idnum+1));
pp->next = soap->pht[h];
pp->type = type;
pp->mark1 = 0;
@@ -6659,6 +6770,7 @@ soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a,
soap->pht[h] = pp;
pp->id = ++soap->idnum;
return pp->id;
+ (void)n;
}
#endif
#endif
@@ -6747,6 +6859,7 @@ soap_begin_count(struct soap *soap)
soap->encoding = 0;
soap->part = SOAP_BEGIN;
soap->event = 0;
+ soap->evlev = 0;
soap->idnum = 0;
soap_clr_attr(soap);
soap_set_local_namespaces(soap);
@@ -6829,7 +6942,7 @@ soap_begin_send(struct soap *soap)
#ifdef WIN32
#ifndef UNDER_CE
#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
+ if (!soap_valid_socket(soap->socket) && !soap->os) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
#ifdef __BORLANDC__
setmode(soap->sendfd, _O_BINARY);
#else
@@ -7084,7 +7197,7 @@ soap_attachment(struct soap *soap, const char *tag, int id, const void *p, const
int i;
if (!p || !a->__ptr || (!aid && !atype))
return soap_element_id(soap, tag, id, p, a, n, type, t);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid?aid:SOAP_STR_EOS, id, atype?atype:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid ? aid : SOAP_STR_EOS, id, atype ? atype : SOAP_STR_EOS));
i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
if (!i)
{ i = soap_pointer_enter(soap, p, a, n, t, &pp);
@@ -7213,7 +7326,7 @@ soap_enter(struct soap *soap, const char *id)
ip = (struct soap_ilist*)SOAP_MALLOC(soap, sizeof(struct soap_ilist) + strlen(id));
if (ip)
{ h = soap_hash(id);
- strcpy(ip->id, id);
+ strcpy((char*)ip->id, id);
ip->next = soap->iht[h];
soap->iht[h] = ip;
}
@@ -7400,13 +7513,16 @@ soap_dealloc(struct soap *soap, void *p)
SOAP_FREE(soap, q);
}
/* we must assume these were deallocated: */
+ soap->http_content = NULL;
soap->action = NULL;
soap->fault = NULL;
soap->header = NULL;
soap->userid = NULL;
soap->passwd = NULL;
soap->authrealm = NULL;
- soap->http_content = NULL;
+#ifdef WITH_NTLM
+ soap->ntlm_challenge = NULL;
+#endif
#ifndef WITH_LEANER
soap_clr_mime(soap);
#endif
@@ -7537,32 +7653,33 @@ soap_link(struct soap *soap, void *p, int t, int n, int (*fdelete)(struct soap_c
/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
-void
+int
SOAP_FMAC2
soap_unlink(struct soap *soap, const void *p)
{ register char **q;
register struct soap_clist **cp;
- if (!soap || !p)
- return;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
+ if (soap && p)
+ { for (q = (char**)&soap->alist; *q; q = *(char***)q)
+ { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
+ { *q = **(char***)q;
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
#ifdef SOAP_MEM_DEBUG
- soap_track_unlink(soap, p);
+ soap_track_unlink(soap, p);
#endif
- return;
+ return SOAP_OK; /* found and removed from dealloc chain */
+ }
}
- }
- for (cp = &soap->clist; *cp; cp = &(*cp)->next)
- { if (p == (*cp)->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
- q = (char**)*cp;
- *cp = (*cp)->next;
- SOAP_FREE(soap, q);
- return;
+ for (cp = &soap->clist; *cp; cp = &(*cp)->next)
+ { if (p == (*cp)->ptr)
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
+ q = (char**)*cp;
+ *cp = (*cp)->next;
+ SOAP_FREE(soap, q);
+ return SOAP_OK; /* found and removed from dealloc chain */
+ }
}
}
+ return SOAP_ERR;
}
#endif
@@ -7802,6 +7919,7 @@ SOAP_FMAC2
soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t len, const void *q, size_t n)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Copying data type=%d (target type=%d) %p -> %p (%lu bytes)\n", st, tt, q, p, (unsigned long)n));
memcpy(p, q, n);
+ (void)soap; (void)st; (void)tt; (void)len;
}
#endif
@@ -7867,7 +7985,7 @@ soap_end_send(struct soap *soap)
soap->mode &= ~SOAP_ENC_ZLIB;
soap->zlib_state = SOAP_ZLIB_NONE;
if (deflateEnd(soap->d_stream) != Z_OK || r != Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS));
return soap->error = SOAP_ZLIB_ERROR;
}
#ifdef WITH_GZIP
@@ -8004,7 +8122,7 @@ soap_end_recv(struct soap *soap)
for (i = 0; i < 8; i++)
{ if ((int)(c = soap_get1(soap)) == EOF)
{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: unable to read crc value\n"));
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
}
soap->z_buf[i] = (char)c;
}
@@ -8232,6 +8350,7 @@ soap_copy_context(struct soap *copy, const struct soap *soap)
return NULL;
if (copy)
{ register struct soap_plugin *p = NULL;
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying context\n"));
#ifdef __cplusplus
*copy = *soap;
#else
@@ -8241,6 +8360,9 @@ soap_copy_context(struct soap *copy, const struct soap *soap)
copy->error = SOAP_OK;
copy->userid = NULL;
copy->passwd = NULL;
+#ifdef WITH_NTLM
+ copy->ntlm_challenge = NULL;
+#endif
copy->nlist = NULL;
copy->blist = NULL;
copy->clist = NULL;
@@ -8260,8 +8382,18 @@ soap_copy_context(struct soap *copy, const struct soap *soap)
soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]);
soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]);
#endif
+ copy->namespaces = NULL;
+ copy->local_namespaces = NULL;
+ if (soap->local_namespaces)
+ soap_set_namespaces(copy, soap->local_namespaces);
+ else
+ soap_set_namespaces(copy, soap->namespaces);
#ifdef WITH_C_LOCALE
+# ifdef WIN32
+ copy->c_locale = _create_locale(LC_ALL, "C");
+# else
copy->c_locale = duplocale(soap->c_locale);
+# endif
#else
copy->c_locale = NULL;
#endif
@@ -8326,7 +8458,10 @@ soap_copy_stream(struct soap *copy, struct soap *soap)
copy->mode = soap->mode;
copy->imode = soap->imode;
copy->omode = soap->omode;
+ copy->master = soap->master;
copy->socket = soap->socket;
+ copy->sendsk = soap->sendsk;
+ copy->recvsk = soap->recvsk;
copy->recv_timeout = soap->recv_timeout;
copy->send_timeout = soap->send_timeout;
#if defined(__cplusplus) && !defined(WITH_LEAN)
@@ -8350,23 +8485,27 @@ soap_copy_stream(struct soap *copy, struct soap *soap)
#ifndef WITH_NOIO
copy->peer = soap->peer;
copy->peerlen = soap->peerlen;
+ copy->ip = soap->ip;
+ copy->port = soap->port;
+ memcpy(copy->host, soap->host, sizeof(soap->host));
+ memcpy(copy->endpoint, soap->endpoint, sizeof(soap->endpoint));
#endif
#ifdef WITH_OPENSSL
- copy->bio = NULL;
- copy->ctx = NULL;
- copy->ssl = NULL;
- if (soap->ssl)
- copy->ssl = SSL_dup(soap->ssl);
+ copy->bio = soap->bio;
+ copy->ctx = soap->ctx;
+ copy->ssl = soap->ssl;
#endif
#ifdef WITH_GNUTLS
- copy->session = soap->session; /* TODO: Oops, GNUTLS provides a dup? */
+ copy->session = soap->session;
#endif
#ifdef WITH_ZLIB
copy->zlib_state = soap->zlib_state;
copy->zlib_in = soap->zlib_in;
copy->zlib_out = soap->zlib_out;
- copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream));
- memcpy(copy->d_stream, soap->d_stream, sizeof(z_stream));
+ if (!copy->d_stream)
+ copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream));
+ if (copy->d_stream)
+ memcpy(copy->d_stream, soap->d_stream, sizeof(z_stream));
copy->z_crc = soap->z_crc;
copy->z_ratio_in = soap->z_ratio_in;
copy->z_ratio_out = soap->z_ratio_out;
@@ -8375,7 +8514,8 @@ soap_copy_stream(struct soap *copy, struct soap *soap)
copy->z_level = soap->z_level;
if (soap->z_buf && soap->zlib_state != SOAP_ZLIB_NONE)
{ copy->z_buf = (char*)SOAP_MALLOC(copy, SOAP_BUFLEN);
- memcpy(copy->z_buf, soap->z_buf, sizeof(soap->z_buf));
+ if (copy->z_buf)
+ memcpy(copy->z_buf, soap->z_buf, SOAP_BUFLEN);
}
copy->z_dict = soap->z_dict;
copy->z_dict_len = soap->z_dict_len;
@@ -8411,10 +8551,18 @@ soap_copy_stream(struct soap *copy, struct soap *soap)
SOAP_FREE(copy, nq);
}
}
- copy->level = soap->level;
+ memcpy(copy->tag, soap->tag, sizeof(copy->tag));
+ memcpy(copy->id, soap->id, sizeof(copy->id));
+ memcpy(copy->href, soap->href, sizeof(copy->href));
+ memcpy(copy->type, soap->type, sizeof(copy->type));
+ copy->other = soap->other;
+ copy->root = soap->root;
+ copy->null = soap->null;
copy->body = soap->body;
+ copy->part = soap->part;
+ copy->mustUnderstand = soap->mustUnderstand;
+ copy->level = soap->level;
copy->peeked = soap->peeked;
- memcpy(copy->tag, soap->tag, sizeof(copy->tag));
/* copy attributes */
for (tq = soap->attributes; tq; tq = tq->next)
{ struct soap_attribute *tr = tp;
@@ -8440,24 +8588,22 @@ void
SOAP_FMAC2
soap_free_stream(struct soap *soap)
{ soap->socket = SOAP_INVALID_SOCKET;
+ soap->sendsk = SOAP_INVALID_SOCKET;
+ soap->recvsk = SOAP_INVALID_SOCKET;
#ifdef WITH_OPENSSL
soap->bio = NULL;
- if (soap->ssl)
- SSL_free(soap->ssl);
+ soap->ctx = NULL;
soap->ssl = NULL;
#endif
#ifdef WITH_GNUTLS
soap->xcred = NULL;
soap->acred = NULL;
soap->cache = NULL;
- soap->session = NULL; /* TODO: GNUTLS free here when dupped */
+ soap->session = NULL;
soap->dh_params = NULL;
soap->rsa_params = NULL;
#endif
#ifdef WITH_ZLIB
- if (soap->d_stream)
- SOAP_FREE(soap, soap->d_stream);
- soap->d_stream = NULL;
if (soap->z_buf)
SOAP_FREE(soap, soap->z_buf);
soap->z_buf = NULL;
@@ -8470,7 +8616,7 @@ soap_free_stream(struct soap *soap)
SOAP_FMAC1
void
SOAP_FMAC2
-soap_init(struct soap *soap)
+soap_versioning(soap_init)(struct soap *soap, soap_mode imode, soap_mode omode)
{ size_t i;
soap->state = SOAP_INIT;
#ifdef SOAP_MEM_DEBUG
@@ -8480,7 +8626,7 @@ soap_init(struct soap *soap)
soap_init_logs(soap);
#endif
#ifdef SOAP_DEBUG
-#ifdef TANDEM
+#ifdef TANDEM_NONSTOP
soap_set_test_logfile(soap, "TESTLOG");
soap_set_sent_logfile(soap, "SENTLOG");
soap_set_recv_logfile(soap, "RECVLOG");
@@ -8491,21 +8637,26 @@ soap_init(struct soap *soap)
#endif
#endif
soap->version = 0;
- soap_imode(soap, SOAP_IO_DEFAULT);
- soap_omode(soap, SOAP_IO_DEFAULT);
+ soap_mode(soap, imode);
+ soap_imode(soap, imode);
+ soap_omode(soap, omode);
soap->plugins = NULL;
soap->user = NULL;
for (i = 0; i < sizeof(soap->data)/sizeof(*soap->data); i++)
soap->data[i] = NULL;
soap->userid = NULL;
soap->passwd = NULL;
+ soap->authrealm = NULL;
+#ifdef WITH_NTLM
+ soap->ntlm_challenge = NULL;
+#endif
#ifndef WITH_NOHTTP
soap->fpost = http_post;
- soap->fput = http_put;
soap->fget = http_get;
+ soap->fput = http_405;
soap->fdel = http_405;
- soap->fopt = http_405;
- soap->fhead = http_405;
+ soap->fopt = http_200;
+ soap->fhead = http_200;
soap->fform = NULL;
soap->fposthdr = http_post_header;
soap->fresponse = http_response;
@@ -8611,6 +8762,8 @@ soap_init(struct soap *soap)
soap->fault = NULL;
soap->master = SOAP_INVALID_SOCKET;
soap->socket = SOAP_INVALID_SOCKET;
+ soap->sendsk = SOAP_INVALID_SOCKET;
+ soap->recvsk = SOAP_INVALID_SOCKET;
soap->os = NULL;
soap->is = NULL;
#ifndef WITH_LEANER
@@ -8639,7 +8792,6 @@ soap_init(struct soap *soap)
soap->proxy_port = 8080;
soap->proxy_userid = NULL;
soap->proxy_passwd = NULL;
- soap->authrealm = NULL;
soap->prolog = NULL;
#ifdef WITH_ZLIB
soap->zlib_state = SOAP_ZLIB_NONE;
@@ -8709,7 +8861,11 @@ soap_init(struct soap *soap)
soap->rsa_params = NULL;
#endif
#ifdef WITH_C_LOCALE
+# ifdef WIN32
+ soap->c_locale = _create_locale(LC_ALL, "C");
+# else
soap->c_locale = newlocale(LC_ALL_MASK, "C", NULL);
+# endif
#else
soap->c_locale = NULL;
#endif
@@ -8726,6 +8882,7 @@ soap_init(struct soap *soap)
soap->ns = 0;
soap->part = SOAP_END;
soap->event = 0;
+ soap->evlev = 0;
soap->alloced = 0;
soap->count = 0;
soap->length = 0;
@@ -8740,28 +8897,6 @@ soap_init(struct soap *soap)
#endif
/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init1(struct soap *soap, soap_mode mode)
-{ soap_init2(soap, mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init2(struct soap *soap, soap_mode imode, soap_mode omode)
-{ soap_init(soap);
- soap_imode(soap, imode);
- soap_omode(soap, omode);
-}
-#endif
-
-/******************************************************************************/
#ifndef PALM_2
SOAP_FMAC1
void
@@ -8772,7 +8907,6 @@ soap_begin(struct soap *soap)
{ soap->buflen = 0;
soap->bufidx = 0;
}
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
soap->null = 0;
soap->position = 0;
soap->encoding = 0;
@@ -8781,6 +8915,7 @@ soap_begin(struct soap *soap)
soap->ns = 0;
soap->part = SOAP_END;
soap->event = 0;
+ soap->evlev = 0;
soap->alloced = 0;
soap->count = 0;
soap->length = 0;
@@ -8903,6 +9038,8 @@ soap_set_local_namespaces(struct soap *soap)
soap->version = 2;
}
soap->local_namespaces = ns2;
+ for (; ns2->id; ns2++)
+ ns2->out = NULL;
}
}
}
@@ -8976,7 +9113,7 @@ soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized)
return NULL;
}
}
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns?ns:"(null)", utilized));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns ? ns : "(null)", utilized));
n = strlen(id);
if (ns)
k = strlen(ns);
@@ -8989,9 +9126,9 @@ soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized)
}
np->next = soap->nlist;
soap->nlist = np;
- strcpy(np->id, id);
+ strcpy((char*)np->id, id);
if (ns)
- np->ns = strcpy(np->id + n + 1, ns);
+ np->ns = strcpy((char*)np->id + n + 1, ns);
else
np->ns = NULL;
np->level = soap->level;
@@ -9003,8 +9140,13 @@ soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized)
/******************************************************************************/
#ifndef WITH_LEAN
static void
-soap_utilize_ns(struct soap *soap, const char *tag, size_t n)
-{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n);
+soap_utilize_ns(struct soap *soap, const char *tag)
+{ register struct soap_nlist *np;
+ size_t n = 0;
+ const char *t = strchr(tag, ':');
+ if (t)
+ n = t - tag;
+ np = soap_lookup_ns(soap, tag, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag));
if (np)
{ if (np->index == 0)
@@ -9028,7 +9170,8 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type)
#ifndef WITH_LEAN
register const char *s;
#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' level='%u' id='%d' type='%s'\n", tag, soap->level, id, type ? type : SOAP_STR_EOS));
+ soap->level++;
#ifdef WITH_DOM
#ifndef WITH_LEAN
if (soap->wsuid && soap_tagsearch(soap->wsuid, tag))
@@ -9039,12 +9182,20 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type)
if (soap_set_attr(soap, "wsu:Id", soap->tag, 1))
return soap->error;
}
- if (soap->event == SOAP_SEC_BEGIN && (soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS))
- { register struct soap_nlist *np;
- /* wsu:Id found: clear xmlns renderings, so re-emit them for exc-c14n */
- for (np = soap->nlist; np; np = np->next)
- { if (np->index == 2)
- np->index = 0;
+ if ((soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS))
+ { if (soap->evlev >= soap->level)
+ soap->evlev = 0;
+ if (soap->event == SOAP_SEC_BEGIN && !soap->evlev)
+ { register struct soap_nlist *np;
+ /* non-nested wsu:Id found: clear xmlns, re-emit them for exc-c14n */
+ for (np = soap->nlist; np; np = np->next)
+ { if (np->index == 2)
+ { struct soap_nlist *np1 = soap_push_ns(soap, np->id, np->ns, 1);
+ if (np1)
+ np1->index = 0;
+ }
+ }
+ soap->evlev = soap->level;
}
}
#endif
@@ -9080,7 +9231,6 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type)
else
{
#endif
- soap->level++;
#ifndef WITH_LEAN
if (!soap->ns)
{ if (!(soap->mode & SOAP_XML_CANONICAL)
@@ -9135,26 +9285,30 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type)
soap->ns = 1; /* namespace table control: ns = 0 or 2 to start, then 1 to stop dumping the table */
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
- { const char *t = strchr(tag, ':');
- if (t)
- soap_utilize_ns(soap, tag, t - tag);
- }
+ soap_utilize_ns(soap, tag);
#endif
if (id > 0)
{ sprintf(soap->tmpbuf, "_%d", id);
if (soap_attribute(soap, "id", soap->tmpbuf))
return soap->error;
}
- if (type && *type && soap->part != SOAP_IN_HEADER) /* TODO: filter Header? */
- { if (soap_attribute(soap, "xsi:type", type))
- return soap->error;
+ if (type && *type && !(soap->mode & SOAP_XML_NOTYPE) && soap->part != SOAP_IN_HEADER)
+ { const char *t = type;
#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { const char *t = strchr(type, ':');
+ if (soap->mode & SOAP_XML_DEFAULTNS)
+ { t = strchr(type, ':');
if (t)
- soap_utilize_ns(soap, type, t - type);
+ t++;
+ else
+ t = type;
}
#endif
+ if (soap->attributes ? soap_set_attr(soap, "xsi:type", t, 1) : soap_attribute(soap, "xsi:type", t))
+ return soap->error;
+#ifndef WITH_LEAN
+ if (soap->mode & SOAP_XML_CANONICAL)
+ soap_utilize_ns(soap, type);
+#endif
}
if (soap->null && soap->position > 0)
{ register int i;
@@ -9189,8 +9343,8 @@ soap_element(struct soap *soap, const char *tag, int id, const char *type)
}
soap->null = 0;
soap->position = 0;
- if (soap->event == SOAP_SEC_BEGIN && (soap->mode & SOAP_XML_CANONICAL))
- soap->event = SOAP_SEC_SIGN;
+ if (soap->event == SOAP_SEC_BEGIN)
+ soap->event = 0;
return SOAP_OK;
}
#endif
@@ -9358,10 +9512,7 @@ soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *typ
}
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
- { const char *s = strchr(type, ':');
- if (s)
- soap_utilize_ns(soap, type, s - type);
- }
+ soap_utilize_ns(soap, type);
#endif
return soap_element_start_end_out(soap, NULL);
}
@@ -9379,14 +9530,11 @@ soap_element_start_end_out(struct soap *soap, const char *tag)
{ struct soap_nlist *np;
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible && tp->name)
- { const char *s = strchr(tp->name, ':');
- if (s)
- soap_utilize_ns(soap, tp->name, s - tp->name);
- }
+ soap_utilize_ns(soap, tp->name);
}
for (np = soap->nlist; np; np = np->next)
{ if (np->index == 1 && np->ns)
- { sprintf(soap->tmpbuf, "xmlns:%s", np->id);
+ { sprintf(soap->tmpbuf, *(np->id) ? "xmlns:%s" : "xmlns", np->id);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns));
soap_set_attr(soap, soap->tmpbuf, np->ns, 1);
np->index = 2;
@@ -9636,6 +9784,7 @@ soap_check_result(struct soap *soap, const char *tag)
{ soap_instring(soap, ":result", NULL, NULL, 0, 2, -1, -1);
/* just ignore content for compliance reasons, but should compare tag to element's QName value? */
}
+ (void)tag;
}
#endif
@@ -9664,16 +9813,9 @@ soap_attribute(struct soap *soap, const char *name, const char *value)
#endif
#ifndef WITH_LEAN
if (soap->mode & SOAP_XML_CANONICAL)
- { /* TODO: consider using this code to handle default namespace bindings
+ { /* push namespace */
if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0'))
- { if (name[5] == ':')
- soap_push_ns(soap, name + 6, value, 0);
- else
- soap_push_ns(soap, "", value, 0);
- }
- */
- if (!strncmp(name, "xmlns:", 6))
- soap_push_ns(soap, name + 6, value, 0);
+ soap_push_ns(soap, name + 5 + (name[5] == ':'), value, 0);
else if (soap_set_attr(soap, name, value, 1))
return soap->error;
}
@@ -9710,7 +9852,8 @@ soap_element_begin_in(struct soap *soap, const char *tag, int nillable, const ch
return soap->error = SOAP_NULL;
if (soap->body)
soap->level++;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:SOAP_STR_EOS ));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag ? tag : SOAP_STR_EOS ));
+ soap->error = SOAP_OK;
}
}
else if (soap->error == SOAP_NO_TAG && tag && *tag == '-')
@@ -9749,7 +9892,7 @@ soap_element_end_in(struct soap *soap, const char *tag)
do
{ while (((c = soap_get(soap)) != SOAP_TT))
{ if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
if (c == SOAP_LT)
n++;
else if (c == '/')
@@ -9769,7 +9912,7 @@ soap_element_end_in(struct soap *soap, const char *tag)
}
*s = '\0';
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
while (soap_blank(c))
c = soap_get(soap);
if (c != SOAP_GT)
@@ -9784,12 +9927,12 @@ soap_element_end_in(struct soap *soap, const char *tag)
if (tag && (soap->mode & SOAP_XML_STRICT))
{ soap_pop_namespace(soap);
if (soap_match_tag(soap, soap->tag, tag))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag '%s' does not match '%s'\n", soap->tag, tag?tag:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag '%s' does not match '%s'\n", soap->tag, tag ? tag : SOAP_STR_EOS));
return soap->error = SOAP_SYNTAX_ERROR;
}
}
#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag ? tag : SOAP_STR_EOS));
soap->level--;
return SOAP_OK;
}
@@ -9831,7 +9974,7 @@ soap_set_attr(struct soap *soap, const char *name, const char *value, int flag)
{ register struct soap_attribute *tp;
if (*name == '-')
return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value?value:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value ? value : SOAP_STR_EOS));
for (tp = soap->attributes; tp; tp = tp->next)
{ if (!strcmp(tp->name, name))
break;
@@ -9883,7 +10026,7 @@ soap_set_attr(struct soap *soap, const char *name, const char *value, int flag)
{ tp->next = soap->attributes;
soap->attributes = tp;
}
- strcpy(tp->name, name);
+ strcpy((char*)tp->name, name);
tp->value = NULL;
}
else if (tp->visible)
@@ -9906,9 +10049,9 @@ soap_set_attr(struct soap *soap, const char *name, const char *value, int flag)
if (!strncmp(tp->name, "xmlns:", 6))
tp->ns = tp->value;
tp->visible = 2;
- tp->flag = flag;
+ tp->flag = (short)flag;
#ifndef WITH_LEAN
- if (soap->event != SOAP_SEC_SIGN && !strcmp(name, "wsu:Id"))
+ if (!strcmp(name, "wsu:Id"))
{ soap->event = SOAP_SEC_BEGIN;
strncpy(soap->id, value, sizeof(soap->id));
soap->id[sizeof(soap->id)-1] = '\0';
@@ -9996,7 +10139,7 @@ soap_getattrval(struct soap *soap, char *s, size_t n, soap_wchar d)
}
default:
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
*s++ = (char)c;
}
}
@@ -10085,8 +10228,19 @@ soap_peek_element(struct soap *soap)
soap->position = 0;
soap->null = 0;
soap->mustUnderstand = 0;
- /* skip BOM */
- if ((c = soap_getchar(soap)) != 0xEF || (c = soap_get1(soap)) != 0xBB || (c = soap_get1(soap)) != 0xBF)
+ /* UTF-8 BOM? */
+ c = soap_getchar(soap);
+ if (c == 0xEF && soap_get0(soap) == 0xBB)
+ { c = soap_get1(soap);
+ if ((c = soap_get1(soap)) == 0xBF)
+ soap->mode &= ~SOAP_ENC_LATIN;
+ else
+ soap_unget(soap, (0x0F << 12) | (0xBB << 6) | (c & 0x3F)); /* UTF-8 */
+ }
+ else if ((c == 0xFE && soap_get0(soap) == 0xFF) /* UTF-16 BE */
+ || (c == 0xFF && soap_get0(soap) == 0xFE)) /* UTF-16 LE */
+ return soap->error = SOAP_UTF_ERROR;
+ else
soap_unget(soap, c);
c = soap_get(soap);
#ifdef WITH_DOM
@@ -10116,7 +10270,7 @@ soap_peek_element(struct soap *soap)
if (c != SOAP_LT)
{ *soap->tag = '\0';
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
soap_unget(soap, c > 0 ? c | 0x80000000 : c);
#ifdef WITH_DOM
/* whitespace leading to end tag is significant for DOM */
@@ -10221,7 +10375,7 @@ soap_peek_element(struct soap *soap)
{ tp = (struct soap_attribute*)SOAP_MALLOC(soap, sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
if (!tp)
return soap->error = SOAP_EOM;
- strcpy(tp->name, soap->tmpbuf);
+ strcpy((char*)tp->name, soap->tmpbuf);
tp->value = NULL;
tp->size = 0;
tp->ns = NULL;
@@ -10254,6 +10408,7 @@ soap_peek_element(struct soap *soap)
return soap->error;
if (tp->value)
SOAP_FREE(soap, tp->value);
+ tp->value = NULL;
for (;;)
{ if (soap_getattrval(soap, soap->labbuf + soap->labidx, soap->lablen - soap->labidx, c))
{ if (soap->error != SOAP_EOM)
@@ -10333,7 +10488,7 @@ soap_peek_element(struct soap *soap)
}
#endif
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
if (!(soap->body = (c != '/')))
do c = soap_get1(soap);
while (soap_blank(c));
@@ -10342,8 +10497,6 @@ soap_peek_element(struct soap *soap)
{ if (!soap->body && soap->dom->prnt)
soap->dom = soap->dom->prnt;
}
- if (soap->feltbegin)
- return soap->error = soap->feltbegin(soap, soap->tag);
#endif
for (tp = soap->attributes; tp; tp = tp->next)
{ if (tp->visible && tp->value)
@@ -10436,6 +10589,10 @@ soap_peek_element(struct soap *soap)
}
}
}
+#ifdef WITH_DOM
+ if (soap->feltbegin)
+ return soap->error = soap->feltbegin(soap, soap->tag);
+#endif
return soap->error = SOAP_OK;
}
#endif
@@ -10536,7 +10693,7 @@ soap_string_out(struct soap *soap, const char *s, int flag)
if (soap->mode & SOAP_C_MBSTRING)
{ wchar_t wc;
register int m = mbtowc(&wc, t - 1, MB_CUR_MAX);
- if (m > 0 && (soap_wchar)wc != c)
+ if (m > 0 && !((soap_wchar)wc == c && m == 1 && c < 0x80))
{ if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, wc))
return soap->error;
s = t += m - 1;
@@ -10649,11 +10806,11 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
if ((int)c == EOF)
goto end;
if ((c >= 0x80 || c < SOAP_AP) && state != 1 && !(soap->mode & SOAP_ENC_LATIN))
- { if (c >= 0x80)
+ { if ((c & 0x7FFFFFFF) >= 0x80)
{ soap_unget(soap, c);
c = soap_getutf8(soap);
}
- if (soap->mode & SOAP_C_UTFSTRING)
+ if ((c & 0x7FFFFFFF) >= 0x80 && (soap->mode & SOAP_C_UTFSTRING))
{ c &= 0x7FFFFFFF;
t = buf;
if (c < 0x0800)
@@ -10688,17 +10845,17 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
{ case 1:
if (c == ']')
state = 4;
- *s++ = c;
+ *s++ = (char)c;
continue;
case 2:
if (c == '-')
state = 6;
- *s++ = c;
+ *s++ = (char)c;
continue;
case 3:
if (c == '?')
state = 8;
- *s++ = c;
+ *s++ = (char)c;
continue;
/* CDATA */
case 4:
@@ -10706,14 +10863,14 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
state = 5;
else
state = 1;
- *s++ = c;
+ *s++ = (char)c;
continue;
case 5:
if (c == '>')
state = 0;
else
state = 1;
- *s++ = c;
+ *s++ = (char)c;
continue;
/* comment */
case 6:
@@ -10721,14 +10878,14 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
state = 7;
else
state = 2;
- *s++ = c;
+ *s++ = (char)c;
continue;
case 7:
if (c == '>')
state = 0;
else
state = 2;
- *s++ = c;
+ *s++ = (char)c;
continue;
/* PI */
case 8:
@@ -10736,7 +10893,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
state = 0;
else
state = 3;
- *s++ = c;
+ *s++ = (char)c;
continue;
}
switch (c)
@@ -10830,7 +10987,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
#ifndef WITH_LEANER
#ifdef HAVE_WCTOMB
if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
+ { m = wctomb(buf, (wchar_t)(c & 0x7FFFFFFF));
if (m >= 1 && m <= (int)MB_CUR_MAX)
{ t = buf;
*s++ = *t++;
@@ -11001,7 +11158,7 @@ soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
#ifndef WITH_LEANER
#ifdef HAVE_WCTOMB
if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
+ { m = wctomb(buf, (wchar_t)(c & 0x7FFFFFFF));
if (m >= 1 && m <= (int)MB_CUR_MAX)
{ t = buf;
*s++ = *t++;
@@ -11266,7 +11423,7 @@ soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen)
if ((int)c == EOF)
goto end;
if (sizeof(wchar_t) < 4 && c > 0xFFFF)
- { wchar_t c1, c2;
+ { soap_wchar c1, c2;
/* http://unicode.org/faq/utf_bom.html#utf16-2 */
c1 = 0xD800 - (0x10000 >> 10) + (c >> 10);
c2 = 0xDC00 + (c & 0x3FF);
@@ -11511,7 +11668,7 @@ soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
soap_reset_errno;
#endif
#endif
- *p = strtoll(s, &r, 10);
+ *p = soap_strtoll(s, &r, 10);
if (s == r || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
@@ -11726,7 +11883,11 @@ soap_float2s(struct soap *soap, float n)
return "-INF";
s = soap->tmpbuf;
#if defined(HAVE_SPRINTF_L)
+# ifdef WIN32
+ _sprintf_s_l(s, _countof(soap->tmpbuf), soap->float_format, soap->c_locale, n);
+# else
sprintf_l(s, soap->c_locale, soap->float_format, n);
+# endif
#else
sprintf(s, soap->float_format, n);
s = strchr(s, ','); /* convert decimal comma to DP */
@@ -11772,7 +11933,11 @@ soap_s2float(struct soap *soap, const char *s, float *p)
/* On some systems strtof requires -std=c99 or does not even link: so we try to use strtod first */
#if defined(HAVE_STRTOD_L)
char *r;
+# ifdef WIN32
+ *p = (float)_strtod_l(s, &r, soap->c_locale);
+# else
*p = (float)strtod_l(s, &r, soap->c_locale);
+# endif
if (*r)
#elif defined(HAVE_STRTOD)
char *r;
@@ -11872,7 +12037,11 @@ soap_double2s(struct soap *soap, double n)
return "-INF";
s = soap->tmpbuf;
#if defined(HAVE_SPRINTF_L)
+# ifdef WIN32
+ _sprintf_s_l(s, _countof(soap->tmpbuf), soap->double_format, soap->c_locale, n);
+# else
sprintf_l(s, soap->c_locale, soap->double_format, n);
+# endif
#else
sprintf(s, soap->double_format, n);
s = strchr(s, ','); /* convert decimal comma to DP */
@@ -11917,7 +12086,11 @@ soap_s2double(struct soap *soap, const char *s, double *p)
{
#if defined(HAVE_STRTOD_L)
char *r;
+# ifdef WIN32
+ *p = _strtod_l(s, &r, soap->c_locale);
+# else
*p = strtod_l(s, &r, soap->c_locale);
+# endif
if (*r)
#elif defined(HAVE_STRTOD)
char *r;
@@ -12313,7 +12486,7 @@ soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
soap_reset_errno;
#endif
#endif
- *p = strtoull(s, &r, 10);
+ *p = soap_strtoull(s, &r, 10);
if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r
#ifndef WITH_NOIO
#ifndef WITH_LEAN
@@ -12414,7 +12587,7 @@ soap_s2QName(struct soap *soap, const char *s, char **t, long minlen, long maxle
break;
/* find next QName */
n = 1;
- while (s[n] && !soap_blank(s[n]))
+ while (s[n] && !soap_blank((soap_wchar)s[n]))
n++;
np = soap->nlist;
/* if there is no namespace stack, or prefix is "xml" then copy string */
@@ -12455,7 +12628,7 @@ soap_s2QName(struct soap *soap, const char *s, char **t, long minlen, long maxle
soap_append_lab(soap, "\"", 1);
}
else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:SOAP_STR_EOS));
+ { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns ? np->ns : SOAP_STR_EOS));
return soap->error = SOAP_NAMESPACE;
}
}
@@ -12506,10 +12679,7 @@ soap_QName2s(struct soap *soap, const char *s)
{ soap_append_lab(soap, s, n);
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
- { const char *r = strchr(s, ':');
- if (r)
- soap_utilize_ns(soap, s, r - s);
- }
+ soap_utilize_ns(soap, s);
#endif
}
else /* URL-based string prefix */
@@ -12688,7 +12858,8 @@ SOAP_FMAC1
char **
SOAP_FMAC2
soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1, NULL))
+{ (void)type;
+ if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG)
return NULL;
soap->error = SOAP_OK;
@@ -12754,7 +12925,8 @@ SOAP_FMAC1
wchar_t **
SOAP_FMAC2
soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1, NULL))
+{ (void)type;
+ if (soap_element_begin_in(soap, tag, 1, NULL))
{ if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG)
return NULL;
soap->error = SOAP_OK;
@@ -13217,7 +13389,7 @@ soap_getline(struct soap *soap, char *s, int len)
if (c == '\r' || c == '\n')
break;
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
*s++ = (char)c;
}
if (c != '\n')
@@ -13231,7 +13403,7 @@ soap_getline(struct soap *soap, char *s, int len)
break;
}
else if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
if (i < 0)
return soap->error = SOAP_HDR;
}
@@ -13346,7 +13518,7 @@ SOAP_FMAC2
soap_putdimehdr(struct soap *soap)
{ unsigned char tmp[12];
size_t optlen = 0, idlen = 0, typelen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime.id?soap->dime.id:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS));
if (soap->dime.options)
optlen = (((unsigned char)soap->dime.options[2] << 8) | ((unsigned char)soap->dime.options[3])) + 4;
if (soap->dime.id)
@@ -13442,7 +13614,7 @@ soap_putdime(struct soap *soap)
bufsize = sizeof(soap->tmpbuf);
if (!(bufsize = soap->fdimeread(soap, handle, soap->tmpbuf, bufsize)))
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size));
- soap->error = SOAP_EOF;
+ soap->error = SOAP_CHK_EOF;
break;
}
if (soap_send_raw(soap, soap->tmpbuf, bufsize))
@@ -13484,7 +13656,7 @@ soap_getdimefield(struct soap *soap, size_t n)
{ s = p;
for (i = n; i > 0; i--)
{ if ((int)(c = soap_get1(soap)) == EOF)
- { soap->error = SOAP_EOF;
+ { soap->error = SOAP_CHK_EOF;
return NULL;
}
*s++ = (char)c;
@@ -13518,7 +13690,7 @@ soap_getdimehdr(struct soap *soap)
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
if (soap->dime.buflen || soap->dime.chunksize)
{ if (soap_move(soap, (long)(soap->dime.size - soap_tell(soap))))
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
return SOAP_OK;
@@ -13526,7 +13698,7 @@ soap_getdimehdr(struct soap *soap)
s = (char*)tmp;
for (i = 12; i > 0; i--)
{ if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
*s++ = (char)c;
}
if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
@@ -13543,7 +13715,7 @@ soap_getdimehdr(struct soap *soap)
return soap->error;
if (!(soap->dime.type = soap_getdimefield(soap, typelen)) && soap->error)
return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime.id?soap->dime.id:SOAP_STR_EOS, soap->dime.type?soap->dime.type:"", soap->dime.options?soap->dime.options+4:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime.id ? soap->dime.id : SOAP_STR_EOS, soap->dime.type ? soap->dime.type : "", soap->dime.options ? soap->dime.options+4 : SOAP_STR_EOS));
if (soap->dime.flags & SOAP_DIME_ME)
soap->mode &= ~SOAP_ENC_DIME;
return SOAP_OK;
@@ -13795,7 +13967,7 @@ soap_get_mime_attachment(struct soap *soap, void *handle)
return NULL;
}
}
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:SOAP_STR_EOS, content->type?content->type:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id ? content->id : SOAP_STR_EOS, content->type ? content->type : SOAP_STR_EOS));
if (!content->ptr && soap_new_block(soap) == NULL)
{ soap->error = SOAP_EOM;
return NULL;
@@ -13816,7 +13988,7 @@ soap_get_mime_attachment(struct soap *soap, void *handle)
{ if (!flag)
{ c = soap_get1(soap);
if ((int)c == EOF)
- { soap->error = SOAP_EOF;
+ { soap->error = SOAP_CHK_EOF;
return NULL;
}
}
@@ -13829,7 +14001,7 @@ soap_get_mime_attachment(struct soap *soap, void *handle)
do c = soap_getchar(soap);
while (c == *t++);
if ((int)c == EOF)
- { soap->error = SOAP_EOF;
+ { soap->error = SOAP_CHK_EOF;
return NULL;
}
if (!*--t)
@@ -13954,7 +14126,7 @@ int
SOAP_FMAC2
soap_putmimehdr(struct soap *soap, struct soap_multipart *content)
{ const char *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type=%s\n", content->type?content->type:SOAP_STR_EOS));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type=%s\n", content->type ? content->type : SOAP_STR_EOS));
if (soap_send3(soap, "\r\n--", soap->mime.boundary, "\r\n"))
return soap->error;
if (content->type && soap_send3(soap, "Content-Type: ", content->type, "\r\n"))
@@ -14245,7 +14417,7 @@ soap_getgziphdr(struct soap *soap)
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
for (i = 0; i < 9; i++)
{ if ((int)(c = soap_get1(soap) == EOF))
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
if (i == 1 && c == 8)
soap->z_dict = 0;
if (i == 2)
@@ -14254,7 +14426,7 @@ soap_getgziphdr(struct soap *soap)
if (f & 0x04) /* FEXTRA */
{ for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
{ if ((int)soap_get1(soap) == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
}
}
if (f & 0x08) /* skip FNAME */
@@ -14272,7 +14444,7 @@ soap_getgziphdr(struct soap *soap)
c = soap_get1(soap);
}
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_ZLIB_ERROR;
return SOAP_OK;
}
#endif
@@ -14292,7 +14464,10 @@ soap_begin_serve(struct soap *soap)
}
#endif
soap_begin(soap);
- if (soap_begin_recv(soap))
+ if (soap_begin_recv(soap)
+ || soap_envelope_begin_in(soap)
+ || soap_recv_header(soap)
+ || soap_body_begin_in(soap))
{ if (soap->error < SOAP_STOP)
{
#ifdef WITH_FASTCGI
@@ -14303,10 +14478,6 @@ soap_begin_serve(struct soap *soap)
}
return soap_closesock(soap);
}
- if (soap_envelope_begin_in(soap)
- || soap_recv_header(soap)
- || soap_body_begin_in(soap))
- return soap->error;
return SOAP_OK;
}
#endif
@@ -14317,7 +14488,7 @@ SOAP_FMAC1
int
SOAP_FMAC2
soap_begin_recv(struct soap *soap)
-{ soap_wchar c;
+{ register soap_wchar c;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for input\n"));
soap->error = SOAP_OK;
soap->filterstop = SOAP_OK;
@@ -14350,6 +14521,7 @@ soap_begin_recv(struct soap *soap)
soap->header = NULL;
soap->fault = NULL;
soap->status = 0;
+ soap->fform = NULL;
#ifndef WITH_LEANER
soap->dom = NULL;
soap->dime.chunksize = 0;
@@ -14366,7 +14538,7 @@ soap_begin_recv(struct soap *soap)
#ifdef WIN32
#ifndef UNDER_CE
#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket))
+ if (!soap_valid_socket(soap->socket) && !soap->is) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
#ifdef __BORLANDC__
setmode(soap->recvfd, _O_BINARY);
#else
@@ -14433,14 +14605,24 @@ soap_begin_recv(struct soap *soap)
else
#endif
{ /* skip BOM */
- if (c == 0xEF && (c = soap_getchar(soap)) == 0xBB && (c = soap_getchar(soap)) == 0xBF)
- c = soap_getchar(soap);
+ if (c == 0xEF && soap_get0(soap) == 0xBB)
+ { c = soap_get1(soap);
+ if ((c = soap_get1(soap)) == 0xBF)
+ { soap->mode &= ~SOAP_ENC_LATIN;
+ c = soap_getchar(soap);
+ }
+ else
+ c = (0x0F << 12) | (0xBB << 6) | (c & 0x3F); /* UTF-8 */
+ }
+ else if ((c == 0xFE && soap_get0(soap) == 0xFF) /* UTF-16 BE */
+ || (c == 0xFF && soap_get0(soap) == 0xFE)) /* UTF-16 LE */
+ return soap->error = SOAP_UTF_ERROR;
/* skip space */
while (soap_blank(c))
c = soap_getchar(soap);
}
if ((int)c == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
soap_unget(soap, c);
#ifndef WITH_NOHTTP
/* if not XML or MIME/DIME/ZLIB, assume HTTP header */
@@ -14453,7 +14635,13 @@ soap_begin_recv(struct soap *soap)
return soap->error;
}
if (soap->error == SOAP_STOP)
+ { if (soap->fform)
+ { soap->error = soap->fform(soap);
+ if (soap->error == SOAP_OK)
+ soap->error = SOAP_STOP; /* prevents further processing */
+ }
return soap->error;
+ }
soap->mode = soap->imode; /* if imode is changed, effectuate */
soap->imode = m; /* restore imode */
#ifdef WITH_ZLIB
@@ -14532,7 +14720,7 @@ soap_begin_recv(struct soap *soap)
if (soap->mode & SOAP_ENC_MIME)
{ do /* skip preamble */
{ if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
+ return soap->error = SOAP_CHK_EOF;
} while (c != '-' || soap_get0(soap) != '-');
soap_unget(soap, c);
if (soap_getmimehdr(soap))
@@ -14614,7 +14802,8 @@ SOAP_FMAC1
int
SOAP_FMAC2
soap_envelope_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope") || soap_send_raw(soap, "\r\n", 2)) /* 2.8: always emit \r\n after SOAP Envelope */
+{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope")
+ || soap_send_raw(soap, "\r\n", 2)) /* 2.8: always emit \r\n */
return soap->error;
#ifndef WITH_LEANER
if ((soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM))
@@ -14959,23 +15148,32 @@ soap_try_connect_command(struct soap *soap, int http_command, const char *endpoi
}
else
#endif
+ soap->action = soap_strdup(soap, action);
if (soap->fopen && *soap->host)
{ if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap))
{ soap->error = SOAP_OK;
- soap->keep_alive = 0; /* to force close */
- soap->omode &= ~SOAP_IO_UDP; /* to force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
#ifndef WITH_LEAN
if (!strncmp(endpoint, "soap.udp:", 9))
soap->omode |= SOAP_IO_UDP;
+ else
#endif
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
+ { soap->keep_alive = 0; /* to force close */
+ soap->omode &= ~SOAP_IO_UDP; /* to force close */
+ }
+ soap_closesock(soap);
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to '%s' host='%s' path='%s' port=%d\n", endpoint?endpoint:"(null)", soap->host, soap->path, soap->port));
+ if (!soap->keep_alive || !soap_valid_socket(soap->socket))
+ { soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
+ if (soap->error)
+ return soap->error;
+ soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
+ }
}
}
+#ifdef WITH_NTLM
+ if (soap_ntlm_handshake(soap, SOAP_GET, endpoint, soap->host, soap->port))
+ return soap->error;
+#endif
count = soap_count_attachments(soap);
if (soap_begin_send(soap))
return soap->error;
@@ -14984,7 +15182,6 @@ soap_try_connect_command(struct soap *soap, int http_command, const char *endpoi
soap->mode |= SOAP_IO_BUFFER;
}
#ifndef WITH_NOHTTP
- soap->action = soap_strdup(soap, action);
if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
{ unsigned int k = soap->mode;
soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
@@ -15000,7 +15197,7 @@ soap_try_connect_command(struct soap *soap, int http_command, const char *endpoi
#endif
soap->mode = k;
}
- if (http_command == SOAP_GET)
+ if (http_command == SOAP_GET || http_command == SOAP_DEL)
return soap_end_send(soap);
#endif
return SOAP_OK;
@@ -15008,6 +15205,80 @@ soap_try_connect_command(struct soap *soap, int http_command, const char *endpoi
#endif
/******************************************************************************/
+#ifdef WITH_NTLM
+#ifndef PALM_1
+static int
+soap_ntlm_handshake(struct soap *soap, int command, const char *endpoint, const char *host, int port)
+{ /* requires libntlm from http://www.nongnu.org/libntlm/ */
+ const char *userid = (soap->proxy_userid ? soap->proxy_userid : soap->userid);
+ const char *passwd = (soap->proxy_passwd ? soap->proxy_passwd : soap->passwd);
+ struct SOAP_ENV__Header *oldheader;
+ if (soap->ntlm_challenge && userid && passwd && soap->authrealm)
+ { tSmbNtlmAuthRequest req;
+ tSmbNtlmAuthResponse res;
+ tSmbNtlmAuthChallenge ch;
+ short k = soap->keep_alive;
+ size_t l = soap->length;
+ size_t c = soap->count;
+ soap_mode m = soap->mode, o = soap->omode;
+ int s = soap->status;
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM '%s'\n", soap->ntlm_challenge));
+ if (!*soap->ntlm_challenge)
+ { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM S->C Type 1: received NTLM authentication challenge from server\n"));
+ /* S -> C 401 Unauthorized
+ WWW-Authenticate: NTLM
+ */
+ buildSmbNtlmAuthRequest(&req, userid, soap->authrealm);
+ soap->ntlm_challenge = soap_s2base64(soap, (unsigned char*)&req, NULL, SmbLength(&req));
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM C->S Type 2: sending NTLM authorization to server\nAuthorization: NTLM %s\n", soap->ntlm_challenge));
+ /* C -> S GET ...
+ Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S
+ */
+ soap->omode = SOAP_IO_BUFFER;
+ if (soap_begin_send(soap))
+ return soap->error;
+ soap->keep_alive = 1;
+ soap->status = command;
+ if (soap->fpost(soap, endpoint, host, port, soap->path, soap->action, 0)
+ || soap_end_send(soap))
+ return soap->error;
+ soap->mode = m;
+ soap->keep_alive = k;
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM S->C Type 2: waiting on server NTLM response\n"));
+ oldheader = soap->header;
+ if (soap_begin_recv(soap))
+ if (soap->error == SOAP_EOF)
+ return soap->error;
+ soap_end_recv(soap);
+ soap->header = oldheader;
+ soap->length = l;
+ if (soap->status != 401 && soap->status != 407)
+ return soap->error = SOAP_NTLM_ERROR;
+ soap->error = SOAP_OK;
+ }
+ /* S -> C 401 Unauthorized
+ WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA==
+ */
+ soap_base642s(soap, soap->ntlm_challenge, (char*)&ch, sizeof(tSmbNtlmAuthChallenge), NULL);
+ buildSmbNtlmAuthResponse(&ch, &res, userid, passwd);
+ soap->ntlm_challenge = soap_s2base64(soap, (unsigned char*)&res, NULL, SmbLength(&res));
+ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "NTLM C->S Type 3: sending NTLM authorization to server\nAuthorization: NTLM %s\n", soap->ntlm_challenge));
+ /* C -> S GET ...
+ Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHIAAAAYABgAigAAABQAFABAAAAADAAMAFQAAAASABIAYAAAAAAAAACiAAAAAYIAAFUAUgBTAEEALQBNAEkATgBPAFIAWgBhAHAAaABvAGQATABJAEcASABUAEMASQBUAFkArYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADT
+ */
+ soap->keep_alive = k;
+ soap->length = l;
+ soap->count = c;
+ soap->mode = m;
+ soap->omode = o;
+ soap->status = s;
+ }
+ return SOAP_OK;
+}
+#endif
+#endif
+
+/******************************************************************************/
#ifndef WITH_LEAN
SOAP_FMAC1
char*
@@ -15055,7 +15326,8 @@ SOAP_FMAC1
const char*
SOAP_FMAC2
soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n)
-{ register int i, j, c;
+{ register size_t i, j;
+ register soap_wchar c;
register unsigned long m;
register const char *p;
if (!s || !*s)
@@ -15066,7 +15338,7 @@ soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n)
return SOAP_NON_NULL;
}
if (!t)
- { l = (strlen(s) + 3) / 4 * 3;
+ { l = (strlen(s) + 3) / 4 * 3 + 1; /* make sure enough space for \0 */
t = (char*)soap_malloc(soap, l);
}
if (!t)
@@ -15093,7 +15365,9 @@ soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n)
i += 2;
}
if (n)
- *n += i;
+ *n += (int)i;
+ if (l >= j)
+ *t = '\0';
return p;
}
c -= '+';
@@ -15111,14 +15385,15 @@ soap_base642s(struct soap *soap, const char *s, char *t, size_t l, int *n)
return NULL;
}
}
- *t++ = (char)((m >> 16) & 0xFF);
- *t++ = (char)((m >> 8) & 0xFF);
- *t++ = (char)(m & 0xFF);
if (l < 3)
{ if (n)
- *n += i;
+ *n += (int)i;
+ *t = '\0';
return p;
}
+ *t++ = (char)((m >> 16) & 0xFF);
+ *t++ = (char)((m >> 8) & 0xFF);
+ *t++ = (char)(m & 0xFF);
l -= 3;
}
if (n)
@@ -15168,7 +15443,7 @@ soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n)
return SOAP_NON_NULL;
}
if (!t)
- { l = strlen(s) / 2;
+ { l = strlen(s) / 2 + 1; /* make sure enough space for \0 */
t = (char*)soap_malloc(soap, l);
}
if (!t)
@@ -15182,11 +15457,13 @@ soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n)
d2 = *s++;
if (!d2)
break;
- *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
+ *t++ = (char)(((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'));
l--;
}
if (n)
*n = (int)(t - p);
+ if (l)
+ *t = '\0';
return p;
}
#endif
@@ -15198,13 +15475,13 @@ SOAP_FMAC1
int
SOAP_FMAC2
soap_puthttphdr(struct soap *soap, int status, size_t count)
-{ if (soap->status != SOAP_GET)
+{ if (soap->status != SOAP_GET && soap->status != SOAP_DEL && soap->status != SOAP_CONNECT)
{ register const char *s = "text/xml; charset=utf-8";
register int err = SOAP_OK;
#ifndef WITH_LEANER
register const char *r = NULL;
#endif
- if ((status == SOAP_FILE || soap->status == SOAP_POST_FILE) && soap->http_content)
+ if ((status == SOAP_FILE || soap->status == SOAP_PUT || soap->status == SOAP_POST_FILE) && soap->http_content)
s = soap->http_content;
else if (status == SOAP_HTML)
s = "text/html; charset=utf-8";
@@ -15245,12 +15522,12 @@ soap_puthttphdr(struct soap *soap, int status, size_t count)
}
s = soap->tmpbuf;
}
- if (status == SOAP_OK && soap->version == 2 && soap->action && strlen(soap->action) < sizeof(soap->tmpbuf) - 80)
- { sprintf(soap->tmpbuf, "%s; action=\"%s\"", s, soap->action);
- s = soap->tmpbuf;
- }
+ else
+ s = strcpy(soap->tmpbuf, s);
+ if (status == SOAP_OK && soap->version == 2 && soap->action && strlen(soap->action) + strlen(s) < sizeof(soap->tmpbuf) - 80)
+ sprintf(soap->tmpbuf + strlen(s), "; action=\"%s\"", soap->action);
#endif
- if (s && (err = soap->fposthdr(soap, "Content-Type", s)))
+ if ((err = soap->fposthdr(soap, "Content-Type", s)))
return err;
#ifdef WITH_ZLIB
if ((soap->omode & SOAP_ENC_ZLIB))
@@ -15286,9 +15563,17 @@ soap_puthttphdr(struct soap *soap, int status, size_t count)
static const char*
soap_set_validation_fault(struct soap *soap, const char *s, const char *t)
{ if (*soap->tag)
- sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element '%s'", s, t?t:SOAP_STR_EOS, soap->tag);
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s in element '%s'", s, t ? t : SOAP_STR_EOS, soap->tag);
+#else
+ sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element '%s'", s, t ? t : SOAP_STR_EOS, soap->tag);
+#endif
else
- sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS);
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Validation constraint violation: %s%s", s, t ? t : SOAP_STR_EOS);
+#else
+ sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t ? t : SOAP_STR_EOS);
+#endif
return soap->msgbuf;
}
#endif
@@ -15330,11 +15615,15 @@ soap_set_fault(struct soap *soap)
*s = "Well-formedness violation";
break;
case SOAP_NO_TAG:
- *s = "No XML root element";
+ *s = "No tag: no XML root element or missing SOAP message body element";
break;
case SOAP_MUSTUNDERSTAND:
*c = "SOAP-ENV:MustUnderstand";
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "The data in element '%s' must be understood but cannot be handled", soap->tag);
+#else
sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag);
+#endif
*s = soap->msgbuf;
break;
case SOAP_VERSIONMISMATCH:
@@ -15355,7 +15644,11 @@ soap_set_fault(struct soap *soap)
*s = "Fatal error";
break;
case SOAP_NO_METHOD:
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
+#else
sprintf(soap->msgbuf, "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
+#endif
*s = soap->msgbuf;
break;
case SOAP_NO_DATA:
@@ -15386,7 +15679,7 @@ soap_set_fault(struct soap *soap)
*s = soap_set_validation_fault(soap, "nil not allowed", NULL);
break;
case SOAP_DUPLICATE_ID:
- *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id);
+ *s = soap_set_validation_fault(soap, "multiple definitions (use the SOAP_XML_TREE flag) of the same id ", soap->id);
if (soap->version == 2)
*soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID";
break;
@@ -15411,6 +15704,9 @@ soap_set_fault(struct soap *soap)
case SOAP_HTTP_ERROR:
*s = "An HTTP processing error occurred";
break;
+ case SOAP_NTLM_ERROR:
+ *s = "An HTTP NTLM authentication error occurred";
+ break;
case SOAP_SSL_ERROR:
#ifdef WITH_OPENSSL
*s = "SSL/TLS error";
@@ -15444,7 +15740,11 @@ soap_set_fault(struct soap *soap)
break;
case SOAP_ZLIB_ERROR:
#ifdef WITH_ZLIB
- sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS);
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "Zlib/gzip error: '%s'", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS);
+#else
+ sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream->msg ? soap->d_stream->msg : SOAP_STR_EOS);
+#endif
*s = soap->msgbuf;
#else
*s = "Zlib/gzip not installed for (de)compression: recompile with -DWITH_GZIP";
@@ -15465,8 +15765,11 @@ soap_set_fault(struct soap *soap)
case SOAP_FD_EXCEEDED:
*s = "Maximum number of open connections was reached (no define HAVE_POLL): increase FD_SETSIZE";
break;
+ case SOAP_UTF_ERROR:
+ *s = "UTF content encoding error";
+ break;
case SOAP_STOP:
- *s = "Stopped: no response to be sent or received (informative)";
+ *s = "Stopped: no response sent or received (informative)";
break;
#endif
case SOAP_EOF:
@@ -15488,7 +15791,12 @@ soap_set_fault(struct soap *soap)
#ifndef WITH_NOHTTP
#ifndef WITH_LEAN
if (soap->error > 200 && soap->error < 600)
- { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error));
+ {
+#ifdef HAVE_SNPRINTF
+ soap_snprintf(soap->msgbuf, sizeof(soap->msgbuf), "HTTP Error: %d %s", soap->error, http_error(soap, soap->error));
+#else
+ sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error));
+#endif
*s = soap->msgbuf;
}
else
@@ -15617,12 +15925,14 @@ int
SOAP_FMAC2
soap_send_empty_response(struct soap *soap, int httpstatuscode)
{ register soap_mode m = soap->omode;
- soap->count = 0;
- if ((m & SOAP_IO) == SOAP_IO_CHUNK)
- soap->omode = (m & ~SOAP_IO) | SOAP_IO_BUFFER;
- if (!soap_response(soap, httpstatuscode) && !soap_end_send(soap))
- soap->error = SOAP_STOP; /* stops the server's response */
- soap->omode = m;
+ if (!(m & SOAP_IO_UDP))
+ { soap->count = 0;
+ if ((m & SOAP_IO) == SOAP_IO_CHUNK)
+ soap->omode = (m & ~SOAP_IO) | SOAP_IO_BUFFER;
+ if (!soap_response(soap, httpstatuscode) && !soap_end_send(soap))
+ soap->error = SOAP_STOP; /* stops the server's processing of request */
+ soap->omode = m;
+ }
return soap_closesock(soap);
}
#endif
@@ -15635,10 +15945,12 @@ SOAP_FMAC1
int
SOAP_FMAC2
soap_recv_empty_response(struct soap *soap)
-{ if (!soap_begin_recv(soap))
- soap_end_recv(soap);
- else if (soap->error == SOAP_NO_DATA || soap->error == 202)
- soap->error = SOAP_OK;
+{ if (!(soap->omode & SOAP_IO_UDP))
+ { if (!soap_begin_recv(soap))
+ soap_end_recv(soap);
+ else if (soap->error == SOAP_NO_DATA || soap->error == 202)
+ soap->error = SOAP_OK;
+ }
return soap_closesock(soap);
}
#endif
@@ -15805,16 +16117,15 @@ soap_print_fault(struct soap *soap, FILE *fd)
{ if (soap_check_state(soap))
fprintf(fd, "Error: soap struct state not initialized\n");
else if (soap->error)
- { const char *c, *v = NULL, *s, **d;
- d = soap_faultcode(soap);
- if (!*d)
+ { const char **c, *v = NULL, *s, *d;
+ c = soap_faultcode(soap);
+ if (!*c)
soap_set_fault(soap);
- c = *d;
if (soap->version == 2)
- v = *soap_faultsubcode(soap);
+ v = soap_check_faultsubcode(soap);
s = *soap_faultstring(soap);
- d = soap_faultdetail(soap);
- fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]");
+ d = soap_check_faultdetail(soap);
+ fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
}
}
#endif
@@ -15824,6 +16135,7 @@ soap_print_fault(struct soap *soap, FILE *fd)
#ifdef __cplusplus
#ifndef WITH_LEAN
#ifndef WITH_NOSTDLIB
+#ifndef WITH_COMPAT
SOAP_FMAC1
void
SOAP_FMAC2
@@ -15831,29 +16143,29 @@ soap_stream_fault(struct soap *soap, std::ostream& os)
{ if (soap_check_state(soap))
os << "Error: soap struct state not initialized\n";
else if (soap->error)
- { const char *c, *v = NULL, *s, **d;
- d = soap_faultcode(soap);
- if (!*d)
+ { const char **c, *v = NULL, *s, *d;
+ c = soap_faultcode(soap);
+ if (!*c)
soap_set_fault(soap);
- c = *d;
if (soap->version == 2)
- v = *soap_faultsubcode(soap);
+ v = soap_check_faultsubcode(soap);
s = *soap_faultstring(soap);
- d = soap_faultdetail(soap);
+ d = soap_check_faultdetail(soap);
os << (soap->version ? "SOAP 1." : "Error ")
<< (soap->version ? (int)soap->version : soap->error)
- << " fault: " << c
+ << " fault: " << *c
<< "[" << (v ? v : "no subcode") << "]"
<< std::endl
<< "\"" << (s ? s : "[no reason]") << "\""
<< std::endl
- << "Detail: " << (d && *d ? *d : "[no detail]")
+ << "Detail: " << (d ? d : "[no detail]")
<< std::endl;
}
}
#endif
#endif
#endif
+#endif
/******************************************************************************/
#ifndef WITH_LEAN
@@ -15865,27 +16177,21 @@ soap_sprint_fault(struct soap *soap, char *buf, size_t len)
{ if (soap_check_state(soap))
strncpy(buf, "Error: soap struct not initialized", len);
else if (soap->error)
- { const char *c, *v = NULL, *s, **d;
- d = soap_faultcode(soap);
- if (!*d)
+ { const char **c, *v = NULL, *s, *d;
+ c = soap_faultcode(soap);
+ if (!*c)
soap_set_fault(soap);
- c = *d;
if (soap->version == 2)
v = *soap_faultsubcode(soap);
s = *soap_faultstring(soap);
- d = soap_faultdetail(soap);
+ d = soap_check_faultdetail(soap);
#ifdef HAVE_SNPRINTF
-# ifdef WIN32
- _snprintf
-# else
- snprintf
-# endif
- (buf, len, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]");
+ soap_snprintf(buf, len, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
#else
- if (len > 40 + (v ? strlen(v) : 0) + (s ? strlen(s) : 0) + (d && *d ? strlen(*d) : 0))
- sprintf(buf, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]");
+ if (len > 40 + (v ? strlen(v) : 0) + (s ? strlen(s) : 0) + (d ? strlen(d) : 0))
+ sprintf(buf, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c, v ? v : "no subcode", s ? s : "[no reason]", d ? d : "[no detail]");
else if (len > 40)
- sprintf(buf, "%s%d fault: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c);
+ sprintf(buf, "%s%d fault: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, *c);
else
buf[0] = '\0';
#endif
@@ -15920,8 +16226,8 @@ soap_print_fault_location(struct soap *soap, FILE *fd)
fprintf(fd, "%s%c\n<!-- ** HERE ** -->\n", soap->buf, c1);
if (soap->bufidx < soap->buflen)
fprintf(fd, "%s\n", soap->buf + soap->bufidx);
- soap->buf[i] = c1;
- soap->buf[j] = c2;
+ soap->buf[i] = (char)c1;
+ soap->buf[j] = (char)c2;
}
#endif
}
@@ -15949,7 +16255,7 @@ soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
return SOAP_OK;
}
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id?p->id:"?", r));
+ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id ? p->id : "?", r));
SOAP_FREE(soap, p);
return r;
}
diff --git a/dep/gsoap/stdsoap2.h b/dep/gsoap/stdsoap2.h
index 238b7f175ac..87185924135 100644
--- a/dep/gsoap/stdsoap2.h
+++ b/dep/gsoap/stdsoap2.h
@@ -1,10 +1,10 @@
/*
- stdsoap2.h 2.8.2
+ stdsoap2.h 2.8.10
gSOAP runtime engine
gSOAP XML Web services tools
-Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc., All Rights Reserved.
+Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved.
This part of the software is released under ONE of the following licenses:
GPL, or the gSOAP public license, or Genivia's license for commercial use.
--------------------------------------------------------------------------------
@@ -24,7 +24,7 @@ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc., All Rights Reserved.
+Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc., All Rights Reserved.
--------------------------------------------------------------------------------
GPL license.
@@ -51,6 +51,8 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
--------------------------------------------------------------------------------
*/
+#define GSOAP_VERSION 20810
+
#ifdef WITH_SOAPDEFS_H
# include "soapdefs.h" /* include user-defined stuff */
#endif
@@ -129,6 +131,13 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# endif
#endif
+/* for legacy purposes we use WIN32 macro even though 64 bit is supported */
+#ifdef _WIN64
+# ifndef WIN32
+# define WIN32
+# endif
+#endif
+
#ifdef _WIN32_WCE
# ifndef UNDER_CE
# define UNDER_CE _WIN32_WCE
@@ -211,8 +220,14 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# define HAVE_STRRCHR
# define HAVE_STRTOD
# define HAVE_SSCANF
+# define HAVE_STRTOD_L
+# define HAVE_SPRINTF_L
# define HAVE_STRTOL
# define HAVE_STRTOUL
+# if _MSC_VER >= 1300
+# define HAVE_STRTOLL // use _strtoi64
+# define HAVE_STRTOULL // use _strtoui64
+# endif
# define HAVE_SYS_TIMEB_H
# define HAVE_FTIME
# define HAVE_GMTIME
@@ -293,7 +308,6 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# define HAVE_WCTOMB
# define HAVE_MBTOWC
# define HAVE_ISNAN
-# define HAVE_ISINF
# elif defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD)
# define HAVE_POLL
# define HAVE_SNPRINTF
@@ -472,6 +486,19 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# define ULONG64 unsigned LONG64
# define SOAP_LONG_FORMAT "%ld"
# define SOAP_ULONG_FORMAT "%lu"
+# elif defined(SUN_OS)
+# define HAVE_SNPRINTF
+# define HAVE_STRRCHR
+# define HAVE_STRTOD
+# define HAVE_SSCANF
+# define HAVE_STRTOL
+# define HAVE_STRTOUL
+# define HAVE_SYS_TIMEB_H
+# define HAVE_FTIME
+# define HAVE_RAND_R
+# define HAVE_GETHOSTBYNAME_R
+# define HAVE_GMTIME_R
+# define HAVE_LOCALTIME_R
# else
/* Default assumptions for supported functions */
# define HAVE_SNPRINTF
@@ -515,11 +542,17 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# endif
#endif
-/* native Win and HP-UX compilers don't like empty structs */
+/* native Win, HP-UX, and AIX compilers don't like empty structs */
#if defined(WIN32) || defined(HP_UX) || defined(_AIX41) || defined(_AIX43) || defined(VXWORKS)
# define WITH_NOEMPTYSTRUCT
#endif
+#ifdef WITH_PURE_VIRTUAL
+# define SOAP_PURE_VIRTUAL = 0
+#else
+# define SOAP_PURE_VIRTUAL
+#endif
+
#ifdef HP_UX
# undef HAVE_STRTOLL
# undef HAVE_STRTOULL
@@ -534,8 +567,11 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
/* if we have xlocale.h we use it to avoid decimal point conversion issues */
#ifdef WITH_C_LOCALE
-# include <locale.h>
-# include <xlocale.h>
+# ifdef WIN32
+# include <locale.h>
+# else
+# include <xlocale.h>
+# endif
#else
# undef HAVE_STRTOF_L
# undef HAVE_STRTOD_L
@@ -543,7 +579,7 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# undef HAVE_SPRINTF_L
#endif
-#ifdef TANDEM
+#ifdef TANDEM_NONSTOP
# define SOAP_BUFLEN (32767)
/*# define WITH_NOSTDLIB */ /* uncommment to remove stdlib dependences */
# define WITH_NOIO /* no IO dependences, e.g. remove TCP/IP */
@@ -586,6 +622,10 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# include <limits.h>
#endif
+#ifdef WITH_NTLM
+# include <ntlm.h>
+#endif
+
#ifdef HAVE_POLL
# include <poll.h>
#endif
@@ -672,14 +712,6 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# define SOAP_WINSOCKINT size_t
#endif
-#ifdef WITH_IPV6
-# ifdef IPV6_V6ONLY
-# if !defined(WITH_NO_IPV6_V6ONLY) && !defined(WITH_IPV6_V6ONLY)
-# define WITH_NO_IPV6_V6ONLY /* turn on IPv6-IPv4 switching */
-# endif
-# endif
-#endif
-
#if defined(WITH_IPV6_V6ONLY) || defined(WITH_NO_IPV6_V6ONLY)
# ifndef WITH_IPV6
# define WITH_IPV6
@@ -691,9 +723,17 @@ A commercial use license is available from Genivia, Inc., contact@genivia.com
# include <io.h>
# include <fcntl.h>
# endif
-# include <winsock2.h> /* Visual Studio 2005 users: you must install the Platform SDK (R2) */
-# include <ws2tcpip.h>
-# include <wspiapi.h>
+// When you get macro redefinition errors when compiling the code below:
+// try arrange your include list that <windows.h> is included after "stdsoap2.h"
+// or define _WINSOCKAPI_ first:
+// #define _WINSOCKAPI_ // stops windows.h including winsock.h
+// #include <windows.h>
+// #include "stdsoap2.h"
+# include <winsock2.h> /* Visual Studio 2005 users: install Platform SDK (R2) */
+# include <ws2tcpip.h>
+// # define _WSPIAPI_COUNTOF /* DEV NOTE: enble to fix problems with VC6 */
+// # include <wspiapi.h>
+# include <ws2spi.h> /* DEV NOTE: replaces older wspiapi.h above */
# ifdef WITH_IPV6
# define SOAP_GAI_STRERROR gai_strerrorA
# endif
@@ -790,9 +830,9 @@ extern "C" {
# endif
#elif defined(SOCKLEN_T)
# define SOAP_SOCKLEN_T SOCKLEN_T
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD) || defined(__QNX__) || defined(QNX) || defined(OS390) || defined(HP_UX)
+#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD) || defined(__QNX__) || defined(QNX) || defined(OS390)
# define SOAP_SOCKLEN_T socklen_t
-#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
+#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) || defined(HP_UX)
# define SOAP_SOCKLEN_T int
#else
# define SOAP_SOCKLEN_T size_t
@@ -822,6 +862,12 @@ extern "C" {
# define FD_SETSIZE (1024)
#endif
+#ifdef WITH_LEAN
+# define SOAP_CHK_EOF SOAP_EOF
+#else
+# define SOAP_CHK_EOF (soap->error ? soap->error : SOAP_EOF)
+#endif
+
#if defined(SYMBIAN)
# define LONG64 long
# define ULONG64 unsigned LONG64
@@ -874,7 +920,6 @@ extern "C" {
#elif defined(PALM)
# define soap_int32 Int32
#elif defined(_AIX)
-# define SOAP_NEW(type) new type /* AIX compilers don't like new (t) */
# if defined(_AIX43)
# define soap_int32 int32_t
# else
@@ -1133,6 +1178,14 @@ extern const char soap_base64o[], soap_base64i[];
#define soap_isninfd(n) ((n) < 0 && soap_isinf(n))
#define soap_isninff(n) ((n) < 0 && soap_isinf(n))
+#ifdef HAVE_SNPRINTF
+# ifdef WIN32
+# define soap_snprintf _snprintf
+# else
+# define soap_snprintf snprintf
+# endif
+#endif
+
/* gSOAP error codes */
#define SOAP_EOF EOF
@@ -1184,6 +1237,8 @@ extern const char soap_base64o[], soap_base64i[];
#define SOAP_OCCURS 44
#define SOAP_LENGTH 45
#define SOAP_FD_EXCEEDED 46
+#define SOAP_UTF_ERROR 47
+#define SOAP_NTLM_ERROR 48
#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_NO_TAG || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF)
#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD)
@@ -1199,7 +1254,7 @@ extern const char soap_base64o[], soap_base64i[];
/* Exceptional gSOAP HTTP server response status codes >= 1000 */
#define SOAP_STOP 1000 /* No HTTP response */
-#define SOAP_FORM 1001 /* Form request/response */
+#define SOAP_FORM 1001 /* Request (form) data is present, no HTTP response */
#define SOAP_HTML 1002 /* Custom HTML response */
#define SOAP_FILE 1003 /* Custom file-based response */
@@ -1208,6 +1263,9 @@ extern const char soap_base64o[], soap_base64i[];
#define SOAP_POST 2000 /* POST request */
#define SOAP_POST_FILE 2001 /* Custom file-based POST request */
#define SOAP_GET 2002 /* GET request */
+#define SOAP_PUT 2003 /* PUT request */
+#define SOAP_DEL 2004 /* DELETE request */
+#define SOAP_CONNECT 2005 /* CONNECT request */
/* gSOAP DIME */
@@ -1254,21 +1312,22 @@ typedef soap_int32 soap_mode;
#define SOAP_XML_DEFAULTNS 0x00008000 /* out: emit xmlns="..." */
#define SOAP_XML_CANONICAL 0x00010000 /* out: excC14N canonical XML */
#define SOAP_XML_TREE 0x00020000 /* out: XML tree (no id/ref) */
-#define SOAP_XML_GRAPH 0x00040000 /* see DOM manual */
-#define SOAP_XML_NIL 0x00080000 /* out: NULLs as xsi:nil */
+#define SOAP_XML_NIL 0x00040000 /* out: NULLs as xsi:nil */
+#define SOAP_XML_NOTYPE 0x00080000 /* out: NULLs as xsi:nil */
-#define SOAP_C_NOIOB 0x00100000 /* don't fault on array index out of bounds (just ignore) */
-#define SOAP_C_UTFSTRING 0x00200000 /* (de)serialize strings with UTF8 content */
-#define SOAP_C_MBSTRING 0x00400000 /* (de)serialize strings with multi-byte content */
-#define SOAP_C_NILSTRING 0x00800000 /* serialize empty strings as nil (omitted) */
+#define SOAP_DOM_TREE 0x00100000 /* see DOM manual */
+#define SOAP_DOM_NODE 0x00200000
+#define SOAP_DOM_ASIS 0x00400000
-#define SOAP_XML_DOM 0x01000000
+#define SOAP_C_NOIOB 0x01000000 /* don't fault on array index out of bounds (just ignore) */
+#define SOAP_C_UTFSTRING 0x02000000 /* (de)serialize strings with UTF8 content */
+#define SOAP_C_MBSTRING 0x04000000 /* (de)serialize strings with multi-byte content */
+#define SOAP_C_NILSTRING 0x08000000 /* serialize empty strings as nil (omitted) */
-#define SOAP_DOM_TREE 0x02000000
-#define SOAP_DOM_NODE 0x04000000
-#define SOAP_DOM_ASIS 0x08000000
+#define SOAP_XML_DOM 0x10000000 /* enable internal DOM */
+#define SOAP_XML_GRAPH 0x20000000 /* id-ref graph in DOM */
-#define SOAP_MIME_POSTCHECK 0x10000000 /* MIME flag (internal) */
+#define SOAP_MIME_POSTCHECK 0x40000000 /* MIME flag (internal) */
#define SOAP_SEC_WSUID 0x80000000 /* Add Body wsu:Id */
@@ -1303,7 +1362,7 @@ typedef soap_int32 soap_mode;
#define soap_check_state(soap) (!(soap) || ((soap)->state != SOAP_INIT && (soap)->state != SOAP_COPY))
-/* parts, states, and events */
+/* parts */
#define SOAP_BEGIN 0
#define SOAP_IN_ENVELOPE 2
@@ -1315,8 +1374,11 @@ typedef soap_int32 soap_mode;
#define SOAP_END_ENVELOPE 8
#define SOAP_END 9
-#define SOAP_SEC_BEGIN 10
-#define SOAP_SEC_SIGN 11
+/* events */
+
+#define SOAP_SEC_BEGIN 1
+#define SOAP_SEC_SIGN 2
+#define SOAP_SEC_DECRYPT 3
/* DEBUG macros */
@@ -1349,13 +1411,17 @@ typedef soap_int32 soap_mode;
#endif
#ifndef SOAP_NEW /* use C++ new operator */
-# if (__GNUC__ <= 2) && !defined(__BORLANDC__) /* Borland uses GNU C? */
+# if (defined(__GNUC__) && (__GNUC__ <= 2) && !defined(__BORLANDC__)) || defined(__clang__) || defined(_AIX)
# define SOAP_NEW(type) new type /* old form w/o parenthesis */
# else
# define SOAP_NEW(type) new (type) /* prefer with parenthesis */
# endif
#endif
+#ifndef SOAP_PLACEMENT_NEW
+# define SOAP_PLACEMENT_NEW(buf, type) new (buf) type
+#endif
+
#ifndef SOAP_NEW_COPY /* use C++ new operator for ::copy() */
# define SOAP_NEW_COPY(clas) new clas /* prefer w/o parenthesis */
#endif
@@ -1792,9 +1858,15 @@ struct SOAP_STD_API soap
struct soap_plugin *plugins; /* linked list of plug-in data */
const char *userid; /* HTTP Basic authorization userid */
const char *passwd; /* HTTP Basic authorization passwd */
+ const char *authrealm; /* HTTP authentication realm (NTLM domain) */
+#if !defined(WITH_LEAN) || defined(WITH_NTLM)
+ const char *ntlm_challenge; /* HTTP NTLM challenge key string */
+ short ntlm_auth; /* HTTP NTLM authentication type */
+ short ntlm_stage; /* HTTP NTLM stage 0..3 */
+#endif
int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
int (*fget)(struct soap*); /* HTTP GET hook (not set by default) */
- int (*fput)(struct soap*); /* HTTP PUT hook (handled as POST) */
+ int (*fput)(struct soap*); /* HTTP PUT hook (handled as POST by default) */
int (*fdel)(struct soap*); /* HTTP DELETE hook (not set by default) */
int (*fopt)(struct soap*); /* HTTP OPTIONS hook (not set by default) */
int (*fhead)(struct soap*); /* HTTP HEAD hook (not set by default) */
@@ -1847,11 +1919,13 @@ struct SOAP_STD_API soap
size_t (*fmimeread)(struct soap*, void*, char*, size_t);
int (*fmimewrite)(struct soap*, void*, const char*, size_t);
#endif
- SOAP_SOCKET master;
- SOAP_SOCKET socket;
+ SOAP_SOCKET master; /* socket bound to TCP/IP port */
+ SOAP_SOCKET socket; /* socket to send and receive */
+ SOAP_SOCKET sendsk; /* socket to send (overrides ::socket) */
+ SOAP_SOCKET recvsk; /* socket to receive (overrides ::socket) */
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
- std::ostream *os;
- std::istream *is;
+ std::ostream *os; /* stream to send */
+ std::istream *is; /* stream to receive */
#else
void *os; /* preserve struct size */
void *is; /* preserve struct size */
@@ -1860,8 +1934,8 @@ struct SOAP_STD_API soap
int sendfd; /* WinCE FD to send */
int recvfd; /* WinCE FD to receive */
#else
- FILE *sendfd;
- FILE *recvfd;
+ FILE *sendfd; /* FD to send */
+ FILE *recvfd; /* FD to receive */
#endif
size_t bufidx; /* index in soap.buf[] */
size_t buflen; /* length of soap.buf[] content */
@@ -1885,9 +1959,9 @@ struct SOAP_STD_API soap
char arraySize[SOAP_TAGLEN];
char arrayOffset[SOAP_TAGLEN];
short other;
- short position;
- int positions[SOAP_MAXDIMS];
short root;
+ int position;
+ int positions[SOAP_MAXDIMS];
struct soap_attribute *attributes; /* attribute list */
short encoding; /* when set, output encodingStyle */
short mustUnderstand; /* a mustUnderstand element was parsed or is output */
@@ -1895,6 +1969,7 @@ struct SOAP_STD_API soap
short ns; /* when not set, output full xmlns bindings */
short part; /* SOAP part state (header or body) */
short event; /* engine events and states for use by plugins */
+ unsigned int evlev; /* event level */
short alloced;
short peeked;
size_t chunksize;
@@ -1903,7 +1978,6 @@ struct SOAP_STD_API soap
char path[SOAP_TAGLEN];
char host[SOAP_TAGLEN];
char *action;
- char *authrealm; /* HTTP authentication realm */
char *prolog; /* XML declaration prolog */
unsigned long ip; /* IP number */
int port; /* port number */
@@ -1990,7 +2064,11 @@ struct SOAP_STD_API soap
char session_host[SOAP_TAGLEN];
int session_port;
#ifdef WITH_C_LOCALE
+# ifdef WIN32
+ _locale_t c_locale; /* set to C locale by default */
+# else
locale_t c_locale; /* set to C locale by default */
+# endif
#else
void *c_locale;
#endif
@@ -2073,13 +2151,26 @@ soap_wchar soap_get0(struct soap*);
soap_wchar soap_get1(struct soap*);
#endif
+#define soap_versioning_paste(name, ext) name##_LIBRARY_VERSION_REQUIRED_##ext
+#define soap_versioning_ext(name, ext) soap_versioning_paste(name, ext)
+#define soap_versioning(name) soap_versioning_ext(name, GSOAP_VERSION)
+
+#define soap_init(soap) soap_init1(soap, SOAP_IO_DEFAULT)
+#define soap_init1(soap, mode) soap_init2(soap, mode, mode)
+#define soap_init2(soap, imode, omode) soap_versioning(soap_init)(soap, imode, omode)
+
+#define soap_new() soap_new1(SOAP_IO_DEFAULT)
+#define soap_new1(mode) soap_new2(mode, mode)
+#define soap_new2(imode, omode) soap_versioning(soap_new)(imode, omode)
+
#define soap_revget1(soap) ((soap)->bufidx--)
#define soap_unget(soap, c) ((soap)->ahead = c)
#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL)
-#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n))
+#define soap_mode(soap, n) ((soap)->mode = (soap)->imode = (soap)->omode = (n))
+#define soap_imode(soap, n) ((soap)->imode = (n))
+#define soap_omode(soap, n) ((soap)->omode = (n))
#define soap_set_imode(soap, n) ((soap)->imode |= (n))
#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n))
-#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n))
#define soap_set_omode(soap, n) ((soap)->omode |= (n))
#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n))
#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n))
@@ -2104,6 +2195,18 @@ soap_wchar soap_get1(struct soap*);
SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b);
#endif
+#ifdef WIN32
+# define soap_strtoll _strtoi64
+#else
+# define soap_strtoll strtoll
+#endif
+
+#ifdef WIN32
+# define soap_strtoull _strtoui64
+#else
+# define soap_strtoull strtoull
+#endif
+
#if defined(WITH_OPENSSL)
# define soap_random soap_rand()
SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void);
@@ -2131,18 +2234,29 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void);
# define soap_markelement(s, p, n) (0)
#endif
-SOAP_FMAC1 void SOAP_FMAC2 soap_header(struct soap*);
-SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*);
-SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*);
-SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*);
-SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*);
-SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*);
+/* soap_traverse() traversal/walker routines take walker function arguments */
+typedef void soap_walker(struct soap*, void*, int, const char*, const char*);
+
+SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap);
+SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap *soap);
+
+#ifndef WITH_NOGLOBAL
+SOAP_FMAC3 void SOAP_FMAC4 soap_header(struct soap*);
+SOAP_FMAC3 void SOAP_FMAC4 soap_fault(struct soap*);
+SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultcode(struct soap*);
+SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultsubcode(struct soap*);
+SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultstring(struct soap*);
+SOAP_FMAC3 const char** SOAP_FMAC4 soap_faultdetail(struct soap*);
+SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultsubcode(struct soap*);
+SOAP_FMAC3 const char* SOAP_FMAC4 soap_check_faultdetail(struct soap*);
+SOAP_FMAC3 void SOAP_FMAC4 soap_serializefault(struct soap*);
+#endif
+
SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*);
-SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*);
SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*);
-SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*);
-SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*);
+SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*);
SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*);
+SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_ssl_init(void);
SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*);
@@ -2234,7 +2348,7 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*);
SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t);
SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*);
SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, int (*fdelete)(struct soap_clist*));
-SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*);
+SOAP_FMAC1 int SOAP_FMAC2 soap_unlink(struct soap*, const void*);
SOAP_FMAC1 void SOAP_FMAC2 soap_free_temp(struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_del(struct soap*);
@@ -2262,18 +2376,15 @@ SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int);
SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int);
SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*);
+SOAP_FMAC1 int SOAP_FMAC2 soap_force_closesock(struct soap*);
-SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void);
-SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode);
-SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode);
+SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_versioning(soap_new)(soap_mode, soap_mode);
SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*);
SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(const struct soap*);
SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*, const struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_copy_stream(struct soap*, struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_free_stream(struct soap*);
-SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*);
-SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode);
-SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode);
+SOAP_FMAC1 void SOAP_FMAC2 soap_versioning(soap_init)(struct soap*, soap_mode, soap_mode);
SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*);
SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*);
@@ -2353,6 +2464,7 @@ SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*, struct soap_blist*);
SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*, struct soap_blist*);
SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, struct soap_blist*, char*, int);
SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*, struct soap_blist*);
+SOAP_FMAC1 void SOAP_FMAC2 soap_update_pointers(struct soap *soap, char *start, char *end, char *p1, char *p2);
SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*);
SOAP_FMAC1 int soap_envelope_end_out(struct soap*);
@@ -2382,8 +2494,10 @@ SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*, int check);
SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*);
SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*);
# ifndef WITH_LEAN
-# ifdef __cplusplus
+# ifndef WITH_COMPAT
+# ifdef __cplusplus
SOAP_FMAC1 void SOAP_FMAC2 soap_stream_fault(struct soap*, std::ostream&);
+# endif
# endif
SOAP_FMAC1 char* SOAP_FMAC2 soap_sprint_fault(struct soap*, char*, size_t);
# endif
diff --git a/dep/gsoap/tc_upgrades.txt b/dep/gsoap/tc_upgrades.txt
new file mode 100644
index 00000000000..04298b2ae82
--- /dev/null
+++ b/dep/gsoap/tc_upgrades.txt
@@ -0,0 +1,12 @@
+* Generate new headers based on TrinityCore soap-services stub:
+gsoap/bin/linux386/soapcpp2 -1 -S -L -w -x -y soap.stub
+
+* Copy the following files from the gsoap package:
+gsoap/stdsoap2.h
+gsoap/stdsoap2.cpp
+
+* Remove the following files after generation:
+ns1.nsmap
+soapObject.h
+
+* Test compile and see if SOAP works...
diff --git a/dep/utf8cpp/utf8/checked.h b/dep/utf8cpp/utf8/checked.h
index a1d2035364d..3b00644444c 100644
--- a/dep/utf8cpp/utf8/checked.h
+++ b/dep/utf8cpp/utf8/checked.h
@@ -34,7 +34,7 @@ DEALINGS IN THE SOFTWARE.
namespace utf8
{
// Base for the exceptions that may be thrown from the library
- class exception : public std::exception {
+ class exception : public ::std::exception {
};
// Exceptions that may be thrown from the library functions.
@@ -69,12 +69,38 @@ namespace utf8
/// The library API - functions intended to be called by the users
+ template <typename octet_iterator>
+ octet_iterator append(uint32_t cp, octet_iterator result)
+ {
+ if (!utf8::internal::is_code_point_valid(cp))
+ throw invalid_code_point(cp);
+
+ if (cp < 0x80) // one octet
+ *(result++) = static_cast<uint8_t>(cp);
+ else if (cp < 0x800) { // two octets
+ *(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
+ *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
+ }
+ else if (cp < 0x10000) { // three octets
+ *(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
+ *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
+ *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
+ }
+ else { // four octets
+ *(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
+ *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f) | 0x80);
+ *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
+ *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
+ }
+ return result;
+ }
+
template <typename octet_iterator, typename output_iterator>
output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
{
while (start != end) {
octet_iterator sequence_start = start;
- internal::utf_error err_code = internal::validate_next(start, end);
+ internal::utf_error err_code = utf8::internal::validate_next(start, end);
switch (err_code) {
case internal::UTF8_OK :
for (octet_iterator it = sequence_start; it != start; ++it)
@@ -83,16 +109,16 @@ namespace utf8
case internal::NOT_ENOUGH_ROOM:
throw not_enough_room();
case internal::INVALID_LEAD:
- append (replacement, out);
+ utf8::append (replacement, out);
++start;
break;
case internal::INCOMPLETE_SEQUENCE:
case internal::OVERLONG_SEQUENCE:
case internal::INVALID_CODE_POINT:
- append (replacement, out);
+ utf8::append (replacement, out);
++start;
// just one replacement mark for the sequence
- while (internal::is_trail(*start) && start != end)
+ while (start != end && utf8::internal::is_trail(*start))
++start;
break;
}
@@ -103,41 +129,15 @@ namespace utf8
template <typename octet_iterator, typename output_iterator>
inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
{
- static const uint32_t replacement_marker = internal::mask16(0xfffd);
- return replace_invalid(start, end, out, replacement_marker);
- }
-
- template <typename octet_iterator>
- octet_iterator append(uint32_t cp, octet_iterator result)
- {
- if (!internal::is_code_point_valid(cp))
- throw invalid_code_point(cp);
-
- if (cp < 0x80) // one octet
- *(result++) = static_cast<uint8_t>(cp);
- else if (cp < 0x800) { // two octets
- *(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else if (cp < 0x10000) { // three octets
- *(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- else { // four octets
- *(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
- *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
- *(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
- }
- return result;
+ static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
+ return utf8::replace_invalid(start, end, out, replacement_marker);
}
template <typename octet_iterator>
uint32_t next(octet_iterator& it, octet_iterator end)
{
uint32_t cp = 0;
- internal::utf_error err_code = internal::validate_next(it, end, &cp);
+ internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);
switch (err_code) {
case internal::UTF8_OK :
break;
@@ -156,18 +156,22 @@ namespace utf8
template <typename octet_iterator>
uint32_t peek_next(octet_iterator it, octet_iterator end)
{
- return next(it, end);
+ return utf8::next(it, end);
}
template <typename octet_iterator>
uint32_t prior(octet_iterator& it, octet_iterator start)
{
+ // can't do much if it == start
+ if (it == start)
+ throw not_enough_room();
+
octet_iterator end = it;
- while (internal::is_trail(*(--it)))
- if (it < start)
+ // Go back until we hit either a lead octet or start
+ while (utf8::internal::is_trail(*(--it)))
+ if (it == start)
throw invalid_utf8(*it); // error - no lead byte in the sequence
- octet_iterator temp = it;
- return next(temp, end);
+ return utf8::peek_next(it, end);
}
/// Deprecated in versions that include "prior"
@@ -175,18 +179,18 @@ namespace utf8
uint32_t previous(octet_iterator& it, octet_iterator pass_start)
{
octet_iterator end = it;
- while (internal::is_trail(*(--it)))
+ while (utf8::internal::is_trail(*(--it)))
if (it == pass_start)
throw invalid_utf8(*it); // error - no lead byte in the sequence
octet_iterator temp = it;
- return next(temp, end);
+ return utf8::next(temp, end);
}
template <typename octet_iterator, typename distance_type>
void advance (octet_iterator& it, distance_type n, octet_iterator end)
{
for (distance_type i = 0; i < n; ++i)
- next(it, end);
+ utf8::next(it, end);
}
template <typename octet_iterator>
@@ -195,7 +199,7 @@ namespace utf8
{
typename std::iterator_traits<octet_iterator>::difference_type dist;
for (dist = 0; first < last; ++dist)
- next(first, last);
+ utf8::next(first, last);
return dist;
}
@@ -203,12 +207,12 @@ namespace utf8
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
{
while (start != end) {
- uint32_t cp = internal::mask16(*start++);
+ uint32_t cp = utf8::internal::mask16(*start++);
// Take care of surrogate pairs first
- if (internal::is_lead_surrogate(cp)) {
+ if (utf8::internal::is_lead_surrogate(cp)) {
if (start != end) {
- uint32_t trail_surrogate = internal::mask16(*start++);
- if (internal::is_trail_surrogate(trail_surrogate))
+ uint32_t trail_surrogate = utf8::internal::mask16(*start++);
+ if (utf8::internal::is_trail_surrogate(trail_surrogate))
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
else
throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
@@ -218,10 +222,10 @@ namespace utf8
}
// Lone trail surrogate
- else if (internal::is_trail_surrogate(cp))
+ else if (utf8::internal::is_trail_surrogate(cp))
throw invalid_utf16(static_cast<uint16_t>(cp));
- result = append(cp, result);
+ result = utf8::append(cp, result);
}
return result;
}
@@ -230,7 +234,7 @@ namespace utf8
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
{
while (start != end) {
- uint32_t cp = next(start, end);
+ uint32_t cp = utf8::next(start, end);
if (cp > 0xffff) { //make a surrogate pair
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
@@ -245,7 +249,7 @@ namespace utf8
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
{
while (start != end)
- result = append(*(start++), result);
+ result = utf8::append(*(start++), result);
return result;
}
@@ -254,7 +258,7 @@ namespace utf8
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
{
while (start != end)
- (*result++) = next(start, end);
+ (*result++) = utf8::next(start, end);
return result;
}
@@ -280,7 +284,7 @@ namespace utf8
uint32_t operator * () const
{
octet_iterator temp = it;
- return next(temp, range_end);
+ return utf8::next(temp, range_end);
}
bool operator == (const iterator& rhs) const
{
@@ -294,24 +298,24 @@ namespace utf8
}
iterator& operator ++ ()
{
- next(it, range_end);
+ utf8::next(it, range_end);
return *this;
}
iterator operator ++ (int)
{
iterator temp = *this;
- next(it, range_end);
+ utf8::next(it, range_end);
return temp;
}
iterator& operator -- ()
{
- prior(it, range_start);
+ utf8::prior(it, range_start);
return *this;
}
iterator operator -- (int)
{
iterator temp = *this;
- prior(it, range_start);
+ utf8::prior(it, range_start);
return temp;
}
}; // class iterator
diff --git a/dep/utf8cpp/utf8/core.h b/dep/utf8cpp/utf8/core.h
index ec709f12006..693d388c078 100644
--- a/dep/utf8cpp/utf8/core.h
+++ b/dep/utf8cpp/utf8/core.h
@@ -68,7 +68,7 @@ namespace internal
template<typename octet_type>
inline bool is_trail(octet_type oc)
{
- return ((mask8(oc) >> 6) == 0x2);
+ return ((utf8::internal::mask8(oc) >> 6) == 0x2);
}
template <typename u16>
@@ -92,14 +92,14 @@ namespace internal
template <typename u32>
inline bool is_code_point_valid(u32 cp)
{
- return (cp <= CODE_POINT_MAX && !is_surrogate(cp) && cp != 0xfffe && cp != 0xffff);
+ return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));
}
template <typename octet_iterator>
inline typename std::iterator_traits<octet_iterator>::difference_type
sequence_length(octet_iterator lead_it)
{
- uint8_t lead = mask8(*lead_it);
+ uint8_t lead = utf8::internal::mask8(*lead_it);
if (lead < 0x80)
return 1;
else if ((lead >> 5) == 0x6)
@@ -133,123 +133,94 @@ namespace internal
enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
- /// get_sequence_x functions decode utf-8 sequences of the length x
+ /// Helper for get_sequence_x
+ template <typename octet_iterator>
+ utf_error increase_safely(octet_iterator& it, octet_iterator end)
+ {
+ if (++it == end)
+ return NOT_ENOUGH_ROOM;
+
+ if (!utf8::internal::is_trail(*it))
+ return INCOMPLETE_SEQUENCE;
+
+ return UTF8_OK;
+ }
+ #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}
+
+ /// get_sequence_x functions decode utf-8 sequences of the length x
template <typename octet_iterator>
- utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t* code_point)
+ utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
- if (it != end) {
- if (code_point)
- *code_point = mask8(*it);
- return UTF8_OK;
- }
- return NOT_ENOUGH_ROOM;
+ if (it == end)
+ return NOT_ENOUGH_ROOM;
+
+ code_point = utf8::internal::mask8(*it);
+
+ return UTF8_OK;
}
template <typename octet_iterator>
- utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t* code_point)
+ utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
- utf_error ret_code = NOT_ENOUGH_ROOM;
+ if (it == end)
+ return NOT_ENOUGH_ROOM;
+
+ code_point = utf8::internal::mask8(*it);
- if (it != end) {
- uint32_t cp = mask8(*it);
- if (++it != end) {
- if (is_trail(*it)) {
- cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
- if (code_point)
- *code_point = cp;
- ret_code = UTF8_OK;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
+ code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
- return ret_code;
+ return UTF8_OK;
}
template <typename octet_iterator>
- utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t* code_point)
+ utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
- utf_error ret_code = NOT_ENOUGH_ROOM;
-
- if (it != end) {
- uint32_t cp = mask8(*it);
- if (++it != end) {
- if (is_trail(*it)) {
- cp = ((cp << 12) & 0xffff) + ((mask8(*it) << 6) & 0xfff);
- if (++it != end) {
- if (is_trail(*it)) {
- cp += (*it) & 0x3f;
-
- if (code_point)
- *code_point = cp;
- ret_code = UTF8_OK;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
+ if (it == end)
+ return NOT_ENOUGH_ROOM;
+
+ code_point = utf8::internal::mask8(*it);
+
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+ code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
+
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
- return ret_code;
+ code_point += (*it) & 0x3f;
+
+ return UTF8_OK;
}
template <typename octet_iterator>
- utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t* code_point)
+ utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
- utf_error ret_code = NOT_ENOUGH_ROOM;
-
- if (it != end) {
- uint32_t cp = mask8(*it);
- if (++it != end) {
- if (is_trail(*it)) {
- cp = ((cp << 18) & 0x1fffff) + ((mask8(*it) << 12) & 0x3ffff);
- if (++it != end) {
- if (is_trail(*it)) {
- cp += (mask8(*it) << 6) & 0xfff;
- if (++it != end) {
- if (is_trail(*it)) {
- cp += (*it) & 0x3f;
-
- if (code_point)
- *code_point = cp;
- ret_code = UTF8_OK;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
- else
- ret_code = INCOMPLETE_SEQUENCE;
- }
- else
- ret_code = NOT_ENOUGH_ROOM;
- }
+ if (it == end)
+ return NOT_ENOUGH_ROOM;
- return ret_code;
+ code_point = utf8::internal::mask8(*it);
+
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+ code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
+
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+ code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
+
+ UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+ code_point += (*it) & 0x3f;
+
+ return UTF8_OK;
}
+ #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
+
template <typename octet_iterator>
- utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t* code_point)
+ utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
{
// Save the original value of it so we can go back in case of failure
// Of course, it does not make much sense with i.e. stream iterators
@@ -258,34 +229,33 @@ namespace internal
uint32_t cp = 0;
// Determine the sequence length based on the lead octet
typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
- octet_difference_type length = sequence_length(it);
- if (length == 0)
- return INVALID_LEAD;
+ const octet_difference_type length = utf8::internal::sequence_length(it);
- // Now that we have a valid sequence length, get trail octets and calculate the code point
+ // Get trail octets and calculate the code point
utf_error err = UTF8_OK;
switch (length) {
+ case 0:
+ return INVALID_LEAD;
case 1:
- err = get_sequence_1(it, end, &cp);
+ err = utf8::internal::get_sequence_1(it, end, cp);
break;
case 2:
- err = get_sequence_2(it, end, &cp);
+ err = utf8::internal::get_sequence_2(it, end, cp);
break;
case 3:
- err = get_sequence_3(it, end, &cp);
+ err = utf8::internal::get_sequence_3(it, end, cp);
break;
case 4:
- err = get_sequence_4(it, end, &cp);
+ err = utf8::internal::get_sequence_4(it, end, cp);
break;
}
if (err == UTF8_OK) {
// Decoding succeeded. Now, security checks...
- if (is_code_point_valid(cp)) {
- if (!is_overlong_sequence(cp, length)){
+ if (utf8::internal::is_code_point_valid(cp)) {
+ if (!utf8::internal::is_overlong_sequence(cp, length)){
// Passed! Return here.
- if (code_point)
- *code_point = cp;
+ code_point = cp;
++it;
return UTF8_OK;
}
@@ -303,7 +273,8 @@ namespace internal
template <typename octet_iterator>
inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
- return validate_next(it, end, 0);
+ uint32_t ignored;
+ return utf8::internal::validate_next(it, end, ignored);
}
} // namespace internal
@@ -318,7 +289,7 @@ namespace internal
{
octet_iterator result = start;
while (result != end) {
- internal::utf_error err_code = internal::validate_next(result, end);
+ utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);
if (err_code != internal::UTF8_OK)
return result;
}
@@ -328,27 +299,27 @@ namespace internal
template <typename octet_iterator>
inline bool is_valid(octet_iterator start, octet_iterator end)
{
- return (find_invalid(start, end) == end);
+ return (utf8::find_invalid(start, end) == end);
}
template <typename octet_iterator>
inline bool starts_with_bom (octet_iterator it, octet_iterator end)
{
return (
- ((it != end) && (internal::mask8(*it++)) == bom[0]) &&
- ((it != end) && (internal::mask8(*it++)) == bom[1]) &&
- ((it != end) && (internal::mask8(*it)) == bom[2])
+ ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&
+ ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&
+ ((it != end) && (utf8::internal::mask8(*it)) == bom[2])
);
}
- //Deprecated in release 2.3
+ //Deprecated in release 2.3
template <typename octet_iterator>
inline bool is_bom (octet_iterator it)
{
return (
- (internal::mask8(*it++)) == bom[0] &&
- (internal::mask8(*it++)) == bom[1] &&
- (internal::mask8(*it)) == bom[2]
+ (utf8::internal::mask8(*it++)) == bom[0] &&
+ (utf8::internal::mask8(*it++)) == bom[1] &&
+ (utf8::internal::mask8(*it)) == bom[2]
);
}
} // namespace utf8
diff --git a/dep/utf8cpp/utf8/unchecked.h b/dep/utf8cpp/utf8/unchecked.h
index 2f3eb4d1d02..b4547fad945 100644
--- a/dep/utf8cpp/utf8/unchecked.h
+++ b/dep/utf8cpp/utf8/unchecked.h
@@ -60,7 +60,7 @@ namespace utf8
template <typename octet_iterator>
uint32_t next(octet_iterator& it)
{
- uint32_t cp = internal::mask8(*it);
+ uint32_t cp = utf8::internal::mask8(*it);
typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
switch (length) {
case 1:
@@ -71,15 +71,15 @@ namespace utf8
break;
case 3:
++it;
- cp = ((cp << 12) & 0xffff) + ((internal::mask8(*it) << 6) & 0xfff);
+ cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
++it;
cp += (*it) & 0x3f;
break;
case 4:
++it;
- cp = ((cp << 18) & 0x1fffff) + ((internal::mask8(*it) << 12) & 0x3ffff);
+ cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
++it;
- cp += (internal::mask8(*it) << 6) & 0xfff;
+ cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
++it;
cp += (*it) & 0x3f;
break;
@@ -91,29 +91,29 @@ namespace utf8
template <typename octet_iterator>
uint32_t peek_next(octet_iterator it)
{
- return next(it);
+ return utf8::unchecked::next(it);
}
template <typename octet_iterator>
uint32_t prior(octet_iterator& it)
{
- while (internal::is_trail(*(--it))) ;
+ while (utf8::internal::is_trail(*(--it))) ;
octet_iterator temp = it;
- return next(temp);
+ return utf8::unchecked::next(temp);
}
// Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous)
template <typename octet_iterator>
inline uint32_t previous(octet_iterator& it)
{
- return prior(it);
+ return utf8::unchecked::prior(it);
}
template <typename octet_iterator, typename distance_type>
void advance (octet_iterator& it, distance_type n)
{
for (distance_type i = 0; i < n; ++i)
- next(it);
+ utf8::unchecked::next(it);
}
template <typename octet_iterator>
@@ -122,7 +122,7 @@ namespace utf8
{
typename std::iterator_traits<octet_iterator>::difference_type dist;
for (dist = 0; first < last; ++dist)
- next(first);
+ utf8::unchecked::next(first);
return dist;
}
@@ -130,13 +130,13 @@ namespace utf8
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
{
while (start != end) {
- uint32_t cp = internal::mask16(*start++);
+ uint32_t cp = utf8::internal::mask16(*start++);
// Take care of surrogate pairs first
- if (internal::is_lead_surrogate(cp)) {
- uint32_t trail_surrogate = internal::mask16(*start++);
+ if (utf8::internal::is_lead_surrogate(cp)) {
+ uint32_t trail_surrogate = utf8::internal::mask16(*start++);
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
}
- result = append(cp, result);
+ result = utf8::unchecked::append(cp, result);
}
return result;
}
@@ -145,7 +145,7 @@ namespace utf8
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
{
while (start < end) {
- uint32_t cp = next(start);
+ uint32_t cp = utf8::unchecked::next(start);
if (cp > 0xffff) { //make a surrogate pair
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
@@ -160,7 +160,7 @@ namespace utf8
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
{
while (start != end)
- result = append(*(start++), result);
+ result = utf8::unchecked::append(*(start++), result);
return result;
}
@@ -169,7 +169,7 @@ namespace utf8
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
{
while (start < end)
- (*result++) = next(start);
+ (*result++) = utf8::unchecked::next(start);
return result;
}
@@ -186,7 +186,7 @@ namespace utf8
uint32_t operator * () const
{
octet_iterator temp = it;
- return next(temp);
+ return utf8::unchecked::next(temp);
}
bool operator == (const iterator& rhs) const
{
@@ -198,24 +198,24 @@ namespace utf8
}
iterator& operator ++ ()
{
- std::advance(it, internal::sequence_length(it));
+ ::std::advance(it, utf8::internal::sequence_length(it));
return *this;
}
iterator operator ++ (int)
{
iterator temp = *this;
- std::advance(it, internal::sequence_length(it));
+ ::std::advance(it, utf8::internal::sequence_length(it));
return temp;
}
iterator& operator -- ()
{
- prior(it);
+ utf8::unchecked::prior(it);
return *this;
}
iterator operator -- (int)
{
iterator temp = *this;
- prior(it);
+ utf8::unchecked::prior(it);
return temp;
}
}; // class iterator
diff --git a/dep/zlib/adler32.c b/dep/zlib/adler32.c
index 65ad6a5adc4..a868f073d8a 100644
--- a/dep/zlib/adler32.c
+++ b/dep/zlib/adler32.c
@@ -1,5 +1,5 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2007 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -9,9 +9,9 @@
#define local static
-local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
+local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
-#define BASE 65521UL /* largest prime smaller than 65536 */
+#define BASE 65521 /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
@@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
-/* use NO_DIVIDE if your processor does not do division in hardware */
+/* use NO_DIVIDE if your processor does not do division in hardware --
+ try it both ways to see which is faster */
#ifdef NO_DIVIDE
-# define MOD(a) \
+/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
+ (thank you to John Reiser for pointing this out) */
+# define CHOP(a) \
+ do { \
+ unsigned long tmp = a >> 16; \
+ a &= 0xffffUL; \
+ a += (tmp << 4) - tmp; \
+ } while (0)
+# define MOD28(a) \
do { \
- if (a >= (BASE << 16)) a -= (BASE << 16); \
- if (a >= (BASE << 15)) a -= (BASE << 15); \
- if (a >= (BASE << 14)) a -= (BASE << 14); \
- if (a >= (BASE << 13)) a -= (BASE << 13); \
- if (a >= (BASE << 12)) a -= (BASE << 12); \
- if (a >= (BASE << 11)) a -= (BASE << 11); \
- if (a >= (BASE << 10)) a -= (BASE << 10); \
- if (a >= (BASE << 9)) a -= (BASE << 9); \
- if (a >= (BASE << 8)) a -= (BASE << 8); \
- if (a >= (BASE << 7)) a -= (BASE << 7); \
- if (a >= (BASE << 6)) a -= (BASE << 6); \
- if (a >= (BASE << 5)) a -= (BASE << 5); \
- if (a >= (BASE << 4)) a -= (BASE << 4); \
- if (a >= (BASE << 3)) a -= (BASE << 3); \
- if (a >= (BASE << 2)) a -= (BASE << 2); \
- if (a >= (BASE << 1)) a -= (BASE << 1); \
+ CHOP(a); \
if (a >= BASE) a -= BASE; \
} while (0)
-# define MOD4(a) \
+# define MOD(a) \
do { \
- if (a >= (BASE << 4)) a -= (BASE << 4); \
- if (a >= (BASE << 3)) a -= (BASE << 3); \
- if (a >= (BASE << 2)) a -= (BASE << 2); \
- if (a >= (BASE << 1)) a -= (BASE << 1); \
+ CHOP(a); \
+ MOD28(a); \
+ } while (0)
+# define MOD63(a) \
+ do { /* this assumes a is not negative */ \
+ z_off64_t tmp = a >> 32; \
+ a &= 0xffffffffL; \
+ a += (tmp << 8) - (tmp << 5) + tmp; \
+ tmp = a >> 16; \
+ a &= 0xffffL; \
+ a += (tmp << 4) - tmp; \
+ tmp = a >> 16; \
+ a &= 0xffffL; \
+ a += (tmp << 4) - tmp; \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
-# define MOD4(a) a %= BASE
+# define MOD28(a) a %= BASE
+# define MOD63(a) a %= BASE
#endif
/* ========================================================================= */
@@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
}
if (adler >= BASE)
adler -= BASE;
- MOD4(sum2); /* only added so many BASE's */
+ MOD28(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
@@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
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 */
- rem = (unsigned)(len2 % BASE);
+ MOD63(len2); /* assumes len2 >= 0 */
+ rem = (unsigned)len2;
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
diff --git a/dep/zlib/crc32.c b/dep/zlib/crc32.c
index 91be372d224..979a7190a3c 100644
--- a/dep/zlib/crc32.c
+++ b/dep/zlib/crc32.c
@@ -1,5 +1,5 @@
/* crc32.c -- compute the CRC-32 of a data stream
- * Copyright (C) 1995-2006, 2010 Mark Adler
+ * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
@@ -17,6 +17,8 @@
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
first call get_crc_table() to initialize the tables before allowing more than
one thread to use crc32().
+
+ DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
*/
#ifdef MAKECRCH
@@ -30,31 +32,11 @@
#define local static
-/* Find a four-byte integer type for crc32_little() and crc32_big(). */
-#ifndef NOBYFOUR
-# ifdef STDC /* need ANSI C limits.h to determine sizes */
-# include <limits.h>
-# define BYFOUR
-# if (UINT_MAX == 0xffffffffUL)
- typedef unsigned int u4;
-# else
-# if (ULONG_MAX == 0xffffffffUL)
- typedef unsigned long u4;
-# else
-# if (USHRT_MAX == 0xffffffffUL)
- typedef unsigned short u4;
-# else
-# undef BYFOUR /* can't find a four-byte integer type! */
-# endif
-# endif
-# endif
-# endif /* STDC */
-#endif /* !NOBYFOUR */
-
/* Definitions for doing the crc four data bytes at a time. */
+#if !defined(NOBYFOUR) && defined(Z_U4)
+# define BYFOUR
+#endif
#ifdef BYFOUR
-# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
- (((w)&0xff00)<<8)+(((w)&0xff)<<24))
local unsigned long crc32_little OF((unsigned long,
const unsigned char FAR *, unsigned));
local unsigned long crc32_big OF((unsigned long,
@@ -68,16 +50,16 @@
local unsigned long gf2_matrix_times OF((unsigned long *mat,
unsigned long vec));
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
-local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
+local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
#ifdef DYNAMIC_CRC_TABLE
local volatile int crc_table_empty = 1;
-local unsigned long FAR crc_table[TBLS][256];
+local z_crc_t FAR crc_table[TBLS][256];
local void make_crc_table OF((void));
#ifdef MAKECRCH
- local void write_table OF((FILE *, const unsigned long FAR *));
+ local void write_table OF((FILE *, const z_crc_t FAR *));
#endif /* MAKECRCH */
/*
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
@@ -107,9 +89,9 @@ local void make_crc_table OF((void));
*/
local void make_crc_table()
{
- unsigned long c;
+ z_crc_t c;
int n, k;
- unsigned long poly; /* polynomial exclusive-or pattern */
+ z_crc_t poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static volatile int first = 1; /* flag to limit concurrent making */
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
@@ -121,13 +103,13 @@ local void make_crc_table()
first = 0;
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
- poly = 0UL;
- for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
- poly |= 1UL << (31 - p[n]);
+ poly = 0;
+ for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
+ poly |= (z_crc_t)1 << (31 - p[n]);
/* generate a crc for every 8-bit value */
for (n = 0; n < 256; n++) {
- c = (unsigned long)n;
+ c = (z_crc_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[0][n] = c;
@@ -138,11 +120,11 @@ local void make_crc_table()
and then the byte reversal of those as well as the first table */
for (n = 0; n < 256; n++) {
c = crc_table[0][n];
- crc_table[4][n] = REV(c);
+ crc_table[4][n] = ZSWAP32(c);
for (k = 1; k < 4; k++) {
c = crc_table[0][c & 0xff] ^ (c >> 8);
crc_table[k][n] = c;
- crc_table[k + 4][n] = REV(c);
+ crc_table[k + 4][n] = ZSWAP32(c);
}
}
#endif /* BYFOUR */
@@ -164,7 +146,7 @@ local void make_crc_table()
if (out == NULL) return;
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
- fprintf(out, "local const unsigned long FAR ");
+ fprintf(out, "local const z_crc_t FAR ");
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
write_table(out, crc_table[0]);
# ifdef BYFOUR
@@ -184,12 +166,13 @@ local void make_crc_table()
#ifdef MAKECRCH
local void write_table(out, table)
FILE *out;
- const unsigned long FAR *table;
+ const z_crc_t FAR *table;
{
int n;
for (n = 0; n < 256; n++)
- fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
+ fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
+ (unsigned long)(table[n]),
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
}
#endif /* MAKECRCH */
@@ -204,13 +187,13 @@ local void write_table(out, table)
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
-const unsigned long FAR * ZEXPORT get_crc_table()
+const z_crc_t FAR * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif /* DYNAMIC_CRC_TABLE */
- return (const unsigned long FAR *)crc_table;
+ return (const z_crc_t FAR *)crc_table;
}
/* ========================================================================= */
@@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
#ifdef BYFOUR
if (sizeof(void *) == sizeof(ptrdiff_t)) {
- u4 endian;
+ z_crc_t endian;
endian = 1;
if (*((unsigned char *)(&endian)))
@@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
- register u4 c;
- register const u4 FAR *buf4;
+ register z_crc_t c;
+ register const z_crc_t FAR *buf4;
- c = (u4)crc;
+ c = (z_crc_t)crc;
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
len--;
}
- buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
while (len >= 32) {
DOLIT32;
len -= 32;
@@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
const unsigned char FAR *buf;
unsigned len;
{
- register u4 c;
- register const u4 FAR *buf4;
+ register z_crc_t c;
+ register const z_crc_t FAR *buf4;
- c = REV((u4)crc);
+ c = ZSWAP32((z_crc_t)crc);
c = ~c;
while (len && ((ptrdiff_t)buf & 3)) {
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
len--;
}
- buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
buf4--;
while (len >= 32) {
DOBIG32;
@@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
} while (--len);
c = ~c;
- return (unsigned long)(REV(c));
+ return (unsigned long)(ZSWAP32(c));
}
#endif /* BYFOUR */
diff --git a/dep/zlib/crc32.h b/dep/zlib/crc32.h
index 8053b6117c0..9e0c7781025 100644
--- a/dep/zlib/crc32.h
+++ b/dep/zlib/crc32.h
@@ -2,7 +2,7 @@
* Generated automatically by crc32.c
*/
-local const unsigned long FAR crc_table[TBLS][256] =
+local const z_crc_t FAR crc_table[TBLS][256] =
{
{
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
diff --git a/dep/zlib/deflate.c b/dep/zlib/deflate.c
index 5c4022f3d47..9e4c2cbc8af 100644
--- a/dep/zlib/deflate.c
+++ b/dep/zlib/deflate.c
@@ -1,5 +1,5 @@
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -37,7 +37,7 @@
* REFERENCES
*
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- * Available in http://www.ietf.org/rfc/rfc1951.txt
+ * 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.
@@ -52,7 +52,7 @@
#include "deflate.h"
const char deflate_copyright[] =
- " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
+ " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -155,6 +155,9 @@ local const config configuration_table[10] = {
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
#endif
+/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
+#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
+
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
@@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
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) strm->zfree = zcfree;
+ 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;
@@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
uInt dictLength;
{
deflate_state *s;
- uInt length = dictLength;
- uInt n;
- IPos hash_head = 0;
+ uInt str, n;
+ int wrap;
+ unsigned avail;
+ unsigned char *next;
- if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
- strm->state->wrap == 2 ||
- (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
+ if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
return Z_STREAM_ERROR;
-
s = strm->state;
- if (s->wrap)
- strm->adler = adler32(strm->adler, dictionary, dictLength);
+ wrap = s->wrap;
+ if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
+ return Z_STREAM_ERROR;
- if (length < MIN_MATCH) return Z_OK;
- if (length > s->w_size) {
- length = s->w_size;
- dictionary += dictLength - length; /* use the tail of the dictionary */
+ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
+ if (wrap == 1)
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
+ s->wrap = 0; /* avoid computing Adler-32 in read_buf */
+
+ /* if dictionary would fill window, just replace the history */
+ if (dictLength >= s->w_size) {
+ if (wrap == 0) { /* already empty otherwise */
+ CLEAR_HASH(s);
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->insert = 0;
+ }
+ dictionary += dictLength - s->w_size; /* use the tail */
+ dictLength = s->w_size;
}
- zmemcpy(s->window, dictionary, length);
- s->strstart = length;
- s->block_start = (long)length;
- /* Insert all strings in the hash table (except for the last two bytes).
- * s->lookahead stays null, so s->ins_h will be recomputed at the next
- * call of fill_window.
- */
- s->ins_h = s->window[0];
- UPDATE_HASH(s, s->ins_h, s->window[1]);
- for (n = 0; n <= length - MIN_MATCH; n++) {
- INSERT_STRING(s, n, hash_head);
+ /* insert dictionary into window and hash */
+ avail = strm->avail_in;
+ next = strm->next_in;
+ strm->avail_in = dictLength;
+ strm->next_in = (Bytef *)dictionary;
+ fill_window(s);
+ while (s->lookahead >= MIN_MATCH) {
+ str = s->strstart;
+ n = s->lookahead - (MIN_MATCH-1);
+ do {
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+ s->head[s->ins_h] = (Pos)str;
+ str++;
+ } while (--n);
+ s->strstart = str;
+ s->lookahead = MIN_MATCH-1;
+ fill_window(s);
}
- if (hash_head) hash_head = 0; /* to make compiler happy */
+ s->strstart += s->lookahead;
+ s->block_start = (long)s->strstart;
+ s->insert = s->lookahead;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ strm->next_in = next;
+ strm->avail_in = avail;
+ s->wrap = wrap;
return Z_OK;
}
/* ========================================================================= */
-int ZEXPORT deflateReset (strm)
+int ZEXPORT deflateResetKeep (strm)
z_streamp strm;
{
deflate_state *s;
@@ -380,12 +419,23 @@ int ZEXPORT deflateReset (strm)
s->last_flush = Z_NO_FLUSH;
_tr_init(s);
- lm_init(s);
return Z_OK;
}
/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+ z_streamp strm;
+{
+ int ret;
+
+ ret = deflateResetKeep(strm);
+ if (ret == Z_OK)
+ lm_init(strm->state);
+ return ret;
+}
+
+/* ========================================================================= */
int ZEXPORT deflateSetHeader (strm, head)
z_streamp strm;
gz_headerp head;
@@ -397,14 +447,42 @@ int ZEXPORT deflateSetHeader (strm, head)
}
/* ========================================================================= */
+int ZEXPORT deflatePending (strm, pending, bits)
+ unsigned *pending;
+ int *bits;
+ z_streamp strm;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (pending != Z_NULL)
+ *pending = strm->state->pending;
+ if (bits != Z_NULL)
+ *bits = strm->state->bi_valid;
+ return Z_OK;
+}
+
+/* ========================================================================= */
int ZEXPORT deflatePrime (strm, bits, value)
z_streamp strm;
int bits;
int value;
{
+ deflate_state *s;
+ int put;
+
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
- strm->state->bi_valid = bits;
- strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
+ s = strm->state;
+ if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
+ return Z_BUF_ERROR;
+ do {
+ put = Buf_size - s->bi_valid;
+ if (put > bits)
+ put = bits;
+ s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
+ s->bi_valid += put;
+ _tr_flush_bits(s);
+ value >>= put;
+ bits -= put;
+ } while (bits);
return Z_OK;
}
@@ -562,19 +640,22 @@ local void putShortMSB (s, b)
local void flush_pending(strm)
z_streamp strm;
{
- unsigned len = strm->state->pending;
+ unsigned len;
+ deflate_state *s = strm->state;
+ _tr_flush_bits(s);
+ len = s->pending;
if (len > strm->avail_out) len = strm->avail_out;
if (len == 0) return;
- zmemcpy(strm->next_out, strm->state->pending_out, len);
+ zmemcpy(strm->next_out, s->pending_out, len);
strm->next_out += len;
- strm->state->pending_out += len;
+ s->pending_out += len;
strm->total_out += len;
strm->avail_out -= len;
- strm->state->pending -= len;
- if (strm->state->pending == 0) {
- strm->state->pending_out = strm->state->pending_buf;
+ s->pending -= len;
+ if (s->pending == 0) {
+ s->pending_out = s->pending_buf;
}
}
@@ -801,7 +882,7 @@ int ZEXPORT deflate (strm, flush)
* flushes. For repeated and useless calls with Z_FINISH, we keep
* returning Z_STREAM_END instead of Z_BUF_ERROR.
*/
- } else if (strm->avail_in == 0 && flush <= old_flush &&
+ } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
flush != Z_FINISH) {
ERR_RETURN(strm, Z_BUF_ERROR);
}
@@ -850,6 +931,7 @@ int ZEXPORT deflate (strm, flush)
if (s->lookahead == 0) {
s->strstart = 0;
s->block_start = 0L;
+ s->insert = 0;
}
}
}
@@ -945,12 +1027,12 @@ int ZEXPORT deflateCopy (dest, source)
ss = source->state;
- zmemcpy(dest, source, sizeof(z_stream));
+ zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
if (ds == Z_NULL) return Z_MEM_ERROR;
dest->state = (struct internal_state FAR *) ds;
- zmemcpy(ds, ss, sizeof(deflate_state));
+ zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
ds->strm = dest;
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
@@ -966,8 +1048,8 @@ int ZEXPORT deflateCopy (dest, source)
}
/* following zmemcpy do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
- zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
- zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+ zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
+ zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
@@ -1001,15 +1083,15 @@ local int read_buf(strm, buf, size)
strm->avail_in -= len;
+ zmemcpy(buf, strm->next_in, len);
if (strm->state->wrap == 1) {
- strm->adler = adler32(strm->adler, strm->next_in, len);
+ strm->adler = adler32(strm->adler, buf, len);
}
#ifdef GZIP
else if (strm->state->wrap == 2) {
- strm->adler = crc32(strm->adler, strm->next_in, len);
+ strm->adler = crc32(strm->adler, buf, len);
}
#endif
- zmemcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
@@ -1036,6 +1118,7 @@ local void lm_init (s)
s->strstart = 0;
s->block_start = 0L;
s->lookahead = 0;
+ s->insert = 0;
s->match_length = s->prev_length = MIN_MATCH-1;
s->match_available = 0;
s->ins_h = 0;
@@ -1310,6 +1393,8 @@ local void fill_window(s)
unsigned more; /* Amount of free space at the end of the window. */
uInt wsize = s->w_size;
+ Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+
do {
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
@@ -1362,7 +1447,7 @@ local void fill_window(s)
#endif
more += wsize;
}
- if (s->strm->avail_in == 0) return;
+ if (s->strm->avail_in == 0) break;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
@@ -1381,12 +1466,24 @@ local void fill_window(s)
s->lookahead += n;
/* Initialize the hash value now that we have some input: */
- if (s->lookahead >= MIN_MATCH) {
- s->ins_h = s->window[s->strstart];
- UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+ if (s->lookahead + s->insert >= MIN_MATCH) {
+ uInt str = s->strstart - s->insert;
+ s->ins_h = s->window[str];
+ UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
+ while (s->insert) {
+ UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
+#ifndef FASTEST
+ s->prev[str & s->w_mask] = s->head[s->ins_h];
+#endif
+ s->head[s->ins_h] = (Pos)str;
+ str++;
+ s->insert--;
+ if (s->lookahead + s->insert < MIN_MATCH)
+ break;
+ }
}
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
* but this is not important since only literal bytes will be emitted.
@@ -1427,6 +1524,9 @@ local void fill_window(s)
s->high_water += init;
}
}
+
+ Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
+ "not enough room for search");
}
/* ===========================================================================
@@ -1506,8 +1606,14 @@ local block_state deflate_stored(s, flush)
FLUSH_BLOCK(s, 0);
}
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if ((long)s->strstart > s->block_start)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
/* ===========================================================================
@@ -1603,8 +1709,14 @@ local block_state deflate_fast(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
#ifndef FASTEST
@@ -1728,8 +1840,14 @@ local block_state deflate_slow(s, flush)
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0;
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
#endif /* FASTEST */
@@ -1749,11 +1867,11 @@ local block_state deflate_rle(s, flush)
for (;;) {
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
- * for the longest encodable run.
+ * for the longest run, plus one for the unrolled loop.
*/
- if (s->lookahead < MAX_MATCH) {
+ if (s->lookahead <= MAX_MATCH) {
fill_window(s);
- if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+ if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
return need_more;
}
if (s->lookahead == 0) break; /* flush the current block */
@@ -1776,6 +1894,7 @@ local block_state deflate_rle(s, flush)
if (s->match_length > s->lookahead)
s->match_length = s->lookahead;
}
+ Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
}
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
@@ -1796,8 +1915,14 @@ local block_state deflate_rle(s, flush)
}
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
/* ===========================================================================
@@ -1829,6 +1954,12 @@ local block_state deflate_huff(s, flush)
s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0);
}
- FLUSH_BLOCK(s, flush == Z_FINISH);
- return flush == Z_FINISH ? finish_done : block_done;
+ s->insert = 0;
+ if (flush == Z_FINISH) {
+ FLUSH_BLOCK(s, 1);
+ return finish_done;
+ }
+ if (s->last_lit)
+ FLUSH_BLOCK(s, 0);
+ return block_done;
}
diff --git a/dep/zlib/deflate.h b/dep/zlib/deflate.h
index cbf0d1ea5d9..fbac44d908e 100644
--- a/dep/zlib/deflate.h
+++ b/dep/zlib/deflate.h
@@ -1,5 +1,5 @@
/* deflate.h -- internal compression state
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -48,6 +48,9 @@
#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */
+#define Buf_size 16
+/* size of bit buffer in bi_buf */
+
#define INIT_STATE 42
#define EXTRA_STATE 69
#define NAME_STATE 73
@@ -188,7 +191,7 @@ typedef struct internal_state {
int nice_match; /* Stop searching when current match exceeds this */
/* used by trees.c: */
- /* Didn't use ct_data typedef below to supress compiler warning */
+ /* Didn't use ct_data typedef below to suppress compiler warning */
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
@@ -244,7 +247,7 @@ typedef struct internal_state {
ulg opt_len; /* bit length of current block with optimal trees */
ulg static_len; /* bit length of current block with static trees */
uInt matches; /* number of string matches in current block */
- int last_eob_len; /* bit length of EOB code for last block */
+ uInt insert; /* bytes at end of window left to insert */
#ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
@@ -294,6 +297,7 @@ void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
+void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
ulg stored_len, int last));
diff --git a/dep/zlib/gzguts.h b/dep/zlib/gzguts.h
index 0f8fb79f87d..ee3f281aa57 100644
--- a/dep/zlib/gzguts.h
+++ b/dep/zlib/gzguts.h
@@ -1,5 +1,5 @@
/* gzguts.h -- zlib internal header definitions for gz* operations
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -12,7 +12,7 @@
# endif
#endif
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
@@ -27,13 +27,65 @@
#endif
#include <fcntl.h>
+#ifdef _WIN32
+# include <stddef.h>
+#endif
+
+#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
+# include <io.h>
+#endif
+
#ifdef NO_DEFLATE /* for compatibility with old definition */
# define NO_GZCOMPRESS
#endif
-#ifdef _MSC_VER
-# include <io.h>
-# define vsnprintf _vsnprintf
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#if defined(__CYGWIN__)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+
+#ifndef HAVE_VSNPRINTF
+# ifdef MSDOS
+/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+ but for now we just assume it doesn't. */
+# define NO_vsnprintf
+# endif
+# ifdef __TURBOC__
+# define NO_vsnprintf
+# endif
+# ifdef WIN32
+/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+# if !defined(vsnprintf) && !defined(NO_vsnprintf)
+# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
+# define vsnprintf _vsnprintf
+# endif
+# endif
+# endif
+# ifdef __SASC
+# define NO_vsnprintf
+# endif
+# ifdef VMS
+# define NO_vsnprintf
+# endif
+# ifdef __OS400__
+# define NO_vsnprintf
+# endif
+# ifdef __MVS__
+# define NO_vsnprintf
+# endif
#endif
#ifndef local
@@ -52,7 +104,7 @@
# include <windows.h>
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else
-# ifdef STDC
+# ifndef NO_STRERROR
# include <errno.h>
# define zstrerror() strerror(errno)
# else
@@ -68,6 +120,13 @@
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
#endif
+/* default memLevel */
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+
/* default i/o buffer size -- double this for output when reading */
#define GZBUFSIZE 8192
@@ -84,23 +143,25 @@
/* internal gzip file state data structure */
typedef struct {
+ /* exposed contents for gzgetc() macro */
+ struct gzFile_s x; /* "x" for exposed */
+ /* x.have: number of bytes available at x.next */
+ /* x.next: next output data to deliver or write */
+ /* x.pos: current position in uncompressed data */
/* used for both reading and writing */
int mode; /* see gzip modes above */
int fd; /* file descriptor */
char *path; /* path or fd for error messages */
- z_off64_t pos; /* current position in uncompressed data */
unsigned size; /* buffer size, zero if not allocated yet */
unsigned want; /* requested buffer size, default is GZBUFSIZE */
unsigned char *in; /* input buffer */
unsigned char *out; /* output buffer (double-sized when reading) */
- unsigned char *next; /* next output data to deliver or write */
+ int direct; /* 0 if processing gzip, 1 if transparent */
/* just for reading */
- unsigned have; /* amount of output data unused at next */
- int eof; /* true if end of input file reached */
- z_off64_t start; /* where the gzip data started, for rewinding */
- z_off64_t raw; /* where the raw data started, for seeking */
int how; /* 0: get header, 1: copy, 2: decompress */
- int direct; /* true if last read direct, false if gzip */
+ z_off64_t start; /* where the gzip data started, for rewinding */
+ int eof; /* true if end of input file reached */
+ int past; /* true if read requested past end */
/* just for writing */
int level; /* compression level */
int strategy; /* compression strategy */
diff --git a/dep/zlib/gzlib.c b/dep/zlib/gzlib.c
index 603e60ed544..ca55c6ea926 100644
--- a/dep/zlib/gzlib.c
+++ b/dep/zlib/gzlib.c
@@ -1,19 +1,23 @@
/* gzlib.c -- zlib functions common to reading and writing gzip files
- * Copyright (C) 2004, 2010 Mark Adler
+ * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "gzguts.h"
+#if defined(_WIN32) && !defined(__BORLANDC__)
+# define LSEEK _lseeki64
+#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64
#else
# define LSEEK lseek
#endif
+#endif
/* Local functions */
local void gz_reset OF((gz_statep));
-local gzFile gz_open OF((const char *, int, const char *));
+local gzFile gz_open OF((const void *, int, const char *));
#if defined UNDER_CE
@@ -71,25 +75,37 @@ char ZLIB_INTERNAL *gz_strwinerror (error)
local void gz_reset(state)
gz_statep state;
{
+ state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */
- state->have = 0; /* no output data available */
state->eof = 0; /* not at end of file */
+ state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */
- state->direct = 1; /* default for empty file */
}
state->seek = 0; /* no seek request pending */
gz_error(state, Z_OK, NULL); /* clear error */
- state->pos = 0; /* no uncompressed data yet */
+ state->x.pos = 0; /* no uncompressed data yet */
state->strm.avail_in = 0; /* no input data yet */
}
/* Open a gzip file either by name or file descriptor. */
local gzFile gz_open(path, fd, mode)
- const char *path;
+ const void *path;
int fd;
const char *mode;
{
gz_statep state;
+ size_t len;
+ int oflag;
+#ifdef O_CLOEXEC
+ int cloexec = 0;
+#endif
+#ifdef O_EXCL
+ int exclusive = 0;
+#endif
+
+ /* check input */
+ if (path == NULL)
+ return NULL;
/* allocate gzFile structure to return */
state = malloc(sizeof(gz_state));
@@ -103,6 +119,7 @@ local gzFile gz_open(path, fd, mode)
state->mode = GZ_NONE;
state->level = Z_DEFAULT_COMPRESSION;
state->strategy = Z_DEFAULT_STRATEGY;
+ state->direct = 0;
while (*mode) {
if (*mode >= '0' && *mode <= '9')
state->level = *mode - '0';
@@ -124,6 +141,16 @@ local gzFile gz_open(path, fd, mode)
return NULL;
case 'b': /* ignore -- will request binary anyway */
break;
+#ifdef O_CLOEXEC
+ case 'e':
+ cloexec = 1;
+ break;
+#endif
+#ifdef O_EXCL
+ case 'x':
+ exclusive = 1;
+ break;
+#endif
case 'f':
state->strategy = Z_FILTERED;
break;
@@ -135,6 +162,8 @@ local gzFile gz_open(path, fd, mode)
break;
case 'F':
state->strategy = Z_FIXED;
+ case 'T':
+ state->direct = 1;
default: /* could consider as an error, but just ignore */
;
}
@@ -147,30 +176,67 @@ local gzFile gz_open(path, fd, mode)
return NULL;
}
+ /* can't force transparent read */
+ if (state->mode == GZ_READ) {
+ if (state->direct) {
+ free(state);
+ return NULL;
+ }
+ state->direct = 1; /* for empty file */
+ }
+
/* save the path name for error messages */
- state->path = malloc(strlen(path) + 1);
+#ifdef _WIN32
+ if (fd == -2) {
+ len = wcstombs(NULL, path, 0);
+ if (len == (size_t)-1)
+ len = 0;
+ }
+ else
+#endif
+ len = strlen(path);
+ state->path = malloc(len + 1);
if (state->path == NULL) {
free(state);
return NULL;
}
- strcpy(state->path, path);
+#ifdef _WIN32
+ if (fd == -2)
+ if (len)
+ wcstombs(state->path, path, len + 1);
+ else
+ *(state->path) = 0;
+ else
+#endif
+ strcpy(state->path, path);
- /* open the file with the appropriate mode (or just use fd) */
- state->fd = fd != -1 ? fd :
- open(path,
+ /* compute the flags for open() */
+ oflag =
#ifdef O_LARGEFILE
- O_LARGEFILE |
+ O_LARGEFILE |
#endif
#ifdef O_BINARY
- O_BINARY |
+ O_BINARY |
+#endif
+#ifdef O_CLOEXEC
+ (cloexec ? O_CLOEXEC : 0) |
#endif
- (state->mode == GZ_READ ?
- O_RDONLY :
- (O_WRONLY | O_CREAT | (
- state->mode == GZ_WRITE ?
- O_TRUNC :
- O_APPEND))),
- 0666);
+ (state->mode == GZ_READ ?
+ O_RDONLY :
+ (O_WRONLY | O_CREAT |
+#ifdef O_EXCL
+ (exclusive ? O_EXCL : 0) |
+#endif
+ (state->mode == GZ_WRITE ?
+ O_TRUNC :
+ O_APPEND)));
+
+ /* open the file with the appropriate flags (or just use fd) */
+ state->fd = fd > -1 ? fd : (
+#ifdef _WIN32
+ fd == -2 ? _wopen(path, oflag, 0666) :
+#endif
+ open(path, oflag, 0666));
if (state->fd == -1) {
free(state->path);
free(state);
@@ -225,6 +291,16 @@ gzFile ZEXPORT gzdopen(fd, mode)
}
/* -- see zlib.h -- */
+#ifdef _WIN32
+gzFile ZEXPORT gzopen_w(path, mode)
+ const wchar_t *path;
+ const char *mode;
+{
+ return gz_open(path, -2, mode);
+}
+#endif
+
+/* -- see zlib.h -- */
int ZEXPORT gzbuffer(file, size)
gzFile file;
unsigned size;
@@ -243,8 +319,8 @@ int ZEXPORT gzbuffer(file, size)
return -1;
/* check and set requested size */
- if (size == 0)
- return -1;
+ if (size < 2)
+ size = 2; /* need two bytes to check magic header */
state->want = size;
return 0;
}
@@ -261,7 +337,8 @@ int ZEXPORT gzrewind(file)
state = (gz_statep)file;
/* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* back up and start over */
@@ -289,7 +366,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
return -1;
/* check that there's no error */
- if (state->err != Z_OK)
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
/* can only seek from start or relative to current position */
@@ -298,31 +375,32 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* normalize offset to a SEEK_CUR specification */
if (whence == SEEK_SET)
- offset -= state->pos;
+ offset -= state->x.pos;
else if (state->seek)
offset += state->skip;
state->seek = 0;
/* if within raw area while reading, just go there */
if (state->mode == GZ_READ && state->how == COPY &&
- state->pos + offset >= state->raw) {
- ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
+ state->x.pos + offset >= 0) {
+ ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
if (ret == -1)
return -1;
- state->have = 0;
+ state->x.have = 0;
state->eof = 0;
+ state->past = 0;
state->seek = 0;
gz_error(state, Z_OK, NULL);
state->strm.avail_in = 0;
- state->pos += offset;
- return state->pos;
+ state->x.pos += offset;
+ return state->x.pos;
}
/* calculate skip amount, rewinding if needed for back seek when reading */
if (offset < 0) {
if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1;
- offset += state->pos;
+ offset += state->x.pos;
if (offset < 0) /* before start of file! */
return -1;
if (gzrewind(file) == -1) /* rewind, then skip to offset */
@@ -331,11 +409,11 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
/* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) {
- n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
- (unsigned)offset : state->have;
- state->have -= n;
- state->next += n;
- state->pos += n;
+ n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
+ (unsigned)offset : state->x.have;
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
offset -= n;
}
@@ -344,7 +422,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
state->seek = 1;
state->skip = offset;
}
- return state->pos + offset;
+ return state->x.pos + offset;
}
/* -- see zlib.h -- */
@@ -373,7 +451,7 @@ z_off64_t ZEXPORT gztell64(file)
return -1;
/* return position */
- return state->pos + (state->seek ? state->skip : 0);
+ return state->x.pos + (state->seek ? state->skip : 0);
}
/* -- see zlib.h -- */
@@ -433,8 +511,7 @@ int ZEXPORT gzeof(file)
return 0;
/* return end-of-file state */
- return state->mode == GZ_READ ?
- (state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
+ return state->mode == GZ_READ ? state->past : 0;
}
/* -- see zlib.h -- */
@@ -471,8 +548,10 @@ void ZEXPORT gzclearerr(file)
return;
/* clear error and end-of-file */
- if (state->mode == GZ_READ)
+ if (state->mode == GZ_READ) {
state->eof = 0;
+ state->past = 0;
+ }
gz_error(state, Z_OK, NULL);
}
@@ -494,6 +573,10 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
state->msg = NULL;
}
+ /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
+ if (err != Z_OK && err != Z_BUF_ERROR)
+ state->x.have = 0;
+
/* set error code, and if no message, then done */
state->err = err;
if (msg == NULL)
diff --git a/dep/zlib/gzread.c b/dep/zlib/gzread.c
index 548201ab009..3493d34d4ea 100644
--- a/dep/zlib/gzread.c
+++ b/dep/zlib/gzread.c
@@ -1,5 +1,5 @@
/* gzread.c -- zlib functions for reading gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -8,10 +8,9 @@
/* Local functions */
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *));
local int gz_avail OF((gz_statep));
-local int gz_next4 OF((gz_statep, unsigned long *));
-local int gz_head OF((gz_statep));
+local int gz_look OF((gz_statep));
local int gz_decomp OF((gz_statep));
-local int gz_make OF((gz_statep));
+local int gz_fetch OF((gz_statep));
local int gz_skip OF((gz_statep, z_off64_t));
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
@@ -46,67 +45,47 @@ local int gz_load(state, buf, len, have)
error, 0 otherwise. Note that the eof flag is set when the end of the input
file is reached, even though there may be unused data in the buffer. Once
that data has been used, no more attempts will be made to read the file.
- gz_avail() assumes that strm->avail_in == 0. */
+ If strm->avail_in != 0, then the current data is moved to the beginning of
+ the input buffer, and then the remainder of the buffer is loaded with the
+ available data from the input file. */
local int gz_avail(state)
gz_statep state;
{
+ unsigned got;
z_streamp strm = &(state->strm);
- if (state->err != Z_OK)
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR)
return -1;
if (state->eof == 0) {
- if (gz_load(state, state->in, state->size,
- (unsigned *)&(strm->avail_in)) == -1)
+ if (strm->avail_in) { /* copy what's there to the start */
+ unsigned char *p = state->in, *q = strm->next_in;
+ unsigned n = strm->avail_in;
+ do {
+ *p++ = *q++;
+ } while (--n);
+ }
+ if (gz_load(state, state->in + strm->avail_in,
+ state->size - strm->avail_in, &got) == -1)
return -1;
+ strm->avail_in += got;
strm->next_in = state->in;
}
return 0;
}
-/* Get next byte from input, or -1 if end or error. */
-#define NEXT() ((strm->avail_in == 0 && gz_avail(state) == -1) ? -1 : \
- (strm->avail_in == 0 ? -1 : \
- (strm->avail_in--, *(strm->next_in)++)))
-
-/* Get a four-byte little-endian integer and return 0 on success and the value
- in *ret. Otherwise -1 is returned and *ret is not modified. */
-local int gz_next4(state, ret)
- gz_statep state;
- unsigned long *ret;
-{
- int ch;
- unsigned long val;
- z_streamp strm = &(state->strm);
-
- val = NEXT();
- val += (unsigned)NEXT() << 8;
- val += (unsigned long)NEXT() << 16;
- ch = NEXT();
- if (ch == -1)
- return -1;
- val += (unsigned long)ch << 24;
- *ret = val;
- return 0;
-}
-
-/* Look for gzip header, set up for inflate or copy. state->have must be zero.
+/* Look for gzip header, set up for inflate or copy. state->x.have must be 0.
If this is the first time in, allocate required memory. state->how will be
left unchanged if there is no more input data available, will be set to COPY
if there is no gzip header and direct copying will be performed, or it will
- be set to GZIP for decompression, and the gzip header will be skipped so
- that the next available input data is the raw deflate stream. If direct
- copying, then leftover input data from the input buffer will be copied to
- the output buffer. In that case, all further file reads will be directly to
- either the output buffer or a user buffer. If decompressing, the inflate
- state and the check value will be initialized. gz_head() will return 0 on
- success or -1 on failure. Failures may include read errors or gzip header
- errors. */
-local int gz_head(state)
+ be set to GZIP for decompression. If direct copying, then leftover input
+ data from the input buffer will be copied to the output buffer. In that
+ case, all further file reads will be directly to either the output buffer or
+ a user buffer. If decompressing, the inflate state will be initialized.
+ gz_look() will return 0 on success or -1 on failure. */
+local int gz_look(state)
gz_statep state;
{
z_streamp strm = &(state->strm);
- int flags;
- unsigned len;
/* allocate read buffers and inflate memory */
if (state->size == 0) {
@@ -129,7 +108,7 @@ local int gz_head(state)
state->strm.opaque = Z_NULL;
state->strm.avail_in = 0;
state->strm.next_in = Z_NULL;
- if (inflateInit2(&(state->strm), -15) != Z_OK) { /* raw inflate */
+ if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
free(state->out);
free(state->in);
state->size = 0;
@@ -138,83 +117,45 @@ local int gz_head(state)
}
}
- /* get some data in the input buffer */
- if (strm->avail_in == 0) {
+ /* get at least the magic bytes in the input buffer */
+ if (strm->avail_in < 2) {
if (gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0)
return 0;
}
- /* look for the gzip magic header bytes 31 and 139 */
- if (strm->next_in[0] == 31) {
- strm->avail_in--;
- strm->next_in++;
- if (strm->avail_in == 0 && gz_avail(state) == -1)
- return -1;
- if (strm->avail_in && strm->next_in[0] == 139) {
- /* we have a gzip header, woo hoo! */
- strm->avail_in--;
- strm->next_in++;
-
- /* skip rest of header */
- if (NEXT() != 8) { /* compression method */
- gz_error(state, Z_DATA_ERROR, "unknown compression method");
- return -1;
- }
- flags = NEXT();
- if (flags & 0xe0) { /* reserved flag bits */
- gz_error(state, Z_DATA_ERROR, "unknown header flags set");
- return -1;
- }
- NEXT(); /* modification time */
- NEXT();
- NEXT();
- NEXT();
- NEXT(); /* extra flags */
- NEXT(); /* operating system */
- if (flags & 4) { /* extra field */
- len = (unsigned)NEXT();
- len += (unsigned)NEXT() << 8;
- while (len--)
- if (NEXT() < 0)
- break;
- }
- if (flags & 8) /* file name */
- while (NEXT() > 0)
- ;
- if (flags & 16) /* comment */
- while (NEXT() > 0)
- ;
- if (flags & 2) { /* header crc */
- NEXT();
- NEXT();
- }
- /* an unexpected end of file is not checked for here -- it will be
- noticed on the first request for uncompressed data */
-
- /* set up for decompression */
- inflateReset(strm);
- strm->adler = crc32(0L, Z_NULL, 0);
- state->how = GZIP;
- state->direct = 0;
- return 0;
- }
- else {
- /* not a gzip file -- save first byte (31) and fall to raw i/o */
- state->out[0] = 31;
- state->have = 1;
- }
+ /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
+ a logical dilemma here when considering the case of a partially written
+ gzip file, to wit, if a single 31 byte is written, then we cannot tell
+ whether this is a single-byte file, or just a partially written gzip
+ file -- for here we assume that if a gzip file is being written, then
+ the header will be written in a single operation, so that reading a
+ single byte is sufficient indication that it is not a gzip file) */
+ if (strm->avail_in > 1 &&
+ strm->next_in[0] == 31 && strm->next_in[1] == 139) {
+ inflateReset(strm);
+ state->how = GZIP;
+ state->direct = 0;
+ return 0;
+ }
+
+ /* no gzip header -- if we were decoding gzip before, then this is trailing
+ garbage. Ignore the trailing garbage and finish. */
+ if (state->direct == 0) {
+ strm->avail_in = 0;
+ state->eof = 1;
+ state->x.have = 0;
+ return 0;
}
- /* doing raw i/o, save start of raw data for seeking, copy any leftover
- input to output -- this assumes that the output buffer is larger than
- the input buffer, which also assures space for gzungetc() */
- state->raw = state->pos;
- state->next = state->out;
+ /* doing raw i/o, copy any leftover input to output -- this assumes that
+ the output buffer is larger than the input buffer, which also assures
+ space for gzungetc() */
+ state->x.next = state->out;
if (strm->avail_in) {
- memcpy(state->next + state->have, strm->next_in, strm->avail_in);
- state->have += strm->avail_in;
+ memcpy(state->x.next, strm->next_in, strm->avail_in);
+ state->x.have = strm->avail_in;
strm->avail_in = 0;
}
state->how = COPY;
@@ -223,19 +164,15 @@ local int gz_head(state)
}
/* Decompress from input to the provided next_out and avail_out in the state.
- If the end of the compressed data is reached, then verify the gzip trailer
- check value and length (modulo 2^32). state->have and state->next are set
- to point to the just decompressed data, and the crc is updated. If the
- trailer is verified, state->how is reset to LOOK to look for the next gzip
- stream or raw data, once state->have is depleted. Returns 0 on success, -1
- on failure. Failures may include invalid compressed data or a failed gzip
- trailer verification. */
+ On return, state->x.have and state->x.next point to the just decompressed
+ data. If the gzip stream completes, state->how is reset to LOOK to look for
+ the next gzip stream or raw data, once state->x.have is depleted. Returns 0
+ on success, -1 on failure. */
local int gz_decomp(state)
gz_statep state;
{
- int ret;
+ int ret = Z_OK;
unsigned had;
- unsigned long crc, len;
z_streamp strm = &(state->strm);
/* fill output buffer up to end of deflate stream */
@@ -245,15 +182,15 @@ local int gz_decomp(state)
if (strm->avail_in == 0 && gz_avail(state) == -1)
return -1;
if (strm->avail_in == 0) {
- gz_error(state, Z_DATA_ERROR, "unexpected end of file");
- return -1;
+ gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+ break;
}
/* decompress and handle errors */
ret = inflate(strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
gz_error(state, Z_STREAM_ERROR,
- "internal error: inflate stream corrupt");
+ "internal error: inflate stream corrupt");
return -1;
}
if (ret == Z_MEM_ERROR) {
@@ -262,67 +199,55 @@ local int gz_decomp(state)
}
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
gz_error(state, Z_DATA_ERROR,
- strm->msg == NULL ? "compressed data error" : strm->msg);
+ strm->msg == NULL ? "compressed data error" : strm->msg);
return -1;
}
} while (strm->avail_out && ret != Z_STREAM_END);
- /* update available output and crc check value */
- state->have = had - strm->avail_out;
- state->next = strm->next_out - state->have;
- strm->adler = crc32(strm->adler, state->next, state->have);
+ /* update available output */
+ state->x.have = had - strm->avail_out;
+ state->x.next = strm->next_out - state->x.have;
- /* check gzip trailer if at end of deflate stream */
- if (ret == Z_STREAM_END) {
- if (gz_next4(state, &crc) == -1 || gz_next4(state, &len) == -1) {
- gz_error(state, Z_DATA_ERROR, "unexpected end of file");
- return -1;
- }
- if (crc != strm->adler) {
- gz_error(state, Z_DATA_ERROR, "incorrect data check");
- return -1;
- }
- if (len != (strm->total_out & 0xffffffffL)) {
- gz_error(state, Z_DATA_ERROR, "incorrect length check");
- return -1;
- }
- state->how = LOOK; /* ready for next stream, once have is 0 (leave
- state->direct unchanged to remember how) */
- }
+ /* if the gzip stream completed successfully, look for another */
+ if (ret == Z_STREAM_END)
+ state->how = LOOK;
/* good decompression */
return 0;
}
-/* Make data and put in the output buffer. Assumes that state->have == 0.
+/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
Data is either copied from the input file or decompressed from the input
file depending on state->how. If state->how is LOOK, then a gzip header is
- looked for (and skipped if found) to determine wither to copy or decompress.
- Returns -1 on error, otherwise 0. gz_make() will leave state->have as COPY
- or GZIP unless the end of the input file has been reached and all data has
- been processed. */
-local int gz_make(state)
+ looked for to determine whether to copy or decompress. Returns -1 on error,
+ otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
+ end of the input file has been reached and all data has been processed. */
+local int gz_fetch(state)
gz_statep state;
{
z_streamp strm = &(state->strm);
- if (state->how == LOOK) { /* look for gzip header */
- if (gz_head(state) == -1)
- return -1;
- if (state->have) /* got some data from gz_head() */
+ do {
+ switch(state->how) {
+ case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
+ if (gz_look(state) == -1)
+ return -1;
+ if (state->how == LOOK)
+ return 0;
+ break;
+ case COPY: /* -> COPY */
+ if (gz_load(state, state->out, state->size << 1, &(state->x.have))
+ == -1)
+ return -1;
+ state->x.next = state->out;
return 0;
- }
- if (state->how == COPY) { /* straight copy */
- if (gz_load(state, state->out, state->size << 1, &(state->have)) == -1)
- return -1;
- state->next = state->out;
- }
- else if (state->how == GZIP) { /* decompress */
- strm->avail_out = state->size << 1;
- strm->next_out = state->out;
- if (gz_decomp(state) == -1)
- return -1;
- }
+ case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */
+ strm->avail_out = state->size << 1;
+ strm->next_out = state->out;
+ if (gz_decomp(state) == -1)
+ return -1;
+ }
+ } while (state->x.have == 0 && (!state->eof || strm->avail_in));
return 0;
}
@@ -336,12 +261,12 @@ local int gz_skip(state, len)
/* skip over len bytes or reach end-of-file, whichever comes first */
while (len)
/* skip over whatever is in output buffer */
- if (state->have) {
- n = GT_OFF(state->have) || (z_off64_t)state->have > len ?
- (unsigned)len : state->have;
- state->have -= n;
- state->next += n;
- state->pos += n;
+ if (state->x.have) {
+ n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ?
+ (unsigned)len : state->x.have;
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
len -= n;
}
@@ -352,7 +277,7 @@ local int gz_skip(state, len)
/* need more data to skip -- load up output buffer */
else {
/* get more output, looking for header if required */
- if (gz_make(state) == -1)
+ if (gz_fetch(state) == -1)
return -1;
}
return 0;
@@ -374,14 +299,15 @@ int ZEXPORT gzread(file, buf, len)
state = (gz_statep)file;
strm = &(state->strm);
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
- gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+ gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return -1;
}
@@ -400,24 +326,26 @@ int ZEXPORT gzread(file, buf, len)
got = 0;
do {
/* first just try copying data from the output buffer */
- if (state->have) {
- n = state->have > len ? len : state->have;
- memcpy(buf, state->next, n);
- state->next += n;
- state->have -= n;
+ if (state->x.have) {
+ n = state->x.have > len ? len : state->x.have;
+ memcpy(buf, state->x.next, n);
+ state->x.next += n;
+ state->x.have -= n;
}
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && strm->avail_in == 0)
+ else if (state->eof && strm->avail_in == 0) {
+ state->past = 1; /* tried to read past end */
break;
+ }
/* need output data -- for small len or new stream load up our output
buffer */
else if (state->how == LOOK || len < (state->size << 1)) {
/* get more output, looking for header if required */
- if (gz_make(state) == -1)
+ if (gz_fetch(state) == -1)
return -1;
- continue; /* no progress yet -- go back to memcpy() above */
+ continue; /* no progress yet -- go back to copy above */
/* the copy above assures that we will leave with space in the
output buffer, allowing at least one gzungetc() to succeed */
}
@@ -434,15 +362,15 @@ int ZEXPORT gzread(file, buf, len)
strm->next_out = buf;
if (gz_decomp(state) == -1)
return -1;
- n = state->have;
- state->have = 0;
+ n = state->x.have;
+ state->x.have = 0;
}
/* update progress */
len -= n;
buf = (char *)buf + n;
got += n;
- state->pos += n;
+ state->x.pos += n;
} while (len);
/* return number of bytes read into user buffer (will fit in int) */
@@ -450,6 +378,7 @@ int ZEXPORT gzread(file, buf, len)
}
/* -- see zlib.h -- */
+#undef gzgetc
int ZEXPORT gzgetc(file)
gzFile file;
{
@@ -462,15 +391,16 @@ int ZEXPORT gzgetc(file)
return -1;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* try output buffer (no need to check for skip request) */
- if (state->have) {
- state->have--;
- state->pos++;
- return *(state->next)++;
+ if (state->x.have) {
+ state->x.have--;
+ state->x.pos++;
+ return *(state->x.next)++;
}
/* nothing there -- try gzread() */
@@ -478,6 +408,12 @@ int ZEXPORT gzgetc(file)
return ret < 1 ? -1 : buf[0];
}
+int ZEXPORT gzgetc_(file)
+gzFile file;
+{
+ return gzgetc(file);
+}
+
/* -- see zlib.h -- */
int ZEXPORT gzungetc(c, file)
int c;
@@ -490,8 +426,9 @@ int ZEXPORT gzungetc(c, file)
return -1;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return -1;
/* process a skip request */
@@ -506,32 +443,34 @@ int ZEXPORT gzungetc(c, file)
return -1;
/* if output buffer empty, put byte at end (allows more pushing) */
- if (state->have == 0) {
- state->have = 1;
- state->next = state->out + (state->size << 1) - 1;
- state->next[0] = c;
- state->pos--;
+ if (state->x.have == 0) {
+ state->x.have = 1;
+ state->x.next = state->out + (state->size << 1) - 1;
+ state->x.next[0] = c;
+ state->x.pos--;
+ state->past = 0;
return c;
}
/* if no room, give up (must have already done a gzungetc()) */
- if (state->have == (state->size << 1)) {
- gz_error(state, Z_BUF_ERROR, "out of room to push characters");
+ if (state->x.have == (state->size << 1)) {
+ gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1;
}
/* slide output data if needed and insert byte before existing data */
- if (state->next == state->out) {
- unsigned char *src = state->out + state->have;
+ if (state->x.next == state->out) {
+ unsigned char *src = state->out + state->x.have;
unsigned char *dest = state->out + (state->size << 1);
while (src > state->out)
*--dest = *--src;
- state->next = dest;
+ state->x.next = dest;
}
- state->have++;
- state->next--;
- state->next[0] = c;
- state->pos--;
+ state->x.have++;
+ state->x.next--;
+ state->x.next[0] = c;
+ state->x.pos--;
+ state->past = 0;
return c;
}
@@ -551,8 +490,9 @@ char * ZEXPORT gzgets(file, buf, len)
return NULL;
state = (gz_statep)file;
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ || state->err != Z_OK)
+ /* check that we're reading and that there's no (serious) error */
+ if (state->mode != GZ_READ ||
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
return NULL;
/* process a skip request */
@@ -569,32 +509,31 @@ char * ZEXPORT gzgets(file, buf, len)
left = (unsigned)len - 1;
if (left) do {
/* assure that something is in the output buffer */
- if (state->have == 0) {
- if (gz_make(state) == -1)
- return NULL; /* error */
- if (state->have == 0) { /* end of file */
- if (buf == str) /* got bupkus */
- return NULL;
- break; /* got something -- return it */
- }
+ if (state->x.have == 0 && gz_fetch(state) == -1)
+ return NULL; /* error */
+ if (state->x.have == 0) { /* end of file */
+ state->past = 1; /* read past end */
+ break; /* return what we have */
}
/* look for end-of-line in current output buffer */
- n = state->have > left ? left : state->have;
- eol = memchr(state->next, '\n', n);
+ n = state->x.have > left ? left : state->x.have;
+ eol = memchr(state->x.next, '\n', n);
if (eol != NULL)
- n = (unsigned)(eol - state->next) + 1;
+ n = (unsigned)(eol - state->x.next) + 1;
/* copy through end-of-line, or remainder if not found */
- memcpy(buf, state->next, n);
- state->have -= n;
- state->next += n;
- state->pos += n;
+ memcpy(buf, state->x.next, n);
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
left -= n;
buf += n;
} while (left && eol == NULL);
- /* found end-of-line or out of space -- terminate string and return it */
+ /* return terminated string, or if nothing, end of file */
+ if (buf == str)
+ return NULL;
buf[0] = 0;
return str;
}
@@ -610,16 +549,12 @@ int ZEXPORT gzdirect(file)
return 0;
state = (gz_statep)file;
- /* check that we're reading */
- if (state->mode != GZ_READ)
- return 0;
-
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
- if (state->how == LOOK && state->have == 0)
- (void)gz_head(state);
+ if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+ (void)gz_look(state);
- /* return 1 if reading direct, 0 if decompressing a gzip stream */
+ /* return 1 if transparent, 0 if processing a gzip stream */
return state->direct;
}
@@ -627,7 +562,7 @@ int ZEXPORT gzdirect(file)
int ZEXPORT gzclose_r(file)
gzFile file;
{
- int ret;
+ int ret, err;
gz_statep state;
/* get internal structure */
@@ -645,9 +580,10 @@ int ZEXPORT gzclose_r(file)
free(state->out);
free(state->in);
}
+ err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL);
free(state->path);
ret = close(state->fd);
free(state);
- return ret ? Z_ERRNO : Z_OK;
+ return ret ? Z_ERRNO : err;
}
diff --git a/dep/zlib/gzwrite.c b/dep/zlib/gzwrite.c
index e8defc6887a..27cb3428e32 100644
--- a/dep/zlib/gzwrite.c
+++ b/dep/zlib/gzwrite.c
@@ -1,5 +1,5 @@
/* gzwrite.c -- zlib functions for writing gzip files
- * Copyright (C) 2004, 2005, 2010 Mark Adler
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -18,44 +18,55 @@ local int gz_init(state)
int ret;
z_streamp strm = &(state->strm);
- /* allocate input and output buffers */
+ /* allocate input buffer */
state->in = malloc(state->want);
- state->out = malloc(state->want);
- if (state->in == NULL || state->out == NULL) {
- if (state->out != NULL)
- free(state->out);
- if (state->in != NULL)
- free(state->in);
+ if (state->in == NULL) {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
- /* allocate deflate memory, set up for gzip compression */
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
- strm->opaque = Z_NULL;
- ret = deflateInit2(strm, state->level, Z_DEFLATED,
- 15 + 16, 8, state->strategy);
- if (ret != Z_OK) {
- free(state->in);
- gz_error(state, Z_MEM_ERROR, "out of memory");
- return -1;
+ /* only need output buffer and deflate state if compressing */
+ if (!state->direct) {
+ /* allocate output buffer */
+ state->out = malloc(state->want);
+ if (state->out == NULL) {
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
+
+ /* allocate deflate memory, set up for gzip compression */
+ strm->zalloc = Z_NULL;
+ strm->zfree = Z_NULL;
+ strm->opaque = Z_NULL;
+ ret = deflateInit2(strm, state->level, Z_DEFLATED,
+ MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+ if (ret != Z_OK) {
+ free(state->out);
+ free(state->in);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
}
/* mark state as initialized */
state->size = state->want;
- /* initialize write buffer */
- strm->avail_out = state->size;
- strm->next_out = state->out;
- state->next = strm->next_out;
+ /* initialize write buffer if compressing */
+ if (!state->direct) {
+ strm->avail_out = state->size;
+ strm->next_out = state->out;
+ state->x.next = strm->next_out;
+ }
return 0;
}
/* Compress whatever is at avail_in and next_in and write to the output file.
Return -1 if there is an error writing to the output file, otherwise 0.
flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
- then the deflate() state is reset to start a new gzip stream. */
+ then the deflate() state is reset to start a new gzip stream. If gz->direct
+ is true, then simply write to the output file without compressing, and
+ ignore flush. */
local int gz_comp(state, flush)
gz_statep state;
int flush;
@@ -68,6 +79,17 @@ local int gz_comp(state, flush)
if (state->size == 0 && gz_init(state) == -1)
return -1;
+ /* write directly if requested */
+ if (state->direct) {
+ got = write(state->fd, strm->next_in, strm->avail_in);
+ if (got < 0 || (unsigned)got != strm->avail_in) {
+ gz_error(state, Z_ERRNO, zstrerror());
+ return -1;
+ }
+ strm->avail_in = 0;
+ return 0;
+ }
+
/* run deflate() on provided input until it produces no more output */
ret = Z_OK;
do {
@@ -75,8 +97,8 @@ local int gz_comp(state, flush)
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
(flush != Z_FINISH || ret == Z_STREAM_END))) {
- have = (unsigned)(strm->next_out - state->next);
- if (have && ((got = write(state->fd, state->next, have)) < 0 ||
+ have = (unsigned)(strm->next_out - state->x.next);
+ if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
(unsigned)got != have)) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
@@ -85,7 +107,7 @@ local int gz_comp(state, flush)
strm->avail_out = state->size;
strm->next_out = state->out;
}
- state->next = strm->next_out;
+ state->x.next = strm->next_out;
}
/* compress */
@@ -131,7 +153,7 @@ local int gz_zero(state, len)
}
strm->avail_in = n;
strm->next_in = state->in;
- state->pos += n;
+ state->x.pos += n;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return -1;
len -= n;
@@ -163,7 +185,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* since an int is returned, make sure len fits in one, otherwise return
with an error (this avoids the flaw in the interface) */
if ((int)len < 0) {
- gz_error(state, Z_BUF_ERROR, "requested length does not fit in int");
+ gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
return 0;
}
@@ -193,7 +215,7 @@ int ZEXPORT gzwrite(file, buf, len)
n = len;
memcpy(strm->next_in + strm->avail_in, buf, n);
strm->avail_in += n;
- state->pos += n;
+ state->x.pos += n;
buf = (char *)buf + n;
len -= n;
if (len && gz_comp(state, Z_NO_FLUSH) == -1)
@@ -208,7 +230,7 @@ int ZEXPORT gzwrite(file, buf, len)
/* directly compress user buffer to file */
strm->avail_in = len;
strm->next_in = (voidp)buf;
- state->pos += len;
+ state->x.pos += len;
if (gz_comp(state, Z_NO_FLUSH) == -1)
return 0;
}
@@ -249,15 +271,15 @@ int ZEXPORT gzputc(file, c)
if (strm->avail_in == 0)
strm->next_in = state->in;
strm->next_in[strm->avail_in++] = c;
- state->pos++;
- return c;
+ state->x.pos++;
+ return c & 0xff;
}
/* no room in buffer or not initialized, use gz_write() */
buf[0] = c;
if (gzwrite(file, buf, 1) != 1)
return -1;
- return c;
+ return c & 0xff;
}
/* -- see zlib.h -- */
@@ -274,7 +296,7 @@ int ZEXPORT gzputs(file, str)
return ret == 0 && len != 0 ? -1 : ret;
}
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
#include <stdarg.h>
/* -- see zlib.h -- */
@@ -316,19 +338,19 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
va_start(va, format);
#ifdef NO_vsnprintf
# ifdef HAS_vsprintf_void
- (void)vsprintf(state->in, format, va);
+ (void)vsprintf((char *)(state->in), format, va);
va_end(va);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
- len = vsprintf(state->in, format, va);
+ len = vsprintf((char *)(state->in), format, va);
va_end(va);
# endif
#else
# ifdef HAS_vsnprintf_void
- (void)vsnprintf(state->in, size, format, va);
+ (void)vsnprintf((char *)(state->in), size, format, va);
va_end(va);
- len = strlen(state->in);
+ len = strlen((char *)(state->in));
# else
len = vsnprintf((char *)(state->in), size, format, va);
va_end(va);
@@ -342,11 +364,11 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...)
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
- state->pos += len;
+ state->x.pos += len;
return len;
}
-#else /* !STDC */
+#else /* !STDC && !Z_HAVE_STDARG_H */
/* -- see zlib.h -- */
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
@@ -366,6 +388,10 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
state = (gz_statep)file;
strm = &(state->strm);
+ /* check that can really pass pointer in ints */
+ if (sizeof(int) != sizeof(void *))
+ return 0;
+
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
return 0;
@@ -390,22 +416,23 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
state->in[size - 1] = 0;
#ifdef NO_snprintf
# ifdef HAS_sprintf_void
- sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
for (len = 0; len < size; len++)
if (state->in[len] == 0) break;
# else
- len = sprintf(state->in, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
# endif
#else
# ifdef HAS_snprintf_void
- snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
- len = strlen(state->in);
+ len = strlen((char *)(state->in));
# else
- len = snprintf(state->in, size, format, a1, a2, a3, a4, a5, a6, a7, a8,
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
+ a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
+ a19, a20);
# endif
#endif
@@ -416,7 +443,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
/* update buffer and position, defer compression until needed */
strm->avail_in = (unsigned)len;
strm->next_in = state->in;
- state->pos += len;
+ state->x.pos += len;
return len;
}
@@ -500,7 +527,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
int ZEXPORT gzclose_w(file)
gzFile file;
{
- int ret = 0;
+ int ret = Z_OK;
gz_statep state;
/* get internal structure */
@@ -515,17 +542,24 @@ int ZEXPORT gzclose_w(file)
/* check for seek request */
if (state->seek) {
state->seek = 0;
- ret += gz_zero(state, state->skip);
+ if (gz_zero(state, state->skip) == -1)
+ ret = state->err;
}
/* flush, free memory, and close file */
- ret += gz_comp(state, Z_FINISH);
- (void)deflateEnd(&(state->strm));
- free(state->out);
- free(state->in);
+ if (state->size) {
+ if (gz_comp(state, Z_FINISH) == -1)
+ ret = state->err;
+ if (!state->direct) {
+ (void)deflateEnd(&(state->strm));
+ free(state->out);
+ }
+ free(state->in);
+ }
gz_error(state, Z_OK, NULL);
free(state->path);
- ret += close(state->fd);
+ if (close(state->fd) == -1)
+ ret = Z_ERRNO;
free(state);
- return ret ? Z_ERRNO : Z_OK;
+ return ret;
}
diff --git a/dep/zlib/infback.c b/dep/zlib/infback.c
index af3a8c965d5..981aff17c2d 100644
--- a/dep/zlib/infback.c
+++ b/dep/zlib/infback.c
@@ -1,5 +1,5 @@
/* infback.c -- inflate using a call-back interface
- * Copyright (C) 1995-2009 Mark Adler
+ * Copyright (C) 1995-2011 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -42,10 +42,19 @@ int stream_size;
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
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) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
+ strm->zfree = zcfree;
+#endif
state = (struct inflate_state FAR *)ZALLOC(strm, 1,
sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
@@ -394,7 +403,6 @@ void FAR *out_desc;
PULLBYTE();
}
if (here.val < 16) {
- NEEDBITS(here.bits);
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
diff --git a/dep/zlib/inffixed.h b/dep/zlib/inffixed.h
index 75ed4b5978d..d6283277694 100644
--- a/dep/zlib/inffixed.h
+++ b/dep/zlib/inffixed.h
@@ -2,9 +2,9 @@
* Generated automatically by makefixed().
*/
- /* WARNING: this file should *not* be used by applications. It
- is part of the implementation of the compression library and
- is subject to change. Applications should only use zlib.h.
+ /* WARNING: this file should *not* be used by applications.
+ It is part of the implementation of this library and is
+ subject to change. Applications should only use zlib.h.
*/
static const code lenfix[512] = {
diff --git a/dep/zlib/inflate.c b/dep/zlib/inflate.c
index a8431abeacf..47418a1e1e1 100644
--- a/dep/zlib/inflate.c
+++ b/dep/zlib/inflate.c
@@ -1,5 +1,5 @@
/* inflate.c -- zlib decompression
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -100,7 +100,7 @@ local int updatewindow OF((z_streamp strm, unsigned out));
local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
unsigned len));
-int ZEXPORT inflateReset(strm)
+int ZEXPORT inflateResetKeep(strm)
z_streamp strm;
{
struct inflate_state FAR *state;
@@ -109,15 +109,13 @@ z_streamp strm;
state = (struct inflate_state FAR *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL;
- strm->adler = 1; /* to support ill-conceived Java test suite */
+ if (state->wrap) /* to support ill-conceived Java test suite */
+ strm->adler = state->wrap & 1;
state->mode = HEAD;
state->last = 0;
state->havedict = 0;
state->dmax = 32768U;
state->head = Z_NULL;
- state->wsize = 0;
- state->whave = 0;
- state->wnext = 0;
state->hold = 0;
state->bits = 0;
state->lencode = state->distcode = state->next = state->codes;
@@ -127,6 +125,19 @@ z_streamp strm;
return Z_OK;
}
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ state->wsize = 0;
+ state->whave = 0;
+ state->wnext = 0;
+ return inflateResetKeep(strm);
+}
+
int ZEXPORT inflateReset2(strm, windowBits)
z_streamp strm;
int windowBits;
@@ -180,10 +191,19 @@ int stream_size;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
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) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0)
+#ifdef Z_SOLO
+ return Z_STREAM_ERROR;
+#else
+ strm->zfree = zcfree;
+#endif
state = (struct inflate_state FAR *)
ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
@@ -321,8 +341,8 @@ void makefixed()
low = 0;
for (;;) {
if ((low % 7) == 0) printf("\n ");
- printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
- state.lencode[low].val);
+ printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
+ state.lencode[low].bits, state.lencode[low].val);
if (++low == size) break;
putchar(',');
}
@@ -499,11 +519,6 @@ unsigned out;
bits -= bits & 7; \
} while (0)
-/* Reverse the bytes in a 32-bit value */
-#define REVERSE(q) \
- ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
- (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
-
/*
inflate() uses a state machine to process as much input data and generate as
much output data as possible before returning. The state machine is
@@ -797,7 +812,7 @@ int flush;
#endif
case DICTID:
NEEDBITS(32);
- strm->adler = state->check = REVERSE(hold);
+ strm->adler = state->check = ZSWAP32(hold);
INITBITS();
state->mode = DICT;
case DICT:
@@ -925,7 +940,6 @@ int flush;
PULLBYTE();
}
if (here.val < 16) {
- NEEDBITS(here.bits);
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
}
@@ -1170,7 +1184,7 @@ int flush;
#ifdef GUNZIP
state->flags ? hold :
#endif
- REVERSE(hold)) != state->check) {
+ ZSWAP32(hold)) != state->check) {
strm->msg = (char *)"incorrect data check";
state->mode = BAD;
break;
@@ -1214,7 +1228,8 @@ int flush;
*/
inf_leave:
RESTORE();
- if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
+ if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
+ (state->mode < CHECK || flush != Z_FINISH)))
if (updatewindow(strm, out)) {
state->mode = MEM;
return Z_MEM_ERROR;
@@ -1255,7 +1270,10 @@ const Bytef *dictionary;
uInt dictLength;
{
struct inflate_state FAR *state;
- unsigned long id;
+ unsigned long dictid;
+ unsigned char *next;
+ unsigned avail;
+ int ret;
/* check state */
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
@@ -1263,29 +1281,27 @@ uInt dictLength;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
- /* check for correct dictionary id */
+ /* check for correct dictionary identifier */
if (state->mode == DICT) {
- id = adler32(0L, Z_NULL, 0);
- id = adler32(id, dictionary, dictLength);
- if (id != state->check)
+ dictid = adler32(0L, Z_NULL, 0);
+ dictid = adler32(dictid, dictionary, dictLength);
+ if (dictid != state->check)
return Z_DATA_ERROR;
}
- /* copy dictionary to window */
- if (updatewindow(strm, strm->avail_out)) {
+ /* copy dictionary to window using updatewindow(), which will amend the
+ existing dictionary if appropriate */
+ next = strm->next_out;
+ avail = strm->avail_out;
+ strm->next_out = (Bytef *)dictionary + dictLength;
+ strm->avail_out = 0;
+ ret = updatewindow(strm, dictLength);
+ strm->avail_out = avail;
+ strm->next_out = next;
+ if (ret) {
state->mode = MEM;
return Z_MEM_ERROR;
}
- if (dictLength > state->wsize) {
- zmemcpy(state->window, dictionary + dictLength - state->wsize,
- state->wsize);
- state->whave = state->wsize;
- }
- else {
- zmemcpy(state->window + state->wsize - dictLength, dictionary,
- dictLength);
- state->whave = dictLength;
- }
state->havedict = 1;
Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
@@ -1433,8 +1449,8 @@ z_streamp source;
}
/* copy state */
- zmemcpy(dest, source, sizeof(z_stream));
- zmemcpy(copy, state, sizeof(struct inflate_state));
+ zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
+ zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
if (state->lencode >= state->codes &&
state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes);
diff --git a/dep/zlib/inftrees.c b/dep/zlib/inftrees.c
index 11e9c52accb..abcd7c45ed3 100644
--- a/dep/zlib/inftrees.c
+++ b/dep/zlib/inftrees.c
@@ -1,5 +1,5 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-2010 Mark Adler
+ * Copyright (C) 1995-2012 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -9,7 +9,7 @@
#define MAXBITS 15
const char inflate_copyright[] =
- " inflate 1.2.5 Copyright 1995-2010 Mark Adler ";
+ " inflate 1.2.7 Copyright 1995-2012 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
- 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195};
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -289,38 +289,14 @@ unsigned short FAR *work;
}
}
- /*
- Fill in rest of table for incomplete codes. This loop is similar to the
- loop above in incrementing huff for table indices. It is assumed that
- len is equal to curr + drop, so there is no loop needed to increment
- through high index bits. When the current sub-table is filled, the loop
- drops back to the root table to fill in any remaining entries there.
- */
- here.op = (unsigned char)64; /* invalid code marker */
- here.bits = (unsigned char)(len - drop);
- here.val = (unsigned short)0;
- while (huff != 0) {
- /* when done with sub-table, drop back to root table */
- if (drop != 0 && (huff & mask) != low) {
- drop = 0;
- len = root;
- next = *table;
- here.bits = (unsigned char)len;
- }
-
- /* put invalid code marker in table */
- next[huff >> drop] = here;
-
- /* backwards increment the len-bit code huff */
- incr = 1U << (len - 1);
- while (huff & incr)
- incr >>= 1;
- if (incr != 0) {
- huff &= incr - 1;
- huff += incr;
- }
- else
- huff = 0;
+ /* fill in remaining table entry if code is incomplete (guaranteed to have
+ at most one remaining entry, since if the code is incomplete, the
+ maximum code length that was allowed to get this far is one bit) */
+ if (huff != 0) {
+ here.op = (unsigned char)64; /* invalid code marker */
+ here.bits = (unsigned char)(len - drop);
+ here.val = (unsigned short)0;
+ next[huff] = here;
}
/* set return parameters */
diff --git a/dep/zlib/trees.c b/dep/zlib/trees.c
index 56e9bb1c115..8c32b214b1d 100644
--- a/dep/zlib/trees.c
+++ b/dep/zlib/trees.c
@@ -1,5 +1,5 @@
/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-2010 Jean-loup Gailly
+ * Copyright (C) 1995-2012 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -74,11 +74,6 @@ local const uch bl_order[BL_CODES]
* probability, to avoid transmitting the lengths for unused bit length codes.
*/
-#define Buf_size (8 * 2*sizeof(char))
-/* Number of bits used within bi_buf. (bi_buf might be implemented on
- * more than 16 bits on some systems.)
- */
-
/* ===========================================================================
* Local data. These are initialized only once.
*/
@@ -399,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
s->bi_buf = 0;
s->bi_valid = 0;
- s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;
@@ -883,15 +877,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
}
/* ===========================================================================
+ * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
+ */
+void ZLIB_INTERNAL _tr_flush_bits(s)
+ deflate_state *s;
+{
+ bi_flush(s);
+}
+
+/* ===========================================================================
* Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer.
- * The current inflate code requires 9 bits of lookahead. If the
- * last two codes for the previous block (real code plus EOB) were coded
- * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
- * the last real code. In this case we send two empty static blocks instead
- * of one. (There are no problems if the previous block is stored or fixed.)
- * To simplify the code, we assume the worst case of last real code encoded
- * on one bit only.
*/
void ZLIB_INTERNAL _tr_align(s)
deflate_state *s;
@@ -902,20 +898,6 @@ void ZLIB_INTERNAL _tr_align(s)
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif
bi_flush(s);
- /* Of the 10 bits for the empty block, we have already sent
- * (10 - bi_valid) bits. The lookahead for the last real code (before
- * the EOB of the previous block) was thus at least one plus the length
- * of the EOB plus what we have just sent of the empty static block.
- */
- if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
- send_bits(s, STATIC_TREES<<1, 3);
- send_code(s, END_BLOCK, static_ltree);
-#ifdef DEBUG
- s->compressed_len += 10L;
-#endif
- bi_flush(s);
- }
- s->last_eob_len = 7;
}
/* ===========================================================================
@@ -1118,7 +1100,6 @@ local void compress_block(s, ltree, dtree)
} while (lx < s->last_lit);
send_code(s, END_BLOCK, ltree);
- s->last_eob_len = ltree[END_BLOCK].Len;
}
/* ===========================================================================
@@ -1226,7 +1207,6 @@ local void copy_block(s, buf, len, header)
int header; /* true if block header must be written */
{
bi_windup(s); /* align on byte boundary */
- s->last_eob_len = 8; /* enough lookahead for inflate */
if (header) {
put_short(s, (ush)len);
diff --git a/dep/zlib/zconf.h b/dep/zlib/zconf.h
index 02ce56c4313..8a46a58b30c 100644
--- a/dep/zlib/zconf.h
+++ b/dep/zlib/zconf.h
@@ -1,5 +1,5 @@
/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -15,6 +15,7 @@
* this permanently in zconf.h using "./configure --zprefix".
*/
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
+# define Z_PREFIX_SET
/* all linked symbols */
# define _dist_code z__dist_code
@@ -27,9 +28,11 @@
# define adler32 z_adler32
# define adler32_combine z_adler32_combine
# define adler32_combine64 z_adler32_combine64
-# define compress z_compress
-# define compress2 z_compress2
-# define compressBound z_compressBound
+# ifndef Z_SOLO
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# endif
# define crc32 z_crc32
# define crc32_combine z_crc32_combine
# define crc32_combine64 z_crc32_combine64
@@ -40,44 +43,52 @@
# define deflateInit2_ z_deflateInit2_
# define deflateInit_ z_deflateInit_
# define deflateParams z_deflateParams
+# define deflatePending z_deflatePending
# define deflatePrime z_deflatePrime
# define deflateReset z_deflateReset
+# define deflateResetKeep z_deflateResetKeep
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
-# define gz_error z_gz_error
-# define gz_intmax z_gz_intmax
-# define gz_strwinerror z_gz_strwinerror
-# define gzbuffer z_gzbuffer
-# define gzclearerr z_gzclearerr
-# define gzclose z_gzclose
-# define gzclose_r z_gzclose_r
-# define gzclose_w z_gzclose_w
-# define gzdirect z_gzdirect
-# define gzdopen z_gzdopen
-# define gzeof z_gzeof
-# define gzerror z_gzerror
-# define gzflush z_gzflush
-# define gzgetc z_gzgetc
-# define gzgets z_gzgets
-# define gzoffset z_gzoffset
-# define gzoffset64 z_gzoffset64
-# define gzopen z_gzopen
-# define gzopen64 z_gzopen64
-# define gzprintf z_gzprintf
-# define gzputc z_gzputc
-# define gzputs z_gzputs
-# define gzread z_gzread
-# define gzrewind z_gzrewind
-# define gzseek z_gzseek
-# define gzseek64 z_gzseek64
-# define gzsetparams z_gzsetparams
-# define gztell z_gztell
-# define gztell64 z_gztell64
-# define gzungetc z_gzungetc
-# define gzwrite z_gzwrite
+# ifndef Z_SOLO
+# define gz_error z_gz_error
+# define gz_intmax z_gz_intmax
+# define gz_strwinerror z_gz_strwinerror
+# define gzbuffer z_gzbuffer
+# define gzclearerr z_gzclearerr
+# define gzclose z_gzclose
+# define gzclose_r z_gzclose_r
+# define gzclose_w z_gzclose_w
+# define gzdirect z_gzdirect
+# define gzdopen z_gzdopen
+# define gzeof z_gzeof
+# define gzerror z_gzerror
+# define gzflush z_gzflush
+# define gzgetc z_gzgetc
+# define gzgetc_ z_gzgetc_
+# define gzgets z_gzgets
+# define gzoffset z_gzoffset
+# define gzoffset64 z_gzoffset64
+# define gzopen z_gzopen
+# define gzopen64 z_gzopen64
+# ifdef _WIN32
+# define gzopen_w z_gzopen_w
+# endif
+# define gzprintf z_gzprintf
+# define gzputc z_gzputc
+# define gzputs z_gzputs
+# define gzread z_gzread
+# define gzrewind z_gzrewind
+# define gzseek z_gzseek
+# define gzseek64 z_gzseek64
+# define gzsetparams z_gzsetparams
+# define gztell z_gztell
+# define gztell64 z_gztell64
+# define gzungetc z_gzungetc
+# define gzwrite z_gzwrite
+# endif
# define inflate z_inflate
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
@@ -95,13 +106,18 @@
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateUndermine z_inflateUndermine
+# define inflateResetKeep z_inflateResetKeep
# define inflate_copyright z_inflate_copyright
# define inflate_fast z_inflate_fast
# define inflate_table z_inflate_table
-# define uncompress z_uncompress
+# ifndef Z_SOLO
+# define uncompress z_uncompress
+# endif
# define zError z_zError
-# define zcalloc z_zcalloc
-# define zcfree z_zcfree
+# ifndef Z_SOLO
+# define zcalloc z_zcalloc
+# define zcfree z_zcfree
+# endif
# define zlibCompileFlags z_zlibCompileFlags
# define zlibVersion z_zlibVersion
@@ -111,7 +127,9 @@
# define alloc_func z_alloc_func
# define charf z_charf
# define free_func z_free_func
-# define gzFile z_gzFile
+# ifndef Z_SOLO
+# define gzFile z_gzFile
+# endif
# define gz_header z_gz_header
# define gz_headerp z_gz_headerp
# define in_func z_in_func
@@ -197,6 +215,12 @@
# endif
#endif
+#if defined(ZLIB_CONST) && !defined(z_const)
+# define z_const const
+#else
+# define z_const
+#endif
+
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
@@ -243,6 +267,14 @@
# endif
#endif
+#ifndef Z_ARG /* function prototypes for stdarg */
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
+# define Z_ARG(args) args
+# else
+# define Z_ARG(args) ()
+# endif
+#endif
+
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
@@ -356,12 +388,45 @@ typedef uLong FAR uLongf;
typedef Byte *voidp;
#endif
+/* ./configure may #define Z_U4 here */
+
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
+# include <limits.h>
+# if (UINT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned
+# else
+# if (ULONG_MAX == 0xffffffffUL)
+# define Z_U4 unsigned long
+# else
+# if (USHRT_MAX == 0xffffffffUL)
+# define Z_U4 unsigned short
+# endif
+# endif
+# endif
+#endif
+
+#ifdef Z_U4
+ typedef Z_U4 z_crc_t;
+#else
+ typedef unsigned long z_crc_t;
+#endif
+
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
# define Z_HAVE_UNISTD_H
#endif
+#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
+# define Z_HAVE_STDARG_H
+#endif
+
#ifdef STDC
-# include <sys/types.h> /* for off_t */
+# ifndef Z_SOLO
+# include <sys/types.h> /* for off_t */
+# endif
+#endif
+
+#ifdef _WIN32
+# include <stddef.h> /* for wchar_t */
#endif
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -370,21 +435,38 @@ typedef uLong FAR uLongf;
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
* equivalently requesting no 64-bit operations
*/
-#if -_LARGEFILE64_SOURCE - -1 == 1
+#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
# undef _LARGEFILE64_SOURCE
#endif
-#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
-# include <unistd.h> /* for SEEK_* and off_t */
-# ifdef VMS
-# include <unixio.h> /* for off_t */
-# endif
-# ifndef z_off_t
-# define z_off_t off_t
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
+# define Z_HAVE_UNISTD_H
+#endif
+#ifndef Z_SOLO
+# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
+# ifdef VMS
+# include <unixio.h> /* for off_t */
+# endif
+# ifndef z_off_t
+# define z_off_t off_t
+# endif
# endif
#endif
-#ifndef SEEK_SET
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
+# define Z_LFS64
+#endif
+
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
+# define Z_LARGE64
+#endif
+
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
+# define Z_WANT64
+#endif
+
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
@@ -394,18 +476,14 @@ typedef uLong FAR uLongf;
# define z_off_t long
#endif
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
-# define z_off64_t z_off_t
-#endif
-
-#if defined(__OS400__)
-# define NO_vsnprintf
-#endif
-
-#if defined(__MVS__)
-# define NO_vsnprintf
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+# define z_off64_t __int64
+# else
+# define z_off64_t z_off_t
+# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
diff --git a/dep/zlib/zlib.h b/dep/zlib/zlib.h
index bfbba83e8ee..3edf3acdb57 100644
--- a/dep/zlib/zlib.h
+++ b/dep/zlib/zlib.h
@@ -1,7 +1,7 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
- version 1.2.5, April 19th, 2010
+ version 1.2.7, May 2nd, 2012
- Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
+ Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -24,8 +24,8 @@
The data format used by the zlib library is described by RFCs (Request for
- Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
- (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
*/
#ifndef ZLIB_H
@@ -37,11 +37,11 @@
extern "C" {
#endif
-#define ZLIB_VERSION "1.2.5"
-#define ZLIB_VERNUM 0x1250
+#define ZLIB_VERSION "1.2.7"
+#define ZLIB_VERNUM 0x1270
#define ZLIB_VER_MAJOR 1
#define ZLIB_VER_MINOR 2
-#define ZLIB_VER_REVISION 5
+#define ZLIB_VER_REVISION 7
#define ZLIB_VER_SUBREVISION 0
/*
@@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
- Bytef *next_in; /* next input byte */
+ z_const Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
- uLong total_in; /* total nb of input bytes read so far */
+ uLong total_in; /* total number of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
- uLong total_out; /* total nb of bytes output so far */
+ uLong total_out; /* total number of bytes output so far */
- char *msg; /* last error message, NULL if no error */
+ z_const char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
@@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least the
- value returned by deflateBound (see below). If deflate does not return
- Z_STREAM_END, then it must be called again as described above.
+ value returned by deflateBound (see below). Then deflate is guaranteed to
+ return Z_STREAM_END. If not enough output space is provided, deflate will
+ not return Z_STREAM_END, and it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
@@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
error. However if all decompression is to be performed in a single step (a
single call of inflate), the parameter flush should be set to Z_FINISH. In
this case all pending input is processed and all pending output is flushed;
- avail_out must be large enough to hold all the uncompressed data. (The size
- of the uncompressed data may have been saved by the compressor for this
- purpose.) The next operation on this stream must be inflateEnd to deallocate
- the decompression state. The use of Z_FINISH is never required, but can be
- used to inform inflate that a faster approach may be used for the single
- inflate() call.
+ avail_out must be large enough to hold all of the uncompressed data for the
+ operation to complete. (The size of the uncompressed data may have been
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
+ required to perform an inflation in one step. However it may be used to
+ inform inflate that a faster approach can be used for the single inflate()
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
+ stream completes, which reduces inflate's memory footprint. If the stream
+ does not complete, either because not all of the stream is provided or not
+ enough output space is provided, then a sliding window will be allocated and
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
+ been used.
In this implementation, inflate() always flushes as much output as
possible to the output buffer, and always uses the faster approach on the
- first call. So the only effect of the flush parameter in this implementation
- is on the return value of inflate(), as noted below, or when it returns early
- because Z_BLOCK or Z_TREES is used.
+ first call. So the effects of the flush parameter in this implementation are
+ on the return value of inflate() as noted below, when inflate() returns early
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
+ memory for a sliding window when Z_FINISH is used.
If a preset dictionary is needed after this call (see inflateSetDictionary
- below), inflate sets strm->adler to the adler32 checksum of the dictionary
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
- strm->adler to the adler32 checksum of all output produced so far (that is,
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
below. At the end of the stream, inflate() checks that its computed adler32
checksum is equal to that saved by the compressor and returns Z_STREAM_END
@@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
initializing with inflateInit2(). Any information contained in the gzip
header is not retained, so applications that need that information should
instead use raw inflate, see inflateInit2() below, or inflateBack() and
- perform their own processing of the gzip header and trailer.
+ perform their own processing of the gzip header and trailer. When processing
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
+ producted so far. The CRC-32 is checked against the gzip trailer.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
@@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
- without producing any compressed output. This function must be called
- immediately after deflateInit, deflateInit2 or deflateReset, before any call
- of deflate. The compressor and decompressor must use exactly the same
- dictionary (see inflateSetDictionary).
+ without producing any compressed output. When using the zlib format, this
+ function must be called immediately after deflateInit, deflateInit2 or
+ deflateReset, and before any call of deflate. When doing raw deflate, this
+ function must be called either before any call of deflate, or immediately
+ after the completion of a deflate block, i.e. after all input has been
+ consumed and all output has been delivered when using any of the flush
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
+ compressor and decompressor must use exactly the same dictionary (see
+ inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
@@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
inconsistent (for example if deflate has already been called for this stream
- or if the compression method is bsort). deflateSetDictionary does not
- perform any compression: this will be done by deflate().
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
+ not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
@@ -688,8 +702,28 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
deflation of sourceLen bytes. It must be called after deflateInit() or
deflateInit2(), and after deflateSetHeader(), if used. This would be used
to allocate an output buffer for deflation in a single pass, and so would be
- called before deflate().
-*/
+ called before deflate(). If that first deflate() call is provided the
+ sourceLen input bytes, an output buffer allocated to the size returned by
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
+ be larger than the value returned by deflateBound() if flush options other
+ than Z_FINISH or Z_NO_FLUSH are used.
+*/
+
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
+ unsigned *pending,
+ int *bits));
+/*
+ deflatePending() returns the number of bytes and bits of output that have
+ been generated, but not yet provided in the available output. The bytes not
+ provided would be due to the available output space having being consumed.
+ The number of bits of output not provided are between 0 and 7, where they
+ await more bits to join them in order to fill out a full byte. If pending
+ or bits are Z_NULL, then those values are not set.
+
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+ */
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
int bits,
@@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
than or equal to 16, and that many of the least significant bits of value
will be inserted in the output.
- deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
- stream state was inconsistent.
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
+ source stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
@@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the adler32 value returned by that call of inflate.
The compressor and decompressor must use exactly the same dictionary (see
- deflateSetDictionary). For raw inflate, this function can be called
- immediately after inflateInit2() or inflateReset() and before any call of
- inflate() to set the dictionary. The application must insure that the
- dictionary that was used for compression is provided.
+ deflateSetDictionary). For raw inflate, this function can be called at any
+ time to set the dictionary. If the provided dictionary is smaller than the
+ window and there is already data in the window, then the provided dictionary
+ will amend what's there. The application must insure that the dictionary
+ that was used for compression is provided.
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
@@ -805,17 +841,21 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
- Skips invalid compressed data until a full flush point (see above the
- description of deflate with Z_FULL_FLUSH) can be found, or until all
+ Skips invalid compressed data until a possible full flush point (see above
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
- inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
- if no more input was provided, Z_DATA_ERROR if no flush point has been
- found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the
- success case, the application may save the current current value of total_in
- which indicates where valid compressed data was found. In the error case,
- the application may repeatedly call inflateSync, providing more input each
- time, until success or end of the input data.
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
+ All full flush points have this pattern, but not all occurences of this
+ pattern are full flush points.
+
+ inflateSync returns Z_OK if a possible full flush point has been found,
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
+ In the success case, the application may save the current current value of
+ total_in which indicates where valid compressed data was found. In the
+ error case, the application may repeatedly call inflateSync, providing more
+ input each time, until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
@@ -962,7 +1002,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
See inflateBack() for the usage of these routines.
inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
- the paramaters are invalid, Z_MEM_ERROR if the internal state could not be
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
allocated, or Z_VERSION_ERROR if the version of the library does not match
the version of the header file.
*/
@@ -1088,6 +1128,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
27-31: 0 (reserved)
*/
+#ifndef Z_SOLO
/* utility functions */
@@ -1149,10 +1190,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
- buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
+ the case where there is not enough room, uncompress() will fill the output
+ buffer with the uncompressed data up to that point.
*/
-
/* gzip file access functions */
/*
@@ -1162,7 +1204,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
wrapper, documented in RFC 1952, wrapped around a deflate stream.
*/
-typedef voidp gzFile; /* opaque gzip file descriptor */
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
/*
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
@@ -1172,13 +1214,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
for fixed code compression as in "wb9F". (See the description of
- deflateInit2 for more information about the strategy parameter.) Also "a"
- can be used instead of "w" to request that the gzip stream that will be
- written be appended to the file. "+" will result in an error, since reading
- and writing to the same gzip file is not supported.
+ deflateInit2 for more information about the strategy parameter.) 'T' will
+ request transparent writing or appending with no compression and not using
+ the gzip format.
+
+ "a" can be used instead of "w" to request that the gzip stream that will
+ be written be appended to the file. "+" will result in an error, since
+ reading and writing to the same gzip file is not supported. The addition of
+ "x" when writing will create the file exclusively, which fails if the file
+ already exists. On systems that support it, the addition of "e" when
+ reading or writing will set the flag to close the file on an execve() call.
+
+ These functions, as well as gzip, will read and decode a sequence of gzip
+ streams in a file. The append function of gzopen() can be used to create
+ such a file. (Also see gzflush() for another way to do this.) When
+ appending, gzopen does not test whether the file begins with a gzip stream,
+ nor does it look for the end of the gzip streams to begin appending. gzopen
+ will simply append a gzip stream to the existing file.
gzopen can be used to read a file which is not in gzip format; in this
- case gzread will directly read from the file without decompression.
+ case gzread will directly read from the file without decompression. When
+ reading, this will be detected automatically by looking for the magic two-
+ byte gzip header.
gzopen returns NULL if the file could not be opened, if there was
insufficient memory to allocate the gzFile state, or if an invalid mode was
@@ -1197,7 +1254,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
mode);. The duplicated descriptor should be saved to avoid a leak, since
- gzdopen does not close fd if it fails.
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
+ file descriptor from a FILE *, then you will have to use dup() to avoid
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
+ close the associated file descriptor, so they need to have different file
+ descriptors.
gzdopen returns NULL if there was insufficient memory to allocate the
gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
@@ -1235,14 +1296,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file. If
- the input file was not in gzip format, gzread copies the given number of
- bytes into the buffer.
+ the input file is not in gzip format, gzread copies the given number of
+ bytes into the buffer directly from the file.
After reaching the end of a gzip stream in the input, gzread will continue
- to read, looking for another gzip stream, or failing that, reading the rest
- of the input file directly without decompression. The entire input file
- will be read if gzread is called until it returns less than the requested
- len.
+ to read, looking for another gzip stream. Any number of gzip streams may be
+ concatenated in the input file, and will all be decompressed by gzread().
+ If something other than a gzip stream is encountered after a gzip stream,
+ that remaining trailing garbage is ignored (and no error is returned).
+
+ gzread can be used to read a gzip file that is being concurrently written.
+ Upon reaching the end of the input, gzread will return with the available
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+ gzclearerr can be used to clear the end of file indicator in order to permit
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
+ middle of a gzip stream. Note that gzread does not return -1 in the event
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+ stream. Alternatively, gzerror can be used before gzclose to detect this
+ case.
gzread returns the number of uncompressed bytes actually read, less than
len for end of file, or -1 for error.
@@ -1256,7 +1329,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
error.
*/
-ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the arguments to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
@@ -1301,7 +1374,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte or -1
- in case of end of file or error.
+ in case of end of file or error. This is implemented as a macro for speed.
+ As such, it does not do all of the checking the other functions do. I.e.
+ it does not check to see if file is NULL, nor whether the structure file
+ points to has been clobbered or not.
*/
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
@@ -1397,9 +1473,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file));
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
/*
Returns true (1) if file is being copied directly while reading, or false
- (0) if file is a gzip stream being decompressed. This state can change from
- false to true while reading the input file if the end of a gzip stream is
- reached, but is followed by data that is not another gzip stream.
+ (0) if file is a gzip stream being decompressed.
If the input file is empty, gzdirect() will return true, since the input
does not contain a gzip stream.
@@ -1408,6 +1482,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
cause buffers to be allocated to allow reading the file to determine if it
is a gzip file. Therefore if gzbuffer() is used, it should be called before
gzdirect().
+
+ When writing, gzdirect() returns true (1) if transparent writing was
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
+ gzdirect() is not needed when writing. Transparent writing must be
+ explicitly requested, so the application already knows the answer. When
+ linking statically, using gzdirect() will include all of the zlib code for
+ gzip file reading and decompression, which may not be desired.)
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
@@ -1419,7 +1500,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file));
must not be called more than once on the same allocation.
gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
- file operation error, or Z_OK on success.
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+ last read ended in the middle of a gzip stream, or Z_OK on success.
*/
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
@@ -1457,6 +1539,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
file that is being written concurrently.
*/
+#endif /* !Z_SOLO */
/* checksum functions */
@@ -1492,16 +1575,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
- seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
+ negative, the result has no meaning or utility.
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running CRC-32 with the bytes buf[0..len-1] and return the
updated CRC-32. If buf is Z_NULL, this function returns the required
- initial value for the for the crc. Pre- and post-conditioning (one's
- complement) is performed within this function so it shouldn't be done by the
- application.
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
Usage example:
@@ -1544,17 +1628,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
const char *version,
int stream_size));
#define deflateInit(strm, level) \
- deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit(strm) \
- inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
- (strategy), ZLIB_VERSION, sizeof(z_stream))
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
- inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
+ (int)sizeof(z_stream))
#define inflateBackInit(strm, windowBits, window) \
inflateBackInit_((strm), (windowBits), (window), \
- ZLIB_VERSION, sizeof(z_stream))
+ ZLIB_VERSION, (int)sizeof(z_stream))
+
+#ifndef Z_SOLO
+
+/* gzgetc() macro and its supporting function and exposed data structure. Note
+ * that the real internal state is much larger than the exposed structure.
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
+ * user should not mess with these exposed elements, since their names or
+ * behavior could change in the future, perhaps even capriciously. They can
+ * only be used by the gzgetc() macro. You have been warned.
+ */
+struct gzFile_s {
+ unsigned have;
+ unsigned char *next;
+ z_off64_t pos;
+};
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
+#ifdef Z_PREFIX_SET
+# undef z_gzgetc
+# define z_gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#else
+# define gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
+#endif
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
@@ -1562,7 +1671,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
* functions are changed to 64 bits) -- in case these are set on systems
* without large file support, _LFS64_LARGEFILE must also be true
*/
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
@@ -1571,14 +1680,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
#endif
-#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
-# define gzopen gzopen64
-# define gzseek gzseek64
-# define gztell gztell64
-# define gzoffset gzoffset64
-# define adler32_combine adler32_combine64
-# define crc32_combine crc32_combine64
-# ifdef _LARGEFILE64_SOURCE
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
+# ifdef Z_PREFIX_SET
+# define z_gzopen z_gzopen64
+# define z_gzseek z_gzseek64
+# define z_gztell z_gztell64
+# define z_gzoffset z_gzoffset64
+# define z_adler32_combine z_adler32_combine64
+# define z_crc32_combine z_crc32_combine64
+# else
+# define gzopen gzopen64
+# define gzseek gzseek64
+# define gztell gztell64
+# define gzoffset gzoffset64
+# define adler32_combine adler32_combine64
+# define crc32_combine crc32_combine64
+# endif
+# ifndef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
@@ -1595,6 +1713,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
#endif
+#else /* Z_SOLO */
+
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
+
+#endif /* !Z_SOLO */
+
/* hack for buggy compilers */
#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;};
@@ -1603,8 +1728,14 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
/* undocumented functions */
ZEXTERN const char * ZEXPORT zError OF((int));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
-ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
+#if defined(_WIN32) && !defined(Z_SOLO)
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
+ const char *mode));
+#endif
#ifdef __cplusplus
}
diff --git a/dep/zlib/zutil.c b/dep/zlib/zutil.c
index 898ed345b0e..65e0d3b72b0 100644
--- a/dep/zlib/zutil.c
+++ b/dep/zlib/zutil.c
@@ -1,11 +1,14 @@
/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zutil.h"
+#ifndef Z_SOLO
+# include "gzguts.h"
+#endif
#ifndef NO_DUMMY_DECL
struct internal_state {int dummy;}; /* for buggy compilers */
@@ -85,27 +88,27 @@ uLong ZEXPORT zlibCompileFlags()
#ifdef FASTEST
flags += 1L << 21;
#endif
-#ifdef STDC
+#if defined(STDC) || defined(Z_HAVE_STDARG_H)
# ifdef NO_vsnprintf
- flags += 1L << 25;
+ flags += 1L << 25;
# ifdef HAS_vsprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# else
# ifdef HAS_vsnprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# endif
#else
- flags += 1L << 24;
+ flags += 1L << 24;
# ifdef NO_snprintf
- flags += 1L << 25;
+ flags += 1L << 25;
# ifdef HAS_sprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# else
# ifdef HAS_snprintf_void
- flags += 1L << 26;
+ flags += 1L << 26;
# endif
# endif
#endif
@@ -181,6 +184,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
}
#endif
+#ifndef Z_SOLO
#ifdef SYS16BIT
@@ -316,3 +320,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
}
#endif /* MY_ZCALLOC */
+
+#endif /* !Z_SOLO */
diff --git a/dep/zlib/zutil.h b/dep/zlib/zutil.h
index 258fa88799a..4e3dcc6ae9f 100644
--- a/dep/zlib/zutil.h
+++ b/dep/zlib/zutil.h
@@ -1,5 +1,5 @@
/* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-2010 Jean-loup Gailly.
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -13,7 +13,7 @@
#ifndef ZUTIL_H
#define ZUTIL_H
-#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
+#ifdef HAVE_HIDDEN
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
# define ZLIB_INTERNAL
@@ -21,7 +21,7 @@
#include "zlib.h"
-#ifdef STDC
+#if defined(STDC) && !defined(Z_SOLO)
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
# include <stddef.h>
# endif
@@ -29,6 +29,10 @@
# include <stdlib.h>
#endif
+#ifdef Z_SOLO
+ typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
+#endif
+
#ifndef local
# define local static
#endif
@@ -78,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
# define OS_CODE 0x00
-# if defined(__TURBOC__) || defined(__BORLANDC__)
-# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
- /* Allow compilation with ANSI keywords only enabled */
- void _Cdecl farfree( void *block );
- void *_Cdecl farmalloc( unsigned long nbytes );
-# else
-# include <alloc.h>
+# ifndef Z_SOLO
+# if defined(__TURBOC__) || defined(__BORLANDC__)
+# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+ /* Allow compilation with ANSI keywords only enabled */
+ void _Cdecl farfree( void *block );
+ void *_Cdecl farmalloc( unsigned long nbytes );
+# else
+# include <alloc.h>
+# endif
+# else /* MSC or DJGPP */
+# include <malloc.h>
# endif
-# else /* MSC or DJGPP */
-# include <malloc.h>
# endif
#endif
@@ -107,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifdef OS2
# define OS_CODE 0x06
-# ifdef M_I86
+# if defined(M_I86) && !defined(Z_SOLO)
# include <malloc.h>
# endif
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
-# include <unix.h> /* for fdopen */
-# else
-# ifndef fdopen
-# define fdopen(fd,mode) NULL /* No fdopen() */
+# ifndef Z_SOLO
+# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fdopen */
+# else
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
# endif
# endif
#endif
@@ -153,14 +161,14 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# endif
#endif
-#if defined(__BORLANDC__)
+#if defined(__BORLANDC__) && !defined(MSDOS)
#pragma warn -8004
#pragma warn -8008
#pragma warn -8066
#endif
/* provide prototypes for these when building zlib without LFS */
-#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
+#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
#endif
@@ -177,42 +185,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
/* functions */
-#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
-# ifndef HAVE_VSNPRINTF
-# define HAVE_VSNPRINTF
-# endif
-#endif
-#if defined(__CYGWIN__)
-# ifndef HAVE_VSNPRINTF
-# define HAVE_VSNPRINTF
-# endif
-#endif
-#ifndef HAVE_VSNPRINTF
-# ifdef MSDOS
- /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
- but for now we just assume it doesn't. */
-# define NO_vsnprintf
-# endif
-# ifdef __TURBOC__
-# define NO_vsnprintf
-# endif
-# ifdef WIN32
- /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
-# if !defined(vsnprintf) && !defined(NO_vsnprintf)
-# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
-# define vsnprintf _vsnprintf
-# endif
-# endif
-# endif
-# ifdef __SASC
-# define NO_vsnprintf
-# endif
-#endif
-#ifdef VMS
-# define NO_vsnprintf
-#endif
-
-#if defined(pyr)
+#if defined(pyr) || defined(Z_SOLO)
# define NO_MEMCPY
#endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@@ -261,14 +234,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
# define Tracecv(c,x)
#endif
-
-voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
- unsigned size));
-void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+#ifndef Z_SOLO
+ voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
+ unsigned size));
+ void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+#endif
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+/* Reverse the bytes in a 32-bit value */
+#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
+ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
+
#endif /* ZUTIL_H */