1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/streamconv/converters/nsHTTPCompressConv.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#if !defined (__nsHTTPCompressConv__h__) 1.10 +#define __nsHTTPCompressConv__h__ 1 1.11 + 1.12 +#include "nsIStreamConverter.h" 1.13 +#include "nsCOMPtr.h" 1.14 + 1.15 +#include "zlib.h" 1.16 + 1.17 +class nsIStringInputStream; 1.18 + 1.19 +#define NS_HTTPCOMPRESSCONVERTER_CID \ 1.20 +{ \ 1.21 + /* 66230b2b-17fa-4bd3-abf4-07986151022d */ \ 1.22 + 0x66230b2b, \ 1.23 + 0x17fa, \ 1.24 + 0x4bd3, \ 1.25 + {0xab, 0xf4, 0x07, 0x98, 0x61, 0x51, 0x02, 0x2d}\ 1.26 +} 1.27 + 1.28 + 1.29 +#define HTTP_DEFLATE_TYPE "deflate" 1.30 +#define HTTP_GZIP_TYPE "gzip" 1.31 +#define HTTP_X_GZIP_TYPE "x-gzip" 1.32 +#define HTTP_COMPRESS_TYPE "compress" 1.33 +#define HTTP_X_COMPRESS_TYPE "x-compress" 1.34 +#define HTTP_IDENTITY_TYPE "identity" 1.35 +#define HTTP_UNCOMPRESSED_TYPE "uncompressed" 1.36 + 1.37 +typedef enum { 1.38 + HTTP_COMPRESS_GZIP, 1.39 + HTTP_COMPRESS_DEFLATE, 1.40 + HTTP_COMPRESS_COMPRESS, 1.41 + HTTP_COMPRESS_IDENTITY 1.42 + } CompressMode; 1.43 + 1.44 +class nsHTTPCompressConv : public nsIStreamConverter { 1.45 +public: 1.46 + // nsISupports methods 1.47 + NS_DECL_THREADSAFE_ISUPPORTS 1.48 + 1.49 + NS_DECL_NSIREQUESTOBSERVER 1.50 + NS_DECL_NSISTREAMLISTENER 1.51 + 1.52 + // nsIStreamConverter methods 1.53 + NS_DECL_NSISTREAMCONVERTER 1.54 + 1.55 + 1.56 + nsHTTPCompressConv (); 1.57 + virtual ~nsHTTPCompressConv (); 1.58 + 1.59 +private: 1.60 + 1.61 + nsIStreamListener *mListener; // this guy gets the converted data via his OnDataAvailable () 1.62 + CompressMode mMode; 1.63 + 1.64 + unsigned char *mOutBuffer; 1.65 + unsigned char *mInpBuffer; 1.66 + 1.67 + uint32_t mOutBufferLen; 1.68 + uint32_t mInpBufferLen; 1.69 + 1.70 + nsCOMPtr<nsISupports> mAsyncConvContext; 1.71 + nsCOMPtr<nsIStringInputStream> mStream; 1.72 + 1.73 + nsresult do_OnDataAvailable (nsIRequest *request, nsISupports *aContext, 1.74 + uint64_t aSourceOffset, const char *buffer, 1.75 + uint32_t aCount); 1.76 + 1.77 + bool mCheckHeaderDone; 1.78 + bool mStreamEnded; 1.79 + bool mStreamInitialized; 1.80 + bool mDummyStreamInitialised; 1.81 + 1.82 + z_stream d_stream; 1.83 + unsigned mLen, hMode, mSkipCount, mFlags; 1.84 + 1.85 + uint32_t check_header (nsIInputStream *iStr, uint32_t streamLen, nsresult *rv); 1.86 +}; 1.87 + 1.88 + 1.89 +#endif