Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
filesystem.h
Go to the documentation of this file.
1
11#ifndef FILESYSTEM_H
12#define FILESYSTEM_H
13
14#include <wireshark.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/*
21 * Default profile name.
22 */
23#define DEFAULT_PROFILE "Default"
24
36WS_DLL_PUBLIC char *configuration_init(const char *arg0);
37
38/*
39 * Get the directory in which the main (Wireshark, TShark, Stratoshark, etc)
40 * program resides.
41 * Extcaps should use get_extcap_dir() to get their path.
42 *
43 * @return The main program file directory.
44 */
45WS_DLL_PUBLIC const char *get_progfile_dir(void);
46
47/*
48 * Construct the path name of a non-extcap Wireshark executable file,
49 * given the program name. The executable name doesn't include ".exe";
50 * append it on Windows, so that callers don't have to worry about that.
51 *
52 * This presumes that all non-extcap executables are in the same directory.
53 *
54 * The returned file name was g_malloc()'d so it must be g_free()d when the
55 * caller is done with it.
56 */
57WS_DLL_PUBLIC char *get_executable_path(const char *filename);
58
59/*
60 * Get the directory in which plugins are stored; this must not be called
61 * before configuration_init() is called, as they might be stored in a
62 * subdirectory of the program file directory.
63 */
64WS_DLL_PUBLIC const char *get_plugins_dir(void);
65
66/*
67 * Append VERSION_MAJOR.VERSION_MINOR to the plugin dir.
68 */
69WS_DLL_PUBLIC const char *get_plugins_dir_with_version(void);
70
71/*
72 * Get the personal plugin dir.
73 */
74WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);
75
76/*
77 * Append VERSION_MAJOR.VERSION_MINOR to the plugin personal dir.
78 */
79WS_DLL_PUBLIC const char *get_plugins_pers_dir_with_version(void);
80
81/*
82 * Get the directory in which extcap hooks are stored; this must not be called
83 * before configuration_init() is called, as they might be stored in a
84 * subdirectory of the program file directory.
85 */
86WS_DLL_PUBLIC const char *get_extcap_dir(void);
87
88/*
89 * Get the personal extcap dir.
90 */
91WS_DLL_PUBLIC const char *get_extcap_pers_dir(void);
92
93/*
94 * Get the flag indicating whether we're running from a build
95 * directory.
96 */
97WS_DLL_PUBLIC bool running_in_build_directory(void);
98
99/*
100 * Get the directory in which global configuration files are
101 * stored.
102 */
103WS_DLL_PUBLIC const char *get_datafile_dir(void);
104
105/*
106 * Construct the path name of a global configuration file, given the
107 * file name.
108 *
109 * The returned file name was g_malloc()'d so it must be g_free()d when the
110 * caller is done with it.
111 */
112WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
113
114/*
115 * Get the directory in which global documentation files are
116 * stored.
117 */
118WS_DLL_PUBLIC const char *get_doc_dir(void);
119
120/*
121 * Construct the path name of a global documentation file, given the
122 * file name.
123 *
124 * The returned file name was g_malloc()'d so it must be g_free()d when the
125 * caller is done with it.
126 */
127WS_DLL_PUBLIC char *get_docfile_path(const char *filename);
128
129/*
130 * Construct the path URL of a global documentation file, given the
131 * file name.
132 *
133 * The returned file name was g_malloc()'d so it must be g_free()d when the
134 * caller is done with it.
135 */
136WS_DLL_PUBLIC char *doc_file_url(const char *filename);
137
138/*
139 * Get the directory in which files that, at least on UNIX, are
140 * system files (such as "/etc/ethers") are stored; on Windows,
141 * there's no "/etc" directory, so we get them from the Wireshark
142 * global configuration and data file directory.
143 */
144WS_DLL_PUBLIC const char *get_systemfile_dir(void);
145
146/*
147 * Set the configuration profile name to be used for storing
148 * personal configuration files.
149 */
150WS_DLL_PUBLIC void set_profile_name(const char *profilename);
151
152/*
153 * Get the current configuration profile name used for storing
154 * personal configuration files.
155 */
156WS_DLL_PUBLIC const char *get_profile_name(void);
157
158/*
159 * Check if current profile is default profile.
160 */
161WS_DLL_PUBLIC bool is_default_profile(void);
162
163/*
164 * Check if we have global profiles.
165 */
166WS_DLL_PUBLIC bool has_global_profiles(void);
167
168/*
169 * Get the directory used to store configuration profile directories.
170 * Caller must free the returned string
171 */
172WS_DLL_PUBLIC char *get_profiles_dir(void);
173
174/*
175 * Get the directory used to store configuration files for a given profile.
176 * Caller must free the returned string.
177 */
178WS_DLL_PUBLIC char *get_profile_dir(const char *profilename, bool is_global);
179
180/*
181 * Create the directory used to store configuration profile directories.
182 */
183WS_DLL_PUBLIC int create_profiles_dir(char **pf_dir_path_return);
184
185/*
186 * Get the directory used to store global configuration profile directories.
187 * Caller must free the returned string
188 */
189WS_DLL_PUBLIC char *get_global_profiles_dir(void);
190
191
192/*
193 * Store filenames used for personal config files so we know which
194 * files to copy when duplicate a configuration profile.
195 */
196WS_DLL_PUBLIC void profile_store_persconffiles(bool store);
197
198/*
199 * Register a filename to the personal config files storage.
200 * This is for files which are not read using get_persconffile_path() during startup.
201 */
202WS_DLL_PUBLIC void profile_register_persconffile(const char *filename);
203
204/*
205 * Check if given configuration profile exists.
206 */
207WS_DLL_PUBLIC bool profile_exists(const char *profilename, bool global);
208
209/*
210 * Create a directory for the given configuration profile.
211 * If we attempted to create it, and failed, return -1 and
212 * set "*pf_dir_path_return" to the pathname of the directory we failed
213 * to create (it's g_mallocated, so our caller should free it); otherwise,
214 * return 0.
215 */
216WS_DLL_PUBLIC int create_persconffile_profile(const char *profilename,
217 char **pf_dir_path_return);
218
219/*
220 * Returns the list of known profile config filenames
221 */
222WS_DLL_PUBLIC const GHashTable * allowed_profile_filenames(void);
223
224/*
225 * Delete the directory for the given configuration profile.
226 * If we attempted to delete it, and failed, return -1 and
227 * set "*pf_dir_path_return" to the pathname of the directory we failed
228 * to delete (it's g_mallocated, so our caller should free it); otherwise,
229 * return 0.
230 */
231WS_DLL_PUBLIC int delete_persconffile_profile(const char *profilename,
232 char **pf_dir_path_return);
233
234/*
235 * Rename the directory for the given confinguration profile.
236 */
237WS_DLL_PUBLIC int rename_persconffile_profile(const char *fromname, const char *toname,
238 char **pf_from_dir_path_return,
239 char **pf_to_dir_path_return);
240
241/*
242 * Copy files in one profile to the other.
243 */
244WS_DLL_PUBLIC int copy_persconffile_profile(const char *toname, const char *fromname,
245 bool from_global,
246 char **pf_filename_return,
247 char **pf_to_dir_path_return,
248 char **pf_from_dir_path_return);
249
250/*
251 * Create the directory that holds personal configuration files, if
252 * necessary. If we attempted to create it, and failed, return -1 and
253 * set "*pf_dir_path_return" to the pathname of the directory we failed
254 * to create (it's g_mallocated, so our caller should free it); otherwise,
255 * return 0.
256 */
257WS_DLL_PUBLIC int create_persconffile_dir(char **pf_dir_path_return);
258
259/*
260 * Construct the path name of a personal configuration file, given the
261 * file name. If using configuration profiles this directory will be
262 * used if "from_profile" is true.
263 *
264 * The returned file name was g_malloc()'d so it must be g_free()d when the
265 * caller is done with it.
266 */
267WS_DLL_PUBLIC char *get_persconffile_path(const char *filename, bool from_profile);
268
269/*
270 * Set the path of the personal configuration file directory.
271 */
272WS_DLL_PUBLIC void set_persconffile_dir(const char *p);
273
274/*
275 * Get the (default) directory in which personal data is stored.
276 *
277 * On Win32, this is the "My Documents" folder in the personal profile.
278 * On UNIX this is simply the current directory.
279 */
280WS_DLL_PUBLIC const char *get_persdatafile_dir(void);
281
282/*
283 * Set the path of the directory in which personal data is stored.
284 */
285WS_DLL_PUBLIC void set_persdatafile_dir(const char *p);
286
287/*
288 * Get the current working directory.
289 */
290WS_DLL_PUBLIC WS_RETNONNULL const char *get_current_working_dir(void);
291
292/*
293 * Return an error message for UNIX-style errno indications on open or
294 * create operations.
295 */
296WS_DLL_PUBLIC const char *file_open_error_message(int err, bool for_writing);
297
298/*
299 * Return an error message for UNIX-style errno indications on write
300 * operations.
301 */
302WS_DLL_PUBLIC const char *file_write_error_message(int err);
303
304/*
305 * Given a pathname, return the last component.
306 */
307WS_DLL_PUBLIC const char *get_basename(const char *);
308
309 /*
310 * Given a pathname, return a pointer to the last pathname separator
311 * character in the pathname, or NULL if the pathname contains no
312 * separators.
313 */
314WS_DLL_PUBLIC char *find_last_pathname_separator(const char *path);
315
316/*
317 * Given a pathname, return a string containing everything but the
318 * last component. NOTE: this overwrites the pathname handed into
319 * it....
320 */
321WS_DLL_PUBLIC char *get_dirname(char *);
322
323/*
324 * Given a pathname, return:
325 *
326 * the errno, if an attempt to "stat()" the file fails;
327 *
328 * EISDIR, if the attempt succeeded and the file turned out
329 * to be a directory;
330 *
331 * 0, if the attempt succeeded and the file turned out not
332 * to be a directory.
333 */
334WS_DLL_PUBLIC int test_for_directory(const char *);
335
336/*
337 * Given a pathname, return:
338 *
339 * the errno, if an attempt to "stat()" the file fails;
340 *
341 * ESPIPE, if the attempt succeeded and the file turned out
342 * to be a FIFO;
343 *
344 * 0, if the attempt succeeded and the file turned out not
345 * to be a FIFO.
346 */
347WS_DLL_PUBLIC int test_for_fifo(const char *);
348
349/*
350 * Given a pathname, return true if the attempt to "stat()" the file
351 * succeeds, and it turns out to be a regular file. "stat()" follows
352 * links, so returns true if the pathname is a link to a regular file.
353 */
354WS_DLL_PUBLIC bool test_for_regular_file(const char *);
355
356/*
357 * Check if a file exists.
358 */
359WS_DLL_PUBLIC bool file_exists(const char *fname);
360
361/*
362 * Check if file is existing and has text entries which does not start
363 * with the comment character.
364 */
365WS_DLL_PUBLIC bool config_file_exists_with_entries(const char *fname, char comment_char);
366
367/*
368 * Check if two filenames are identical (with absolute and relative paths).
369 */
370WS_DLL_PUBLIC bool files_identical(const char *fname1, const char *fname2);
371
372/*
373 * Check if file has been recreated since it was opened.
374 */
375WS_DLL_PUBLIC bool file_needs_reopen(int fd, const char* filename);
376
377/*
378 * Write content to a file in binary mode, for those operating systems that
379 * care about such things. This should be OK for all files, even text files, as
380 * we'll write the raw bytes, and we don't look at the bytes as we copy them.
381 *
382 * Returns true on success, false on failure. If a failure, it also
383 * displays a simple dialog window with the error message.
384 */
385WS_DLL_PUBLIC bool write_file_binary_mode(const char *filename,
386 const void *content, size_t content_len);
387
388/*
389 * Copy a file in binary mode, for those operating systems that care about
390 * such things. This should be OK for all files, even text files, as
391 * we'll copy the raw bytes, and we don't look at the bytes as we copy
392 * them.
393 *
394 * Returns true on success, false on failure. If a failure, it also
395 * displays a simple dialog window with the error message.
396 */
397WS_DLL_PUBLIC bool copy_file_binary_mode(const char *from_filename,
398 const char *to_filename);
399
400
401/*
402 * Given a filename return a filesystem URL. Relative paths are prefixed with
403 * the datafile directory path.
404 *
405 * @param filename A file name or path. Relative paths will be prefixed with
406 * the data file directory path.
407 * @return A filesystem URL for the file or NULL on failure. A non-NULL return
408 * value must be freed with g_free().
409 */
410WS_DLL_PUBLIC char* data_file_url(const char *filename);
411
412/*
413 * Free the internal structtures
414 */
415WS_DLL_PUBLIC void free_progdirs(void);
416
417#ifdef __cplusplus
418}
419#endif /* __cplusplus */
420
421#endif /* FILESYSTEM_H */
WS_DLL_PUBLIC char * configuration_init(const char *arg0)
Definition filesystem.c:930