[evolution-activesync] libeasclient: add eas_sync_handler_get_folder_list
- From: Patrick Ohly <pohly src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-activesync] libeasclient: add eas_sync_handler_get_folder_list
- Date: Tue, 26 Feb 2013 10:05:49 +0000 (UTC)
commit 034673860a90b92d96b5b0d9f6d4fa1420e4d2f0
Author: Graham R. Cobb <g+syncevolution cobb uk net>
Date: Mon Feb 4 23:05:06 2013 +0000
libeasclient: add eas_sync_handler_get_folder_list
Folder listing code was moved into eas-folder.c and the existing
eas_mail_handler_get_folder_list was modified to use the new common code.
A new function eas_sync_handler_get_folder_list (with the same parameters and
behaviour, except for requiring a sync handle instead of a mail handle) was
added for the convenience of sync clients. This will be used by libeasclient
and the syncevolution ActiveSync backend.
libeasclient/eas-folder.c | 106 +++++++++++++++++++++++++++++++++++++++++++++
libeasclient/eas-folder.h | 10 ++++
libeasclient/libeasmail.c | 78 +--------------------------------
libeasclient/libeassync.c | 28 ++++++++++++
libeasclient/libeassync.h | 24 ++++++++++
5 files changed, 171 insertions(+), 75 deletions(-)
---
diff --git a/libeasclient/eas-folder.c b/libeasclient/eas-folder.c
index 08334e1..f4d70bf 100644
--- a/libeasclient/eas-folder.c
+++ b/libeasclient/eas-folder.c
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include "eas-folder.h"
+#include "eas-errors.h"
+#include "eas-dbus-client.h"
G_DEFINE_TYPE (EasFolder, eas_folder, G_TYPE_OBJECT);
@@ -130,3 +132,107 @@ eas_folder_deserialise (EasFolder* folder, const gchar *data)
return TRUE;
}
+// takes an NULL terminated array of serialised folders and creates a list of EasFolder objects
+static gboolean
+build_folder_list (const gchar **serialised_folder_array, GSList **folder_list, GError **error)
+{
+ gboolean ret = TRUE;
+ guint i = 0;
+
+ g_debug ("build_folder_list++");
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_assert (folder_list);
+ g_assert (*folder_list == NULL);
+
+ while (serialised_folder_array[i]) {
+ EasFolder *folder = eas_folder_new();
+ if (folder) {
+ *folder_list = g_slist_append (*folder_list, folder); // add it to the list first
to aid cleanup
+ if (!folder_list) {
+ g_free (folder);
+ ret = FALSE;
+ goto cleanup;
+ }
+ if (!eas_folder_deserialise (folder, serialised_folder_array[i])) {
+ ret = FALSE;
+ goto cleanup;
+ }
+ } else {
+ ret = FALSE;
+ goto cleanup;
+ }
+ i++;
+ }
+
+cleanup:
+ if (!ret) {
+ // set the error
+ g_set_error (error, EAS_CONNECTION_ERROR,
+ EAS_CONNECTION_ERROR_NOTENOUGHMEMORY,
+ ("out of memory"));
+ // clean up on error
+ g_slist_foreach (*folder_list, (GFunc) g_free, NULL);
+ g_slist_free (*folder_list);
+ *folder_list = NULL;
+ }
+
+ g_debug ("list has %d items", g_slist_length (*folder_list));
+ g_debug ("build_folder_list++");
+ return ret;
+}
+
+gboolean
+eas_folder_get_folder_list (void *client_ptr,
+ gboolean force_refresh,
+ GSList **folders,
+ GCancellable *cancellable,
+ GError **error)
+{
+ // client_ptr is void* so that eas-folder.h does not have to include
+ // eas-dbus-client.h. Unfortunately eas_gdbus_client is just a struct
+ // not a GObject so we can't check the caller passed the correct type.
+ struct eas_gdbus_client *client = client_ptr;
+ gboolean ret = FALSE;
+ gchar **folder_array = NULL;
+
+ g_debug ("%s++ : account_uid[%s]", __func__,
+ (client && client->account_uid ? client->account_uid : "NULL"));
+
+ if (client == NULL || folders == NULL || *folders != NULL) {
+ g_set_error (error,
+ EAS_CONNECTION_ERROR,
+ EAS_CONNECTION_ERROR_BADARG,
+ "%s requires valid arguments", __func__);
+ goto out;
+ }
+
+ ret = eas_gdbus_call (client,
+ EAS_SERVICE_COMMON_OBJECT_PATH, EAS_SERVICE_COMMON_INTERFACE,
+ "get_folders", NULL, NULL,
+ "(sb)", "(^as)", cancellable, error,
+ client->account_uid, force_refresh,
+ &folder_array);
+ if (!ret)
+ goto out;
+
+ g_debug ("%s called successfully", __func__);
+
+ // get 3 arrays of strings of 'serialised' EasFolders, convert to EasFolder lists:
+ ret = build_folder_list ( (const gchar **) folder_array, folders, error);
+
+ g_strfreev (folder_array);
+
+ if (!ret) { // failed - cleanup lists
+ g_assert (error == NULL || *error != NULL);
+ if (error) {
+ g_warning (" Error: %s", (*error)->message);
+ }
+ g_debug ("%s failure - cleanup lists", __func__);
+ g_slist_foreach (*folders, (GFunc) g_free, NULL);
+ g_free (*folders);
+ *folders = NULL;
+ }
+ out:
+ g_debug ("%s--", __func__);
+ return ret;
+}
diff --git a/libeasclient/eas-folder.h b/libeasclient/eas-folder.h
index 56f8d04..d31034b 100644
--- a/libeasclient/eas-folder.h
+++ b/libeasclient/eas-folder.h
@@ -27,6 +27,7 @@
#define _EAS_MAIL_FOLDER_H_
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
@@ -102,6 +103,15 @@ populate the object from a string
*/
gboolean eas_folder_deserialise (EasFolder* folder, const gchar *data);
+/*
+fetch folders and create a list of EasFolder objects
+*/
+gboolean eas_folder_get_folder_list (void *client, // Must be a struct eas_gdbus_client*
+ gboolean force_refresh,
+ GSList **folders,
+ GCancellable *cancellable,
+ GError **error);
+
G_END_DECLS
diff --git a/libeasclient/libeasmail.c b/libeasclient/libeasmail.c
index 839df96..c493e18 100644
--- a/libeasclient/libeasmail.c
+++ b/libeasclient/libeasmail.c
@@ -175,56 +175,6 @@ eas_mail_handler_new (const char* account_uid, GError **error)
#define eas_gdbus_mail_call(self, ...) eas_gdbus_call(&(self)->priv->eas_client,
EAS_SERVICE_MAIL_OBJECT_PATH, EAS_SERVICE_MAIL_INTERFACE, __VA_ARGS__)
#define eas_gdbus_common_call(self, ...) eas_gdbus_call(&(self)->priv->eas_client,
EAS_SERVICE_COMMON_OBJECT_PATH, EAS_SERVICE_COMMON_INTERFACE, __VA_ARGS__)
-// takes an NULL terminated array of serialised folders and creates a list of EasFolder objects
-static gboolean
-build_folder_list (const gchar **serialised_folder_array, GSList **folder_list, GError **error)
-{
- gboolean ret = TRUE;
- guint i = 0;
-
- g_debug ("build_folder_list++");
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- g_assert (folder_list);
- g_assert (*folder_list == NULL);
-
- while (serialised_folder_array[i]) {
- EasFolder *folder = eas_folder_new();
- if (folder) {
- *folder_list = g_slist_append (*folder_list, folder); // add it to the list first
to aid cleanup
- if (!folder_list) {
- g_free (folder);
- ret = FALSE;
- goto cleanup;
- }
- if (!eas_folder_deserialise (folder, serialised_folder_array[i])) {
- ret = FALSE;
- goto cleanup;
- }
- } else {
- ret = FALSE;
- goto cleanup;
- }
- i++;
- }
-
-cleanup:
- if (!ret) {
- // set the error
- g_set_error (error, EAS_MAIL_ERROR,
- EAS_MAIL_ERROR_NOTENOUGHMEMORY,
- ("out of memory"));
- // clean up on error
- g_slist_foreach (*folder_list, (GFunc) g_free, NULL);
- g_slist_free (*folder_list);
- *folder_list = NULL;
- }
-
- g_debug ("list has %d items", g_slist_length (*folder_list));
- g_debug ("build_folder_list++");
- return ret;
-}
-
-
// takes an NULL terminated array of serialised emailinfos and creates a list of EasEmailInfo objects
static gboolean
build_emailinfo_list (const gchar **serialised_emailinfo_array, GSList **emailinfo_list, GError **error)
@@ -432,7 +382,6 @@ eas_mail_handler_get_folder_list (EasEmailHandler *self,
GError **error)
{
gboolean ret = FALSE;
- gchar **folder_array = NULL;
g_debug ("%s++ : account_uid[%s]", __func__,
(self->priv->eas_client.account_uid ? self->priv->eas_client.account_uid : "NULL"));
@@ -441,34 +390,13 @@ eas_mail_handler_get_folder_list (EasEmailHandler *self,
g_set_error (error,
EAS_MAIL_ERROR,
EAS_MAIL_ERROR_BADARG,
- "eas_mail_handler_get_folder_list requires valid arguments");
+ "%s requires valid arguments", __func__);
goto out;
}
- ret = eas_gdbus_common_call (self, "get_folders", NULL, NULL,
- "(sb)", "(^as)", cancellable, error,
- self->priv->eas_client.account_uid, force_refresh,
- &folder_array);
- if (!ret)
- goto out;
-
- g_debug ("%s called successfully", __func__);
-
- // get 3 arrays of strings of 'serialised' EasFolders, convert to EasFolder lists:
- ret = build_folder_list ( (const gchar **) folder_array, folders, error);
-
- g_strfreev (folder_array);
+ ret = eas_folder_get_folder_list (&(self)->priv->eas_client,
+ force_refresh, folders, cancellable, error);
- if (!ret) { // failed - cleanup lists
- g_assert (error == NULL || *error != NULL);
- if (error) {
- g_warning (" Error: %s", (*error)->message);
- }
- g_debug ("%s failure - cleanup lists", __func__);
- g_slist_foreach (*folders, (GFunc) g_free, NULL);
- g_free (*folders);
- *folders = NULL;
- }
out:
g_debug ("%s--", __func__);
return ret;
diff --git a/libeasclient/libeassync.c b/libeasclient/libeassync.c
index a0c12ad..cebfcbd 100644
--- a/libeasclient/libeassync.c
+++ b/libeasclient/libeassync.c
@@ -148,6 +148,34 @@ eas_sync_handler_new (const gchar* account_uid)
return object;
}
+gboolean
+eas_sync_handler_get_folder_list (EasSyncHandler *self,
+ gboolean force_refresh,
+ GSList **folders,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ g_debug ("%s++ : account_uid[%s]", __func__,
+ (self->priv->eas_client.account_uid ? self->priv->eas_client.account_uid : "NULL"));
+
+ if (self == NULL || folders == NULL || *folders != NULL) {
+ g_set_error (error,
+ EAS_SYNC_ERROR,
+ EAS_SYNC_ERROR_BADARG,
+ "%s requires valid arguments", __func__);
+ goto out;
+ }
+
+ ret = eas_folder_get_folder_list (&(self)->priv->eas_client,
+ force_refresh, folders, cancellable, error);
+
+ out:
+ g_debug ("%s--", __func__);
+ return ret;
+}
+
static void
free_string_array (gchar **array)
{
diff --git a/libeasclient/libeassync.h b/libeasclient/libeassync.h
index 3136839..af799b2 100644
--- a/libeasclient/libeassync.h
+++ b/libeasclient/libeassync.h
@@ -27,7 +27,9 @@
#define EAS_SYNC_H
#include <glib-object.h>
+#include <gio/gio.h>
#include "eas-item-info.h"
+#include "eas-errors.h"
G_BEGIN_DECLS
@@ -78,6 +80,28 @@ GType eas_sync_handler_get_type (void) G_GNUC_CONST;
// as an argument
EasSyncHandler *eas_sync_handler_new (const char* account_uid);
+/* function name: eas_sync_handler_get_folder_list
+ * function description: gets current folder structure of account. Supplies
+ * Supplies lists of EasFolders.
+ * return value: TRUE if function success, FALSE if error
+ * params:
+ * EasEmailHandler* this (in): use value returned from eas_sync_hander_new()
+ * gboolean force_update (in): check for updates from the server. If FALSE, uses the
+ * information already cached by the ActiveSync dæmon.
+ * GSList **folders (out): returns a list of EasFolder structs that describe the
+ * folders on the server.
+ * GError **error (out): returns error information if an error occurs. If no
+ * error occurs this will unchanged. This error information
+ * could be related to errors in this API or errors propagated
+ * back through underlying layers
+*/
+gboolean
+eas_sync_handler_get_folder_list (EasSyncHandler *self,
+ gboolean force_refresh,
+ GSList **folders,
+ GCancellable *cancellable,
+ GError **error);
+
/* function name: eas_sync_handler_get calendar_items
* function description: pulls down changes in calendar folder
* return value: TRUE if function success, FALSE if error
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]