#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <netinet/in.h>
#include <glib/gi18n-lib.h>
#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/proxy-subclass.h>
#include <telepathy-glib/util.h>
+#include <telepathy-glib/interfaces.h>
#include "empathy-tp-file.h"
#include "empathy-marshal.h"
typedef struct {
TpChannel *channel;
- gboolean ready;
GInputStream *in_stream;
GOutputStream *out_stream;
EmpathyTpFileOperationCallback op_callback;
gpointer op_user_data;
+ gboolean is_closing;
gboolean is_closed;
gboolean dispose_run;
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,
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);
+
+ /* TODO: we should prefer PORT over LOCALHOST when the CM will
+ * support it.
+ */
+
+ priv->socket_access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
}
out:
DEBUG ("Socket address type: %u, access control %u",
- priv->socket_address_type, priv->socket_access_control);
+ priv->socket_address_type, priv->socket_access_control);
}
static void
gpointer user_data)
{
EmpathyTpFile *tp_file;
+ EmpathyTpFilePriv *priv;
GError *error = NULL;
tp_file = user_data;
+ priv = GET_PRIV (tp_file);
g_output_stream_splice_finish (G_OUTPUT_STREAM (source), res, &error);
DEBUG ("Splice stream ready cb, error %p", error);
- if (error != NULL)
+ if (error != NULL && !priv->is_closing)
{
ft_operation_close_with_error (tp_file, error);
g_clear_error (&error);
{
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);
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)
{
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;
* report the method error.
*/
g_clear_error (&myerr);
- myerr = g_error_copy (error);
}
+
+ myerr = g_error_copy (error);
}
if (myerr != NULL)
{
- DEBUG ("Error: %s", error->message);
+ DEBUG ("Error: %s", myerr->message);
ft_operation_close_with_error (tp_file, myerr);
g_clear_error (&myerr);
return;
initialize_empty_ac_variant (TpSocketAccessControl ac,
GValue *val)
{
+ /* TODO: we will add more types here once we support PORT access control. */
if (ac == TP_SOCKET_ACCESS_CONTROL_LOCALHOST)
{
g_value_init (val, G_TYPE_STRING);
g_value_set_static_string (val, "");
}
- else if (ac == TP_SOCKET_ACCESS_CONTROL_PORT)
- {
- g_value_init (val, TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4);
- }
}
static void
in_stream = g_file_read_finish (G_FILE (source), res, &error);
- if (error != NULL)
+ if (error != NULL && !priv->is_closing)
{
ft_operation_close_with_error (tp_file, error);
g_clear_error (&error);
DEBUG ("Closing channel, should cancel %s", cancel ?
"True" : "False");
+ priv->is_closing = TRUE;
+
tp_cli_channel_call_close (priv->channel, -1,
channel_closed_cb, GINT_TO_POINTER (cancel), NULL, G_OBJECT (tp_file));
}
case PROP_CHANNEL:
priv->channel = g_object_ref (g_value_get_object (value));
break;
- case PROP_INCOMING:
- priv->incoming = g_value_get_boolean (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
g_signal_connect (priv->channel, "invalidated",
G_CALLBACK (tp_file_invalidated_cb), tp_file);
+ priv->incoming = !tp_channel_get_requested (priv->channel);
+
tp_cli_channel_type_file_transfer_connect_to_file_transfer_state_changed (
priv->channel, tp_file_state_changed_cb, NULL, NULL, object, NULL);
"direction of transfer",
"The direction of the file being transferred",
FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READABLE));
g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));
}
* @channel: a #TpChannel
* @incoming: whether the file transfer is incoming or not
*
- * Creates a new #EmpathyTpFile wrapping @channel, with the direction
- * specified by @incoming. The returned #EmpathyTpFile should be unrefed
+ * Creates a new #EmpathyTpFile wrapping @channel.
+ * The returned #EmpathyTpFile should be unrefed
* with g_object_unref() when finished with.
*
* Return value: a new #EmpathyTpFile
*/
EmpathyTpFile *
-empathy_tp_file_new (TpChannel *channel,
- gboolean incoming)
+empathy_tp_file_new (TpChannel *channel)
{
EmpathyTpFile *tp_file;
g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
tp_file = g_object_new (EMPATHY_TYPE_TP_FILE,
- "channel", channel, "incoming", incoming,
+ "channel", channel,
NULL);
return tp_file;