Author: siwuzzz
Date: Mon Jul  9 17:09:55 2007
New Revision: 205

Added:
   trunk/clients/cs/lib/Mobile/WindowsMobile/zlib.arm.dll   (contents, props 
changed)
   trunk/clients/cs/lib/Release/zlib.x86.dll   (contents, props changed)
   trunk/clients/cs/src/core/gzipstream.cs
Modified:
   trunk/clients/cs/RELEASE_NOTES.txt
   trunk/clients/cs/readme.txt
   trunk/clients/cs/src/VS2003/gdata/gdata.csproj
   trunk/clients/cs/src/VS2005.mobile/GDataMobile/GDataMobile.csproj
   trunk/clients/cs/src/core/request.cs
   trunk/clients/cs/src/core/serviceinterface.cs

Log:
src/core/gzipstream.cs:
- Custom implementation of GZipStream. Read only.

src/core/request.cs:
- Added UseGZip property to GDataRequest and GDataRequestFactory.

src/core/serviceinterface.cs:
- Added UseGZip property to IGDataRequest and IGDataRequestFactory.

lib/Release/zlib.x86.dll, lib/WindowsMobile/zlib.arm.dll:
- Added Windows (zlib.x86.dll) and Windows Mobile 5 (zlib.arm.dll) zlib dlls.
- Each has to be placed in the same directory as Google.GData.Client.dll 
(depending on what version you use)

readme.txt:
- Added zlib license, and greetings

RELEASE_NOTES.txt:
- Added gzip capability

Modified: trunk/clients/cs/RELEASE_NOTES.txt
==============================================================================
--- trunk/clients/cs/RELEASE_NOTES.txt  (original)
+++ trunk/clients/cs/RELEASE_NOTES.txt  Mon Jul  9 17:09:55 2007
@@ -1,4 +1,5 @@
 == 1.0.9.9 ==
+- added GZip support for .NET 1.1, 2.0 and .NET Compact Framework 2.0 (see 
readme).
 - added GBase support for m:adjusted_name and gm:adjusted_value inside 
attributes
   (returned only when adjustments are enabled)
 - Google Apps changes:

Added: trunk/clients/cs/lib/Mobile/WindowsMobile/zlib.arm.dll
==============================================================================
Binary file. No diff available.

Added: trunk/clients/cs/lib/Release/zlib.x86.dll
==============================================================================
Binary file. No diff available.

Modified: trunk/clients/cs/readme.txt
==============================================================================
--- trunk/clients/cs/readme.txt (original)
+++ trunk/clients/cs/readme.txt Mon Jul  9 17:09:55 2007
@@ -13,6 +13,36 @@
  * limitations under the License.
 */
 
+
+This program makes use of the zlib compression library made by Jean-loup Gailly
+and Mark Adler. See license.
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+*  version 1.2.3, July 18th, 2005
+*
+*  Copyright (C) 1995-2005 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
+*  arising from the use of this software.
+*
+*  Permission is granted to anyone to use this software for any purpose,
+*  including commercial applications, and to alter it and redistribute it
+*  freely, subject to the following restrictions:
+*
+*  1. 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.
+*  2. Altered source versions must be plainly marked as such, and must not be
+*     misrepresented as being the original software.
+*  3. This notice may not be removed or altered from any source distribution.
+*
+*  Jean-loup Gailly [EMAIL PROTECTED]
+*  Mark Adler [EMAIL PROTECTED]
+*
+*/
+
+
 The C# code is developed and tested using .NET 1.1, and Mono version
 1.1.13.2, on the Macintosh OS X. It should build and run on any platform that 
has
 Mono available.
@@ -132,6 +162,4 @@
             }
         }
 
-For more details check the online documentation for batch and look into the 
unittests/gbase.cs file. 
-
-        
+For more details check the online documentation for batch and look into the 
unittests/gbase.cs file.
\ No newline at end of file

