Ejemplo n.º 1
1
bool LZMADecodeFile ( const char *fromFile, const char *toFile, CProgressInfo7Zip *progress )
{
	CMyComPtr<ISequentialInStream> inStream;
	CInFileStream *inStreamSpec = new CInFileStream;
	inStream = inStreamSpec;

	if ( !inStreamSpec->Open ( GetSystemString(fromFile) ) )
		return false;

	CMyComPtr<ISequentialOutStream> outStream;
	COutFileStream *outStreamSpec = new COutFileStream;
	outStream = outStreamSpec;
	if ( !outStreamSpec->Create ( GetSystemString(toFile), true ) )
		return false;


	NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;

	CMyComPtr<ICompressCoder> decoder = decoderSpec;

	const UInt32 kPropertiesSize = 5;
	Byte properties[kPropertiesSize];
	UInt32 processedSize;
	
	if ( ReadStream (inStream, properties, kPropertiesSize, &processedSize) != S_OK )
		return false;

	if ( processedSize != kPropertiesSize )
		return false;

	if ( decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK )
		return false;

	UInt64 fileSize = 0;
	for (int i = 0; i < 8; i++)
	{
	  Byte b;
	  if ( inStream->Read(&b, 1, &processedSize) != S_OK )
		  return false;

	  if ( processedSize != 1 )
		  return false;
	  fileSize |= ((UInt64)b) << (8 * i);
	}

	if ( progress )
	{
		progress->Init();
		progress->ApprovedStart = 1 << 21;
		progress->SetMax ( fileSize );
	}

	if ( decoder->Code(inStream, outStream, 0, &fileSize, progress) != S_OK )
		// decoder error
		return false;

	return true;
}
Ejemplo n.º 2
0
bool ReadStream( std::string &strdata, std::string &strpath )
{
struct stat statbuf;
std::ifstream stream;

int res = stat( strpath.data(), &statbuf );

if ( res == -1 )
        {
        strdata.clear();
        return false;
        }

stream.open( strpath.data(), std::ios::in );

strdata.reserve(statbuf.st_size+10);

if ( stream.is_open() )
        {
        ReadStream( stream, strdata, statbuf.st_size );

        stream.close();

        return true;
        }

return(0);
}
Ejemplo n.º 3
0
void OIBReader::ReadSequenceOib()
{
   for (int i=0; i<(int)m_oib_info.size(); i++)
   {
      wstring path_name = m_oib_info[i].filename;

      if (path_name == m_path_name)
         m_cur_time = i;
	  
	   //storage
	   POLE::Storage pStg("temp_storage.txt"); 
	   //open
	   if (pStg.open()) {
		  //enumerate
		  std::list<std::string> entries = 
			  pStg.entries();
		  for(std::list<std::string>::iterator it = entries.begin();
			  it != entries.end(); ++it) {
                  m_oib_t = i;
			  if (!pStg.isDirectory(*it)) {
				  std::wstring st = s2ws(*it);
				  ReadStream(pStg,st);
			  }
		  }
	   }
	   //release
	   pStg.close();
   }
}
Ejemplo n.º 4
0
LONG ReadStreamLong (struct IFFHandle *iff,
    APTR valptr,
    struct IFFParseBase_intern *IFFParseBase)
{
    LONG val;
#if AROS_BIG_ENDIAN
#   define bytes valptr
#else
    UBYTE bytes[4];
#endif

    D(bug("ReadStreamLong(iff=%p valptr=%p)\n", iff, valptr));

    val = ReadStream (iff, bytes, sizeof(LONG), IFFParseBase);

    D(bug("ReadStreamLong: val %ld\n", val));

    if (val < 0)
	return val;
    else if (val != sizeof(LONG))
	return IFFERR_EOF;

#if !AROS_BIG_ENDIAN
    *(LONG *)valptr = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
#endif

    D(bug("ReadStreamLong: *valptr 0x%08lx '%c%c%c%c'\n", *(LONG *) valptr, dmkid(*(LONG *) valptr)));

