michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #if !defined (__nsHTTPCompressConv__h__) michael@0: #define __nsHTTPCompressConv__h__ 1 michael@0: michael@0: #include "nsIStreamConverter.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: #include "zlib.h" michael@0: michael@0: class nsIStringInputStream; michael@0: michael@0: #define NS_HTTPCOMPRESSCONVERTER_CID \ michael@0: { \ michael@0: /* 66230b2b-17fa-4bd3-abf4-07986151022d */ \ michael@0: 0x66230b2b, \ michael@0: 0x17fa, \ michael@0: 0x4bd3, \ michael@0: {0xab, 0xf4, 0x07, 0x98, 0x61, 0x51, 0x02, 0x2d}\ michael@0: } michael@0: michael@0: michael@0: #define HTTP_DEFLATE_TYPE "deflate" michael@0: #define HTTP_GZIP_TYPE "gzip" michael@0: #define HTTP_X_GZIP_TYPE "x-gzip" michael@0: #define HTTP_COMPRESS_TYPE "compress" michael@0: #define HTTP_X_COMPRESS_TYPE "x-compress" michael@0: #define HTTP_IDENTITY_TYPE "identity" michael@0: #define HTTP_UNCOMPRESSED_TYPE "uncompressed" michael@0: michael@0: typedef enum { michael@0: HTTP_COMPRESS_GZIP, michael@0: HTTP_COMPRESS_DEFLATE, michael@0: HTTP_COMPRESS_COMPRESS, michael@0: HTTP_COMPRESS_IDENTITY michael@0: } CompressMode; michael@0: michael@0: class nsHTTPCompressConv : public nsIStreamConverter { michael@0: public: michael@0: // nsISupports methods michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: michael@0: // nsIStreamConverter methods michael@0: NS_DECL_NSISTREAMCONVERTER michael@0: michael@0: michael@0: nsHTTPCompressConv (); michael@0: virtual ~nsHTTPCompressConv (); michael@0: michael@0: private: michael@0: michael@0: nsIStreamListener *mListener; // this guy gets the converted data via his OnDataAvailable () michael@0: CompressMode mMode; michael@0: michael@0: unsigned char *mOutBuffer; michael@0: unsigned char *mInpBuffer; michael@0: michael@0: uint32_t mOutBufferLen; michael@0: uint32_t mInpBufferLen; michael@0: michael@0: nsCOMPtr mAsyncConvContext; michael@0: nsCOMPtr mStream; michael@0: michael@0: nsresult do_OnDataAvailable (nsIRequest *request, nsISupports *aContext, michael@0: uint64_t aSourceOffset, const char *buffer, michael@0: uint32_t aCount); michael@0: michael@0: bool mCheckHeaderDone; michael@0: bool mStreamEnded; michael@0: bool mStreamInitialized; michael@0: bool mDummyStreamInitialised; michael@0: michael@0: z_stream d_stream; michael@0: unsigned mLen, hMode, mSkipCount, mFlags; michael@0: michael@0: uint32_t check_header (nsIInputStream *iStr, uint32_t streamLen, nsresult *rv); michael@0: }; michael@0: michael@0: michael@0: #endif