diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-23 16:03:18 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-23 16:03:18 +0000 |
commit | c51e55653d3631fef57b1b179cfb080fbb9fa759 (patch) | |
tree | 3fbd33d06d7d1ac9ca3f26a87b690afd22388ac9 | |
parent | e1d0e91e4f0d7b77d3a52e898b077f2b9189384d (diff) | |
parent | 264fa79f6a2b08fd2727e84f0a8240ba74c34a8f (diff) |
Merge remote-tracking branch 'andrunko/protocol-addressing'
-rw-r--r-- | glib/docs/reference/telepathy-glib-sections.txt | 33 | ||||
-rw-r--r-- | glib/examples/cm/echo-message-parts/protocol.c | 38 | ||||
-rw-r--r-- | glib/spec/Connection_Interface_Addressing.xml | 93 | ||||
-rw-r--r-- | glib/spec/Protocol.xml | 2 | ||||
-rw-r--r-- | glib/spec/Protocol_Interface_Addressing.xml | 78 | ||||
-rw-r--r-- | glib/telepathy-glib/base-protocol.c | 240 | ||||
-rw-r--r-- | glib/telepathy-glib/base-protocol.h | 45 | ||||
-rw-r--r-- | glib/telepathy-glib/protocol.xml | 1 | ||||
-rw-r--r-- | glib/tests/dbus/protocol-objects.c | 36 |
9 files changed, 486 insertions, 80 deletions
diff --git a/glib/docs/reference/telepathy-glib-sections.txt b/glib/docs/reference/telepathy-glib-sections.txt index 3f6f3697b..f952dd6a0 100644 --- a/glib/docs/reference/telepathy-glib-sections.txt +++ b/glib/docs/reference/telepathy-glib-sections.txt @@ -2593,6 +2593,8 @@ TP_IFACE_CONNECTION_MANAGER TP_IFACE_QUARK_CONNECTION_MANAGER TP_IFACE_PROTOCOL TP_IFACE_QUARK_PROTOCOL +TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING +TP_IFACE_QUARK_PROTOCOL_INTERFACE_ADDRESSING TP_IFACE_PROTOCOL_INTERFACE_AVATARS TP_IFACE_QUARK_PROTOCOL_INTERFACE_AVATARS TP_IFACE_PROTOCOL_INTERFACE_PRESENCE @@ -2948,6 +2950,8 @@ TP_PROP_PROTOCOL_AUTHENTICATION_TYPES TP_PROP_PROTOCOL_CONNECTION_INTERFACES TP_PROP_PROTOCOL_ENGLISH_NAME TP_PROP_PROTOCOL_ICON +TP_PROP_PROTOCOL_INTERFACE_ADDRESSING_ADDRESSABLE_URI_SCHEMES +TP_PROP_PROTOCOL_INTERFACE_ADDRESSING_ADDRESSABLE_VCARD_FIELDS TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_BYTES TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_HEIGHT TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_WIDTH @@ -3053,6 +3057,7 @@ tp_iface_quark_media_session_handler tp_iface_quark_media_stream_handler tp_iface_quark_properties_interface tp_iface_quark_protocol +tp_iface_quark_protocol_interface_addressing tp_iface_quark_protocol_interface_avatars tp_iface_quark_protocol_interface_presence tp_iface_quark_channel_interface_call_state @@ -5282,6 +5287,16 @@ TP_BASE_PROTOCOL_GET_CLASS TP_IS_BASE_PROTOCOL TP_IS_BASE_PROTOCOL_CLASS TP_TYPE_BASE_PROTOCOL +tp_protocol_addressing_get_type +TP_TYPE_PROTOCOL_ADDRESSING +TP_IS_PROTOCOL_ADDRESSING +TP_PROTOCOL_ADDRESSING_GET_INTERFACE +<SUBSECTION> +TpProtocolAddressingInterface +TpBaseProtocolDupSupportedVCardFieldsFunc +TpBaseProtocolDupSupportedURISchemesFunc +TpBaseProtocolNormalizeVCardAddressFunc +TpBaseProtocolNormalizeURIFunc <SUBSECTION Private> TpBaseProtocolPrivate TpBaseProtocolClassPrivate @@ -5301,6 +5316,9 @@ tp_svc_protocol_normalize_contact_impl tp_svc_protocol_return_from_identify_account tp_svc_protocol_return_from_normalize_contact <SUBSECTION> +TpSvcProtocolInterfaceAddressing +TpSvcProtocolInterfaceAddressingClass +<SUBSECTION> TpSvcProtocolInterfacePresence TpSvcProtocolInterfacePresenceClass <SUBSECTION> @@ -5313,6 +5331,17 @@ TP_SVC_PROTOCOL_CLASS TP_SVC_PROTOCOL_GET_CLASS TP_IS_SVC_PROTOCOL TP_TYPE_SVC_PROTOCOL +TP_IS_SVC_PROTOCOL_INTERFACE_ADDRESSING +TP_TYPE_SVC_PROTOCOL_INTERFACE_ADDRESSING +tp_svc_protocol_interface_addressing_get_type +TP_SVC_PROTOCOL_INTERFACE_ADDRESSING +TP_SVC_PROTOCOL_INTERFACE_ADDRESSING_GET_CLASS +tp_svc_protocol_interface_addressing_implement_normalize_uri +tp_svc_protocol_interface_addressing_implement_normalize_vcard_address +tp_svc_protocol_interface_addressing_normalize_uri_impl +tp_svc_protocol_interface_addressing_normalize_vcard_address_impl +tp_svc_protocol_interface_addressing_return_from_normalize_uri +tp_svc_protocol_interface_addressing_return_from_normalize_vcard_address tp_svc_protocol_interface_presence_get_type TP_SVC_PROTOCOL_INTERFACE_PRESENCE TP_SVC_PROTOCOL_INTERFACE_PRESENCE_CLASS @@ -5355,6 +5384,10 @@ tp_cli_protocol_call_identify_account tp_cli_protocol_call_normalize_contact tp_cli_protocol_callback_for_identify_account tp_cli_protocol_callback_for_normalize_contact +tp_cli_protocol_interface_addressing_call_normalize_uri +tp_cli_protocol_interface_addressing_call_normalize_vcard_address +tp_cli_protocol_interface_addressing_callback_for_normalize_uri +tp_cli_protocol_interface_addressing_callback_for_normalize_vcard_address <SUBSECTION Standard> tp_protocol_get_type TP_PROTOCOL diff --git a/glib/examples/cm/echo-message-parts/protocol.c b/glib/examples/cm/echo-message-parts/protocol.c index 3c8bb6c42..11a22269c 100644 --- a/glib/examples/cm/echo-message-parts/protocol.c +++ b/glib/examples/cm/echo-message-parts/protocol.c @@ -15,12 +15,15 @@ #include "conn.h" #include "im-manager.h" -G_DEFINE_TYPE (ExampleEcho2Protocol, - example_echo_2_protocol, - TP_TYPE_BASE_PROTOCOL) +static void addressing_iface_init (TpProtocolAddressingInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (ExampleEcho2Protocol, example_echo_2_protocol, + TP_TYPE_BASE_PROTOCOL, + G_IMPLEMENT_INTERFACE (TP_TYPE_PROTOCOL_ADDRESSING, addressing_iface_init)) const gchar * const protocol_interfaces[] = { TP_IFACE_PROTOCOL_INTERFACE_AVATARS, + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, NULL }; const gchar * const supported_avatar_mime_types[] = { @@ -29,6 +32,16 @@ const gchar * const supported_avatar_mime_types[] = { "image/gif", NULL }; +const gchar * const addressing_vcard_fields[] = { + "x-jabber", + "tel", + NULL }; + +const gchar * const addressing_uri_schemes[] = { + "xmpp", + "tel", + NULL }; + static void example_echo_2_protocol_init ( ExampleEcho2Protocol *self) @@ -198,6 +211,18 @@ get_avatar_details (TpBaseProtocol *self, *max_bytes = 37748736; } +static GStrv +dup_supported_uri_schemes (TpBaseProtocol *self) +{ + return g_strdupv ((GStrv) addressing_uri_schemes); +} + +static GStrv +dup_supported_vcard_fields (TpBaseProtocol *self) +{ + return g_strdupv ((GStrv) addressing_vcard_fields); +} + static void example_echo_2_protocol_class_init ( ExampleEcho2ProtocolClass *klass) @@ -214,3 +239,10 @@ example_echo_2_protocol_class_init ( base_class->get_connection_details = get_connection_details; base_class->get_avatar_details = get_avatar_details; } + +static void +addressing_iface_init (TpProtocolAddressingInterface *iface) +{ + iface->dup_supported_vcard_fields = dup_supported_vcard_fields; + iface->dup_supported_uri_schemes = dup_supported_uri_schemes; +} diff --git a/glib/spec/Connection_Interface_Addressing.xml b/glib/spec/Connection_Interface_Addressing.xml index 497c6d0d9..db8155f23 100644 --- a/glib/spec/Connection_Interface_Addressing.xml +++ b/glib/spec/Connection_Interface_Addressing.xml @@ -39,7 +39,7 @@ <p>The vCard field of the addresses we are requesting. The field name SHOULD be in lower case. Supported fields can be found in - <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing.DRAFT">AddressableVCardFields</tp:dbus-ref>.</p> + <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing">AddressableVCardFields</tp:dbus-ref>.</p> <p>The <code>url</code> vCard field MUST NOT appear here; see <tp:member-ref>GetContactsByURI</tp:member-ref> instead.</p> @@ -76,7 +76,18 @@ </tp:docstring> </arg> - <arg direction="out" type="a{ua{sv}}" name="Requested_Contacts" + <arg direction="out" type="a{su}" name="Requested" + tp:type="Addressing_Normalization_Map"> + <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> + <p>A mapping from requested vCard addresses to the corresponding + contact handles.</p> + + <p>Requested addresses that are not valid or understood for this protocol + MUST be omitted from the mapping.</p> + </tp:docstring> + </arg> + + <arg direction="out" type="a{ua{sv}}" name="Attributes" tp:type="Contact_Attributes_Map"> <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <p>A dictionary mapping the contact handles to contact attributes. @@ -86,14 +97,12 @@ the attribute should either be omitted from the result or replaced with a default value.</p> - <p>Requested addresses that cannot be satisfied MUST be ommitted - from the mapping.</p> + <p>Requested addresses that are not valid or understood for this protocol + MUST be omitted from the mapping.</p> <p>Each contact's attributes will always include at least the identifier that would be obtained by inspecting the handle - (<code>org.freedesktop.Telepathy.Connection/contact-id</code>), - and the vCard field used for requesting the contact in - <code>org.freedesktop.Telepathy.Connection.Interface.ContactInfo/info</code>. + (<code>org.freedesktop.Telepathy.Connection/contact-id</code>). </p> </tp:docstring> </arg> @@ -121,7 +130,7 @@ <tp:docstring> The URI addresses to get contact handles for. Supported schemes can be found in - <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing.DRAFT">AddressableURISchemes</tp:dbus-ref>. + <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing">AddressableURISchemes</tp:dbus-ref>. </tp:docstring> </arg> <arg direction="in" name="Interfaces" type="as" @@ -143,7 +152,17 @@ </tp:docstring> </arg> - <arg direction="out" type="a{ua{sv}}" name="Requested_Contacts" + <arg direction="out" type="a{su}" name="Requested" + tp:type="Addressing_Normalization_Map"> + <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> + <p>A mapping of requested URIs to the corresponding contact handles.</p> + + <p>Requested URIs that are not valid or understood for this protocol + MUST be omitted from the mapping.</p> + </tp:docstring> + </arg> + + <arg direction="out" type="a{ua{sv}}" name="Attributes" tp:type="Contact_Attributes_Map"> <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <p>A dictionary mapping the contact handles to contact attributes. @@ -153,8 +172,8 @@ the attribute should either be omitted from the result or replaced with a default value.</p> - <p>Requested URIs that cannot be satisfied MUST be ommitted - from the mapping.</p> + <p>Requested URIs that are not valid or understood for this protocol + MUST be omitted from the mapping.</p> <p>Each contact's attributes will always include at least the identifier that would be obtained by inspecting the handle @@ -201,57 +220,25 @@ </tp:docstring> </tp:contact-attribute> - <tp:contact-attribute name="requested-address" type="(ss)" - tp:type="Requested_Address"> - <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> - <p>The contact's address, as it was requested - through <tp:member-ref>GetContactsByVCardField</tp:member-ref>. This - attribute MUST be ommitted if the contact was not retrieved - through <tp:member-ref>GetContactsByVCardField</tp:member-ref>.</p> - <tp:rationale> - <p>When retrieving more than one contact - through <tp:member-ref>GetContactsByVCardField</tp:member-ref>, - there needs to be a way to map the given contact back o the - original request.</p> - </tp:rationale> - </tp:docstring> - </tp:contact-attribute> - - <tp:contact-attribute name="requested-uri" type="s"> - <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> - <p>The contact's URI, as it was requested through - <tp:member-ref>GetContactsByURI</tp:member-ref>. This - attribute MUST be ommitted if the contact was not retrieved - through <tp:member-ref>GetContactsByURI</tp:member-ref>.</p> - <tp:rationale> - <p>When retrieving more than one contact - through <tp:member-ref>GetContactsByURI</tp:member-ref>, - there needs to be a way to map the given contact back o the - original request.</p> - </tp:rationale> - </tp:docstring> - </tp:contact-attribute> - - <tp:struct name="Requested_Address" array-name=""> + <tp:mapping name="Addressing_Normalization_Map"> <tp:docstring> - The address that has been requested by - <tp:member-ref>GetContactsByVCardField</tp:member-ref> or - <tp:member-ref>GetContactsByURI</tp:member-ref>. + A map from URIs/vCard addresses to the corresponding handle. </tp:docstring> + <tp:added version="0.25.UNRELEASED"/> - <tp:member name="Field" type="s"> + <tp:member type="s" name="Requested_String"> <tp:docstring> - The vCard field used in <tp:member-ref>GetContactsByVCardField</tp:member-ref>. + The URI or vCard address that has been requested by + <tp:member-ref>GetContactsByVCardField</tp:member-ref> or + <tp:member-ref>GetContactsByURI</tp:member-ref>. </tp:docstring> </tp:member> - - <tp:member name="Address" type="s"> + <tp:member type="u" name="Handle" tp:type="Contact_Handle"> <tp:docstring> - The address that was requested. + A nonzero handle. </tp:docstring> </tp:member> - - </tp:struct> + </tp:mapping> </interface> </node> diff --git a/glib/spec/Protocol.xml b/glib/spec/Protocol.xml index e987a638d..f779492f3 100644 --- a/glib/spec/Protocol.xml +++ b/glib/spec/Protocol.xml @@ -226,7 +226,7 @@ allowed=org.freedesktop.Telepathy.Channel.TargetHandle;org.freedesktop.Telepathy <p>A more exhaustive list of addressable vCard fields can be found in the Protocol's Addressing interface's - <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing.DRAFT">AddressableVCardFields</tp:dbus-ref>.</p> + <tp:dbus-ref namespace="org.freedesktop.Telepathy.Protocol.Interface.Addressing">AddressableVCardFields</tp:dbus-ref>.</p> <p>It is not necessarily valid to interpret contacts' identifiers as values of this vCard field. For instance, telepathy-sofiasip diff --git a/glib/spec/Protocol_Interface_Addressing.xml b/glib/spec/Protocol_Interface_Addressing.xml index 3722c3b81..0bad92a6d 100644 --- a/glib/spec/Protocol_Interface_Addressing.xml +++ b/glib/spec/Protocol_Interface_Addressing.xml @@ -21,9 +21,9 @@ </tp:license> <interface - name="org.freedesktop.Telepathy.Protocol.Interface.Addressing.DRAFT" - tp:causes-havoc="experimental"> - <tp:added version="0.19.12">(as draft)</tp:added> + name="org.freedesktop.Telepathy.Protocol.Interface.Addressing"> + <tp:added version="0.25.UNRELEASED">(as stable API)</tp:added> + <tp:changed version="0.25.UNRELEASED">(renamed NormalizeURI)</tp:changed> <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <p>An interface for protocols that support multiple forms of addressing contacts, for example through vCard addresses and URIs.</p> @@ -62,13 +62,6 @@ AddressableURISchemes=tel;sip; schemes that make sense to resolve as a contact.</p> </tp:rationale> - <p>This property should only be used when the connection is - offline. When it is connected the addressable fields should be - retrieved from the - <tp:dbus-ref - namespace="org.freedesktop.Telepathy.Connection.Interface">Requests.RequestableChannelClasses</tp:dbus-ref>'s - TargetVCardField fixed-property instead.</p> - <p>Connection managers with a <code>.manager</code> file MUST cache this property in the protocol's section of the <code>.manager</code> file if it is non-empty, using the key @@ -102,6 +95,9 @@ AddressableURISchemes=tel;sip; <dd>The X-MSN vCard field. Used for MSN contacts.</dd> <dt><code>x-yahoo</code></dt> <dd>The X-YAHOO vCard field. Used for Yahoo! IDs.</dd> + <dt><code>x-facebook-id</code></dt> + <dd>Used for Facebook IDs in XMPP. If the user JID is + "-12345@chat.facebook.com" then the x-facebook-id is "12345"</dd> </dl> </tp:docstring> @@ -147,7 +143,7 @@ AddressableURISchemes=tel;sip; For example: <code>xmpp:julien@example.com</code>.</dd> <dt><code>msnim</code></dt> <dd>For the purposes of - <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing.DRAFT</tp:dbus-ref>, + <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing</tp:dbus-ref>, <tp:dbus-ref namespace="org.freedesktop.Telepathy">Connection.Interface.Addressing.DRAFT</tp:dbus-ref>, and <tp:dbus-ref namespace="org.freedesktop.Telepathy">Channel.Interface.Addressing.DRAFT</tp:dbus-ref>, @@ -157,7 +153,7 @@ AddressableURISchemes=tel;sip; For example: <code>msnim:add?contact=julien</code>.</dd> <dt><code>aim</code></dt> <dd>For the purposes of - <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing.DRAFT</tp:dbus-ref>, + <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing</tp:dbus-ref>, <tp:dbus-ref namespace="org.freedesktop.Telepathy">Connection.Interface.Addressing.DRAFT</tp:dbus-ref>, and <tp:dbus-ref namespace="org.freedesktop.Telepathy">Channel.Interface.Addressing.DRAFT</tp:dbus-ref>, @@ -170,7 +166,7 @@ AddressableURISchemes=tel;sip; For example: <code>skype:julien</code>.</dd> <dt><code>ymsgr</code></dt> <dd>For the purposes of - <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing.DRAFT</tp:dbus-ref>, + <tp:dbus-ref namespace="org.freedesktop.Telepathy">Protocol.Interface.Addressing</tp:dbus-ref>, <tp:dbus-ref namespace="org.freedesktop.Telepathy">Connection.Interface.Addressing.DRAFT</tp:dbus-ref>, and <tp:dbus-ref namespace="org.freedesktop.Telepathy">Channel.Interface.Addressing.DRAFT</tp:dbus-ref>, @@ -217,7 +213,8 @@ AddressableURISchemes=tel;sip; <arg direction="in" name="VCard_Address" type="s"> <tp:docstring> - The address to normalize. + The address to normalize, which is assumed to belong to a + contact (and not, for instance, a chatroom or server). </tp:docstring> </arg> @@ -243,8 +240,9 @@ AddressableURISchemes=tel;sip; </tp:possible-errors> </method> - <method name="NormalizeURI" - tp:name-for-bindings="Normalize_URI"> + <method name="NormalizeContactURI" + tp:name-for-bindings="Normalize_Contact_URI"> + <tp:added version="0.25.UNRELEASED">(renamed from NormalizeURI)</tp:added> <tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <p>Attempt to normalize the given contact URI. Where possible, this SHOULD return an address that would appear in the @@ -258,8 +256,28 @@ AddressableURISchemes=tel;sip; namespace="org.freedesktop.Telepathy">Connection</tp:dbus-ref>, this method SHOULD perform a best-effort normalization.</p> - <p>Example: <code>xmpp:eitan@EXAMPLE.COM</code> would be normalized to - <code>xmpp:eitan@example.com</code>.</p> + <p>If the URI has extra information beyond what's necessary to + identify a particular contact, such as an XMPP resource or an + action to carry out, this extra information SHOULD be removed. + If all URIs in a scheme contain a verb or action + (like <code>aim</code>, <code>ymsgr</code> and + <code>msnim</code> URIs), then the verb SHOULD be replaced + with the one specified in + <tp:member-ref>AddressableURISchemes</tp:member-ref>.</p> + + <tp:rationale> + <p>This method is intended to normalize URIs stored in address + books, for instance. In protocols like XMPP, if you + vary the resource or action (query string), the URI still + refers to the same high-level contact.</p> + </tp:rationale> + + <p>For instance, + <code>xmpp:romeo@Example.Com/Empathy?message;body=Hello</code> + would be normalized to <code>xmpp:romeo@example.com</code>, + and <code>aim:goim?screenname=Romeo%20M&message=Hello</code> + would be normalized to + <code>aim:addbuddy?screenname=romeom</code>.</p> <p>This method MAY simply raise NotImplemented on some protocols, if it has no use.</p> @@ -267,9 +285,18 @@ AddressableURISchemes=tel;sip; <arg direction="in" name="URI" type="s"> <tp:docstring> - The URI to normalize. The URI's scheme (i.e. the part before - the first colon) MUST appear in - <tp:member-ref>AddressableURISchemes</tp:member-ref>. + <p>The URI to normalize, which is assumed to refer to a contact + (as opposed to, for instance, a chatroom or a server).</p> + + <tp:rationale> + <p>In some protocols, like XMPP, there is no way to tell whether + a given URI refers to a contact or a chatroom by looking at + its syntax.</p> + </tp:rationale> + + <p>The URI's scheme (i.e. the part before + the first colon) MUST appear in + <tp:member-ref>AddressableURISchemes</tp:member-ref>.</p> </tp:docstring> </arg> @@ -289,7 +316,14 @@ AddressableURISchemes=tel;sip; <tp:error name="org.freedesktop.Telepathy.Error.InvalidArgument"> <tp:docstring> - The URI is syntactically incorrect. + <p>The URI is syntactically incorrect or cannot be interpreted + as a reference to a contact.</p> + + <tp:rationale> + <p>For instance, <code>aim:!?</code> is not a valid AIM URI, + while <code>aim:goaway?message=Absent</code> is a + valid AIM URI, but not a contact.</p> + </tp:rationale> </tp:docstring> </tp:error> </tp:possible-errors> diff --git a/glib/telepathy-glib/base-protocol.c b/glib/telepathy-glib/base-protocol.c index 0204caa7d..7cec21074 100644 --- a/glib/telepathy-glib/base-protocol.c +++ b/glib/telepathy-glib/base-protocol.c @@ -412,6 +412,88 @@ tp_cm_param_filter_string_nonempty (const TpCMParamSpec *paramspec, */ /** + * TP_TYPE_PROTOCOL_ADDRESSING: + * + * Interface representing a #TpBaseProtocol that implements + * Protocol.Interface.Addressing. + * + * Since: 0.13.UNRELEASED + */ + +/** + * TpProtocolAddressingInterface: + * @parent: the parent interface + * @dup_supported_uri_schemes: provides the supported URI schemes. Must always + * be implemented. + * @dup_supported_vcard_fields: provides the supported vCard fields. Must + * always be implemented. + * @normalize_vcard_address: protocol-specific implementation for normalizing + * vCard addresses. + * @normalize_contact_uri: protocol-specific implementation for normalizing contact URIs. + * + * The interface vtable for a %TP_TYPE_PROTOCOL_ADDRESSING. + * + * Since: 0.13.UNRELEASED + */ + +/** + * TpBaseProtocolDupSupportedVCardFieldsFunc: + * @self: a protocol + * + * Signature of a virtual method to get the supported vCard fields supported by + * #self. + * + * Returns: (allow-none) (out) (transfer full): a list of vCard fields in lower + * case, e.g. [x-sip, tel] + * + * Since: 0.13.UNRELEASED + */ + +/** + * TpBaseProtocolDupSupportedURISchemesFunc: + * @self: a protocol + * + * Signature of a virtual method to get the supported URI schemes supported by + * #self. + * + * Returns: (allow-none) (out) (transfer full): a list of uri schemes, e.g. [sip, sips, tel] + * + * Since: 0.13.UNRELEASED + */ + +/** + * TpBaseProtocolNormalizeVCardAddressFunc: + * @self: a protocol + * @vcard_field: The vCard field of the address to be normalized. + * @vcard_address: The address to normalize. + * @error: used to return an error if %NULL is returned + * + * Signature of a virtual method to perform best-effort offline normalization + * of a vCard address. It must either return a newly allocated string + * that is the normalized form of @vcard_address, or raise an error and + * return %NULL. + * + * Returns: (transfer full): a normalized identifier, or %NULL on error + * + * Since: 0.13.UNRELEASED + */ + +/** + * TpBaseProtocolNormalizeURIFunc: + * @self: a protocol + * @uri: The URI to normalize. + * @error: used to return an error if %NULL is returned + * + * Signature of a virtual method to perform best-effort offline normalization + * of a URI. It must either return a newly allocated string + * that is the normalized form of @uri, or raise an error and return %NULL. + * + * Returns: (transfer full): a normalized identifier, or %NULL on error + * + * Since: 0.13.11 + */ + +/** * TpBaseProtocolClass: * @parent_class: the parent class * @dbus_properties_class: a D-Bus properties mixin @@ -453,6 +535,7 @@ tp_cm_param_filter_string_nonempty (const TpCMParamSpec *paramspec, static void protocol_iface_init (TpSvcProtocolClass *cls); static void presence_iface_init (TpSvcProtocolInterfacePresenceClass *cls); +static void addressing_iface_init (TpSvcProtocolInterfaceAddressingClass *cls); G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TpBaseProtocol, tp_base_protocol, G_TYPE_OBJECT, @@ -462,7 +545,12 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TpBaseProtocol, tp_base_protocol, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_PROTOCOL_INTERFACE_PRESENCE, presence_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_PROTOCOL_INTERFACE_AVATARS, - NULL)) + NULL); + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_PROTOCOL_INTERFACE_ADDRESSING, + addressing_iface_init)) + +G_DEFINE_INTERFACE (TpProtocolAddressing, tp_protocol_addressing, + TP_TYPE_BASE_PROTOCOL) typedef struct { @@ -699,6 +787,13 @@ tp_base_protocol_get_immutable_properties (TpBaseProtocol *self) NULL); } + if (tp_strv_contains ((const gchar * const *) self->priv->interfaces, + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING)) + tp_dbus_properties_mixin_fill_properties_hash ((GObject *) self, table, + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, "AddressableVCardFields", + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, "AddressableURISchemes", + NULL); + /* FIXME: we should add Presence properties as well */ return table; @@ -804,6 +899,12 @@ typedef enum { N_PPA } ProtocolAvatarProp; +typedef enum { + PADP_ADDRESSABLE_VCARD_FIELDS, + PADP_ADDRESSABLE_URI_SCHEMES, + N_PADP +} ProtocolAddressingProp; + static void protocol_prop_presence_getter (GObject *object, GQuark iface G_GNUC_UNUSED, @@ -917,6 +1018,39 @@ protocol_prop_avatar_getter (GObject *object, } static void +protocol_prop_addressing_getter (GObject *object, + GQuark iface G_GNUC_UNUSED, + GQuark name G_GNUC_UNUSED, + GValue *value, + gpointer getter_data) +{ + TpBaseProtocol *self = (TpBaseProtocol *) object; + TpProtocolAddressingInterface *addr_iface; + + g_return_if_fail (TP_IS_PROTOCOL_ADDRESSING (self)); + + addr_iface = TP_PROTOCOL_ADDRESSING_GET_INTERFACE (self); + + switch (GPOINTER_TO_INT (getter_data)) + { + case PADP_ADDRESSABLE_VCARD_FIELDS: + g_assert (addr_iface->dup_supported_vcard_fields != NULL); + g_value_take_boxed (value, + addr_iface->dup_supported_vcard_fields (self)); + break; + + case PADP_ADDRESSABLE_URI_SCHEMES: + g_assert (addr_iface->dup_supported_uri_schemes != NULL); + g_value_take_boxed (value, + addr_iface->dup_supported_uri_schemes (self)); + break; + + default: + g_assert_not_reached (); + } +} + +static void protocol_properties_getter (GObject *object, GQuark iface G_GNUC_UNUSED, GQuark name G_GNUC_UNUSED, @@ -1014,12 +1148,22 @@ tp_base_protocol_class_init (TpBaseProtocolClass *klass) { NULL } }; + static TpDBusPropertiesMixinPropImpl addressing_props[] = { + { "AddressableVCardFields", + GINT_TO_POINTER (PADP_ADDRESSABLE_VCARD_FIELDS), NULL }, + { "AddressableURISchemes", + GINT_TO_POINTER (PADP_ADDRESSABLE_URI_SCHEMES), NULL }, + { NULL } + }; + static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { { TP_IFACE_PROTOCOL, protocol_properties_getter, NULL, channel_props }, { TP_IFACE_PROTOCOL_INTERFACE_PRESENCE, protocol_prop_presence_getter, NULL, presence_props }, { TP_IFACE_PROTOCOL_INTERFACE_AVATARS, protocol_prop_avatar_getter, NULL, avatar_props }, + { TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, + protocol_prop_addressing_getter, NULL, addressing_props }, { NULL } }; @@ -1581,6 +1725,86 @@ protocol_identify_account (TpSvcProtocol *protocol, } static void +addressing_normalize_contact_uri (TpSvcProtocolInterfaceAddressing *protocol, + const gchar *uri, + DBusGMethodInvocation *context) +{ + TpBaseProtocol *self = TP_BASE_PROTOCOL (protocol); + TpProtocolAddressingInterface *iface; + GError *error = NULL; + gchar *ret = NULL; + + if (!TP_IS_PROTOCOL_ADDRESSING (self)) + goto notimplemented; + + iface = TP_PROTOCOL_ADDRESSING_GET_INTERFACE (self); + + if (iface->normalize_contact_uri == NULL) + goto notimplemented; + + ret = iface->normalize_contact_uri (self, uri, &error); + + if (ret == NULL) + { + dbus_g_method_return_error (context, error); + g_error_free (error); + return; + } + + tp_svc_protocol_interface_addressing_return_from_normalize_contact_uri (context, + ret); + + g_free (ret); + + return; + + notimplemented: + tp_dbus_g_method_return_not_implemented (context); +} + +static void +addressing_normalize_vcard_address (TpSvcProtocolInterfaceAddressing *protocol, + const gchar *vcard_field, + const gchar *vcard_address, + DBusGMethodInvocation *context) +{ + TpBaseProtocol *self = TP_BASE_PROTOCOL (protocol); + TpProtocolAddressingInterface *iface; + GError *error = NULL; + gchar *ret = NULL; + + if (!TP_IS_PROTOCOL_ADDRESSING (self)) + goto notimplemented; + + iface = TP_PROTOCOL_ADDRESSING_GET_INTERFACE (self); + + if (iface->normalize_vcard_address == NULL) + goto notimplemented; + + ret = iface->normalize_vcard_address (self, vcard_field, vcard_address, + &error); + + if (ret == NULL) + { + dbus_g_method_return_error (context, error); + g_error_free (error); + return; + } + + tp_svc_protocol_interface_addressing_return_from_normalize_vcard_address ( + context, + ret); + + g_free (ret); + + return; + + notimplemented: + tp_dbus_g_method_return_not_implemented (context); +} + + +static void protocol_iface_init (TpSvcProtocolClass *cls) { #define IMPLEMENT(x) tp_svc_protocol_implement_##x (cls, protocol_##x) @@ -1593,3 +1817,17 @@ static void presence_iface_init (TpSvcProtocolInterfacePresenceClass *cls) { } + +static void +addressing_iface_init (TpSvcProtocolInterfaceAddressingClass *cls) +{ +#define IMPLEMENT(x) tp_svc_protocol_interface_addressing_implement_##x (cls, addressing_##x) + IMPLEMENT (normalize_contact_uri); + IMPLEMENT (normalize_vcard_address); +#undef IMPLEMENT +} + +static void +tp_protocol_addressing_default_init (TpProtocolAddressingInterface *iface) +{ +} diff --git a/glib/telepathy-glib/base-protocol.h b/glib/telepathy-glib/base-protocol.h index 3f94943a4..9d34be555 100644 --- a/glib/telepathy-glib/base-protocol.h +++ b/glib/telepathy-glib/base-protocol.h @@ -181,6 +181,51 @@ const TpPresenceStatusSpec *tp_base_protocol_get_statuses (TpBaseProtocol *self) TpBaseConnection *tp_base_protocol_new_connection (TpBaseProtocol *self, GHashTable *asv, GError **error); + +/* ---- Implemented by subclasses for Addressing support ---- */ + +#define TP_TYPE_PROTOCOL_ADDRESSING \ + (tp_protocol_addressing_get_type ()) + +#define TP_IS_PROTOCOL_ADDRESSING(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + TP_TYPE_PROTOCOL_ADDRESSING)) + +#define TP_PROTOCOL_ADDRESSING_GET_INTERFACE(obj) \ + (G_TYPE_INSTANCE_GET_INTERFACE ((obj), \ + TP_TYPE_PROTOCOL_ADDRESSING, TpProtocolAddressingInterface)) + +typedef struct _TpProtocolAddressingInterface TpProtocolAddressingInterface; + +typedef GStrv (*TpBaseProtocolDupSupportedVCardFieldsFunc) (TpBaseProtocol *self); + +typedef GStrv (*TpBaseProtocolDupSupportedURISchemesFunc) (TpBaseProtocol *self); + +typedef gchar *(*TpBaseProtocolNormalizeVCardAddressFunc) ( + TpBaseProtocol *self, + const gchar *vcard_field, + const gchar *vcard_address, + GError **error); + +typedef gchar *(*TpBaseProtocolNormalizeURIFunc) ( + TpBaseProtocol *self, + const gchar *uri, + GError **error); + +struct _TpProtocolAddressingInterface { + GTypeInterface parent; + + TpBaseProtocolDupSupportedVCardFieldsFunc dup_supported_vcard_fields; + + TpBaseProtocolDupSupportedURISchemesFunc dup_supported_uri_schemes; + + TpBaseProtocolNormalizeVCardAddressFunc normalize_vcard_address; + + TpBaseProtocolNormalizeURIFunc normalize_contact_uri; +}; + +GType tp_protocol_addressing_get_type (void) G_GNUC_CONST; + G_END_DECLS #endif diff --git a/glib/telepathy-glib/protocol.xml b/glib/telepathy-glib/protocol.xml index b0d12d8fb..82edad614 100644 --- a/glib/telepathy-glib/protocol.xml +++ b/glib/telepathy-glib/protocol.xml @@ -5,6 +5,7 @@ <tp:title>Protocol interfaces</tp:title> <xi:include href="../spec/Protocol.xml"/> +<xi:include href="../spec/Protocol_Interface_Addressing.xml"/> <xi:include href="../spec/Protocol_Interface_Avatars.xml"/> <xi:include href="../spec/Protocol_Interface_Presence.xml"/> diff --git a/glib/tests/dbus/protocol-objects.c b/glib/tests/dbus/protocol-objects.c index 68bf23da7..b12bb13e1 100644 --- a/glib/tests/dbus/protocol-objects.c +++ b/glib/tests/dbus/protocol-objects.c @@ -114,6 +114,7 @@ const gchar * const expected_interfaces[] = { const gchar * const expected_protocol_interfaces[] = { TP_IFACE_PROTOCOL_INTERFACE_AVATARS, + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, NULL }; const gchar * const expected_supported_avatar_mime_types[] = { @@ -122,6 +123,16 @@ const gchar * const expected_supported_avatar_mime_types[] = { "image/gif", NULL }; +const gchar * const expected_addressable_vcard_fields[] = { + "x-jabber", + "tel", + NULL }; + +const gchar * const expected_addressable_uri_schemes[] = { + "xmpp", + "tel", + NULL }; + static void test_protocol_properties (Test *test, gconstpointer data G_GNUC_UNUSED) @@ -223,6 +234,29 @@ test_protocol_avatar_properties (Test *test, } static void +test_protocol_addressing_properties (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *properties = NULL; + + test->protocol = tp_protocol_new (test->dbus, "example_echo_2", + "example", NULL, NULL); + g_assert (test->protocol != NULL); + + tp_cli_dbus_properties_run_get_all (test->protocol, -1, + TP_IFACE_PROTOCOL_INTERFACE_ADDRESSING, &properties, &test->error, NULL); + g_assert_no_error (test->error); + + tp_tests_assert_strv_equals ( + tp_asv_get_boxed (properties, "AddressableVCardFields", G_TYPE_STRV), + expected_addressable_vcard_fields); + + tp_tests_assert_strv_equals ( + tp_asv_get_boxed (properties, "AddressableURISchemes", G_TYPE_STRV), + expected_addressable_uri_schemes); +} + +static void test_protocols_property (Test *test, gconstpointer data G_GNUC_UNUSED) { @@ -481,6 +515,8 @@ main (int argc, test_protocol_properties, teardown); g_test_add ("/protocol-objects/protocol-avatar-properties", Test, NULL, setup, test_protocol_avatar_properties, teardown); + g_test_add ("/protocol-objects/protocol-addressing-properties", Test, NULL, + setup, test_protocol_addressing_properties, teardown); g_test_add ("/protocol-objects/protocols-property", Test, NULL, setup, test_protocols_property, teardown); g_test_add ("/protocol-objects/protocols-property-old", Test, NULL, setup, |