summaryrefslogtreecommitdiff
path: root/src/libtracker-common/tracker-dbus.c
blob: 17c63fcbccb5a5682e36c4a141c0830ed2a7efce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
/*
 * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#include "config.h"

#include <gio/gio.h>
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>

#include <dbus/dbus-glib-bindings.h>

#include "tracker-dbus.h"
#include "tracker-log.h"

/* How long clients can exist since last D-Bus call before being
 * cleaned up.
 */
#define CLIENT_CLEAN_UP_TIME  300

typedef struct {
	gchar *sender;
	gchar *binary;
	gulong pid;
	GTimeVal last_time;
	guint clean_up_id;
} ClientData;

struct _TrackerDBusRequest {
	guint request_id;
	ClientData *cd;
};

typedef struct {
	GInputStream *unix_input_stream;
	GInputStream *buffered_input_stream;
	GOutputStream *output_stream;
	GDBusMessage *reply;
	TrackerDBusSendAndSpliceCallback callback;
	GCancellable *cancellable;
	gpointer user_data;
} SendAndSpliceData;

static gboolean client_lookup_enabled;
static DBusGConnection *freedesktop_connection;
static DBusGProxy *freedesktop_proxy;
static GHashTable *clients;

static void     client_data_free    (gpointer data);
static gboolean client_clean_up_cb (gpointer data);

static gboolean
clients_init (void)
{
	GError *error = NULL;
	DBusGConnection *conn;

	conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);

	if (!conn) {
		g_critical ("Could not connect to the D-Bus session bus, %s",
		            error ? error->message : "no error given.");
		g_error_free (error);
		return FALSE;
	}

	freedesktop_connection = dbus_g_connection_ref (conn);

	freedesktop_proxy =
		dbus_g_proxy_new_for_name (freedesktop_connection,
		                           DBUS_SERVICE_DBUS,
		                           DBUS_PATH_DBUS,
		                           DBUS_INTERFACE_DBUS);

	if (!freedesktop_proxy) {
		g_critical ("Could not create a proxy for the Freedesktop service, %s",
		            error ? error->message : "no error given.");
		g_error_free (error);
		return FALSE;
	}

	clients = g_hash_table_new_full (g_str_hash,
	                                 g_str_equal,
	                                 NULL,
	                                 client_data_free);

	return TRUE;
}

static gboolean
clients_shutdown (void)
{
	if (freedesktop_proxy) {
		g_object_unref (freedesktop_proxy);
		freedesktop_proxy = NULL;
	}

	if (freedesktop_connection) {
		dbus_g_connection_unref (freedesktop_connection);
		freedesktop_connection = NULL;
	}

	if (clients) {
		g_hash_table_unref (clients);
		clients = NULL;
	}

	return TRUE;
}

static void
client_data_free (gpointer data)
{
	ClientData *cd = data;

	if (!cd) {
		return;
	}

	g_source_remove (cd->clean_up_id);

	g_free (cd->sender);
	g_free (cd->binary);

	g_slice_free (ClientData, cd);
}

static ClientData *
client_data_new (gchar *sender)
{
	ClientData *cd;
	GError *error = NULL;
	guint pid;
	gboolean get_binary = TRUE;

	cd = g_slice_new0 (ClientData);
	cd->sender = sender;

	if (org_freedesktop_DBus_get_connection_unix_process_id (freedesktop_proxy,
	                                                         sender,
	                                                         &pid,
	                                                         &error)) {
		cd->pid = pid;
	}

	if (get_binary) {
		gchar *filename;
		gchar *pid_str;
		gchar *contents = NULL;
		GError *error = NULL;
		gchar **strv;

		pid_str = g_strdup_printf ("%ld", cd->pid);
		filename = g_build_filename (G_DIR_SEPARATOR_S,
		                             "proc",
		                             pid_str,
		                             "cmdline",
		                             NULL);
		g_free (pid_str);

		if (!g_file_get_contents (filename, &contents, NULL, &error)) {
			g_warning ("Could not get process name from id %ld, %s",
			           cd->pid,
			           error ? error->message : "no error given");
			g_clear_error (&error);
			g_free (filename);
			return cd;
		}

		g_free (filename);

		strv = g_strsplit (contents, "^@", 2);
		if (strv && strv[0]) {
			cd->binary = g_path_get_basename (strv[0]);
		}

		g_strfreev (strv);
		g_free (contents);
	}

	return cd;
}

