aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2004-12-26 16:46:52 +0000
committerVincent Richard <[email protected]>2004-12-26 16:46:52 +0000
commitf5f15e5076b979e1c532bf03a12cda96c42bf0b1 (patch)
treef35b0ed8fd175d08101f0a0cb09cc9db26ebe75d
parentFixed bug in URL parsing. (diff)
downloadvmime-f5f15e5076b979e1c532bf03a12cda96c42bf0b1.tar.gz
vmime-f5f15e5076b979e1c532bf03a12cda96c42bf0b1.zip
Allow creating a service from an URL.
-rw-r--r--ChangeLog3
-rw-r--r--src/exception.cpp6
-rw-r--r--src/exception.hpp2
-rw-r--r--src/messaging/serviceFactory.cpp9
-rw-r--r--src/messaging/session.cpp28
-rw-r--r--src/messaging/session.hpp25
6 files changed, 64 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 9547babc..b9d828f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,9 @@ VERSION 0.6.1-cvs
* Added versioning in library name (eg. libvmime-0.6.a).
+ * Allow creating a service from an URL (session::getStore("url") and
+ session::getTransport("url"))
+
2004-12-24 Vincent Richard <[email protected]>
* Renamed class 'disposition' to 'contentDisposition' and the enum
diff --git a/src/exception.cpp b/src/exception.cpp
index bdc1dd5f..9dc71c81 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -355,8 +355,10 @@ const string unsupported_option::name() const { return "unsupported_option"; }
//
no_service_available::~no_service_available() throw() {}
-no_service_available::no_service_available(const exception& other)
- : messaging_exception("No service available for this protocol.", other) {}
+no_service_available::no_service_available(const string& proto, const exception& other)
+ : messaging_exception(proto.empty()
+ ? "No service available for this protocol."
+ : "No service available for this protocol: '" + proto + "'.", other) {}
exception* no_service_available::clone() const { return new no_service_available(*this); }
const string no_service_available::name() const { return "no_service_available"; }
diff --git a/src/exception.hpp b/src/exception.hpp
index 4ed40485..d7f95b95 100644
--- a/src/exception.hpp
+++ b/src/exception.hpp
@@ -399,7 +399,7 @@ class no_service_available : public messaging_exception
{
public:
- no_service_available(const exception& other = NO_EXCEPTION);
+ no_service_available(const string& proto = "", const exception& other = NO_EXCEPTION);
~no_service_available() throw();
exception* clone() const;
diff --git a/src/messaging/serviceFactory.cpp b/src/messaging/serviceFactory.cpp
index 666e052d..9d51e79b 100644
--- a/src/messaging/serviceFactory.cpp
+++ b/src/messaging/serviceFactory.cpp
@@ -62,9 +62,10 @@ service* serviceFactory::create
if (u.getPort() != url::UNSPECIFIED_PORT)
sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.port"] = u.getPort();
- // Path portion of the URL is used to point a specific folder (empty = root)
- //if (!u.path().empty())
- // sess->properties()[serv->getInfos().getPropertyPrefix() + "server.path"] = u.getPath();
+ // Path portion of the URL is used to point a specific folder (empty = root).
+ // In maildir, this is used to point to the root of the message repository.
+ if (!u.getPath().empty())
+ sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.rootpath"] = u.getPath();
if (!u.getUsername().empty())
{
@@ -87,7 +88,7 @@ const serviceFactory::registeredService* serviceFactory::getServiceByProtocol(co
return (*it);
}
- throw exceptions::no_service_available();
+ throw exceptions::no_service_available(name);
}
diff --git a/src/messaging/session.cpp b/src/messaging/session.cpp
index 76d3c07a..8edfcab4 100644
--- a/src/messaging/session.cpp
+++ b/src/messaging/session.cpp
@@ -64,6 +64,20 @@ transport* session::getTransport(const string& protocol, authenticator* auth)
}
+transport* session::getTransport(const messaging::url& url, authenticator* auth)
+{
+ service* sv = serviceFactory::getInstance()->create(this, url, auth);
+
+ if (sv->getType() != service::TYPE_TRANSPORT)
+ {
+ delete (sv);
+ throw exceptions::no_service_available();
+ }
+
+ return static_cast<transport*>(sv);
+}
+
+
store* session::getStore(authenticator* auth)
{
return (getStore(m_props["store.protocol"], auth));
@@ -84,6 +98,20 @@ store* session::getStore(const string& protocol, authenticator* auth)
}
+store* session::getStore(const messaging::url& url, authenticator* auth)
+{
+ service* sv = serviceFactory::getInstance()->create(this, url, auth);
+
+ if (sv->getType() != service::TYPE_STORE)
+ {
+ delete (sv);
+ throw exceptions::no_service_available();
+ }
+
+ return static_cast<store*>(sv);
+}
+
+
const propertySet& session::getProperties() const
{
return (m_props);
diff --git a/src/messaging/session.hpp b/src/messaging/session.hpp
index 61e94fb1..4ee25157 100644
--- a/src/messaging/session.hpp
+++ b/src/messaging/session.hpp
@@ -23,6 +23,7 @@
#include "messaging/authenticator.hpp"
#include "messaging/progressionListener.hpp"
+#include "messaging/url.hpp"
#include "propertySet.hpp"
@@ -70,6 +71,16 @@ public:
*/
transport* getTransport(const string& protocol, authenticator* auth = NULL);
+ /** Return a transport service instance for the specified URL.
+ *
+ * @param url full URL with at least the protocol to use (eg: "smtp://myserver.com/")
+ * @param auth authenticator object to use for the new transport service. If
+ * NULL, a default one is used. The default authenticator simply return user
+ * credentials by reading the session properties "auth.username" and "auth.password".
+ * @return a new transport service
+ */
+ transport* getTransport(const messaging::url& url, authenticator* auth = NULL);
+
/** Return a transport service instance for the protocol specified
* in the session properties.
*
@@ -78,7 +89,7 @@ public:
* @param auth authenticator object to use for the new store service. If
* NULL, a default one is used. The default authenticator simply return user
* credentials by reading the session properties "auth.username" and "auth.password".
- * @return a new transport service
+ * @return a new store service
*/
store* getStore(authenticator* auth = NULL);
@@ -88,10 +99,20 @@ public:
* @param auth authenticator object to use for the new store service. If
* NULL, a default one is used. The default authenticator simply return user
* credentials by reading the session properties "auth.username" and "auth.password".
- * @return a new transport service
+ * @return a new store service
*/
store* getStore(const string& protocol, authenticator* auth = NULL);
+ /** Return a store service instance for the specified URL.
+ *
+ * @param url full URL with at least the protocol to use (eg: "imap://username:[email protected]/")
+ * @param auth authenticator object to use for the new store service. If
+ * NULL, a default one is used. The default authenticator simply return user
+ * credentials by reading the session properties "auth.username" and "auth.password".
+ * @return a new store service
+ */
+ store* getStore(const messaging::url& url, authenticator* auth = NULL);
+
/** Properties for the session and for the services.
*/
const propertySet& getProperties() const;