summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2017-01-08 23:04:40 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2017-01-08 23:24:59 +0000
commit74c429d0da0f8b218cf578d46df791532aa1e1c6 (patch)
treed61d313bee3c23954d116efe2b31b8d83e5ffb3b
parentc2610d1c15cbccd72529e25482045e7545e3b576 (diff)
downloadlibgdata-74c429d0da0f8b218cf578d46df791532aa1e1c6.tar.gz
core: Improve GDataAccessRule validation
-rw-r--r--gdata/gdata-access-rule.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index 9b2c1f76..2ee3e00c 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -95,6 +95,7 @@ static void get_xml (GDataParsable *parsable, GString *xml_string);
static void gdata_access_rule_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void gdata_access_rule_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
+static gboolean post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error);
struct _GDataAccessRulePrivate {
gchar *role;
@@ -130,6 +131,7 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
gobject_class->set_property = gdata_access_rule_set_property;
parsable_class->parse_xml = parse_xml;
+ parsable_class->post_parse_xml = post_parse_xml;
parsable_class->get_xml = get_xml;
parsable_class->get_namespaces = get_namespaces;
@@ -372,8 +374,10 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
xmlChar *scope_type, *scope_value;
scope_type = xmlGetProp (node, (xmlChar*) "type");
- if (scope_type == NULL)
+ if (scope_type == NULL || *scope_type == '\0') {
+ xmlFree (scope_type);
return gdata_parser_error_required_property_missing (node, "type", error);
+ }
scope_value = xmlGetProp (node, (xmlChar*) "value");
@@ -436,6 +440,20 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
return TRUE;
}
+static gboolean
+post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error)
+{
+ GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
+
+ /* Check for missing required elements */
+ if (gdata_entry_get_title (GDATA_ENTRY (parsable)) == NULL || *gdata_entry_get_title (GDATA_ENTRY (parsable)) == '\0')
+ return gdata_parser_error_required_element_missing ("role", "entry", error);
+ if (priv->scope_type == NULL)
+ return gdata_parser_error_required_element_missing ("scope", "entry", error);
+
+ return TRUE;
+}
+
static void
get_xml (GDataParsable *parsable, GString *xml_string)
{
@@ -559,7 +577,7 @@ void
gdata_access_rule_set_scope (GDataAccessRule *self, const gchar *type, const gchar *value)
{
g_return_if_fail (GDATA_IS_ACCESS_RULE (self));
- g_return_if_fail (type != NULL);
+ g_return_if_fail (type != NULL && *type != '\0');
g_return_if_fail ((strcmp (type, GDATA_ACCESS_SCOPE_DEFAULT) == 0 && value == NULL) || value != NULL);
g_free (self->priv->scope_type);