X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=libempathy%2Fempathy-tube-handler.c;h=43e19fde7207dbe2d31efc45e89c9634e8948f63;hp=4fb82177da5bae4c77c8971ea668b5a1a48c4faf;hb=c8d23985b7754541cab512992294c19f5c87cfaa;hpb=2d374c38c8d57fb0d2d3a55f2004d6e6d08d12e7 diff --git a/libempathy/empathy-tube-handler.c b/libempathy/empathy-tube-handler.c index 4fb82177..43e19fde 100644 --- a/libempathy/empathy-tube-handler.c +++ b/libempathy/empathy-tube-handler.c @@ -59,15 +59,38 @@ typedef struct gchar *channel; guint handle_type; guint handle; + EmpathyTpTube *tube; } IdleData; +static void +tube_ready_cb (EmpathyTpTube *tube, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + IdleData *idle_data = user_data; + + g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, tube); +} + +static void +tube_ready_destroy_notify (gpointer data) +{ + IdleData *idle_data = data; + + g_object_unref (idle_data->tube); + g_free (idle_data->bus_name); + g_free (idle_data->connection); + g_free (idle_data->channel); + g_slice_free (IdleData, idle_data); +} + static gboolean tube_handler_handle_tube_idle_cb (gpointer data) { IdleData *idle_data = data; TpConnection *connection; TpChannel *channel; - EmpathyTpTube *tube; static TpDBusDaemon *daemon = NULL; DEBUG ("New tube to be handled"); @@ -82,16 +105,12 @@ tube_handler_handle_tube_idle_cb (gpointer data) idle_data->handle, NULL); tp_channel_run_until_ready (channel, NULL, NULL); - tube = empathy_tp_tube_new (channel); - g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, tube); + idle_data->tube = empathy_tp_tube_new (channel); + empathy_tp_tube_call_when_ready (idle_data->tube, tube_ready_cb, idle_data, + tube_ready_destroy_notify, NULL); - g_object_unref (tube); g_object_unref (channel); g_object_unref (connection); - g_free (idle_data->bus_name); - g_free (idle_data->connection); - g_free (idle_data->channel); - g_slice_free (IdleData, idle_data); return FALSE; } @@ -185,12 +204,31 @@ OUT: return thandler; } +static gchar * +sanitize_service_name (const gchar *str) +{ + guint i; + gchar *result; + + g_assert (str != NULL); + result = g_strdup (str); + + for (i = 0; result[i] != '\0'; i++) + { + if (!g_ascii_isalnum (result[i])) + result[i] = '_'; + } + + return result; +} + gchar * empathy_tube_handler_build_bus_name (TpTubeType type, const gchar *service) { gchar *str = NULL; const gchar *prefix = NULL; + gchar *service_escaped; g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL); g_return_val_if_fail (service != NULL, NULL); @@ -202,7 +240,9 @@ empathy_tube_handler_build_bus_name (TpTubeType type, else g_return_val_if_reached (NULL); - str = g_strconcat (prefix, service, NULL); + service_escaped = sanitize_service_name (service); + str = g_strconcat (prefix, service_escaped, NULL); + g_free (service_escaped); return str; }