From c12336006558fc5c6975c50529b3174d90d12308 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sat, 19 Apr 2008 21:04:18 +0000 Subject: [PATCH] Rename empathy_offer_ipv4_stream_tube() to empathy_tp_tube_new_ipv4_stream_tube() and return the new EmpathyTpTube object. svn path=/trunk/; revision=981 --- libempathy/empathy-tp-tube.c | 165 +++++++++++++++++++---------------- libempathy/empathy-tp-tube.h | 5 +- 2 files changed, 93 insertions(+), 77 deletions(-) diff --git a/libempathy/empathy-tp-tube.c b/libempathy/empathy-tp-tube.c index b789bf07..15356938 100644 --- a/libempathy/empathy-tp-tube.c +++ b/libempathy/empathy-tp-tube.c @@ -384,6 +384,97 @@ empathy_tp_tube_new (TpChannel *channel, guint tube_id) return tube; } +EmpathyTpTube * +empathy_tp_tube_new_ipv4_stream_tube (EmpathyContact *contact, + const gchar *hostname, + guint port, + const gchar *service) +{ + MissionControl *mc; + McAccount *account; + TpConnection *connection; + TpChannel *channel; + gchar *object_path; + guint id; + GHashTable *params; + GValue *address; + GValue *control_param; + EmpathyTpTube *tube; + GError *error = NULL; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + g_return_val_if_fail (hostname != NULL, NULL); + g_return_val_if_fail (service != NULL, NULL); + + mc = empathy_mission_control_new (); + account = empathy_contact_get_account (contact); + connection = mission_control_get_tpconnection (mc, account, NULL); + + if (!tp_cli_connection_run_request_channel (connection, -1, + TP_IFACE_CHANNEL_TYPE_TUBES, TP_HANDLE_TYPE_CONTACT, + empathy_contact_get_handle (contact), FALSE, &object_path, &error, NULL)) + { + g_clear_error (&error); + g_object_unref (mc); + g_object_unref (account); + g_object_unref (connection); + return NULL; + } + + empathy_debug (DEBUG_DOMAIN, "Offering a new stream tube"); + + channel = tp_channel_new (connection, object_path, + TP_IFACE_CHANNEL_TYPE_TUBES, TP_HANDLE_TYPE_CONTACT, + empathy_contact_get_handle (contact), NULL); + + params = g_hash_table_new (g_str_hash, g_str_equal); + address = g_new0 (GValue, 1); + g_value_init (address, + dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_UINT, + G_TYPE_INVALID)); + g_value_take_boxed (address, + dbus_g_type_specialized_construct (dbus_g_type_get_struct ("GValueArray", + G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))); + dbus_g_type_struct_set (address, 0, hostname, 1, port, G_MAXUINT); + + /* localhost access control, variant is ignored */ + control_param = g_new0 (GValue, 1); + g_value_init (control_param, G_TYPE_STRING); + + if (!tp_cli_channel_type_tubes_run_offer_stream_tube (channel, -1, + service, params, TP_SOCKET_ADDRESS_TYPE_IPV4, address, + TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, &id, &error, NULL)) + { + empathy_debug (DEBUG_DOMAIN, "Couldn't offer tube: %s", error->message); + g_clear_error (&error); + } + + empathy_debug (DEBUG_DOMAIN, "Stream tube id=%d offered", id); + + tube = g_object_new (EMPATHY_TYPE_TP_TUBE, + "channel", channel, + "id", id, + "initiator", empathy_contact_get_handle (contact), + "type", TP_SOCKET_ADDRESS_TYPE_IPV4, + "service", service, + "parameters", control_param, + "state", TP_TUBE_STATE_REMOTE_PENDING, + NULL); + + g_object_unref (channel); + g_free (object_path); + g_hash_table_destroy (params); + g_value_reset (address); + g_value_reset (control_param); + g_free (address); + g_free (control_param); + g_object_unref (mc); + g_object_unref (account); + g_object_unref (connection); + + return tube; +} + static void tp_tube_accept_stream_cb (TpChannel *proxy, const GValue *address, @@ -501,77 +592,3 @@ empathy_tp_tube_get_ipv4_socket (EmpathyTpTube *tube, g_free (address); } -void -empathy_offer_ipv4_stream_tube (EmpathyContact *contact, - const gchar *hostname, - guint port, - const gchar *service) -{ - MissionControl *mc; - McAccount *account; - TpConnection *connection; - TpChannel *channel; - gchar *object_path; - guint id; - GHashTable *params; - GValue *address; - GValue *control_param; - GError *error = NULL; - - mc = empathy_mission_control_new (); - account = empathy_contact_get_account (contact); - connection = mission_control_get_tpconnection (mc, account, NULL); - - if (!tp_cli_connection_run_request_channel (connection, -1, - TP_IFACE_CHANNEL_TYPE_TUBES, TP_HANDLE_TYPE_CONTACT, - empathy_contact_get_handle (contact), FALSE, &object_path, &error, NULL)) - { - g_clear_error (&error); - g_object_unref (mc); - g_object_unref (account); - g_object_unref (connection); - return; - } - - empathy_debug (DEBUG_DOMAIN, "Offering a new stream tube"); - - channel = tp_channel_new (connection, object_path, - TP_IFACE_CHANNEL_TYPE_TUBES, TP_HANDLE_TYPE_CONTACT, - empathy_contact_get_handle (contact), NULL); - - params = g_hash_table_new (g_str_hash, g_str_equal); - address = g_new0 (GValue, 1); - g_value_init (address, - dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_UINT, - G_TYPE_INVALID)); - g_value_take_boxed (address, - dbus_g_type_specialized_construct (dbus_g_type_get_struct ("GValueArray", - G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))); - dbus_g_type_struct_set (address, 0, hostname, 1, port, G_MAXUINT); - - /* localhost access control, variant is ignored */ - control_param = g_new0 (GValue, 1); - g_value_init (control_param, G_TYPE_STRING); - - if (!tp_cli_channel_type_tubes_run_offer_stream_tube (channel, -1, - service, params, TP_SOCKET_ADDRESS_TYPE_IPV4, address, - TP_SOCKET_ACCESS_CONTROL_LOCALHOST, control_param, &id, &error, NULL)) - { - empathy_debug (DEBUG_DOMAIN, "Couldn't offer tube: %s", error->message); - g_clear_error (&error); - } - - empathy_debug (DEBUG_DOMAIN, "Stream tube id=%d offered", id); - - g_object_unref (channel); - g_free (object_path); - g_hash_table_destroy (params); - g_value_reset (address); - g_value_reset (control_param); - g_free (address); - g_free (control_param); - g_object_unref (mc); - g_object_unref (account); - g_object_unref (connection); -} - diff --git a/libempathy/empathy-tp-tube.h b/libempathy/empathy-tp-tube.h index b4c009ba..72314d43 100644 --- a/libempathy/empathy-tp-tube.h +++ b/libempathy/empathy-tp-tube.h @@ -55,15 +55,14 @@ struct _EmpathyTpTubeClass { GType empathy_tp_tube_get_type (void) G_GNUC_CONST; EmpathyTpTube *empathy_tp_tube_new (TpChannel *channel, guint tube_id); +EmpathyTpTube *empathy_tp_tube_new_ipv4_stream_tube (EmpathyContact *contact, + const gchar *hostname, guint port, const gchar *service); void empathy_tp_tube_accept_ipv4_stream_tube (EmpathyTpTube *tube); void empathy_tp_tube_accept_unix_stream_tube (EmpathyTpTube *tube); void empathy_tp_tube_get_ipv4_socket (EmpathyTpTube *tube, gchar **hostname, guint *port); gchar * empathy_tp_tube_get_unix_socket (EmpathyTpTube *tube); -void empathy_offer_ipv4_stream_tube (EmpathyContact *contact, - const gchar *hostname, guint port, const gchar *service); - G_END_DECLS #endif /* __EMPATHY_TP_TUBE_H__ */ -- 2.39.2