[libgdata/wip/rishi/drive: 3/4] core: Add a comment pointing to the Drive permissions API



commit ffb5c0294b0db86bc0658acd932e87563c97397d
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jun 5 13:48:56 2015 +0200

    core: Add a comment pointing to the Drive permissions API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 gdata/gdata-access-rule.c                          |   67 ------------
 .../documents/gdata-documents-access-rule.c        |  108 +++++++++++++++++++-
 2 files changed, 104 insertions(+), 71 deletions(-)
---
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index 23691f7..ec94f02 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -96,13 +96,9 @@ 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 parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
-static gboolean post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error);
 static void get_json (GDataParsable *parsable, JsonBuilder *builder);
 
 struct _GDataAccessRulePrivate {
-       gchar *domain;
-       gchar *email;
        gchar *role;
        gchar *scope_type;
        gchar *scope_value;
@@ -139,8 +135,6 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
        parsable_class->get_xml = get_xml;
        parsable_class->get_namespaces = get_namespaces;
 
-       parsable_class->parse_json = parse_json;
-       parsable_class->post_parse_json = post_parse_json;
        parsable_class->get_json = get_json;
 
        entry_class->kind_term = "http://schemas.google.com/acl/2007#accessRule";;
@@ -287,8 +281,6 @@ gdata_access_rule_finalize (GObject *object)
 {
        GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (object)->priv;
 
-       g_free (priv->domain);
-       g_free (priv->email);
        g_free (priv->role);
        g_free (priv->scope_type);
        g_free (priv->scope_value);
@@ -495,65 +487,6 @@ get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
        g_hash_table_insert (namespaces, (gchar*) "gAcl", (gchar*) "http://schemas.google.com/acl/2007";);
 }
 
-static gboolean
-parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
-{
-       GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
-       gboolean success;
-       gchar *scope_type = NULL;
-
-       if (gdata_parser_string_from_json_member (reader, "authKey", P_REQUIRED | P_NON_EMPTY, &(priv->key), 
&success, error) == TRUE ||
-           gdata_parser_string_from_json_member (reader, "emailAddress", P_REQUIRED | P_NON_EMPTY, 
&(priv->email), &success, error) == TRUE ||
-           gdata_parser_string_from_json_member (reader, "domain", P_REQUIRED | P_NON_EMPTY, 
&(priv->domain), &success, error) == TRUE ||
-           gdata_parser_string_from_json_member (reader, "role", P_REQUIRED | P_NON_EMPTY, &(priv->role), 
&success, error) == TRUE) {
-               return success;
-       } else if (gdata_parser_string_from_json_member (reader, "type", P_REQUIRED | P_NON_EMPTY, 
&scope_type, &success, error) == TRUE) {
-               if (g_strcmp0 (scope_type, "anyone") == 0) {
-                       priv->scope_type = g_strdup (GDATA_ACCESS_SCOPE_DEFAULT);
-               } else {
-                       priv->scope_type = scope_type;
-                       scope_type = NULL;
-               }
-
-               g_free (scope_type);
-               return success;
-       }
-
-       return GDATA_PARSABLE_CLASS (gdata_access_rule_parent_class)->parse_json (parsable, reader, 
user_data, error);
-}
-
-static gboolean
-post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error)
-{
-       GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
-
-       if (g_strcmp0 (priv->scope_type, "group") == 0 || g_strcmp0 (priv->scope_type, "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 {
-                       priv->scope_value = priv->email;
-                       priv->email = NULL;
-               }
-       } else if (g_strcmp0 (priv->scope_type, "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 {
-                       priv->scope_value = priv->domain;
-                       priv->domain = NULL;
-               }
-       }
-
-       return TRUE;
-}
-
 static void
 get_json (GDataParsable *parsable, JsonBuilder *builder)
 {
diff --git a/gdata/services/documents/gdata-documents-access-rule.c 
b/gdata/services/documents/gdata-documents-access-rule.c
index 37e43e1..054d11a 100644
--- a/gdata/services/documents/gdata-documents-access-rule.c
+++ b/gdata/services/documents/gdata-documents-access-rule.c
@@ -35,17 +35,28 @@
 #include "gdata-parser.h"
 #include "gdata-documents-access-rule.h"
 
-static const gchar *
-get_content_type (void);
+static void gdata_documents_access_rule_finalize (GObject *object);
+static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
+static gboolean post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error);
+static const gchar *get_content_type (void);
+
+typedef struct {
+       gchar *domain;
+       gchar *email;
+       gchar *scope_type;
+} GDataDocumentsAccessRulePrivate;
 
