[Telepathy-commits] [telepathy-salut/master] Implement new draft of the spec
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Nov 21 03:46:48 PST 2008
---
src/salut-file-transfer-channel.c | 102 +++++++++++++++++------------
src/salut-file-transfer-channel.h | 3 +
src/salut-ft-manager.c | 8 ++-
tests/twisted/avahi/test-receive-file.py | 12 ++--
tests/twisted/avahi/test-send-file.py | 24 +++-----
5 files changed, 83 insertions(+), 66 deletions(-)
diff --git a/src/salut-file-transfer-channel.c b/src/salut-file-transfer-channel.c
index b7e3d8a..f16872c 100644
--- a/src/salut-file-transfer-channel.c
+++ b/src/salut-file-transfer-channel.c
@@ -1049,6 +1049,46 @@ check_address_and_access_control (SalutFileTransferChannel *self,
return FALSE;
}
+gboolean
+salut_file_transfer_channel_offer_file (SalutFileTransferChannel *self,
+ GError **error)
+{
+ SalutXmppConnectionManagerRequestConnectionResult request_result;
+ GibberXmppConnection *connection = NULL;
+
+ g_assert (!CHECK_STR_EMPTY (self->priv->filename));
+ g_assert (self->priv->size != SALUT_UNDEFINED_FILE_SIZE);
+
+ DEBUG ("Offering file transfer");
+
+ request_result = salut_xmpp_connection_manager_request_connection (
+ self->priv->xmpp_connection_manager, self->priv->contact,
+ &connection, error);
+
+ if (request_result ==
+ SALUT_XMPP_CONNECTION_MANAGER_REQUEST_CONNECTION_RESULT_DONE)
+ {
+ self->priv->xmpp_connection = connection;
+ send_file_offer (self);
+ }
+ else if (request_result ==
+ SALUT_XMPP_CONNECTION_MANAGER_REQUEST_CONNECTION_RESULT_PENDING)
+ {
+ g_signal_connect (self->priv->xmpp_connection_manager,
+ "new-connection",
+ G_CALLBACK (xmpp_connection_manager_new_connection_cb), self);
+ }
+ else
+ {
+ DEBUG ("Request connection failed");
+ g_set_error (error, TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+ "Request connection failed");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/**
* salut_file_transfer_channel_accept_file
*
@@ -1075,10 +1115,10 @@ salut_file_transfer_channel_accept_file (SalutSvcChannelTypeFileTransfer *iface,
g_error_free (error);
}
- if (self->priv->state != SALUT_FILE_TRANSFER_STATE_LOCAL_PENDING)
+ if (self->priv->state != SALUT_FILE_TRANSFER_STATE_PENDING)
{
g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
- "State is not local pending; cannot accept file");
+ "State is not pending; cannot accept file");
dbus_g_method_return_error (context, error);
return;
}
@@ -1122,69 +1162,45 @@ salut_file_transfer_channel_accept_file (SalutSvcChannelTypeFileTransfer *iface,
}
/**
- * salut_file_transfer_channel_offer_file
+ * salut_file_transfer_channel_provide_file
*
- * Implements D-Bus method OfferFile
+ * Implements D-Bus method ProvideFile
* on interface org.freedesktop.Telepathy.Channel.Type.File
*/
static void
-salut_file_transfer_channel_offer_file (SalutSvcChannelTypeFileTransfer *iface,
+salut_file_transfer_channel_provide_file (SalutSvcChannelTypeFileTransfer *iface,
guint address_type,
guint access_control,
const GValue *access_control_param,
DBusGMethodInvocation *context)
{
SalutFileTransferChannel *self = SALUT_FILE_TRANSFER_CHANNEL (iface);
- GibberXmppConnection *connection = NULL;
- SalutXmppConnectionManagerRequestConnectionResult request_result;
- GError *error = NULL;
+ TpBaseConnection *base_conn = (TpBaseConnection *) self->priv->connection;
SalutFileTransferChannel *channel = SALUT_FILE_TRANSFER_CHANNEL (iface);
GValue out_address = { 0 };
+ GError *error = NULL;
- if (self->priv->state != SALUT_FILE_TRANSFER_STATE_NOT_OFFERED)
+ if (self->priv->initiator != base_conn->self_handle)
{
g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
- "State is not not offered; cannot offer file");
+ "Channel is not an outgoing transfer");
dbus_g_method_return_error (context, error);
return;
}
- if (!check_address_and_access_control (self, address_type, access_control,
- access_control_param, &error))
+ if (self->priv->socket_path != NULL)
{
+ g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "ProvideFile has already been called for this channel");
dbus_g_method_return_error (context, error);
- g_error_free (error);
return;
}
- g_assert (!CHECK_STR_EMPTY (channel->priv->filename));
- g_assert (channel->priv->size != SALUT_UNDEFINED_FILE_SIZE);
-
- DEBUG ("Offering file transfer");
-
- request_result = salut_xmpp_connection_manager_request_connection (
- channel->priv->xmpp_connection_manager, channel->priv->contact,
- &connection, &error);
-
- if (request_result ==
- SALUT_XMPP_CONNECTION_MANAGER_REQUEST_CONNECTION_RESULT_DONE)
- {
- channel->priv->xmpp_connection = connection;
- send_file_offer (channel);
- }
- else if (request_result ==
- SALUT_XMPP_CONNECTION_MANAGER_REQUEST_CONNECTION_RESULT_PENDING)
- {
- g_signal_connect (channel->priv->xmpp_connection_manager,
- "new-connection",
- G_CALLBACK (xmpp_connection_manager_new_connection_cb), channel);
- }
- else
+ if (!check_address_and_access_control (self, address_type, access_control,
+ access_control_param, &error))
{
- DEBUG ("Request connection failed");
- g_set_error (&error, TP_ERRORS, TP_ERROR_NETWORK_ERROR,
- "Request connection failed");
dbus_g_method_return_error (context, error);
+ g_error_free (error);
return;
}
@@ -1200,10 +1216,10 @@ salut_file_transfer_channel_offer_file (SalutSvcChannelTypeFileTransfer *iface,
g_value_set_string (&out_address, channel->priv->socket_path);
salut_file_transfer_channel_set_state (iface,
- SALUT_FILE_TRANSFER_STATE_REMOTE_PENDING,
+ SALUT_FILE_TRANSFER_STATE_PENDING,
SALUT_FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED);
- salut_svc_channel_type_file_transfer_return_from_offer_file (context,
+ salut_svc_channel_type_file_transfer_return_from_provide_file (context,
&out_address);
}
@@ -1217,7 +1233,7 @@ file_transfer_iface_init (gpointer g_iface,
#define IMPLEMENT(x) salut_svc_channel_type_file_transfer_implement_##x (\
klass, salut_file_transfer_channel_##x)
IMPLEMENT (accept_file);
- IMPLEMENT (offer_file);
+ IMPLEMENT (provide_file);
#undef IMPLEMENT
}
@@ -1264,6 +1280,8 @@ get_socket_channel (SalutFileTransferChannel *self)
path = get_local_unix_socket_path (self);
+ /* FIXME: should use the socket type and access control chosen by
+ * the user. */
fd = socket (PF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
{
diff --git a/src/salut-file-transfer-channel.h b/src/salut-file-transfer-channel.h
index a073364..d27ef8c 100644
--- a/src/salut-file-transfer-channel.h
+++ b/src/salut-file-transfer-channel.h
@@ -69,6 +69,9 @@ gboolean salut_file_transfer_channel_received_file_offer (
SalutFileTransferChannel *self, GibberXmppStanza *stanza,
GibberXmppConnection *conn);
+gboolean salut_file_transfer_channel_offer_file (SalutFileTransferChannel *self,
+ GError **error);
+
G_END_DECLS
#endif /* #ifndef __SALUT_FILE_TRANSFER_CHANNEL_H__*/
diff --git a/src/salut-ft-manager.c b/src/salut-ft-manager.c
index a37680a..99b5896 100644
--- a/src/salut-ft-manager.c
+++ b/src/salut-ft-manager.c
@@ -274,16 +274,15 @@ salut_ft_manager_new_channel (SalutFtManager *mgr,
DEBUG ("%s channel requested", requested ? "Outgoing" : "Incoming");
+ state = SALUT_FILE_TRANSFER_STATE_PENDING;
if (!requested)
{
/* incoming channel */
- state = SALUT_FILE_TRANSFER_STATE_LOCAL_PENDING;
initiator = handle;
}
else
{
/* outgoing channel */
- state = SALUT_FILE_TRANSFER_STATE_NOT_OFFERED;
initiator = base_connection->self_handle;
}
@@ -438,6 +437,11 @@ salut_ft_manager_handle_request (TpChannelManager *manager,
"initial-offset", initial_offset,
NULL);
+ if (!salut_file_transfer_channel_offer_file (chan, &error))
+ {
+ /* FIXME */
+ }
+
requests = g_slist_prepend (requests, request_token);
tp_channel_manager_emit_new_channel (manager, TP_EXPORTABLE_CHANNEL (chan),
requests);
diff --git a/tests/twisted/avahi/test-receive-file.py b/tests/twisted/avahi/test-receive-file.py
index f2e75c5..0eff1b7 100644
--- a/tests/twisted/avahi/test-receive-file.py
+++ b/tests/twisted/avahi/test-receive-file.py
@@ -26,13 +26,11 @@ HT_CONTACT_LIST = 3
TEXT_MESSAGE_TYPE_NORMAL = dbus.UInt32(0)
FT_STATE_NONE = 0
-FT_STATE_NOT_OFFERED = 1
+FT_STATE_PENDING = 1
FT_STATE_ACCEPTED = 2
-FT_STATE_LOCAL_PENDING = 3
-FT_STATE_REMOTE_PENDING = 4
-FT_STATE_OPEN = 5
-FT_STATE_COMPLETED = 6
-FT_STATE_CANCELLED = 7
+FT_STATE_OPEN = 3
+FT_STATE_COMPLETED = 4
+FT_STATE_CANCELLED = 5
FT_STATE_CHANGE_REASON_NONE = 0
FT_STATE_CHANGE_REASON_REQUESTED = 1
@@ -136,7 +134,7 @@ def test(q, bus, conn):
assert props[CHANNEL_INTERFACE + '.InitiatorID'] == contact_name
# org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties
- assert props[CHANNEL_TYPE_FILE_TRANSFER + '.State'] == FT_STATE_LOCAL_PENDING
+ assert props[CHANNEL_TYPE_FILE_TRANSFER + '.State'] == FT_STATE_PENDING
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.ContentType'] == FILE_CONTENT_TYPE
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.Filename'] == FILE_NAME
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.Size'] == FILE_SIZE
diff --git a/tests/twisted/avahi/test-send-file.py b/tests/twisted/avahi/test-send-file.py
index 2a0d68b..e022e82 100644
--- a/tests/twisted/avahi/test-send-file.py
+++ b/tests/twisted/avahi/test-send-file.py
@@ -24,13 +24,11 @@ HT_CONTACT_LIST = 3
TEXT_MESSAGE_TYPE_NORMAL = dbus.UInt32(0)
FT_STATE_NONE = 0
-FT_STATE_NOT_OFFERED = 1
+FT_STATE_PENDING = 1
FT_STATE_ACCEPTED = 2
-FT_STATE_LOCAL_PENDING = 3
-FT_STATE_REMOTE_PENDING = 4
-FT_STATE_OPEN = 5
-FT_STATE_COMPLETED = 6
-FT_STATE_CANCELLED = 7
+FT_STATE_OPEN = 3
+FT_STATE_COMPLETED = 4
+FT_STATE_CANCELLED = 5
FT_STATE_CHANGE_REASON_NONE = 0
FT_STATE_CHANGE_REASON_REQUESTED = 1
@@ -127,7 +125,7 @@ def test(q, bus, conn):
assert props[CHANNEL_INTERFACE + '.InitiatorID'] == self_handle_name
# org.freedesktop.Telepathy.Channel.Type.FileTransfer D-Bus properties
- assert props[CHANNEL_TYPE_FILE_TRANSFER + '.State'] == FT_STATE_NOT_OFFERED
+ assert props[CHANNEL_TYPE_FILE_TRANSFER + '.State'] == FT_STATE_PENDING
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.ContentType'] == FILE_CONTENT_TYPE
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.Filename'] == FILE_NAME
assert props[CHANNEL_TYPE_FILE_TRANSFER + '.Size'] == FILE_SIZE
@@ -144,19 +142,12 @@ def test(q, bus, conn):
ft_channel = make_channel_proxy(conn, path, 'Channel.Type.FileTransfer.DRAFT')
ft_props = dbus.Interface(bus.get_object(conn.object.bus_name, path), PROPERTIES_IFACE)
- address = ft_channel.OfferFile(SOCKET_ADDRESS_TYPE_UNIX, SOCKET_ACCESS_CONTROL_LOCALHOST, "")
-
- conn_event, state_event, iq_event = q.expect_many(
+ conn_event, iq_event = q.expect_many(
EventPattern('incoming-connection', listener = listener),
- EventPattern('dbus-signal', signal='FileTransferStateChanged'),
EventPattern('stream-iq'))
incoming = conn_event.connection
- state, reason = state_event.args
- assert state == FT_STATE_REMOTE_PENDING
- assert reason == FT_STATE_CHANGE_REASON_REQUESTED
-
assert iq_event.iq_type == 'set'
assert iq_event.connection == incoming
iq = iq_event.stanza
@@ -173,6 +164,7 @@ def test(q, bus, conn):
desc = desc_node.children[0]
assert desc == FILE_DESCRIPTION
+ # Accept transfer
reply = domish.Element(('', 'iq'))
reply['to'] = iq['from']
reply['from'] = iq['to']
@@ -185,6 +177,8 @@ def test(q, bus, conn):
http = httplib.HTTPConnection(host)
http.request('GET', file)
+ address = ft_channel.ProvideFile(SOCKET_ADDRESS_TYPE_UNIX, SOCKET_ACCESS_CONTROL_LOCALHOST, "")
+
e = q.expect('dbus-signal', signal='FileTransferStateChanged')
state, reason = e.args
assert state == FT_STATE_OPEN
--
1.5.6.5
More information about the Telepathy-commits
mailing list