[libgdata] [core] Move all boolean property parsing into one function



commit 3d42629c55cdaef4901d7cb343e3696a87d12030
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Mar 22 21:55:47 2010 +0000

    [core] Move all boolean property parsing into one function

 gdata/gd/gdata-gd-email-address.c                 |   26 ++++--------
 gdata/gd/gdata-gd-im-address.c                    |   22 ++--------
 gdata/gd/gdata-gd-organization.c                  |   20 ++-------
 gdata/gd/gdata-gd-phone-number.c                  |   21 ++-------
 gdata/gd/gdata-gd-postal-address.c                |   22 +++-------
 gdata/gdata-parser.c                              |   44 +++++++++++++++++++++
 gdata/gdata-parser.h                              |    4 ++
 gdata/media/gdata-media-content.c                 |   11 +-----
 gdata/services/calendar/gdata-calendar-calendar.c |   14 ++-----
 gdata/services/calendar/gdata-calendar-event.c    |   36 +++++++---------
 gdata/services/contacts/gdata-contacts-contact.c  |   13 +-----
 gdata/services/documents/gdata-documents-entry.c  |   11 +-----
 12 files changed, 103 insertions(+), 141 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-email-address.c b/gdata/gd/gdata-gd-email-address.c
index 12b8880..893dae4 100644
--- a/gdata/gd/gdata-gd-email-address.c
+++ b/gdata/gd/gdata-gd-email-address.c
@@ -240,34 +240,26 @@ gdata_gd_email_address_set_property (GObject *object, guint property_id, const G
 static gboolean
 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
 {
-	xmlChar *address, *rel, *primary;
+	xmlChar *address, *rel;
 	gboolean primary_bool;
 	GDataGDEmailAddressPrivate *priv = GDATA_GD_EMAIL_ADDRESS (parsable)->priv;
 
+	/* Is it the primary e-mail address? */
+	if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
+		return FALSE;
+
 	address = xmlGetProp (root_node, (xmlChar*) "address");
-	if (address == NULL || *address == '\0')
+	if (address == NULL || *address == '\0') {
+		xmlFree (address);
 		return gdata_parser_error_required_property_missing (root_node, "address", error);
+	}
 
 	rel = xmlGetProp (root_node, (xmlChar*) "rel");
 	if (rel != NULL && *rel == '\0') {
 		xmlFree (address);
-		return gdata_parser_error_required_property_missing (root_node, "rel", error);
-	}
-
-	/* Is it the primary e-mail address? */
-	primary = xmlGetProp (root_node, (xmlChar*) "primary");
-	if (primary == NULL || xmlStrcmp (primary, (xmlChar*) "false") == 0)
-		primary_bool = FALSE;
-	else if (xmlStrcmp (primary, (xmlChar*) "true") == 0)
-		primary_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "primary", (gchar*) primary, error);
-		xmlFree (primary);
-		xmlFree (address);
 		xmlFree (rel);
-		return FALSE;
+		return gdata_parser_error_required_property_missing (root_node, "rel", error);
 	}
-	xmlFree (primary);
 
 	priv->address = (gchar*) address;
 	priv->relation_type = (gchar*) rel;
diff --git a/gdata/gd/gdata-gd-im-address.c b/gdata/gd/gdata-gd-im-address.c
index 4199952..69d828a 100644
--- a/gdata/gd/gdata-gd-im-address.c
+++ b/gdata/gd/gdata-gd-im-address.c
@@ -240,10 +240,14 @@ gdata_gd_im_address_set_property (GObject *object, guint property_id, const GVal
 static gboolean
 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
 {
-	xmlChar *address, *protocol, *rel, *primary;
+	xmlChar *address, *protocol, *rel;
 	gboolean primary_bool;
 	GDataGDIMAddressPrivate *priv = GDATA_GD_IM_ADDRESS (parsable)->priv;
 
+	/* Is it the primary IM address? */
+	if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
+		return FALSE;
+
 	address = xmlGetProp (root_node, (xmlChar*) "address");
 	if (address == NULL || *address == '\0')
 		return gdata_parser_error_required_property_missing (root_node, "address", error);
@@ -255,22 +259,6 @@ pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointe
 	}
 	protocol = xmlGetProp (root_node, (xmlChar*) "protocol");
 
-	/* Is it the primary IM address? */
-	primary = xmlGetProp (root_node, (xmlChar*) "primary");
-	if (primary == NULL || xmlStrcmp (primary, (xmlChar*) "false") == 0)
-		primary_bool = FALSE;
-	else if (xmlStrcmp (primary, (xmlChar*) "true") == 0)
-		primary_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "primary", (gchar*) primary, error);
-		xmlFree (primary);
-		xmlFree (address);
-		xmlFree (protocol);
-		xmlFree (rel);
-		return FALSE;
-	}
-	xmlFree (primary);
-
 	priv->address = (gchar*) address;
 	priv->protocol = (gchar*) protocol;
 	priv->relation_type = (gchar*) rel;
