* Rename the Avatar interface to HasAvatar
* Rename the Presence interface to HasPresence
* Rename the Favourite interface to Favouritable
+* Add IMableError
+* Throw IMableError from IMable.normalise_im_address()
Bugs fixed:
* Bug 635178 — Leak in
* Bug 636251 — Fails to add contact
* Bug 629526 — Generate gtk-doc documentation
* Bug 627397 — Use better interface names
+* Bug 636714 — Assertion failure on invalid IM address
Overview of changes from libfolks 0.3.1 to libfolks 0.3.2
==========================================================
value.foreach ((k, v) =>
{
unowned string protocol = (string) k;
- unowned GenericArray<string> addresses = (GenericArray<string>) v;
+ unowned GenericArray<string?> addresses =
+ (GenericArray<string?>) v;
+ uint offset = 0;
for (int i = 0; i < addresses.length; i++)
{
- addresses[i] =
- IMable.normalise_im_address (addresses[i], protocol);
+ try
+ {
+ addresses[i - offset] =
+ IMable.normalise_im_address (addresses[i],
+ protocol);
+ }
+ catch (IMableError e)
+ {
+ /* Somehow an error has crept into the user's
+ * relationships.ini. Warn of it and ignore the IM
+ * address. We achieve this by decrementing the offset
+ * between the index of the address being set and the
+ * index of the address being read. */
+ warning (e.message);
+ addresses[i - offset] = null;
+ offset++;
+ }
}
+ /* Nullify the last few addresses if we have a non-zero offset,
+ * as they're the gaps left by invalid addresses, which we want
+ * set_string_list() to ignore. */
+ for (; offset > 0; offset--)
+ addresses[addresses.length - offset] = null;
+
unowned string[] _addresses =
(string[]) ((PtrArray) addresses).pdata;
_addresses.length = (int) addresses.length;
foreach (string _address in im_addresses)
{
- string address =
- IMable.normalise_im_address (_address, protocol);
+ try
+ {
+ string address =
+ IMable.normalise_im_address (_address, protocol);
- if (!address_set.contains (address))
+ if (!address_set.contains (address))
+ {
+ im_address_array.add (address);
+ address_set.add (address);
+ }
+ }
+ catch (IMableError e)
{
- im_address_array.add (address);
- address_set.add (address);
+ /* Warn of and ignore any invalid IM addresses */
+ warning (e.message);
}
}
using GLib;
/**
+ * Errors related to IM addresses and IM address handling.
+ */
+public errordomain Folks.IMableError
+{
+ /**
+ * The specified IM address could not be parsed.
+ */
+ INVALID_IM_ADDRESS
+}
+
+/**
* IM addresses exposed by an object implementing {@link HasPresence}.
*
* @since 0.1.13
* only one of which is canonical. In order to allow simple string comparisons
* of IM addresses to work, the IM addresses must be normalised beforehand.
*
+ * If the provided IM address is invalid,
+ * {@link Folks.IMableError.INVALID_IM_ADDRESS} will be thrown. Note that this
+ * isn't guaranteed to be thrown for all invalid addresses, but if it is
+ * thrown, the address is guaranteed to be invalid.
+ *
* @param im_address the address to normalise
* @param protocol the protocol of this im_address
*
* @since 0.2.0
+ * @throws Folks.IMableError if the provided IM address was invalid
*/
public static string normalise_im_address (string im_address, string protocol)
+ throws Folks.IMableError
{
string normalised;
/* Parse the JID */
string[] parts = im_address.split ("/", 2);
- return_val_if_fail (parts.length >= 1, null);
+ if (parts.length < 1)
+ {
+ throw new IMableError.INVALID_IM_ADDRESS (
+ /* Translators: the parameter is an IM address. */
+ _("The IM address '%s' could not be understood."),
+ im_address);
+ }
string resource = null;
if (parts.length == 2)
parts = parts[0].split ("@", 2);
- return_val_if_fail (parts.length >= 1, null);
+ if (parts.length < 1)
+ {
+ throw new IMableError.INVALID_IM_ADDRESS (
+ /* Translators: the parameter is an IM address. */
+ _("The IM address '%s' could not be understood."),
+ im_address);
+ }
string node, domain;
if (parts.length == 2)
domain = parts[0];
}
- return_val_if_fail (node == null || node != "", null);
- return_val_if_fail (domain != null && domain != "", null);
- return_val_if_fail (resource == null || resource != "", null);
+ if ((node != null && node == "") ||
+ (domain == null || domain == "") ||
+ (resource != null && resource == ""))
+ {
+ throw new IMableError.INVALID_IM_ADDRESS (
+ /* Translators: the parameter is an IM address. */
+ _("The IM address '%s' could not be understood."),
+ im_address);
+ }
domain = domain.down ();
if (node != null)
/* Build a new JID */
if (node != null && resource != null)
- normalised = "%s@%s/%s".printf (node, domain, resource);
+ {
+ normalised = "%s@%s/%s".printf (node, domain, resource);
+ }
else if (node != null)
- normalised = "%s@%s".printf (node, domain);
+ {
+ normalised = "%s@%s".printf (node, domain);
+ }
else if (resource != null)
- normalised = "%s/%s".printf (domain, resource);
+ {
+ normalised = "%s/%s".printf (domain, resource);
+ }
else
- assert_not_reached ();
+ {
+ throw new IMableError.INVALID_IM_ADDRESS (
+ /* Translators: the parameter is an IM address. */
+ _("The IM address '%s' could not be understood."),
+ im_address);
+ }
}
else
{