Split stream.hpp/.cpp into multiple source files.
This commit is contained in:
parent
b5927243a2
commit
cc49395dd2
14
SConstruct
14
SConstruct
@ -144,6 +144,20 @@ libvmime_sources = [
|
||||
'utility/smartPtr.cpp', 'utility/smartPtr.hpp',
|
||||
'utility/smartPtrInt.cpp', 'utility/smartPtrInt.hpp',
|
||||
'utility/stream.cpp', 'utility/stream.hpp',
|
||||
'utility/streamUtils.cpp', 'utility/streamUtils.hpp',
|
||||
'utility/filteredStream.cpp', 'utility/filteredStream.hpp',
|
||||
'utility/inputStream.cpp', 'utility/inputStream.hpp',
|
||||
'utility/inputStreamAdapter.cpp', 'utility/inputStreamAdapter.hpp',
|
||||
'utility/inputStreamByteBufferAdapter.cpp', 'utility/inputStreamByteBufferAdapter.hpp',
|
||||
'utility/inputStreamPointerAdapter.cpp', 'utility/inputStreamPointerAdapter.hpp',
|
||||
'utility/inputStreamSocketAdapter.cpp', 'utility/inputStreamSocketAdapter.hpp',
|
||||
'utility/inputStreamStringAdapter.cpp', 'utility/inputStreamStringAdapter.hpp',
|
||||
'utility/inputStreamStringProxyAdapter.cpp', 'utility/inputStreamStringProxyAdapter.hpp',
|
||||
'utility/outputStream.cpp', 'utility/outputStream.hpp',
|
||||
'utility/outputStreamAdapter.cpp', 'utility/outputStreamAdapter.hpp',
|
||||
'utility/outputStreamByteArrayAdapter.cpp', 'utility/outputStreamByteArrayAdapter.hpp',
|
||||
'utility/outputStreamSocketAdapter.cpp', 'utility/outputStreamSocketAdapter.hpp',
|
||||
'utility/outputStreamStringAdapter.cpp', 'utility/outputStreamStringAdapter.hpp',
|
||||
'utility/stringProxy.cpp', 'utility/stringProxy.hpp',
|
||||
'utility/stringUtils.cpp', 'utility/stringUtils.hpp',
|
||||
'utility/url.cpp', 'utility/url.hpp',
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "vmime/charsetConverter.hpp"
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
extern "C"
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "vmime/component.hpp"
|
||||
#include "vmime/base.hpp"
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "vmime/encoding.hpp"
|
||||
#include "vmime/contentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/encoder/encoderFactory.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "vmime/exception.hpp"
|
||||
|
||||
#include "vmime/streamContentHandler.hpp"
|
||||
#include "vmime/utility/inputStreamPointerAdapter.hpp"
|
||||
|
||||
#include "vmime/contentDispositionField.hpp"
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "vmime/generatedMessageAttachment.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "vmime/emptyContentHandler.hpp"
|
||||
#include "vmime/stringContentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "vmime/path.hpp"
|
||||
#include "vmime/dateTime.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace mdn {
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "vmime/mdn/receivedMDNInfos.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace mdn {
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "vmime/message.hpp"
|
||||
#include "vmime/options.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/utility/smartPtr.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "vmime/net/imap/IMAPPart.hpp"
|
||||
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <typeinfo>
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
@ -35,6 +35,9 @@
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/platform.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/platform.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "vmime/net/pop3/POP3Folder.hpp"
|
||||
#include "vmime/net/pop3/POP3Store.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "vmime/security/digest/messageDigestFactory.hpp"
|
||||
#include "vmime/utility/filteredStream.hpp"
|
||||
#include "vmime/utility/stringUtils.hpp"
|
||||
#include "vmime/utility/inputStreamSocketAdapter.hpp"
|
||||
|
||||
#include "vmime/net/defaultConnectionInfos.hpp"
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "vmime/utility/childProcess.hpp"
|
||||
#include "vmime/utility/smartPtr.hpp"
|
||||
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
#include "vmime/net/defaultConnectionInfos.hpp"
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
|
@ -30,6 +30,8 @@
|
||||
|
||||
#include "vmime/utility/filteredStream.hpp"
|
||||
#include "vmime/utility/stringUtils.hpp"
|
||||
#include "vmime/utility/outputStreamSocketAdapter.hpp"
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
#include "vmime/net/defaultConnectionInfos.hpp"
|
||||
|
||||
|
@ -27,6 +27,9 @@
|
||||
#include "vmime/mailboxList.hpp"
|
||||
#include "vmime/message.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
@ -27,6 +27,9 @@
|
||||
#include "vmime/text.hpp"
|
||||
#include "vmime/encoding.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "vmime/stringContentHandler.hpp"
|
||||
#include "vmime/contentDisposition.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
#include "vmime/security/cert/X509Certificate.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace security {
|
||||
|
@ -33,6 +33,9 @@
|
||||
#include "vmime/utility/encoder/encoderFactory.hpp"
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
|
@ -23,6 +23,10 @@
|
||||
|
||||
#include "vmime/streamContentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -23,6 +23,10 @@
|
||||
|
||||
#include "vmime/stringContentHandler.hpp"
|
||||
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "vmime/utility/encoder/defaultEncoder.hpp"
|
||||
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
33
src/utility/inputStream.cpp
Normal file
33
src/utility/inputStream.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
70
src/utility/inputStreamAdapter.cpp
Normal file
70
src/utility/inputStreamAdapter.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamAdapter::inputStreamAdapter(std::istream& is)
|
||||
: m_stream(is)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamAdapter::eof() const
|
||||
{
|
||||
return (m_stream.eof());
|
||||
}
|
||||
|
||||
|
||||
void inputStreamAdapter::reset()
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.seekg(0, std::ios::beg);
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.read(data, count);
|
||||
return (m_stream.gcount());
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamAdapter::skip(const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.ignore(count);
|
||||
return (m_stream.gcount());
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
90
src/utility/inputStreamByteBufferAdapter.cpp
Normal file
90
src/utility/inputStreamByteBufferAdapter.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
|
||||
: m_buffer(buffer), m_length(length), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamByteBufferAdapter::eof() const
|
||||
{
|
||||
return m_pos >= m_length;
|
||||
}
|
||||
|
||||
|
||||
void inputStreamByteBufferAdapter::reset()
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamByteBufferAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
const size_type remaining = m_length - m_pos;
|
||||
|
||||
if (remaining < count)
|
||||
{
|
||||
std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
|
||||
m_pos += remaining;
|
||||
|
||||
return remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
|
||||
m_pos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
|
||||
{
|
||||
const size_type remaining = m_length - m_pos;
|
||||
|
||||
if (remaining < count)
|
||||
{
|
||||
m_pos += remaining;
|
||||
return remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
46
src/utility/inputStreamPointerAdapter.cpp
Normal file
46
src/utility/inputStreamPointerAdapter.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamPointerAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
|
||||
: inputStreamAdapter(*is), m_stream(is), m_own(own)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inputStreamPointerAdapter::~inputStreamPointerAdapter()
|
||||
{
|
||||
if (m_own)
|
||||
delete (m_stream);
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
82
src/utility/inputStreamSocketAdapter.cpp
Normal file
82
src/utility/inputStreamSocketAdapter.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamSocketAdapter.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/socket.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
|
||||
: m_socket(sok)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamSocketAdapter::eof() const
|
||||
{
|
||||
// Can't know...
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void inputStreamSocketAdapter::reset()
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
return m_socket.receiveRaw(data, count);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::skip
|
||||
(const size_type /* count */)
|
||||
{
|
||||
// Not supported
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::getBlockSize()
|
||||
{
|
||||
return m_socket.getBlockSize();
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
94
src/utility/inputStreamStringAdapter.cpp
Normal file
94
src/utility/inputStreamStringAdapter.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
|
||||
: m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
|
||||
const string::size_type begin, const string::size_type end)
|
||||
: m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamStringAdapter::eof() const
|
||||
{
|
||||
return (m_pos >= m_end);
|
||||
}
|
||||
|
||||
|
||||
void inputStreamStringAdapter::reset()
|
||||
{
|
||||
m_pos = m_begin;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
if (m_pos + count >= m_end)
|
||||
{
|
||||
const size_type remaining = m_end - m_pos;
|
||||
|
||||
std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
|
||||
m_pos = m_end;
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringAdapter::skip(const size_type count)
|
||||
{
|
||||
if (m_pos + count >= m_end)
|
||||
{
|
||||
const size_type remaining = m_end - m_pos;
|
||||
m_pos = m_end;
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
89
src/utility/inputStreamStringProxyAdapter.cpp
Normal file
89
src/utility/inputStreamStringProxyAdapter.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
|
||||
#include "vmime/utility/stringProxy.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
|
||||
: m_buffer(buffer), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamStringProxyAdapter::eof() const
|
||||
{
|
||||
return (m_pos >= m_buffer.length());
|
||||
}
|
||||
|
||||
|
||||
void inputStreamStringProxyAdapter::reset()
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringProxyAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
const size_type remaining = m_buffer.length() - m_pos;
|
||||
|
||||
if (count > remaining)
|
||||
{
|
||||
std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
|
||||
m_pos = m_buffer.length();
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
|
||||
{
|
||||
const size_type remaining = m_buffer.length() - m_pos;
|
||||
|
||||
if (count > remaining)
|
||||
{
|
||||
m_pos = m_buffer.length();
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
33
src/utility/outputStream.cpp
Normal file
33
src/utility/outputStream.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
54
src/utility/outputStreamAdapter.cpp
Normal file
54
src/utility/outputStreamAdapter.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
outputStreamAdapter::outputStreamAdapter(std::ostream& os)
|
||||
: m_stream(os)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamAdapter::write
|
||||
(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.write(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamAdapter::flush()
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.flush();
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
51
src/utility/outputStreamByteArrayAdapter.cpp
Normal file
51
src/utility/outputStreamByteArrayAdapter.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
|
||||
: m_array(array)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_array.insert(m_array.end(), data, data + count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamByteArrayAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
68
src/utility/outputStreamSocketAdapter.cpp
Normal file
68
src/utility/outputStreamSocketAdapter.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/outputStreamSocketAdapter.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/socket.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
|
||||
: m_socket(sok)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamSocketAdapter::write
|
||||
(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_socket.sendRaw(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamSocketAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
stream::size_type outputStreamSocketAdapter::getBlockSize()
|
||||
{
|
||||
return m_socket.getBlockSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
51
src/utility/outputStreamStringAdapter.cpp
Normal file
51
src/utility/outputStreamStringAdapter.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
|
||||
: m_buffer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_buffer.append(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamStringAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
@ -22,503 +22,18 @@
|
||||
//
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
#include "vmime/utility/stringProxy.hpp"
|
||||
|
||||
#include <algorithm> // for std::copy
|
||||
#include <iterator> // for std::back_inserter
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
#include "vmime/net/socket.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
// stream
|
||||
|
||||
stream::size_type stream::getBlockSize()
|
||||
{
|
||||
return 32768; // 32 KB
|
||||
}
|
||||
|
||||
|
||||
// Helpers
|
||||
|
||||
outputStream& operator<<(outputStream& os, const stream::value_type c)
|
||||
{
|
||||
os.write(&c, 1);
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
outputStream& operator<<(outputStream& os, const string& str)
|
||||
{
|
||||
os.write(str.data(), str.length());
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
|
||||
{
|
||||
return bufferedStreamCopy(is, os, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
|
||||
const stream::size_type length, progressListener* progress)
|
||||
{
|
||||
const stream::size_type blockSize =
|
||||
std::min(is.getBlockSize(), os.getBlockSize());
|
||||
|
||||
std::vector <stream::value_type> vbuffer(blockSize);
|
||||
|
||||
stream::value_type* buffer = &vbuffer.front();
|
||||
stream::size_type total = 0;
|
||||
|
||||
if (progress != NULL)
|
||||
progress->start(length);
|
||||
|
||||
while (!is.eof())
|
||||
{
|
||||
const stream::size_type read = is.read(buffer, blockSize);
|
||||
|
||||
if (read != 0)
|
||||
{
|
||||
os.write(buffer, read);
|
||||
total += read;
|
||||
|
||||
if (progress != NULL)
|
||||
progress->progress(total, std::max(total, length));
|
||||
}
|
||||
}
|
||||
|
||||
if (progress != NULL)
|
||||
progress->stop(total);
|
||||
|
||||
return (total);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// outputStreamAdapter
|
||||
|
||||
outputStreamAdapter::outputStreamAdapter(std::ostream& os)
|
||||
: m_stream(os)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamAdapter::write
|
||||
(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.write(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamAdapter::flush()
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// outputStreamStringAdapter
|
||||
|
||||
outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
|
||||
: m_buffer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_buffer.append(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamStringAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
|
||||
// outputStreamByteArrayAdapter
|
||||
|
||||
outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
|
||||
: m_array(array)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_array.insert(m_array.end(), data, data + count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamByteArrayAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamAdapter
|
||||
|
||||
inputStreamAdapter::inputStreamAdapter(std::istream& is)
|
||||
: m_stream(is)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamAdapter::eof() const
|
||||
{
|
||||
return (m_stream.eof());
|
||||
}
|
||||
|
||||
|
||||
void inputStreamAdapter::reset()
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.seekg(0, std::ios::beg);
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.read(data, count);
|
||||
return (m_stream.gcount());
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamAdapter::skip(const size_type count)
|
||||
{
|
||||
m_stream.exceptions(std::ios_base::badbit);
|
||||
m_stream.ignore(count);
|
||||
return (m_stream.gcount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamStringAdapter
|
||||
|
||||
inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
|
||||
: m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
|
||||
const string::size_type begin, const string::size_type end)
|
||||
: m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamStringAdapter::eof() const
|
||||
{
|
||||
return (m_pos >= m_end);
|
||||
}
|
||||
|
||||
|
||||
void inputStreamStringAdapter::reset()
|
||||
{
|
||||
m_pos = m_begin;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
if (m_pos + count >= m_end)
|
||||
{
|
||||
const size_type remaining = m_end - m_pos;
|
||||
|
||||
std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
|
||||
m_pos = m_end;
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringAdapter::skip(const size_type count)
|
||||
{
|
||||
if (m_pos + count >= m_end)
|
||||
{
|
||||
const size_type remaining = m_end - m_pos;
|
||||
m_pos = m_end;
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamStringProxyAdapter
|
||||
|
||||
inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
|
||||
: m_buffer(buffer), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamStringProxyAdapter::eof() const
|
||||
{
|
||||
return (m_pos >= m_buffer.length());
|
||||
}
|
||||
|
||||
|
||||
void inputStreamStringProxyAdapter::reset()
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringProxyAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
const size_type remaining = m_buffer.length() - m_pos;
|
||||
|
||||
if (count > remaining)
|
||||
{
|
||||
std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
|
||||
m_pos = m_buffer.length();
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
|
||||
{
|
||||
const size_type remaining = m_buffer.length() - m_pos;
|
||||
|
||||
if (count > remaining)
|
||||
{
|
||||
m_pos = m_buffer.length();
|
||||
return (remaining);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return (count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamPointerAdapter
|
||||
|
||||
inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
|
||||
: m_stream(is), m_own(own)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inputStreamPointerAdapter::inputStreamPointerAdapter(const inputStreamPointerAdapter&)
|
||||
: inputStream(), m_stream(NULL), m_own(false)
|
||||
{
|
||||
// Not copiable
|
||||
}
|
||||
|
||||
|
||||
inputStreamPointerAdapter::~inputStreamPointerAdapter()
|
||||
{
|
||||
if (m_own)
|
||||
delete (m_stream);
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamPointerAdapter::eof() const
|
||||
{
|
||||
return (m_stream->eof());
|
||||
}
|
||||
|
||||
|
||||
void inputStreamPointerAdapter::reset()
|
||||
{
|
||||
m_stream->exceptions(std::ios_base::badbit);
|
||||
m_stream->seekg(0, std::ios::beg);
|
||||
m_stream->clear();
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamPointerAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
m_stream->exceptions(std::ios_base::badbit);
|
||||
m_stream->read(data, count);
|
||||
return (m_stream->gcount());
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamPointerAdapter::skip(const size_type count)
|
||||
{
|
||||
m_stream->exceptions(std::ios_base::badbit);
|
||||
m_stream->ignore(count);
|
||||
return (m_stream->gcount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamByteBufferAdapter
|
||||
|
||||
inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
|
||||
: m_buffer(buffer), m_length(length), m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamByteBufferAdapter::eof() const
|
||||
{
|
||||
return m_pos >= m_length;
|
||||
}
|
||||
|
||||
|
||||
void inputStreamByteBufferAdapter::reset()
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamByteBufferAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
const size_type remaining = m_length - m_pos;
|
||||
|
||||
if (remaining < count)
|
||||
{
|
||||
std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
|
||||
m_pos += remaining;
|
||||
|
||||
return remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
|
||||
m_pos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
|
||||
{
|
||||
const size_type remaining = m_length - m_pos;
|
||||
|
||||
if (remaining < count)
|
||||
{
|
||||
m_pos += remaining;
|
||||
return remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pos += count;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
// outputStreamSocketAdapter
|
||||
|
||||
outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
|
||||
: m_socket(sok)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void outputStreamSocketAdapter::write
|
||||
(const value_type* const data, const size_type count)
|
||||
{
|
||||
m_socket.sendRaw(data, count);
|
||||
}
|
||||
|
||||
|
||||
void outputStreamSocketAdapter::flush()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
stream::size_type outputStreamSocketAdapter::getBlockSize()
|
||||
{
|
||||
return m_socket.getBlockSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// inputStreamSocketAdapter
|
||||
|
||||
inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
|
||||
: m_socket(sok)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool inputStreamSocketAdapter::eof() const
|
||||
{
|
||||
// Can't know...
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void inputStreamSocketAdapter::reset()
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::read
|
||||
(value_type* const data, const size_type count)
|
||||
{
|
||||
return m_socket.receiveRaw(data, count);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::skip
|
||||
(const size_type /* count */)
|
||||
{
|
||||
// Not supported
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
stream::size_type inputStreamSocketAdapter::getBlockSize()
|
||||
{
|
||||
return m_socket.getBlockSize();
|
||||
}
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
92
src/utility/streamUtils.cpp
Normal file
92
src/utility/streamUtils.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
#include <algorithm> // for std::copy
|
||||
#include <iterator> // for std::back_inserter
|
||||
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
outputStream& operator<<(outputStream& os, const stream::value_type c)
|
||||
{
|
||||
os.write(&c, 1);
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
outputStream& operator<<(outputStream& os, const string& str)
|
||||
{
|
||||
os.write(str.data(), str.length());
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
|
||||
{
|
||||
return bufferedStreamCopy(is, os, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
|
||||
const stream::size_type length, progressListener* progress)
|
||||
{
|
||||
const stream::size_type blockSize =
|
||||
std::min(is.getBlockSize(), os.getBlockSize());
|
||||
|
||||
std::vector <stream::value_type> vbuffer(blockSize);
|
||||
|
||||
stream::value_type* buffer = &vbuffer.front();
|
||||
stream::size_type total = 0;
|
||||
|
||||
if (progress != NULL)
|
||||
progress->start(length);
|
||||
|
||||
while (!is.eof())
|
||||
{
|
||||
const stream::size_type read = is.read(buffer, blockSize);
|
||||
|
||||
if (read != 0)
|
||||
{
|
||||
os.write(buffer, read);
|
||||
total += read;
|
||||
|
||||
if (progress != NULL)
|
||||
progress->progress(total, std::max(total, length));
|
||||
}
|
||||
}
|
||||
|
||||
if (progress != NULL)
|
||||
progress->stop(total);
|
||||
|
||||
return (total);
|
||||
}
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "vmime/utility/stringProxy.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "vmime/utility/smartPtr.hpp"
|
||||
#include "vmime/parserHelpers.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
|
||||
#include "vmime/utility/encoder/encoder.hpp"
|
||||
#include "vmime/utility/encoder/b64Encoder.hpp"
|
||||
#include "vmime/utility/encoder/qpEncoder.hpp"
|
||||
|
@ -33,6 +33,9 @@
|
||||
|
||||
#include "vmime/utility/stringUtils.hpp"
|
||||
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
{
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "vmime/config.hpp"
|
||||
#include "vmime/types.hpp"
|
||||
#include "vmime/constants.hpp"
|
||||
#include "vmime/utility/stream.hpp"
|
||||
#include "vmime/utility/smartPtr.hpp"
|
||||
|
||||
|
||||
@ -255,7 +254,26 @@ namespace vmime
|
||||
return y.dynamicCast <X>();
|
||||
}
|
||||
|
||||
/** Inherit from this class to indicate the subclass is not copyable,
|
||||
* ie. you want to prohibit copy construction and copy assignment.
|
||||
*/
|
||||
class noncopyable
|
||||
{
|
||||
protected:
|
||||
|
||||
noncopyable() { }
|
||||
virtual ~noncopyable() { }
|
||||
|
||||
private:
|
||||
|
||||
noncopyable(const noncopyable&);
|
||||
void operator=(const noncopyable&);
|
||||
};
|
||||
|
||||
} // vmime
|
||||
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
|
||||
|
||||
#endif // VMIME_BASE_HPP_INCLUDED
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
|
||||
#include "vmime/base.hpp"
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
#include "vmime/component.hpp"
|
||||
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
|
||||
#include "vmime/base.hpp"
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
|
@ -37,6 +37,9 @@
|
||||
#include "vmime/utility/encoder/b64Encoder.hpp"
|
||||
#include "vmime/utility/encoder/qpEncoder.hpp"
|
||||
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
|
||||
#include "vmime/platform.hpp"
|
||||
|
||||
#include "vmime/net/timeoutHandler.hpp"
|
||||
@ -3825,7 +3828,7 @@ public:
|
||||
: m_date_time(NULL), m_number(NULL), m_envelope(NULL),
|
||||
m_uniqueid(NULL), m_nstring(NULL), m_body(NULL), m_flag_list(NULL),
|
||||
m_section(NULL)
|
||||
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
|
76
vmime/utility/inputStream.hpp
Normal file
76
vmime/utility/inputStream.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** Simple input stream.
|
||||
*/
|
||||
|
||||
class inputStream : public stream
|
||||
{
|
||||
public:
|
||||
|
||||
/** Test for end of stream (no more data to read).
|
||||
*
|
||||
* @return true if we have reached the end of stream, false otherwise
|
||||
*/
|
||||
virtual bool eof() const = 0;
|
||||
|
||||
/** Set the read pointer to the beginning of the stream.
|
||||
*
|
||||
* @warning WARNING: this may not work for all stream types.
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
|
||||
/** Read data from the stream.
|
||||
*
|
||||
* @param data will receive the data read
|
||||
* @param count maximum number of bytes to read
|
||||
* @return number of bytes read
|
||||
*/
|
||||
virtual size_type read(value_type* const data, const size_type count) = 0;
|
||||
|
||||
/** Skip a number of bytes.
|
||||
*
|
||||
* @param count maximum number of bytes to ignore
|
||||
* @return number of bytes skipped
|
||||
*/
|
||||
virtual size_type skip(const size_type count) = 0;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
|
||||
|
64
vmime/utility/inputStreamAdapter.hpp
Normal file
64
vmime/utility/inputStreamAdapter.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for C++ standard input streams.
|
||||
*/
|
||||
|
||||
class inputStreamAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param is input stream to wrap
|
||||
*/
|
||||
inputStreamAdapter(std::istream& is);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
std::istream& m_stream;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
|
63
vmime/utility/inputStreamByteBufferAdapter.hpp
Normal file
63
vmime/utility/inputStreamByteBufferAdapter.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for reading from an array of bytes.
|
||||
*/
|
||||
|
||||
class inputStreamByteBufferAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamByteBufferAdapter(const byte_t* buffer, size_type length);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
const byte_t* m_buffer;
|
||||
const size_type m_length;
|
||||
|
||||
size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
|
||||
|
63
vmime/utility/inputStreamPointerAdapter.hpp
Normal file
63
vmime/utility/inputStreamPointerAdapter.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStreamAdapter.hpp"
|
||||
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for pointer to C++ standard input stream.
|
||||
*/
|
||||
|
||||
class inputStreamPointerAdapter : public inputStreamAdapter
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param is input stream to wrap
|
||||
* @param own if set to 'true', the pointer will be deleted when
|
||||
* this object is destroyed
|
||||
*/
|
||||
inputStreamPointerAdapter(std::istream* is, const bool own = true);
|
||||
~inputStreamPointerAdapter();
|
||||
|
||||
private:
|
||||
|
||||
std::istream* m_stream;
|
||||
const bool m_own;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
|
||||
|
77
vmime/utility/inputStreamSocketAdapter.hpp
Normal file
77
vmime/utility/inputStreamSocketAdapter.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
class socket; // forward reference
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An input stream that is connected to a socket.
|
||||
*/
|
||||
|
||||
class inputStreamSocketAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamSocketAdapter(net::socket& sok);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
size_type getBlockSize();
|
||||
|
||||
private:
|
||||
|
||||
inputStreamSocketAdapter(const inputStreamSocketAdapter&);
|
||||
|
||||
net::socket& m_socket;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
|
66
vmime/utility/inputStreamStringAdapter.hpp
Normal file
66
vmime/utility/inputStreamStringAdapter.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for string input.
|
||||
*/
|
||||
|
||||
class inputStreamStringAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamStringAdapter(const string& buffer);
|
||||
inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
inputStreamStringAdapter(const inputStreamStringAdapter&);
|
||||
|
||||
const string m_buffer; // do _NOT_ keep a reference...
|
||||
const string::size_type m_begin;
|
||||
const string::size_type m_end;
|
||||
string::size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
|
68
vmime/utility/inputStreamStringProxyAdapter.hpp
Normal file
68
vmime/utility/inputStreamStringProxyAdapter.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
class stringProxy;
|
||||
|
||||
|
||||
/** An adapter class for stringProxy input.
|
||||
*/
|
||||
|
||||
class inputStreamStringProxyAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param buffer stringProxy object to wrap
|
||||
*/
|
||||
inputStreamStringProxyAdapter(const stringProxy& buffer);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
|
||||
|
||||
const stringProxy& m_buffer;
|
||||
string::size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
|
||||
|
107
vmime/utility/outputStream.hpp
Normal file
107
vmime/utility/outputStream.hpp
Normal file
@ -0,0 +1,107 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/stream.hpp"
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++6
|
||||
# include <cstring>
|
||||
#endif
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** Simple output stream.
|
||||
*/
|
||||
|
||||
class outputStream : public stream
|
||||
{
|
||||
public:
|
||||
|
||||
/** Write data to the stream.
|
||||
*
|
||||
* @param data buffer containing data to write
|
||||
* @param count number of bytes to write
|
||||
*/
|
||||
virtual void write(const value_type* const data, const size_type count) = 0;
|
||||
|
||||
/** Flush this output stream and forces any buffered output
|
||||
* bytes to be written out to the stream.
|
||||
*/
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
|
||||
// Helpers functions
|
||||
|
||||
outputStream& operator<<(outputStream& os, const string& str);
|
||||
outputStream& operator<<(outputStream& os, const stream::value_type c);
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1200) // Internal compiler error with VC++6
|
||||
|
||||
inline outputStream& operator<<(outputStream& os, const char* str)
|
||||
{
|
||||
os.write(str, ::strlen(str));
|
||||
return (os);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <int N>
|
||||
outputStream& operator<<(outputStream& os, const char (&str)[N])
|
||||
{
|
||||
os.write(str, N - 1);
|
||||
return (os);
|
||||
}
|
||||
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER <= 1200)
|
||||
|
||||
|
||||
template <typename T>
|
||||
outputStream& operator<<(outputStream& os, const T& t)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss.imbue(std::locale::classic()); // no formatting
|
||||
|
||||
oss << t;
|
||||
|
||||
os << oss.str();
|
||||
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
|
||||
|
62
vmime/utility/outputStreamAdapter.hpp
Normal file
62
vmime/utility/outputStreamAdapter.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for C++ standard output streams.
|
||||
*/
|
||||
|
||||
class outputStreamAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param os output stream to wrap
|
||||
*/
|
||||
outputStreamAdapter(std::ostream& os);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
|
||||
std::ostream& m_stream;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
|
||||
|
58
vmime/utility/outputStreamByteArrayAdapter.hpp
Normal file
58
vmime/utility/outputStreamByteArrayAdapter.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for byte array output.
|
||||
*/
|
||||
|
||||
class outputStreamByteArrayAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamByteArrayAdapter(byteArray& array);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
|
||||
byteArray& m_array;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
|
||||
|
75
vmime/utility/outputStreamSocketAdapter.hpp
Normal file
75
vmime/utility/outputStreamSocketAdapter.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
class socket; // forward reference
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An output stream that is connected to a socket.
|
||||
*/
|
||||
|
||||
class outputStreamSocketAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamSocketAdapter(net::socket& sok);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
size_type getBlockSize();
|
||||
|
||||
private:
|
||||
|
||||
outputStreamSocketAdapter(const outputStreamSocketAdapter&);
|
||||
|
||||
net::socket& m_socket;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
|
||||
|
59
vmime/utility/outputStreamStringAdapter.hpp
Normal file
59
vmime/utility/outputStreamStringAdapter.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** An adapter class for string output.
|
||||
*/
|
||||
|
||||
class outputStreamStringAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamStringAdapter(string& buffer);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
size_type getBlockSize(){return 8192;}
|
||||
private:
|
||||
|
||||
string& m_buffer;
|
||||
};
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
|
||||
|
@ -25,40 +25,22 @@
|
||||
#define VMIME_UTILITY_STREAM_HPP_INCLUDED
|
||||
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
#include "vmime/types.hpp"
|
||||
|
||||
#include "vmime/utility/progressListener.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
class socket; // forward reference
|
||||
} // net
|
||||
} // vmime
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++6
|
||||
# include <cstring>
|
||||
#endif
|
||||
#include "vmime/base.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
class stringProxy;
|
||||
|
||||
|
||||
/** Base class for input/output stream.
|
||||
*/
|
||||
|
||||
class stream : public object
|
||||
class stream : public object, private noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
@ -81,365 +63,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Simple output stream.
|
||||
*/
|
||||
|
||||
class outputStream : public stream
|
||||
{
|
||||
public:
|
||||
|
||||
/** Write data to the stream.
|
||||
*
|
||||
* @param data buffer containing data to write
|
||||
* @param count number of bytes to write
|
||||
*/
|
||||
virtual void write(const value_type* const data, const size_type count) = 0;
|
||||
|
||||
/** Flush this output stream and forces any buffered output
|
||||
* bytes to be written out to the stream.
|
||||
*/
|
||||
virtual void flush() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Simple input stream.
|
||||
*/
|
||||
|
||||
class inputStream : public stream
|
||||
{
|
||||
public:
|
||||
|
||||
/** Test for end of stream (no more data to read).
|
||||
*
|
||||
* @return true if we have reached the end of stream, false otherwise
|
||||
*/
|
||||
virtual bool eof() const = 0;
|
||||
|
||||
/** Set the read pointer to the beginning of the stream.
|
||||
*
|
||||
* @warning WARNING: this may not work for all stream types.
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
|
||||
/** Read data from the stream.
|
||||
*
|
||||
* @param data will receive the data read
|
||||
* @param count maximum number of bytes to read
|
||||
* @return number of bytes read
|
||||
*/
|
||||
virtual size_type read(value_type* const data, const size_type count) = 0;
|
||||
|
||||
/** Skip a number of bytes.
|
||||
*
|
||||
* @param count maximum number of bytes to ignore
|
||||
* @return number of bytes skipped
|
||||
*/
|
||||
virtual size_type skip(const size_type count) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Helpers functions
|
||||
|
||||
outputStream& operator<<(outputStream& os, const string& str);
|
||||
outputStream& operator<<(outputStream& os, const stream::value_type c);
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1200) // Internal compiler error with VC++6
|
||||
|
||||
inline outputStream& operator<<(outputStream& os, const char* str)
|
||||
{
|
||||
os.write(str, ::strlen(str));
|
||||
return (os);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <int N>
|
||||
outputStream& operator<<(outputStream& os, const char (&str)[N])
|
||||
{
|
||||
os.write(str, N - 1);
|
||||
return (os);
|
||||
}
|
||||
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER <= 1200)
|
||||
|
||||
|
||||
template <typename T>
|
||||
outputStream& operator<<(outputStream& os, const T& t)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss.imbue(std::locale::classic()); // no formatting
|
||||
|
||||
oss << t;
|
||||
|
||||
os << oss.str();
|
||||
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
/** Copy data from one stream into another stream using a buffered method.
|
||||
*
|
||||
* @param is input stream (source data)
|
||||
* @param os output stream (destination for data)
|
||||
* @return number of bytes copied
|
||||
*/
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os);
|
||||
|
||||
/** Copy data from one stream into another stream using a buffered method
|
||||
* and notify progress state of the operation.
|
||||
*
|
||||
* @param is input stream (source data)
|
||||
* @param os output stream (destination for data)
|
||||
* @param length predicted number of bytes to copy
|
||||
* @param progress listener to notify
|
||||
* @return number of bytes copied
|
||||
*/
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
|
||||
const stream::size_type length, progressListener* progress);
|
||||
|
||||
|
||||
// Adapters
|
||||
|
||||
|
||||
/** An adapter class for C++ standard output streams.
|
||||
*/
|
||||
|
||||
class outputStreamAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param os output stream to wrap
|
||||
*/
|
||||
outputStreamAdapter(std::ostream& os);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
|
||||
std::ostream& m_stream;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for string output.
|
||||
*/
|
||||
|
||||
class outputStreamStringAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamStringAdapter(string& buffer);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
size_type getBlockSize(){return 8192;}
|
||||
private:
|
||||
|
||||
string& m_buffer;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for byte array output.
|
||||
*/
|
||||
|
||||
class outputStreamByteArrayAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamByteArrayAdapter(byteArray& array);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
|
||||
byteArray& m_array;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for C++ standard input streams.
|
||||
*/
|
||||
|
||||
class inputStreamAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param is input stream to wrap
|
||||
*/
|
||||
inputStreamAdapter(std::istream& is);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
std::istream& m_stream;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for string input.
|
||||
*/
|
||||
|
||||
class inputStreamStringAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamStringAdapter(const string& buffer);
|
||||
inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
inputStreamStringAdapter(const inputStreamStringAdapter&);
|
||||
|
||||
const string m_buffer; // do _NOT_ keep a reference...
|
||||
const string::size_type m_begin;
|
||||
const string::size_type m_end;
|
||||
string::size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for stringProxy input.
|
||||
*/
|
||||
|
||||
class inputStreamStringProxyAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param buffer stringProxy object to wrap
|
||||
*/
|
||||
inputStreamStringProxyAdapter(const stringProxy& buffer);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
|
||||
|
||||
const stringProxy& m_buffer;
|
||||
string::size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for pointer to C++ standard input stream.
|
||||
*/
|
||||
|
||||
class inputStreamPointerAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
/** @param is input stream to wrap
|
||||
* @param own if set to 'true', the pointer will be deleted when
|
||||
* this object is destroyed
|
||||
*/
|
||||
inputStreamPointerAdapter(std::istream* is, const bool own = true);
|
||||
~inputStreamPointerAdapter();
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
inputStreamPointerAdapter(const inputStreamPointerAdapter&);
|
||||
|
||||
std::istream* m_stream;
|
||||
const bool m_own;
|
||||
};
|
||||
|
||||
|
||||
/** An adapter class for reading from an array of bytes.
|
||||
*/
|
||||
|
||||
class inputStreamByteBufferAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamByteBufferAdapter(const byte_t* buffer, size_type length);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
private:
|
||||
|
||||
const byte_t* m_buffer;
|
||||
const size_type m_length;
|
||||
|
||||
size_type m_pos;
|
||||
};
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
/** An output stream that is connected to a socket.
|
||||
*/
|
||||
|
||||
class outputStreamSocketAdapter : public outputStream
|
||||
{
|
||||
public:
|
||||
|
||||
outputStreamSocketAdapter(net::socket& sok);
|
||||
|
||||
void write(const value_type* const data, const size_type count);
|
||||
void flush();
|
||||
|
||||
size_type getBlockSize();
|
||||
|
||||
private:
|
||||
|
||||
outputStreamSocketAdapter(const outputStreamSocketAdapter&);
|
||||
|
||||
net::socket& m_socket;
|
||||
};
|
||||
|
||||
|
||||
/** An input stream that is connected to a socket.
|
||||
*/
|
||||
|
||||
class inputStreamSocketAdapter : public inputStream
|
||||
{
|
||||
public:
|
||||
|
||||
inputStreamSocketAdapter(net::socket& sok);
|
||||
|
||||
bool eof() const;
|
||||
void reset();
|
||||
size_type read(value_type* const data, const size_type count);
|
||||
size_type skip(const size_type count);
|
||||
|
||||
size_type getBlockSize();
|
||||
|
||||
private:
|
||||
|
||||
inputStreamSocketAdapter(const inputStreamSocketAdapter&);
|
||||
|
||||
net::socket& m_socket;
|
||||
};
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
66
vmime/utility/streamUtils.hpp
Normal file
66
vmime/utility/streamUtils.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2012 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
|
||||
#define VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
|
||||
#include "vmime/utility/progressListener.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace utility {
|
||||
|
||||
|
||||
/** Copy data from one stream into another stream using a buffered method.
|
||||
*
|
||||
* @param is input stream (source data)
|
||||
* @param os output stream (destination for data)
|
||||
* @return number of bytes copied
|
||||
*/
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os);
|
||||
|
||||
/** Copy data from one stream into another stream using a buffered method
|
||||
* and notify progress state of the operation.
|
||||
*
|
||||
* @param is input stream (source data)
|
||||
* @param os output stream (destination for data)
|
||||
* @param length predicted number of bytes to copy
|
||||
* @param progress listener to notify
|
||||
* @return number of bytes copied
|
||||
*/
|
||||
|
||||
stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
|
||||
const stream::size_type length, progressListener* progress);
|
||||
|
||||
|
||||
} // utility
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "vmime/types.hpp"
|
||||
#include "vmime/utility/stream.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
#include "vmime/utility/progressListener.hpp"
|
||||
|
||||
|
||||
|
@ -68,6 +68,22 @@
|
||||
// Encoders
|
||||
#include "vmime/utility/encoder/encoderFactory.hpp"
|
||||
|
||||
// Streams
|
||||
#include "vmime/utility/filteredStream.hpp"
|
||||
#include "vmime/utility/inputStream.hpp"
|
||||
#include "vmime/utility/inputStreamAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamPointerAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamSocketAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
|
||||
#include "vmime/utility/outputStream.hpp"
|
||||
#include "vmime/utility/outputStreamAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamSocketAdapter.hpp"
|
||||
#include "vmime/utility/outputStreamStringAdapter.hpp"
|
||||
#include "vmime/utility/streamUtils.hpp"
|
||||
|
||||
// Message builder/parser
|
||||
#include "vmime/messageBuilder.hpp"
|
||||
#include "vmime/messageParser.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user