diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-14 13:44:24 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-05-14 15:04:09 +0200 |
commit | 153c9d799b39440f5d7bcbfa23757c6316f3f753 (patch) | |
tree | 0c18ab241db200fd451b2d9ce6f6ef4d5df4e775 | |
parent | 6afc5819e15200f7cf0970bad982ea245dca4327 (diff) | |
download | telepathy-glib-153c9d799b39440f5d7bcbfa23757c6316f3f753.tar.gz |
Deprecate tp_connection_parse_object_path()
We have tp_connection_get_protocol_name() and
tp_connection_get_connection_manager_name() now.
-rw-r--r-- | telepathy-glib/connection.c | 31 | ||||
-rw-r--r-- | telepathy-glib/connection.h | 3 | ||||
-rw-r--r-- | telepathy-glib/contact.c | 12 | ||||
-rw-r--r-- | tests/dbus/connection.c | 34 |
4 files changed, 66 insertions, 14 deletions
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index c53c515c4..a3988eec4 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -1419,11 +1419,17 @@ _tp_connection_got_properties (TpProxy *proxy, } } +static gboolean _tp_connection_parse (const gchar *path_or_bus_name, + char delimiter, + gchar **protocol, + gchar **cm_name); + static void tp_connection_constructed (GObject *object) { GObjectClass *object_class = (GObjectClass *) tp_connection_parent_class; TpConnection *self = TP_CONNECTION (object); + const gchar *object_path; if (object_class->constructed != NULL) object_class->constructed (object); @@ -1440,8 +1446,9 @@ tp_connection_constructed (GObject *object) tp_cli_connection_connect_to_connection_error (self, tp_connection_connection_error_cb, NULL, NULL, NULL, NULL); - tp_connection_parse_object_path (self, &(self->priv->proto_name), - &(self->priv->cm_name)); + object_path = tp_proxy_get_object_path (TP_PROXY (self)); + g_assert (_tp_connection_parse (object_path, '/', + &(self->priv->proto_name), &(self->priv->cm_name))); tp_cli_dbus_properties_call_get_all (self, -1, TP_IFACE_CONNECTION, _tp_connection_got_properties, NULL, NULL, NULL); @@ -2376,6 +2383,13 @@ _tp_connection_new_with_factory (TpSimpleClientFactory *factory, bus_name = dup_name; } + if (!_tp_connection_parse (object_path, '/', NULL, NULL)) + { + g_set_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_INVALID_OBJECT_PATH, + "Connection object path is not in the right format"); + goto finally; + } + if (!tp_dbus_check_valid_bus_name (bus_name, TP_DBUS_NAME_TYPE_NOT_BUS_DAEMON, error)) goto finally; @@ -3130,18 +3144,23 @@ tp_connection_presence_type_cmp_availability (TpConnectionPresenceType p1, * Returns: TRUE if the object path was correctly parsed, FALSE otherwise. * * Since: 0.7.27 + * Deprecated: Use tp_connection_get_protocol_name() and + * tp_connection_get_connection_manager_name() instead. */ gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol, gchar **cm_name) { - const gchar *object_path; - g_return_val_if_fail (TP_IS_CONNECTION (self), FALSE); - object_path = tp_proxy_get_object_path (TP_PROXY (self)); - return _tp_connection_parse (object_path, '/', protocol, cm_name); + if (protocol != NULL) + *protocol = g_strdup (self->priv->proto_name); + + if (cm_name != NULL) + *cm_name = g_strdup (self->priv->cm_name); + + return TRUE; } /* Can return a contact that's not meant to be visible to library users diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h index b5af72b0f..55a0061c9 100644 --- a/telepathy-glib/connection.h +++ b/telepathy-glib/connection.h @@ -202,8 +202,11 @@ void tp_connection_init_known_interfaces (void); gint tp_connection_presence_type_cmp_availability (TpConnectionPresenceType p1, TpConnectionPresenceType p2); +#ifndef TP_DISABLE_DEPRECATED +_TP_DEPRECATED_IN_UNRELEASED_FOR(tp_connection_get_protocol_name) gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol, gchar **cm_name); +#endif _TP_AVAILABLE_IN_0_20 const gchar *tp_connection_get_detailed_error (TpConnection *self, diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 54c027572..f813b2c5e 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -2633,18 +2633,16 @@ build_avatar_filename (TpConnection *connection, gchar **ret_filename, gchar **ret_mime_filename) { - gchar *protocol; - gchar *cm_name; gchar *dir; gchar *token_escaped; gboolean success = TRUE; - if (!tp_connection_parse_object_path (connection, &protocol, &cm_name)) - return FALSE; - token_escaped = tp_escape_as_identifier (avatar_token); dir = g_build_filename (g_get_user_cache_dir (), - "telepathy", "avatars", cm_name, protocol, NULL); + "telepathy", "avatars", + tp_connection_get_connection_manager_name (connection), + tp_connection_get_protocol_name (connection), + NULL); if (create_dir) { @@ -2665,8 +2663,6 @@ build_avatar_filename (TpConnection *connection, out: - g_free (protocol); - g_free (cm_name); g_free (dir); g_free (token_escaped); diff --git a/tests/dbus/connection.c b/tests/dbus/connection.c index fca25664c..f9f34d0da 100644 --- a/tests/dbus/connection.c +++ b/tests/dbus/connection.c @@ -394,6 +394,38 @@ test_call_when_invalid (Test *test, test->cwr_error = NULL; } +static void +test_object_path (Test *test, + gconstpointer nil G_GNUC_UNUSED) +{ + const gchar *invalid_path = TP_CONN_OBJECT_PATH_BASE "invalid"; + const gchar *invalid_name = TP_CONN_BUS_NAME_BASE "invalid"; + TpConnection *connection; + GError *error = NULL; + + test->conn = tp_connection_new (test->dbus, test->conn_name, test->conn_path, + &error); + g_assert (test->conn != NULL); + g_assert_no_error (error); + + tp_tests_proxy_run_until_prepared (test->conn, NULL); + g_assert_cmpstr (tp_connection_get_connection_manager_name (test->conn), ==, + "simple"); + g_assert_cmpstr (tp_connection_get_protocol_name (test->conn), ==, + "simple-protocol"); + + /* Register the same connection with an invalid object path */ + tp_dbus_daemon_register_object (test->dbus, invalid_path, test->service_conn); + tp_dbus_daemon_request_name (test->dbus, invalid_name, FALSE, &error); + g_assert_no_error (error); + + /* Create a TpConnection for that path, it return invalidated connection */ + connection = tp_connection_new (test->dbus, NULL, invalid_path, &error); + g_assert (connection == NULL); + g_assert_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_INVALID_OBJECT_PATH); + g_clear_error (&error); +} + int main (int argc, char **argv) @@ -411,6 +443,8 @@ main (int argc, test_call_when_ready, teardown); g_test_add ("/conn/call_when_invalid", Test, NULL, setup, test_call_when_invalid, teardown); + g_test_add ("/conn/object_path", Test, NULL, setup, + test_object_path, teardown); return g_test_run (); } |