aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SConstruct14
-rw-r--r--src/charsetConverter.cpp2
-rw-r--r--src/component.cpp1
-rw-r--r--src/encoding.cpp1
-rw-r--r--src/fileAttachment.cpp1
-rw-r--r--src/generatedMessageAttachment.cpp2
-rw-r--r--src/htmlTextPart.cpp2
-rw-r--r--src/mdn/MDNHelper.cpp2
-rw-r--r--src/mdn/receivedMDNInfos.cpp2
-rw-r--r--src/message.cpp2
-rw-r--r--src/net/imap/IMAPFolder.cpp2
-rw-r--r--src/net/imap/IMAPMessage.cpp2
-rw-r--r--src/net/imap/IMAPMessagePartContentHandler.cpp3
-rw-r--r--src/net/maildir/maildirFolder.cpp3
-rw-r--r--src/net/maildir/maildirMessage.cpp2
-rw-r--r--src/net/pop3/POP3Message.cpp2
-rw-r--r--src/net/pop3/POP3Store.cpp1
-rw-r--r--src/net/sendmail/sendmailTransport.cpp2
-rw-r--r--src/net/smtp/SMTPTransport.cpp2
-rw-r--r--src/net/transport.cpp3
-rw-r--r--src/parameter.cpp3
-rw-r--r--src/parsedMessageAttachment.cpp2
-rw-r--r--src/security/cert/X509Certificate.cpp2
-rw-r--r--src/security/sasl/SASLContext.cpp3
-rw-r--r--src/streamContentHandler.cpp4
-rw-r--r--src/stringContentHandler.cpp4
-rw-r--r--src/utility/encoder/defaultEncoder.cpp2
-rw-r--r--src/utility/inputStream.cpp33
-rw-r--r--src/utility/inputStreamAdapter.cpp70
-rw-r--r--src/utility/inputStreamByteBufferAdapter.cpp90
-rw-r--r--src/utility/inputStreamPointerAdapter.cpp46
-rw-r--r--src/utility/inputStreamSocketAdapter.cpp82
-rw-r--r--src/utility/inputStreamStringAdapter.cpp94
-rw-r--r--src/utility/inputStreamStringProxyAdapter.cpp89
-rw-r--r--src/utility/outputStream.cpp33
-rw-r--r--src/utility/outputStreamAdapter.cpp54
-rw-r--r--src/utility/outputStreamByteArrayAdapter.cpp51
-rw-r--r--src/utility/outputStreamSocketAdapter.cpp68
-rw-r--r--src/utility/outputStreamStringAdapter.cpp51
-rw-r--r--src/utility/stream.cpp485
-rw-r--r--src/utility/streamUtils.cpp92
-rw-r--r--src/utility/stringProxy.cpp2
-rw-r--r--src/word.cpp3
-rw-r--r--src/wordEncoder.cpp3
-rw-r--r--vmime/base.hpp20
-rw-r--r--vmime/charset.hpp2
-rw-r--r--vmime/component.hpp2
-rw-r--r--vmime/net/imap/IMAPParser.hpp5
-rw-r--r--vmime/utility/filteredStream.hpp3
-rw-r--r--vmime/utility/inputStream.hpp76
-rw-r--r--vmime/utility/inputStreamAdapter.hpp64
-rw-r--r--vmime/utility/inputStreamByteBufferAdapter.hpp63
-rw-r--r--vmime/utility/inputStreamPointerAdapter.hpp63
-rw-r--r--vmime/utility/inputStreamSocketAdapter.hpp77
-rw-r--r--vmime/utility/inputStreamStringAdapter.hpp66
-rw-r--r--vmime/utility/inputStreamStringProxyAdapter.hpp68
-rw-r--r--vmime/utility/outputStream.hpp107
-rw-r--r--vmime/utility/outputStreamAdapter.hpp62
-rw-r--r--vmime/utility/outputStreamByteArrayAdapter.hpp58
-rw-r--r--vmime/utility/outputStreamSocketAdapter.hpp75
-rw-r--r--vmime/utility/outputStreamStringAdapter.hpp59
-rw-r--r--vmime/utility/stream.hpp381
-rw-r--r--vmime/utility/streamUtils.hpp66
-rw-r--r--vmime/utility/stringProxy.hpp1
-rw-r--r--vmime/vmime.hpp16
65 files changed, 1884 insertions, 867 deletions
diff --git a/SConstruct b/SConstruct
index 11e884b5..ea5c4eb1 100644
--- a/SConstruct
+++ b/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',
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp
index 2135788c..cf75bdda 100644
--- a/src/charsetConverter.cpp
+++ b/src/charsetConverter.cpp
@@ -23,6 +23,8 @@
#include "vmime/charsetConverter.hpp"
#include "vmime/exception.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
extern "C"
diff --git a/src/component.cpp b/src/component.cpp
index fbf677b5..139cf664 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -23,6 +23,7 @@
#include "vmime/component.hpp"
#include "vmime/base.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
#include <sstream>
diff --git a/src/encoding.cpp b/src/encoding.cpp
index b4e79db7..5d99ab63 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -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>
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index da7c4b7d..cb23cd04 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -28,6 +28,7 @@
#include "vmime/exception.hpp"
#include "vmime/streamContentHandler.hpp"
+#include "vmime/utility/inputStreamPointerAdapter.hpp"
#include "vmime/contentDispositionField.hpp"
diff --git a/src/generatedMessageAttachment.cpp b/src/generatedMessageAttachment.cpp
index e9bd1a6e..443a9d30 100644
--- a/src/generatedMessageAttachment.cpp
+++ b/src/generatedMessageAttachment.cpp
@@ -23,6 +23,8 @@
#include "vmime/generatedMessageAttachment.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp
index c845b576..98524afb 100644
--- a/src/htmlTextPart.cpp
+++ b/src/htmlTextPart.cpp
@@ -31,6 +31,8 @@
#include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp
index b419b854..1dd7ff34 100644
--- a/src/mdn/MDNHelper.cpp
+++ b/src/mdn/MDNHelper.cpp
@@ -31,6 +31,8 @@
#include "vmime/path.hpp"
#include "vmime/dateTime.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/mdn/receivedMDNInfos.cpp b/src/mdn/receivedMDNInfos.cpp
index cff211cf..f97a58d4 100644
--- a/src/mdn/receivedMDNInfos.cpp
+++ b/src/mdn/receivedMDNInfos.cpp
@@ -23,6 +23,8 @@
#include "vmime/mdn/receivedMDNInfos.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/message.cpp b/src/message.cpp
index 6f4b046a..1b4f0867 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -24,6 +24,8 @@
#include "vmime/message.hpp"
#include "vmime/options.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <sstream>
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 50a2f2ba..81bf3861 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -34,6 +34,8 @@
#include "vmime/exception.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <algorithm>
#include <sstream>
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index bc661edf..702d5f2b 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -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>
diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp
index 4e6ba97a..85c6ec21 100644
--- a/src/net/imap/IMAPMessagePartContentHandler.cpp
+++ b/src/net/imap/IMAPMessagePartContentHandler.cpp
@@ -23,6 +23,9 @@
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp
index d11ae3b8..8c4b2758 100644
--- a/src/net/maildir/maildirFolder.cpp
+++ b/src/net/maildir/maildirFolder.cpp
@@ -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 {
diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp
index 51cd1bad..4ab75e75 100644
--- a/src/net/maildir/maildirMessage.cpp
+++ b/src/net/maildir/maildirMessage.cpp
@@ -31,6 +31,8 @@
#include "vmime/exception.hpp"
#include "vmime/platform.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp
index 50f4f874..69ef004c 100644
--- a/src/net/pop3/POP3Message.cpp
+++ b/src/net/pop3/POP3Message.cpp
@@ -25,6 +25,8 @@
#include "vmime/net/pop3/POP3Folder.hpp"
#include "vmime/net/pop3/POP3Store.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <sstream>
diff --git a/src/net/pop3/POP3Store.cpp b/src/net/pop3/POP3Store.cpp
index 9d554c6d..793112a7 100644
--- a/src/net/pop3/POP3Store.cpp
+++ b/src/net/pop3/POP3Store.cpp
@@ -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"
diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp
index 53ff0d15..e7762ccc 100644
--- a/src/net/sendmail/sendmailTransport.cpp
+++ b/src/net/sendmail/sendmailTransport.cpp
@@ -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"
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp
index d9fb7b86..bbbea755 100644
--- a/src/net/smtp/SMTPTransport.cpp
+++ b/src/net/smtp/SMTPTransport.cpp
@@ -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"
diff --git a/src/net/transport.cpp b/src/net/transport.cpp
index dd4663d8..f8ca7b7a 100644
--- a/src/net/transport.cpp
+++ b/src/net/transport.cpp
@@ -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 {
diff --git a/src/parameter.cpp b/src/parameter.cpp
index d757e1be..ccbe1a5b 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -27,6 +27,9 @@
#include "vmime/text.hpp"
#include "vmime/encoding.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+
namespace vmime
{
diff --git a/src/parsedMessageAttachment.cpp b/src/parsedMessageAttachment.cpp
index bde56aaf..cb7d71de 100644
--- a/src/parsedMessageAttachment.cpp
+++ b/src/parsedMessageAttachment.cpp
@@ -26,6 +26,8 @@
#include "vmime/stringContentHandler.hpp"
#include "vmime/contentDisposition.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/security/cert/X509Certificate.cpp b/src/security/cert/X509Certificate.cpp
index 1cd079c3..8df4e5e8 100644
--- a/src/security/cert/X509Certificate.cpp
+++ b/src/security/cert/X509Certificate.cpp
@@ -28,6 +28,8 @@
#include "vmime/security/cert/X509Certificate.hpp"
+#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
+
namespace vmime {
namespace security {
diff --git a/src/security/sasl/SASLContext.cpp b/src/security/sasl/SASLContext.cpp
index 51c2bed0..4bb33c14 100644
--- a/src/security/sasl/SASLContext.cpp
+++ b/src/security/sasl/SASLContext.cpp
@@ -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 {
diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp
index 2ebd073a..89a36b4f 100644
--- a/src/streamContentHandler.cpp
+++ b/src/streamContentHandler.cpp
@@ -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
{
diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp
index 4e85a6ce..5a1e72cd 100644
--- a/src/stringContentHandler.cpp
+++ b/src/stringContentHandler.cpp
@@ -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
{
diff --git a/src/utility/encoder/defaultEncoder.cpp b/src/utility/encoder/defaultEncoder.cpp
index 4d0ffb5d..e2d226e6 100644
--- a/src/utility/encoder/defaultEncoder.cpp
+++ b/src/utility/encoder/defaultEncoder.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/encoder/defaultEncoder.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
namespace vmime {
namespace utility {
diff --git a/src/utility/inputStream.cpp b/src/utility/inputStream.cpp
new file mode 100644
index 00000000..dd0adf4d
--- /dev/null
+++ b/src/utility/inputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamAdapter.cpp b/src/utility/inputStreamAdapter.cpp
new file mode 100644
index 00000000..b44b0841
--- /dev/null
+++ b/src/utility/inputStreamAdapter.cpp
@@ -0,0 +1,70 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamByteBufferAdapter.cpp b/src/utility/inputStreamByteBufferAdapter.cpp
new file mode 100644
index 00000000..92e779fe
--- /dev/null
+++ b/src/utility/inputStreamByteBufferAdapter.cpp
@@ -0,0 +1,90 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamPointerAdapter.cpp b/src/utility/inputStreamPointerAdapter.cpp
new file mode 100644
index 00000000..4d03e306
--- /dev/null
+++ b/src/utility/inputStreamPointerAdapter.cpp
@@ -0,0 +1,46 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamSocketAdapter.cpp b/src/utility/inputStreamSocketAdapter.cpp
new file mode 100644
index 00000000..b93cc3cd
--- /dev/null
+++ b/src/utility/inputStreamSocketAdapter.cpp
@@ -0,0 +1,82 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamStringAdapter.cpp b/src/utility/inputStreamStringAdapter.cpp
new file mode 100644
index 00000000..31c9fdaf
--- /dev/null
+++ b/src/utility/inputStreamStringAdapter.cpp
@@ -0,0 +1,94 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/inputStreamStringProxyAdapter.cpp b/src/utility/inputStreamStringProxyAdapter.cpp
new file mode 100644
index 00000000..5e4b60b9
--- /dev/null
+++ b/src/utility/inputStreamStringProxyAdapter.cpp
@@ -0,0 +1,89 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/outputStream.cpp b/src/utility/outputStream.cpp
new file mode 100644
index 00000000..8a65db53
--- /dev/null
+++ b/src/utility/outputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/outputStreamAdapter.cpp b/src/utility/outputStreamAdapter.cpp
new file mode 100644
index 00000000..2da94f16
--- /dev/null
+++ b/src/utility/outputStreamAdapter.cpp
@@ -0,0 +1,54 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/outputStreamByteArrayAdapter.cpp b/src/utility/outputStreamByteArrayAdapter.cpp
new file mode 100644
index 00000000..97b27d2b
--- /dev/null
+++ b/src/utility/outputStreamByteArrayAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/outputStreamSocketAdapter.cpp b/src/utility/outputStreamSocketAdapter.cpp
new file mode 100644
index 00000000..d933e73d
--- /dev/null
+++ b/src/utility/outputStreamSocketAdapter.cpp
@@ -0,0 +1,68 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/outputStreamStringAdapter.cpp b/src/utility/outputStreamStringAdapter.cpp
new file mode 100644
index 00000000..62b2a72c
--- /dev/null
+++ b/src/utility/outputStreamStringAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index ec30b7d3..1c940c2a 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -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
diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp
new file mode 100644
index 00000000..f1d3b9de
--- /dev/null
+++ b/src/utility/streamUtils.cpp
@@ -0,0 +1,92 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp
index a4ba6d22..74344b57 100644
--- a/src/utility/stringProxy.cpp
+++ b/src/utility/stringProxy.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/stringProxy.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <iterator>
#include <algorithm>
diff --git a/src/word.cpp b/src/word.cpp
index aeaa7371..79060a18 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -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"
diff --git a/src/wordEncoder.cpp b/src/wordEncoder.cpp
index 67bd7a1d..194a1890 100644
--- a/src/wordEncoder.cpp
+++ b/src/wordEncoder.cpp
@@ -33,6 +33,9 @@
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime
{
diff --git a/vmime/base.hpp b/vmime/base.hpp
index 60e637d2..b7940311 100644
--- a/vmime/base.hpp
+++ b/vmime/base.hpp
@@ -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
diff --git a/vmime/charset.hpp b/vmime/charset.hpp
index b2e241cc..5f5e8e58 100644
--- a/vmime/charset.hpp
+++ b/vmime/charset.hpp
@@ -26,6 +26,8 @@
#include "vmime/base.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
#include "vmime/component.hpp"
diff --git a/vmime/component.hpp b/vmime/component.hpp
index b38127fb..12b04060 100644
--- a/vmime/component.hpp
+++ b/vmime/component.hpp
@@ -26,6 +26,8 @@
#include "vmime/base.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
namespace vmime
diff --git a/vmime/net/imap/IMAPParser.hpp b/vmime/net/imap/IMAPParser.hpp
index d71c3ca7..f4305103 100644
--- a/vmime/net/imap/IMAPParser.hpp
+++ b/vmime/net/imap/IMAPParser.hpp
@@ -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)
-
+
{
}
diff --git a/vmime/utility/filteredStream.hpp b/vmime/utility/filteredStream.hpp
index 00be785a..2a55edde 100644
--- a/vmime/utility/filteredStream.hpp
+++ b/vmime/utility/filteredStream.hpp
@@ -27,7 +27,8 @@
#include <algorithm>
-#include "vmime/utility/stream.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
namespace vmime {
diff --git a/vmime/utility/inputStream.hpp b/vmime/utility/inputStream.hpp
new file mode 100644
index 00000000..4a76a7d1
--- /dev/null
+++ b/vmime/utility/inputStream.hpp
@@ -0,0 +1,76 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamAdapter.hpp b/vmime/utility/inputStreamAdapter.hpp
new file mode 100644
index 00000000..278ab529
--- /dev/null
+++ b/vmime/utility/inputStreamAdapter.hpp
@@ -0,0 +1,64 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamByteBufferAdapter.hpp b/vmime/utility/inputStreamByteBufferAdapter.hpp
new file mode 100644
index 00000000..0f6a442d
--- /dev/null
+++ b/vmime/utility/inputStreamByteBufferAdapter.hpp
@@ -0,0 +1,63 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamPointerAdapter.hpp b/vmime/utility/inputStreamPointerAdapter.hpp
new file mode 100644
index 00000000..44e9bad8
--- /dev/null
+++ b/vmime/utility/inputStreamPointerAdapter.hpp
@@ -0,0 +1,63 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamSocketAdapter.hpp b/vmime/utility/inputStreamSocketAdapter.hpp
new file mode 100644
index 00000000..0f99c215
--- /dev/null
+++ b/vmime/utility/inputStreamSocketAdapter.hpp
@@ -0,0 +1,77 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamStringAdapter.hpp b/vmime/utility/inputStreamStringAdapter.hpp
new file mode 100644
index 00000000..a7d986f1
--- /dev/null
+++ b/vmime/utility/inputStreamStringAdapter.hpp
@@ -0,0 +1,66 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/inputStreamStringProxyAdapter.hpp b/vmime/utility/inputStreamStringProxyAdapter.hpp
new file mode 100644
index 00000000..74b3f604
--- /dev/null
+++ b/vmime/utility/inputStreamStringProxyAdapter.hpp
@@ -0,0 +1,68 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/outputStream.hpp b/vmime/utility/outputStream.hpp
new file mode 100644
index 00000000..7372d200
--- /dev/null
+++ b/vmime/utility/outputStream.hpp
@@ -0,0 +1,107 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/outputStreamAdapter.hpp b/vmime/utility/outputStreamAdapter.hpp
new file mode 100644
index 00000000..be55d8db
--- /dev/null
+++ b/vmime/utility/outputStreamAdapter.hpp
@@ -0,0 +1,62 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/outputStreamByteArrayAdapter.hpp b/vmime/utility/outputStreamByteArrayAdapter.hpp
new file mode 100644
index 00000000..bf7d839c
--- /dev/null
+++ b/vmime/utility/outputStreamByteArrayAdapter.hpp
@@ -0,0 +1,58 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/outputStreamSocketAdapter.hpp b/vmime/utility/outputStreamSocketAdapter.hpp
new file mode 100644
index 00000000..e3d3eb0e
--- /dev/null
+++ b/vmime/utility/outputStreamSocketAdapter.hpp
@@ -0,0 +1,75 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/outputStreamStringAdapter.hpp b/vmime/utility/outputStreamStringAdapter.hpp
new file mode 100644
index 00000000..8c8b3048
--- /dev/null
+++ b/vmime/utility/outputStreamStringAdapter.hpp
@@ -0,0 +1,59 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index 1faab55f..566ab9df 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -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
diff --git a/vmime/utility/streamUtils.hpp b/vmime/utility/streamUtils.hpp
new file mode 100644
index 00000000..cdf70aad
--- /dev/null
+++ b/vmime/utility/streamUtils.hpp
@@ -0,0 +1,66 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// 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
+
diff --git a/vmime/utility/stringProxy.hpp b/vmime/utility/stringProxy.hpp
index 21c65ea8..66a6dfd7 100644
--- a/vmime/utility/stringProxy.hpp
+++ b/vmime/utility/stringProxy.hpp
@@ -29,6 +29,7 @@
#include "vmime/types.hpp"
#include "vmime/utility/stream.hpp"
+#include "vmime/utility/outputStream.hpp"
#include "vmime/utility/progressListener.hpp"
diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp
index f187b9e6..fd04853b 100644
--- a/vmime/vmime.hpp
+++ b/vmime/vmime.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"