summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-28 13:27:03 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-11-11 16:49:08 +0000
commit1c491dae9d8f6a90b4d1398dfc8914d8f4ff20a7 (patch)
tree12d2647df35487b2bfee1279486351cf1882d041 /examples
parenta48cf1a835d94ea6220d67883eca4071e686a4a7 (diff)
downloadtelepathy-glib-1c491dae9d8f6a90b4d1398dfc8914d8f4ff20a7.tar.gz
TpProtocol: add high-level API for the Addressing interface
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71048 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Diffstat (limited to 'examples')
-rw-r--r--examples/cm/echo-message-parts/protocol.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/cm/echo-message-parts/protocol.c b/examples/cm/echo-message-parts/protocol.c
index ae8894a26..7917ba000 100644
--- a/examples/cm/echo-message-parts/protocol.c
+++ b/examples/cm/echo-message-parts/protocol.c
@@ -226,6 +226,72 @@ dup_supported_vcard_fields (TpBaseProtocol *self)
return g_strdupv ((GStrv) addressing_vcard_fields);
}
+static gchar *
+normalize_vcard_address (TpBaseProtocol *self,
+ const gchar *vcard_field,
+ const gchar *vcard_address,
+ GError **error)
+{
+ if (g_ascii_strcasecmp (vcard_field, "x-jabber") == 0)
+ {
+ /* This is not really how you normalize a JID but it's good enough
+ * for an example. In real life you'd do syntax-checking beyond
+ * "is it empty?", stringprep, and so on. Here, we just assume
+ * non-empty means valid, and lower-case means normalized. */
+
+ if (tp_str_empty (vcard_address))
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+ "The empty string is not a valid JID");
+ return NULL;
+ }
+
+ return g_utf8_strdown (vcard_address, -1);
+ }
+ else
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED,
+ "Don't know how to normalize vCard field: %s", vcard_field);
+ return NULL;
+ }
+}
+
+static gchar *
+normalize_contact_uri (TpBaseProtocol *self,
+ const gchar *uri,
+ GError **error)
+{
+ gchar *scheme = g_uri_parse_scheme (uri);
+
+ if (g_ascii_strcasecmp (scheme, "xmpp") == 0)
+ {
+ gchar *ret = NULL;
+ gchar *id;
+
+ id = normalize_vcard_address (self, "x-jabber", uri + 5, error);
+
+ if (id != NULL)
+ ret = g_strdup_printf ("%s:%s", scheme, id);
+
+ g_free (scheme);
+ g_free (id);
+ return ret;
+ }
+ else if (scheme == NULL)
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+ "Not a valid URI: %s", uri);
+ return NULL;
+ }
+ else
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED,
+ "Don't know how to normalize URIs of that scheme: %s", scheme);
+ g_free (scheme);
+ return NULL;
+ }
+}
+
static void
example_echo_2_protocol_class_init (
ExampleEcho2ProtocolClass *klass)
@@ -248,4 +314,6 @@ addressing_iface_init (TpProtocolAddressingInterface *iface)
{
iface->dup_supported_vcard_fields = dup_supported_vcard_fields;
iface->dup_supported_uri_schemes = dup_supported_uri_schemes;
+ iface->normalize_vcard_address = normalize_vcard_address;
+ iface->normalize_contact_uri = normalize_contact_uri;
}