    return sizeof(LONG);
} /* ReadStreamLong */
Ejemplo n.º 5
0
MagickExport Image *PingImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Image
    *image;

  ImageInfo
    *ping_info;

  assert(image_info != (ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  ping_info=CloneImageInfo(image_info);
  ping_info->ping=MagickTrue;
  image=ReadStream(ping_info,&PingStream,exception);
  if (image != (Image *) NULL)
    {
      ResetTimer(&image->timer);
      if (ping_info->verbose != MagickFalse)
        (void) IdentifyImage(image,stdout,MagickFalse,exception);
    }
  ping_info=DestroyImageInfo(ping_info);
  return(image);
}
Ejemplo n.º 6
0
static enum MAPISTATUS fetchmail_get_stream(TALLOC_CTX *mem_ctx,
					    mapi_object_t *obj_stream, 
					    DATA_BLOB *body)
{
	enum MAPISTATUS	retval;
	uint16_t	read_size;
	uint8_t		buf[0x1000];

	body->length = 0;
	body->data = talloc_zero(mem_ctx, uint8_t);

	do {
		retval = ReadStream(obj_stream, buf, 0x1000, &read_size);
		MAPI_RETVAL_IF(retval, GetLastError(), body->data);
		if (read_size) {
			body->data = talloc_realloc(mem_ctx, body->data, uint8_t,
						    body->length + read_size);
			memcpy(&(body->data[body->length]), buf, read_size);
			body->length += read_size;
		}
	} while (read_size);

	errno = 0;
	return MAPI_E_SUCCESS;
}
Ejemplo n.º 7
0
  void BaseConnection::EventRead() {
    if (state_ != STATE_CONNECTED) {
      return;
    }

    // Allocate buffer for socket to write to.
    if (buffer_.Reserved() < buffer_length_ + buffer_.Length()) {
      buffer_.Reserve(buffer_length_ - buffer_.Reserved());
    }

    ssize_t len;
    try {
      // Append socket's data at buffer's end.
      len = ReadStream(buffer_.End(), buffer_length_);
      buffer_.AdjustLength(len);
    }
    catch (const sockets::SocketException& e) {
      GetLogger_().warn("ReadStream failed with error: " + e.why());
      Close();
      return;
    }

    if (len == 0) {
      buffer_.Clear();
      return;
    }

    ProcessEventRead_(buffer_);
  }
Ejemplo n.º 8
0
unsigned char *LZMADecodeData ( unsigned char *fromData, long fromSize, long &toSize, CProgressInfo7Zip *progress )
{
	CMyComPtr<ISequentialInStream> inStream;
	CInDataStream *inStreamSpec = new CInDataStream;
	inStream = inStreamSpec;

	inStreamSpec->LoadData ( fromData, fromSize );

	NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;

	CMyComPtr<ICompressCoder> decoder = decoderSpec;

	const UInt32 kPropertiesSize = 5;
	Byte properties[kPropertiesSize];
	UInt32 processedSize;
	
	if ( ReadStream (inStream, properties, kPropertiesSize, &processedSize) != S_OK )
		return NULL;

	if ( processedSize != kPropertiesSize )
		return NULL;

	if ( decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK )
		return NULL;

	UInt64 fileSize = 0;
	for (int i = 0; i < 8; i++)
	{
	  Byte b;
	  if ( inStream->Read(&b, 1, &processedSize) != S_OK )
		  return NULL;

	  if ( processedSize != 1 )
		  return NULL;
	  fileSize |= ((UInt64)b) << (8 * i);
	}

	CMyComPtr<ISequentialOutStream> outStream;
	COutDataStream *outStreamSpec = new COutDataStream;
	outStream = outStreamSpec;
	outStreamSpec->Create ( fileSize );

//	CProgressInfo *progressInfoSpec = new CProgressInfo;
//	CMyComPtr<ICompressProgressInfo> progressInfo = progress;

	if ( progress )
	{
		progress->Init();
		progress->ApprovedStart = 1 << 21;
		progress->SetMax ( fileSize );
	}

	if ( decoder->Code(inStream, outStream, 0, &fileSize, progress) != S_OK )
		// decoder error
		return NULL;

	toSize = outStreamSpec->GetCurrentSize ();
	return outStreamSpec->GetData ();
}
Ejemplo n.º 9
0
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
  UInt32 realProcessedSize;
  HRESULT result = ReadStream(m_Stream, data, size, &realProcessedSize);
  if(processedSize != NULL)
    *processedSize = realProcessedSize;
  AddToSeekValue(realProcessedSize);
  return result;
}
Ejemplo n.º 10
0
attachment::attachment(message& mapi_message, const uint32_t attach_num) throw(mapi_exception)
: object(mapi_message.get_session(), "attachment"), m_attach_num(attach_num), m_bin_data(NULL), m_data_size(0), m_filename("")
{
	if (OpenAttach(&mapi_message.data(), attach_num, &m_object) != MAPI_E_SUCCESS)
		throw mapi_exception(GetLastError(), "attachment::attachment : OpenAttach");

	property_container properties = get_property_container();
	properties << PR_ATTACH_FILENAME << PR_ATTACH_LONG_FILENAME << PR_ATTACH_SIZE << PR_ATTACH_DATA_BIN << PR_ATTACH_METHOD;
	properties.fetch();

	const char* filename = static_cast<const char*>(properties[PR_ATTACH_LONG_FILENAME]);
	if (!filename) {
		filename = static_cast<const char*>(properties[PR_ATTACH_FILENAME]);
	}

	if (filename)
		m_filename = filename;

	m_data_size = *(static_cast<const uint32_t*>(properties[PR_ATTACH_SIZE]));

	const Binary_r* attachment_data = static_cast<const Binary_r*>(properties[PR_ATTACH_DATA_BIN]);

	// Don't load PR_ATTACH_DATA_BIN if it's embedded in message.
	// NOTE: Use RopOpenEmbeddedMessage when it is implemented.
	const uint32_t attach_method = *static_cast<const uint32_t*>(properties[PR_ATTACH_METHOD]);
	if (attach_method != ATTACH_BY_VALUE)
		return;

	// Get Binary Data.
	if (attachment_data) {
		m_data_size = attachment_data->cb;
		m_bin_data = new uint8_t[m_data_size];
		memcpy(m_bin_data, attachment_data->lpb, attachment_data->cb);
	} else {
		mapi_object_t obj_stream;
		mapi_object_init(&obj_stream);
		if (OpenStream(&m_object, (enum MAPITAGS)PidTagAttachDataBinary, OpenStream_ReadOnly, &obj_stream) != MAPI_E_SUCCESS)
			throw mapi_exception(GetLastError(), "attachment::attachment : OpenStream");

		if (GetStreamSize(&obj_stream, &m_data_size) != MAPI_E_SUCCESS)
			throw mapi_exception(GetLastError(), "attachment::attachment : GetStreamSize");

		m_bin_data = new uint8_t[m_data_size];

		uint32_t pos = 0;
		uint16_t bytes_read = 0;
		do {
			if (ReadStream(&obj_stream, m_bin_data+pos, 1024, &bytes_read) != MAPI_E_SUCCESS)
				throw mapi_exception(GetLastError(), "attachment::attachment : ReadStream");

			pos += bytes_read;

		} while (bytes_read && pos < m_data_size);

		mapi_object_release(&obj_stream);
	}
}
Ejemplo n.º 11
0
HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
{
  CTempCabInBuffer2 inBuffer;
  inBuffer.Pos = 0;
  RINOK(ReadStream_FALSE(_stream, inBuffer.Buffer, kDataBlockHeaderSize))

  UInt32 checkSum = inBuffer.ReadUInt32();
  packSize = inBuffer.ReadUInt16();
  unpackSize = inBuffer.ReadUInt16();
  if (ReservedSize != 0)
  {
    RINOK(ReadStream_FALSE(_stream, _buffer, ReservedSize));
  }
  _pos = 0;
  CCheckSum2 checkSumCalc;
  checkSumCalc.Init();
  UInt32 packSize2 = packSize;
  if (MsZip && _size == 0)
  {
    if (packSize < 2)
      return S_FALSE; // bad block;
    Byte sig[2];
    RINOK(ReadStream_FALSE(_stream, sig, 2));
    if (sig[0] != 0x43 || sig[1] != 0x4B)
      return S_FALSE;
    packSize2 -= 2;
    checkSumCalc.Update(sig, 2);
  }

  if (kBlockSize - _size < packSize2)
    return S_FALSE;

  UInt32 curSize = packSize2;
  if (curSize != 0)
  {
    size_t processedSizeLoc = curSize;
    RINOK(ReadStream(_stream, _buffer + _size, &processedSizeLoc));
    checkSumCalc.Update(_buffer + _size, (UInt32)processedSizeLoc);
    _size += (UInt32)processedSizeLoc;
    if (processedSizeLoc != curSize)
      return S_FALSE;
  }
  TotalPackSize = _size;

  checkSumCalc.FinishDataUpdate();
  
  bool dataError;
  if (checkSum == 0)
    dataError = false;
  else
  {
    checkSumCalc.UpdateUInt32(packSize | (((UInt32)unpackSize) << 16));
    dataError = (checkSumCalc.GetResult() != checkSum);
  }
  DataError |= dataError;
  return dataError ? S_FALSE : S_OK;
}
Ejemplo n.º 12
0
void CStreamChunk::Read(Framework::CStream& inputStream)
{
	CBaseChunk::Read(inputStream);
	m_numElements = inputStream.Read32_MSBF();
	m_vertexCount = inputStream.Read32_MSBF();
	m_bytesPerVertex = inputStream.Read32_MSBF();
	m_unknown1 = inputStream.Read32_MSBF();
	ReadElements(inputStream);
	ReadStream(inputStream);
}
Ejemplo n.º 13
0
 bool LoadFile(const wxString& filename, wxString& contents)
 {
     if (!wxFileName::IsFileReadable(filename))
         return false;
     wxFileInputStream file(filename);
     if (!file.IsOk())
         return false;
     contents = ReadStream(file);
     return true;
 }
