[evolution-ews] Parse OAB url in autodiscover.



commit cbc674cb2cd58aa6a4860b21bab98ebf3821650a
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Mon Jun 20 12:53:18 2011 +0530

    Parse OAB url in autodiscover.

 .../exchange-ews-account-setup.c                   |   23 +++++---
 src/server/e-ews-connection.c                      |   56 ++++++++++++--------
 src/server/e-ews-connection.h                      |   12 ++++-
 src/server/tests/test-connection.c                 |   38 ++++++++++----
 4 files changed, 86 insertions(+), 43 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-ews-account-setup.c b/src/account-setup-eplugin/exchange-ews-account-setup.c
index 6930e63..c6303e0 100644
--- a/src/account-setup-eplugin/exchange-ews-account-setup.c
+++ b/src/account-setup-eplugin/exchange-ews-account-setup.c
@@ -92,16 +92,22 @@ struct _AutoDiscCallBackData {
 	GtkWidget *entry;
 };
 
-static void autodiscover_callback (char *url, gpointer user_data, GError *error)
+static void autodiscover_callback (EwsUrls *urls, gpointer user_data, GError *error)
 {
+	struct _AutoDiscCallBackData *cbdata = (struct _AutoDiscCallBackData *) user_data;
+	
 	if (error) {
 		g_warning ("Autodiscover failed: %s", error->message);
 		g_clear_error (&error);
 	}
-	if (url) {
-		g_message("Got ASURL %s", url);
-		gtk_entry_set_text (GTK_ENTRY (user_data), url);
-		g_free (url);
+	if (urls) {
+		g_message("Got ASURL %s", urls->as_url);
+
+		gtk_entry_set_text (GTK_ENTRY (cbdata->entry), urls->as_url);
+		
+		g_free (urls->as_url);
+		g_free (urls->oab_url);
+		g_free (urls);
 	}
 }
 
@@ -125,14 +131,14 @@ validate_credentials (GtkWidget *widget, struct _AutoDiscCallBackData *cbdata)
 		g_free (password);
 		title = g_strdup_printf (_("Enter Password for %s"), target_account->account->id->address);
 		password = e_passwords_ask_password (title, EXCHANGE_EWS_PASSWORD_COMPONENT, key, title,
-						     E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET,
+                                                    E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET,
 						     &remember, NULL);
 		g_free (title);
 	}
 
 	/*Can there be a account without password ?*/
 	if (password && *password) {
-		e_ews_autodiscover_ws_url (autodiscover_callback, cbdata->entry,
+		e_ews_autodiscover_ws_url (autodiscover_callback, cbdata,
 					   target_account->account->id->address,
 					   password);
 	} else {
@@ -198,6 +204,7 @@ org_gnome_exchange_ews_account_setup (EPlugin *epl, EConfigHookItemFactoryData *
 		const gchar *temp, *email_id;
 		gchar *url_string;
 		struct _AutoDiscCallBackData *cbdata = g_new0 (struct _AutoDiscCallBackData, 1);
+		/* FIXME free cbdata */
 
 		g_object_get (data->parent, "n-rows", &row, NULL);
 
@@ -267,8 +274,6 @@ org_gnome_exchange_ews_check_options(EPlugin *epl, EConfigHookPageCheckData *dat
 				camel_url_free (hurl);
 		}
 
-
-
 		if (url)
 			camel_url_free(url);
 	}
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 990b20e..750574c 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -158,18 +158,22 @@ ews_node_new ()
 	return node;
 }
 
-static gchar*
-autodiscover_parse_protocol(xmlNode *node)
+static gboolean
+autodiscover_parse_protocol (xmlNode *node, EwsUrls *urls)
 {
 	for (node = node->children; node; node = node->next) {
 		if (node->type == XML_ELEMENT_NODE &&
 		    !strcmp((char *)node->name, "ASUrl")) {
-			char *asurl = (char *)xmlNodeGetContent(node);
-			if (asurl)
-				return asurl;
-		}
+			urls->as_url = (gchar *) xmlNodeGetContent(node);
+		} else if (node->type == XML_ELEMENT_NODE &&
+		    !strcmp((char *)node->name, "OABUrl"))
+			urls->oab_url = (gchar *) xmlNodeGetContent(node);
+			
+		if (urls->as_url && urls->oab_url)
+			return TRUE;
 	}
-	return NULL;
+
+	return FALSE;
 }
 
 static gint
