]> git.0d.be Git - empathy.git/commitdiff
Emit an error for socket types we don't handle
authorCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Sun, 7 Jun 2009 13:10:23 +0000 (15:10 +0200)
committerCosimo Cecchi <cosimo.cecchi@collabora.co.uk>
Sun, 7 Jun 2009 13:20:09 +0000 (15:20 +0200)
Also, fix error handling when a socket fails on connect().

libempathy/empathy-tp-file.c

index a056699f8a11e6be72027d8bace91beea39c7ee3..998de5e51fa6385713d0de032e0dae0986765588 100644 (file)
@@ -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;