[gnome-online-accounts] exchange: Don't save the AsUrl and OabUrl, use the server instead



commit bff45b269956875d25bc4c0691c9dfc393eedc25
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Apr 4 20:22:49 2012 +0200

    exchange: Don't save the AsUrl and OabUrl, use the server instead
    
    A new org.gnome.OnlineAccounts.Exchange interface was added with a
    property named Host to expose the server's domain name over DBus. It
    is upto the clients to retrieve the AsUrl and OabUrl.
    
    Fixes: https://bugzilla.gnome.org/667889

 data/dbus-interfaces.xml             |   24 ++++++++++++
 src/goabackend/goaewsclient.c        |   70 ++++++++++++----------------------
 src/goabackend/goaewsclient.h        |   14 +------
 src/goabackend/goaexchangeprovider.c |   38 ++++++++++++------
 4 files changed, 76 insertions(+), 70 deletions(-)
---
diff --git a/data/dbus-interfaces.xml b/data/dbus-interfaces.xml
index d07838a..6713076 100644
--- a/data/dbus-interfaces.xml
+++ b/data/dbus-interfaces.xml
@@ -420,4 +420,28 @@
   <interface name="org.gnome.OnlineAccounts.Documents">
   </interface>
 
+  <!--
+      org.gnome.OnlineAccounts.Exchange:
+      @since: 3.6.0
+
+      An account object implements this interface if it represents
+      a Microsoft Exchange server.
+  -->
+  <interface name="org.gnome.OnlineAccounts.Exchange">
+    <!-- Host:
+         The Exchange server to use. This is always a domain name.
+
+         Use this to determine the <ulink
+         url="http://msdn.microsoft.com/en-us/library/gg591268%28v=exchg.140%29.aspx";>
+         Autodiscover</ulink> service endpoints. eg. if
+         #org.gnome.OnlineAccounts.Exchange:Host is
+         <literal>bar.com</literal>, then the possible endpoints are
+         <literal>https://bar.com/autodiscover/autodiscover.xml
+         </literal> and <literal>
+         https://autodiscover.bar.com/autodiscover/autodiscover.xml
+         </literal>.
+      -->
+    <property name="Host" type="s" access="read"/>
+  </interface>
+
 </node>
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index 34a9944..6627514 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -143,37 +143,27 @@ ews_client_autodiscover_cancelled_cb (GCancellable *cancellable, gpointer user_d
   soup_session_abort (data->session);
 }
 
-static GoaEwsUrls *
+static gboolean
 ews_client_autodiscover_parse_protocol (xmlNode *node)
 {
-  GoaEwsUrls *urls;
-  gchar *as_url;
-  gchar *oab_url;
+  gboolean as_url;
+  gboolean oab_url;
 
-  urls = NULL;
-  as_url = NULL;
-  oab_url = NULL;
+  as_url = FALSE;
+  oab_url = FALSE;
 
   for (node = node->children; node; node = node->next)
     {
       if (ews_client_check_node (node, "ASUrl"))
-        as_url = (gchar *) xmlNodeGetContent (node);
+        as_url = TRUE;
       else if (ews_client_check_node (node, "OABUrl"))
-        oab_url = (gchar *) xmlNodeGetContent (node);
+        oab_url = TRUE;
 
-      if (as_url != NULL && oab_url !=NULL)
-        {
-          urls = g_slice_new0 (GoaEwsUrls);
-          urls->as_url = as_url;
-          urls->oab_url = oab_url;
-          goto out;
-        }
+      if (as_url && oab_url)
+        break;
     }
 
-  g_free (oab_url);
-  g_free (as_url);
- out:
-  return urls;
+  return as_url && oab_url;
 }
 
 static void
