[evolution-ews] Bug 656376 - Support for delegation
- From: Vibha Yadav <yvibha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Bug 656376 - Support for delegation
- Date: Fri, 2 Dec 2011 10:20:58 +0000 (UTC)
commit c9501f7515737e9fa19ef6ec3bc962aea1f9f844
Author: Vibha Yadav <yvibha suse com>
Date: Fri Dec 2 15:48:51 2011 +0530
Bug 656376 - Support for delegation
Adding up get_delegate api along with its test case.
src/server/e-ews-connection.c | 222 ++++++++++++++++++++++++++++++++++-
src/server/e-ews-connection.h | 50 ++++++++
src/server/tests/Makefile.am | 3 +-
src/server/tests/test-getdelegate.c | 113 ++++++++++++++++++
src/server/tests/test-libews.c | 2 +
5 files changed, 387 insertions(+), 3 deletions(-)
---
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index f501834..0d7ba59 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -432,8 +432,9 @@ ews_response_cb (SoupSession *session, SoupMessage *msg, gpointer data)
subparam = e_soap_parameter_get_next_child (subparam)) {
int l = strlen ((char *)subparam->name);
if (l < 15 || (strcmp((char *)subparam->name + l - 15, "ResponseMessage") &&
- strcmp((char *)subparam->name, "FreeBusyResponse"))) {
- g_warning ("Unexpected element '%s' in place of ResponseMessage or FreeBusyResponse",
+ strcmp((char *)subparam->name, "FreeBusyResponse")&&
+ strcmp((char *)subparam->name, "DelegateUserResponseMessageType"))) {
+ g_warning ("Unexpected element '%s' in place of ResponseMessage or FreeBusyResponse or DelegateUserResponseMessageType",
subparam->name);
continue;
}
@@ -857,6 +858,20 @@ ews_connection_authenticate (SoupSession *sess, SoupMessage *msg,
}
void
+ews_user_id_free (EwsUserId *id)
+{
+ if (id)
+ {
+ g_free(id->sid);
+ g_free(id->primary_smtp_add);
+ g_free(id->display_name);
+ g_free(id->distinguished_user);
+ g_free(id->external_user);
+ g_free(id);
+ }
+}
+
+void
e_ews_connection_authenticate (EEwsConnection *cnc,
SoupAuth *auth, const gchar *user,
const gchar *passwd, GError *error)
@@ -4105,3 +4120,206 @@ e_ews_connection_get_free_busy (EEwsConnection *cnc,
return result;
}
+
+static EwsPermissionLevel get_permission_from_string(gchar *permission)
+{
+ g_return_val_if_fail(permission != NULL, NONE);
+
+ if (!g_ascii_strcasecmp (permission, "Editor"))
+ return EWS_PERM_EDITOR;
+ else if (!g_ascii_strcasecmp (permission, "Author"))
+ return EWS_PERM_AUTHOR;
+ else if (!g_ascii_strcasecmp (permission, "Reviewer"))
+ return EWS_PERM_REVIEWER;
+ else if (!g_ascii_strcasecmp (permission, "Custom"))
+ return CUSTOM;
+ else
+ return NONE;
+
+}
+
+static void
+get_delegate_response_cb (ESoapParameter *param, EwsNode *enode)
+{
+ ESoapParameter *subparam, *node, *child;
+ EwsAsyncData *async_data;
+ EwsDelegateInfo *data;
+ gchar *value;
+
+ async_data = g_simple_async_result_get_op_res_gpointer (enode->simple);
+
+ node = e_soap_parameter_get_first_child_by_name (param, "DelegateUser");
+
+ data = g_new(EwsDelegateInfo, 1);
+ data->user_id = g_new0(EwsUserId, 1);
+
+ subparam = e_soap_parameter_get_first_child_by_name(node, "UserId");
+
+ /*Parse User Id*/
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "SID");
+ data->user_id->sid = e_soap_parameter_get_string_value(child);
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "PrimarySmtpAddress");
+ data->user_id->primary_smtp_add = e_soap_parameter_get_string_value(child);
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "DisplayName");
+ data->user_id->display_name = e_soap_parameter_get_string_value(child);
+
+ subparam = e_soap_parameter_get_first_child_by_name(node, "DelegatePermissions");
+ /*Parse Delegate Permissions*/
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "CalendarFolderPermissionLevel");
+ data->calendar = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "ContactsFolderPermissionLevel");
+ data->contact = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "InboxFolderPermissionLevel");
+ data->inbox = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "TasksFolderPermissionLevel");
+ data->tasks = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "NotesFolderPermissionLevel");
+ data->notes = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ child = e_soap_parameter_get_first_child_by_name(subparam, "JournalFolderPermissionLevel");
+ data->journal = get_permission_from_string(e_soap_parameter_get_string_value(child));
+
+ subparam = e_soap_parameter_get_first_child_by_name(node, "ReceiveCopiesOfMeetingMessages");
+
+ value = e_soap_parameter_get_string_value(subparam);
+ if(!g_ascii_strcasecmp(value, "true"))
+ data->meetingcopies = TRUE;
+
+ subparam = e_soap_parameter_get_first_child_by_name(node, "ViewPrivateItems");
+
+ value = e_soap_parameter_get_string_value(subparam);
+ if(!g_ascii_strcasecmp(value, "true"))
+ data->view_priv_items = TRUE;
+ else
+ data->view_priv_items = FALSE;
+
+ async_data->items = g_slist_append (async_data->items, data);
+ async_data->items_created = g_slist_append (async_data->items_created, data);
+
+ return;
+}
+
+
+/**
+ * e_ews_connection_get_delegate_start
+ * @cnc:
+ * @pri:
+ * @mail_id: mail is for which delegate is requested
+ * @include permission: "true", "false"
+ * @delete_type: "HardDelete", "SoftDelete", "MoveToDeletedItems"
+ * @cb:
+ * @cancellable:
+ * @user_data:
+ **/
+void
+e_ews_connection_get_delegate_start (EEwsConnection *cnc,
+ gint pri,
+ const gchar *mail_id,
+ const gchar *include_permissions,
+ GAsyncReadyCallback cb,
+ GCancellable *cancellable,
+ gpointer user_data)
+{
+ ESoapMessage *msg;
+ GSimpleAsyncResult *simple;
+ EwsAsyncData *async_data;
+
+ msg = e_ews_message_new_with_header (cnc->priv->uri, "GetDelegate", "IncludePermissions", include_permissions, EWS_EXCHANGE_2007_SP1);
+
+ e_soap_message_start_element (msg, "Mailbox", "messages", NULL);
+
+ e_ews_message_write_string_parameter (msg, "EmailAddress", NULL, mail_id);
+
+ e_soap_message_end_element (msg);
+
+ e_ews_message_write_footer (msg);
+
+ simple = g_simple_async_result_new (G_OBJECT (cnc),
+ cb,
+ user_data,
+ e_ews_connection_get_delegate_start);
+
+ async_data = g_new0 (EwsAsyncData, 1);
+ g_simple_async_result_set_op_res_gpointer (
+ simple, async_data, (GDestroyNotify) async_data_free);
+
+ ews_connection_queue_request (cnc, msg, get_delegate_response_cb, pri, cancellable, simple, cb == ews_sync_reply_cb);
+}
+
+
+gboolean
+e_ews_connection_get_delegate_finish (EEwsConnection *cnc,
+ GAsyncResult *result,
+ EwsDelegateInfo **get_delegate,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+ EwsAsyncData *async_data;
+
+ g_return_val_if_fail (
+ g_simple_async_result_is_valid (
+ result, G_OBJECT (cnc), e_ews_connection_get_delegate_start),
+ FALSE);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ async_data = g_simple_async_result_get_op_res_gpointer (simple);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+ *get_delegate = (EwsDelegateInfo *) async_data->items_created->data;
+ g_slist_free (async_data->items_created);
+
+ return TRUE;
+}
+
+gboolean
+/**
+ * e_ews_connection_get_delegate
+ * @cnc:
+ * @pri:
+ * @mail_id: mail id for which delegate requested
+ * @include_permissions: "true", "false"
+ * @cancellable:
+ * @error:
+ **/
+e_ews_connection_get_delegate (EEwsConnection *cnc,
+ gint pri,
+ const gchar *mail_id,
+ const gchar *include_permissions,
+ EwsDelegateInfo **get_delegate,
+ GCancellable *cancellable,
+ GError **error)
+{
+ EwsSyncData *sync_data;
+ gboolean result;
+
+ sync_data = g_new0 (EwsSyncData, 1);
+ sync_data->eflag = e_flag_new ();
+
+ e_ews_connection_get_delegate_start (cnc, pri, mail_id,
+ include_permissions,
+ ews_sync_reply_cb,
+ cancellable,
+ (gpointer) sync_data);
+
+ e_flag_wait (sync_data->eflag);
+
+ result = e_ews_connection_get_delegate_finish (cnc, sync_data->res,
+ get_delegate, error);
+
+ e_flag_free (sync_data->eflag);
+ g_object_unref (sync_data->res);
+ g_free (sync_data);
+
+ return result;
+
+}
+
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 3c2a26f..4616890 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -115,6 +115,30 @@ typedef struct {
gchar *filename;
} EwsOALDetails;
+typedef struct{
+ gchar *sid;
+ gchar *primary_smtp_add;
+ gchar *display_name;
+ gchar *distinguished_user;
+ gchar *external_user;
+}EwsUserId;
+
+typedef enum{
+ NONE,
+ EWS_PERM_EDITOR,
+ EWS_PERM_REVIEWER,
+ EWS_PERM_AUTHOR,
+ CUSTOM
+}EwsPermissionLevel;
+
+typedef struct{
+ EwsUserId *user_id;
+ EwsPermissionLevel calendar, contact, inbox, tasks, notes, journal;
+ gboolean meetingcopies;
+ gboolean view_priv_items;
+}EwsDelegateInfo;
+
+
GType e_ews_connection_get_type (void);
EEwsConnection *e_ews_connection_new (const gchar *uri,
const gchar *username,
@@ -139,6 +163,9 @@ void e_ews_autodiscover_ws_url (EEwsAutoDiscoverCallback cb,
const gchar *username);
void e_ews_connection_set_mailbox (EEwsConnection *cnc,
const gchar *email);
+
+void ews_user_id_free (EwsUsedId);
+
/* Sync folder items */
void e_ews_connection_sync_folder_items_start
(EEwsConnection *cnc,
@@ -666,6 +693,29 @@ gboolean e_ews_connection_download_oal_file
gpointer progress_data,
GCancellable *cancellable,
GError **error);
+/*Get Delegation*/
+void e_ews_connection_get_delegate_start (EEwsConnection *cnc,
+ gint pri,
+ const gchar *mail_id,
+ const gchar *include_permissions,
+ GAsyncReadyCallback cb,
+ GCancellable *cancellable,
+ gpointer user_data);
+gboolean e_ews_connection_get_delegate_finish (EEwsConnection *cnc,
+ GAsyncResult *result,
+ EwsDelegateInfo **get_delegate,
+ GError **error);
+gboolean e_ews_connection_get_delegate
+ (EEwsConnection *cnc,
+ gint pri,
+ const gchar *mail_id,
+ const gchar *include_permissions,
+ EwsDelegateInfo **get_delegate,
+ GCancellable *cancellable,
+ GError **error);
+
+
+
G_END_DECLS
diff --git a/src/server/tests/Makefile.am b/src/server/tests/Makefile.am
index d5043b8..2df723c 100644
--- a/src/server/tests/Makefile.am
+++ b/src/server/tests/Makefile.am
@@ -20,10 +20,11 @@ testews_SOURCES = \
test-connection.c \
test-syncfolder.c \
test-cuditem.c \
- test-getattachment.c \
+ test-getattachment.c \
test-autocompletion.c \
test-createfolder.c \
test-deletefolder.c \
+ test-getdelegate.c \
test-libews.c \
utils.h
diff --git a/src/server/tests/test-getdelegate.c b/src/server/tests/test-getdelegate.c
new file mode 100644
index 0000000..b7d5419
--- /dev/null
+++ b/src/server/tests/test-getdelegate.c
@@ -0,0 +1,113 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors : Vibha Yadav <yvibha suse com>
+ *
+ * Copyright (C) 1999-2011 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/* API : e_ews_connection_create_folders */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "utils.h"
+#include <e-ews-connection.h>
+#include <e-ews-folder.h>
+#include <e-ews-message.h>
+
+void get_delegate_tests_run ();
+
+static GMainLoop *main_loop;
+
+EwsFolderId *folder_id;
+
+static void
+get_delegate_cb (GObject *object, GAsyncResult *res, gpointer data)
+{
+ EEwsConnection *cnc = E_EWS_CONNECTION (object);
+ GError *error = NULL;
+ EwsDelegateInfo *get_delegate;
+
+ e_ews_connection_get_delegate_finish (cnc, res, &get_delegate,
+ &error);
+
+ if (error != NULL) {
+ g_warning ("Unable to get delegate: %s \n", error->message);
+ g_clear_error (&error);
+ goto quit;
+ }
+ if(get_delegate !=NULL && get_delegate->user_id != NULL)
+ g_print ("Delegate is %s", get_delegate->user_id->display_name);
+
+
+quit:
+ if(get_delegate)
+ {
+ ews_user_id_free(get_delegate->user_id);
+ g_free(get_delegate);
+ }
+ g_main_loop_quit(main_loop);
+}
+
+static void
+op_test_get_delegate ()
+{
+ const gchar *username;
+ const gchar *password;
+ const gchar *uri;
+ EEwsConnection *cnc;
+ GCancellable *cancellable;
+
+ cancellable = g_cancellable_new ();
+
+ util_get_login_info_from_env (&username, &password, &uri);
+ g_assert_cmpstr (username, !=, NULL);
+ g_assert_cmpstr (password, !=, NULL);
+ g_assert_cmpstr (uri, !=, NULL);
+
+ cnc = e_ews_connection_new (uri, username, password, NULL, NULL, NULL);
+ g_assert (cnc != NULL);
+ e_ews_connection_get_delegate_start (cnc, EWS_PRIORITY_MEDIUM, "abc xyz com",
+ "true" ,
+ get_delegate_cb,
+ cancellable, NULL);
+
+}
+
+static gboolean
+idle_cb (gpointer data)
+{
+ op_test_get_delegate();
+ return FALSE;
+}
+
+void
+get_delegate_tests_run ()
+{
+ g_type_init ();
+ g_thread_init (NULL);
+
+ main_loop = g_main_loop_new (NULL, TRUE);
+ g_idle_add ((GSourceFunc) idle_cb, NULL);
+ g_main_loop_run (main_loop);
+
+ /* terminate */
+ g_main_loop_unref (main_loop);
+}
+
diff --git a/src/server/tests/test-libews.c b/src/server/tests/test-libews.c
index bbcd26a..0f33032 100644
--- a/src/server/tests/test-libews.c
+++ b/src/server/tests/test-libews.c
@@ -14,6 +14,7 @@ void autocompletion_tests_run ();
void createfolder_tests_run ();
void deletefolder_tests_run (gconstpointer data);
void get_attachments_tests_run ();
+void get_delegate_tests_run ();
static void
finalize_test_data ()
@@ -43,6 +44,7 @@ int main (int argc, char *argv[])
g_test_add_data_func ("/libews/deletefolder", &folder_id, deletefolder_tests_run);
g_test_add_func ("/libews/cuditem", cuditem_tests_run);
+ g_test_add_func ("/libews/getdelegate", get_delegate_tests_run);
g_test_add_func ("/libews/getattachment", get_attachments_tests_run);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]