other-licenses/7zstub/src/7zip/Common/StreamObjects.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 // StreamObjects.h
     3 #ifndef __STREAMOBJECTS_H
     4 #define __STREAMOBJECTS_H
     6 #include "../../Common/DynamicBuffer.h"
     7 #include "../../Common/MyCom.h"
     8 #include "../IStream.h"
    10 class CSequentialInStreamImp: 
    11   public ISequentialInStream,
    12   public CMyUnknownImp
    13 {
    14   const Byte *_dataPointer;
    15   size_t _size;
    16   size_t _pos;
    18 public:
    19   void Init(const Byte *dataPointer, size_t size)
    20   {
    21     _dataPointer = dataPointer;
    22     _size = size;
    23     _pos = 0;
    24   }
    26   MY_UNKNOWN_IMP
    28   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
    29 };
    32 class CWriteBuffer
    33 {
    34   CByteDynamicBuffer _buffer;
    35   size_t _size;
    36 public:
    37   CWriteBuffer(): _size(0) {}
    38   void Init() { _size = 0;  }
    39   void Write(const void *data, size_t size);
    40   size_t GetSize() const { return _size; }
    41   const CByteDynamicBuffer& GetBuffer() const { return _buffer; }
    42 };
    44 class CSequentialOutStreamImp: 
    45   public ISequentialOutStream,
    46   public CMyUnknownImp
    47 {
    48   CWriteBuffer _writeBuffer;
    49 public:
    50   void Init() { _writeBuffer.Init(); }
    51   size_t GetSize() const { return _writeBuffer.GetSize(); }
    52   const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }
    54   MY_UNKNOWN_IMP
    56   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
    57 };
    59 class CSequentialOutStreamImp2: 
    60   public ISequentialOutStream,
    61   public CMyUnknownImp
    62 {
    63   Byte *_buffer;
    64 public:
    65   size_t _size;
    66   size_t _pos;
    68   void Init(Byte *buffer, size_t size)  
    69   { 
    70     _buffer = buffer;
    71     _pos = 0;
    72     _size = size; 
    73   }
    75   MY_UNKNOWN_IMP
    77   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
    78 };
    80 class CSequentialInStreamSizeCount: 
    81   public ISequentialInStream,
    82   public CMyUnknownImp
    83 {
    84   CMyComPtr<ISequentialInStream> _stream;
    85   UInt64 _size;
    86 public:
    87   void Init(ISequentialInStream *stream)
    88   {
    89     _stream = stream;
    90     _size = 0;
    91   }
    92   UInt64 GetSize() const { return _size; }
    94   MY_UNKNOWN_IMP
    96   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
    97 };
    99 class CSequentialInStreamRollback: 
   100   public ISequentialInStream,
   101   public CMyUnknownImp
   102 {
   103   CMyComPtr<ISequentialInStream> _stream;
   104   Byte *_buffer;
   105   size_t _bufferSize;
   106   UInt64 _size;
   108   size_t _currentSize;
   109   size_t _currentPos;
   110 public:
   111   CSequentialInStreamRollback(size_t bufferSize):
   112     _bufferSize(bufferSize),
   113     _buffer(0)
   114   {
   115     _buffer = new Byte[bufferSize];
   116   }
   117   ~CSequentialInStreamRollback()
   118   {
   119     delete _buffer;
   120   }
   122   void Init(ISequentialInStream *stream)
   123   {
   124     _stream = stream;
   125     _size = 0;
   126     _currentSize = 0;
   127     _currentPos = 0;
   128   }
   129   UInt64 GetSize() const { return _size; }
   131   MY_UNKNOWN_IMP
   133   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
   134   HRESULT Rollback(size_t rollbackSize);
   135 };
   137 class CSequentialOutStreamSizeCount: 
   138   public ISequentialOutStream,
   139   public CMyUnknownImp
   140 {
   141   CMyComPtr<ISequentialOutStream> _stream;
   142   UInt64 _size;
   143 public:
   144   void Init(ISequentialOutStream *stream)
   145   {
   146     _stream = stream;
   147     _size = 0;
   148   }
   149   UInt64 GetSize() const { return _size; }
   151   MY_UNKNOWN_IMP
   153   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
   154 };
   156 #endif

mercurial