From e0d50ce93c07a12ccac8031c12abe24735d05655 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 1 Feb 2013 13:23:48 -0500 Subject: [PATCH] EServerSideSource: Add an "auth-session-type" property. This will allow modules -- particularly the online accounts modules -- to subclass and customize EAuthenticationSession, and then register the subclass to be used for data sources under their purview. Care must be taken when subclassing, however, to comply with the D-Bus interaction protocol that clients will be expecting, lest the client be left hanging during its authenticate() call. --- .../reference/libebackend/libebackend-sections.txt | 2 + libebackend/e-server-side-source.c | 89 ++++++++++++++++++++++ libebackend/e-server-side-source.h | 5 ++ 3 files changed, 96 insertions(+) diff --git a/docs/reference/libebackend/libebackend-sections.txt b/docs/reference/libebackend/libebackend-sections.txt index 200698e..96dc658 100644 --- a/docs/reference/libebackend/libebackend-sections.txt +++ b/docs/reference/libebackend/libebackend-sections.txt @@ -366,6 +366,8 @@ e_server_side_source_get_node e_server_side_source_get_server e_server_side_source_get_allow_auth_prompt e_server_side_source_set_allow_auth_prompt +e_server_side_source_get_auth_session_type +e_server_side_source_set_auth_session_type e_server_side_source_get_exported e_server_side_source_get_write_directory e_server_side_source_set_write_directory diff --git a/libebackend/e-server-side-source.c b/libebackend/e-server-side-source.c index 2b63346..2daf021 100644 --- a/libebackend/e-server-side-source.c +++ b/libebackend/e-server-side-source.c @@ -54,6 +54,7 @@ struct _EServerSideSourcePrivate { gchar *file_contents; gboolean allow_auth_prompt; + GType auth_session_type; gchar *write_directory; }; @@ -67,6 +68,7 @@ struct _AsyncContext { enum { PROP_0, PROP_ALLOW_AUTH_PROMPT, + PROP_AUTH_SESSION_TYPE, PROP_EXPORTED, PROP_FILE, PROP_OAUTH2_SUPPORT, @@ -509,6 +511,12 @@ server_side_source_set_property (GObject *object, g_value_get_boolean (value)); return; + case PROP_AUTH_SESSION_TYPE: + e_server_side_source_set_auth_session_type ( + E_SERVER_SIDE_SOURCE (object), + g_value_get_gtype (value)); + return; + case PROP_FILE: server_side_source_set_file ( E_SERVER_SIDE_SOURCE (object), @@ -575,6 +583,13 @@ server_side_source_get_property (GObject *object, E_SERVER_SIDE_SOURCE (object))); return; + case PROP_AUTH_SESSION_TYPE: + g_value_set_boolean ( + value, + e_server_side_source_get_auth_session_type ( + E_SERVER_SIDE_SOURCE (object))); + return; + case PROP_EXPORTED: g_value_set_boolean ( value, @@ -1171,6 +1186,18 @@ e_server_side_source_class_init (EServerSideSourceClass *class) g_object_class_install_property ( object_class, + PROP_AUTH_SESSION_TYPE, + g_param_spec_gtype ( + "auth-session-type", + "Auth Session Type", + "The type of authentication session " + "to instantiate for this source", + E_TYPE_AUTHENTICATION_SESSION, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property ( + object_class, PROP_EXPORTED, g_param_spec_boolean ( "exported", @@ -1302,6 +1329,8 @@ e_server_side_source_init (EServerSideSource *source) user_dir = e_server_side_source_get_user_dir (); source->priv->write_directory = g_strdup (user_dir); + + source->priv->auth_session_type = E_TYPE_AUTHENTICATION_SESSION; } /** @@ -1712,6 +1741,66 @@ e_server_side_source_set_allow_auth_prompt (EServerSideSource *source, } /** + * e_server_side_source_get_auth_session_type: + * @source: an #EServerSideSource + * + * Returns the type of authentication session to use for @source, + * which will get passed to e_source_registry_server_authenticate(). + * + * This defaults to the #GType for #EAuthenticationSession. + * + * Returns: the type of authentication session to use for @source + * + * Since: 3.8 + **/ +GType +e_server_side_source_get_auth_session_type (EServerSideSource *source) +{ + g_return_val_if_fail ( + E_IS_SERVER_SIDE_SOURCE (source), + E_TYPE_AUTHENTICATION_SESSION); + + return source->priv->auth_session_type; +} + +/** + * e_server_side_source_set_auth_session_type: + * @source: an #EServerSideSource + * @auth_session_type: the type of authentication session to use for @source + * + * Sets the type of authentication session to use for @source, which will + * get passed to e_source_registry_server_authenticate(). + * + * @auth_session_type must be derived from #EAuthenticationSession, or else + * the function will reject the #GType with a runtime warning. + * + * This defaults to the #GType for #EAuthenticationSession. + * + * Since: 3.8 + **/ +void +e_server_side_source_set_auth_session_type (EServerSideSource *source, + GType auth_session_type) +{ + g_return_if_fail (E_IS_SERVER_SIDE_SOURCE (source)); + + if (!g_type_is_a (auth_session_type, E_TYPE_AUTHENTICATION_SESSION)) { + g_warning ( + "Invalid auth session type '%s' for source '%s'", + g_type_name (auth_session_type), + e_source_get_display_name (E_SOURCE (source))); + return; + } + + if (auth_session_type == source->priv->auth_session_type) + return; + + source->priv->auth_session_type = auth_session_type; + + g_object_notify (G_OBJECT (source), "auth-session-type"); +} + +/** * e_server_side_source_get_exported: * @source: an #EServerSideSource * diff --git a/libebackend/e-server-side-source.h b/libebackend/e-server-side-source.h index f25a764..bed3f61 100644 --- a/libebackend/e-server-side-source.h +++ b/libebackend/e-server-side-source.h @@ -97,6 +97,11 @@ gboolean e_server_side_source_get_allow_auth_prompt void e_server_side_source_set_allow_auth_prompt (EServerSideSource *source, gboolean allow_auth_prompt); +GType e_server_side_source_get_auth_session_type + (EServerSideSource *source); +void e_server_side_source_set_auth_session_type + (EServerSideSource *source, + GType auth_session_type); gboolean e_server_side_source_get_exported (EServerSideSource *source); const gchar * e_server_side_source_get_write_directory -- 2.7.4