[libgdata] core: Remove ACL modification methods from GDataAccessHandler



commit f9ebfd701a78ccef5b4ae01d136bd17d93f75928
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Oct 5 13:50:20 2010 +0100

    core: Remove ACL modification methods from GDataAccessHandler
    
     â?¢ gdata_access_handler_insert_rule() â?? gdata_service_insert_entry()
     â?¢ gdata_access_handler_update_rule() â?? gdata_service_update_entry()
     â?¢ gdata_access_handler_delete_rule() â?? gdata_service_delete_entry()

 docs/reference/gdata-sections.txt |    3 -
 gdata/gdata-access-handler.c      |  249 -------------------------------------
 gdata/gdata-access-handler.h      |    6 -
 gdata/gdata.symbols               |    3 -
 gdata/tests/calendar.c            |   11 ++-
 gdata/tests/documents.c           |    7 +-
 6 files changed, 14 insertions(+), 265 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 0ebf0bd..7483809 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -646,9 +646,6 @@ GDATA_LINK_ACCESS_CONTROL_LIST
 GDataAccessHandler
 GDataAccessHandlerIface
 gdata_access_handler_get_rules
-gdata_access_handler_insert_rule
-gdata_access_handler_update_rule
-gdata_access_handler_delete_rule
 <SUBSECTION Standard>
 gdata_access_handler_get_type
 GDATA_ACCESS_HANDLER
diff --git a/gdata/gdata-access-handler.c b/gdata/gdata-access-handler.c
index 075a21b..86f7f20 100644
--- a/gdata/gdata-access-handler.c
+++ b/gdata/gdata-access-handler.c
@@ -125,252 +125,3 @@ gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service,
 
 	return feed;
 }
