X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=libmodest-dbus-client%2Flibmodest-dbus-client.c;h=0e9668797da22f03ae4360ef4073692c92ab69ef;hp=fefaaf2a8848e5fe977277d0d89f62a6f33a0fe9;hb=b91f5d417772ff0ae30acb9b955ad90ad89e1699;hpb=b9ed460defaba68c025556d4d658bd9f0b288d91 diff --git a/libmodest-dbus-client/libmodest-dbus-client.c b/libmodest-dbus-client/libmodest-dbus-client.c index fefaaf2..0e96687 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.c +++ b/libmodest-dbus-client/libmodest-dbus-client.c @@ -30,6 +30,11 @@ #include "libmodest-dbus-client.h" #include /* For the API strings. */ +//#define DBUS_API_SUBJECT_TO_CHANGE 1 +#include +#include +#include + gboolean libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments) @@ -165,3 +170,387 @@ libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) return TRUE; } + +static void +modest_search_hit_free (ModestSearchHit *hit) +{ + g_free (hit->msgid); + + g_slice_free (ModestSearchHit, hit); +} + + +static char * +_dbus_iter_get_string_or_null (DBusMessageIter *iter) +{ + const char *string; + char *ret; + + dbus_message_iter_get_basic (iter, &string); + + ret = NULL; + if (string && strlen (string)) { + ret = g_strdup (string); + } + + return ret; +} + +static guint64 +_dbus_iter_get_uint64 (DBusMessageIter *iter) +{ + dbus_uint64_t ui64v; + guint64 ret; + + ui64v = 0; + dbus_message_iter_get_basic (iter, &ui64v); + + ret = (guint64) ui64v; + + return ret; +} + + +static gint64 +_dbus_iter_get_int64 (DBusMessageIter *iter) +{ + dbus_int64_t i64v; + gint64 ret; + + i64v = 0; + dbus_message_iter_get_basic (iter, &i64v); + + ret = (gint64) i64v; + + return ret; +} + +static gboolean +_dbus_iter_get_boolean (DBusMessageIter *iter) + +{ + dbus_bool_t val; + gboolean ret; + + val = FALSE; + dbus_message_iter_get_basic (iter, &val); + + ret = (gboolean) val; + + return ret; +} + + +static ModestSearchHit * +dbus_message_iter_get_search_hit (DBusMessageIter *parent) +{ + ModestSearchHit *hit; + DBusMessageIter child; + dbus_bool_t res; + int arg_type; + gboolean error; + + error = FALSE; + hit = g_slice_new0 (ModestSearchHit); + + arg_type = dbus_message_iter_get_arg_type (parent); + + if (arg_type != 'r') { + return NULL; + } + + dbus_message_iter_recurse (parent, &child); + + /* msgid */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_STRING) { + error = TRUE; + goto out; + } + + hit->msgid = _dbus_iter_get_string_or_null (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* subject */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_STRING) { + error = TRUE; + goto out; + } + + hit->subject = _dbus_iter_get_string_or_null (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* folder */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_STRING) { + error = TRUE; + goto out; + } + + hit->folder = _dbus_iter_get_string_or_null (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* sender */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_STRING) { + error = TRUE; + goto out; + } + + hit->sender = _dbus_iter_get_string_or_null (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* msize */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_UINT64) { + error = TRUE; + goto out; + } + + hit->msize = _dbus_iter_get_uint64 (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* has_attachment */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_BOOLEAN) { + error = TRUE; + goto out; + } + + hit->has_attachment = _dbus_iter_get_boolean (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* is_unread */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_BOOLEAN) { + error = TRUE; + goto out; + } + + hit->is_unread = _dbus_iter_get_boolean (&child); + + res = dbus_message_iter_next (&child); + if (res == FALSE) { + error = TRUE; + goto out; + } + + /* msize */ + arg_type = dbus_message_iter_get_arg_type (&child); + + if (arg_type != DBUS_TYPE_INT64) { + error = TRUE; + goto out; + } + + hit->timestamp = _dbus_iter_get_int64 (&child); + + res = dbus_message_iter_next (&child); + if (res == TRUE) { + error = TRUE; + goto out; + } + +out: + if (error) { + g_warning ("Error during unmarshaling"); + modest_search_hit_free (hit); + hit = NULL; + } + + return hit; +} + + +gboolean +libmodest_dbus_client_search (osso_context_t *osso_ctx, + const gchar *query, + const gchar *folder, + time_t start_date, + time_t end_date, + guint32 min_size, + ModestDBusSearchFlags flags, + GList **hits) +{ + + DBusMessage *msg; + dbus_bool_t res; + DBusError err; + DBusConnection *con; + DBusMessageIter iter; + DBusMessageIter child; + DBusMessage *reply = NULL; + gint timeout; + int arg_type; + dbus_int64_t sd_v; + dbus_int64_t ed_v; + dbus_int32_t flags_v; + dbus_uint32_t size_v; + + + con = osso_get_dbus_connection (osso_ctx); + + if (con == NULL) { + g_warning ("Could not get dbus connection\n"); + return FALSE; + + } + + + msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE, + MODEST_DBUS_OBJECT, + MODEST_DBUS_IFACE, + MODEST_DBUS_METHOD_SEARCH); + + if (msg == NULL) { + //ULOG_ERR_F("dbus_message_new_method_call failed"); + return OSSO_ERROR; + } + + sd_v = start_date; + ed_v = end_date; + flags_v = (dbus_int32_t) flags; + size_v = (dbus_uint32_t) min_size; + + res = dbus_message_append_args (msg, + DBUS_TYPE_STRING, &query, + DBUS_TYPE_STRING, &folder, + DBUS_TYPE_INT64, &sd_v, + DBUS_TYPE_INT64, &ed_v, + DBUS_TYPE_INT32, &flags_v, + DBUS_TYPE_UINT32, &size_v, + DBUS_TYPE_INVALID); + + dbus_message_set_auto_start (msg, TRUE); + + dbus_error_init (&err); + + timeout = 1000; //XXX + osso_rpc_get_timeout (osso_ctx, &timeout); + + reply = dbus_connection_send_with_reply_and_block (con, + msg, + timeout, + &err); + + dbus_message_unref (msg); + + + if (reply == NULL) { + //ULOG_ERR_F("dbus_connection_send_with_reply_and_block error: %s", err.message); + //XXX to GError?! + return FALSE; + } + + switch (dbus_message_get_type (reply)) { + + case DBUS_MESSAGE_TYPE_ERROR: + dbus_set_error_from_message (&err, reply); + //XXX to GError?! + dbus_error_free (&err); + dbus_message_unref (reply); + return FALSE; + + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + /* ok we are good to go + * lets drop outa here and handle that */ + break; + default: + //ULOG_WARN_F("got unknown message type as reply"); + //retval->type = DBUS_TYPE_STRING; + //retval->value.s = g_strdup("Invalid return value"); + //XXX to GError?! + dbus_message_unref (reply); + return FALSE; + } + + g_debug ("message return"); + + dbus_message_iter_init (reply, &iter); + arg_type = dbus_message_iter_get_arg_type (&iter); + + dbus_message_iter_recurse (&iter, &child); + + do { + ModestSearchHit *hit; + + hit = dbus_message_iter_get_search_hit (&child); + + if (hit) { + *hits = g_list_prepend (*hits, hit); + } + + } while (dbus_message_iter_next (&child)); + + dbus_message_unref (reply); + + + /* TODO: This is from osso source, do we need it? */ +#if 0 + /* Tell TaskNavigator to show "launch banner" */ + msg = dbus_message_new_method_call (TASK_NAV_SERVICE, + APP_LAUNCH_BANNER_METHOD_PATH, + APP_LAUNCH_BANNER_METHOD_INTERFACE, + APP_LAUNCH_BANNER_METHOD); + + if (msg == NULL) { + g_warn ("dbus_message_new_method_call failed"); + } + + + + dbus_message_append_args (msg, + DBUS_TYPE_STRING, + &service, + DBUS_TYPE_INVALID); + + b = dbus_connection_send (conn, msg, NULL); + + if (b == NULL) { + ULOG_WARN_F("dbus_connection_send failed"); + } + + dbus_message_unref (msg); +#endif + + return TRUE; +} +