ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / libgnomevfs / gnome-vfs-utils.h
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-utils.h - Public utility functions for the GNOME Virtual
3    File System.
4
5    Copyright (C) 1999 Free Software Foundation
6    Copyright (C) 2000 Eazel, Inc.
7
8    The Gnome Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public License as
10    published by the Free Software Foundation; either version 2 of the
11    License, or (at your option) any later version.
12
13    The Gnome Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Library General Public
19    License along with the Gnome Library; see the file COPYING.LIB.  If not,
20    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.
22
23    Authors: Ettore Perazzoli <ettore@comm2000.it>
24             John Sullivan <sullivan@eazel.com> 
25 */
26
27 #ifndef GNOME_VFS_UTILS_H
28 #define GNOME_VFS_UTILS_H
29
30 #include <glib/gmessages.h>
31 #include <libgnomevfs/gnome-vfs-file-size.h>
32 #include <libgnomevfs/gnome-vfs-result.h>
33 #include <libgnomevfs/gnome-vfs-uri.h>
34 #include <libgnomevfs/gnome-vfs-handle.h>
35
36 G_BEGIN_DECLS
37
38 typedef enum {
39         GNOME_VFS_MAKE_URI_DIR_NONE = 0,
40         GNOME_VFS_MAKE_URI_DIR_HOMEDIR = 1 << 0,
41         GNOME_VFS_MAKE_URI_DIR_CURRENT = 1 << 1
42 } GnomeVFSMakeURIDirs;
43
44 /* Makes a human-readable string. */
45 char *gnome_vfs_format_file_size_for_display (GnomeVFSFileSize  size);
46
47 /* Converts unsafe characters to % sequences so the string can be
48  * used as a piece of a URI. Escapes all reserved URI characters.
49  */
50 char *gnome_vfs_escape_string                (const char      *string);
51
52 /* Converts unsafe characters to % sequences so the path can be
53  * used as a piece of a URI. Escapes all reserved URI characters
54  * except for "/".
55  */
56 char *gnome_vfs_escape_path_string           (const char      *path);
57
58 /* Converts unsafe characters to % sequences so the host/path segment
59  * can be used as a piece of a URI.  Allows ":" and "@" in the host
60  * section (everything up to the first "/"), and after that, it behaves
61  * like gnome_vfs_escape_path_string.
62  */
63 char *gnome_vfs_escape_host_and_path_string  (const char      *path);
64
65 /* Converts only slashes and % characters to % sequences. This is useful
66  * for code that wants to use an arbitrary string as a file name. To use
67  * it in a URI, you have to escape again, of course.
68  */
69 char *gnome_vfs_escape_slashes               (const char      *string);
70
71
72 /* Escapes all the characters that match any of the @match_set */                                        
73 char *gnome_vfs_escape_set                   (const char      *string,
74                                               const char      *match_set);
75
76 /* Returns NULL if any of the illegal character appear in escaped
77  * form. If the illegal characters are in there unescaped, that's OK.
78  * Typically you pass "/" for illegal characters when converting to a
79  * Unix path, since pieces of Unix paths can't contain "/". ASCII 0
80  * is always illegal due to the limitations of NULL-terminated strings.
81  */
82 char *gnome_vfs_unescape_string              (const char      *escaped_string,
83                                               const char      *illegal_characters);
84
85 /* returns a copy of uri, converted to a canonical form */
86 char *gnome_vfs_make_uri_canonical           (const char        *uri);
87
88 /* returns a copy of path, converted to a canonical form */
89 char *gnome_vfs_make_path_name_canonical     (const char      *path);
90
91 /* returns a copy of path, with initial ~ expanded, or just copy of path
92  * if there's no initial ~ 
93  */
94 char *gnome_vfs_expand_initial_tilde         (const char      *path);
95
96 /* Prepare an escaped string for display. Unlike gnome_vfs_unescape_string,
97  * this doesn't return NULL if an illegal sequences appears in the string,
98  * instead doing its best to provide a useful result.
99  */
100 char *gnome_vfs_unescape_string_for_display  (const char      *escaped);
101
102 /* Turn a "file://" URI in string form into a local path. Returns NULL
103  * if it's not a URI that can be converted.
104  */
105 char *gnome_vfs_get_local_path_from_uri      (const char      *uri);
106
107 /* Turn a path into a "file://" URI. */
108 char *gnome_vfs_get_uri_from_local_path      (const char      *local_full_path);
109
110 /* Check whether a string starts with an executable command */ 
111 gboolean gnome_vfs_is_executable_command_string (const char *command_string);
112
113 /* Free the list, freeing each item data with a g_free */
114 void   gnome_vfs_list_deep_free               (GList            *list);
115
116
117 /* Return amount of free space on target */
118 GnomeVFSResult  gnome_vfs_get_volume_free_space (const GnomeVFSURI      *vfs_uri, 
119                                                  GnomeVFSFileSize       *size);
120
121 char *gnome_vfs_icon_path_from_filename       (const char *filename);
122
123 /* Convert a file descriptor to a handle */
124 GnomeVFSResult  gnome_vfs_open_fd       (GnomeVFSHandle **handle,
125                                          int filedes);
126
127 /* TRUE if the current thread is the thread with the main glib event loop */
128 gboolean        gnome_vfs_is_primary_thread (void);
129
130 /**
131  * GNOME_VFS_ASSERT_PRIMARY_THREAD:
132  *
133  * Asserts that the current thread is the thread with 
134  * the main glib event loop 
135  **/
136 #define GNOME_VFS_ASSERT_PRIMARY_THREAD g_assert (gnome_vfs_is_primary_thread())
137
138 /**
139  * GNOME_VFS_ASSERT_SECONDARY_THREAD:
140  *
141  * Asserts that the current thread is NOT the thread with
142  * the main glib event loop 
143  **/
144 #define GNOME_VFS_ASSERT_SECONDARY_THREAD g_assert (!gnome_vfs_is_primary_thread())
145
146 /* Reads the contents of an entire file into memory */
147 GnomeVFSResult  gnome_vfs_read_entire_file (const char *uri,
148                                             int *file_size,
149                                             char **file_contents);
150
151 char *   gnome_vfs_format_uri_for_display            (const char          *uri);
152 char *   gnome_vfs_make_uri_from_input               (const char          *uri);
153 char *   gnome_vfs_make_uri_from_input_with_dirs     (const char          *uri,
154                                                       GnomeVFSMakeURIDirs  dirs);
155 char *   gnome_vfs_make_uri_canonical_strip_fragment (const char          *uri);
156 gboolean gnome_vfs_uris_match                        (const char          *uri_1,
157                                                       const char          *uri_2);
158 char *   gnome_vfs_get_uri_scheme                    (const char          *uri);
159 char *   gnome_vfs_make_uri_from_shell_arg           (const char          *uri);
160
161
162 #ifndef GNOME_VFS_DISABLE_DEPRECATED
163 char * gnome_vfs_make_uri_full_from_relative (const char *base_uri,
164                                               const char *relative_uri);
165 #endif /* GNOME_VFS_DISABLE_DEPRECATED */
166
167 GnomeVFSResult gnome_vfs_url_show                        (const char   *url);
168 GnomeVFSResult gnome_vfs_url_show_with_env               (const char   *url, 
169                                                           char        **envp);
170
171
172 G_END_DECLS
173
174 #endif /* GNOME_VFS_UTILS_H */