1 // FilterCoder.h 2 3 #ifndef __FILTER_CODER_H 4 #define __FILTER_CODER_H 5 6 #include "../../Common/MyCom.h" 7 #include "../ICoder.h" 8 #include "../IPassword.h" 9 10 #define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) else if (iid == IID_ ## i) \ 11 { if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \ 12 *outObject = (void *)(i *)this; } 13 14 class CFilterCoder: 15 public ICompressCoder, 16 public ICompressSetInStream, 17 public ISequentialInStream, 18 public ICompressSetOutStream, 19 public ISequentialOutStream, 20 public IOutStreamFlush, 21 22 #ifndef _NO_CRYPTO 23 public ICryptoSetPassword, 24 public ICryptoProperties, 25 #endif 26 #ifndef EXTRACT_ONLY 27 public ICompressSetCoderProperties, 28 public ICompressWriteCoderProperties, 29 // public ICryptoResetSalt, 30 public ICryptoResetInitVector, 31 #endif 32 public ICompressSetDecoderProperties2, 33 public CMyUnknownImp 34 { 35 protected: 36 Byte *_buffer; 37 CMyComPtr<ISequentialInStream> _inStream; 38 CMyComPtr<ISequentialOutStream> _outStream; 39 UInt32 _bufferPos; 40 UInt32 _convertedPosBegin; 41 UInt32 _convertedPosEnd; 42 bool _outSizeIsDefined; 43 UInt64 _outSize; 44 UInt64 _nowPos64; 45 Init2()46 void Init2() 47 { 48 _nowPos64 = 0; 49 _outSizeIsDefined = false; 50 } 51 Init()52 HRESULT Init() 53 { 54 Init2(); 55 return Filter->Init(); 56 } 57 58 CMyComPtr<ICryptoSetPassword> _setPassword; 59 CMyComPtr<ICryptoProperties> _cryptoProperties; 60 #ifndef EXTRACT_ONLY 61 CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties; 62 CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties; 63 // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt; 64 CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector; 65 #endif 66 CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties; 67 public: 68 CMyComPtr<ICompressFilter> Filter; 69 70 CFilterCoder(); 71 ~CFilterCoder(); 72 HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size); 73 74 public: 75 MY_QUERYINTERFACE_BEGIN2(ICompressCoder) 76 MY_QUERYINTERFACE_ENTRY(ICompressSetInStream) 77 MY_QUERYINTERFACE_ENTRY(ISequentialInStream) 78 MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream) 79 MY_QUERYINTERFACE_ENTRY(ISequentialOutStream) 80 MY_QUERYINTERFACE_ENTRY(IOutStreamFlush) 81 82 #ifndef _NO_CRYPTO 83 MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword) 84 MY_QUERYINTERFACE_ENTRY_AG(ICryptoProperties, Filter, _cryptoProperties) 85 #endif 86 87 #ifndef EXTRACT_ONLY 88 MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties) 89 MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties) 90 // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt) 91 MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector) 92 #endif 93 94 MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties) 95 MY_QUERYINTERFACE_END 96 MY_ADDREF_RELEASE 97 STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 98 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 99 STDMETHOD(ReleaseInStream)(); 100 STDMETHOD(SetInStream)(ISequentialInStream *inStream); 101 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \ 102 STDMETHOD(SetOutStream)(ISequentialOutStream *outStream); 103 STDMETHOD(ReleaseOutStream)(); 104 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 105 STDMETHOD(Flush)(); 106 107 #ifndef _NO_CRYPTO 108 STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); 109 110 STDMETHOD(SetKey)(const Byte *data, UInt32 size); 111 STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); 112 #endif 113 #ifndef EXTRACT_ONLY 114 STDMETHOD(SetCoderProperties)(const PROPID *propIDs, 115 const PROPVARIANT *properties, UInt32 numProperties); 116 STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); 117 // STDMETHOD(ResetSalt)(); 118 STDMETHOD(ResetInitVector)(); 119 #endif 120 STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 121 122 void SetInStream_NoSubFilterInit(ISequentialInStream *inStream); 123 124 }; 125 126 class CInStreamReleaser 127 { 128 public: 129 CFilterCoder *FilterCoder; CInStreamReleaser()130 CInStreamReleaser(): FilterCoder(0) {} ~CInStreamReleaser()131 ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); } 132 }; 133 134 class COutStreamReleaser 135 { 136 public: 137 CFilterCoder *FilterCoder; COutStreamReleaser()138 COutStreamReleaser(): FilterCoder(0) {} ~COutStreamReleaser()139 ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); } 140 }; 141 142 #endif 143