[evolution-data-server] Revise camel_session_get_service_by_url().



commit 8f0817e9f4d2c04ed81f6bbd82ebb43c0cafb8cf
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Apr 29 09:11:38 2011 -0400

    Revise camel_session_get_service_by_url().
    
    Some groupware providers use the same URL for their mail store and mail
    transport services, so add a CamelProviderType argument so callers have
    to explicitly say which service type they want.
    
    The need for this was discovered in bug #648841 for evolution-mapi.

 camel/camel-session.c                        |   30 ++++++++++++++++++++-----
 camel/camel-session.h                        |    3 +-
 docs/reference/camel/tmpl/camel-session.sgml |    1 +
 3 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/camel/camel-session.c b/camel/camel-session.c
index d0a1045..ddd57ac 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -577,9 +577,11 @@ camel_session_get_service (CamelSession *session,
  * camel_session_get_service_by_url:
  * @session: a #CamelSession
  * @url: a #CamelURL
+ * @type: a #CamelProviderType
  *
- * Looks up a #CamelService by trying to match its #CamelURL against
- * the given @url.  The service must have been previously added using
+ * Looks up a #CamelService by trying to match its #CamelURL against the
+ * given @url and then checking that the object is of the desired @type.
+ * The service must have been previously added using
  * camel_session_add_service().
  *
  * Note this function is significantly slower than camel_session_get_service().
@@ -590,7 +592,8 @@ camel_session_get_service (CamelSession *session,
  **/
 CamelService *
 camel_session_get_service_by_url (CamelSession *session,
-                                  CamelURL *url)
+                                  CamelURL *url,
+                                  CamelProviderType type)
 {
 	CamelService *match = NULL;
 	GList *list, *iter;
@@ -612,10 +615,25 @@ camel_session_get_service_by_url (CamelSession *session,
 		if (provider->url_equal == NULL)
 			continue;
 
-		if (provider->url_equal (url, service_url)) {
-			match = service;
-			break;
+		if (!provider->url_equal (url, service_url))
+			continue;
+
+		switch (type) {
+			case CAMEL_PROVIDER_STORE:
+				if (CAMEL_IS_STORE (service))
+					match = service;
+				break;
+			case CAMEL_PROVIDER_TRANSPORT:
+				if (CAMEL_IS_TRANSPORT (service))
+					match = service;
+				break;
+			default:
+				g_warn_if_reached ();
+				break;
 		}
+
+		if (match != NULL)
+			break;
 	}
 
 	g_list_free (list);
diff --git a/camel/camel-session.h b/camel/camel-session.h
index ad48d49..466f98f 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -170,7 +170,8 @@ CamelService *	camel_session_get_service	(CamelSession *session,
 						 const gchar *uid);
 CamelService *	camel_session_get_service_by_url
 						(CamelSession *session,
-						 CamelURL *url);
+						 CamelURL *url,
+						 CamelProviderType type);
 GList *		camel_session_list_services	(CamelSession *session);
 gchar *		camel_session_get_password	(CamelSession *session,
 						 CamelService *service,
diff --git a/docs/reference/camel/tmpl/camel-session.sgml b/docs/reference/camel/tmpl/camel-session.sgml
index fdd6495..ad229f6 100644
--- a/docs/reference/camel/tmpl/camel-session.sgml
+++ b/docs/reference/camel/tmpl/camel-session.sgml
@@ -131,6 +131,7 @@ CamelSession
 
 @session: 
 @url: 
+ type: 
 @Returns: 
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]