@@ -181,7 +171,7 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
 {
   GError *error;
   AutodiscoverData *data = user_data;
-  GoaEwsUrls *urls;
+  gboolean op_res;
   guint status;
   gint idx;
   gsize size;
@@ -192,8 +182,8 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
   if (status == SOUP_STATUS_CANCELLED)
     return;
 
-  urls = NULL;
   error = NULL;
+  op_res = FALSE;
   size = sizeof (data->msgs) / sizeof (data->msgs[0]);
 
   for (idx = 0; idx < size; idx++)
@@ -273,11 +263,11 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
     {
       if (ews_client_check_node (node, "Protocol"))
         {
-          urls = ews_client_autodiscover_parse_protocol (node);
+          op_res = ews_client_autodiscover_parse_protocol (node);
           break;
         }
     }
-  if (urls == NULL)
+  if (!op_res)
     {
       g_set_error (&error,
                    GOA_ERROR,
@@ -316,7 +306,7 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
       g_simple_async_result_set_from_error (data->res, error);
     }
   else
-    g_simple_async_result_set_op_res_gpointer (data->res, urls, NULL);
+    g_simple_async_result_set_op_res_gboolean (data->res, op_res);
 
   g_simple_async_result_complete_in_idle (data->res);
   ews_client_autodiscover_data_free (data);
@@ -465,20 +455,21 @@ goa_ews_client_autodiscover (GoaEwsClient        *client,
   xmlFreeDoc (doc);
 }
 
-GoaEwsUrls *
+gboolean
 goa_ews_client_autodiscover_finish (GoaEwsClient *client, GAsyncResult *res, GError **error)
 {
   GSimpleAsyncResult *simple;
 
-  g_return_val_if_fail (g_simple_async_result_is_valid (res, G_OBJECT (client), goa_ews_client_autodiscover), NULL);
-  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+  g_return_val_if_fail (g_simple_async_result_is_valid (res, G_OBJECT (client), goa_ews_client_autodiscover),
+                        FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   simple = G_SIMPLE_ASYNC_RESULT (res);
 
   if (g_simple_async_result_propagate_error (simple, error))
-    return NULL;
+    return FALSE;
 
-  return g_simple_async_result_get_op_res_gpointer (simple);
+  return g_simple_async_result_get_op_res_gboolean (simple);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -487,7 +478,7 @@ typedef struct
 {
   GError **error;
   GMainLoop *loop;
-  GoaEwsUrls *urls;
+  gboolean op_res;
 } AutodiscoverSyncData;
 
 static void
@@ -495,11 +486,11 @@ ews_client_autodiscover_sync_cb (GObject *source_object, GAsyncResult *res, gpoi
 {
   AutodiscoverSyncData *data = user_data;
 
-  data->urls = goa_ews_client_autodiscover_finish (GOA_EWS_CLIENT (source_object), res, data->error);
+  data->op_res = goa_ews_client_autodiscover_finish (GOA_EWS_CLIENT (source_object), res, data->error);
   g_main_loop_quit (data->loop);
 }
 
-GoaEwsUrls *
+gboolean
 goa_ews_client_autodiscover_sync (GoaEwsClient        *client,
                                   const gchar         *email,
                                   const gchar         *password,
@@ -512,7 +503,6 @@ goa_ews_client_autodiscover_sync (GoaEwsClient        *client,
   GMainContext *context = NULL;
 
   data.error = error;
-  data.urls = NULL;
 
   context = g_main_context_new ();
   g_main_context_push_thread_default (context);
@@ -532,15 +522,5 @@ goa_ews_client_autodiscover_sync (GoaEwsClient        *client,
   g_main_context_pop_thread_default (context);
   g_main_context_unref (context);
 
-  return data.urls;
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-void
-goa_ews_urls_free (GoaEwsUrls *urls)
-{
-  g_free (urls->as_url);
-  g_free (urls->oab_url);
-  g_slice_free (GoaEwsUrls, urls);
+  return data.op_res;
 }
diff --git a/src/goabackend/goaewsclient.h b/src/goabackend/goaewsclient.h
index 0390506..6f72c41 100644
--- a/src/goabackend/goaewsclient.h
+++ b/src/goabackend/goaewsclient.h
@@ -35,14 +35,6 @@ G_BEGIN_DECLS
 #define GOA_EWS_CLIENT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_EWS_CLIENT, GoaEwsClient))
 #define GOA_IS_EWS_CLIENT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_EWS_CLIENT))
 
-typedef struct _GoaEwsUrls GoaEwsUrls;
-
-struct _GoaEwsUrls
-{
-  gchar *as_url;
-  gchar *oab_url;
-};
-
 GType           goa_ews_client_get_type            (void) G_GNUC_CONST;
 GoaEwsClient   *goa_ews_client_new                 (void);
 void            goa_ews_client_autodiscover        (GoaEwsClient        *client,
@@ -53,10 +45,10 @@ void            goa_ews_client_autodiscover        (GoaEwsClient        *client,
                                                     GCancellable        *cancellable,
                                                     GAsyncReadyCallback  callback,
                                                     gpointer             gpointer);
-GoaEwsUrls     *goa_ews_client_autodiscover_finish (GoaEwsClient        *client,
+gboolean        goa_ews_client_autodiscover_finish (GoaEwsClient        *client,
                                                     GAsyncResult        *res,
                                                     GError             **error);
-GoaEwsUrls     *goa_ews_client_autodiscover_sync   (GoaEwsClient        *client,
+gboolean        goa_ews_client_autodiscover_sync   (GoaEwsClient        *client,
                                                     const gchar         *email,
                                                     const gchar         *password,
                                                     const gchar         *username,
@@ -64,8 +56,6 @@ GoaEwsUrls     *goa_ews_client_autodiscover_sync   (GoaEwsClient        *client,
                                                     GCancellable        *cancellable,
                                                     GError             **error);
 
-void            goa_ews_urls_free                  (GoaEwsUrls *urls);
-
 G_END_DECLS
 
 #endif /* __GOA_EWS_CLIENT_H__ */
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index b046104..d613424 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -93,6 +93,7 @@ build_object (GoaProvider         *provider,
   GoaAccount *account;
   GoaCalendar *calendar;
   GoaContacts *contacts;
+  GoaExchange *exchange;
   GoaMail *mail;
   GoaPasswordBased *password_based;
   gboolean calendar_enabled;
@@ -103,6 +104,7 @@ build_object (GoaProvider         *provider,
   account = NULL;
   calendar = NULL;
   contacts = NULL;
+  exchange = NULL;
   mail = NULL;
   password_based = NULL;
   ret = FALSE;
@@ -186,9 +188,24 @@ build_object (GoaProvider         *provider,
         goa_object_skeleton_set_contacts (object, NULL);
     }
 
+  /* Exchange */
+  exchange = goa_object_get_exchange (GOA_OBJECT (object));
+  if (exchange == NULL)
+    {
+      gchar *host;
+
+      host = g_key_file_get_string (key_file, group, "Host", NULL);
+      exchange = goa_exchange_skeleton_new ();
+      g_object_set (G_OBJECT (exchange), "host", host, NULL);
+      goa_object_skeleton_set_exchange (object, exchange);
+      g_free (host);
+    }
+
   ret = TRUE;
 
  out:
+  if (exchange != NULL)
+    g_object_unref (exchange);
   if (contacts != NULL)
     g_object_unref (contacts);
   if (calendar != NULL)
@@ -347,7 +364,6 @@ add_account (GoaProvider    *provider,
   GError *local_error;
   GVariantBuilder builder;
   GoaEwsClient *ews_client;
-  GoaEwsUrls *urls;
   GoaObject *ret;
   GtkWidget *alignment;
   GtkWidget *label;
@@ -430,14 +446,13 @@ add_account (GoaProvider    *provider,
   server = gtk_entry_get_text (GTK_ENTRY (data.server));
 
   local_error = NULL;
-  urls = goa_ews_client_autodiscover_sync (ews_client,
-                                           email_address,
-                                           password,
-                                           username,
-                                           server,
-                                           NULL,
-                                           &local_error);
-  if (urls == NULL)
+  if (!goa_ews_client_autodiscover_sync (ews_client,
+                                         email_address,
+                                         password,
+                                         username,
+                                         server,
+                                         NULL,
+                                         &local_error))
     {
       markup = g_strdup_printf ("<b>%s:</b> %s",
                                 _("Error connecting to Microsoft Exchange server"),
@@ -463,10 +478,7 @@ add_account (GoaProvider    *provider,
   g_variant_builder_add (&builder, "{ss}", "MailEnabled", "true");
   g_variant_builder_add (&builder, "{ss}", "CalendarEnabled", "true");
   g_variant_builder_add (&builder, "{ss}", "ContactsEnabled", "true");
-  g_variant_builder_add (&builder, "{ss}", "Server", server);
-  g_variant_builder_add (&builder, "{ss}", "AsUrl", urls->as_url);
-  g_variant_builder_add (&builder, "{ss}", "OabUrl", urls->oab_url);
-  goa_ews_urls_free (urls);
+  g_variant_builder_add (&builder, "{ss}", "Host", server);
 
   goa_manager_call_add_account (goa_client_get_manager (client),
                                 goa_provider_get_provider_type (provider),



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