예제 #1
0
static gboolean
post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error)
{
	GDataDocumentsAccessRulePrivate *priv;

	priv = gdata_documents_access_rule_get_instance_private (GDATA_DOCUMENTS_ACCESS_RULE (parsable));

	if (g_strcmp0 (priv->scope_type, GDATA_ACCESS_SCOPE_DEFAULT) == 0) {
		gdata_access_rule_set_scope (GDATA_ACCESS_RULE (parsable), priv->scope_type, NULL);
	} else if (g_strcmp0 (priv->scope_type, "group") == 0 || g_strcmp0 (priv->scope_type, GDATA_ACCESS_SCOPE_USER) == 0) {
		if (priv->email == NULL || priv->email[0] == '\0') {
			g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING,
			             /* Translators: the parameter is an error message */
			             _("Error parsing JSON: %s"),
			             "Permission type ‘group’ or ‘user’ needs an ‘emailAddress’ property.");
			return FALSE;
		} else {
			gdata_access_rule_set_scope (GDATA_ACCESS_RULE (parsable), priv->scope_type, priv->email);
		}
	} else if (g_strcmp0 (priv->scope_type, GDATA_ACCESS_SCOPE_DOMAIN) == 0) {
		if (priv->domain == NULL || priv->domain[0] == '\0') {
			g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING,
			             /* Translators: the parameter is an error message */
			             _("Error parsing JSON: %s"),
			             "Permission type ‘domain’ needs a ‘domain’ property.");
			return FALSE;
		} else {
			gdata_access_rule_set_scope (GDATA_ACCESS_RULE (parsable), priv->scope_type, priv->domain);
		}
	}

	return TRUE;
}
static gboolean
parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
{
	gboolean success;

	if (g_strcmp0 (json_reader_get_member_name (reader), "role") == 0) {
		gchar *role = NULL;  /* owned */

		g_assert (gdata_parser_string_from_json_member (reader, "role",
		                                                P_REQUIRED |
		                                                P_NON_EMPTY,
		                                                &role, &success,
		                                                error));

		if (!success) {
			return FALSE;
		}

		gdata_access_rule_set_role (GDATA_ACCESS_RULE (parsable),
		                            role_v3_to_v2 (role));
		g_free (role);

		return TRUE;
	} else if (g_strcmp0 (json_reader_get_member_name (reader),
	                                                   "scope") == 0) {
		const gchar *scope_type;
		const gchar *scope_value;

		/* Check this is an object. */
		if (!json_reader_is_object (reader)) {
			return gdata_parser_error_required_json_content_missing (reader,
			                                                         error);
		}

		json_reader_read_member (reader, "type");
		scope_type = json_reader_get_string_value (reader);
		json_reader_end_member (reader);

		json_reader_read_member (reader, "value");
		scope_value = json_reader_get_string_value (reader);
		json_reader_end_member (reader);

		/* Scope type is required. */
		if (scope_type == NULL) {
			return gdata_parser_error_required_json_content_missing (reader,
			                                                         error);
		}

		gdata_access_rule_set_scope (GDATA_ACCESS_RULE (parsable),
		                             scope_type_v3_to_v2 (scope_type),
		                             scope_value);

		return TRUE;
	}

	return GDATA_PARSABLE_CLASS (gdata_calendar_access_rule_parent_class)->parse_json (parsable, reader, user_data, error);
}