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)
210 for (iter = hits; iter; iter = iter->next) {
211 modest_search_hit_free ((ModestSearchHit *) iter->data);
218 _dbus_iter_get_string_or_null (DBusMessageIter *iter)
223 dbus_message_iter_get_basic (iter, &string);
226 if (string && strlen (string)) {
227 ret = g_strdup (string);
234 _dbus_iter_get_uint64 (DBusMessageIter *iter)
240 dbus_message_iter_get_basic (iter, &ui64v);
242 ret = (guint64) ui64v;
249 _dbus_iter_get_int64 (DBusMessageIter *iter)
255 dbus_message_iter_get_basic (iter, &i64v);
263 _dbus_iter_get_boolean (DBusMessageIter *iter)
270 dbus_message_iter_get_basic (iter, &val);
272 ret = (gboolean) val;
278 static ModestSearchHit *
279 dbus_message_iter_get_search_hit (DBusMessageIter *parent)
281 ModestSearchHit *hit;
282 DBusMessageIter child;
288 hit = g_slice_new0 (ModestSearchHit);
290 arg_type = dbus_message_iter_get_arg_type (parent);
292 if (arg_type != 'r') {
296 dbus_message_iter_recurse (parent, &child);
299 arg_type = dbus_message_iter_get_arg_type (&child);
301 if (arg_type != DBUS_TYPE_STRING) {
306 hit->msgid = _dbus_iter_get_string_or_null (&child);
308 res = dbus_message_iter_next (&child);
315 arg_type = dbus_message_iter_get_arg_type (&child);
317 if (arg_type != DBUS_TYPE_STRING) {
322 hit->subject = _dbus_iter_get_string_or_null (&child);
324 res = dbus_message_iter_next (&child);
331 arg_type = dbus_message_iter_get_arg_type (&child);
333 if (arg_type != DBUS_TYPE_STRING) {
338 hit->folder = _dbus_iter_get_string_or_null (&child);
340 res = dbus_message_iter_next (&child);
347 arg_type = dbus_message_iter_get_arg_type (&child);
349 if (arg_type != DBUS_TYPE_STRING) {
354 hit->sender = _dbus_iter_get_string_or_null (&child);
356 res = dbus_message_iter_next (&child);
363 arg_type = dbus_message_iter_get_arg_type (&child);
365 if (arg_type != DBUS_TYPE_UINT64) {
370 hit->msize = _dbus_iter_get_uint64 (&child);
372 res = dbus_message_iter_next (&child);
379 arg_type = dbus_message_iter_get_arg_type (&child);
381 if (arg_type != DBUS_TYPE_BOOLEAN) {
386 hit->has_attachment = _dbus_iter_get_boolean (&child);
388 res = dbus_message_iter_next (&child);
395 arg_type = dbus_message_iter_get_arg_type (&child);
397 if (arg_type != DBUS_TYPE_BOOLEAN) {
402 hit->is_unread = _dbus_iter_get_boolean (&child);
404 res = dbus_message_iter_next (&child);
411 arg_type = dbus_message_iter_get_arg_type (&child);
413 if (arg_type != DBUS_TYPE_INT64) {
418 hit->timestamp = _dbus_iter_get_int64 (&child);
420 res = dbus_message_iter_next (&child);
428 g_warning ("Error during unmarshaling");
429 modest_search_hit_free (hit);
438 libmodest_dbus_client_search (osso_context_t *osso_ctx,
444 ModestDBusSearchFlags flags,
452 DBusMessageIter iter;
453 DBusMessageIter child;
454 DBusMessage *reply = NULL;
459 dbus_int32_t flags_v;
460 dbus_uint32_t size_v;
463 con = osso_get_dbus_connection (osso_ctx);
466 g_warning ("Could not get dbus connection\n");
472 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
475 MODEST_DBUS_METHOD_SEARCH);
478 //ULOG_ERR_F("dbus_message_new_method_call failed");
484 flags_v = (dbus_int32_t) flags;
485 size_v = (dbus_uint32_t) min_size;
487 res = dbus_message_append_args (msg,
488 DBUS_TYPE_STRING, &query,
489 DBUS_TYPE_STRING, &folder,
490 DBUS_TYPE_INT64, &sd_v,
491 DBUS_TYPE_INT64, &ed_v,
492 DBUS_TYPE_INT32, &flags_v,
493 DBUS_TYPE_UINT32, &size_v,
496 dbus_message_set_auto_start (msg, TRUE);
498 dbus_error_init (&err);
500 timeout = 1000; //XXX
501 osso_rpc_get_timeout (osso_ctx, &timeout);
503 reply = dbus_connection_send_with_reply_and_block (con,
508 dbus_message_unref (msg);
512 //ULOG_ERR_F("dbus_connection_send_with_reply_and_block error: %s", err.message);
517 switch (dbus_message_get_type (reply)) {
519 case DBUS_MESSAGE_TYPE_ERROR:
520 dbus_set_error_from_message (&err, reply);
522 dbus_error_free (&err);
523 dbus_message_unref (reply);
526 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
527 /* ok we are good to go
528 * lets drop outa here and handle that */
531 //ULOG_WARN_F("got unknown message type as reply");
532 //retval->type = DBUS_TYPE_STRING;
533 //retval->value.s = g_strdup("Invalid return value");
535 dbus_message_unref (reply);
539 g_debug ("message return");
541 dbus_message_iter_init (reply, &iter);
542 arg_type = dbus_message_iter_get_arg_type (&iter);
544 dbus_message_iter_recurse (&iter, &child);
547 ModestSearchHit *hit;
549 hit = dbus_message_iter_get_search_hit (&child);
552 *hits = g_list_prepend (*hits, hit);
555 } while (dbus_message_iter_next (&child));
557 dbus_message_unref (reply);
560 /* TODO: This is from osso source, do we need it? */
562 /* Tell TaskNavigator to show "launch banner" */
563 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
564 APP_LAUNCH_BANNER_METHOD_PATH,
565 APP_LAUNCH_BANNER_METHOD_INTERFACE,
566 APP_LAUNCH_BANNER_METHOD);
569 g_warn ("dbus_message_new_method_call failed");
574 dbus_message_append_args (msg,
579 b = dbus_connection_send (conn, msg, NULL);
582 ULOG_WARN_F("dbus_connection_send failed");
585 dbus_message_unref (msg);