1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/* 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
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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, see <http://www.gnu.org/licenses/>.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#include "config.h"
#include <string.h>
#include "gvfs.h"
#include "glib-private.h"
#include "glocalvfs.h"
#include "gresourcefile.h"
#include "giomodule-priv.h"
#include "glibintl.h"
/**
* SECTION:gvfs
* @short_description: Virtual File System
* @include: gio/gio.h
*
* Entry point for using GIO functionality.
*
*/
G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
static void
g_vfs_class_init (GVfsClass *klass)
{
}
static void
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.
*/
gboolean
g_vfs_is_active (GVfs *vfs)
{
GVfsClass *class;
g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
class = G_VFS_GET_CLASS (vfs);
return (* class->is_active) (vfs);
}
/**
* g_vfs_get_file_for_path:
* @vfs: a #GVfs.
* @path: a string containing a VFS path.
*
* Gets a #GFile for @path.
*
* 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)
{
GVfsClass *class;
g_return_val_if_fail (G_IS_VFS (vfs), NULL);
g_return_val_if_fail (path != NULL, NULL);
class = G_VFS_GET_CLASS (vfs);
return (* class->get_file_for_path) (vfs, path);
}
/**
* g_vfs_get_file_for_uri:
* @vfs: a#GVfs.
* @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 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)
{
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: (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);
return (* class->get_supported_uri_schemes) (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
* be parsed by the #GVfs module.
*
* 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)
{
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);
if (g_str_has_prefix (parse_name, "resource:"))
return _g_resource_file_new (parse_name);
return (* class->parse_name) (vfs, parse_name);
}
/**
* g_vfs_get_default:
*
* Gets the default #GVfs for the system.
*
* Returns: (transfer none): a #GVfs.
*/
GVfs *
g_vfs_get_default (void)
{
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: (transfer none): a #GVfs.
*/
GVfs *
g_vfs_get_local (void)
{
static gsize vfs = 0;
if (g_once_init_enter (&vfs))
g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
return G_VFS (vfs);
}
|