Home | History | Annotate | Download | only in Common
      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) if (iid == IID_ ## i) \
     11 { if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
     12 *outObject = (void *)(i *)this; AddRef(); return S_OK; }
     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   #endif
     25   #ifndef EXTRACT_ONLY
     26   public ICompressSetCoderProperties,
     27   public ICompressWriteCoderProperties,
     28   // public ICryptoResetSalt,
     29   public ICryptoResetInitVector,
     30   #endif
     31   public ICompressSetDecoderProperties2,
     32   public CMyUnknownImp
     33 {
     34 protected:
     35   Byte *_buffer;
     36   CMyComPtr<ISequentialInStream> _inStream;
     37   CMyComPtr<ISequentialOutStream> _outStream;
     38   UInt32 _bufferPos;
     39   UInt32 _convertedPosBegin;
     40   UInt32 _convertedPosEnd;
     41   bool _outSizeIsDefined;
     42   UInt64 _outSize;
     43   UInt64 _nowPos64;
     44 
     45   HRESULT Init()
     46   {
     47     _nowPos64 = 0;
     48     _outSizeIsDefined = false;
     49     return Filter->Init();
     50   }
     51 
     52   CMyComPtr<ICryptoSetPassword> _setPassword;
     53   #ifndef EXTRACT_ONLY
     54   CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;
     55   CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;
     56   // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;
     57   CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;
     58   #endif
     59   CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;
     60 public:
     61   CMyComPtr<ICompressFilter> Filter;
     62 
     63   CFilterCoder();
     64   ~CFilterCoder();
     65   HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);
     66 
     67 public:
     68   MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
     69     MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
     70     MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
     71     MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)
     72     MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)
     73     MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)
     74 
     75     #ifndef _NO_CRYPTO
     76     MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)
     77     #endif
     78 
     79     #ifndef EXTRACT_ONLY
     80     MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)
     81     MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)
     82     // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)
     83     MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)
     84     #endif
     85 
     86     MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)
     87   MY_QUERYINTERFACE_END
     88   MY_ADDREF_RELEASE
     89   STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
     90       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
     91   STDMETHOD(ReleaseInStream)();
     92   STDMETHOD(SetInStream)(ISequentialInStream *inStream);
     93   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \
     94   STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
     95   STDMETHOD(ReleaseOutStream)();
     96   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
     97   STDMETHOD(Flush)();
     98 
     99   #ifndef _NO_CRYPTO
    100   STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
    101   #endif
    102   #ifndef EXTRACT_ONLY
    103   STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
    104       const PROPVARIANT *properties, UInt32 numProperties);
    105   STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
    106   // STDMETHOD(ResetSalt)();
    107   STDMETHOD(ResetInitVector)();
    108   #endif
    109   STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
    110 };
    111 
    112 class CInStreamReleaser
    113 {
    114 public:
    115   CFilterCoder *FilterCoder;
    116   CInStreamReleaser(): FilterCoder(0) {}
    117   ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }
    118 };
    119 
    120 class COutStreamReleaser
    121 {
    122 public:
    123   CFilterCoder *FilterCoder;
    124   COutStreamReleaser(): FilterCoder(0) {}
    125   ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }
    126 };
    127 
    128 #endif
    129