[libgdata] contacts: Require the content type of new contact photos to be passed
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] contacts: Require the content type of new contact photos to be passed
- Date: Fri, 10 Dec 2010 20:02:35 +0000 (UTC)
commit a456b9be8884b2bc9d39ffd09e54b2ce1d0b1ca5
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Dec 10 19:25:10 2010 +0000
contacts: Require the content type of new contact photos to be passed
Google's servers technically require a precise content type for image data
which is uploaded by gdata_contacts_contact_set_photo(), so it's necessary
to add a content type argument to the method.
This breaks the API of gdata_contacts_contact_set_photo().
gdata/services/contacts/gdata-contacts-contact.c | 8 +++++---
gdata/services/contacts/gdata-contacts-contact.h | 2 +-
gdata/tests/contacts.c | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index 8551872..76bb6dc 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -3128,10 +3128,11 @@ gdata_contacts_contact_get_photo_finish (GDataContactsContact *self, GAsyncResul
* @service: a #GDataService
* @data: (allow-none): the image data, or %NULL
* @length: the image length, in bytes
+ * @content_type: (allow-none): the content type of the image, or %NULL
* @cancellable: optional #GCancellable object, or %NULL
* @error: a #GError, or %NULL
*
- * Sets the contact's photo to @data or, if @data is %NULL, deletes the contact's photo.
+ * Sets the contact's photo to @data or, if @data is %NULL, deletes the contact's photo. @content_type must be specified if @data is non-%NULL.
*
* If @cancellable is not %NULL, then the operation can be cancelled by triggering the @cancellable object from another thread.
* If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
@@ -3143,7 +3144,7 @@ gdata_contacts_contact_get_photo_finish (GDataContactsContact *self, GAsyncResul
* Since: 0.8.0
**/
gboolean
-gdata_contacts_contact_set_photo (GDataContactsContact *self, GDataService *service, const guint8 *data, gsize length,
+gdata_contacts_contact_set_photo (GDataContactsContact *self, GDataService *service, const guint8 *data, gsize length, const gchar *content_type,
GCancellable *cancellable, GError **error)
{
GDataLink *_link;
@@ -3154,6 +3155,7 @@ gdata_contacts_contact_set_photo (GDataContactsContact *self, GDataService *serv
/* TODO: async version */
g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), FALSE);
g_return_val_if_fail (GDATA_IS_SERVICE (service), FALSE);
+ g_return_val_if_fail (data == NULL || content_type != NULL, FALSE);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -3170,7 +3172,7 @@ gdata_contacts_contact_set_photo (GDataContactsContact *self, GDataService *serv
/* Append the data */
if (deleting_photo == FALSE)
- soup_message_set_request (message, "image/*", SOUP_MEMORY_STATIC, (gchar*) data, length);
+ soup_message_set_request (message, content_type, SOUP_MEMORY_STATIC, (gchar*) data, length);
/* Send the message */
status = _gdata_service_send_message (service, message, cancellable, error);
diff --git a/gdata/services/contacts/gdata-contacts-contact.h b/gdata/services/contacts/gdata-contacts-contact.h
index ad63679..6a5ebdd 100644
--- a/gdata/services/contacts/gdata-contacts-contact.h
+++ b/gdata/services/contacts/gdata-contacts-contact.h
@@ -287,7 +287,7 @@ guint8 *gdata_contacts_contact_get_photo_finish (GDataContactsContact *self, GAs
GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
gboolean gdata_contacts_contact_set_photo (GDataContactsContact *self, GDataService *service, const guint8 *data, gsize length,
- GCancellable *cancellable, GError **error);
+ const gchar *content_type, GCancellable *cancellable, GError **error);
G_END_DECLS
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index 960d0fe..14efeb8 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -1579,7 +1579,7 @@ test_photo_add (gconstpointer service)
/* Add it to the contact */
contact = get_contact (service);
- retval = gdata_contacts_contact_set_photo (contact, GDATA_SERVICE (service), data, length, NULL, &error);
+ retval = gdata_contacts_contact_set_photo (contact, GDATA_SERVICE (service), data, length, "image/jpeg", NULL, &error);
g_assert_no_error (error);
g_assert (retval == TRUE);
@@ -1668,7 +1668,7 @@ test_photo_delete (gconstpointer service)
g_assert (gdata_contacts_contact_has_photo (contact) == TRUE);
/* Remove the contact's photo */
- g_assert (gdata_contacts_contact_set_photo (contact, GDATA_SERVICE (service), NULL, 0, NULL, &error) == TRUE);
+ g_assert (gdata_contacts_contact_set_photo (contact, GDATA_SERVICE (service), NULL, 0, NULL, NULL, &error) == TRUE);
g_assert_no_error (error);
g_assert (gdata_contacts_contact_has_photo (contact) == FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]