diff options
author | Dan Winship <danw@src.gnome.org> | 2001-03-26 22:01:33 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2001-03-26 22:01:33 +0800 |
commit | d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf (patch) | |
tree | a205fbbfee42f9621002e849340ac5c264e5541f | |
parent | 25d35e4efd9c8393d3b164c1967aa7babfaca6d4 (diff) | |
download | gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar.gz gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar.bz2 gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar.lz gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar.xz gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.tar.zst gsoc2013-evolution-d3ce110bb79d7e5fc7966e8375d79201ac6ffbaf.zip |
New. Return the provider for a URL.
* camel-session.c (camel_session_get_provider): New. Return
the provider for a URL.
svn path=/trunk/; revision=8941
-rw-r--r-- | camel/ChangeLog | 5 | ||||
-rw-r--r-- | camel/camel-session.c | 80 | ||||
-rw-r--r-- | camel/camel-session.h | 4 |
3 files changed, 71 insertions, 18 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index f05ad41461..67fa005e15 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,8 @@ +2001-03-26 Dan Winship <danw@ximian.com> + + * camel-session.c (camel_session_get_provider): New. Return + the provider for a URL. + 2001-03-25 Dan Winship <danw@ximian.com> * camel-url.c (camel_url_new_with_base): New URL parser with full diff --git a/camel/camel-session.c b/camel/camel-session.c index 6ec2c5f1cf..dd8f57b74d 100644 --- a/camel/camel-session.c +++ b/camel/camel-session.c @@ -246,6 +246,63 @@ camel_session_list_providers (CamelSession *session, gboolean load) return list; } +static CamelProvider * +get_provider_locked (CamelSession *session, const char *protocol, + CamelException *ex) +{ + CamelProvider *provider; + + provider = g_hash_table_lookup (session->providers, protocol); + if (!provider) { + /* See if there's one we can load. */ + char *path; + + path = g_hash_table_lookup (session->modules, protocol); + if (path) { + camel_provider_load (session, path, ex); + if (camel_exception_is_set (ex)) + return NULL; + } + provider = g_hash_table_lookup (session->providers, protocol); + } + + if (!provider) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID, + _("No provider available for protocol `%s'"), + protocol); + } + + return provider; +} + +/** + * camel_session_get_provider: + * @session: the session + * @url_string: the URL for the service whose provider you want + * @ex: a CamelException + * + * This returns the CamelProvider that would be used to handle + * @url_string, loading it in from disk if necessary. + * + * Return value: the provider, or %NULL, in which case @ex will be set. + **/ +CamelProvider * +camel_session_get_provider (CamelSession *session, const char *url_string, + CamelException *ex) +{ + CamelProvider *provider; + char *protocol; + + protocol = g_strndup (url_string, strcspn (url_string, ":")); + CAMEL_SESSION_LOCK(session, lock); + provider = get_provider_locked (session, protocol, ex); + CAMEL_SESSION_UNLOCK(session, lock); + g_free (protocol); + + return provider; +} + + static void service_cache_remove (CamelService *service, gpointer event_data, gpointer user_data) { @@ -298,27 +355,14 @@ camel_session_get_service (CamelSession *session, const char *url_string, /* We need to look up the provider so we can then lookup the service in the provider's cache */ CAMEL_SESSION_LOCK(session, lock); - provider = g_hash_table_lookup (session->providers, url->protocol); - if (!provider) { - /* See if there's one we can load. */ - char *path; - - path = g_hash_table_lookup (session->modules, url->protocol); - if (path) { - camel_provider_load (session, path, ex); - if (camel_exception_is_set (ex)) { - camel_url_free (url); - CAMEL_SESSION_UNLOCK(session, lock); - return NULL; - } - } - provider = g_hash_table_lookup (session->providers, url->protocol); - } - - if (!provider || !provider->object_types[type]) { + provider = get_provider_locked (session, url->protocol, ex); + if (provider && !provider->object_types[type]) { camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID, _("No provider available for protocol `%s'"), url->protocol); + provider = NULL; + } + if (!provider) { camel_url_free (url); CAMEL_SESSION_UNLOCK(session, lock); return NULL; diff --git a/camel/camel-session.h b/camel/camel-session.h index 39b65f7da6..c73fa853ce 100644 --- a/camel/camel-session.h +++ b/camel/camel-session.h @@ -95,6 +95,10 @@ void camel_session_register_provider (CamelSession *session, GList * camel_session_list_providers (CamelSession *session, gboolean load); +CamelProvider * camel_session_get_provider (CamelSession *session, + const char *url_string, + CamelException *ex); + CamelService * camel_session_get_service (CamelSession *session, const char *url_string, CamelProviderType type, |