static gboolean
client_clean_up_cb (gpointer data)
{
	ClientData *cd;

	cd = data;

	g_debug ("Removing D-Bus client data for '%s' (pid: %lu) with id:'%s'",
	         cd->binary, cd->pid, cd->sender);
	g_hash_table_remove (clients, cd->sender);

	if (g_hash_table_size (clients) < 1) {
		/* Clean everything up. */
		clients_shutdown ();
	}

	return FALSE;
}

static ClientData *
client_get_for_sender (const gchar *sender)
{
	ClientData *cd;

	if (!client_lookup_enabled) {
		return NULL;
	}

	/* Only really done with tracker-extract where we use
	 * functions from the command line with dbus code in them.
	 */
	if (!sender) {
		return NULL;
	}

	if (G_UNLIKELY (!clients)) {
		clients_init ();
	}

	cd = g_hash_table_lookup (clients, sender);
	if (!cd) {
		gchar *sender_dup;

		sender_dup = g_strdup (sender);
		cd = client_data_new (sender_dup);
		g_hash_table_insert (clients, sender_dup, cd);
	} else {
		g_source_remove (cd->clean_up_id);
	}

	cd->clean_up_id = g_timeout_add_seconds (CLIENT_CLEAN_UP_TIME, client_clean_up_cb, cd);

	g_get_current_time (&cd->last_time);

	return cd;
}

GQuark
tracker_dbus_error_quark (void)
{
	return g_quark_from_static_string (TRACKER_DBUS_ERROR_DOMAIN);
}

gchar **
tracker_dbus_slist_to_strv (GSList *list)
{
	GSList  *l;
	gchar  **strv;
	gint     i = 0;

	strv = g_new0 (gchar*, g_slist_length (list) + 1);

	for (l = list; l != NULL; l = l->next) {
		if (!g_utf8_validate (l->data, -1, NULL)) {
			g_message ("Could not add string:'%s' to GStrv, invalid UTF-8",
			           (gchar*) l->data);
			continue;
		}

		strv[i++] = g_strdup (l->data);
	}

	strv[i] = NULL;

	return strv;
}

static guint
get_next_request_id (void)
{
	static guint request_id = 1;

	return request_id++;
}

TrackerDBusRequest *
tracker_dbus_request_begin (const gchar *sender,
                            const gchar *format,
                            ...)
{
	TrackerDBusRequest *request;
	gchar *str;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	request = g_slice_new (TrackerDBusRequest);
	request->request_id = get_next_request_id ();
	request->cd = client_get_for_sender (sender);

	g_debug ("<--- [%d%s%s|%lu] %s",
	         request->request_id,
	         request->cd ? "|" : "",
	         request->cd ? request->cd->binary : "",
	         request->cd ? request->cd->pid : 0,
	         str);

	g_free (str);

	return request;
}

void
tracker_dbus_request_end (TrackerDBusRequest *request,
                          GError             *error)
{
	if (!error) {
		g_debug ("---> [%d%s%s|%lu] Success, no error given",
			 request->request_id,
			 request->cd ? "|" : "",
			 request->cd ? request->cd->binary : "",
			 request->cd ? request->cd->pid : 0);
	} else {
		g_message ("---> [%d%s%s|%lu] Failed, %s",
			   request->request_id,
			   request->cd ? "|" : "",
			   request->cd ? request->cd->binary : "",
			   request->cd ? request->cd->pid : 0,
			   error->message);
	}

	g_slice_free (TrackerDBusRequest, request);
}

