Add e_source_registry_server_new_auth_session().
authorMatthew Barnes <mbarnes@redhat.com>
Fri, 1 Feb 2013 19:03:14 +0000 (14:03 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 1 Feb 2013 19:15:17 +0000 (14:15 -0500)
Convenience function instantiates an appropriate authentication session
type for the given data source UID.

docs/reference/libebackend/libebackend-sections.txt
libebackend/e-source-registry-server.c
libebackend/e-source-registry-server.h

index 96dc658..4441793 100644 (file)
@@ -408,6 +408,7 @@ e_source_registry_server_list_sources
 e_source_registry_server_find_extension
 e_source_registry_server_ref_backend
 e_source_registry_server_ref_backend_factory
+e_source_registry_server_new_auth_session
 e_source_registry_server_authenticate_sync
 e_source_registry_server_authenticate
 e_source_registry_server_authenticate_finish
index f3bd2c5..e0db5b3 100644 (file)
@@ -2290,6 +2290,58 @@ e_source_registry_server_ref_backend_factory (ESourceRegistryServer *server,
 }
 
 /**
+ * e_source_registry_server_new_auth_session:
+ * @server: an #ESourceRegistryServer
+ * @authenticator: an #ESourceAuthenticator
+ * @source_uid: a data source identifier
+ *
+ * Convenience function instantiates an appropriate authentication
+ * session type for @source_uid.
+ *
+ * If @server has an #EServerSideSource instance for @source_uid, then
+ * its #EServerSideSource:auth-session-type is used to instantiate a new
+ * authentication session.  Otherwise a plain #EAuthenticationSession is
+ * instantiated.
+ *
+ * Unreference the returned #EAuthenticationSession with g_object_unref()
+ * when finished with it.
+ *
+ * Returns: a new #EAuthenticationSession for @source_uid
+ *
+ * Since: 3.8
+ **/
+EAuthenticationSession *
+e_source_registry_server_new_auth_session (ESourceRegistryServer *server,
+                                           ESourceAuthenticator *authenticator,
+                                           const gchar *source_uid)
+{
+       GType auth_session_type = E_TYPE_AUTHENTICATION_SESSION;
+       ESource *source;
+
+       g_return_val_if_fail (E_IS_SOURCE_REGISTRY_SERVER (server), NULL);
+       g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATOR (authenticator), NULL);
+       g_return_val_if_fail (source_uid != NULL, NULL);
+
+       source = e_source_registry_server_ref_source (server, source_uid);
+       if (source != NULL) {
+               auth_session_type =
+                       e_server_side_source_get_auth_session_type (
+                       E_SERVER_SIDE_SOURCE (source));
+               g_object_unref (source);
+       }
+
+       g_return_val_if_fail (
+               g_type_is_a (auth_session_type,
+               E_TYPE_AUTHENTICATION_SESSION), NULL);
+
+       return g_object_new (
+               auth_session_type,
+               "server", server,
+               "authenticator", authenticator,
+               "source-uid", source_uid, NULL);
+}
+
+/**
  * e_source_registry_server_authenticate_sync:
  * @server: an #ESourceRegistryServer
  * @session: an #EAuthenticationSession
index 725e0d0..add0b7c 100644 (file)
@@ -146,6 +146,11 @@ ECollectionBackendFactory *
                e_source_registry_server_ref_backend_factory
                                                (ESourceRegistryServer *server,
                                                 ESource *source);
+EAuthenticationSession *
+               e_source_registry_server_new_auth_session
+                                               (ESourceRegistryServer *server,
+                                                ESourceAuthenticator *authenticator,
+                                                const gchar *source_uid);
 gboolean       e_source_registry_server_authenticate_sync
                                                (ESourceRegistryServer *server,
                                                 EAuthenticationSession *session,