diff options
Diffstat (limited to 'libempathy/empathy-ft-handler.c')
-rw-r--r-- | libempathy/empathy-ft-handler.c | 146 |
1 files changed, 79 insertions, 67 deletions
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index f18278a71..9b77abffd 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -773,46 +773,26 @@ static void ft_handler_populate_outgoing_request (EmpathyFTHandler *handler) { guint contact_handle; - GHashTable *request; - GValue *value; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); - request = priv->request = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, (GDestroyNotify) tp_g_value_slice_free); - contact_handle = empathy_contact_get_handle (priv->contact); - /* org.freedesktop.Telepathy.Channel.ChannelType */ - value = tp_g_value_slice_new_string (TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER); - g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value); - - /* org.freedesktop.Telepathy.Channel.TargetHandleType */ - value = tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT); - g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value); - - /* org.freedesktop.Telepathy.Channel.TargetHandle */ - value = tp_g_value_slice_new_uint (contact_handle); - g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentType */ - value = tp_g_value_slice_new_string (priv->content_type); - g_hash_table_insert (request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentType", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Filename */ - value = tp_g_value_slice_new_string (priv->filename); - g_hash_table_insert (request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Filename", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Size */ - value = tp_g_value_slice_new_uint64 (priv->total_bytes); - g_hash_table_insert (request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size", value); - - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.Date */ - value = tp_g_value_slice_new_uint64 ((guint64) priv->mtime); - g_hash_table_insert (request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date", value); + priv->request = tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, + TP_HANDLE_TYPE_CONTACT, + TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT, + contact_handle, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING, + priv->content_type, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING, + priv->filename, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64, + priv->total_bytes, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE, G_TYPE_UINT64, + priv->mtime, + NULL); } static gboolean @@ -822,7 +802,6 @@ hash_job_done (gpointer user_data) EmpathyFTHandler *handler = hash_data->handler; EmpathyFTHandlerPriv *priv; GError *error = NULL; - GValue *value; DEBUG ("Closing stream after hashing."); @@ -864,10 +843,9 @@ hash_job_done (gpointer user_data) /* set the checksum in the request... * org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash */ - value = tp_g_value_slice_new_string - (g_checksum_get_string (hash_data->checksum)); - g_hash_table_insert (priv->request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHash", value); + tp_asv_set_string (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH, + g_checksum_get_string (hash_data->checksum)); } cleanup: @@ -987,7 +965,6 @@ ft_handler_read_async_cb (GObject *source, GFileInputStream *stream; GError *error = NULL; HashingData *hash_data; - GValue *value; EmpathyFTHandler *handler = user_data; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); @@ -1009,10 +986,9 @@ ft_handler_read_async_cb (GObject *source, /* FIXME: MD5 is the only ContentHashType supported right now */ hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5); - /* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHashType */ - value = tp_g_value_slice_new_uint (TP_FILE_HASH_TYPE_MD5); - g_hash_table_insert (priv->request, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType", value); + tp_asv_set_uint32 (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE, + TP_FILE_HASH_TYPE_MD5); g_signal_emit (handler, signals[HASHING_STARTED], 0); @@ -1031,35 +1007,53 @@ callbacks_data_free (gpointer user_data) g_slice_free (CallbacksData, data); } -static void +static gboolean set_content_hash_type_from_classes (EmpathyFTHandler *handler, - GList *classes) + GPtrArray *classes) { - GValueArray *class; - GValue *v; - GList *l; GArray *possible_values; guint value; - GHashTable *fprops; gboolean valid; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); + gboolean support_ft = FALSE; + guint i; possible_values = g_array_new (TRUE, TRUE, sizeof (guint)); - for (l = classes; l != NULL; l = l->next) + for (i = 0; i < classes->len; i++) { - class = l->data; - v = g_value_array_get_nth (class, 0); - fprops = g_value_get_boxed (v); + GHashTable *fixed; + GStrv allowed; + const gchar *chan_type; + + tp_value_array_unpack (g_ptr_array_index (classes, i), 2, + &fixed, &allowed); + + chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE); + + if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) + continue; + + if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) != + TP_HANDLE_TYPE_CONTACT) + continue; + + support_ft = TRUE; value = tp_asv_get_uint32 - (fprops, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType", + (fixed, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE, &valid); if (valid) g_array_append_val (possible_values, value); } + if (!support_ft) + { + g_array_free (possible_values, TRUE); + return FALSE; + } + if (possible_values->len == 0) { /* there are no channel classes with hash support, disable it. */ @@ -1093,18 +1087,35 @@ out: DEBUG ("Hash enabled %s; setting content hash type as %u", priv->use_hash ? "True" : "False", priv->content_hash_type); + + return TRUE; } static void -find_ft_channel_classes_cb (GList *channel_classes, +conn_prepared_cb (GObject *conn, + GAsyncResult *result, gpointer user_data) { CallbacksData *data = user_data; EmpathyFTHandler *handler = data->handler; EmpathyFTHandlerPriv *priv = GET_PRIV (handler); GError *myerr = NULL; + TpCapabilities *caps; + GPtrArray *classes; - if (channel_classes == NULL) + if (!tp_proxy_prepare_finish (conn, result, &myerr)) + { + DEBUG ("Failed to prepare connection: %s", myerr->message); + + data->callback (handler, myerr, data->user_data); + goto out; + } + + caps = tp_connection_get_capabilities (TP_CONNECTION (conn)); + classes = tp_capabilities_get_channel_classes (caps); + + /* set whether we support hash and the type of it */ + if (!set_content_hash_type_from_classes (handler, classes)) { g_set_error_literal (&myerr, EMPATHY_FT_ERROR_QUARK, EMPATHY_FT_ERROR_NOT_SUPPORTED, @@ -1118,13 +1129,11 @@ find_ft_channel_classes_cb (GList *channel_classes, } else { - /* set whether we support hash and the type of it */ - set_content_hash_type_from_classes (handler, channel_classes); - /* get back to the caller now */ data->callback (handler, NULL, data->user_data); } +out: callbacks_data_free (data); } @@ -1202,11 +1211,14 @@ out: else { /* see if FT/hashing are allowed */ - empathy_dispatcher_find_requestable_channel_classes_async - (priv->dispatcher, empathy_contact_get_connection (priv->contact), - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT, - find_ft_channel_classes_cb, cb_data, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType", NULL); + TpConnection *connection; + GQuark features[] = { TP_CONNECTION_FEATURE_CAPABILITIES, 0 }; + + connection = empathy_contact_get_connection (priv->contact); + g_assert (connection != NULL); + + tp_proxy_prepare_async (connection, features, + conn_prepared_cb, cb_data); } } |