-
-/**
- * gdata_access_handler_insert_rule:
- * @self: a #GDataAccessHandler
- * @service: a #GDataService
- * @rule: the #GDataAccessRule to insert
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: a #GError, or %NULL
- *
- * Inserts @rule in the access control list of the #GDataAccessHandler.
- *
- * The service will return an updated version of the rule, which is the return value of this function on success.
- *
- * 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.
- *
- * If the rule is marked as already having been inserted a %GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED error will be returned immediately
- * (there will be no network requests).
- *
- * If there is an error inserting the rule, a %GDATA_SERVICE_ERROR_PROTOCOL_ERROR error will be returned.
- *
- * Return value: (transfer full): an updated #GDataAccessRule, or %NULL; unref with g_object_unref()
- *
- * Since: 0.3.0
- **/
-GDataAccessRule *
-gdata_access_handler_insert_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error)
-{
-	GDataAccessRule *updated_rule;
-	GDataLink *_link;
-	SoupMessage *message;
-	gchar *upload_data;
-	guint status;
-
-	g_return_val_if_fail (GDATA_IS_ACCESS_HANDLER (self), NULL);
-	g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
-	g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), NULL);
-	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
-	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
-	if (gdata_entry_is_inserted (GDATA_ENTRY (rule)) == TRUE) {
-		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED,
-		                     _("The rule has already been inserted."));
-		return NULL;
-	}
-
-	/* Get the ACL URI */
-	/* TODO: ETag support */
-	_link = gdata_entry_look_up_link (GDATA_ENTRY (self), GDATA_LINK_ACCESS_CONTROL_LIST);
-	g_assert (_link != NULL);
-	message = _gdata_service_build_message (service, SOUP_METHOD_POST, gdata_link_get_uri (_link), NULL, FALSE);
-
-	/* Append the data */
-	upload_data = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
-	soup_message_set_request (message, "application/atom+xml", SOUP_MEMORY_TAKE, upload_data, strlen (upload_data));
-
-	/* Send the message */
-	status = _gdata_service_send_message (service, message, cancellable, error);
-
-	if (status == SOUP_STATUS_NONE || status == SOUP_STATUS_CANCELLED) {
-		/* Redirect error or cancelled */
-		g_object_unref (message);
-		return NULL;
-	} else if (status != SOUP_STATUS_CREATED) {
-		/* Error */
-		GDataServiceClass *klass = GDATA_SERVICE_GET_CLASS (service);
-		g_assert (klass->parse_error_response != NULL);
-		klass->parse_error_response (service, GDATA_OPERATION_INSERTION, status, message->reason_phrase, message->response_body->data,
-		                             message->response_body->length, error);
-		g_object_unref (message);
-		return NULL;
-	}
-
-	/* Parse the XML; create and return a new GDataEntry of the same type as @entry */
-	g_assert (message->response_body->data != NULL);
-	updated_rule = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (G_OBJECT_TYPE (rule), message->response_body->data,
-	                                                               message->response_body->length, error));
-	g_object_unref (message);
-
-	return updated_rule;
-}
-
-static SoupMessage *
-build_message (GDataAccessHandler *access_handler, GDataService *service, GDataAccessRule *rule, const gchar *method)
-{
-	GDataLink *_link;
-	SoupMessage *message;
-	GString *uri_string;
-	gchar *uri;
-	const gchar *scope_type, *scope_value;
-
-	/* Get the edit URI */
-	_link = gdata_entry_look_up_link (GDATA_ENTRY (rule), GDATA_LINK_EDIT);
-	if (_link != NULL)
-		return _gdata_service_build_message (service, method, gdata_link_get_uri (_link), NULL, FALSE);
-
-	/* Try building the URI instead */
-	_link = gdata_entry_look_up_link (GDATA_ENTRY (access_handler), GDATA_LINK_ACCESS_CONTROL_LIST);
-	g_assert (_link != NULL);
-	gdata_access_rule_get_scope (rule, &scope_type, &scope_value);
-
-	uri_string = g_string_sized_new (strlen (gdata_link_get_uri (_link)) + 30);
-	g_string_append_printf (uri_string, "%s/", gdata_link_get_uri (_link));
-	g_string_append_uri_escaped (uri_string, scope_type, NULL, FALSE);
-	if (scope_value != NULL) {
-		g_string_append (uri_string, "%3A");
-		g_string_append_uri_escaped (uri_string, scope_value, NULL, FALSE);
-	}
-
-	uri = g_string_free (uri_string, FALSE);
-	message = _gdata_service_build_message (service, method, uri, NULL, FALSE);
-	g_free (uri);
-
-	return message;
-}
-
-/**
- * gdata_access_handler_update_rule:
- * @self: a #GDataAccessHandler
- * @service: a #GDataService
- * @rule: the #GDataAccessRule to update
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: a #GError, or %NULL
- *
- * Updates @rule in the access control list of the #GDataAccessHandler.
- *
- * The service will return an updated version of the rule, which is the return value of this function on success.
- *
- * 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.
- *
- * If there is an error updating the rule, a %GDATA_SERVICE_ERROR_PROTOCOL_ERROR error will be returned.
- *
- * Return value: (transfer full): an updated #GDataAccessRule, or %NULL; unref with g_object_unref()
- *
- * Since: 0.3.0
- **/
-GDataAccessRule *
-gdata_access_handler_update_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error)
-{
-	GDataAccessRule *updated_rule;
-	SoupMessage *message;
-	gchar *upload_data;
-	guint status;
-
-	g_return_val_if_fail (GDATA_IS_ACCESS_HANDLER (self), NULL);
-	g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
-	g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), NULL);
-	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
-	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
-	/* TODO: ETag support */
-	message = build_message (self, service, rule, SOUP_METHOD_PUT);
-
-	/* Append the data */
-	upload_data = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
-	soup_message_set_request (message, "application/atom+xml", SOUP_MEMORY_TAKE, upload_data, strlen (upload_data));
-
-	/* Send the message */
-	status = _gdata_service_send_message (service, message, cancellable, error);
-
-	if (status == SOUP_STATUS_NONE || status == SOUP_STATUS_CANCELLED) {
-		/* Redirect error or cancelled */
-		g_object_unref (message);
-		return NULL;
-	} else if (status != SOUP_STATUS_OK) {
-		/* Error */
-		GDataServiceClass *klass = GDATA_SERVICE_GET_CLASS (service);
-		g_assert (klass->parse_error_response != NULL);
-		klass->parse_error_response (service, GDATA_OPERATION_UPDATE, status, message->reason_phrase, message->response_body->data,
-		                             message->response_body->length, error);
-		g_object_unref (message);
-		return NULL;
-	}
-
-	/* Parse the XML; create and return a new GDataEntry of the same type as @entry */
-	g_assert (message->response_body->data != NULL);
-	updated_rule = GDATA_ACCESS_RULE (gdata_parsable_new_from_xml (G_OBJECT_TYPE (rule), message->response_body->data,
-	                                                               message->response_body->length, error));
-	g_object_unref (message);
-
-	return updated_rule;
-}
-
-/**
- * gdata_access_handler_delete_rule:
- * @self: a #GDataAccessHandler
- * @service: a #GDataService
- * @rule: the #GDataAccessRule to delete
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: a #GError, or %NULL
- *
- * Deletes @rule from the access control list of the #GDataAccessHandler.
- *
- * 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.
- *
- * If there is an error deleting the rule, a %GDATA_SERVICE_ERROR_PROTOCOL_ERROR error will be returned, unless the @rule was the owner's
- * rule; in which case, %GDATA_SERVICE_ERROR_FORBIDDEN will be returned without any network activity.
- *
- * Return value: %TRUE on success, %FALSE otherwise
- *
- * Since: 0.3.0
- **/
-gboolean
-gdata_access_handler_delete_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error)
-{
-	GDataAccessHandlerIface *iface;
-	SoupMessage *message;
-	guint status;
-
-	g_return_val_if_fail (GDATA_IS_ACCESS_HANDLER (self), FALSE);
-	g_return_val_if_fail (GDATA_IS_SERVICE (service), FALSE);
-	g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), FALSE);
-	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
-	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
-	/* The owner of the access handler can't be deleted */
-	iface = GDATA_ACCESS_HANDLER_GET_IFACE (self);
-	g_assert (iface->is_owner_rule != NULL);
-	if (iface->is_owner_rule (rule) == TRUE) {
-		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN,
-		                     _("The owner's rule may not be deleted."));
-		return FALSE;
-	}
-
-	/* TODO: ETag support */
-	/* Build and send the message */
-	message = build_message (self, service, rule, SOUP_METHOD_DELETE);
-	status = _gdata_service_send_message (service, message, cancellable, error);
-
-	if (status == SOUP_STATUS_NONE || status == SOUP_STATUS_CANCELLED) {
-		/* Redirect error or cancelled */
-		g_object_unref (message);
-		return FALSE;
-	} else if (status != SOUP_STATUS_OK) {
-		/* Error */
-		GDataServiceClass *klass = GDATA_SERVICE_GET_CLASS (service);
-		g_assert (klass->parse_error_response != NULL);
-		klass->parse_error_response (service, GDATA_OPERATION_DELETION, status, message->reason_phrase, message->response_body->data,
-		                             message->response_body->length, error);
-		g_object_unref (message);
-		return FALSE;
-	}
-
-	g_object_unref (message);
-
-	return TRUE;
-}
diff --git a/gdata/gdata-access-handler.h b/gdata/gdata-access-handler.h
index f6fb779..0d79628 100644
--- a/gdata/gdata-access-handler.h
+++ b/gdata/gdata-access-handler.h
@@ -76,12 +76,6 @@ GType gdata_access_handler_get_type (void) G_GNUC_CONST;
 GDataFeed *gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable,
                                            GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                            GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-GDataAccessRule *gdata_access_handler_insert_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule,
