[evolution-ews] Implementing new EWS operation API for transportation layer (e-ews-connection)



commit 82a5557561f6c066fc53722c2c1ae9b452dde31b
Author: Pavel Ocheretny <potzarti infradead org>
Date:   Mon May 2 23:15:26 2011 +0300

    Implementing new EWS operation API for transportation layer (e-ews-connection)

 src/server/e-ews-connection.c |  105 +++++++++++++++++++++++++++++++++++++++++
 src/server/e-ews-connection.h |    9 ++++
 2 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 3438a5c..9147bb0 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -50,6 +50,7 @@ static gint comp_func (gconstpointer a, gconstpointer b);
 
 typedef void (*response_cb) (ESoapParameter *param, struct _EwsNode *enode);
 static void ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data);
+static void ews_operation_response_cb (SoupSession *session, SoupMessage *msg, gpointer data);
 
 static void
 ews_connection_authenticate	(SoupSession *sess, SoupMessage *msg,
@@ -106,6 +107,8 @@ struct _EwsNode {
 
 	GCancellable *cancellable;
 	gulong cancel_handler_id;
+
+	SoupSessionCallback callback;
 };
 
 typedef struct {
@@ -378,7 +381,90 @@ ews_connection_queue_request (EEwsConnection *cnc, ESoapMessage *msg, response_c
 	ews_trigger_next_request(cnc);
 }
 
+static void
+ews_connection_queue_operation_request (EEwsConnection *cnc, ESoapMessage *msg, EwsOperationPriority priority, GCancellable *cancellable, GSimpleAsyncResult *simple)
+{
+	EwsNode *node;
+
+	node = ews_node_new ();
+	node->msg = msg;
+	node->pri = priority;
+	node->cnc = cnc;
+	node->simple = simple;
+	node->callback = ews_operation_response_cb;
+
+	QUEUE_LOCK (cnc);
+	cnc->priv->jobs = g_slist_insert_sorted (cnc->priv->jobs, (gpointer *) node, (GCompareFunc) comp_func);
+	QUEUE_UNLOCK (cnc);
+
+	if (cancellable) {
+		node->cancellable = cancellable;
+		node->cancel_handler_id = g_cancellable_connect	(cancellable,
+								 G_CALLBACK (ews_cancel_request),
+								 (gpointer) node, NULL);
+	}
+
+	ews_trigger_next_request(cnc);
+}
+
 /* Response callbacks */
+static void
+ews_operation_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
+{
+	EwsNode *enode = (EwsNode *) data;
+	ESoapResponse *response;
+	ESoapParameter *param;
+	GError *error = NULL;
+
+	// check for cancelled state
+	if (enode->cancellable && g_cancellable_is_cancelled (enode->cancellable))
+		goto exit;
+
+	// no "401 Unauthorized"
+	if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
+		g_simple_async_result_set_error (enode->simple,
+						 EWS_CONNECTION_ERROR,
+						 EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED,
+						 _("Authentication failed"));
+		goto exit;
+	}
+
+	// got a response
+	response = e_soap_message_parse_response ((ESoapMessage *) msg);
+	if (!response) {
+		g_simple_async_result_set_error	(enode->simple,
+						 EWS_CONNECTION_ERROR,
+						 EWS_CONNECTION_ERROR_NORESPONSE,
+						 _("No response"));
+
+		goto exit;
+	}
+
+	// dump response if expected to
+	if (g_getenv ("EWS_DEBUG") && (atoi (g_getenv ("EWS_DEBUG")) >= 1))
+		e_soap_response_dump_response (response, stdout);
+
+	// TODO: validate response using xml schema
+
+	// prepare value returned to callback
+	param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages");
+	if (param)
+		g_simple_async_result_set_op_res_gpointer (enode->simple, g_object_ref (response), g_object_unref);
+	else
+		ews_parse_soap_fault (response, &error);
+
+	if (error) {
+		g_simple_async_result_set_from_error (enode->simple, error);
+		g_clear_error (&error);
+	}
+
+exit:
+	g_simple_async_result_complete_in_idle (enode->simple);
+
+	ews_active_job_done (enode->cnc, enode);
+
+	g_object_unref (response);
+}
 
 static void
 ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
@@ -608,6 +694,25 @@ ews_create_folder_cb (ESoapParameter *soapparam, EwsNode *enode)
 	async_data->items_created = fids;
 }
 
+void
+e_ews_connection_queue_operation (EEwsConnection *cnc,
+						ESoapMessage *msg,
+						GCancellable *cancellable,
+						EwsOperationPriority priority,
+						GAsyncReadyCallback cb,
+						GObject *source,
+						gpointer user_data)
+{
+	GSimpleAsyncResult *simple;
+
+	simple = g_simple_async_result_new (source,
+					    cb,
+					    user_data,
+					    e_ews_connection_queue_operation);
+
+	ews_connection_queue_operation_request (cnc, msg, priority, cancellable, simple);
+}
+
 static void
 e_ews_connection_dispose (GObject *object)
 {
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 2c4835b..6690d83 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -94,6 +94,15 @@ void		e_ews_autodiscover_ws_url	(EEwsAutoDiscoverCallback cb,
 void		e_ews_connection_set_mailbox	(EEwsConnection *cnc,
 						 const gchar *email);
 
+/* API for queuing messages */
+void		e_ews_connection_queue_operation (EEwsConnection *cnc,
+						ESoapMessage *msg,
+						GCancellable *cancellable,
+						EwsOperationPriority priority,
+						GAsyncReadyCallback cb,
+						GObject *source,
+						gpointer user_data);
+
 /* Expose uri and mail for a new API */
 const gchar * e_ews_connection_get_uri (EEwsConnection *cnc);
 



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