Modified: trunk/clients/cs/src/VS2003/gdata/gdata.csproj
==============================================================================
--- trunk/clients/cs/src/VS2003/gdata/gdata.csproj      (original)
+++ trunk/clients/cs/src/VS2003/gdata/gdata.csproj      Mon Jul  9 17:09:55 2007
@@ -1,7 +1,7 @@
 <VisualStudioProject>
     <CSHARP
         ProjectType = "Local"
-        ProductVersion = "7.10.6030"
+        ProductVersion = "7.10.3077"
         SchemaVersion = "2.0"
         ProjectGuid = "{B6F6D938-0D45-42BA-8A67-55D92EF03995}"
     >
@@ -298,6 +298,12 @@
                 <File
                     RelPath = "gdatabatch.cs"
                     Link = "..\..\core\gdatabatch.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "gzipstream.cs"
+                    Link = "..\..\core\gzipstream.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
                 />

Modified: trunk/clients/cs/src/VS2005.mobile/GDataMobile/GDataMobile.csproj
==============================================================================
--- trunk/clients/cs/src/VS2005.mobile/GDataMobile/GDataMobile.csproj   
(original)
+++ trunk/clients/cs/src/VS2005.mobile/GDataMobile/GDataMobile.csproj   Mon Jul 
 9 17:09:55 2007
@@ -141,6 +141,9 @@
     <Compile Include="..\..\core\gdatabatch.cs">
       <Link>gdatabatch.cs</Link>
     </Compile>
+    <Compile Include="..\..\core\gzipstream.cs">
+      <Link>gzipstream.cs</Link>
+    </Compile>
     <Compile Include="..\..\core\HttpUtility.cs">
       <Link>HttpUtility.cs</Link>
     </Compile>

