• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // FilterCoder.h
2 
3 #ifndef ZIP7_INC_FILTER_CODER_H
4 #define ZIP7_INC_FILTER_CODER_H
5 
6 #include "../../../C/Alloc.h"
7 
8 #include "../../Common/MyCom.h"
9 #include "../ICoder.h"
10 
11 #ifndef Z7_NO_CRYPTO
12 #include "../IPassword.h"
13 #endif
14 
15 #define Z7_COM_QI_ENTRY_AG(i, sub0, sub) else if (iid == IID_ ## i) \
16   { if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
17     *outObject = (void *)(i *)this; }
18 
19 
20 struct CAlignedMidBuffer
21 {
22   Byte *_buf;
23 
CAlignedMidBufferCAlignedMidBuffer24   CAlignedMidBuffer(): _buf(NULL) {}
25   ~CAlignedMidBuffer();
26   void AllocAligned(size_t size);
27 };
28 
29 
30 class CFilterCoder Z7_final :
31   public ICompressCoder,
32 
33   public ICompressSetOutStreamSize,
34   public ICompressInitEncoder,
35 
36   public ICompressSetInStream,
37   public ISequentialInStream,
38 
39   public ICompressSetOutStream,
40   public ISequentialOutStream,
41   public IOutStreamFinish,
42 
43   public ICompressSetBufSize,
44 
45   #ifndef Z7_NO_CRYPTO
46   public ICryptoSetPassword,
47   public ICryptoProperties,
48   #endif
49 
50   #ifndef Z7_EXTRACT_ONLY
51   public ICompressSetCoderProperties,
52   public ICompressWriteCoderProperties,
53   public ICompressSetCoderPropertiesOpt,
54   // public ICryptoResetSalt,
55   public ICryptoResetInitVector,
56   #endif
57 
58   public ICompressSetDecoderProperties2,
59   public CMyUnknownImp,
60   public CAlignedMidBuffer
61 {
62   UInt32 _bufSize;
63   UInt32 _inBufSize;
64   UInt32 _outBufSize;
65 
66   bool _encodeMode;
67   bool _outSize_Defined;
68   UInt64 _outSize;
69   UInt64 _nowPos64;
70 
71   CMyComPtr<ISequentialInStream> _inStream;
72   CMyComPtr<ISequentialOutStream> _outStream;
73   UInt32 _bufPos;
74   UInt32 _convPos;    // current pos in buffer for converted data
75   UInt32 _convSize;   // size of converted data starting from _convPos
76 
InitSpecVars()77   void InitSpecVars()
78   {
79     _bufPos = 0;
80     _convPos = 0;
81     _convSize = 0;
82 
83     _outSize_Defined = false;
84     _outSize = 0;
85     _nowPos64 = 0;
86   }
87 
88   HRESULT Alloc();
89   HRESULT Init_and_Alloc();
90   HRESULT Flush2();
91 
92   #ifndef Z7_NO_CRYPTO
93   CMyComPtr<ICryptoSetPassword> _setPassword;
94   CMyComPtr<ICryptoProperties> _cryptoProperties;
95   #endif
96 
97   #ifndef Z7_EXTRACT_ONLY
98   CMyComPtr<ICompressSetCoderProperties> _setCoderProperties;
99   CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;
100   CMyComPtr<ICompressSetCoderPropertiesOpt> _setCoderPropertiesOpt;
101   // CMyComPtr<ICryptoResetSalt> _cryptoResetSalt;
102   CMyComPtr<ICryptoResetInitVector> _cryptoResetInitVector;
103   #endif
104 
105   CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties2;
106 
107 public:
108   CMyComPtr<ICompressFilter> Filter;
109 
110   CFilterCoder(bool encodeMode);
111 
112   struct C_InStream_Releaser
113   {
114     CFilterCoder *FilterCoder;
C_InStream_ReleaserC_InStream_Releaser115     C_InStream_Releaser(): FilterCoder(NULL) {}
~C_InStream_ReleaserC_InStream_Releaser116     ~C_InStream_Releaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }
117   };
118 
119   struct C_OutStream_Releaser
120   {
121     CFilterCoder *FilterCoder;
C_OutStream_ReleaserC_OutStream_Releaser122     C_OutStream_Releaser(): FilterCoder(NULL) {}
~C_OutStream_ReleaserC_OutStream_Releaser123     ~C_OutStream_Releaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }
124   };
125 
126   struct C_Filter_Releaser
127   {
128     CFilterCoder *FilterCoder;
C_Filter_ReleaserC_Filter_Releaser129     C_Filter_Releaser(): FilterCoder(NULL) {}
~C_Filter_ReleaserC_Filter_Releaser130     ~C_Filter_Releaser() { if (FilterCoder) FilterCoder->Filter.Release(); }
131   };
132 
133 private:
134   Z7_COM_QI_BEGIN2(ICompressCoder)
135 
136     Z7_COM_QI_ENTRY(ICompressSetOutStreamSize)
137     Z7_COM_QI_ENTRY(ICompressInitEncoder)
138 
139     Z7_COM_QI_ENTRY(ICompressSetInStream)
140     Z7_COM_QI_ENTRY(ISequentialInStream)
141 
142     Z7_COM_QI_ENTRY(ICompressSetOutStream)
143     Z7_COM_QI_ENTRY(ISequentialOutStream)
144     Z7_COM_QI_ENTRY(IOutStreamFinish)
145 
146     Z7_COM_QI_ENTRY(ICompressSetBufSize)
147 
148     #ifndef Z7_NO_CRYPTO
149     Z7_COM_QI_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)
150     Z7_COM_QI_ENTRY_AG(ICryptoProperties, Filter, _cryptoProperties)
151     #endif
152 
153     #ifndef Z7_EXTRACT_ONLY
154     Z7_COM_QI_ENTRY_AG(ICompressSetCoderProperties, Filter, _setCoderProperties)
155     Z7_COM_QI_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)
156     Z7_COM_QI_ENTRY_AG(ICompressSetCoderPropertiesOpt, Filter, _setCoderPropertiesOpt)
157     // Z7_COM_QI_ENTRY_AG(ICryptoResetSalt, Filter, _cryptoResetSalt)
158     Z7_COM_QI_ENTRY_AG(ICryptoResetInitVector, Filter, _cryptoResetInitVector)
159     #endif
160 
161     Z7_COM_QI_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties2)
162   Z7_COM_QI_END
163   Z7_COM_ADDREF_RELEASE
164 
165 public:
166   Z7_IFACE_COM7_IMP(ICompressCoder)
167   Z7_IFACE_COM7_IMP(ICompressSetOutStreamSize)
168   Z7_IFACE_COM7_IMP(ICompressInitEncoder)
169   Z7_IFACE_COM7_IMP(ICompressSetInStream)
170 private:
171   Z7_IFACE_COM7_IMP(ISequentialInStream)
172 public:
173   Z7_IFACE_COM7_IMP(ICompressSetOutStream)
174 private:
175   Z7_IFACE_COM7_IMP(ISequentialOutStream)
176 public:
177   Z7_IFACE_COM7_IMP(IOutStreamFinish)
178 private:
179 
180   Z7_IFACE_COM7_IMP(ICompressSetBufSize)
181 
182   #ifndef Z7_NO_CRYPTO
183   Z7_IFACE_COM7_IMP(ICryptoSetPassword)
184   Z7_IFACE_COM7_IMP(ICryptoProperties)
185   #endif
186 
187   #ifndef Z7_EXTRACT_ONLY
188   Z7_IFACE_COM7_IMP(ICompressSetCoderProperties)
189   Z7_IFACE_COM7_IMP(ICompressWriteCoderProperties)
190   Z7_IFACE_COM7_IMP(ICompressSetCoderPropertiesOpt)
191   // Z7_IFACE_COM7_IMP(ICryptoResetSalt)
192   Z7_IFACE_COM7_IMP(ICryptoResetInitVector)
193   #endif
194 
195 public:
196   Z7_IFACE_COM7_IMP(ICompressSetDecoderProperties2)
197 
198   HRESULT Init_NoSubFilterInit();
199 };
200 
201 #endif
202