Add a test for the previous fix
[glib.git] / gio / gvfs.c
blobd08c49ef14a04b594974a68d8204e0539b94332c
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
23 #include "config.h"
24 #include <string.h>
25 #include "gvfs.h"
26 #include "glib-private.h"
27 #include "glocalvfs.h"
28 #include "gresourcefile.h"
29 #include "giomodule-priv.h"
30 #include "glibintl.h"
33 /**
34 * SECTION:gvfs
35 * @short_description: Virtual File System
36 * @include: gio/gio.h
38 * Entry point for using GIO functionality.
42 G_DEFINE_TYPE (GVfs, g_vfs, G_TYPE_OBJECT);
44 static void
45 g_vfs_class_init (GVfsClass *klass)
49 static void
50 g_vfs_init (GVfs *vfs)
54 /**
55 * g_vfs_is_active:
56 * @vfs: a #GVfs.
58 * Checks if the VFS is active.
60 * Returns: %TRUE if construction of the @vfs was successful
61 * and it is now active.
63 gboolean
64 g_vfs_is_active (GVfs *vfs)
66 GVfsClass *class;
68 g_return_val_if_fail (G_IS_VFS (vfs), FALSE);
70 class = G_VFS_GET_CLASS (vfs);
72 return (* class->is_active) (vfs);
76 /**
77 * g_vfs_get_file_for_path:
78 * @vfs: a #GVfs.
79 * @path: a string containing a VFS path.
81 * Gets a #GFile for @path.
83 * Returns: (transfer full): a #GFile.
84 * Free the returned object with g_object_unref().
86 GFile *
87 g_vfs_get_file_for_path (GVfs *vfs,
88 const char *path)
90 GVfsClass *class;
92 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
93 g_return_val_if_fail (path != NULL, NULL);
95 class = G_VFS_GET_CLASS (vfs);
97 return (* class->get_file_for_path) (vfs, path);
101 * g_vfs_get_file_for_uri:
102 * @vfs: a#GVfs.
103 * @uri: a string containing a URI
105 * Gets a #GFile for @uri.
107 * This operation never fails, but the returned object
108 * might not support any I/O operation if the URI
109 * is malformed or if the URI scheme is not supported.
111 * Returns: (transfer full): a #GFile.
112 * Free the returned object with g_object_unref().
114 GFile *
115 g_vfs_get_file_for_uri (GVfs *vfs,
116 const char *uri)
118 GVfsClass *class;
120 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
121 g_return_val_if_fail (uri != NULL, NULL);
123 class = G_VFS_GET_CLASS (vfs);
125 /* This is an unfortunate placement, but we really
126 * need to check this before chaining to the vfs,
127 * because we want to support resource uris for
128 * all vfs:es, even those that predate resources.
130 if (g_str_has_prefix (uri, "resource:"))
131 return _g_resource_file_new (uri);
133 return (* class->get_file_for_uri) (vfs, uri);
137 * g_vfs_get_supported_uri_schemes:
138 * @vfs: a #GVfs.
140 * Gets a list of URI schemes supported by @vfs.
142 * Returns: (transfer none): a %NULL-terminated array of strings.
143 * The returned array belongs to GIO and must
144 * not be freed or modified.
146 const gchar * const *
147 g_vfs_get_supported_uri_schemes (GVfs *vfs)
149 GVfsClass *class;
151 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
153 class = G_VFS_GET_CLASS (vfs);
155 return (* class->get_supported_uri_schemes) (vfs);
159 * g_vfs_parse_name:
160 * @vfs: a #GVfs.
161 * @parse_name: a string to be parsed by the VFS module.
163 * This operation never fails, but the returned object might
164 * not support any I/O operations if the @parse_name cannot
165 * be parsed by the #GVfs module.
167 * Returns: (transfer full): a #GFile for the given @parse_name.
168 * Free the returned object with g_object_unref().
170 GFile *
171 g_vfs_parse_name (GVfs *vfs,
172 const char *parse_name)
174 GVfsClass *class;
176 g_return_val_if_fail (G_IS_VFS (vfs), NULL);
177 g_return_val_if_fail (parse_name != NULL, NULL);
179 class = G_VFS_GET_CLASS (vfs);
181 if (g_str_has_prefix (parse_name, "resource:"))
182 return _g_resource_file_new (parse_name);
184 return (* class->parse_name) (vfs, parse_name);
188 * g_vfs_get_default:
190 * Gets the default #GVfs for the system.
192 * Returns: (transfer none): a #GVfs.
194 GVfs *
195 g_vfs_get_default (void)
197 if (GLIB_PRIVATE_CALL (g_check_setuid) ())
198 return g_vfs_get_local ();
199 return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME,
200 "GIO_USE_VFS",
201 (GIOModuleVerifyFunc)g_vfs_is_active);
205 * g_vfs_get_local:
207 * Gets the local #GVfs for the system.
209 * Returns: (transfer none): a #GVfs.
211 GVfs *
212 g_vfs_get_local (void)
214 static gsize vfs = 0;
216 if (g_once_init_enter (&vfs))
217 g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ());
219 return G_VFS (vfs);