diff options
36 files changed, 142 insertions, 113 deletions
diff --git a/doc/book/net.tex b/doc/book/net.tex index c5581e33..1e5f1803 100644 --- a/doc/book/net.tex +++ b/doc/book/net.tex @@ -68,7 +68,7 @@ services. Before using a messaging service, you must create and initialize a session object: \begin{lstlisting} -vmime::shared_ptr <net::session> theSession = vmime::make_shared <net::session>(); +vmime::shared_ptr <vmime::net::session> theSession = vmime::net::session::create(); \end{lstlisting} Session properties include: @@ -328,8 +328,7 @@ This is how to use it: \begin{lstlisting} // First, create a session -vmime::shared_ptr <vmime::net::session> sess = - vmime::make_shared <vmime::net::session>(); +vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); // Next, initialize a service which will use our authenticator vmime::shared_ptr <vmime::net::store> st = @@ -417,8 +416,7 @@ const vmime::string msgData = // Create a new session vmime::utility::url url("smtp://example.com"); -vmime::shared_ptr <vmime::net::session> sess = - vmime::make_shared <vmime::net::session>(); +vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); // Create an instance of the transport service vmime::shared_ptr <vmime::net::transport> tr = sess->getTransport(url); @@ -471,8 +469,7 @@ store service: // Create a new session vmime::utility::url url("imap://vincent:password@imap:example.org"); -vmime::shared_ptr <vmime::net::session> sess = - vmime::make_shared <vmime::net::session>(); +vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); // Create an instance of the transport service vmime::shared_ptr <vmime::net::store> store = sess->getStore(url); diff --git a/examples/example6.cpp b/examples/example6.cpp index 09c61014..c2f0c2dd 100644 --- a/examples/example6.cpp +++ b/examples/example6.cpp @@ -38,8 +38,7 @@ // Global session object -static vmime::shared_ptr <vmime::net::session> g_session - = vmime::make_shared <vmime::net::session>(); +static vmime::shared_ptr <vmime::net::session> g_session = vmime::net::session::create(); /** Returns the messaging protocols supported by VMime. diff --git a/src/vmime/net/events.hpp b/src/vmime/net/events.hpp index 0c6a16d3..18bc0e52 100644 --- a/src/vmime/net/events.hpp +++ b/src/vmime/net/events.hpp @@ -47,7 +47,7 @@ namespace events { /** Event occurring on folders or messages. */ -class VMIME_EXPORT event : public object +class VMIME_EXPORT event : public object, public enable_shared_from_this <event> { public: diff --git a/src/vmime/net/folder.hpp b/src/vmime/net/folder.hpp index fc21d6b3..5186bae0 100644 --- a/src/vmime/net/folder.hpp +++ b/src/vmime/net/folder.hpp @@ -59,11 +59,11 @@ class store; /** Abstract representation of a folder in a message store. */ -class VMIME_EXPORT folder : public object +class VMIME_EXPORT folder : public object, public enable_shared_from_this <folder> { protected: - folder(const folder&) : object() { } + folder(const folder&) : object(), enable_shared_from_this <folder>() { } folder() { } diff --git a/src/vmime/net/imap/IMAPCommand.hpp b/src/vmime/net/imap/IMAPCommand.hpp index facbed78..dd499859 100644 --- a/src/vmime/net/imap/IMAPCommand.hpp +++ b/src/vmime/net/imap/IMAPCommand.hpp @@ -48,7 +48,7 @@ class IMAPConnection; /** An IMAP command that will be sent to the server. */ -class VMIME_EXPORT IMAPCommand : public object +class VMIME_EXPORT IMAPCommand : public object, public enable_shared_from_this <IMAPCommand> { public: diff --git a/src/vmime/net/imap/IMAPConnection.cpp b/src/vmime/net/imap/IMAPConnection.cpp index 4daa2774..0cc08178 100644 --- a/src/vmime/net/imap/IMAPConnection.cpp +++ b/src/vmime/net/imap/IMAPConnection.cpp @@ -325,7 +325,7 @@ void IMAPConnection::authenticateSASL() std::vector <shared_ptr <security::sasl::SASLMechanism> > mechList; shared_ptr <security::sasl::SASLContext> saslContext = - make_shared <security::sasl::SASLContext>(); + security::sasl::SASLContext::create(); for (unsigned int i = 0 ; i < saslMechs.size() ; ++i) { diff --git a/src/vmime/net/imap/IMAPConnection.hpp b/src/vmime/net/imap/IMAPConnection.hpp index b863ce33..0ce9092d 100644 --- a/src/vmime/net/imap/IMAPConnection.hpp +++ b/src/vmime/net/imap/IMAPConnection.hpp @@ -52,7 +52,7 @@ class IMAPStore; class IMAPCommand; -class VMIME_EXPORT IMAPConnection : public object +class VMIME_EXPORT IMAPConnection : public object, public enable_shared_from_this <IMAPConnection> { public: diff --git a/src/vmime/net/imap/IMAPFolder.cpp b/src/vmime/net/imap/IMAPFolder.cpp index fbc23d4d..8761de81 100644 --- a/src/vmime/net/imap/IMAPFolder.cpp +++ b/src/vmime/net/imap/IMAPFolder.cpp @@ -652,7 +652,7 @@ shared_ptr <folder> IMAPFolder::getFolder(const folder::path::component& name) if (!store) throw exceptions::illegal_state("Store disconnected"); - return make_shared <IMAPFolder>(m_path / name, store, shared_ptr <folderAttributes>()); + return shared_ptr <IMAPFolder>(new IMAPFolder(m_path / name, store, shared_ptr <folderAttributes>())); } @@ -734,7 +734,7 @@ std::vector <shared_ptr <folder> > IMAPFolder::getFolders(const bool recursive) IMAPUtils::mailboxFlagsToFolderAttributes (m_connection, mailbox_flag_list, *attribs); - v.push_back(make_shared <IMAPFolder>(path, store, attribs)); + v.push_back(shared_ptr <IMAPFolder>(new IMAPFolder(path, store, attribs))); } } @@ -945,7 +945,9 @@ shared_ptr <folder> IMAPFolder::getParent() if (m_path.isEmpty()) return null; else - return make_shared <IMAPFolder>(m_path.getParent(), m_store.lock(), shared_ptr <folderAttributes>()); + return shared_ptr <IMAPFolder>( + new IMAPFolder(m_path.getParent(), m_store.lock(), shared_ptr <folderAttributes>()) + ); } diff --git a/src/vmime/net/imap/IMAPFolder.hpp b/src/vmime/net/imap/IMAPFolder.hpp index 0841c7b7..d4e1c34a 100644 --- a/src/vmime/net/imap/IMAPFolder.hpp +++ b/src/vmime/net/imap/IMAPFolder.hpp @@ -63,11 +63,10 @@ private: friend class IMAPMessage; IMAPFolder(const IMAPFolder&); + IMAPFolder(const folder::path& path, shared_ptr <IMAPStore> store, shared_ptr <folderAttributes> attribs); public: - IMAPFolder(const folder::path& path, shared_ptr <IMAPStore> store, shared_ptr <folderAttributes> attribs); - ~IMAPFolder(); int getMode() const; diff --git a/src/vmime/net/imap/IMAPStore.cpp b/src/vmime/net/imap/IMAPStore.cpp index cc7c7a3f..bf93f284 100644 --- a/src/vmime/net/imap/IMAPStore.cpp +++ b/src/vmime/net/imap/IMAPStore.cpp @@ -75,10 +75,10 @@ shared_ptr <folder> IMAPStore::getRootFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <IMAPFolder> - (folder::path(), - dynamicCast <IMAPStore>(shared_from_this()), - shared_ptr <folderAttributes>()); + return shared_ptr <IMAPFolder> + (new IMAPFolder(folder::path(), + dynamicCast <IMAPStore>(shared_from_this()), + shared_ptr <folderAttributes>())); } @@ -87,10 +87,10 @@ shared_ptr <folder> IMAPStore::getDefaultFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <IMAPFolder> - (folder::path::component("INBOX"), - dynamicCast <IMAPStore>(shared_from_this()), - shared_ptr <folderAttributes>()); + return shared_ptr <IMAPFolder> + (new IMAPFolder(folder::path::component("INBOX"), + dynamicCast <IMAPStore>(shared_from_this()), + shared_ptr <folderAttributes>())); } @@ -99,10 +99,10 @@ shared_ptr <folder> IMAPStore::getFolder(const folder::path& path) if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <IMAPFolder> - (path, - dynamicCast <IMAPStore>(shared_from_this()), - shared_ptr <folderAttributes>()); + return shared_ptr <IMAPFolder> + (new IMAPFolder(path, + dynamicCast <IMAPStore>(shared_from_this()), + shared_ptr <folderAttributes>())); } diff --git a/src/vmime/net/maildir/maildirFolder.cpp b/src/vmime/net/maildir/maildirFolder.cpp index 94cf5b68..8951cb1c 100644 --- a/src/vmime/net/maildir/maildirFolder.cpp +++ b/src/vmime/net/maildir/maildirFolder.cpp @@ -462,7 +462,7 @@ shared_ptr <folder> maildirFolder::getFolder(const folder::path::component& name if (!store) throw exceptions::illegal_state("Store disconnected"); - return make_shared <maildirFolder>(m_path / name, store); + return shared_ptr <maildirFolder>(new maildirFolder(m_path / name, store)); } @@ -495,7 +495,7 @@ void maildirFolder::listFolders(std::vector <shared_ptr <folder> >& list, const for (std::vector <folder::path>::size_type i = 0, n = pathList.size() ; i < n ; ++i) { shared_ptr <maildirFolder> subFolder = - make_shared <maildirFolder>(pathList[i], store); + shared_ptr <maildirFolder>(new maildirFolder(pathList[i], store)); list.push_back(subFolder); } @@ -1170,7 +1170,7 @@ shared_ptr <folder> maildirFolder::getParent() if (m_path.isEmpty()) return null; else - return make_shared <maildirFolder>(m_path.getParent(), m_store.lock()); + return shared_ptr <maildirFolder>(new maildirFolder(m_path.getParent(), m_store.lock())); } diff --git a/src/vmime/net/maildir/maildirFolder.hpp b/src/vmime/net/maildir/maildirFolder.hpp index a5f74186..d6bdb7e8 100644 --- a/src/vmime/net/maildir/maildirFolder.hpp +++ b/src/vmime/net/maildir/maildirFolder.hpp @@ -61,11 +61,10 @@ private: friend class maildirMessage; maildirFolder(const maildirFolder&) : folder() { } + maildirFolder(const folder::path& path, shared_ptr <maildirStore> store); public: - maildirFolder(const folder::path& path, shared_ptr <maildirStore> store); - ~maildirFolder(); diff --git a/src/vmime/net/maildir/maildirStore.cpp b/src/vmime/net/maildir/maildirStore.cpp index b6efa62d..3c777551 100644 --- a/src/vmime/net/maildir/maildirStore.cpp +++ b/src/vmime/net/maildir/maildirStore.cpp @@ -83,9 +83,9 @@ shared_ptr <folder> maildirStore::getRootFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <maildirFolder> - (folder::path(), - dynamicCast <maildirStore>(shared_from_this())); + return shared_ptr <maildirFolder> + (new maildirFolder(folder::path(), + dynamicCast <maildirStore>(shared_from_this()))); } @@ -94,9 +94,9 @@ shared_ptr <folder> maildirStore::getDefaultFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <maildirFolder> - (folder::path::component("inbox"), - dynamicCast <maildirStore>(shared_from_this())); + return shared_ptr <maildirFolder> + (new maildirFolder(folder::path::component("inbox"), + dynamicCast <maildirStore>(shared_from_this()))); } @@ -105,8 +105,8 @@ shared_ptr <folder> maildirStore::getFolder(const folder::path& path) if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <maildirFolder> - (path, dynamicCast <maildirStore>(shared_from_this())); + return shared_ptr <maildirFolder> + (new maildirFolder(path, dynamicCast <maildirStore>(shared_from_this()))); } diff --git a/src/vmime/net/message.hpp b/src/vmime/net/message.hpp index bc1b62b4..4c64a1cf 100644 --- a/src/vmime/net/message.hpp +++ b/src/vmime/net/message.hpp @@ -50,12 +50,12 @@ class messageStructure; /** A MIME part in a message. */ -class VMIME_EXPORT messagePart : public object +class VMIME_EXPORT messagePart : public object, public enable_shared_from_this <messagePart> { protected: messagePart() { } - messagePart(const messagePart&) : object() { } + messagePart(const messagePart&) : object(), enable_shared_from_this <messagePart>() { } virtual ~messagePart() { } @@ -126,12 +126,12 @@ public: /** Structure of a MIME part/message. */ -class VMIME_EXPORT messageStructure : public object +class VMIME_EXPORT messageStructure : public object, public enable_shared_from_this <messageStructure> { protected: messageStructure() { } - messageStructure(const messageStructure&) : object() { } + messageStructure(const messageStructure&) : object(), enable_shared_from_this <messageStructure>() { } public: @@ -164,12 +164,12 @@ public: /** Abstract representation of a message in a store/transport service. */ -class VMIME_EXPORT message : public object +class VMIME_EXPORT message : public object, public enable_shared_from_this <message> { protected: message() { } - message(const message&) : object() { } + message(const message&) : object(), enable_shared_from_this <message>() { } enum PrivateConstants { diff --git a/src/vmime/net/pop3/POP3Connection.cpp b/src/vmime/net/pop3/POP3Connection.cpp index a503ba88..9fa12fa5 100644 --- a/src/vmime/net/pop3/POP3Connection.cpp +++ b/src/vmime/net/pop3/POP3Connection.cpp @@ -409,7 +409,7 @@ void POP3Connection::authenticateSASL() std::vector <shared_ptr <security::sasl::SASLMechanism> > mechList; shared_ptr <security::sasl::SASLContext> saslContext = - make_shared <security::sasl::SASLContext>(); + security::sasl::SASLContext::create(); for (unsigned int i = 0 ; i < saslMechs.size() ; ++i) { diff --git a/src/vmime/net/pop3/POP3Connection.hpp b/src/vmime/net/pop3/POP3Connection.hpp index f40f9562..f40f1193 100644 --- a/src/vmime/net/pop3/POP3Connection.hpp +++ b/src/vmime/net/pop3/POP3Connection.hpp @@ -61,7 +61,7 @@ class POP3Store; /** Manage connection to a POP3 server. */ -class VMIME_EXPORT POP3Connection : public object +class VMIME_EXPORT POP3Connection : public object, public enable_shared_from_this <POP3Connection> { public: diff --git a/src/vmime/net/pop3/POP3Folder.cpp b/src/vmime/net/pop3/POP3Folder.cpp index 459cc043..b3bf88c9 100644 --- a/src/vmime/net/pop3/POP3Folder.cpp +++ b/src/vmime/net/pop3/POP3Folder.cpp @@ -287,7 +287,7 @@ shared_ptr <folder> POP3Folder::getFolder(const folder::path::component& name) if (!store) throw exceptions::illegal_state("Store disconnected"); - return make_shared <POP3Folder>(m_path / name, store); + return shared_ptr <POP3Folder>(new POP3Folder(m_path / name, store)); } @@ -301,7 +301,7 @@ std::vector <shared_ptr <folder> > POP3Folder::getFolders(const bool /* recursiv if (m_path.isEmpty()) { std::vector <shared_ptr <folder> > v; - v.push_back(make_shared <POP3Folder>(folder::path::component("INBOX"), store)); + v.push_back(shared_ptr <POP3Folder>(new POP3Folder(folder::path::component("INBOX"), store))); return (v); } else @@ -520,7 +520,7 @@ shared_ptr <folder> POP3Folder::getParent() if (m_path.isEmpty()) return null; else - return make_shared <POP3Folder>(m_path.getParent(), m_store.lock()); + return shared_ptr <POP3Folder>(new POP3Folder(m_path.getParent(), m_store.lock())); } diff --git a/src/vmime/net/pop3/POP3Folder.hpp b/src/vmime/net/pop3/POP3Folder.hpp index 9b073cc8..339399d8 100644 --- a/src/vmime/net/pop3/POP3Folder.hpp +++ b/src/vmime/net/pop3/POP3Folder.hpp @@ -59,11 +59,10 @@ private: friend class POP3Message; POP3Folder(const POP3Folder&); + POP3Folder(const folder::path& path, shared_ptr <POP3Store> store); public: - POP3Folder(const folder::path& path, shared_ptr <POP3Store> store); - ~POP3Folder(); int getMode() const; diff --git a/src/vmime/net/pop3/POP3Store.cpp b/src/vmime/net/pop3/POP3Store.cpp index 63448d4f..4d1bb432 100644 --- a/src/vmime/net/pop3/POP3Store.cpp +++ b/src/vmime/net/pop3/POP3Store.cpp @@ -73,9 +73,9 @@ shared_ptr <folder> POP3Store::getDefaultFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <POP3Folder> - (folder::path(folder::path::component("INBOX")), - dynamicCast <POP3Store>(shared_from_this())); + return shared_ptr <POP3Folder> + (new POP3Folder(folder::path(folder::path::component("INBOX")), + dynamicCast <POP3Store>(shared_from_this()))); } @@ -84,8 +84,8 @@ shared_ptr <folder> POP3Store::getRootFolder() if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <POP3Folder> - (folder::path(), dynamicCast <POP3Store>(shared_from_this())); + return shared_ptr <POP3Folder> + (new POP3Folder(folder::path(), dynamicCast <POP3Store>(shared_from_this()))); } @@ -94,8 +94,8 @@ shared_ptr <folder> POP3Store::getFolder(const folder::path& path) if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return make_shared <POP3Folder> - (path, dynamicCast <POP3Store>(shared_from_this())); + return shared_ptr <POP3Folder> + (new POP3Folder(path, dynamicCast <POP3Store>(shared_from_this()))); } diff --git a/src/vmime/net/service.hpp b/src/vmime/net/service.hpp index b00d15ac..8d144aec 100644 --- a/src/vmime/net/service.hpp +++ b/src/vmime/net/service.hpp @@ -56,7 +56,7 @@ namespace net { /** Base class for messaging services. */ -class VMIME_EXPORT service : public object +class VMIME_EXPORT service : public object, public enable_shared_from_this <service> { protected: diff --git a/src/vmime/net/session.cpp b/src/vmime/net/session.cpp index cfe58925..7e335899 100644 --- a/src/vmime/net/session.cpp +++ b/src/vmime/net/session.cpp @@ -48,30 +48,33 @@ session::session() } -session::session(const session& sess) - : object(), m_props(sess.m_props) +session::session(const propertySet& props) + : m_props(props) { #if VMIME_HAVE_TLS_SUPPORT - m_tlsProps = make_shared <tls::TLSProperties>(*sess.m_tlsProps); + m_tlsProps = make_shared <tls::TLSProperties>(); #endif // VMIME_HAVE_TLS_SUPPORT } -session::session(const propertySet& props) - : m_props(props) +session::~session() { +} -#if VMIME_HAVE_TLS_SUPPORT - m_tlsProps = make_shared <tls::TLSProperties>(); -#endif // VMIME_HAVE_TLS_SUPPORT +// static +shared_ptr <session> session::create() +{ + return shared_ptr <session>(new session()); } -session::~session() +// static +shared_ptr <session> session::create(const propertySet& props) { + return shared_ptr <session>(new session(props)); } diff --git a/src/vmime/net/session.hpp b/src/vmime/net/session.hpp index 1145ae12..3165e1ce 100644 --- a/src/vmime/net/session.hpp +++ b/src/vmime/net/session.hpp @@ -54,15 +54,24 @@ class transport; * for connection to a service. */ -class VMIME_EXPORT session : public object +class VMIME_EXPORT session : public object, public enable_shared_from_this <session> { public: - session(); - session(const session& sess); - session(const propertySet& props); + /** Construct a new session. + * + * @return pointer to a new session + */ + static shared_ptr <session> create(); - virtual ~session(); + /** Construct a new session given properties. + * + * @param props session properties + * @return pointer to a new session + */ + static shared_ptr <session> create(const propertySet& props); + + ~session(); /** Return a transport service instance for the protocol specified * in the session properties. @@ -169,6 +178,10 @@ public: private: + session(); + session(const propertySet& props); + + propertySet m_props; #if VMIME_HAVE_TLS_SUPPORT diff --git a/src/vmime/net/smtp/SMTPConnection.cpp b/src/vmime/net/smtp/SMTPConnection.cpp index 4832929c..26f1a4b0 100644 --- a/src/vmime/net/smtp/SMTPConnection.cpp +++ b/src/vmime/net/smtp/SMTPConnection.cpp @@ -330,7 +330,7 @@ void SMTPConnection::authenticateSASL() std::vector <shared_ptr <security::sasl::SASLMechanism> > mechList; shared_ptr <security::sasl::SASLContext> saslContext = - make_shared <security::sasl::SASLContext>(); + security::sasl::SASLContext::create(); for (unsigned int i = 0 ; i < saslMechs.size() ; ++i) { diff --git a/src/vmime/net/tls/TLSSession.hpp b/src/vmime/net/tls/TLSSession.hpp index 9e061f89..8951ffa4 100644 --- a/src/vmime/net/tls/TLSSession.hpp +++ b/src/vmime/net/tls/TLSSession.hpp @@ -46,7 +46,7 @@ namespace tls { /** Describe a TLS connection between a client and a server. */ -class VMIME_EXPORT TLSSession : public object +class VMIME_EXPORT TLSSession : public object, public enable_shared_from_this <TLSSession> { public: diff --git a/src/vmime/object.cpp b/src/vmime/object.cpp index 1c0d331f..d07c3c19 100644 --- a/src/vmime/object.cpp +++ b/src/vmime/object.cpp @@ -35,7 +35,6 @@ object::object() object::object(const object&) - : enable_shared_from_this <object>() { } diff --git a/src/vmime/object.hpp b/src/vmime/object.hpp index 0b12df3c..ecaafc1e 100644 --- a/src/vmime/object.hpp +++ b/src/vmime/object.hpp @@ -35,7 +35,7 @@ namespace vmime /** Base object for all objects in the library. */ -class VMIME_EXPORT object : public enable_shared_from_this <object> +class VMIME_EXPORT object { protected: diff --git a/src/vmime/security/cert/certificate.hpp b/src/vmime/security/cert/certificate.hpp index aef1f1f9..58e0638a 100644 --- a/src/vmime/security/cert/certificate.hpp +++ b/src/vmime/security/cert/certificate.hpp @@ -35,7 +35,7 @@ namespace cert { /** Identity certificate for a peer. */ -class VMIME_EXPORT certificate : public object +class VMIME_EXPORT certificate : public object, public enable_shared_from_this <certificate> { public: diff --git a/src/vmime/security/sasl/SASLContext.cpp b/src/vmime/security/sasl/SASLContext.cpp index 3474cbeb..fc474129 100644 --- a/src/vmime/security/sasl/SASLContext.cpp +++ b/src/vmime/security/sasl/SASLContext.cpp @@ -62,11 +62,18 @@ SASLContext::~SASLContext() } +// static +shared_ptr <SASLContext> SASLContext::create() +{ + return shared_ptr <SASLContext>(new SASLContext()); +} + + shared_ptr <SASLSession> SASLContext::createSession (const string& serviceName, shared_ptr <authenticator> auth, shared_ptr <SASLMechanism> mech) { - return make_shared <SASLSession> + return SASLSession::create (serviceName, dynamicCast <SASLContext>(shared_from_this()), auth, mech); } diff --git a/src/vmime/security/sasl/SASLContext.hpp b/src/vmime/security/sasl/SASLContext.hpp index 200f78db..7e1fff4a 100644 --- a/src/vmime/security/sasl/SASLContext.hpp +++ b/src/vmime/security/sasl/SASLContext.hpp @@ -44,7 +44,7 @@ namespace sasl { /** An SASL client context. */ -class VMIME_EXPORT SASLContext : public object +class VMIME_EXPORT SASLContext : public object, public enable_shared_from_this <SASLContext> { friend class SASLSession; friend class builtinSASLMechanism; @@ -54,8 +54,10 @@ public: ~SASLContext(); /** Construct and initialize a new SASL context. + * + * @return pointer to a new SASL context */ - SASLContext(); + static shared_ptr <SASLContext> create(); /** Create and initialize a new SASL session. * @@ -105,6 +107,10 @@ public: private: + SASLContext(); + SASLContext(SASLContext&); + + static const string getErrorMessage(const string& fname, const int code); diff --git a/src/vmime/security/sasl/SASLSession.cpp b/src/vmime/security/sasl/SASLSession.cpp index 087ef27b..c7e4b2f9 100644 --- a/src/vmime/security/sasl/SASLSession.cpp +++ b/src/vmime/security/sasl/SASLSession.cpp @@ -68,6 +68,15 @@ SASLSession::~SASLSession() } +// static +shared_ptr <SASLSession> SASLSession::create + (const string& serviceName, shared_ptr <SASLContext> ctx, + shared_ptr <authenticator> auth, shared_ptr <SASLMechanism> mech) +{ + return shared_ptr <SASLSession>(new SASLSession(serviceName, ctx, auth, mech)); +} + + void SASLSession::init() { shared_ptr <SASLAuthenticator> saslAuth = dynamicCast <SASLAuthenticator>(m_auth); diff --git a/src/vmime/security/sasl/SASLSession.hpp b/src/vmime/security/sasl/SASLSession.hpp index 21ccc420..96c43f5c 100644 --- a/src/vmime/security/sasl/SASLSession.hpp +++ b/src/vmime/security/sasl/SASLSession.hpp @@ -33,9 +33,10 @@ #include "vmime/types.hpp" +#include "vmime/net/socket.hpp" + #include "vmime/security/sasl/SASLAuthenticator.hpp" #include "vmime/security/sasl/SASLMechanism.hpp" -#include "vmime/security/sasl/SASLSocket.hpp" namespace vmime { @@ -48,7 +49,7 @@ class SASLContext; /** An SASL client session. */ -class VMIME_EXPORT SASLSession : public object +class VMIME_EXPORT SASLSession : public object, public enable_shared_from_this <SASLSession> { friend class builtinSASLMechanism; friend class SASLSocket; @@ -64,8 +65,9 @@ public: * @param auth authenticator to use for this session * @param mech SASL mechanism */ - SASLSession(const string& serviceName, shared_ptr <SASLContext> ctx, - shared_ptr <authenticator> auth, shared_ptr <SASLMechanism> mech); + static shared_ptr <SASLSession> create + (const string& serviceName, shared_ptr <SASLContext> ctx, + shared_ptr <authenticator> auth, shared_ptr <SASLMechanism> mech); /** Initialize this SASL session. This must be called before * calling any other method on this object (except accessors). @@ -133,6 +135,11 @@ public: private: + SASLSession + (const string& serviceName, shared_ptr <SASLContext> ctx, + shared_ptr <authenticator> auth, shared_ptr <SASLMechanism> mech); + + const string m_serviceName; shared_ptr <SASLContext> m_context; diff --git a/tests/net/imap/IMAPCommandTest.cpp b/tests/net/imap/IMAPCommandTest.cpp index 00054781..f274bb27 100644 --- a/tests/net/imap/IMAPCommandTest.cpp +++ b/tests/net/imap/IMAPCommandTest.cpp @@ -458,8 +458,7 @@ VMIME_TEST_SUITE_BEGIN(IMAPCommandTest) { vmime::shared_ptr <IMAPCommand> cmd = IMAPCommand::createCommand("MY_COMMAND param1 param2"); - vmime::shared_ptr <vmime::net::session> sess = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); vmime::shared_ptr <vmime::security::authenticator> auth = vmime::make_shared <vmime::security::defaultAuthenticator>(); diff --git a/tests/net/maildir/maildirStoreTest.cpp b/tests/net/maildir/maildirStoreTest.cpp index b456089a..11868c9d 100644 --- a/tests/net/maildir/maildirStoreTest.cpp +++ b/tests/net/maildir/maildirStoreTest.cpp @@ -473,8 +473,7 @@ private: vmime::shared_ptr <vmime::net::store> createAndConnectStore() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::store> store = session->getStore(getStoreURL()); diff --git a/tests/net/pop3/POP3StoreTest.cpp b/tests/net/pop3/POP3StoreTest.cpp index 5517f770..a6818d46 100644 --- a/tests/net/pop3/POP3StoreTest.cpp +++ b/tests/net/pop3/POP3StoreTest.cpp @@ -39,8 +39,7 @@ VMIME_TEST_SUITE_BEGIN(POP3StoreTest) void testCreateFromURL() { - vmime::shared_ptr <vmime::net::session> sess - = vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); // POP3 vmime::utility::url url("pop3://pop3.vmime.org"); @@ -57,8 +56,7 @@ VMIME_TEST_SUITE_BEGIN(POP3StoreTest) void testConnectToInvalidServer() { - vmime::shared_ptr <vmime::net::session> sess - = vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); vmime::utility::url url("pop3://invalid-pop3-server"); vmime::shared_ptr <vmime::net::store> store = sess->getStore(url); diff --git a/tests/net/pop3/POP3TestUtils.hpp b/tests/net/pop3/POP3TestUtils.hpp index beb202b8..b0ec09b8 100644 --- a/tests/net/pop3/POP3TestUtils.hpp +++ b/tests/net/pop3/POP3TestUtils.hpp @@ -30,7 +30,7 @@ class POP3TestStore : public vmime::net::pop3::POP3Store public: POP3TestStore() - : POP3Store(vmime::make_shared <vmime::net::session>(), + : POP3Store(vmime::net::session::create(), vmime::shared_ptr <vmime::security::authenticator>()) { } diff --git a/tests/net/smtp/SMTPTransportTest.cpp b/tests/net/smtp/SMTPTransportTest.cpp index 5997588e..dd5546cc 100644 --- a/tests/net/smtp/SMTPTransportTest.cpp +++ b/tests/net/smtp/SMTPTransportTest.cpp @@ -44,8 +44,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testConnectToInvalidServer() { - vmime::shared_ptr <vmime::net::session> sess - = vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create(); vmime::utility::url url("smtp://invalid-smtp-server"); vmime::shared_ptr <vmime::net::transport> store = sess->getTransport(url); @@ -55,8 +54,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testGreetingError() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::transport> tr = session->getTransport (vmime::utility::url("smtp://localhost")); @@ -70,8 +68,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testMAILandRCPT() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::transport> tr = session->getTransport (vmime::utility::url("smtp://localhost")); @@ -96,8 +93,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testChunking() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::transport> tr = session->getTransport (vmime::utility::url("smtp://localhost")); @@ -122,8 +118,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testSize_Chunking() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::transport> tr = session->getTransport (vmime::utility::url("smtp://localhost")); @@ -149,8 +144,7 @@ VMIME_TEST_SUITE_BEGIN(SMTPTransportTest) void testSize_NoChunking() { - vmime::shared_ptr <vmime::net::session> session = - vmime::make_shared <vmime::net::session>(); + vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create(); vmime::shared_ptr <vmime::net::transport> tr = session->getTransport (vmime::utility::url("smtp://localhost")); |