aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tp-file.c
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2009-05-19 22:17:22 +0800
committerCosimo Cecchi <cosimo.cecchi@collabora.co.uk>2009-06-07 21:20:08 +0800
commit62197f1d3c75224c2138ebda5dbc420bc166e3a6 (patch)
tree426f7e6aeeed59daf636ca8d4a7169406fcc6d9e /libempathy/empathy-tp-file.c
parent396aff97047f039c5bca8f3a0da13b9b295e657b (diff)
downloadgsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar.gz
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar.bz2
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar.lz
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar.xz
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.tar.zst
gsoc2013-empathy-62197f1d3c75224c2138ebda5dbc420bc166e3a6.zip
Look at the available socket type
Look at the available socket types, and don't hardcode UNIX/LOCALHOST values.
Diffstat (limited to 'libempathy/empathy-tp-file.c')
-rw-r--r--libempathy/empathy-tp-file.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index 3a5826868..c265e29f0 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -36,6 +36,7 @@
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
+#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/proxy-subclass.h>
#include <telepathy-glib/util.h>
@@ -71,6 +72,8 @@ typedef struct {
/* org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties */
TpFileTransferState state;
TpFileTransferStateChangeReason state_change_reason;
+ TpSocketAddressType socket_address_type;
+ TpSocketAccessControl socket_access_control;
/* transfer properties */
gboolean incoming;
@@ -123,6 +126,71 @@ tp_file_get_state_cb (TpProxy *proxy,
priv->state = g_value_get_uint (value);
}
+static gint
+uint_compare (gconstpointer a, gconstpointer b)
+{
+ const guint *uinta = a;
+ const guint *uintb = b;
+
+ if (*uinta == *uintb)
+ return 0;
+
+ return (*uinta > *uintb) ? 1 : -1;
+}
+
+static void
+tp_file_get_available_socket_types_cb (TpProxy *proxy,
+ const GValue *value,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
+ GHashTable *socket_types;
+ GArray *access_controls;
+
+ if (error != NULL ||
+ !G_VALUE_HOLDS (value, TP_HASH_TYPE_SUPPORTED_SOCKET_MAP))
+ {
+ /* set a default value */
+ priv->socket_address_type = TP_SOCKET_ADDRESS_TYPE_UNIX;
+ priv->socket_access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
+ goto out;
+ }
+
+ socket_types = g_value_get_boxed (value);
+
+ /* here UNIX is preferred to IPV4 */
+ if ((access_controls = g_hash_table_lookup (socket_types,
+ GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX))) != NULL)
+ {
+ priv->socket_address_type = TP_SOCKET_ADDRESS_TYPE_UNIX;
+ priv->socket_access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
+ goto out;
+ }
+
+ if ((access_controls = g_hash_table_lookup (socket_types,
+ GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_IPV4))) != NULL)
+ {
+ priv->socket_address_type = TP_SOCKET_ADDRESS_TYPE_IPV4;
+ g_array_sort (access_controls, uint_compare);
+
+ /* here port is preferred over localhost */
+ if ((g_array_index (access_controls, guint, 0) ==
+ TP_SOCKET_ACCESS_CONTROL_LOCALHOST) &&
+ (g_array_index (access_controls, guint, 1) ==
+ TP_SOCKET_ACCESS_CONTROL_PORT))
+ priv->socket_access_control = TP_SOCKET_ACCESS_CONTROL_PORT;
+ else
+ priv->socket_access_control =
+ g_array_index (access_controls, guint, 0);
+ }
+
+out:
+ DEBUG ("Socket address type: %d, access control %d",
+ priv->socket_address_type, priv->socket_access_control);
+}
+
static void
tp_file_invalidated_cb (TpProxy *proxy,
guint domain,
@@ -667,6 +735,10 @@ do_constructed (GObject *object)
-1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", tp_file_get_state_cb,
NULL, NULL, object);
+ tp_cli_dbus_properties_call_get (priv->channel,
+ -1, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "AvailableSocketTypes",
+ tp_file_get_available_socket_types_cb, NULL, NULL, file_obj);
+
priv->state_change_reason =
TP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE;
}