[evolution-ews] Create Attachment operation is set to return the new change key, it will be stored after the operati
- From: Or Goshen <ogosh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Create Attachment operation is set to return the new change key, it will be stored after the operati
- Date: Mon, 20 Jun 2011 15:05:04 +0000 (UTC)
commit 60699b1b986fd57f3bf84bbb62541439d0a45d91
Author: Or Goshen <orx goshen intel com>
Date: Mon Jun 20 18:15:58 2011 +0300
Create Attachment operation is set to return the new change key, it will be stored after the operation is called in the calendar backend
src/calendar/e-cal-backend-ews.c | 103 ++++++++++++++++++++++++++++----------
src/server/e-ews-connection.c | 20 ++++---
src/server/e-ews-connection.h | 2 +
src/server/e-ews-item.h | 6 --
4 files changed, 91 insertions(+), 40 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index a4a7461..b862fe7 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -1064,33 +1064,74 @@ convert_calcomp_to_xml(ESoapMessage *msg, gpointer user_data)
}
static void
+e_cal_backend_ews_remove_object (ECalBackend *backend, EDataCal *cal, EServerMethodContext context,
+ const gchar *uid, const gchar *rid, CalObjModType mod);
+
+typedef struct {
+ ECalBackendEws *cbews;
+ ECalComponent *comp;
+} EwsCreateAttachmentsData;
+
+static void
ews_create_attachments_cb(GObject *object, GAsyncResult *res, gpointer user_data)
{
EEwsConnection *cnc = E_EWS_CONNECTION (object);
- /*ECalComponent *comp = user_data;*/
- GSList *ids = NULL, *next;
- EwsAttachmentId *attach_id;
+ EwsCreateAttachmentsData *create_data = user_data;
+ ECalBackendEwsPrivate *priv = create_data->cbews->priv;
+ gchar *change_key;
+ GSList *ids, *i;
GError *error = NULL;
+ icalproperty *icalprop;
+ icalcomponent *icalcomp;
+ icalparameter *icalparam;
+
+ ids = e_ews_connection_create_attachments_finish (cnc, &change_key, res, &error);
+
+ /* make sure there was no error */
+ if (error != NULL) {
+ g_warning ("Error while creating attachments: %s\n", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ /* get exclusive access to the store */
+ e_cal_backend_store_freeze_changes(priv->store);
- /* TODO - am I suppose to do anything with the ids I get back ? */
- /* right now just free them */
- ids = e_ews_connection_create_attachments_finish (cnc, res, &error);
- for (next = ids; next; next = next->next) {
- attach_id = next->data;
+ /* Update change key. id remains the same, but change key changed.*/
+ icalcomp = e_cal_component_get_icalcomponent (create_data->comp);
+ icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
+ while (icalprop) {
+ const gchar *x_name;
+ x_name = icalproperty_get_x_name (icalprop);
+ if (!g_ascii_strcasecmp (x_name, "X-EVOLUTION-CHANGEKEY")) {
+ icalproperty_set_value_from_string (icalprop, change_key, "NO");
+ break;
+ }
+ icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
+ }
- g_free (attach_id->id);
- g_free (attach_id->rootItemId);
- g_free (attach_id->rootItemChangeKey);
+ /* TODO: are we setting the correct attachment ids ? */
+ icalprop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
+ i = ids;
+ for (; i && icalprop; i = i->next, icalprop = icalcomponent_get_next_property (icalcomp, ICAL_ATTACH_PROPERTY)) {
+ icalparam = icalparameter_new_x (i->data);
+ icalparameter_set_xname (icalparam, "X-EWS-ATTACHMENTID");
+ icalproperty_add_parameter (icalprop, icalparam);
- g_free (attach_id);
+ g_free (i->data);
}
+ e_cal_component_commit_sequence (create_data->comp);
+
+ /* update changes and release access to the store */
+ e_cal_backend_store_thaw_changes (priv->store);
+
g_slist_free (ids);
-}
-static void
-e_cal_backend_ews_remove_object (ECalBackend *backend, EDataCal *cal, EServerMethodContext context,
- const gchar *uid, const gchar *rid, CalObjModType mod);
+ g_object_unref (create_data->cbews);
+ g_object_unref (create_data->comp);
+ g_free (create_data);
+}
static void
ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
@@ -1100,7 +1141,7 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
ECalBackendEws *cbews = create_data->cbews;
ECalBackendEwsPrivate *priv = cbews->priv;
GError *error = NULL;
- GSList *ids = NULL, *attachments = NULL;
+ GSList *ids = NULL, *attachments = NULL, *i;
const gchar *comp_uid;
const EwsId *item_id;
icalproperty *icalprop;
@@ -1115,11 +1156,29 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
return;
}
+ item_id = e_ews_item_get_id((EEwsItem *)ids->data);
+ g_slist_free (ids);
+
+ /* attachments */
+ if (e_cal_component_get_num_attachments (create_data->comp) > 0) {
+ EwsCreateAttachmentsData *attach_data = g_new0(EwsCreateAttachmentsData, 1);
+
+ attach_data->cbews = g_object_ref (create_data->cbews);
+ attach_data->comp = g_object_ref (create_data->comp);
+
+ e_cal_component_get_attachment_list (create_data->comp, &attachments);
+ e_ews_connection_create_attachments_start (cnc, EWS_PRIORITY_MEDIUM,
+ item_id, attachments,
+ ews_create_attachments_cb, NULL, attach_data);
+
+ for (i = attachments; i ; i = i->next) g_free (i->data);
+ g_slist_free (attachments);
+ }
+
/* get exclusive access to the store */
e_cal_backend_store_freeze_changes(priv->store);
/* set item id */
- item_id = e_ews_item_get_id((EEwsItem *)ids->data);
e_cal_component_set_uid(create_data->comp, item_id->id);
/* set a new ical property containing the change key we got from the exchange server for future use */
@@ -1128,14 +1187,6 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
icalcomp = e_cal_component_get_icalcomponent(create_data->comp);
icalcomponent_add_property (icalcomp, icalprop);
- /* attachments */
- if (e_cal_component_get_num_attachments (create_data->comp) > 0) {
- e_cal_component_get_attachment_list (create_data->comp, &attachments);
- e_ews_connection_create_attachments_start (cnc, EWS_PRIORITY_MEDIUM,
- item_id, attachments,
- ews_create_attachments_cb, NULL, create_data->comp);
- }
-
/* update component internal data */
e_cal_component_commit_sequence(create_data->comp);
put_component_to_store (create_data->cbews, create_data->comp);
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 750574c..70ba2ad 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -2743,9 +2743,9 @@ static void
create_attachments_response_cb (ESoapParameter *param,
EwsNode *enode)
{
- ESoapParameter *subparam, *attspara;
+ /* http://msdn.microsoft.com/en-us/library/aa565877%28v=EXCHG.80%29.aspx */
+ ESoapParameter *subparam, *attspara, *last_relevant = NULL;
EwsAsyncData *async_data;
- EwsAttachmentId *attach_id;
async_data = g_simple_async_result_get_op_res_gpointer (enode->simple);
@@ -2753,14 +2753,15 @@ create_attachments_response_cb (ESoapParameter *param,
for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; subparam = e_soap_parameter_get_next_child (subparam)) {
if (!g_ascii_strcasecmp (e_soap_parameter_get_name(subparam), "FileAttachment")) {
- attach_id = g_new0 (EwsAttachmentId, 1);
- attach_id->id = e_soap_parameter_get_property (subparam, "Id");
- attach_id->rootItemId = e_soap_parameter_get_property (subparam, "RootItemId");
- attach_id->rootItemChangeKey = e_soap_parameter_get_property (subparam, "RootItemChangeKey");
+ last_relevant = subparam;
- async_data->items = g_slist_append (async_data->items, attach_id);
+ async_data->items = g_slist_append (async_data->items, e_soap_parameter_get_property (subparam, "Id"));
}
}
+
+ if (last_relevant != NULL) {
+ async_data->sync_state = e_soap_parameter_get_property (last_relevant, "RootItemChangeKey");
+ }
}
static void
@@ -2861,6 +2862,7 @@ e_ews_connection_create_attachments_start (EEwsConnection *cnc,
GSList *
e_ews_connection_create_attachments_finish (EEwsConnection *cnc,
+ gchar **change_key,
GAsyncResult *result,
GError **error)
{
@@ -2880,6 +2882,7 @@ e_ews_connection_create_attachments_finish (EEwsConnection *cnc,
return NULL;
ids = async_data->items;
+ *change_key = async_data->sync_state;
return ids;
}
@@ -2889,6 +2892,7 @@ e_ews_connection_create_attachments (EEwsConnection *cnc,
gint pri,
const EwsId *parent,
const GSList *files,
+ gchar **change_key,
GCancellable *cancellable,
GError **error)
{
@@ -2907,7 +2911,7 @@ e_ews_connection_create_attachments (EEwsConnection *cnc,
e_flag_wait (sync_data->eflag);
- ids = e_ews_connection_create_attachments_finish (cnc, sync_data->res,
+ ids = e_ews_connection_create_attachments_finish (cnc, change_key, sync_data->res,
error);
e_flag_free (sync_data->eflag);
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index b901e60..8c5deb8 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -475,6 +475,7 @@ void e_ews_connection_create_attachments_start
GSList * e_ews_connection_create_attachments_finish
(EEwsConnection *cnc,
+ gchar **change_key,
GAsyncResult *result,
GError **error);
@@ -483,6 +484,7 @@ GSList * e_ews_connection_create_attachments
gint pri,
const EwsId *parent,
const GSList *files,
+ gchar **change_key,
GCancellable *cancellable,
GError **error);
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index c74fa96..f4982bd 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -72,12 +72,6 @@ typedef struct {
} EwsId;
typedef struct {
- gchar *id;
- gchar *rootItemId;
- gchar *rootItemChangeKey;
-} EwsAttachmentId;
-
-typedef struct {
gchar *name;
gchar *email;
} EwsMailbox;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]