void
tracker_dbus_request_info (TrackerDBusRequest    *request,
                           const gchar           *format,
                           ...)
{
	gchar *str;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	tracker_info ("---- [%d%s%s|%lu] %s",
	              request->request_id,
	              request->cd ? "|" : "",
	              request->cd ? request->cd->binary : "",
	              request->cd ? request->cd->pid : 0,
	              str);
	g_free (str);
}

void
tracker_dbus_request_comment (TrackerDBusRequest    *request,
                              const gchar           *format,
                              ...)
{
	gchar *str;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	g_message ("---- [%d%s%s|%lu] %s",
	           request->request_id,
	           request->cd ? "|" : "",
	           request->cd ? request->cd->binary : "",
	           request->cd ? request->cd->pid : 0,
	           str);
	g_free (str);
}

void
tracker_dbus_request_debug (TrackerDBusRequest    *request,
                            const gchar           *format,
                            ...)
{
	gchar *str;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	g_debug ("---- [%d%s%s|%lu] %s",
	         request->request_id,
	         request->cd ? "|" : "",
	         request->cd ? request->cd->binary : "",
	         request->cd ? request->cd->pid : 0,
	         str);
	g_free (str);
}

void
tracker_dbus_enable_client_lookup (gboolean enabled)
{
	/* If this changed and we disabled everything, simply shut it
	 * all down.
	 */
	if (client_lookup_enabled != enabled && !enabled) {
		clients_shutdown ();
	}

	client_lookup_enabled = enabled;
}

TrackerDBusRequest *
tracker_g_dbus_request_begin (GDBusMethodInvocation *invocation,
                              const gchar           *format,
                              ...)
{
	TrackerDBusRequest *request;
	gchar *str;
	const gchar *sender;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	sender = g_dbus_method_invocation_get_sender (invocation);
	request = tracker_dbus_request_begin (sender, "%s", str);

	g_free (str);

	return request;
}

TrackerDBusRequest *
tracker_dbus_g_request_begin (DBusGMethodInvocation *context,
                              const gchar           *format,
                              ...)
{
	TrackerDBusRequest *request;
	gchar *str, *sender;
	va_list args;

	va_start (args, format);
	str = g_strdup_vprintf (format, args);
	va_end (args);

	sender = dbus_g_method_get_sender (context);

	request = tracker_dbus_request_begin (sender, "%s", str);

	g_free (sender);

	g_free (str);

	return request;
}

// todo remove
static GStrv
dbus_send_and_splice_get_variable_names (DBusMessage  *message,
                                         gboolean      copy_strings)
{
	GPtrArray *found;
	DBusMessageIter iter, arr;

	dbus_message_iter_init (message, &iter);
	dbus_message_iter_recurse (&iter, &arr);

	found = g_ptr_array_new ();

	while (dbus_message_iter_get_arg_type (&arr) != DBUS_TYPE_INVALID) {
		gchar *str;

		dbus_message_iter_get_basic (&arr, &str);
		g_ptr_array_add (found, copy_strings ? g_strdup (str) : str);
		dbus_message_iter_next (&arr);
	}

	g_ptr_array_add (found, NULL);

	return (GStrv) g_ptr_array_free (found, FALSE);
}

/*
 * /!\ BIG FAT WARNING /!\
 * The message must be destroyed for this function to succeed, so pass a
 * message with a refcount of 1 (and say goodbye to it, 'cause you'll never
 * see it again
 */