diff --git a/gdata/gd/gdata-gd-organization.c b/gdata/gd/gdata-gd-organization.c
index 12ea137..209b830 100644
--- a/gdata/gd/gdata-gd-organization.c
+++ b/gdata/gd/gdata-gd-organization.c
@@ -360,30 +360,20 @@ gdata_gd_organization_set_property (GObject *object, guint property_id, const GV
 static gboolean
 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
 {
-	xmlChar *rel, *primary;
+	xmlChar *rel;
 	gboolean primary_bool;
 	GDataGDOrganizationPrivate *priv = GDATA_GD_ORGANIZATION (parsable)->priv;
 
+	/* Is it the primary organisation? */
+	if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
+		return FALSE;
+
 	rel = xmlGetProp (root_node, (xmlChar*) "rel");
 	if (rel != NULL && *rel == '\0') {
 		xmlFree (rel);
 		return gdata_parser_error_required_property_missing (root_node, "rel", error);
 	}
 
-	/* Is it the primary organisation? */
-	primary = xmlGetProp (root_node, (xmlChar*) "primary");
-	if (primary == NULL || xmlStrcmp (primary, (xmlChar*) "false") == 0)
-		primary_bool = FALSE;
-	else if (xmlStrcmp (primary, (xmlChar*) "true") == 0)
-		primary_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "primary", (gchar*) primary, error);
-		xmlFree (primary);
-		xmlFree (rel);
-		return FALSE;
-	}
-	xmlFree (primary);
-
 	priv->relation_type = (gchar*) rel;
 	priv->label = (gchar*) xmlGetProp (root_node, (xmlChar*) "label");
 	priv->is_primary = primary_bool;
diff --git a/gdata/gd/gdata-gd-phone-number.c b/gdata/gd/gdata-gd-phone-number.c
index 2cdb19b..9e9cf04 100644
--- a/gdata/gd/gdata-gd-phone-number.c
+++ b/gdata/gd/gdata-gd-phone-number.c
@@ -245,10 +245,14 @@ gdata_gd_phone_number_set_property (GObject *object, guint property_id, const GV
 static gboolean
 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
 {
-	xmlChar *number, *rel, *primary;
+	xmlChar *number, *rel;
 	gboolean primary_bool;
 	GDataGDPhoneNumberPrivate *priv = GDATA_GD_PHONE_NUMBER (parsable)->priv;
 
+	/* Is it the primary phone number? */
+	if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
+		return FALSE;
+
 	number = xmlNodeListGetString (doc, root_node->children, TRUE);
 	if (number == NULL || *number == '\0') {
 		xmlFree (number);
@@ -262,21 +266,6 @@ pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointe
 		return gdata_parser_error_required_property_missing (root_node, "rel", error);
 	}
 
-	/* Is it the primary phone number? */
-	primary = xmlGetProp (root_node, (xmlChar*) "primary");
-	if (primary == NULL || xmlStrcmp (primary, (xmlChar*) "false") == 0)
-		primary_bool = FALSE;
-	else if (xmlStrcmp (primary, (xmlChar*) "true") == 0)
-		primary_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "primary", (gchar*) primary, error);
-		xmlFree (primary);
-		xmlFree (rel);
-		xmlFree (number);
-		return FALSE;
-	}
-	xmlFree (primary);
-
 	gdata_gd_phone_number_set_number (GDATA_GD_PHONE_NUMBER (parsable), (gchar*) number);
 	priv->uri = (gchar*) xmlGetProp (root_node, (xmlChar*) "uri");
 	priv->relation_type = (gchar*) rel;
