1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "libmodest-dbus-client.h"
31 #include <dbus_api/modest-dbus-api.h> /* For the API strings. */
33 //#define DBUS_API_SUBJECT_TO_CHANGE 1
34 #include <dbus/dbus.h>
35 #include <dbus/dbus-glib-lowlevel.h>
39 libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc,
40 const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
43 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
45 MODEST_DBUS_METHOD_SEND_MAIL, &retval,
48 DBUS_TYPE_STRING, bcc,
49 DBUS_TYPE_STRING, subject,
50 DBUS_TYPE_STRING, body,
54 printf("debug: osso_rpc_run() failed.\n");
57 printf("debug: osso_rpc_run() succeeded.\n");
60 osso_rpc_free_val(&retval);
66 libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto_uri)
69 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
71 MODEST_DBUS_METHOD_MAIL_TO, &retval,
72 DBUS_TYPE_STRING, mailto_uri,
76 printf("debug: osso_rpc_run() failed.\n");
79 printf("debug: osso_rpc_run() succeeded.\n");
82 osso_rpc_free_val(&retval);
88 libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc,
89 const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
92 gchar *attachments_str = NULL;
96 attachments_str = g_strdup( (gchar *) attachments->data );
98 for (next = g_slist_next(attachments); next != NULL; next = g_slist_next(next))
100 tmp = g_strconcat(attachments_str, ",", (gchar *) (next->data), NULL);
101 g_free(attachments_str);
102 attachments_str = tmp;
103 if (attachments_str == NULL) {
108 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
110 MODEST_DBUS_METHOD_COMPOSE_MAIL, &retval,
111 DBUS_TYPE_STRING, to,
112 DBUS_TYPE_STRING, cc,
113 DBUS_TYPE_STRING, bcc,
114 DBUS_TYPE_STRING, subject,
115 DBUS_TYPE_STRING, body,
116 DBUS_TYPE_STRING, attachments_str,
119 if (ret != OSSO_OK) {
120 printf("debug: osso_rpc_run() failed.\n");
123 printf("debug: osso_rpc_run() succeeded.\n");
126 osso_rpc_free_val(&retval);
132 libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri)
135 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
137 MODEST_DBUS_METHOD_OPEN_MESSAGE, &retval,
138 DBUS_TYPE_STRING, mail_uri,
141 if (ret != OSSO_OK) {
142 printf("debug: osso_rpc_run() failed.\n");
145 printf("debug: osso_rpc_run() succeeded.\n");
148 osso_rpc_free_val(&retval);
154 libmodest_dbus_client_send_and_receive (osso_context_t *osso_context)
157 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
159 MODEST_DBUS_METHOD_SEND_RECEIVE, &retval,
162 if (ret != OSSO_OK) {
163 printf("debug: osso_rpc_run() failed.\n");
166 printf("debug: osso_rpc_run() succeeded.\n");
169 osso_rpc_free_val(&retval);
175 libmodest_dbus_client_delete_message (osso_context_t *osso_ctx,
181 ret = osso_rpc_run_with_defaults (osso_ctx,
183 MODEST_DBUS_METHOD_DELETE_MESSAGE, &retval,
184 DBUS_TYPE_STRING, msg_uri,
187 if (ret != OSSO_OK) {
188 g_debug ("debug: osso_rpc_run() failed.\n");
190 g_debug ("debug: osso_rpc_run() succeeded.\n");
193 osso_rpc_free_val (&retval);
195 return ret == OSSO_OK;
199 modest_search_hit_free (ModestSearchHit *hit)
202 g_slice_free (ModestSearchHit, hit);
206 modest_search_hit_list_free (GList *hits)
214 for (iter = hits; iter; iter = iter->next) {
215 modest_search_hit_free ((ModestSearchHit *) iter->data);
222 _dbus_iter_get_string_or_null (DBusMessageIter *iter)
227 dbus_message_iter_get_basic (iter, &string);
230 if (string && strlen (string)) {
231 ret = g_strdup (string);
238 _dbus_iter_get_uint64 (DBusMessageIter *iter)
244 dbus_message_iter_get_basic (iter, &ui64v);
246 ret = (guint64) ui64v;
253 _dbus_iter_get_int64 (DBusMessageIter *iter)
259 dbus_message_iter_get_basic (iter, &i64v);
267 _dbus_iter_get_boolean (DBusMessageIter *iter)
274 dbus_message_iter_get_basic (iter, &val);
276 ret = (gboolean) val;
282 static ModestSearchHit *
283 dbus_message_iter_get_search_hit (DBusMessageIter *parent)
285 ModestSearchHit *hit;
286 DBusMessageIter child;
292 hit = g_slice_new0 (ModestSearchHit);
294 arg_type = dbus_message_iter_get_arg_type (parent);
296 if (arg_type != 'r') {
300 dbus_message_iter_recurse (parent, &child);
303 arg_type = dbus_message_iter_get_arg_type (&child);
305 if (arg_type != DBUS_TYPE_STRING) {
310 hit->msgid = _dbus_iter_get_string_or_null (&child);
312 res = dbus_message_iter_next (&child);
319 arg_type = dbus_message_iter_get_arg_type (&child);
321 if (arg_type != DBUS_TYPE_STRING) {
326 hit->subject = _dbus_iter_get_string_or_null (&child);
328 res = dbus_message_iter_next (&child);
335 arg_type = dbus_message_iter_get_arg_type (&child);
337 if (arg_type != DBUS_TYPE_STRING) {
342 hit->folder = _dbus_iter_get_string_or_null (&child);
344 res = dbus_message_iter_next (&child);
351 arg_type = dbus_message_iter_get_arg_type (&child);
353 if (arg_type != DBUS_TYPE_STRING) {
358 hit->sender = _dbus_iter_get_string_or_null (&child);
360 res = dbus_message_iter_next (&child);
367 arg_type = dbus_message_iter_get_arg_type (&child);
369 if (arg_type != DBUS_TYPE_UINT64) {
374 hit->msize = _dbus_iter_get_uint64 (&child);
376 res = dbus_message_iter_next (&child);
383 arg_type = dbus_message_iter_get_arg_type (&child);
385 if (arg_type != DBUS_TYPE_BOOLEAN) {
390 hit->has_attachment = _dbus_iter_get_boolean (&child);
392 res = dbus_message_iter_next (&child);
399 arg_type = dbus_message_iter_get_arg_type (&child);
401 if (arg_type != DBUS_TYPE_BOOLEAN) {
406 hit->is_unread = _dbus_iter_get_boolean (&child);
408 res = dbus_message_iter_next (&child);
415 arg_type = dbus_message_iter_get_arg_type (&child);
417 if (arg_type != DBUS_TYPE_INT64) {
422 hit->timestamp = _dbus_iter_get_int64 (&child);
424 res = dbus_message_iter_next (&child);
432 g_warning ("Error during unmarshaling");
433 modest_search_hit_free (hit);
442 libmodest_dbus_client_search (osso_context_t *osso_ctx,
448 ModestDBusSearchFlags flags,
456 DBusMessageIter iter;
457 DBusMessageIter child;
458 DBusMessage *reply = NULL;
463 dbus_int32_t flags_v;
464 dbus_uint32_t size_v;
467 con = osso_get_dbus_connection (osso_ctx);
470 g_warning ("Could not get dbus connection\n");
476 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
479 MODEST_DBUS_METHOD_SEARCH);
482 //ULOG_ERR_F("dbus_message_new_method_call failed");
488 flags_v = (dbus_int32_t) flags;
489 size_v = (dbus_uint32_t) min_size;
491 res = dbus_message_append_args (msg,
492 DBUS_TYPE_STRING, &query,
493 DBUS_TYPE_STRING, &folder,
494 DBUS_TYPE_INT64, &sd_v,
495 DBUS_TYPE_INT64, &ed_v,
496 DBUS_TYPE_INT32, &flags_v,
497 DBUS_TYPE_UINT32, &size_v,
500 dbus_message_set_auto_start (msg, TRUE);
502 dbus_error_init (&err);
504 timeout = 1000; //XXX
505 osso_rpc_get_timeout (osso_ctx, &timeout);
507 reply = dbus_connection_send_with_reply_and_block (con,
512 dbus_message_unref (msg);
516 //ULOG_ERR_F("dbus_connection_send_with_reply_and_block error: %s", err.message);
521 switch (dbus_message_get_type (reply)) {
523 case DBUS_MESSAGE_TYPE_ERROR:
524 dbus_set_error_from_message (&err, reply);
526 dbus_error_free (&err);
527 dbus_message_unref (reply);
530 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
531 /* ok we are good to go
532 * lets drop outa here and handle that */
535 //ULOG_WARN_F("got unknown message type as reply");
536 //retval->type = DBUS_TYPE_STRING;
537 //retval->value.s = g_strdup("Invalid return value");
539 dbus_message_unref (reply);
543 g_debug ("message return");
545 dbus_message_iter_init (reply, &iter);
546 arg_type = dbus_message_iter_get_arg_type (&iter);
548 dbus_message_iter_recurse (&iter, &child);
551 ModestSearchHit *hit;
553 hit = dbus_message_iter_get_search_hit (&child);
556 *hits = g_list_prepend (*hits, hit);
559 } while (dbus_message_iter_next (&child));
561 dbus_message_unref (reply);
564 /* TODO: This is from osso source, do we need it? */
566 /* Tell TaskNavigator to show "launch banner" */
567 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
568 APP_LAUNCH_BANNER_METHOD_PATH,
569 APP_LAUNCH_BANNER_METHOD_INTERFACE,
570 APP_LAUNCH_BANNER_METHOD);
573 g_warn ("dbus_message_new_method_call failed");
578 dbus_message_append_args (msg,
583 b = dbus_connection_send (conn, msg, NULL);
586 ULOG_WARN_F("dbus_connection_send failed");
589 dbus_message_unref (msg);