[Telepathy-commits] [telepathy-haze/master] Check that the mime type passed to SetAvatar is acceptable
Will Thompson
will.thompson at collabora.co.uk
Tue Mar 24 05:44:01 PDT 2009
---
src/connection-avatars.c | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/src/connection-avatars.c b/src/connection-avatars.c
index df9c121..f957b23 100644
--- a/src/connection-avatars.c
+++ b/src/connection-avatars.c
@@ -349,15 +349,20 @@ haze_connection_set_avatar (TpSvcConnectionInterfaceAvatars *self,
PurpleAccount *account = conn->account;
PurplePluginProtocolInfo *prpl_info = HAZE_CONNECTION_GET_PRPL_INFO (conn);
+ GError *error = NULL;
+ gchar *message;
+
guchar *icon_data = NULL;
size_t icon_len = avatar->len;
gchar *token;
+ gchar **mime_types = _get_acceptable_mime_types (conn);
+
+ gboolean acceptable_mime_type = FALSE;
const size_t max_filesize = prpl_info->icon_spec.max_filesize;
if (max_filesize > 0 && icon_len > max_filesize)
{
- GError *error = NULL;
g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
"avatar is %" G_GSIZE_FORMAT "B, "
"but the limit is %" G_GSIZE_FORMAT "B",
@@ -369,6 +374,28 @@ haze_connection_set_avatar (TpSvcConnectionInterfaceAvatars *self,
return;
}
+ while (!acceptable_mime_type && *mime_types != NULL)
+ {
+ if (!tp_strdiff (*mime_types, mime_type))
+ acceptable_mime_type = TRUE;
+ mime_types++;
+ }
+
+ if (!acceptable_mime_type)
+ {
+ message = g_strdup_printf ("'%s' is not a supported MIME type",
+ mime_type);
+ g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, message);
+
+ dbus_g_method_return_error (context, error);
+
+ g_error_free (error);
+ g_free (message);
+
+ return;
+ }
+
+
/* purple_buddy_icons_set_account_icon () takes ownership of the pointer
* passed to it, but 'avatar' will be freed soon.
*/
--
1.5.6.5
More information about the telepathy-commits
mailing list