-                                                   GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-GDataAccessRule *gdata_access_handler_update_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule,
-                                                   GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-gboolean gdata_access_handler_delete_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule,
-                                           GCancellable *cancellable, GError **error);
 
 G_END_DECLS
 
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 119cb9b..1a29380 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -305,9 +305,6 @@ gdata_contacts_contact_get_photo
 gdata_contacts_contact_set_photo
 gdata_access_handler_get_type
 gdata_access_handler_get_rules
-gdata_access_handler_insert_rule
-gdata_access_handler_update_rule
-gdata_access_handler_delete_rule
 gdata_access_rule_get_type
 gdata_access_rule_new
 gdata_access_rule_get_role
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index d3cf72a..4051efa 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -564,6 +564,7 @@ test_acls_insert_rule (gconstpointer service)
 	GDataAccessRule *rule, *new_rule;
 	const gchar *scope_type, *scope_value;
 	GDataCategory *category;
+	GDataLink *_link;
 	GList *categories;
 	gchar *xml;
 	gint64 edited;
@@ -596,7 +597,11 @@ test_acls_insert_rule (gconstpointer service)
 	g_free (xml);
 
 	/* Insert the rule */
-	new_rule = gdata_access_handler_insert_rule (GDATA_ACCESS_HANDLER (calendar), GDATA_SERVICE (service), rule, NULL, &error);
+	_link = gdata_entry_look_up_link (GDATA_ENTRY (calendar), GDATA_LINK_ACCESS_CONTROL_LIST);
+	g_assert (_link != NULL);
+
+	new_rule = GDATA_ACCESS_RULE (gdata_service_insert_entry (GDATA_SERVICE (service), gdata_link_get_uri (_link), GDATA_ENTRY (rule),
+	                                                          NULL, &error));
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_ACCESS_RULE (new_rule));
 	g_clear_error (&error);