diff --git a/gdata/gd/gdata-gd-postal-address.c b/gdata/gd/gdata-gd-postal-address.c
index 1d579f2..4f70da7 100644
--- a/gdata/gd/gdata-gd-postal-address.c
+++ b/gdata/gd/gdata-gd-postal-address.c
@@ -545,27 +545,19 @@ gdata_gd_postal_address_set_property (GObject *object, guint property_id, const
 static gboolean
 pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
 {
-	xmlChar *rel, *primary;
+	xmlChar *rel;
 	gboolean primary_bool;
 	GDataGDPostalAddressPrivate *priv = GDATA_GD_POSTAL_ADDRESS (parsable)->priv;
 
-	rel = xmlGetProp (root_node, (xmlChar*) "rel");
-	if (rel != NULL && *rel == '\0')
-		return gdata_parser_error_required_property_missing (root_node, "rel", error);
-
 	/* Is it the primary postal address? */
-	primary = xmlGetProp (root_node, (xmlChar*) "primary");
-	if (primary == NULL || xmlStrcmp (primary, (xmlChar*) "false") == 0)
-		primary_bool = FALSE;
-	else if (xmlStrcmp (primary, (xmlChar*) "true") == 0)
-		primary_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "primary", (gchar*) primary, error);
-		xmlFree (primary);
-		xmlFree (rel);
+	if (gdata_parser_boolean_from_property (root_node, "primary", &primary_bool, 0, error) == FALSE)
 		return FALSE;
+
+	rel = xmlGetProp (root_node, (xmlChar*) "rel");
+	if (rel != NULL && *rel == '\0') {
+		xmlFree (rel);
+		return gdata_parser_error_required_property_missing (root_node, "rel", error);
 	}
-	xmlFree (primary);
 
 	priv->relation_type = (gchar*) rel;
 	priv->label = (gchar*) xmlGetProp (root_node, (xmlChar*) "label");
diff --git a/gdata/gdata-parser.c b/gdata/gdata-parser.c
index e719c19..92d4a5b 100644
--- a/gdata/gdata-parser.c
+++ b/gdata/gdata-parser.c
@@ -204,6 +204,49 @@ gdata_parser_date_from_time_val (const GTimeVal *_time)
 	return g_strdup_printf ("%4d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
 }
 
+/*
+ * gdata_parser_boolean_from_property:
+ * @element: the XML element which owns the property to parse
+ * @property_name: the name of the property to parse
+ * @output: the return location for the parsed boolean value
+ * @default_output: the default value to return in @output if the property can't be found
+ * @error: a #GError, or %NULL
+ *
+ * Parses a GData boolean value from the property @property_name of @element.
+ * The boolean value should be of the form: "<element property_name='[true|false]'/>".
+ * A %GDATA_SERVICE_ERROR_PROTOCOL_ERROR error will be returned in @error if parsing fails, and @output will not be set.
+ *
+ * If no property with the name @property_name exists in @element and @default_output is %0, @output will be set to %FALSE.
+ * If @default_output is %1, @output will be set to %TRUE. If @default_output is %-1, a %GDATA_SERVICE_ERROR_PROTOCOL_ERROR will be
+ * returned in @error.
+ *
+ * Return value: %TRUE on successful parsing, %FALSE otherwise
+ */
+gboolean
+gdata_parser_boolean_from_property (xmlNode *element, const gchar *property_name, gboolean *output, gint default_output, GError **error)
+{
+	xmlChar *value = xmlGetProp (element, (xmlChar*) property_name);
+
+	if (value == NULL) {
+		/* Missing property */
+		if (default_output == -1)
+			return gdata_parser_error_required_property_missing (element, property_name, error);
+		*output = (default_output == 1) ? TRUE : FALSE;
+	} else if (xmlStrcmp (value, (xmlChar*) "false") == 0) {
+		*output = FALSE;
+	} else if (xmlStrcmp (value, (xmlChar*) "true") == 0) {
+		*output = TRUE;
+	} else {
+		/* Parsing failed */
+		gdata_parser_error_unknown_property_value (element, property_name, (gchar*) value, error);
+		xmlFree (value);
+		return FALSE;
+	}
+
+	xmlFree (value);
+	return TRUE;
+}
+
 void
 gdata_parser_string_append_escaped (GString *xml_string, const gchar *pre, const gchar *element_content, const gchar *post)
 {
@@ -272,6 +315,7 @@ gdata_parser_string_append_escaped (GString *xml_string, const gchar *pre, const
 		g_string_append (xml_string, post);
 }
 
+/* TODO: Should be perfectly possible to make this modify the string in-place */
 gchar *
 gdata_parser_utf8_trim_whitespace (const gchar *s)
 {
diff --git a/gdata/gdata-parser.h b/gdata/gdata-parser.h
index 68f4555..7a445d5 100644
--- a/gdata/gdata-parser.h
+++ b/gdata/gdata-parser.h
@@ -31,8 +31,12 @@ gboolean gdata_parser_error_unknown_content (xmlNode *element, const gchar *actu
 gboolean gdata_parser_error_required_property_missing (xmlNode *element, const gchar *property_name, GError **error);
 gboolean gdata_parser_error_required_element_missing (const gchar *element_name, const gchar *parent_element_name, GError **error);
 gboolean gdata_parser_error_duplicate_element (xmlNode *element, GError **error);
+
 gboolean gdata_parser_time_val_from_date (const gchar *date, GTimeVal *_time);
 gchar *gdata_parser_date_from_time_val (const GTimeVal *_time) G_GNUC_WARN_UNUSED_RESULT;
+
+gboolean gdata_parser_boolean_from_property (xmlNode *element, const gchar *property_name, gboolean *output, gint default_output, GError **error);
+
 void gdata_parser_string_append_escaped (GString *xml_string, const gchar *pre, const gchar *element_content, const gchar *post);
 gchar *gdata_parser_utf8_trim_whitespace (const gchar *s) G_GNUC_WARN_UNUSED_RESULT;
 
diff --git a/gdata/media/gdata-media-content.c b/gdata/media/gdata-media-content.c
index b49636f..abb0f4f 100644
--- a/gdata/media/gdata-media-content.c
+++ b/gdata/media/gdata-media-content.c
@@ -298,17 +298,8 @@ pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointe
 	gulong filesize_ulong;
 
 	/* Parse isDefault */
-	is_default = xmlGetProp (root_node, (xmlChar*) "isDefault");
-	if (is_default == NULL || xmlStrcmp (is_default, (xmlChar*) "false") == 0)
-		is_default_bool = FALSE;
-	else if (xmlStrcmp (is_default, (xmlChar*) "true") == 0)
-		is_default_bool = TRUE;
-	else {
-		gdata_parser_error_unknown_property_value (root_node, "isDefault", (gchar*) is_default, error);
-		xmlFree (is_default);
+	if (gdata_parser_boolean_from_property (root_node, "isDefault", &is_default_bool, 0, error) == FALSE)
 		return FALSE;
-	}
-	xmlFree (is_default);
 
 	/* Parse expression */
 	expression = xmlGetProp (root_node, (xmlChar*) "expression");
diff --git a/gdata/services/calendar/gdata-calendar-calendar.c b/gdata/services/calendar/gdata-calendar-calendar.c
index 3e25273..df92a2e 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.c
+++ b/gdata/services/calendar/gdata-calendar-calendar.c
@@ -305,11 +305,8 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 		xmlFree (times_cleaned);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "hidden") == 0) {
 		/* gCal:hidden */
-		xmlChar *hidden = xmlGetProp (node, (xmlChar*) "value");
-		if (hidden == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_calendar_set_is_hidden (self, (xmlStrcmp (hidden, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (hidden);
+		if (gdata_parser_boolean_from_property (node, "value", &(self->priv->is_hidden), -1, error) == FALSE)
+			return FALSE;
 	} else if (xmlStrcmp (node->name, (xmlChar*) "color") == 0) {
 		/* gCal:color */
 		xmlChar *value;
@@ -336,11 +333,8 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 		xmlFree (value);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "selected") == 0) {
 		/* gCal:selected */
-		xmlChar *selected = xmlGetProp (node, (xmlChar*) "value");
-		if (selected == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_calendar_set_is_selected (self, (xmlStrcmp (selected, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (selected);
+		if (gdata_parser_boolean_from_property (node, "value", &(self->priv->is_selected), -1, error) == FALSE)
+			return FALSE;
 	} else if (xmlStrcmp (node->name, (xmlChar*) "accesslevel") == 0) {
 		/* gCal:accesslevel */
 		self->priv->access_level = (gchar*) xmlGetProp (node, (xmlChar*) "value");
diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c
index c1834a5..b1ca713 100644
--- a/gdata/services/calendar/gdata-calendar-event.c
+++ b/gdata/services/calendar/gdata-calendar-event.c
@@ -537,32 +537,28 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 		gdata_calendar_event_add_time (self, when);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "guestsCanModify") == 0) {
 		/* gCal:guestsCanModify */
-		xmlChar *value = xmlGetProp (node, (xmlChar*) "value");
-		if (value == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_event_set_guests_can_modify (self, (xmlStrcmp (value, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (value);
+		gboolean guests_can_modify;
+		if (gdata_parser_boolean_from_property (node, "value", &guests_can_modify, -1, error) == FALSE)
+			return FALSE;
+		gdata_calendar_event_set_guests_can_modify (self, guests_can_modify);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "guestsCanInviteOthers") == 0) {
 		/* gCal:guestsCanInviteOthers */
-		xmlChar *value = xmlGetProp (node, (xmlChar*) "value");
-		if (value == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_event_set_guests_can_invite_others (self, (xmlStrcmp (value, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (value);
+		gboolean guests_can_invite_others;
+		if (gdata_parser_boolean_from_property (node, "value", &guests_can_invite_others, -1, error) == FALSE)
+			return FALSE;
+		gdata_calendar_event_set_guests_can_invite_others (self, guests_can_invite_others);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "guestsCanSeeGuests") == 0) {
 		/* gCal:guestsCanSeeGuests */
-		xmlChar *value = xmlGetProp (node, (xmlChar*) "value");
-		if (value == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_event_set_guests_can_see_guests (self, (xmlStrcmp (value, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (value);
+		gboolean guests_can_see_guests;
+		if (gdata_parser_boolean_from_property (node, "value", &guests_can_see_guests, -1, error) == FALSE)
+			return FALSE;
+		gdata_calendar_event_set_guests_can_see_guests (self, guests_can_see_guests);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "anyoneCanAddSelf") == 0) {
 		/* gCal:anyoneCanAddSelf */
-		xmlChar *value = xmlGetProp (node, (xmlChar*) "value");
-		if (value == NULL)
-			return gdata_parser_error_required_property_missing (node, "value", error);
-		gdata_calendar_event_set_anyone_can_add_self (self, (xmlStrcmp (value, (xmlChar*) "true") == 0) ? TRUE : FALSE);
-		xmlFree (value);
+		gboolean anyone_can_add_self;
+		if (gdata_parser_boolean_from_property (node, "value", &anyone_can_add_self, -1, error) == FALSE)
+			return FALSE;
+		gdata_calendar_event_set_anyone_can_add_self (self, anyone_can_add_self);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "who") == 0) {
 		/* gd:who */
 		GDataGDWho *who = GDATA_GD_WHO (_gdata_parsable_new_from_xml_node (GDATA_TYPE_GD_WHO, doc, node, NULL, error));
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index 277437d..207db82 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -386,7 +386,7 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 			g_free (value);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "groupMembershipInfo") == 0) {
 		/* gContact:groupMembershipInfo */
-		xmlChar *href, *deleted;
+		xmlChar *href;
 		gboolean deleted_bool;
 
 		href = xmlGetProp (node, (xmlChar*) "href");
@@ -394,17 +394,8 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 			return gdata_parser_error_required_property_missing (node, "href", error);
 
 		/* Has it been deleted? */
-		deleted = xmlGetProp (node, (xmlChar*) "deleted");
-		if (deleted == NULL || xmlStrcmp (deleted, (xmlChar*) "false") == 0)
-			deleted_bool = FALSE;
-		else if (xmlStrcmp (deleted, (xmlChar*) "true") == 0)
-			deleted_bool = TRUE;
-		else {
-			gdata_parser_error_unknown_property_value (node, "deleted", (gchar*) deleted, error);
-			g_free (deleted);
+		if (gdata_parser_boolean_from_property (node, "deleted", &deleted_bool, 0, error) == FALSE)
 			return FALSE;
-		}
-		g_free (deleted);
 
 		/* Insert it into the hash table */
 		g_hash_table_insert (self->priv->groups, (gchar*) href, GUINT_TO_POINTER (deleted_bool));
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index ab33fe5..1bcc4f1 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -220,17 +220,8 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 		}
 		xmlFree (last_viewed);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "writersCanInvite") ==  0) {
-		xmlChar *writers_can_invite = xmlGetProp (node, (xmlChar*) "value");
-		if (xmlStrcmp (writers_can_invite, (xmlChar*) "true") == 0) {
-			self->priv->writers_can_invite = TRUE;
-		} else if (xmlStrcmp (writers_can_invite, (xmlChar*) "false") == 0) {
-			self->priv->writers_can_invite = FALSE;
-		} else {
-			gdata_parser_error_unknown_property_value (node, "value", (gchar*) writers_can_invite, error);
-			xmlFree (writers_can_invite);
+		if (gdata_parser_boolean_from_property (node, "value", &(self->priv->writers_can_invite), -1, error) == FALSE)
 			return FALSE;
-		}
-		xmlFree (writers_can_invite);
 	} else if (xmlStrcmp (node->name, (xmlChar*) "deleted") ==  0) {
 		/* <gd:deleted> */
 		/* Note that it doesn't have any parameters, so we unconditionally set priv->is_deleted to TRUE */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]