-G_DEFINE_TYPE (GDataDocumentsAccessRule, gdata_documents_access_rule,
-               GDATA_TYPE_ACCESS_RULE)
+G_DEFINE_TYPE_WITH_PRIVATE (GDataDocumentsAccessRule, gdata_documents_access_rule, GDATA_TYPE_ACCESS_RULE)
 
 static void
 gdata_documents_access_rule_class_init (GDataDocumentsAccessRuleClass *klass)
 {
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
        GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
 
+       object_class->finalize = gdata_documents_access_rule_finalize;
+       parsable_class->parse_json = parse_json;
+       parsable_class->post_parse_json = post_parse_json;
        parsable_class->get_content_type = get_content_type;
 }
 
@@ -55,6 +66,95 @@ gdata_documents_access_rule_init (GDataDocumentsAccessRule *self)
        /* Nothing to do here. */
 }
 
+static void
+gdata_documents_access_rule_finalize (GObject *object)
+{
+       GDataDocumentsAccessRulePrivate *priv;
+
+       priv = gdata_documents_access_rule_get_instance_private (GDATA_DOCUMENTS_ACCESS_RULE (object));
+
+       g_free (priv->domain);
+       g_free (priv->email);
+       g_free (priv->scope_type);
+
+       /* Chain up to the parent class */
+       G_OBJECT_CLASS (gdata_documents_access_rule_parent_class)->finalize (object);
+}
+
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
+{
+       GDataDocumentsAccessRulePrivate *priv;
+       gboolean success;
+       gchar *key = NULL;
+       gchar *role = NULL;
+       gchar *scope_type = NULL;
+
+       priv = gdata_documents_access_rule_get_instance_private (GDATA_DOCUMENTS_ACCESS_RULE (object));
+
+       /* JSON format: https://developers.google.com/drive/v2/reference/permissions */
+
+       if (gdata_parser_string_from_json_member (reader, "emailAddress", P_REQUIRED | P_NON_EMPTY, 
&(priv->email), &success, error) == TRUE ||
+           gdata_parser_string_from_json_member (reader, "domain", P_REQUIRED | P_NON_EMPTY, 
&(priv->domain), &success, error) == TRUE) {
+               return success;
+       } else if (gdata_parser_string_from_json_member (reader, "authKey", P_REQUIRED | P_NON_EMPTY, &key, 
&success, error) == TRUE) {
+               g_free (key);
+               return success;
+       } else if (gdata_parser_string_from_json_member (reader, "role", P_REQUIRED | P_NON_EMPTY, &role, 
&success, error) == TRUE) {
+               if (success && role != NULL && role[0] != '\0')
+                       gdata_access_rule_set_role (GDATA_ACCESS_RULE (parsable), role);
+
+               g_free (role);
+               return success;
+       } else if (gdata_parser_string_from_json_member (reader, "type", P_REQUIRED | P_NON_EMPTY, 
&scope_type, &success, error) == TRUE) {
+               if (g_strcmp0 (scope_type, "anyone") == 0) {
+                       priv->scope_type = g_strdup (GDATA_ACCESS_SCOPE_DEFAULT);
+               } else {
+                       priv->scope_type = scope_type;
+                       scope_type = NULL;
+               }
+
+               g_free (scope_type);
+               return success;
+       }
+
+       return GDATA_PARSABLE_CLASS (gdata_access_rule_parent_class)->parse_json (parsable, reader, 
user_data, error);
+}
+
+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 (object));
+
+       if (g_strcmp0 (priv->scope_type, GDATA_ACCESS_SCOPE_DEFAULT) == 0) {
+               gdata_access_rule_set_scope (GDATA_ACCESS_RULE (parsable), 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->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->domain);
+               }
+       }
+
+       return TRUE;
+}
+
 static const gchar *
 get_content_type (void)
 {


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