diff options
author | Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> | 2009-06-07 21:10:23 +0800 |
---|---|---|
committer | Cosimo Cecchi <cosimo.cecchi@collabora.co.uk> | 2009-06-07 21:20:09 +0800 |
commit | d0c304bac08a910c048bee84338a97d55a5d0811 (patch) | |
tree | a07336efffc6b0069d31a7f6d9a6e9204ff00b85 | |
parent | f0d5544426b06662365a3b99e05eae23e76b6ee6 (diff) | |
download | gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar.gz gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar.bz2 gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar.lz gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar.xz gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.tar.zst gsoc2013-empathy-d0c304bac08a910c048bee84338a97d55a5d0811.zip |
Emit an error for socket types we don't handle
Also, fix error handling when a socket fails on connect().
-rw-r--r-- | libempathy/empathy-tp-file.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c index a056699f8..998de5e51 100644 --- a/libempathy/empathy-tp-file.c +++ b/libempathy/empathy-tp-file.c @@ -266,13 +266,30 @@ tp_file_start_transfer (EmpathyTpFile *tp_file) { gint fd, domain, res = 0; GError *error = NULL; + struct sockaddr *my_addr = NULL; + size_t my_size = 0; EmpathyTpFilePriv *priv = GET_PRIV (tp_file); if (priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_UNIX) - domain = AF_UNIX; + { + domain = AF_UNIX; + } + else if (priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_IPV4) + { + domain = AF_INET; + } + else + { + error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK, + EMPATHY_FT_ERROR_NOT_SUPPORTED, _("Socket type not supported")); - if (priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_IPV4) - domain = AF_INET; + DEBUG ("Socket not supported, closing channel"); + + ft_operation_close_with_error (tp_file, error); + g_clear_error (&error); + + return; + } fd = socket (domain, SOCK_STREAM, 0); @@ -300,7 +317,8 @@ tp_file_start_transfer (EmpathyTpFile *tp_file) strncpy (addr.sun_path, priv->socket_address->data, priv->socket_address->len); - res = connect (fd, (struct sockaddr*) &addr, sizeof (addr)); + my_addr = (struct sockaddr *) &addr; + my_size = sizeof (addr); } else if (priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_IPV4) { @@ -311,9 +329,12 @@ tp_file_start_transfer (EmpathyTpFile *tp_file) inet_pton (AF_INET, priv->socket_address->data, &addr.sin_addr); addr.sin_port = htons (priv->port); - res = connect (fd, (struct sockaddr*) &addr, sizeof (addr)); + my_addr = (struct sockaddr *) &addr; + my_size = sizeof (addr); } + res = connect (fd, my_addr, my_size); + if (res < 0) { int code = errno; |