[Telepathy-commits] [telepathy-glib/master] Add tp_connection_parse_object_path() to get protocol and CM name.
Xavier Claessens
xclaesse at gmail.com
Fri Feb 20 06:37:02 PST 2009
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/connection.c | 59 ++++++++++++++++++++++++++++
telepathy-glib/connection.h | 3 +
tests/dbus/connection.c | 10 ++++-
4 files changed, 72 insertions(+), 1 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index b86f682..22119a2 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -2242,6 +2242,7 @@ tp_connection_hold_handles
tp_connection_unref_handles
tp_connection_init_known_interfaces
tp_connection_presence_type_cmp_availability
+tp_connection_parse_object_path
TpConnection
TpConnectionClass
TP_UNKNOWN_CONNECTION_STATUS
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 687d48a..10ef46b 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -1433,6 +1433,65 @@ tp_connection_presence_type_cmp_availability (TpConnectionPresenceType p1,
}
+/**
+ * tp_connection_parse_object_path:
+ * @self: a connection
+ * @protocol: If not NULL, used to return the protocol of the connection
+ * @cm_name: If not NULL, used to return the connection manager name of the
+ * connection
+ *
+ * If the object path of @connection is in the correct form, set
+ * @protocol and @cm_name, return TRUE. Otherwise leave them unchanged and
+ * return FALSE.
+ *
+ * Returns: TRUE if the object path was correctly parsed, FALSE otherwise.
+ *
+ * Since: 0.7.UNRELEASED
+ */
+gboolean
+tp_connection_parse_object_path (TpConnection *self,
+ gchar **protocol,
+ gchar **cm_name)
+{
+ const gchar *object_path;
+ const gchar *cm_name_start = NULL;
+ const gchar *protocol_start = NULL;
+ const gchar *account_start = NULL;
+
+ g_return_val_if_fail (TP_IS_CONNECTION (self), FALSE);
+
+ /* If CM respects the spec, object path must be in that form:
+ * /org/freedesktop/Telepathy/Connection/cmname/proto/account */
+ object_path = tp_proxy_get_object_path (TP_PROXY (self));
+ if (!g_str_has_prefix (object_path, TP_CONN_OBJECT_PATH_BASE))
+ return FALSE;
+
+ cm_name_start = object_path + strlen (TP_CONN_OBJECT_PATH_BASE);
+ protocol_start = strstr (cm_name_start, "/");
+ if (protocol_start == NULL)
+ return FALSE;
+ protocol_start++;
+
+ account_start = strstr (protocol_start, "/");
+ if (account_start == NULL)
+ return FALSE;
+ account_start++;
+
+ if (cm_name != NULL)
+ {
+ *cm_name = g_strndup (cm_name_start, protocol_start - cm_name_start - 1);
+ g_strdelimit (*cm_name, "_", '-');
+ }
+
+ if (protocol != NULL)
+ {
+ *protocol = g_strndup (protocol_start, account_start - protocol_start - 1);
+ g_strdelimit (*protocol, "_", '-');
+ }
+
+ return TRUE;
+}
+
TpContact *
_tp_connection_lookup_contact (TpConnection *self,
TpHandle handle)
diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h
index 46c345e..8b081ec 100644
--- a/telepathy-glib/connection.h
+++ b/telepathy-glib/connection.h
@@ -105,6 +105,9 @@ void tp_connection_init_known_interfaces (void);
gint tp_connection_presence_type_cmp_availability (TpConnectionPresenceType p1,
TpConnectionPresenceType p2);
+gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol,
+ gchar **cm_name);
+
/* connection-handles.c */
typedef void (*TpConnectionHoldHandlesCb) (TpConnection *connection,
diff --git a/tests/dbus/connection.c b/tests/dbus/connection.c
index e3b8f7c..9f5a622 100644
--- a/tests/dbus/connection.c
+++ b/tests/dbus/connection.c
@@ -89,7 +89,15 @@ conn_ready (TpConnection *connection,
if (error == NULL)
{
+ gboolean parsed;
+ gchar *proto = NULL;
+ gchar *cm_name = NULL;
+
g_message ("connection %p ready", connection);
+ parsed = tp_connection_parse_object_path (connection, &proto, &cm_name);
+ MYASSERT (parsed == TRUE, "");
+ MYASSERT_SAME_STRING (proto, "simple-protocol");
+ MYASSERT_SAME_STRING (cm_name, "simple");
}
else
{
@@ -192,7 +200,7 @@ main (int argc,
service_conn = SIMPLE_CONNECTION (g_object_new (
SIMPLE_TYPE_CONNECTION,
"account", "me at example.com",
- "protocol", "simple",
+ "protocol", "simple-protocol",
NULL));
service_conn_as_base = TP_BASE_CONNECTION (service_conn);
MYASSERT (service_conn != NULL, "");
--
1.5.6.5
More information about the telepathy-commits
mailing list