// todo remove
gboolean
tracker_dbus_send_and_splice (DBusConnection  *connection,
                              DBusMessage     *message,
                              int              fd,
                              GCancellable    *cancellable,
                              void           **dest_buffer,
                              gssize          *dest_buffer_size,
                              GStrv           *variable_names,
                              GError         **error)
{
	DBusPendingCall *call;
	DBusMessage *reply = NULL;
	GInputStream *unix_input_stream;
	GInputStream *buffered_input_stream;
	GOutputStream *output_stream;
	GError *inner_error = NULL;
	gboolean ret_value = FALSE;

	g_return_val_if_fail (connection != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	g_return_val_if_fail (fd > 0, FALSE);
	g_return_val_if_fail (dest_buffer != NULL, FALSE);

	dbus_connection_send_with_reply (connection,
	                                 message,
	                                 &call,
	                                 -1);
	dbus_message_unref (message);

	if (!call) {
		g_set_error (error,
		             TRACKER_DBUS_ERROR,
		             TRACKER_DBUS_ERROR_UNSUPPORTED,
		             "FD passing unsupported or connection disconnected");
		return FALSE;
	}

	unix_input_stream = g_unix_input_stream_new (fd, TRUE);
	buffered_input_stream = g_buffered_input_stream_new_sized (unix_input_stream,
	                                                           TRACKER_DBUS_PIPE_BUFFER_SIZE);
	output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);

	g_output_stream_splice (output_stream,
	                        buffered_input_stream,
	                        G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
	                        G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
	                        cancellable,
	                        &inner_error);

	if (G_LIKELY (!inner_error)) {
		/* Wait for any current d-bus call to finish */
		dbus_pending_call_block (call);

		/* Check we didn't get an error */
		reply = dbus_pending_call_steal_reply (call);

		if (G_UNLIKELY (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)) {
			DBusError dbus_error;

			dbus_error_init (&dbus_error);
			dbus_set_error_from_message (&dbus_error, reply);
			dbus_set_g_error (error, &dbus_error);
			dbus_error_free (&dbus_error);

			/* If any error happened, we're not passing any received data, so we
			 * need to free it */
			g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream)));
		} else {
			*dest_buffer = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream));

			if (dest_buffer_size) {
				*dest_buffer_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (output_stream));
			}

			if (variable_names) {
				*variable_names = dbus_send_and_splice_get_variable_names (reply, TRUE);
			}

			ret_value = TRUE;
		}
	} else {
		g_set_error (error,
		             TRACKER_DBUS_ERROR,
		             TRACKER_DBUS_ERROR_BROKEN_PIPE,
		             "Couldn't get results from server");
		g_error_free (inner_error);
		/* If any error happened, we're not passing any received data, so we
		 * need to free it */
		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream)));
	}

	g_object_unref (output_stream);
	g_object_unref (buffered_input_stream);
	g_object_unref (unix_input_stream);

	if (reply) {
		dbus_message_unref (reply);
	}

	dbus_pending_call_unref (call);

	return ret_value;
}

static SendAndSpliceData *
send_and_splice_data_new (GInputStream                     *unix_input_stream,
                          GInputStream                     *buffered_input_stream,
                          GOutputStream                    *output_stream,
                          GCancellable                     *cancellable,
                          TrackerDBusSendAndSpliceCallback  callback,
                          gpointer                          user_data)
{
	SendAndSpliceData *data;

	data = g_slice_new0 (SendAndSpliceData);
	data->unix_input_stream = unix_input_stream;
	data->buffered_input_stream = buffered_input_stream;
	data->output_stream = output_stream;
	if (cancellable) {
		data->cancellable = g_object_ref (cancellable);
	}
	data->callback = callback;
	data->user_data = user_data;

	return data;
}

static void
send_and_splice_data_free (SendAndSpliceData *data)
{
	g_object_unref (data->unix_input_stream);
	g_object_unref (data->buffered_input_stream);
	g_object_unref (data->output_stream);
	if (data->cancellable) {
		g_object_unref (data->cancellable);
	}
	if (data->reply) {
		g_object_unref (data->reply);
	}
	g_slice_free (SendAndSpliceData, data);
}

static void
send_and_splice_async_callback (GObject      *source,
                                GAsyncResult *result,
                                gpointer      user_data)
{
	GError *error = NULL;

	g_output_stream_splice_finish (G_OUTPUT_STREAM (source), result, &error);

	if (error) {
		g_critical ("Error while splicing: %s",
		            error ? error->message : "Error not specified");
		g_error_free (error);
	}
}