@@ -948,21 +952,20 @@ struct _autodiscover_data {
 	gpointer cbdata;
 };
 
-
 /* Called in the context e_ews_autodiscover_ws_url() was called from,
    with the final result. */
 static void autodiscover_done_cb (GObject *cnc, GAsyncResult *res,
 				  gpointer user_data)
 {
 	struct _autodiscover_data *ad = user_data;
+	EwsUrls *urls = NULL;
 	GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
 	GError *error = NULL;
-	gchar *url = NULL;
 
 	if (!g_simple_async_result_propagate_error (simple, &error))
-		url = g_simple_async_result_get_op_res_gpointer (simple);
+		urls = g_simple_async_result_get_op_res_gpointer (simple);
 
-	ad->cb (url, ad->cbdata, error);
+	ad->cb (urls, ad->cbdata, error);
 	g_object_unref (G_OBJECT (ad->cnc));
 	g_free (ad);
 }
@@ -974,10 +977,10 @@ autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
 {
 	GError *error = NULL;
 	struct _autodiscover_data *ad = data;
+	EwsUrls *urls = NULL;
 	guint status = msg->status_code;
 	xmlDoc *doc;
 	xmlNode *node;
-	char *asurl = NULL;
 	int idx;
 
 	for (idx = 0; idx < 2; idx++) {
@@ -1051,20 +1054,25 @@ autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
 			     _("Failed to find <Account> element\n"));
 		goto failed;
 	}
+
+	urls = g_new0 (EwsUrls, 1);
 	for (node = node->children; node; node = node->next) {
 		if (node->type == XML_ELEMENT_NODE &&
-		    !strcmp((char *)node->name, "Protocol") &&
-		    (asurl = autodiscover_parse_protocol(node)))
-			break;
+		    !strcmp((char *)node->name, "Protocol")) {
+		    	if (autodiscover_parse_protocol(node, urls))
+				break;
+			else {
+				g_free (urls->as_url);
+				g_free (urls->oab_url);
+				g_free (urls);
+				g_set_error	(&error, EWS_CONNECTION_ERROR,
+						 -1,
+						 _("Failed to find <ASUrl> and <OABUrl> in autodiscover response"));
+				goto failed;
+			}
+		}
 	}
 
-	if (!asurl) {
-		g_set_error (
-			     &error, EWS_CONNECTION_ERROR,
-			     -1,
-			     _("Failed to find <ASUrl> in autodiscover response"));
-		goto failed;
-	}
 	/* We have a good response; cancel all the others */
 	for (idx = 0; idx < 2; idx++) {
 		if (ad->msgs[idx]) {
@@ -1074,7 +1082,9 @@ autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
 						     m, SOUP_STATUS_CANCELLED);
 		}
 	}
-	g_simple_async_result_set_op_res_gpointer (ad->simple, asurl, NULL);
+	
+	
+	g_simple_async_result_set_op_res_gpointer (ad->simple, urls, NULL);
 	g_simple_async_result_complete_in_idle (ad->simple);
 	return;
 
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 0655829..b901e60 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -88,6 +88,16 @@ typedef enum {
 	EWS_SPECIFIED_OCCURRENCE_ONLY
 } EwsAffectedTaskOccurrencesType;
 
