Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
filesystem.h
1 /* filesystem.h
2  * Filesystem utility definitions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef FILESYSTEM_H
12 #define FILESYSTEM_H
13 
14 #include "ws_symbol_export.h"
15 #include "ws_attributes.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 /*
22  * Default profile name.
23  */
24 #define DEFAULT_PROFILE "Default"
25 
26 
27 /*
28  * Get the pathname of the directory from which the executable came,
29  * and save it for future use. Returns NULL on success, and a
30  * g_mallocated string containing an error on failure.
31  */
32 WS_DLL_PUBLIC char *init_progfile_dir(const char *arg0);
33 
34 /*
35  * Get the directory in which the program resides.
36  */
37 WS_DLL_PUBLIC const char *get_progfile_dir(void);
38 
39 /*
40  * Get the directory in which plugins are stored; this must not be called
41  * before init_progfile_dir() is called, as they might be stored in a
42  * subdirectory of the program file directory.
43  */
44 WS_DLL_PUBLIC const char *get_plugins_dir(void);
45 
46 /*
47  * Append VERSION_MAJOR.VERSION_MINOR to the plugin dir.
48  */
49 WS_DLL_PUBLIC const char *get_plugins_dir_with_version(void);
50 
51 /*
52  * Get the personal plugin dir.
53  */
54 WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);
55 
56 /*
57  * Append VERSION_MAJOR.VERSION_MINOR to the plugin personal dir.
58  */
59 WS_DLL_PUBLIC const char *get_plugins_pers_dir_with_version(void);
60 
61 /*
62  * Get the directory in which extcap hooks are stored; this must not be called
63  * before init_progfile_dir() is called, as they might be stored in a
64  * subdirectory of the program file directory.
65  */
66 WS_DLL_PUBLIC const char *get_extcap_dir(void);
67 
68 /*
69  * Get the flag indicating whether we're running from a build
70  * directory.
71  */
72 WS_DLL_PUBLIC gboolean running_in_build_directory(void);
73 
74 /*
75  * Get the directory in which global configuration files are
76  * stored.
77  */
78 WS_DLL_PUBLIC const char *get_datafile_dir(void);
79 
80 /*
81  * Construct the path name of a global configuration file, given the
82  * file name.
83  *
84  * The returned file name was g_malloc()'d so it must be g_free()d when the
85  * caller is done with it.
86  */
87 WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
88 
89 /*
90  * Get the directory in which files that, at least on UNIX, are
91  * system files (such as "/etc/ethers") are stored; on Windows,
92  * there's no "/etc" directory, so we get them from the Wireshark
93  * global configuration and data file directory.
94  */
95 WS_DLL_PUBLIC const char *get_systemfile_dir(void);
96 
97 /*
98  * Set the configuration profile name to be used for storing
99  * personal configuration files.
100  */
101 WS_DLL_PUBLIC void set_profile_name(const gchar *profilename);
102 
103 /*
104  * Get the current configuration profile name used for storing
105  * personal configuration files.
106  */
107 WS_DLL_PUBLIC const char *get_profile_name(void);
108 
109 /*
110  * Check if current profile is default profile.
111  */
112 WS_DLL_PUBLIC gboolean is_default_profile(void);
113 
114 /*
115  * Check if we have global profiles.
116  */
117 WS_DLL_PUBLIC gboolean has_global_profiles(void);
118 
119 /*
120  * Get the directory used to store configuration profile directories.
121  * Caller must free the returned string
122  */
123 WS_DLL_PUBLIC char *get_profiles_dir(void);
124 
125 /*
126  * Create the directory used to store configuration profile directories.
127  */
128 WS_DLL_PUBLIC int create_profiles_dir(char **pf_dir_path_return);
129 
130 /*
131  * Get the directory used to store global configuration profile directories.
132  * Caller must free the returned string
133  */
134 WS_DLL_PUBLIC char *get_global_profiles_dir(void);
135 
136 
137 /*
138  * Store filenames used for personal config files so we know which
139  * files to copy when duplicate a configuration profile.
140  */
141 WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
142 
143 /*
144  * Check if given configuration profile exists.
145  */
146 WS_DLL_PUBLIC gboolean profile_exists(const gchar *profilename, gboolean global);
147 
148 /*
149  * Create a directory for the given configuration profile.
150  * If we attempted to create it, and failed, return -1 and
151  * set "*pf_dir_path_return" to the pathname of the directory we failed
152  * to create (it's g_mallocated, so our caller should free it); otherwise,
153  * return 0.
154  */
155 WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
156  char **pf_dir_path_return);
157 
158 /*
159  * Delete the directory for the given configuration profile.
160  * If we attempted to delete it, and failed, return -1 and
161  * set "*pf_dir_path_return" to the pathname of the directory we failed
162  * to delete (it's g_mallocated, so our caller should free it); otherwise,
163  * return 0.
164  */
165 WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
166  char **pf_dir_path_return);
167 
168 /*
169  * Rename the directory for the given confinguration profile.
170  */
171 WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
172  char **pf_from_dir_path_return,
173  char **pf_to_dir_path_return);
174 
175 /*
176  * Copy files in one profile to the other.
177  */
178 WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
179  gboolean from_global,
180  char **pf_filename_return,
181  char **pf_to_dir_path_return,
182  char **pf_from_dir_path_return);
183 
184 /*
185  * Create the directory that holds personal configuration files, if
186  * necessary. If we attempted to create it, and failed, return -1 and
187  * set "*pf_dir_path_return" to the pathname of the directory we failed
188  * to create (it's g_mallocated, so our caller should free it); otherwise,
189  * return 0.
190  */
191 WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
192 
193 /*
194  * Construct the path name of a personal configuration file, given the
195  * file name. If using configuration profiles this directory will be
196  * used if "from_profile" is TRUE.
197  *
198  * The returned file name was g_malloc()'d so it must be g_free()d when the
199  * caller is done with it.
200  */
201 WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, gboolean from_profile);
202 
203 /*
204  * Set the path of the personal configuration file directory.
205  */
206 WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
207 
208 /*
209  * Get the (default) directory in which personal data is stored.
210  *
211  * On Win32, this is the "My Documents" folder in the personal profile.
212  * On UNIX this is simply the current directory.
213  */
214 WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
215 
216 /*
217  * Set the path of the directory in which personal data is stored.
218  */
219 WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
220 
221 /*
222  * Return an error message for UNIX-style errno indications on open or
223  * create operations.
224  */
225 WS_DLL_PUBLIC const char *file_open_error_message(int err, gboolean for_writing);
226 
227 /*
228  * Return an error message for UNIX-style errno indications on write
229  * operations.
230  */
231 WS_DLL_PUBLIC const char *file_write_error_message(int err);
232 
233 /*
234  * Given a pathname, return the last component.
235  */
236 WS_DLL_PUBLIC const char *get_basename(const char *);
237 
238  /*
239  * Given a pathname, return a pointer to the last pathname separator
240  * character in the pathname, or NULL if the pathname contains no
241  * separators.
242  */
243 WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
244 
245 /*
246  * Given a pathname, return a string containing everything but the
247  * last component. NOTE: this overwrites the pathname handed into
248  * it....
249  */
250 WS_DLL_PUBLIC char *get_dirname(char *);
251 
252 /*
253  * Given a pathname, return:
254  *
255  * the errno, if an attempt to "stat()" the file fails;
256  *
257  * EISDIR, if the attempt succeeded and the file turned out
258  * to be a directory;
259  *
260  * 0, if the attempt succeeded and the file turned out not
261  * to be a directory.
262  */
263 WS_DLL_PUBLIC int test_for_directory(const char *);
264 
265 /*
266  * Given a pathname, return:
267  *
268  * the errno, if an attempt to "stat()" the file fails;
269  *
270  * ESPIPE, if the attempt succeeded and the file turned out
271  * to be a FIFO;
272  *
273  * 0, if the attempt succeeded and the file turned out not
274  * to be a FIFO.
275  */
276 WS_DLL_PUBLIC int test_for_fifo(const char *);
277 
278 /*
279  * Check, if file is existing.
280  */
281 WS_DLL_PUBLIC gboolean file_exists(const char *fname);
282 
283 /*
284  * Check if two filenames are identical (with absolute and relative paths).
285  */
286 WS_DLL_PUBLIC gboolean files_identical(const char *fname1, const char *fname2);
287 
288 /*
289  * Copy a file in binary mode, for those operating systems that care about
290  * such things. This should be OK for all files, even text files, as
291  * we'll copy the raw bytes, and we don't look at the bytes as we copy
292  * them.
293  *
294  * Returns TRUE on success, FALSE on failure. If a failure, it also
295  * displays a simple dialog window with the error message.
296  */
297 WS_DLL_PUBLIC gboolean copy_file_binary_mode(const char *from_filename,
298  const char *to_filename);
299 
300 
301 /*
302  * Given a filename return a filesystem URL. Relative paths are prefixed with
303  * the datafile directory path.
304  *
305  * @param filename A file name or path. Relative paths will be prefixed with
306  * the data file directory path.
307  * @return A filesystem URL for the file or NULL on failure. A non-NULL return
308  * value must be freed with g_free().
309  */
310 WS_DLL_PUBLIC gchar* data_file_url(const gchar *filename);
311 
312 /*
313  * Free the internal structtures
314  */
315 WS_DLL_PUBLIC void free_progdirs(void);
316 
317 #ifdef __cplusplus
318 }
319 #endif /* __cplusplus */
320 
321 #endif /* FILESYSTEM_H */