| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | /* 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, write to the | 
					
						
							|  |  |  |  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, | 
					
						
							|  |  |  |  * Boston, MA 02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Author: Alexander Larsson <alexl@redhat.com> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-22 15:10:51 +00:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include "gvfs.h"
 | 
					
						
							|  |  |  | #include "glocalvfs.h"
 | 
					
						
							| 
									
										
										
										
											2011-12-21 23:37:56 +01:00
										 |  |  | #include "gresourcefile.h"
 | 
					
						
							| 
									
										
										
										
											2007-12-05 11:10:21 +00:00
										 |  |  | #include "giomodule-priv.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | #include "glibintl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-28 12:39:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * SECTION:gvfs | 
					
						
							|  |  |  |  * @short_description: Virtual File System  | 
					
						
							| 
									
										
										
										
											2008-02-21 18:20:17 +00:00
										 |  |  |  * @include: gio/gio.h | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  *  | 
					
						
							|  |  |  |  * Entry point for using GIO functionality. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | 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: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * @vfs: a #GVfs. | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * Checks if the VFS is active. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * Returns: %TRUE if construction of the @vfs was successful and it is now active. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | 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: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * @vfs: a #GVfs. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  * @path: a string containing a VFS path. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * Gets a #GFile for @path. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer full): a #GFile.  | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  *     Free the returned object with g_object_unref(). | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | GFile * | 
					
						
							| 
									
										
										
										
											2007-11-30 05:11:25 +00:00
										 |  |  | g_vfs_get_file_for_path (GVfs       *vfs, | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | 			 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: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * @vfs: a#GVfs. | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  * @uri: a string containing a URI  | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  *  | 
					
						
							|  |  |  |  * Gets a #GFile for @uri. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  * This operation never fails, but the returned object | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  * might not support any I/O operation if the URI  | 
					
						
							|  |  |  |  * is malformed or if the URI scheme is not supported. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer full): a #GFile.  | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  *     Free the returned object with g_object_unref(). | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | GFile * | 
					
						
							| 
									
										
										
										
											2007-11-30 05:11:25 +00:00
										 |  |  | g_vfs_get_file_for_uri (GVfs       *vfs, | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | 			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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 23:37:56 +01:00
										 |  |  |   /* 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |   return (* class->get_file_for_uri) (vfs, uri); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * g_vfs_get_supported_uri_schemes: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * @vfs: a #GVfs. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-28 04:29:02 +00:00
										 |  |  |  * Gets a list of URI schemes supported by @vfs. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer none): a %NULL-terminated array of strings. | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  *     The returned array belongs to GIO and must  | 
					
						
							|  |  |  |  *     not be freed or modified. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | 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: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * @vfs: a #GVfs. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  * @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. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer full): a #GFile for the given @parse_name. | 
					
						
							| 
									
										
										
										
											2008-07-21 02:19:56 +00:00
										 |  |  |  *     Free the returned object with g_object_unref(). | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | GFile * | 
					
						
							| 
									
										
										
										
											2007-11-30 05:11:25 +00:00
										 |  |  | g_vfs_parse_name (GVfs       *vfs, | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | 		  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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 23:37:56 +01:00
										 |  |  |   if (g_str_has_prefix (parse_name, "resource:")) | 
					
						
							|  |  |  |     return _g_resource_file_new (parse_name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |   return (* class->parse_name) (vfs, parse_name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * g_vfs_get_default: | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * Gets the default #GVfs for the system. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer none): a #GVfs.  | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | GVfs * | 
					
						
							|  |  |  | g_vfs_get_default (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-21 18:21:27 -04:00
										 |  |  |   return _g_io_module_get_default (G_VFS_EXTENSION_POINT_NAME, | 
					
						
							|  |  |  | 				   "GIO_USE_VFS", | 
					
						
							|  |  |  | 				   (GIOModuleVerifyFunc)g_vfs_is_active); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * g_vfs_get_local: | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  * Gets the local #GVfs for the system. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2010-09-24 18:24:41 -03:00
										 |  |  |  * Returns: (transfer none): a #GVfs. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  **/ | 
					
						
							|  |  |  | GVfs * | 
					
						
							|  |  |  | g_vfs_get_local (void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   static gsize vfs = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (g_once_init_enter (&vfs)) | 
					
						
							| 
									
										
										
										
											2007-11-28 16:01:59 +00:00
										 |  |  |     g_once_init_leave (&vfs, (gsize)_g_local_vfs_new ()); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return G_VFS (vfs); | 
					
						
							|  |  |  | } |