Added: trunk/clients/cs/src/core/gzipstream.cs
==============================================================================
--- (empty file)
+++ trunk/clients/cs/src/core/gzipstream.cs     Mon Jul  9 17:09:55 2007
@@ -0,0 +1,259 @@
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace Google.GData.Client
+{
+    public enum CompressionMode
+       {
+        Compress,
+        Decompress,
+       }
+
+    public class GZipStream : Stream
+    {
+        #region Native const, structs, and defs
+        private const string ZLibVersion = "1.2.3";
+
+        private enum ZLibReturnCode
+        {
+            Ok = 0,
+            StreamEnd = 1,
+            NeedDictionary = 2,
+            Errno = -1,
+            StreamError = -2,
+            DataError = -3,
+            MemoryError = -4,
+            BufferError = -5,
+            VersionError = -6
+        }
+
+        private enum ZLibFlush
+        {
+            NoFlush = 0,
+            PartialFlush = 1,
+            SyncFlush = 2,
+            FullFlush = 3,
+            Finish = 4
+        }
+
+        private enum ZLibCompressionLevel
+        {
+            NoCompression = 0,
+            BestSpeed = 1,
+            BestCompression = 2,
+            DefaultCompression = 3
+        }
+
+        private enum ZLibCompressionStrategy
+        {
+            Filtered = 1,
+            HuffmanOnly = 2,
+            DefaultStrategy = 0
+        }
+
+        private enum ZLibCompressionMethod
+        {
+            Delated = 8
+        }
+
+        private enum ZLibDataType
+        {
+            Binary = 0,
+            Ascii = 1,
+            Unknown = 2,
+        }
+
+        private enum ZLibOpenType
+        {
+            ZLib = 15,
+            GZip = 15 + 16,
+            Both = 15 + 32,
+        }
+
+
+        [StructLayoutAttribute(LayoutKind.Sequential)]
+        private struct z_stream
+        {
+            public IntPtr next_in;  /* next input byte */
+            public uint avail_in;  /* number of bytes available at next_in */
+            public uint total_in;  /* total nb of input bytes read so far */
+
+            public IntPtr next_out; /* next output byte should be put there */
+            public uint avail_out; /* remaining free space at next_out */
+            public uint total_out; /* total nb of bytes output so far */
+
+            public IntPtr msg;      /* last error message, NULL if no error */
+            public IntPtr state; /* not visible by applications */
+
+            public IntPtr zalloc;  /* used to allocate the internal state */
+            public IntPtr zfree;   /* used to free the internal state */
+            public IntPtr opaque;  /* private data object passed to zalloc and 
zfree */
+
+            public ZLibDataType data_type;  /* best guess about the data type: 
ascii or binary */
+            public uint adler;      /* adler32 value of the uncompressed data 
*/
+            public uint reserved;   /* reserved for future use */
+        };
+        #endregion
+
+        #region P/Invoke
+#if WindowsCE || PocketPC
+        [DllImport("zlib.arm.dll", EntryPoint = "inflateInit2_", CharSet = 
CharSet.Auto)]
+#else
+        [DllImport("zlib.x86.dll", EntryPoint = "inflateInit2_", CharSet = 
CharSet.Ansi)]
+#endif
+        private static extern ZLibReturnCode    inflateInit2(ref z_stream 
strm, ZLibOpenType windowBits, string version, int stream_size);
+
+#if WindowsCE || PocketPC
+        [DllImport("zlib.arm.dll", CharSet = CharSet.Auto)]
+#else
+        [DllImport("zlib.x86.dll", CharSet = CharSet.Ansi)]
+#endif
+        private static extern ZLibReturnCode     inflate(ref z_stream strm, 
ZLibFlush flush);
+
+#if WindowsCE || PocketPC
+        [DllImport("zlib.arm.dll", CharSet = CharSet.Auto)]
+#else
+        [DllImport("zlib.x86.dll", CharSet = CharSet.Ansi)]
+#endif
+        private static extern ZLibReturnCode    inflateEnd(ref z_stream strm);
+        #endregion
+
+        private const int           BufferSize = 16384;
+
+        private Stream              compressedStream;
+        private CompressionMode     mode;
+
+        private z_stream            zstream = new z_stream();
+
+        private byte[]              inputBuffer = new byte[BufferSize];
+        private GCHandle            inputBufferHandle;
+
+        public GZipStream(Stream stream, CompressionMode mode)
+        {
+            this.compressedStream = stream;
+            this.mode = mode;
+
+            this.inputBufferHandle = GCHandle.Alloc(inputBuffer, 
GCHandleType.Pinned);
+
+            this.zstream.zalloc = IntPtr.Zero;
+            this.zstream.zfree = IntPtr.Zero;
+            this.zstream.opaque = IntPtr.Zero;
+
+            inflateInit2(ref this.zstream, ZLibOpenType.Both, ZLibVersion, 
Marshal.SizeOf(typeof(z_stream)));
+        }
+
+        ~GZipStream()
+        {
+            inputBufferHandle.Free();
+            inflateEnd(ref this.zstream);
+        }
+
+        public override int Read(byte[] buffer, int offset, int count)
+        {
+            if (this.mode == CompressionMode.Compress)
+                throw new NotSupportedException("Can't read on a compress 
stream!");
+
+            bool exitLoop = false;
+
+            byte[] tmpOutputBuffer = new byte[count];
+            GCHandle tmpOutpuBufferHandle = GCHandle.Alloc(tmpOutputBuffer, 
GCHandleType.Pinned);
+
+            this.zstream.next_out = tmpOutpuBufferHandle.AddrOfPinnedObject();
+            this.zstream.avail_out = (uint)tmpOutputBuffer.Length;
+
+            try
+            {
+                while (this.zstream.avail_out > 0 && exitLoop == false)
+                {
+                    if (this.zstream.avail_in == 0)
+                    {
+                        int readLength = 
this.compressedStream.Read(inputBuffer, 0, inputBuffer.Length);
+                        this.zstream.avail_in = (uint)readLength;
+                        this.zstream.next_in = 
this.inputBufferHandle.AddrOfPinnedObject();
+                    }
+                    ZLibReturnCode  result = inflate(ref zstream, 
ZLibFlush.NoFlush);
+                    switch (result)
+                    {
+                        case ZLibReturnCode.StreamEnd:
+                            exitLoop = true;
+                            Array.Copy(tmpOutputBuffer, 0, buffer, offset, 
count - (int)this.zstream.avail_out);
+                            break;
+                        case ZLibReturnCode.Ok:
+                            Array.Copy(tmpOutputBuffer, 0, buffer, offset, 
count - (int)this.zstream.avail_out);
+                            break;
+                        case ZLibReturnCode.MemoryError:
+                            throw new OutOfMemoryException();
+                        default:
+                            throw new Exception("Zlib Return Code: " + 
result.ToString());
+                    }
+                }
+
+                return (count - (int)this.zstream.avail_out);
+            }
+            finally
+            {
+                tmpOutpuBufferHandle.Free();
+            }
+        }
+
+        public override void Close()
+        {
+            this.compressedStream.Close();
+            base.Close();
+        }
+
+        public override bool CanRead
+        {
+            get { return (this.mode == CompressionMode.Decompress ? true : 
false); }
+        }
+
+        public override bool CanWrite
+        {
+            get { return (this.mode == CompressionMode.Compress ? true : 
false); }
+        }
+
+        public override bool CanSeek
+        {
+            get { return (false); }
+        }
+
+        public Stream BaseStream
+        {
+            get { return (this.compressedStream); }
+        }
+
+        #region Not yet supported
+        public override void Flush()
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        public override long Seek(long offset, SeekOrigin origin)
+        {
+            throw new NotSupportedException();
+        }
+
+        public override void SetLength(long value)
+        {
+            throw new NotSupportedException();
+        }
+
+        public override void Write(byte[] buffer, int offset, int count)
+        {
+            throw new NotSupportedException("Not yet supported!");
+        }
+
+        public override long Length
+        {
+            get { throw new NotSupportedException(); }
+        }
+
+        public override long Position
+        {
+            get { throw new NotSupportedException(); }
+            set { throw new NotSupportedException(); }
+        }
+        #endregion
+    }
+}
\ No newline at end of file

Modified: trunk/clients/cs/src/core/request.cs
==============================================================================
--- trunk/clients/cs/src/core/request.cs        (original)
+++ trunk/clients/cs/src/core/request.cs        Mon Jul  9 17:09:55 2007
@@ -44,7 +44,8 @@
         private StringCollection customHeaders;     // holds any custom 
headers to set
         private String shardingCookie;              // holds the sharding 
cookie if returned
         private WebProxy webProxy;                  // holds a webproxy to use
-        private bool keepAlive;                     // indicates wether or not 
to keep the connection alive    
+        private bool keepAlive;                     // indicates wether or not 
to keep the connection alive
+           private bool useGZip;
 
         /// <summary>Cookie setting header, returned from server</summary>
         public const string SetCookieHeader = "Set-Cookie"; 
@@ -80,6 +81,17 @@
         }
         
