netwerk/streamconv/converters/nsHTTPCompressConv.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:3e8ec305b3fc
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #if !defined (__nsHTTPCompressConv__h__)
7 #define __nsHTTPCompressConv__h__ 1
8
9 #include "nsIStreamConverter.h"
10 #include "nsCOMPtr.h"
11
12 #include "zlib.h"
13
14 class nsIStringInputStream;
15
16 #define NS_HTTPCOMPRESSCONVERTER_CID \
17 { \
18 /* 66230b2b-17fa-4bd3-abf4-07986151022d */ \
19 0x66230b2b, \
20 0x17fa, \
21 0x4bd3, \
22 {0xab, 0xf4, 0x07, 0x98, 0x61, 0x51, 0x02, 0x2d}\
23 }
24
25
26 #define HTTP_DEFLATE_TYPE "deflate"
27 #define HTTP_GZIP_TYPE "gzip"
28 #define HTTP_X_GZIP_TYPE "x-gzip"
29 #define HTTP_COMPRESS_TYPE "compress"
30 #define HTTP_X_COMPRESS_TYPE "x-compress"
31 #define HTTP_IDENTITY_TYPE "identity"
32 #define HTTP_UNCOMPRESSED_TYPE "uncompressed"
33
34 typedef enum {
35 HTTP_COMPRESS_GZIP,
36 HTTP_COMPRESS_DEFLATE,
37 HTTP_COMPRESS_COMPRESS,
38 HTTP_COMPRESS_IDENTITY
39 } CompressMode;
40
41 class nsHTTPCompressConv : public nsIStreamConverter {
42 public:
43 // nsISupports methods
44 NS_DECL_THREADSAFE_ISUPPORTS
45
46 NS_DECL_NSIREQUESTOBSERVER
47 NS_DECL_NSISTREAMLISTENER
48
49 // nsIStreamConverter methods
50 NS_DECL_NSISTREAMCONVERTER
51
52
53 nsHTTPCompressConv ();
54 virtual ~nsHTTPCompressConv ();
55
56 private:
57
58 nsIStreamListener *mListener; // this guy gets the converted data via his OnDataAvailable ()
59 CompressMode mMode;
60
61 unsigned char *mOutBuffer;
62 unsigned char *mInpBuffer;
63
64 uint32_t mOutBufferLen;
65 uint32_t mInpBufferLen;
66
67 nsCOMPtr<nsISupports> mAsyncConvContext;
68 nsCOMPtr<nsIStringInputStream> mStream;
69
70 nsresult do_OnDataAvailable (nsIRequest *request, nsISupports *aContext,
71 uint64_t aSourceOffset, const char *buffer,
72 uint32_t aCount);
73
74 bool mCheckHeaderDone;
75 bool mStreamEnded;
76 bool mStreamInitialized;
77 bool mDummyStreamInitialised;
78
79 z_stream d_stream;
80 unsigned mLen, hMode, mSkipCount, mFlags;
81
82 uint32_t check_header (nsIInputStream *iStr, uint32_t streamLen, nsresult *rv);
83 };
84
85
86 #endif

mercurial