Thrift: Zlib transport.

Summary:
Add a new transport to the C++ library: TZLibTransport.
This wraps another transport (just like TBufferedTransport),
compresses the data written to it, and uncompresses the data it reads.

Reviewed By: mcslee

Test Plan:
For ax_lib_zlib.m4
 - Ran ./bootstrap.sh.
 - Looked at configure.
 - Ran ./configure.
 - Looked at config.status
 - Ran ./configure --with-zlib=/usr.
 - Looked at config.status
 - Changed configure.ac to AC_LIB_ZLIB(1.2.4)
 - Ran ./configure.
 - Watched it fail.

For TZlibTransport
 - test/ZlibTest.cpp
 - Code coverage (hotness) report sent with review.
 - 100% line coverage for all the good stuff.

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665262 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/aclocal/ax_event_base.m4 b/lib/cpp/aclocal/ax_event_base.m4
index 9d5c525..451058f 100644
--- a/lib/cpp/aclocal/ax_event_base.m4
+++ b/lib/cpp/aclocal/ax_event_base.m4
@@ -23,10 +23,10 @@
 AC_DEFUN([AX_EVENT_BASE],
 [
 AC_ARG_WITH([event],
-	AS_HELP_STRING([--with-event@<:@=DIR@:>@], [use event (default is yes) - it is possible to specify an alternate root directory for event]),
-	[
+        AS_HELP_STRING([--with-event@<:@=DIR@:>@], [use event (default is yes) - it is possible to specify an alternate root directory for event]),
+        [
     if test "$withval" = "no"; then
-    		want_event="no"
+                want_event="no"
     elif test "$withval" = "yes"; then
         want_event="yes"
         ac_event_path=""
@@ -38,47 +38,49 @@
     [want_event="yes"])
 
 if test "x$want_event" = "xyes"; then
-	event_lib_version_req=ifelse([$1], ,1.2.0,$1)
-	event_lib_version_req_shorten=`expr $event_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
-	event_lib_version_req_major=`expr $event_lib_version_req : '\([[0-9]]*\)'`
-	event_lib_version_req_minor=`expr $event_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
-	event_lib_version_req_sub_minor=`expr $event_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
-	if test "x$event_lib_version_req_sub_minor" = "x" ; then
-	    event_lib_version_req_sub_minor="0"
-    	fi
-	WANT_EVENT_VERSION=`expr $event_lib_version_req_major \* 10000 \+  $event_lib_version_req_minor \* 100 \+ $event_lib_version_req_sub_minor`
-	WANT_EVENT_MAJOR_VERSION=$event_lib_version_req_major
-	WANT_EVENT_MINOR_VERSION=$event_lib_version_req_minor
-	AC_MSG_CHECKING(for eventlib >= $event_lib_version_req)
-	succeeded=no
+        event_lib_version_req=ifelse([$1], ,1.2.0,$1)
+        event_lib_version_req_shorten=`expr $event_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
+        event_lib_version_req_major=`expr $event_lib_version_req : '\([[0-9]]*\)'`
+        event_lib_version_req_minor=`expr $event_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+        event_lib_version_req_sub_minor=`expr $event_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$event_lib_version_req_sub_minor" = "x" ; then
+            event_lib_version_req_sub_minor="0"
+        fi
+        WANT_EVENT_VERSION=`expr $event_lib_version_req_major \* 10000 \+  $event_lib_version_req_minor \* 100 \+ $event_lib_version_req_sub_minor`
+        WANT_EVENT_MAJOR_VERSION=$event_lib_version_req_major
+        WANT_EVENT_MINOR_VERSION=$event_lib_version_req_minor
+        AC_MSG_CHECKING(for eventlib >= $event_lib_version_req)
+        succeeded=no
         
-	if test "$ac_event_path" != "" && test -f "$ac_event_path/include/event.h"; then
-	    ac_event_include_path=$ac_event_path/include
-	    EVENT_CPPFLAGS="-I$ac_event_include_path"
-	    EVENT_LDFLAGS="-L$ac_event_path/lib -levent"
+        if test "$ac_event_path" != "" && test -f "$ac_event_path/include/event.h"; then
+            ac_event_include_path=$ac_event_path/include
+            EVENT_CPPFLAGS="-I$ac_event_include_path"
+            EVENT_LDFLAGS="-L$ac_event_path/lib -levent"
+            AC_MSG_RESULT(yes)
             succeeded=yes
-	else
-	    for ac_event_path_tmp in /usr /usr/local /opt ; do
-		if test -f "$ac_event_path_tmp/include/event.h"; then
-		    ac_event_include_path=$ac_event_path_tmp/include
-		    EVENT_CPPFLAGS="-I$ac_event_include_path"
-		    EVENT_LDFLAGS="-L$ac_event_path_tmp/lib -levent"
+        else
+            for ac_event_path_tmp in /usr /usr/local /opt ; do
+                if test -f "$ac_event_path_tmp/include/event.h"; then
+                    ac_event_include_path=$ac_event_path_tmp/include
+                    EVENT_CPPFLAGS="-I$ac_event_include_path"
+                    EVENT_LDFLAGS="-L$ac_event_path_tmp/lib -levent"
+                    AC_MSG_RESULT(yes)
                     succeeded=yes
-		    break;
-		fi
-	    done
-	fi
+                    break;
+                fi
+            done
+        fi
 
-	if test "$succeeded" != "yes" ; then
+        if test "$succeeded" != "yes" ; then
             AC_MSG_ERROR([[We could not detect the event libraries (version $event_lib_version_req_shorten or higher). If you have a staged event library (still not installed) please specify \$EVENT_ROOT in your environment and do not give a PATH to --with-event option.  If you are sure you have event installed, then check your version number looking in <event.h>. See http://www.monkey.org/~provos/libevent/ for more documentation.]])
-	else
+        else
             AC_SUBST(EVENT_CPPFLAGS)
-	    AC_SUBST(EVENT_LDFLAGS)
-	    AC_DEFINE(HAVE_EVENT,,[define if the EVENT library is available])
-	fi
+            AC_SUBST(EVENT_LDFLAGS)
+            AC_DEFINE(HAVE_EVENT,,[define if the EVENT library is available])
+        fi
 
         CPPFLAGS="$CPPFLAGS_SAVED"
-       	LDFLAGS="$LDFLAGS_SAVED"
+        LDFLAGS="$LDFLAGS_SAVED"
 fi
 
 ])
diff --git a/lib/cpp/aclocal/ax_lib_zlib.m4 b/lib/cpp/aclocal/ax_lib_zlib.m4
new file mode 100644
index 0000000..39d14cd
--- /dev/null
+++ b/lib/cpp/aclocal/ax_lib_zlib.m4
@@ -0,0 +1,160 @@
+dnl @synopsis AX_LIB_ZLIB([MINIMUM-VERSION])
+dnl
+dnl Test for the libz library of a particular version (or newer).
+dnl
+dnl If no path to the installed zlib is given, the macro will first try
+dnl using no -I or -L flags, then searches under /usr, /usr/local, /opt,
+dnl and /opt/zlib.
+dnl If these all fail, it will try the $ZLIB_ROOT environment variable.
+dnl
+dnl This macro calls:
+dnl   AC_SUBST(ZLIB_CPPFLAGS)
+dnl   AC_SUBST(ZLIB_LDFLAGS)
+dnl
+dnl And (if zlib is found):
+dnl   AC_DEFINE(HAVE_ZLIB)
+dnl
+dnl It also leaves the shell variable "success" set to "yes" or "no".
+dnl
+dnl NOTE: This macro does not currently work for cross-compiling,
+dnl       but it can be easily modified to allow it.
+dnl
+dnl @category InstalledPackages
+dnl @category C
+dnl @author David Reiss <dreiss@facebook.com>
+dnl @version 2007-09-12
+dnl @license AllPermissive
+
+dnl Input: ac_zlib_path, WANT_ZLIB_VERSION
+dnl Output: success=yes/no
+AC_DEFUN([AX_LIB_ZLIB_DO_CHECK],
+         [
+          # Set our flags if we are checking a specific directory.
+          if test -n "$ac_zlib_path" ; then
+            ZLIB_CPPFLAGS="-I$ac_zlib_path/include"
+            ZLIB_LDFLAGS="-L$ac_zlib_path/lib"
+          else
+            ZLIB_CPPFLAGS=""
+            ZLIB_LDFLAGS=""
+          fi
+
+          # Required flag for zlib.
+          ZLIB_LIBS="-lz"
+
+          # Prepare the environment for compilation.
+          CPPFLAGS="$CPPFLAGS $ZLIB_CPPFLAGS"
+          LDFLAGS="$LDFLAGS $ZLIB_LDFLAGS"
+          LIBS="$LIBS $ZLIB_LIBS"
+          export CPPFLAGS
+          export LDFLAGS
+          export LIBS
+
+          success=no
+
+          # Compile, link, and run the program.  This checks:
+          # - zlib.h is available for including.
+          # - zlibVersion() is available for linking.
+          # - ZLIB_VERNUM is greater than or equal to the desired version.
+          # - ZLIB_VERSION (defined in zlib.h) matches zlibVersion()
+          #   (defined in the library).
+          AC_LANG_PUSH([C])
+          dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling.
+          AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+          #include <zlib.h>
+          #if ZLIB_VERNUM >= 0x$WANT_ZLIB_VERSION
+          #else
+          # error zlib is too old
+          #endif
+          ]], [[
+          const char* lib_version = zlibVersion();
+          const char* hdr_version = ZLIB_VERSION;
+          for (;;) {
+            if (*lib_version != *hdr_version) {
+              return 1;
+            }
+            if (*lib_version == '\0') {
+              break;
+            }
+          }
+          return 0;
+          ]])], [
+          success=yes
+          ])
+          AC_LANG_POP([C])
+         ])
+
+
+AC_DEFUN([AX_LIB_ZLIB],
+         [
+
+          dnl Allow search path to be overridden on the command line.
+          AC_ARG_WITH([zlib],
+                      AS_HELP_STRING([--with-zlib@<:@=DIR@:>@], [use zlib (default is yes) - it is possible to specify an alternate root directory for zlib]),
+                      [
+                       if test "$withval" = "xno"; then
+                         want_zlib="no"
+                       elif test "$withval" = "xyes"; then
+                         want_zlib="yes"
+                         ac_zlib_path=""
+                       else
+                         want_zlib="yes"
+                         ac_zlib_path="$withval"
+                       fi
+                       ],
+                       [want_zlib="yes" ; ac_zlib_path="" ])
+
+
+          if test "$want_zlib" = "yes"; then
+            # Parse out the version.
+            zlib_version_req=ifelse([$1], ,1.2.3,$1)
+            zlib_version_req_major=`expr $zlib_version_req : '\([[0-9]]*\)'`
+            zlib_version_req_minor=`expr $zlib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+            zlib_version_req_patch=`expr $zlib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+            if test -z "$zlib_version_req_patch" ; then
+              zlib_version_req_patch="0"
+            fi
+            WANT_ZLIB_VERSION=`expr $zlib_version_req_major \* 1000 \+  $zlib_version_req_minor \* 100 \+ $zlib_version_req_patch \* 10`
+
+            AC_MSG_CHECKING(for zlib >= $zlib_version_req)
+
+            # Save our flags.
+            CPPFLAGS_SAVED="$CPPFLAGS"
+            LDFLAGS_SAVED="$LDFLAGS"
+            LIBS_SAVED="$LIBS"
+
+            # Run tests.
+            if test -n "$ac_zlib_path"; then
+              AX_LIB_ZLIB_DO_CHECK
+            else
+              for ac_zlib_path in "" /usr /usr/local /opt /opt/zlib ; do
+                AX_LIB_ZLIB_DO_CHECK
+                if test "$success" = "yes"; then
+                  break;
+                fi
+              done
+              if test "$success" = "no"; then
+                ac_zlib_path="$ZLIB_ROOT"
+                AX_LIB_ZLIB_DO_CHECK
+              fi
+            fi
+
+            # Restore flags.
+            CPPFLAGS="$CPPFLAGS_SAVED"
+            LDFLAGS="$LDFLAGS_SAVED"
+            LIBS="$LDFLAGS_LIBS"
+
+            if test "$success" != "yes" ; then
+              AC_MSG_RESULT(no)
+              ZLIB_CPPFLAGS=""
+              ZLIB_LDFLAGS=""
+            else
+              AC_MSG_RESULT(yes)
+              AC_DEFINE(HAVE_ZLIB,,[define if zlib is available])
+            fi
+
+            AC_SUBST(ZLIB_CPPFLAGS)
+            AC_SUBST(ZLIB_LDFLAGS)
+            AC_SUBST(ZLIB_LIBS)
+          fi
+
+          ])