@@ -661,7 +666,7 @@ test_acls_update_rule (gconstpointer service)
 	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, GDATA_CALENDAR_ACCESS_ROLE_READ);
 
 	/* Send the update to the server */
-	new_rule = gdata_access_handler_update_rule (GDATA_ACCESS_HANDLER (calendar), GDATA_SERVICE (service), rule, NULL, &error);
+	new_rule = GDATA_ACCESS_RULE (gdata_service_update_entry (GDATA_SERVICE (service), GDATA_ENTRY (rule), NULL, &error));
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_ACCESS_RULE (new_rule));
 	g_clear_error (&error);
@@ -713,7 +718,7 @@ test_acls_delete_rule (gconstpointer service)
 	g_object_unref (feed);
 
 	/* Delete the rule */
-	success = gdata_access_handler_delete_rule (GDATA_ACCESS_HANDLER (calendar), GDATA_SERVICE (service), rule, NULL, &error);
+	success = gdata_service_delete_entry (GDATA_SERVICE (service), GDATA_ENTRY (rule), NULL, &error);
 	g_assert_no_error (error);
 	g_assert (success == TRUE);
 	g_clear_error (&error);
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 79fec19..6d6b2d9 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -525,6 +525,7 @@ test_new_document_with_collaborator (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document;
 	GDataAccessRule *access_rule, *new_access_rule;
+	GDataLink *_link;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
@@ -543,7 +544,11 @@ test_new_document_with_collaborator (gconstpointer service)
 	gdata_access_rule_set_scope (access_rule, GDATA_ACCESS_SCOPE_USER, "libgdata test gmail com");
 
 	/* Set access rules */
-	new_access_rule = gdata_access_handler_insert_rule (GDATA_ACCESS_HANDLER (new_document), GDATA_SERVICE (service), access_rule, NULL, &error);
+	_link = gdata_entry_look_up_link (GDATA_ENTRY (new_document), GDATA_LINK_ACCESS_CONTROL_LIST);
+	g_assert (_link != NULL);
+
+	new_access_rule = GDATA_ACCESS_RULE (gdata_service_insert_entry (GDATA_SERVICE (service), gdata_link_get_uri (_link),
+	                                                                 GDATA_ENTRY (access_rule), NULL, &error));
 	g_assert_no_error (error);
 	g_assert (GDATA_IS_ACCESS_RULE (new_access_rule));
 



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