bug fixes

pull/2/head
weidai 2002-10-06 03:23:16 +00:00
parent 1e45c2d305
commit eee814871a
5 changed files with 682 additions and 695 deletions

View File

@ -44,21 +44,6 @@ unsigned long FileStore::MaxRetrievable() const
return end-current;
}
unsigned int FileStore::Peek(byte &outByte) const
{
if (!m_stream)
return 0;
int result = m_stream->peek();
if (result == EOF) // GCC workaround: 2.95.2 doesn't have char_traits<char>::eof()
return 0;
else
{
outByte = byte(result);
return 1;
}
}
unsigned int FileStore::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking)
{
if (!m_stream)
@ -103,6 +88,19 @@ unsigned int FileStore::CopyRangeTo2(BufferedTransformation &target, unsigned lo
if (!m_stream)
return 0;
if (begin == 0 && end == 1)
{
int result = m_stream->peek();
if (result == EOF) // GCC workaround: 2.95.2 doesn't have char_traits<char>::eof()
return 0;
else
{
unsigned int blockedBytes = target.ChannelPut(channel, byte(result), blocking);
begin += 1-blockedBytes;
return blockedBytes;
}
}
// TODO: figure out what happens on cin
streampos current = m_stream->tellg();
streampos endPosition = m_stream->seekg(0, ios::end).tellg();

View File

@ -30,8 +30,6 @@ public:
std::istream* GetStream() {return m_stream;}
unsigned long MaxRetrievable() const;
unsigned int Peek(byte &outByte) const;
unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;

View File

@ -387,35 +387,27 @@ void Redirector::ChannelInitialize(const std::string &channel, const NameValuePa
// *************************************************************
ProxyFilter::ProxyFilter(BufferedTransformation *filter, unsigned int firstSize, unsigned int lastSize, BufferedTransformation *attachment)
: FilterWithBufferedInput(firstSize, 1, lastSize, attachment), m_filter(filter), m_proxy(NULL)
: FilterWithBufferedInput(firstSize, 1, lastSize, attachment), m_filter(filter)
{
if (m_filter.get())
m_filter->Attach(m_proxy = new OutputProxy(*this, false));
m_filter->Attach(new OutputProxy(*this, false));
}
void ProxyFilter::IsolatedFlush(bool completeFlush)
bool ProxyFilter::IsolatedFlush(bool hardFlush, bool blocking)
{
if (m_filter.get())
{
bool passSignal = m_proxy->GetPassSignal();
m_proxy->SetPassSignal(false);
m_filter->Flush(completeFlush, -1);
m_proxy->SetPassSignal(passSignal);
}
return m_filter.get() ? m_filter->Flush(hardFlush, -1, blocking) : false;
}
void ProxyFilter::SetFilter(Filter *filter)
{
bool passSignal = m_proxy ? m_proxy->GetPassSignal() : false;
m_filter.reset(filter);
if (filter)
{
std::auto_ptr<OutputProxy> temp(m_proxy = new OutputProxy(*this, passSignal));
m_filter->TransferAllTo(*m_proxy);
OutputProxy *proxy;
std::auto_ptr<OutputProxy> temp(proxy = new OutputProxy(*this, false));
m_filter->TransferAllTo(*proxy);
m_filter->Attach(temp.release());
}
else
m_proxy=NULL;
}
void ProxyFilter::NextPutMultiple(const byte *s, unsigned int len)

View File

@ -144,8 +144,8 @@ public:
/*! calls ForceNextPut() if hardFlush is true */
bool IsolatedFlush(bool hardFlush, bool blocking);
/*! the input buffer may contain more than blockSize bytes if lastSize != 0
ForceNextPut() forces a call to NextPut() if this is the case
/*! The input buffer may contain more than blockSize bytes if lastSize != 0.
ForceNextPut() forces a call to NextPut() if this is the case.
*/
void ForceNextPut();
@ -440,14 +440,13 @@ class ProxyFilter : public FilterWithBufferedInput
public:
ProxyFilter(BufferedTransformation *filter, unsigned int firstSize, unsigned int lastSize, BufferedTransformation *attachment);
void IsolatedFlush(bool completeFlush);
bool IsolatedFlush(bool hardFlush, bool blocking);
void SetFilter(Filter *filter);
void NextPutMultiple(const byte *s, unsigned int len);
protected:
member_ptr<BufferedTransformation> m_filter;
OutputProxy *m_proxy;
};
//! simple proxy filter that doesn't modify the underlying filter's input or output

View File

@ -144,7 +144,7 @@ class CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPol
static inline void IncrementCounterByOne(byte *output, const byte *input, unsigned int s)
{
for (int i=s-1, carry=1; i>=0 && carry; i--)
for (int i=s-1, carry=1; i>=0; i--)
carry = !(output[i] = input[i]+1);
}
inline void ProcessMultipleBlocks(byte *output, const byte *input, unsigned int n)