diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/filesystem.c | 73 | ||||
-rw-r--r-- | epan/filesystem.h | 14 | ||||
-rw-r--r-- | epan/libwireshark.def | 2 |
3 files changed, 82 insertions, 7 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c index 10a849edfc..c7a5cbe3b5 100644 --- a/epan/filesystem.c +++ b/epan/filesystem.c @@ -912,6 +912,34 @@ is_default_profile(void) return (!persconfprofile || strcmp(persconfprofile, DEFAULT_PROFILE) == 0) ? TRUE : FALSE; } +gboolean +has_global_profiles(void) +{ + WS_DIR *dir; + WS_DIRENT *file; + const gchar *global_dir = get_global_profiles_dir(); + gchar *filename; + gboolean has_global = FALSE; + + if ((test_for_directory(global_dir) == EISDIR) && + ((dir = ws_dir_open(global_dir, 0, NULL)) != NULL)) + { + while ((file = ws_dir_read_name(dir)) != NULL) { + filename = g_strdup_printf ("%s%s%s", global_dir, G_DIR_SEPARATOR_S, + ws_dir_get_name(file)); + if (test_for_directory(filename) == EISDIR) { + has_global = TRUE; + g_free (filename); + break; + } + g_free (filename); + } + ws_dir_close(dir); + } + + return has_global; +} + void profile_store_persconffiles(gboolean store) { @@ -1027,6 +1055,19 @@ get_profiles_dir(void) return profiles_dir; } +const char * +get_global_profiles_dir(void) +{ + static char *global_profiles_dir = NULL; + + if (!global_profiles_dir) { + global_profiles_dir = g_strdup_printf ("%s%s%s", get_datafile_dir(), + G_DIR_SEPARATOR_S, PROFILES_DIR); + } + + return global_profiles_dir; +} + static const char * get_persconffile_dir(const gchar *profilename) { @@ -1046,10 +1087,20 @@ get_persconffile_dir(const gchar *profilename) } gboolean -profile_exists(const gchar *profilename) +profile_exists(const gchar *profilename, gboolean global) { - if (test_for_directory (get_persconffile_dir (profilename)) == EISDIR) { - return TRUE; + if (global) { + gchar *path = g_strdup_printf ("%s%s%s", get_global_profiles_dir(), + G_DIR_SEPARATOR_S, profilename); + if (test_for_directory (path) == EISDIR) { + g_free (path); + return TRUE; + } + g_free (path); + } else { + if (test_for_directory (get_persconffile_dir (profilename)) == EISDIR) { + return TRUE; + } } return FALSE; @@ -1222,14 +1273,24 @@ hash_table_get_keys(gpointer key, gpointer value _U_, gpointer user_data) #endif int -copy_persconffile_profile(const char *toname, const char *fromname, char **pf_filename_return, - char **pf_to_dir_path_return, char **pf_from_dir_path_return) +copy_persconffile_profile(const char *toname, const char *fromname, gboolean from_global, + char **pf_filename_return, char **pf_to_dir_path_return, char **pf_from_dir_path_return) { - gchar *from_dir = g_strdup (get_persconffile_dir(fromname)); + gchar *from_dir; gchar *to_dir = g_strdup (get_persconffile_dir(toname)); gchar *filename, *from_file, *to_file; GList *files, *file; + if (from_global) { + if (strcmp(fromname, DEFAULT_PROFILE) == 0) { + from_dir = g_strdup (get_global_profiles_dir()); + } else { + from_dir = g_strdup_printf ("%s%s%s", get_global_profiles_dir(), G_DIR_SEPARATOR_S, fromname); + } + } else { + from_dir = g_strdup (get_persconffile_dir(fromname)); + } + #if GLIB_CHECK_VERSION(2,14,0) files = g_hash_table_get_keys(profile_files); #else diff --git a/epan/filesystem.h b/epan/filesystem.h index 065fe2fbce..98c3053cc2 100644 --- a/epan/filesystem.h +++ b/epan/filesystem.h @@ -113,11 +113,22 @@ extern const char *get_profile_name(void); extern gboolean is_default_profile(void); /* + * Check if we have global profiles. + */ +extern gboolean has_global_profiles(void); + +/* * Get the directory used to store configuration profile directories. */ extern const char *get_profiles_dir(void); /* + * Get the directory used to store global configuration profile directories. + */ +extern const char *get_global_profiles_dir(void); + + +/* * Store filenames used for personal config files so we know which * files to copy when duplicate a configuration profile. */ @@ -126,7 +137,7 @@ extern void profile_store_persconffiles(gboolean store); /* * Check if given configuration profile exists. */ -extern gboolean profile_exists(const gchar *profilename); +extern gboolean profile_exists(const gchar *profilename, gboolean global); /* * Create a directory for the given configuration profile. @@ -159,6 +170,7 @@ extern int rename_persconffile_profile(const char *fromname, const char *toname, * Copy files in one profile to the other. */ extern int copy_persconffile_profile(const char *toname, const char *fromname, + gboolean from_global, char **pf_filename_return, char **pf_to_dir_path_return, char **pf_from_dir_path_return); diff --git a/epan/libwireshark.def b/epan/libwireshark.def index 7354fe9b43..84e425da88 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -544,6 +544,7 @@ get_dissector_table_selector_type get_dissector_table_ui_name get_dissector_table_base get_ether_name +get_global_profiles_dir get_host_ipaddr get_host_ipaddr6 get_hostname @@ -592,6 +593,7 @@ h245_set_h223_add_lc_handle h245_set_h223_set_mc_handle h248_param_ber_integer h248_register_package +has_global_profiles have_custom_cols have_filtering_tap_listeners have_tap_listeners |