summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-06 14:21:51 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-07 15:27:05 +0100
commitc0e658ed4e99555466e5d1c09140f43cb4faf898 (patch)
treefbc54605ed856d020f3075bb0c0bc39ef867ee07
parentd96a1a927959b43586a888c56d45ab8b23b60de0 (diff)
connection: add pick_best_resource_for_caps function
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--gabble/connection.h6
-rw-r--r--src/connection.c34
2 files changed, 40 insertions, 0 deletions
diff --git a/gabble/connection.h b/gabble/connection.h
index 6da5d8a7..2de081b3 100644
--- a/gabble/connection.h
+++ b/gabble/connection.h
@@ -65,6 +65,12 @@ gchar *gabble_connection_get_full_jid (GabbleConnection *conn);
const gchar * gabble_connection_get_jid_for_caps (GabbleConnection *conn,
WockyXep0115Capabilities *caps);
+const gchar * gabble_connection_pick_best_resource_for_caps (
+ GabbleConnection *connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data);
+
G_END_DECLS
#endif
diff --git a/src/connection.c b/src/connection.c
index 70424d10..ed85c153 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -3857,3 +3857,37 @@ gabble_connection_get_jid_for_caps (GabbleConnection *conn,
return tp_handle_inspect (contact_handles, handle);
}
+
+const gchar *
+gabble_connection_pick_best_resource_for_caps (GabbleConnection *connection,
+ const gchar *jid,
+ GabbleCapabilitySetPredicate predicate,
+ gconstpointer user_data)
+{
+ TpBaseConnection *base;
+ TpHandleRepoIface *contact_handles;
+ TpHandle handle;
+ GabblePresence *presence;
+
+ g_return_val_if_fail (GABBLE_IS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (!tp_str_empty (jid), NULL);
+
+ base = (TpBaseConnection *) connection;
+ contact_handles = tp_base_connection_get_handles (base,
+ TP_HANDLE_TYPE_CONTACT);
+
+ handle = tp_handle_ensure (contact_handles, jid,
+ NULL, NULL);
+
+ if (handle == 0)
+ return NULL;
+
+ presence = gabble_presence_cache_get (connection->presence_cache,
+ handle);
+
+ if (presence == NULL)
+ return NULL;
+
+ return gabble_presence_pick_resource_by_caps (presence, 0,
+ predicate, user_data);
+}