Ejemplo n.º 14
0
HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
{
  Byte header[kHeaderSize];
  UInt32 processedSize;
  RINOK(ReadStream(inStream, header, kHeaderSize, &processedSize));
  if (processedSize != kHeaderSize)
    return E_FAIL;
  _cipher.DecryptHeader(header);
  return S_OK;
}
Ejemplo n.º 15
0
void FileExplorerUpdater::OnExecTerminate(wxProcessEvent &e)
{
    ReadStream(true);
    m_exec_timer->Stop();
    delete m_exec_timer;
    delete m_exec_proc;
    m_exec_proc=NULL;
    m_exec_cond->Signal();
    m_exec_mutex->Unlock();
}
Ejemplo n.º 16
0
void FrameReader::OpenFile()
{
	  running = false;
	  running_loop = 0;
	  current = -1;
	  movie.clear();
	  moviereader = new Openchunk();
		moviereader->Setting(qfile);
		moviereader->start(QThread::LowPriority);  
		connect(moviereader,SIGNAL(finished()),this, SLOT(ReadStream()));
}
Ejemplo n.º 17
0
HRESULT CHandler::Open2(IInStream *stream)
{
  RINOK(stream->Seek(0, STREAM_SEEK_SET, &_startPos));

  const UInt32 kHeaderSize = 8;
  const UInt32 kRecordSize = 5 * 4;
  const UInt32 kBufSize = kHeaderSize + kNumFilesMax * kRecordSize;
  Byte buf[kBufSize];
  size_t processed = kBufSize;
  RINOK(ReadStream(stream, buf, &processed));
  if (processed < kHeaderSize)
    return S_FALSE;
  UInt32 num = Get32(buf + 4);
  if (Get32(buf) != 0xCAFEBABE || num > kNumFilesMax || processed < kHeaderSize + num * kRecordSize)
    return S_FALSE;
  UInt64 endPosMax = kHeaderSize;
  for (UInt32 i = 0; i < num; i++)
  {
    const Byte *p = buf + kHeaderSize + i * kRecordSize;
    CItem &sb = _items[i];
    sb.IsTail = false;
    sb.Type = Get32(p);
    sb.SubType = Get32(p + 4);
    sb.Offset = Get32(p + 8);
    sb.Size = Get32(p + 12);
    sb.Align = Get32(p + 16);

    if ((sb.Type & ~MACH_TYPE_ABI64) >= 0x100 ||
        (sb.SubType & ~MACH_SUBTYPE_ABI64) >= 0x100 ||
        sb.Align > 31)
      return S_FALSE;

    UInt64 endPos = (UInt64)sb.Offset + sb.Size;
    if (endPos > endPosMax)
      endPosMax = endPos;
  }
  UInt64 fileSize;
  RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
  fileSize -= _startPos;
  _numItems = num;
  if (fileSize > endPosMax)
  {
    CItem &sb = _items[_numItems++];
    sb.IsTail = true;
    sb.Type = 0;
    sb.SubType = 0;
    sb.Offset = endPosMax;
    sb.Size = fileSize - endPosMax;
    sb.Align = 0;
  }
  return S_OK;
}
Ejemplo n.º 18
0
HRESULT CDecoder::CheckMac(ISequentialInStream *inStream, bool &isOK)
{
  isOK = false;
  UInt32 processedSize;
  Byte mac1[kMacSize];
  RINOK(ReadStream(inStream, mac1, kMacSize, &processedSize));
  if (processedSize != kMacSize)
    return E_FAIL;
  Byte mac2[kMacSize];
  _hmac.Final(mac2, kMacSize);
  isOK = CompareArrays(mac1, mac2, kMacSize);
  return S_OK;
}
Ejemplo n.º 19
0
bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
{
  if (m_CryptoMode)
  {
    const Byte *bufData = (const Byte *)m_DecryptedData;
    UInt32 bufSize = m_DecryptedDataSize;
    UInt32 i;
    for (i = 0; i < size && m_CryptoPos < bufSize; i++)
      ((Byte *)data)[i] = bufData[m_CryptoPos++];
    return (i == size);
  }
  UInt32 processedSize;
  ReadStream(m_Stream, data, size, &processedSize);
  return (processedSize == size);
}
Ejemplo n.º 20
0
Byte CInArchive::ReadByte()
{
  if (m_BufferPos >= BlockSize)
    m_BufferPos = 0;
  if (m_BufferPos == 0)
  {
    size_t processedSize = BlockSize;
    if (ReadStream(_stream, m_Buffer, &processedSize) != S_OK)
      throw 1;
    if (processedSize != BlockSize)
      throw 1;
  }
  Byte b = m_Buffer[m_BufferPos++];
  _position++;
  return b;
}
Ejemplo n.º 21
0
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
  size_t realProcessedSize = size;
  HRESULT result = S_OK;
  if (_inBufMode)
  {
    try { realProcessedSize = _inBuffer.ReadBytes((Byte *)data, size); }
    catch (const CInBufferException &e) { return e.ErrorCode; }
  }
  else
    result = ReadStream(Stream, data, &realProcessedSize);
  if (processedSize)
    *processedSize = (UInt32)realProcessedSize;
  m_Position += realProcessedSize;
  return result;
}
Ejemplo n.º 22
0
HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
{
  UInt32 saltSize = _key.GetSaltSize();
  UInt32 extraSize = saltSize + kPwdVerifCodeSize;
  Byte temp[kSaltSizeMax + kPwdVerifCodeSize];
  UInt32 processedSize;
  RINOK(ReadStream(inStream, temp, extraSize, &processedSize));
  if (processedSize != extraSize)
    return E_FAIL;
  UInt32 i;
  for (i = 0; i < saltSize; i++)
    _key.Salt[i] = temp[i];
  for (i = 0; i < kPwdVerifCodeSize; i++)
    _pwdVerifFromArchive[i] = temp[saltSize + i];
  return S_OK;
}
Ejemplo n.º 23
0
STDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
{
  UInt32 processedSizeTotal = 0;
  while(size > 0)
  {
    if (_convertedPosBegin != _convertedPosEnd)
    {
      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);
      memmove(data, _buffer + _convertedPosBegin, sizeTemp);
      _convertedPosBegin += sizeTemp;
      data = (void *)((Byte *)data + sizeTemp);
      size -= sizeTemp;
      processedSizeTotal += sizeTemp;
      break;
    }
    int i;
    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)
      _buffer[i] = _buffer[i + _convertedPosEnd];
    _bufferPos = i;
    _convertedPosBegin = _convertedPosEnd = 0;
    UInt32 processedSizeTemp;
    UInt32 size0 = kBufferSize - _bufferPos;
    // Optimize it:
    RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));
    _bufferPos = _bufferPos + processedSizeTemp;
    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
    if (_convertedPosEnd == 0)
    {
      if (_bufferPos == 0)
        break;
      else
      {
        _convertedPosEnd = _bufferPos; // check it
        continue;
      }
    }
    if (_convertedPosEnd > _bufferPos)
    {
      for (; _bufferPos < _convertedPosEnd; _bufferPos++)
        _buffer[_bufferPos] = 0;
      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
    }
  }
  if (processedSize != NULL)
    *processedSize = processedSizeTotal;
  return S_OK;
}
Ejemplo n.º 24
0
void CCoder::readBlocks(ISequentialInStream *inStream, UInt64 *inSizeProcessed) {
  size_t metadata_size = (size_t)read_int(inStream, inSizeProcessed);
  size_t compressed_size = (size_t)read_int(inStream, inSizeProcessed);
  std::vector<uint8_t> compressed_buffer;
  compressed_buffer.assign(compressed_size, 0);
  if (FAILED(ReadStream(inStream, compressed_buffer.data(), &compressed_size)))
    return;
  ReadMemoryStream rms_compressed(compressed_buffer.data(), compressed_buffer.data() + compressed_size);
  std::unique_ptr<Compressor> c(createMetaDataCompressor());
  std::vector<uint8_t> metadata;
  WriteVectorStream wvs(&metadata);
  c->decompress(&rms_compressed, &wvs, metadata_size);
  auto cmp = read_int(inStream, inSizeProcessed);
  check(cmp == 1234u);
  ReadMemoryStream rms(&metadata);
  blocks_.read(&rms);
}
Ejemplo n.º 25
0
inline long long read_int(ISequentialInStream *inStream, UInt64 *inSizeProcessed)
{
  int sh = 0;
  long long rlt = 0;
  unsigned char b = 0;
  do {
    size_t processedSize = 1;
    if (FAILED(ReadStream(inStream, &b, &processedSize)))
      break;
    if (processedSize < 1)
      break;
    rlt = rlt + ((b & 0x7F) << sh);
    *inSizeProcessed += 1;
    sh += 7;
  } while ((b & 0x80) != 0);
  return rlt;
}
Ejemplo n.º 26
0
STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,
      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
      ICompressProgressInfo *progress)
{
  RINOK(Init());
  UInt32 bufferPos = 0;
  _outSizeIsDefined = (outSize != 0);
  if (_outSizeIsDefined)
    _outSize = *outSize;

  while(NeedMore())
  {
    size_t processedSize = kBufferSize - bufferPos;
    
    // Change it: It can be optimized using ReadPart
    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));
    
    UInt32 endPos = bufferPos + (UInt32)processedSize;

    bufferPos = Filter->Filter(_buffer, endPos);
    if (bufferPos > endPos)
    {
      for (; endPos< bufferPos; endPos++)
        _buffer[endPos] = 0;
      bufferPos = Filter->Filter(_buffer, endPos);
    }

    if (bufferPos == 0)
    {
      if (endPos > 0)
        return WriteWithLimit(outStream, endPos);
      return S_OK;
    }
    RINOK(WriteWithLimit(outStream, bufferPos));
    if (progress != NULL)
    {
      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));
    }
    UInt32 i = 0;
    while(bufferPos < endPos)
      _buffer[i++] = _buffer[bufferPos++];
    bufferPos = i;
  }
  return S_OK;
}
Ejemplo n.º 27
0
static unsigned ReadSection( handle filehndl, unsigned off )
{
    unsigned_16 len;
    unsigned    last;
    void        *new;

    if( ReadStream( filehndl, &len, sizeof( len ) ) != sizeof( len ) ) {
        return( 0 );
    }
    CONV_LE_16( len );
    last = off + len;
    if( last > ParseTableSize ) {
        new = ParseTable;
        _Realloc( new, last );
        if( new == NULL ) return( 0 );
        ParseTable = new;
        ParseTableSize = last;
    }
Ejemplo n.º 28
0
void CInArchive::SafeReadBytes(void *data, unsigned size)
{
  size_t processed = size;
  if (_inBufMode)
  {
    processed = _inBuffer.ReadBytes((Byte *)data, size);
    m_Position += processed;
  }
  else
  {
    HRESULT result = ReadStream(Stream, data, &processed);
    m_Position += processed;
    if (result != S_OK)
      throw CSystemException(result);
  }
  if (processed != size)
    throw CUnexpectEnd();
}
Ejemplo n.º 29
0
void handleInvokeForwardRequest(RemoteOpHeader *h, Node srv, Stream str)
{
  ConcreteType ct;
  Object o;
  unsigned int answer;

  anticipateGC(64*1024 + 2 * StreamLength(str));
  TRACE(rinvoke, 3, ("InvokeForwardRequest received"));
  TRACE(rinvoke, 6, ("Checking for CT for incoming activation"));
  ct = (ConcreteType) doObjectRequest(srv, &h->targetct, ctct);
  assert(! ISNIL(ct));

  TRACE(rinvoke, 4, ("InvokeForwarded for object with ID %s", OIDString(h->target)));
  o = OIDFetch(h->target);
  assert(!ISNIL(o));
  if (RESDNT(o->flags)) {
    int more;
    State *state;
    TRACE(rinvoke, 4, ("The object is here, accepting activation"));
    ReadInt(&answer, str);
    more = memcmp(ReadStream(str, 4), "ACT!", 4);
    assert(!more);
    /* Suck out an activation record - argh! */
    TRACE(rinvoke, 6, ("Incoming activation record!!"));
    state = extractActivation(o, ct, str, srv);
    if (!ISNIL(answer)) {
#define sp state->sp
      PUSH(u32, answer);
      PUSH(ConcreteType, BuiltinInstCT(BOOLEANI));
    }
#undef sp
  } else {
    Node newsrv = getLocFromObj(o);
    TRACE(rinvoke, 4, ("Forwarding request to %s", NodeString(newsrv)));
    if (forwardMsg(newsrv, h, str) < 0) {
      Stream newstr;
      RewindStream(str);
      newstr = StealStream(str);
      findAndSendTo(h->target, newstr);
    }
  }
  TRACE(rinvoke, 4, ("Invoke forward request done"));
  inhibit_gc--;
}
Ejemplo n.º 30
0
bool prepare_ex_data(ISequentialInStream *inStream, int needed)
{
  size_t processedSize;
  if (ex_valid_size - ex_next_offset < needed) {
    if (ex_data_size - ex_next_offset < needed) {
      memmove(ex_data, ex_data + ex_next_offset, ex_valid_size - ex_next_offset);
      ex_valid_size -= ex_next_offset;
      ex_next_offset = 0;
    }
//     if (FAILED(str->Read(ex_data + ex_valid_size, needed - (ex_valid_size - ex_next_offset), &processedSize)))
    processedSize = ex_data_size - ex_valid_size;
    if (FAILED(ReadStream(inStream, ex_data + ex_valid_size, &processedSize)))
      return false;
    ex_valid_size += (int)processedSize;
    if (ex_valid_size - ex_next_offset < needed)
      return false;
  }
  return true;
}