From 15c1cac37016b738219b9e2b18093559604888ee Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Mon, 11 Mar 2013 15:30:19 +0200 Subject: [PATCH 2/4] Allow example provider discovery to be configured. * Default domain, discovery delay, and delay when discovery fails can be configured. --- doc/internals/realmd-internals.xml | 10 +++++++++- service/realm-example-provider.c | 30 ++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/doc/internals/realmd-internals.xml b/doc/internals/realmd-internals.xml index f4b99dd..28f8ea4 100644 --- a/doc/internals/realmd-internals.xml +++ b/doc/internals/realmd-internals.xml @@ -351,6 +351,14 @@ [providers] example = yes + +[example] +# What domain to return for a default discovery +default = default.example.com +# How long to delay a successful discovery, in seconds +example-discovery-delay = 1.3 +# How long to delay a unsuccessful disocvery +example-non-discovery-delay = 0.9 @@ -358,7 +366,7 @@ example = yes -[example.com] +[default.example.com] # Mock administrator account required to join example-administrator = Administrator # Password for above mock admin account diff --git a/service/realm-example-provider.c b/service/realm-example-provider.c index 6cf84f2..82df58c 100644 --- a/service/realm-example-provider.c +++ b/service/realm-example-provider.c @@ -27,8 +27,6 @@ #include -#define EXAMPLE_DOMAIN "EXAMPLE.COM" - struct _RealmExampleProvider { RealmProvider parent; RealmIniConfig *config; @@ -160,15 +158,31 @@ realm_example_provider_discover_async (RealmProvider *provider, /* A valid example domain name */ } else { + gchar *domain; + gdouble delay; + + if (string == NULL || strlen (string) == 0) + domain = g_strdup (realm_settings_value ("example", "default")); + else + domain = parse_example_name (string); + + if (domain && realm_settings_section(domain)) + delay = realm_settings_double (domain, "example-discovery-delay", 0.0); + else { + delay = realm_settings_double ("example", "non-discovery-delay", 0.0); + g_free (domain); + domain = NULL; + } + g_simple_async_result_set_op_res_gpointer (async, - parse_example_name (string), + domain, g_free); - g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, - g_random_int_range (2, 5), - on_discover_timeout, - g_object_ref (async), - g_object_unref); + g_timeout_add_full (G_PRIORITY_DEFAULT, + delay * 1000, + on_discover_timeout, + g_object_ref (async), + g_object_unref); } g_object_unref (async); -- 1.8.1.4