diff options
Diffstat (limited to 'vmime')
-rw-r--r-- | vmime/base.hpp | 20 | ||||
-rw-r--r-- | vmime/charset.hpp | 2 | ||||
-rw-r--r-- | vmime/component.hpp | 2 | ||||
-rw-r--r-- | vmime/net/imap/IMAPParser.hpp | 5 | ||||
-rw-r--r-- | vmime/utility/filteredStream.hpp | 3 | ||||
-rw-r--r-- | vmime/utility/inputStream.hpp | 76 | ||||
-rw-r--r-- | vmime/utility/inputStreamAdapter.hpp | 64 | ||||
-rw-r--r-- | vmime/utility/inputStreamByteBufferAdapter.hpp | 63 | ||||
-rw-r--r-- | vmime/utility/inputStreamPointerAdapter.hpp | 63 | ||||
-rw-r--r-- | vmime/utility/inputStreamSocketAdapter.hpp | 77 | ||||
-rw-r--r-- | vmime/utility/inputStreamStringAdapter.hpp | 66 | ||||
-rw-r--r-- | vmime/utility/inputStreamStringProxyAdapter.hpp | 68 | ||||
-rw-r--r-- | vmime/utility/outputStream.hpp | 107 | ||||
-rw-r--r-- | vmime/utility/outputStreamAdapter.hpp | 62 | ||||
-rw-r--r-- | vmime/utility/outputStreamByteArrayAdapter.hpp | 58 | ||||
-rw-r--r-- | vmime/utility/outputStreamSocketAdapter.hpp | 75 | ||||
-rw-r--r-- | vmime/utility/outputStreamStringAdapter.hpp | 59 | ||||
-rw-r--r-- | vmime/utility/stream.hpp | 381 | ||||
-rw-r--r-- | vmime/utility/streamUtils.hpp | 66 | ||||
-rw-r--r-- | vmime/utility/stringProxy.hpp | 1 | ||||
-rw-r--r-- | vmime/vmime.hpp | 16 |
21 files changed, 952 insertions, 382 deletions
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" |