/** * gdata_access_handler_get_rules_async: * @self: a #GDataAccessHandler * @service: a #GDataService * @cancellable: (allow-none): optional #GCancellable object, or %NULL * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when a rule is loaded, or %NULL * @progress_user_data: (closure): data to pass to the @progress_callback function * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be * called with @progress_user_data as a parameter and can be used to free any memory allocated for it. * @callback: a #GAsyncReadyCallback to call when the query is finished * @user_data: (closure): data to pass to the @callback function * * Retrieves a #GDataFeed containing all the access rules which apply to the given #GDataAccessHandler. Only the owner of a #GDataAccessHandler may * view its rule feed. @self and @service are both reffed when this function is called, so can safely be unreffed after this function returns. * * For more details, see gdata_access_handler_get_rules(), which is the synchronous version of this function, and gdata_service_query_async(), which * is the base asynchronous query function. * * When the operation is finished, @callback will be called. You can then call gdata_service_query_finish() * to get the results of the operation. * * Since: 0.9.1 */ void gdata_access_handler_get_rules_async (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GDestroyNotify destroy_progress_user_data, GAsyncReadyCallback callback, gpointer user_data) { g_autoptr(GTask) task = NULL; GetRulesAsyncData *data; g_return_if_fail (GDATA_IS_ACCESS_HANDLER (self)); g_return_if_fail (GDATA_IS_SERVICE (service)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); g_return_if_fail (callback != NULL); data = g_slice_new (GetRulesAsyncData); data->service = g_object_ref (service); data->progress_callback = progress_callback; data->progress_user_data = progress_user_data; data->destroy_progress_user_data = destroy_progress_user_data; task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, gdata_service_query_async); g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) get_rules_async_data_free); g_task_run_in_thread (task, get_rules_thread); }
/** * gdata_access_handler_get_rules_async: * @self: a #GDataAccessHandler * @service: a #GDataService * @cancellable: (allow-none): optional #GCancellable object, or %NULL * @progress_callback: (allow-none) (closure progress_user_data): a #GDataQueryProgressCallback to call when a rule is loaded, or %NULL * @progress_user_data: (closure): data to pass to the @progress_callback function * @destroy_progress_user_data: (allow-none): the function to call when @progress_callback will not be called any more, or %NULL. This function will be * called with @progress_user_data as a parameter and can be used to free any memory allocated for it. * @callback: a #GAsyncReadyCallback to call when the query is finished * @user_data: (closure): data to pass to the @callback function * * Retrieves a #GDataFeed containing all the access rules which apply to the given #GDataAccessHandler. Only the owner of a #GDataAccessHandler may * view its rule feed. @self and @service are both reffed when this function is called, so can safely be unreffed after this function returns. * * For more details, see gdata_access_handler_get_rules(), which is the synchronous version of this function, and gdata_service_query_async(), which * is the base asynchronous query function. * * When the operation is finished, @callback will be called. You can then call gdata_service_query_finish() * to get the results of the operation. * * Since: 0.9.1 **/ void gdata_access_handler_get_rules_async (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GDestroyNotify destroy_progress_user_data, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *result; GetRulesAsyncData *data; g_return_if_fail (GDATA_IS_ACCESS_HANDLER (self)); g_return_if_fail (GDATA_IS_SERVICE (service)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); g_return_if_fail (callback != NULL); data = g_slice_new (GetRulesAsyncData); data->service = g_object_ref (service); data->progress_callback = progress_callback; data->progress_user_data = progress_user_data; data->destroy_progress_user_data = destroy_progress_user_data; result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, gdata_service_query_async); g_simple_async_result_set_op_res_gpointer (result, data, (GDestroyNotify) get_rules_async_data_free); g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) get_rules_thread, G_PRIORITY_DEFAULT, cancellable); g_object_unref (result); }
/** * 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_WITH_UPDATE error will be returned. * * Return value: an updated #GDataAccessRule, or %NULL * * Since: 0.3.0 **/ GDataAccessRule * gdata_access_handler_update_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error) { GDataServiceClass *klass; GDataAccessRule *updated_rule; SoupMessage *message; gchar *upload_data; guint status; g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL); g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL); g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), NULL); message = get_soup_message (self, rule, SOUP_METHOD_PUT); /* Make sure subclasses set their headers */ klass = GDATA_SERVICE_GET_CLASS (service); if (klass->append_query_headers != NULL) klass->append_query_headers (service, message); /* Looks like ACLs don't support ETags */ /* Append the data */ upload_data = gdata_entry_get_xml (GDATA_ENTRY (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, error); if (status == SOUP_STATUS_NONE) { g_object_unref (message); return NULL; } /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); return NULL; } if (status != 200) { /* Error */ g_assert (klass->parse_error_response != NULL); klass->parse_error_response (service, GDATA_SERVICE_ERROR_WITH_UPDATE, status, message->reason_phrase, message->response_body->data, message->response_body->length, error); g_object_unref (message); return NULL; } /* Build the updated entry */ g_assert (message->response_body->data != NULL); /* Parse the XML; create and return a new GDataEntry of the same type as @entry */ updated_rule = GDATA_ACCESS_RULE (_gdata_entry_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_WITH_DELETION 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) { GDataServiceClass *klass; GDataAccessHandlerIface *iface; SoupMessage *message; guint status; g_return_val_if_fail (GDATA_IS_ENTRY (self), FALSE); g_return_val_if_fail (GDATA_IS_SERVICE (service), FALSE); g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), 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; } message = get_soup_message (self, rule, SOUP_METHOD_DELETE); /* Make sure subclasses set their headers */ klass = GDATA_SERVICE_GET_CLASS (service); if (klass->append_query_headers != NULL) klass->append_query_headers (service, message); /* Looks like ACLs don't support ETags */ /* Send the message */ status = _gdata_service_send_message (service, message, error); if (status == SOUP_STATUS_NONE) { g_object_unref (message); return FALSE; } /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); return FALSE; } if (status != 200) { /* Error */ g_assert (klass->parse_error_response != NULL); klass->parse_error_response (service, GDATA_SERVICE_ERROR_WITH_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; }
/** * gdata_access_handler_get_rules: * @self: a #GDataAccessHandler * @service: a #GDataService * @cancellable: optional #GCancellable object, or %NULL * @progress_callback: a #GDataQueryProgressCallback to call when a rule is loaded, or %NULL * @progress_user_data: data to pass to the @progress_callback function * @error: a #GError, or %NULL * * Retrieves a #GDataFeed containing all the access rules which apply to the given #GDataAccessHandler. Only the owner of a #GDataAccessHandler may * view its rule feed. * * 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. * * A %GDATA_SERVICE_ERROR_WITH_QUERY will be returned if the server indicates there is a problem with the query. * * For each rule in the response feed, @progress_callback will be called in the main thread. If there was an error parsing the XML response, * a #GDataParserError will be returned. * * Return value: a #GDataFeed of access control rules, or %NULL; unref with g_object_unref() * * Since: 0.3.0 **/ GDataFeed * gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error) { GDataServiceClass *klass; GDataFeed *feed; GDataLink *link; SoupMessage *message; guint status; /* TODO: async version */ g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL); g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL); /* Get the ACL URI */ link = gdata_entry_look_up_link (GDATA_ENTRY (self), "http://schemas.google.com/acl/2007#accessControlList"); g_assert (link != NULL); message = soup_message_new (SOUP_METHOD_GET, link->href); /* Make sure subclasses set their headers */ klass = GDATA_SERVICE_GET_CLASS (service); if (klass->append_query_headers != NULL) klass->append_query_headers (service, message); /* Send the message */ status = _gdata_service_send_message (service, message, error); if (status == SOUP_STATUS_NONE) { g_object_unref (message); return NULL; } /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); return NULL; } if (status != 200) { /* Error */ g_assert (klass->parse_error_response != NULL); klass->parse_error_response (service, GDATA_SERVICE_ERROR_WITH_QUERY, status, message->reason_phrase, message->response_body->data, message->response_body->length, error); g_object_unref (message); return NULL; } g_assert (message->response_body->data != NULL); feed = _gdata_feed_new_from_xml (GDATA_TYPE_FEED, message->response_body->data, message->response_body->length, GDATA_TYPE_ACCESS_RULE, progress_callback, progress_user_data, error); g_object_unref (message); return feed; }
/** * gdata_access_handler_get_rules: * @self: a #GDataAccessHandler * @service: a #GDataService * @cancellable: (allow-none): optional #GCancellable object, or %NULL * @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when a rule is loaded, or %NULL * @progress_user_data: (closure): data to pass to the @progress_callback function * @error: a #GError, or %NULL * * Retrieves a #GDataFeed containing all the access rules which apply to the given #GDataAccessHandler. Only the owner of a #GDataAccessHandler may * view its rule feed. * * 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. * * A %GDATA_SERVICE_ERROR_PROTOCOL_ERROR will be returned if the server indicates there is a problem with the query. * * For each rule in the response feed, @progress_callback will be called in the main thread. If there was an error parsing the XML response, * a #GDataParserError will be returned. * * Return value: (transfer full): a #GDataFeed of access control rules, or %NULL; unref with g_object_unref() * * Since: 0.3.0 */ GDataFeed * gdata_access_handler_get_rules (GDataAccessHandler *self, GDataService *service, GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data, GError **error) { GDataAccessHandlerIface *iface; 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 (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); iface = GDATA_ACCESS_HANDLER_GET_IFACE (self); g_assert (iface->get_rules != NULL); return iface->get_rules (self, service, cancellable, progress_callback, progress_user_data, error); }
/** * 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_WITH_INSERTION error will be returned. * * Return value: an updated #GDataAccessRule, or %NULL * * Since: 0.3.0 **/ GDataAccessRule * gdata_access_handler_insert_rule (GDataAccessHandler *self, GDataService *service, GDataAccessRule *rule, GCancellable *cancellable, GError **error) { GDataServiceClass *klass; GDataAccessRule *updated_rule; GDataLink *link; SoupMessage *message; gchar *upload_data; guint status; g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL); g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL); g_return_val_if_fail (GDATA_IS_ACCESS_RULE (rule), 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 */ link = gdata_entry_look_up_link (GDATA_ENTRY (self), "http://schemas.google.com/acl/2007#accessControlList"); g_assert (link != NULL); message = soup_message_new (SOUP_METHOD_POST, link->href); /* Make sure subclasses set their headers */ klass = GDATA_SERVICE_GET_CLASS (service); if (klass->append_query_headers != NULL) klass->append_query_headers (service, message); /* Append the data */ upload_data = gdata_entry_get_xml (GDATA_ENTRY (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, error); if (status == SOUP_STATUS_NONE) { g_object_unref (message); return NULL; } /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); return NULL; } if (status != 201) { /* Error */ g_assert (klass->parse_error_response != NULL); klass->parse_error_response (service, GDATA_SERVICE_ERROR_WITH_INSERTION, status, message->reason_phrase, message->response_body->data, message->response_body->length, error); g_object_unref (message); return NULL; } /* Build the updated entry */ g_assert (message->response_body->data != NULL); /* Parse the XML; create and return a new GDataEntry of the same type as @entry */ updated_rule = GDATA_ACCESS_RULE (_gdata_entry_new_from_xml (G_OBJECT_TYPE (rule), message->response_body->data, message->response_body->length, error)); g_object_unref (message); return updated_rule; }