aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/defaultConnectionInfos.cpp52
-rw-r--r--src/net/imap/IMAPConnection.cpp34
-rw-r--r--src/net/imap/IMAPStore.cpp32
-rw-r--r--src/net/maildir/maildirStore.cpp14
-rw-r--r--src/net/pop3/POP3Store.cpp36
-rw-r--r--src/net/sendmail/sendmailTransport.cpp14
-rw-r--r--src/net/smtp/SMTPTransport.cpp35
-rw-r--r--src/net/tls/TLSSecuredConnectionInfos.cpp63
8 files changed, 265 insertions, 15 deletions
diff --git a/src/net/defaultConnectionInfos.cpp b/src/net/defaultConnectionInfos.cpp
new file mode 100644
index 00000000..e6ecfae0
--- /dev/null
+++ b/src/net/defaultConnectionInfos.cpp
@@ -0,0 +1,52 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 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 2 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/net/defaultConnectionInfos.hpp"
+
+
+namespace vmime {
+namespace net {
+
+
+defaultConnectionInfos::defaultConnectionInfos(const string& host, const port_t port)
+ : m_host(host), m_port(port)
+{
+}
+
+
+const string defaultConnectionInfos::getHost() const
+{
+ return m_host;
+}
+
+
+const port_t defaultConnectionInfos::getPort() const
+{
+ return m_port;
+}
+
+
+} // net
+} // vmime
+
+
diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp
index 76c09316..e4a49041 100644
--- a/src/net/imap/IMAPConnection.cpp
+++ b/src/net/imap/IMAPConnection.cpp
@@ -25,12 +25,15 @@
#include "vmime/exception.hpp"
#include "vmime/platformDependant.hpp"
+#include "vmime/net/defaultConnectionInfos.hpp"
+
#if VMIME_HAVE_SASL_SUPPORT
#include "vmime/security/sasl/SASLContext.hpp"
#endif // VMIME_HAVE_SASL_SUPPORT
#if VMIME_HAVE_TLS_SUPPORT
#include "vmime/net/tls/TLSSession.hpp"
+ #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp"
#endif // VMIME_HAVE_TLS_SUPPORT
#include <sstream>
@@ -52,7 +55,8 @@ namespace imap {
IMAPConnection::IMAPConnection(weak_ref <IMAPStore> store, ref <security::authenticator> auth)
: m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL),
- m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL)
+ m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL),
+ m_secured(false)
{
}
@@ -92,7 +96,7 @@ void IMAPConnection::connect()
m_socket = m_store->getSocketFactory()->create();
#if VMIME_HAVE_TLS_SUPPORT
- if (m_store->isSecuredConnection()) // dedicated port/IMAPS
+ if (m_store->isIMAPS()) // dedicated port/IMAPS
{
ref <tls::TLSSession> tlsSession =
vmime::create <tls::TLSSession>(m_store->getCertificateVerifier());
@@ -101,8 +105,15 @@ void IMAPConnection::connect()
tlsSession->getSocket(m_socket);
m_socket = tlsSocket;
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>(address, port, tlsSession, tlsSocket);
}
#endif // VMIME_HAVE_TLS_SUPPORT
+ else
+ {
+ m_cntInfos = vmime::create <defaultConnectionInfos>(address, port);
+ }
m_socket->connect(address, port);
@@ -446,6 +457,10 @@ void IMAPConnection::startTLS()
m_socket = tlsSocket;
m_parser->setSocket(m_socket);
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>
+ (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket);
}
catch (exceptions::command_error&)
{
@@ -517,6 +532,18 @@ const bool IMAPConnection::isConnected() const
}
+const bool IMAPConnection::isSecuredConnection() const
+{
+ return m_secured;
+}
+
+
+ref <connectionInfos> IMAPConnection::getConnectionInfos() const
+{
+ return m_cntInfos;
+}
+
+
void IMAPConnection::disconnect()
{
if (!isConnected())
@@ -539,6 +566,9 @@ void IMAPConnection::internalDisconnect()
m_timeoutHandler = NULL;
m_state = STATE_LOGOUT;
+
+ m_secured = false;
+ m_cntInfos = NULL;
}
diff --git a/src/net/imap/IMAPStore.cpp b/src/net/imap/IMAPStore.cpp
index 95f96276..aba36751 100644
--- a/src/net/imap/IMAPStore.cpp
+++ b/src/net/imap/IMAPStore.cpp
@@ -33,7 +33,7 @@ namespace imap {
IMAPStore::IMAPStore(ref <session> sess, ref <security::authenticator> auth, const bool secured)
- : store(sess, getInfosInstance(), auth), m_connection(NULL), m_secured(secured)
+ : store(sess, getInfosInstance(), auth), m_connection(NULL), m_isIMAPS(secured)
{
}
@@ -91,12 +91,6 @@ const bool IMAPStore::isValidFolderName(const folder::path::component& /* name *
}
-const bool IMAPStore::isSecuredConnection() const
-{
- return m_secured;
-}
-
-
void IMAPStore::connect()
{
if (isConnected())
@@ -123,6 +117,30 @@ const bool IMAPStore::isConnected() const
}
+const bool IMAPStore::isIMAPS() const
+{
+ return m_isIMAPS;
+}
+
+
+const bool IMAPStore::isSecuredConnection() const
+{
+ if (m_connection == NULL)
+ return false;
+
+ return m_connection->isSecuredConnection();
+}
+
+
+ref <connectionInfos> IMAPStore::getConnectionInfos() const
+{
+ if (m_connection == NULL)
+ return NULL;
+
+ return m_connection->getConnectionInfos();
+}
+
+
void IMAPStore::disconnect()
{
if (!isConnected())
diff --git a/src/net/maildir/maildirStore.cpp b/src/net/maildir/maildirStore.cpp
index d1baf8dd..2803b17b 100644
--- a/src/net/maildir/maildirStore.cpp
+++ b/src/net/maildir/maildirStore.cpp
@@ -26,6 +26,8 @@
#include "vmime/exception.hpp"
#include "vmime/platformDependant.hpp"
+#include "vmime/net/defaultConnectionInfos.hpp"
+
// Helpers for service properties
#define GET_PROPERTY(type, prop) \
@@ -154,6 +156,18 @@ const bool maildirStore::isConnected() const
}
+const bool maildirStore::isSecuredConnection() const
+{
+ return false;
+}
+
+
+ref <connectionInfos> maildirStore::getConnectionInfos() const
+{
+ return vmime::create <defaultConnectionInfos>("localhost", 0);
+}
+
+
void maildirStore::disconnect()
{
for (std::list <maildirFolder*>::iterator it = m_folders.begin() ;
diff --git a/src/net/pop3/POP3Store.cpp b/src/net/pop3/POP3Store.cpp
index 29a22dcf..5340e50d 100644
--- a/src/net/pop3/POP3Store.cpp
+++ b/src/net/pop3/POP3Store.cpp
@@ -27,12 +27,15 @@
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/net/defaultConnectionInfos.hpp"
+
#if VMIME_HAVE_SASL_SUPPORT
#include "vmime/security/sasl/SASLContext.hpp"
#endif // VMIME_HAVE_SASL_SUPPORT
#if VMIME_HAVE_TLS_SUPPORT
#include "vmime/net/tls/TLSSession.hpp"
+ #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp"
#endif // VMIME_HAVE_TLS_SUPPORT
#include <algorithm>
@@ -54,7 +57,8 @@ namespace pop3 {
POP3Store::POP3Store(ref <session> sess, ref <security::authenticator> auth, const bool secured)
: store(sess, getInfosInstance(), auth), m_socket(NULL),
- m_authentified(false), m_timeoutHandler(NULL), m_secured(secured)
+ m_authentified(false), m_timeoutHandler(NULL),
+ m_isPOP3S(secured), m_secured(false)
{
}
@@ -130,7 +134,7 @@ void POP3Store::connect()
m_socket = getSocketFactory()->create();
#if VMIME_HAVE_TLS_SUPPORT
- if (m_secured) // dedicated port/POP3S
+ if (m_isPOP3S) // dedicated port/POP3S
{
ref <tls::TLSSession> tlsSession =
vmime::create <tls::TLSSession>(getCertificateVerifier());
@@ -139,8 +143,15 @@ void POP3Store::connect()
tlsSession->getSocket(m_socket);
m_socket = tlsSocket;
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>(address, port, tlsSession, tlsSocket);
}
#endif // VMIME_HAVE_TLS_SUPPORT
+ else
+ {
+ m_cntInfos = vmime::create <defaultConnectionInfos>(address, port);
+ }
m_socket->connect(address, port);
@@ -165,7 +176,7 @@ void POP3Store::connect()
const bool tlsRequired = HAS_PROPERTY(PROPERTY_CONNECTION_TLS_REQUIRED)
&& GET_PROPERTY(bool, PROPERTY_CONNECTION_TLS_REQUIRED);
- if (!m_secured && tls) // only if not POP3S
+ if (!m_isPOP3S && tls) // only if not POP3S
{
try
{
@@ -533,6 +544,10 @@ void POP3Store::startTLS()
tlsSocket->handshake(m_timeoutHandler);
m_socket = tlsSocket;
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>
+ (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket);
}
catch (exceptions::command_error&)
{
@@ -556,6 +571,18 @@ const bool POP3Store::isConnected() const
}
+const bool POP3Store::isSecuredConnection() const
+{
+ return m_secured;
+}
+
+
+ref <connectionInfos> POP3Store::getConnectionInfos() const
+{
+ return m_cntInfos;
+}
+
+
void POP3Store::disconnect()
{
if (!isConnected())
@@ -590,6 +617,9 @@ void POP3Store::internalDisconnect()
m_timeoutHandler = NULL;
m_authentified = false;
+
+ m_secured = false;
+ m_cntInfos = NULL;
}
diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp
index 2b5c4b04..514a66a6 100644
--- a/src/net/sendmail/sendmailTransport.cpp
+++ b/src/net/sendmail/sendmailTransport.cpp
@@ -28,6 +28,8 @@
#include "vmime/utility/childProcess.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/net/defaultConnectionInfos.hpp"
+
#include "vmime/config.hpp"
@@ -92,6 +94,18 @@ const bool sendmailTransport::isConnected() const
}
+const bool sendmailTransport::isSecuredConnection() const
+{
+ return false;
+}
+
+
+ref <connectionInfos> sendmailTransport::getConnectionInfos() const
+{
+ return vmime::create <defaultConnectionInfos>("localhost", 0);
+}
+
+
void sendmailTransport::disconnect()
{
if (!isConnected())
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp
index 48ea5cdc..385ebcec 100644
--- a/src/net/smtp/SMTPTransport.cpp
+++ b/src/net/smtp/SMTPTransport.cpp
@@ -28,12 +28,15 @@
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/net/defaultConnectionInfos.hpp"
+
#if VMIME_HAVE_SASL_SUPPORT
#include "vmime/security/sasl/SASLContext.hpp"
#endif // VMIME_HAVE_SASL_SUPPORT
#if VMIME_HAVE_TLS_SUPPORT
#include "vmime/net/tls/TLSSession.hpp"
+ #include "vmime/net/tls/TLSSecuredConnectionInfos.hpp"
#endif // VMIME_HAVE_TLS_SUPPORT
@@ -54,7 +57,7 @@ namespace smtp {
SMTPTransport::SMTPTransport(ref <session> sess, ref <security::authenticator> auth, const bool secured)
: transport(sess, getInfosInstance(), auth), m_socket(NULL),
m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL),
- m_secured(secured)
+ m_isSMTPS(secured), m_secured(false)
{
}
@@ -97,7 +100,7 @@ void SMTPTransport::connect()
m_socket = getSocketFactory()->create();
#if VMIME_HAVE_TLS_SUPPORT
- if (m_secured) // dedicated port/SMTPS
+ if (m_isSMTPS) // dedicated port/SMTPS
{
ref <tls::TLSSession> tlsSession =
vmime::create <tls::TLSSession>(getCertificateVerifier());
@@ -106,8 +109,15 @@ void SMTPTransport::connect()
tlsSession->getSocket(m_socket);
m_socket = tlsSocket;
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>(address, port, tlsSession, tlsSocket);
}
#endif // VMIME_HAVE_TLS_SUPPORT
+ else
+ {
+ m_cntInfos = vmime::create <defaultConnectionInfos>(address, port);
+ }
m_socket->connect(address, port);
@@ -163,7 +173,7 @@ void SMTPTransport::connect()
const bool tlsRequired = HAS_PROPERTY(PROPERTY_CONNECTION_TLS_REQUIRED)
&& GET_PROPERTY(bool, PROPERTY_CONNECTION_TLS_REQUIRED);
- if (!m_secured && tls) // only if not POP3S
+ if (!m_isSMTPS && tls) // only if not POP3S
{
try
{
@@ -436,6 +446,10 @@ void SMTPTransport::startTLS()
tlsSocket->handshake(m_timeoutHandler);
m_socket = tlsSocket;
+
+ m_secured = true;
+ m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>
+ (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket);
}
catch (exceptions::command_error&)
{
@@ -459,6 +473,18 @@ const bool SMTPTransport::isConnected() const
}
+const bool SMTPTransport::isSecuredConnection() const
+{
+ return m_secured;
+}
+
+
+ref <connectionInfos> SMTPTransport::getConnectionInfos() const
+{
+ return m_cntInfos;
+}
+
+
void SMTPTransport::disconnect()
{
if (!isConnected())
@@ -486,6 +512,9 @@ void SMTPTransport::internalDisconnect()
m_authentified = false;
m_extendedSMTP = false;
+
+ m_secured = false;
+ m_cntInfos = NULL;
}
diff --git a/src/net/tls/TLSSecuredConnectionInfos.cpp b/src/net/tls/TLSSecuredConnectionInfos.cpp
new file mode 100644
index 00000000..2670b81b
--- /dev/null
+++ b/src/net/tls/TLSSecuredConnectionInfos.cpp
@@ -0,0 +1,63 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 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 2 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/net/tls/TLSSecuredConnectionInfos.hpp"
+#include "vmime/net/tls/TLSSession.hpp"
+
+
+namespace vmime {
+namespace net {
+namespace tls {
+
+
+TLSSecuredConnectionInfos::TLSSecuredConnectionInfos
+ (const string& host, const port_t port,
+ ref <TLSSession> tlsSession, ref <TLSSocket> tlsSocket)
+ : m_host(host), m_port(port),
+ m_tlsSession(tlsSession), m_tlsSocket(tlsSocket)
+{
+}
+
+
+const string TLSSecuredConnectionInfos::getHost() const
+{
+ return m_host;
+}
+
+
+const port_t TLSSecuredConnectionInfos::getPort() const
+{
+ return m_port;
+}
+
+
+ref <const security::cert::certificateChain> TLSSecuredConnectionInfos::getPeerCertificates() const
+{
+ return m_tlsSocket->getPeerCertificates();
+}
+
+
+} // tls
+} // net
+} // vmime
+