/////////////////////////////////////////////////////////////////////////////
 
+
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>set wether or not new request should use GZip</summary>
+        //////////////////////////////////////////////////////////////////////
+        public bool UseGZip
+        {
+            get { return (this.useGZip); }
+            set { this.useGZip = value; }
+        }
+        //////////////////////////////////////////////////////////////////////
+
         //////////////////////////////////////////////////////////////////////
         /// <summary>set's and get's the sharding cookie</summary> 
         /// <returns> </returns>
@@ -98,7 +110,12 @@
         //////////////////////////////////////////////////////////////////////
         public string UserAgent
         {
-            get {return this.userAgent;}
+            get
+            {
+                if (this.useGZip == true)
+                    return this.userAgent + " (gzip)";
+                return this.userAgent;
+            }
             set {this.userAgent = value;}
         }
         
/////////////////////////////////////////////////////////////////////////////
@@ -175,8 +192,10 @@
         private GDataRequestFactory factory; // holds the factory to use
         /// <summary>holds if we are disposed</summary> 
         protected bool disposed; 
+        /// <summary>set wheter or not this request should use GZip</summary>
+        private bool useGZip;
 
-
+        private GZipStream  gzippedStream;
 
    
         //////////////////////////////////////////////////////////////////////
@@ -187,6 +206,7 @@
             this.type = type;
             this.targetUri = uriTarget;
             this.factory = factory; 
