other-licenses/7zstub/src/7zip/Common/OutBuffer.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.

michael@0 1 // OutBuffer.h
michael@0 2
michael@0 3 #ifndef __OUTBUFFER_H
michael@0 4 #define __OUTBUFFER_H
michael@0 5
michael@0 6 #include "../IStream.h"
michael@0 7 #include "../../Common/MyCom.h"
michael@0 8
michael@0 9 #ifndef _NO_EXCEPTIONS
michael@0 10 struct COutBufferException
michael@0 11 {
michael@0 12 HRESULT ErrorCode;
michael@0 13 COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
michael@0 14 };
michael@0 15 #endif
michael@0 16
michael@0 17 class COutBuffer
michael@0 18 {
michael@0 19 protected:
michael@0 20 Byte *_buffer;
michael@0 21 UInt32 _pos;
michael@0 22 UInt32 _limitPos;
michael@0 23 UInt32 _streamPos;
michael@0 24 UInt32 _bufferSize;
michael@0 25 CMyComPtr<ISequentialOutStream> _stream;
michael@0 26 UInt64 _processedSize;
michael@0 27 Byte *_buffer2;
michael@0 28 bool _overDict;
michael@0 29
michael@0 30 HRESULT FlushPart();
michael@0 31 void FlushWithCheck();
michael@0 32 public:
michael@0 33 #ifdef _NO_EXCEPTIONS
michael@0 34 HRESULT ErrorCode;
michael@0 35 #endif
michael@0 36
michael@0 37 COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
michael@0 38 ~COutBuffer() { Free(); }
michael@0 39
michael@0 40 bool Create(UInt32 bufferSize);
michael@0 41 void Free();
michael@0 42
michael@0 43 void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
michael@0 44 void SetStream(ISequentialOutStream *stream);
michael@0 45 void Init();
michael@0 46 HRESULT Flush();
michael@0 47 void ReleaseStream() { _stream.Release(); }
michael@0 48
michael@0 49 void WriteByte(Byte b)
michael@0 50 {
michael@0 51 _buffer[_pos++] = b;
michael@0 52 if(_pos == _limitPos)
michael@0 53 FlushWithCheck();
michael@0 54 }
michael@0 55 void WriteBytes(const void *data, size_t size)
michael@0 56 {
michael@0 57 for (size_t i = 0; i < size; i++)
michael@0 58 WriteByte(((const Byte *)data)[i]);
michael@0 59 }
michael@0 60
michael@0 61 UInt64 GetProcessedSize() const;
michael@0 62 };
michael@0 63
michael@0 64 #endif

mercurial