X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgvfs.c;h=2390b7c1e6c6fafc8e27932920d8525f3e9d1396;hb=2a2b11b1bb6c702d6b2ef1c37524a57688a94a4e;hp=8f69191453c1990ad13c1cdcff57324109e23767;hpb=4f039bd490856afab9d0eff22fbaeeadaef651a2;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gvfs.c b/gio/gvfs.c index 8f69191..2390b7c 100644 --- a/gio/gvfs.c +++ b/gio/gvfs.c @@ -1,5 +1,5 @@ /* GIO - GLib Input, Output and Streaming Library - * + * * Copyright (C) 2006-2007 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -13,30 +13,29 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ -#include +#include "config.h" #include #include "gvfs.h" +#include "glib-private.h" #include "glocalvfs.h" -#include "giomodule.h" +#include "gresourcefile.h" +#include "giomodule-priv.h" #include "glibintl.h" -#include "gioalias.h" /** * SECTION:gvfs - * @short_description: Virtual File System - * @include: gio/gvfs.h - * + * @short_description: Virtual File System + * @include: gio/gio.h + * * Entry point for using GIO functionality. * - **/ + */ G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT); @@ -53,11 +52,12 @@ g_vfs_init (GVfs *vfs) /** * g_vfs_is_active: * @vfs: a #GVfs. - * + * * Checks if the VFS is active. - * - * Returns: %TRUE if construction of the @vfs was successful and it is now active. - **/ + * + * Returns: %TRUE if construction of the @vfs was successful + * and it is now active. + */ gboolean g_vfs_is_active (GVfs *vfs) { @@ -75,17 +75,18 @@ g_vfs_is_active (GVfs *vfs) * g_vfs_get_file_for_path: * @vfs: a #GVfs. * @path: a string containing a VFS path. - * + * * Gets a #GFile for @path. - * - * Returns: a #GFile. - **/ + * + * Returns: (transfer full): a #GFile. + * Free the returned object with g_object_unref(). + */ GFile * g_vfs_get_file_for_path (GVfs *vfs, - const char *path) + const char *path) { GVfsClass *class; - + g_return_val_if_fail (G_IS_VFS (vfs), NULL); g_return_val_if_fail (path != NULL, NULL); @@ -97,44 +98,54 @@ g_vfs_get_file_for_path (GVfs *vfs, /** * g_vfs_get_file_for_uri: * @vfs: a#GVfs. - * @uri: a string containing a URI path. - * + * @uri: a string containing a URI + * * Gets a #GFile for @uri. - * + * * This operation never fails, but the returned object - * might not support any I/O operation if the uri - * is malformed or if the uri type is not supported. - * - * Returns: a #GFile. - * - **/ + * might not support any I/O operation if the URI + * is malformed or if the URI scheme is not supported. + * + * Returns: (transfer full): a #GFile. + * Free the returned object with g_object_unref(). + */ GFile * g_vfs_get_file_for_uri (GVfs *vfs, - const char *uri) + const char *uri) { GVfsClass *class; - + g_return_val_if_fail (G_IS_VFS (vfs), NULL); g_return_val_if_fail (uri != NULL, NULL); class = G_VFS_GET_CLASS (vfs); + /* This is an unfortunate placement, but we really + * need to check this before chaining to the vfs, + * because we want to support resource uris for + * all vfs:es, even those that predate resources. + */ + if (g_str_has_prefix (uri, "resource:")) + return _g_resource_file_new (uri); + return (* class->get_file_for_uri) (vfs, uri); } /** * g_vfs_get_supported_uri_schemes: * @vfs: a #GVfs. - * + * * Gets a list of URI schemes supported by @vfs. - * - * Returns: a list of strings. - **/ + * + * Returns: (transfer none): a %NULL-terminated array of strings. + * The returned array belongs to GIO and must + * not be freed or modified. + */ const gchar * const * g_vfs_get_supported_uri_schemes (GVfs *vfs) { GVfsClass *class; - + g_return_val_if_fail (G_IS_VFS (vfs), NULL); class = G_VFS_GET_CLASS (vfs); @@ -146,125 +157,55 @@ g_vfs_get_supported_uri_schemes (GVfs *vfs) * g_vfs_parse_name: * @vfs: a #GVfs. * @parse_name: a string to be parsed by the VFS module. - * - * This operation never fails, but the returned object might - * not support any I/O operations if the @parse_name cannot + * + * This operation never fails, but the returned object might + * not support any I/O operations if the @parse_name cannot * be parsed by the #GVfs module. - * - * Returns: a #GFile for the given @parse_name. - **/ + * + * Returns: (transfer full): a #GFile for the given @parse_name. + * Free the returned object with g_object_unref(). + */ GFile * g_vfs_parse_name (GVfs *vfs, - const char *parse_name) + const char *parse_name) { GVfsClass *class; - + g_return_val_if_fail (G_IS_VFS (vfs), NULL); g_return_val_if_fail (parse_name != NULL, NULL); class = G_VFS_GET_CLASS (vfs); - return (* class->parse_name) (vfs, parse_name); -} - -/* Note: This compares in reverse order. - Higher prio -> sort first - */ -static gint -compare_vfs_type (gconstpointer a, - gconstpointer b, - gpointer user_data) -{ - GVfsClass *class_a, *class_b; - gint res; - const char *use_this_vfs; - - class_a = g_type_class_ref (*(GType *)a); - class_b = g_type_class_ref (*(GType *)b); - use_this_vfs = user_data; - - if (class_a == class_b) - res = 0; - else if (use_this_vfs != NULL && - strcmp (class_a->name, use_this_vfs) == 0) - res = -1; - else if (use_this_vfs != NULL && - strcmp (class_b->name, use_this_vfs) == 0) - res = 1; - else - res = class_b->priority - class_a->priority; - - g_type_class_unref (class_a); - g_type_class_unref (class_b); - - return res; -} - - -static gpointer -get_default_vfs (gpointer arg) -{ - volatile GType local_type; - GType *vfs_impls; - int i; - guint n_vfs_impls; - const char *use_this; - GVfs *vfs; - GType (*casted_get_type)(void); - - use_this = g_getenv ("GIO_USE_VFS"); - - /* Ensure GLocalVfs type is available - the cast is required to avoid any G_GNUC_CONST optimizations */ - casted_get_type = _g_local_vfs_get_type; - local_type = casted_get_type (); - - /* Ensure vfs in modules loaded */ - _g_io_modules_ensure_loaded (); - - vfs_impls = g_type_children (G_TYPE_VFS, &n_vfs_impls); + if (g_str_has_prefix (parse_name, "resource:")) + return _g_resource_file_new (parse_name); - g_qsort_with_data (vfs_impls, n_vfs_impls, sizeof (GType), - compare_vfs_type, (gpointer)use_this); - - for (i = 0; i < n_vfs_impls; i++) - { - vfs = g_object_new (vfs_impls[i], NULL); - - if (g_vfs_is_active (vfs)) - break; - - g_object_unref (vfs); - vfs = NULL; - } - - g_free (vfs_impls); - - return vfs; + return (* class->parse_name) (vfs, parse_name); } /** * g_vfs_get_default: - * + * * Gets the default #GVfs for the system. - * - * Returns: a #GVfs. - **/ + * + * Returns: (transfer none): a #GVfs. + */ GVfs * g_vfs_get_default (void) { - static GOnce once_init = G_ONCE_INIT; - - return g_once (&once_init, get_default_vfs, NULL); + if (GLIB_PRIVATE_CALL (g_check_setuid) ()) + return g_vfs_get_local (); + return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME, + "GIO_USE_VFS", + (GIOModuleVerifyFunc)g_vfs_is_active); } /** * g_vfs_get_local: - * + * * Gets the local #GVfs for the system. - * - * Returns: a #GVfs. - **/ + * + * Returns: (transfer none): a #GVfs. + */ GVfs * g_vfs_get_local (void) { @@ -275,6 +216,3 @@ g_vfs_get_local (void) return G_VFS (vfs); } - -#define __G_VFS_C__ -#include "gioaliasdef.c"