static void
tracker_dbus_send_and_splice_async_finish (GObject      *source,
                                           GAsyncResult *result,
                                           gpointer      user_data)
{
	SendAndSpliceData *data = user_data;
	GError *error = NULL;

	data->reply = g_dbus_connection_send_message_with_reply_finish (G_DBUS_CONNECTION (source),
	                                                                result, &error);

	if (!error) {
		/* dbus_pending_call_block (data->call);
		   reply = dbus_pending_call_steal_reply (data->call); */

		if (g_dbus_message_get_message_type (data->reply) == G_DBUS_MESSAGE_TYPE_ERROR) {

			/* If any error happened, we're not passing any received data, so we
			 * need to free it */
			g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));

			(* data->callback) (NULL, -1, NULL, error, data->user_data);

			/* Note: GError should be freed by callback. We do this to be aligned
			 * with the behavior of dbus-glib, where if an error happens, the
			 * GError passed to the callback is supposed to be disposed by the
			 * callback itself. */
		} else {
			GStrv v_names = NULL;

			/* dbus_pending_call_cancel (data->call); */

			(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
			                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
			                    v_names,
			                    NULL,
			                    data->user_data);

			/* Don't use g_strfreev here, see above */
			g_free (v_names);
		}
	} else {
		/* If any error happened, we're not passing any received data, so we
		 * need to free it */
		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));

		(* data->callback) (NULL, -1, NULL, error, data->user_data);

		/* Note: GError should be freed by callback. We do this to be aligned
		 * with the behavior of dbus-glib, where if an error happens, the
		 * GError passed to the callback is supposed to be disposed by the
		 * callback itself. */
	}

	send_and_splice_data_free (data);
}

static void
tracker_g_async_ready_callback (GObject      *source_object,
                                GAsyncResult *res,
                                gpointer      user_data)
{
	g_simple_async_result_set_op_res_gpointer (user_data, g_object_ref (res), g_object_unref);
	g_simple_async_result_complete (user_data);
	g_object_unref (user_data);
}

gboolean
tracker_dbus_send_and_splice_async (GDBusConnection                  *connection,
                                    GDBusMessage                     *message,
                                    int                               fd,
                                    GCancellable                     *cancellable,
                                    TrackerDBusSendAndSpliceCallback  callback,
                                    gpointer                          user_data)
{
	SendAndSpliceData *data;
	GInputStream *unix_input_stream;
	GInputStream *buffered_input_stream;
	GOutputStream *output_stream;

	g_return_val_if_fail (connection != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	g_return_val_if_fail (fd > 0, FALSE);
	g_return_val_if_fail (callback != NULL, FALSE);

	unix_input_stream = g_unix_input_stream_new (fd, TRUE);
	buffered_input_stream = g_buffered_input_stream_new_sized (unix_input_stream,
	                                                           TRACKER_DBUS_PIPE_BUFFER_SIZE);
	output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);

	data = send_and_splice_data_new (unix_input_stream,
	                                 buffered_input_stream,
	                                 output_stream,
	                                 cancellable,
	                                 callback,
	                                 user_data);

	g_dbus_connection_send_message_with_reply (connection,
	                                           message,
	                                           G_DBUS_SEND_MESSAGE_FLAGS_NONE,
	                                           -1,
	                                           NULL,
	                                           cancellable,
	                                           tracker_g_async_ready_callback,
	                                           g_simple_async_result_new (G_OBJECT (connection),
	                                                                      tracker_dbus_send_and_splice_async_finish,
	                                                                      user_data, NULL));

	g_output_stream_splice_async (data->output_stream,
	                              data->buffered_input_stream,
	                              G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
	                              G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
	                              0,
	                              data->cancellable,
	                              send_and_splice_async_callback,
	                              data);

	return TRUE;
}