+            this.useGZip = this.factory.UseGZip; // use gzip setting from 
factory
         }
         
/////////////////////////////////////////////////////////////////////////////
 
@@ -218,8 +238,15 @@
         }
         //////////////////////////////////////////////////////////////////////
 
-
-
+        //////////////////////////////////////////////////////////////////////
+        /// <summary>set wether or not this request should use GZip</summary>
+        //////////////////////////////////////////////////////////////////////
+        public bool UseGZip
+        {
+            get { return (this.useGZip); }
+            set { this.useGZip = value; }
+        }
+        //////////////////////////////////////////////////////////////////////
         
         //////////////////////////////////////////////////////////////////////
         /// <summary>does the real disposition</summary> 
@@ -296,9 +323,8 @@
         //////////////////////////////////////////////////////////////////////
         public virtual Stream GetRequestStream()
         {
-
             EnsureWebRequest();
-            this.requestStream = this.webRequest.GetRequestStream() ;
+            this.requestStream = this.webRequest.GetRequestStream();
             return this.requestStream; 
         }
         
/////////////////////////////////////////////////////////////////////////////
@@ -337,6 +363,13 @@
                             break;
     
                     }
+                    if (this.useGZip == true)
+                    {
+                        // Hack to get around the GFE bug
+                        web.Accept = "text/xml";
+                        /////////////////////////////////
+                        web.Headers.Add("Accept-Encoding", "gzip");
+                    }
                     web.ContentType = "application/atom+xml; charset=UTF-8";
                     web.UserAgent = this.factory.UserAgent;
                     web.KeepAlive = this.factory.KeepAlive; 
@@ -398,6 +431,8 @@
                 }
                 Tracing.TraceCall("calling the real execution over the 
webresponse");
                 this.webResponse = this.webRequest.GetResponse(); 
+                if (this.webResponse != null)
+                    this.useGZip = 
(string.Compare(((HttpWebResponse)this.webResponse).ContentEncoding, "gzip", 
true) == 0);
             }
             catch (WebException e)
             {
@@ -475,7 +510,17 @@
         //////////////////////////////////////////////////////////////////////
         public virtual Stream GetResponseStream()
         {
-            return this.webResponse != null ? 
this.webResponse.GetResponseStream() : null;
+            if (this.webResponse == null)
+                return (null);
+
+            if (this.useGZip == true)
+            {
+                if (this.gzippedStream == null)
+                    this.gzippedStream = new 
GZipStream(this.webResponse.GetResponseStream(), CompressionMode.Decompress);
+                return (this.gzippedStream);
+            }
+            else
+                return this.webResponse.GetResponseStream();
         }
         
/////////////////////////////////////////////////////////////////////////////
 

Modified: trunk/clients/cs/src/core/serviceinterface.cs
==============================================================================
--- trunk/clients/cs/src/core/serviceinterface.cs       (original)
+++ trunk/clients/cs/src/core/serviceinterface.cs       Mon Jul  9 17:09:55 2007
@@ -73,6 +73,12 @@
     {
         /// <summary>creation method for GDatarequests</summary> 
         IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget); 
+        /// <summary>set wether or not to use gzip for new requests</summary>
+        bool    UseGZip
+        {
+            get;
+            set;
+        }
     }
     //////////////////////////////////////////////////////////////////////
 
@@ -105,6 +111,12 @@
     {
         /// <summary>get/set for credentials to the service calls. Get's 
passed through to GDatarequest</summary> 
         ICredentials Credentials 
+        {
+            get;
+            set;
+        }
+        /// <summary>set wether or not to use gzip for this request</summary>
+        bool UseGZip
         {
             get;
             set;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to