summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-28 13:17:22 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-11-11 16:49:05 +0000
commita48cf1a835d94ea6220d67883eca4071e686a4a7 (patch)
tree75ce749de3bc8dfaabfd2fc3183b0da03dc226a9
parent689c4297ff8cd7cf971ba4bf46ad605a3149f6b4 (diff)
tp_protocol_identify_account_async: add and test
To make the test a little more interesting and a little more realistic, we normalize the 'account' parameter to lower-case. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71048 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-glib-sections.txt2
-rw-r--r--examples/cm/echo-message-parts/protocol.c2
-rw-r--r--telepathy-glib/protocol.c70
-rw-r--r--telepathy-glib/protocol.h12
-rw-r--r--tests/dbus/protocol-objects.c58
5 files changed, 143 insertions, 1 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 4c6679df2..df104212c 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -6173,6 +6173,8 @@ tp_protocol_get_english_name
tp_protocol_get_icon_name
tp_protocol_get_vcard_field
tp_protocol_get_authentication_types
+tp_protocol_identify_account_async
+tp_protocol_identify_account_finish
tp_protocol_normalize_contact_async
tp_protocol_normalize_contact_finish
<SUBSECTION>
diff --git a/examples/cm/echo-message-parts/protocol.c b/examples/cm/echo-message-parts/protocol.c
index 4512216b9..ae8894a26 100644
--- a/examples/cm/echo-message-parts/protocol.c
+++ b/examples/cm/echo-message-parts/protocol.c
@@ -115,7 +115,7 @@ identify_account (TpBaseProtocol *self G_GNUC_UNUSED,
const gchar *account = tp_asv_get_string (asv, "account");
if (account != NULL)
- return g_strdup (account);
+ return g_utf8_strdown (account, -1);
g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
"'account' parameter not given");
diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c
index fc5adfa3c..7296db8b3 100644
--- a/telepathy-glib/protocol.c
+++ b/telepathy-glib/protocol.c
@@ -45,6 +45,7 @@
#include "telepathy-glib/debug-internal.h"
#include "telepathy-glib/proxy-internal.h"
#include "telepathy-glib/util-internal.h"
+#include "telepathy-glib/variant-util-internal.h"
#include "telepathy-glib/_gen/tp-cli-protocol-body.h"
@@ -1862,3 +1863,72 @@ tp_protocol_normalize_contact_finish (TpProtocol *self,
return g_task_propagate_pointer (G_TASK (result), error);
}
+
+/**
+ * tp_protocol_identify_account_async:
+ * @self: a protocol
+ * @vardict: the account parameters as a #GVariant of
+ * type %G_VARIANT_TYPE_VARDICT. If it is floating, ownership will
+ * be taken, as if via g_variant_ref_sink().
+ * @cancellable: (allow-none): may be used to cancel the async request
+ * @callback: (scope async): a callback to call when
+ * the request is satisfied
+ * @user_data: (closure) (allow-none): data to pass to @callback
+ *
+ * Return a string that could identify the account with the given
+ * parameters. In most protocols that string is a normalized 'account'
+ * parameter, but some protocols have more complex requirements;
+ * for instance, on IRC, the 'account' (nickname) is insufficient,
+ * and must be combined with a server or network name.
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_protocol_identify_account_async (TpProtocol *self,
+ GVariant *vardict,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ GHashTable *asv;
+
+ g_return_if_fail (TP_IS_PROTOCOL (self));
+ g_return_if_fail (vardict != NULL);
+ g_return_if_fail (g_variant_is_of_type (vardict, G_VARIANT_TYPE_VARDICT));
+ /* this makes no sense to call for its side-effects */
+ g_return_if_fail (callback != NULL);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, tp_protocol_identify_account_async);
+ g_variant_ref_sink (vardict);
+ asv = _tp_asv_from_vardict (vardict);
+ tp_cli_protocol_call_identify_account (self, -1, asv,
+ tp_protocol_async_string_cb, task, g_object_unref, NULL);
+ g_hash_table_unref (asv);
+ g_variant_unref (vardict);
+}
+
+/**
+ * tp_protocol_identify_account_finish:
+ * @self: a protocol
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Interpret the result of tp_protocol_identify_account_async().
+ *
+ * Returns: (transfer full): a string identifying the account,
+ * or %NULL on error
+ * Since: 0.UNRELEASED
+ */
+gchar *
+tp_protocol_identify_account_finish (TpProtocol *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, self), NULL);
+ g_return_val_if_fail (g_async_result_is_tagged (result,
+ tp_protocol_identify_account_async), NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
+}
diff --git a/telepathy-glib/protocol.h b/telepathy-glib/protocol.h
index 162390734..05f77814e 100644
--- a/telepathy-glib/protocol.h
+++ b/telepathy-glib/protocol.h
@@ -137,6 +137,18 @@ gchar *tp_protocol_normalize_contact_finish (TpProtocol *self,
GAsyncResult *result,
GError **error);
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_protocol_identify_account_async (TpProtocol *self,
+ GVariant *vardict,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+_TP_AVAILABLE_IN_UNRELEASED
+gchar *tp_protocol_identify_account_finish (TpProtocol *self,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#include <telepathy-glib/_gen/tp-cli-protocol.h>
diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c
index 248805728..fee4afe4b 100644
--- a/tests/dbus/protocol-objects.c
+++ b/tests/dbus/protocol-objects.c
@@ -567,6 +567,62 @@ test_normalize (Test *test,
g_clear_error (&test->error);
}
+static void
+test_id (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ GAsyncResult *result = NULL;
+ gchar *s;
+
+ tp_tests_proxy_run_until_prepared (test->cm, NULL);
+ test->protocol = g_object_ref (
+ tp_connection_manager_get_protocol_object (test->cm, "example"));
+
+ tp_protocol_identify_account_async (test->protocol,
+ g_variant_new_parsed ("{ 'account': <'Hello'> }"),
+ NULL, tp_tests_result_ready_cb, &result);
+ tp_tests_run_until_result (&result);
+ s = tp_protocol_identify_account_finish (test->protocol, result,
+ &test->error);
+ g_assert_no_error (test->error);
+ g_assert_cmpstr (s, ==, "hello");
+ g_clear_object (&result);
+ g_free (s);
+
+ tp_protocol_identify_account_async (test->protocol,
+ g_variant_new_parsed ("{ 'account': <'Hello'>, 'unknown-param': <42> }"),
+ NULL, tp_tests_result_ready_cb, &result);
+ tp_tests_run_until_result (&result);
+ s = tp_protocol_identify_account_finish (test->protocol, result,
+ &test->error);
+ g_assert_error (test->error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT);
+ g_assert_cmpstr (s, ==, NULL);
+ g_clear_object (&result);
+ g_clear_error (&test->error);
+
+ tp_protocol_identify_account_async (test->protocol,
+ g_variant_new_parsed ("@a{sv} {}"),
+ NULL, tp_tests_result_ready_cb, &result);
+ tp_tests_run_until_result (&result);
+ s = tp_protocol_identify_account_finish (test->protocol, result,
+ &test->error);
+ g_assert_error (test->error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT);
+ g_assert_cmpstr (s, ==, NULL);
+ g_clear_object (&result);
+ g_clear_error (&test->error);
+
+ tp_protocol_identify_account_async (test->protocol,
+ g_variant_new_parsed ("@a{sv} { 'account': <''> }"),
+ NULL, tp_tests_result_ready_cb, &result);
+ tp_tests_run_until_result (&result);
+ s = tp_protocol_identify_account_finish (test->protocol, result,
+ &test->error);
+ g_assert_error (test->error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT);
+ g_assert_cmpstr (s, ==, NULL);
+ g_clear_object (&result);
+ g_clear_error (&test->error);
+}
+
int
main (int argc,
char **argv)
@@ -592,6 +648,8 @@ main (int argc,
test_protocol_object_from_file, teardown);
g_test_add ("/protocol-objects/normalize", Test, NULL, setup,
test_normalize, teardown);
+ g_test_add ("/protocol-objects/id", Test, NULL, setup,
+ test_id, teardown);
return tp_tests_run_with_bus ();
}