+typedef struct {
+	gchar *as_url;
+	gchar *oab_url;
+
+	/* all the below variables are for future use */
+	gchar *oof_url;
+	gpointer future1;
+	gpointer future2;
+} EwsUrls;
+
 GType		e_ews_connection_get_type	(void);
 EEwsConnection *e_ews_connection_new		(const gchar *uri,
 						 const gchar *username,
@@ -103,7 +113,7 @@ void		e_ews_connection_authenticate	(EEwsConnection *cnc,
 						 const gchar *passwd,
 						 GError *error);
 
-typedef void (*EEwsAutoDiscoverCallback) (char *url, gpointer user_data, GError *error);
+typedef void (*EEwsAutoDiscoverCallback) (EwsUrls *urls, gpointer user_data, GError *error);
 void		e_ews_autodiscover_ws_url	(EEwsAutoDiscoverCallback cb,
 						 gpointer cbdata,
 						 const gchar *email,
diff --git a/src/server/tests/test-connection.c b/src/server/tests/test-connection.c
index 91de48f..db543fa 100644
--- a/src/server/tests/test-connection.c
+++ b/src/server/tests/test-connection.c
@@ -62,26 +62,36 @@ con_test_create_new_connection ()
 
 struct _cb_data {
 	gboolean positive_case;
+	gchar *test_case;
 	gboolean quit;
 };
 
 static void
-autodiscover_cb (gchar *uri, gpointer user_data, GError *error)
+autodiscover_cb (EwsUrls *urls, gpointer user_data, GError *error)
 {
 	struct _cb_data *data = (struct _cb_data *) user_data;
 	gboolean quit = data->quit;
 
+	g_print ("Response for test case : %s \n", data->test_case);
+
 	if (data->positive_case) {
-		g_assert_cmpstr (uri, !=, NULL);
+		g_assert (urls != NULL);
 	} else
-		g_assert_cmpstr (uri, ==, NULL);
+		g_assert (urls == NULL);
 	
 	if (error)
 		g_print ("Error code:%d desc: %s \n", error->code, error->message);
 	
 	g_clear_error (&error);
+	g_free (data->test_case);
 	g_free (data);
-	
+
+	if (urls) {
+		g_print ("ASUrl - %s \nOABUrl - %s \n", urls->as_url, urls->oab_url);
+		g_free (urls->as_url);
+		g_free (urls->oab_url);
+	}
+
 	if (quit)
 		g_main_loop_quit (main_loop);
 }
@@ -106,28 +116,36 @@ con_test_autodiscover()
 	g_print("%s %s : password : %s \n", G_STRLOC, G_STRFUNC, password);
 	g_print("%s %s : email : %s \n", G_STRLOC, G_STRFUNC, email);
 
-	g_print ("Testing postive case... \n");
 	user_data = g_new0 (struct _cb_data, 1);
+	user_data->test_case = g_strdup ("postive case... \n");
+	g_print ("Testing %s \n", user_data->test_case);
 	user_data->positive_case = TRUE;
-	user_data->quit = TRUE;
 	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, email, password);
 
-	g_print ("Testing wrong password... \n");
 	user_data = g_new0 (struct _cb_data, 1);
+	user_data->test_case =	g_strdup ("wrong password... \n");
+	/* It does respond properly with the url, Check it out */
+	user_data->positive_case = TRUE;
+	g_print ("Testing %s \n", user_data->test_case);
 	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, email, "wrongpassword");
 
-	g_print ("Testing email without domain ... \n");
 	user_data = g_new0 (struct _cb_data, 1);
+	user_data->test_case = g_strdup ("email without domain ... \n");
+	g_print ("Testing %s \n", user_data->test_case);
 	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, "wronguseremail", password);
 
-	g_print ("Testing wrong email address and password... \n");
 	user_data = g_new0 (struct _cb_data, 1);
+	user_data->test_case = g_strdup ("wrong email address and password... \n");
+	g_print ("Testing %s \n", user_data->test_case);
 	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, "godknows donknow com", "wrongpassword");
 
-	g_print ("Testing wrong user name ... \n");
+	user_data->test_case = g_strdup ("wrong user name ... \n");
+	g_print ("Testing %s \n", user_data->test_case);
 	domain = g_strstr_len (email, -1, "@");
 	wrong_username = g_strconcat ("godknows", domain, NULL);
 	user_data = g_new0 (struct _cb_data, 1);
+	user_data->test_case = g_strdup ("wrong user name ... \n");
+	g_print ("Testing %s \n", user_data->test_case);
 	user_data->quit = TRUE;
 	e_ews_autodiscover_ws_url (autodiscover_cb, user_data, wrong_username, password);
 	g_free (wrong_username);



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