void init_pyreshark(void) { char *py_init_path; char *python_cmd; void *py_init_file; python_version_t py_version = PYTHON_VERSION_NOT_SET; g_python_lib = load_python(&py_version); if (g_python_lib == NULL) { return; } python_cmd = g_strdup_printf("import sys;sys.path.append(\'%s\')", get_datafile_path(PYTHON_DIR)); g_python_lib->PyRun_SimpleStringFlags(python_cmd, NULL); g_free(python_cmd); py_init_path = get_datafile_path(PYTHON_DIR G_DIR_SEPARATOR_S PYRESHARK_INIT_FILE); py_init_file = g_python_lib->PyFile_FromString((char *)py_init_path, (char *)"rb"); if (NULL == py_init_file) { printf("Can't open Pyreshark init file: %s\n", py_init_path); g_free(py_init_path); return; } g_free(py_init_path); if (py_version == PYTHON_VERSION_27) { g_python_lib->PyRun_SimpleFileExFlags(g_python_lib->PyFile_AsFile(py_init_file), PYRESHARK_INIT_FILE, FALSE, NULL); } else { g_python_lib->PyRun_SimpleFileExFlags(g_python_lib->PyFile_AsFile(py_init_file), PYRESHARK_INIT_FILE, TRUE, NULL); } g_python_lib->Py_DecRef(py_init_file); }
static GtkWidget * about_license_page_new(void) { GtkWidget *page; char *absolute_path; #if defined(_WIN32) absolute_path = get_datafile_path("COPYING.txt"); #else absolute_path = get_datafile_path("COPYING"); #endif page = text_page_new(absolute_path); return page; }
/* read filters from the filter file */ gboolean color_filters_read_globals(gpointer user_data) { gchar *path; FILE *f; gboolean ret; /* decide what file to open (from dfilter code) */ path = get_datafile_path("colorfilters"); if ((f = ws_fopen(path, "r")) == NULL) { if (errno != ENOENT) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not open global filter file\n\"%s\": %s.", path, g_strerror(errno)); } g_free(path); return FALSE; } g_free(path); path = NULL; ret = read_filters_file(f, user_data); fclose(f); return ret; }
/* read filters from the filter file */ gboolean color_filters_read_globals(gpointer user_data, gchar** err_msg, color_filter_add_cb_func add_cb) { gchar *path; FILE *f; int ret; /* decide what file to open (from dfilter code) */ path = get_datafile_path("colorfilters"); if ((f = ws_fopen(path, "r")) == NULL) { if (errno != ENOENT) { *err_msg = g_strdup_printf("Could not open global filter file\n\"%s\": %s.", path, g_strerror(errno)); } g_free(path); return FALSE; } ret = read_filters_file(path, f, user_data, add_cb); if (ret != 0) { *err_msg = g_strdup_printf("Error reading global filter file\n\"%s\": %s.", path, g_strerror(errno)); fclose(f); g_free(path); return FALSE; } fclose(f); g_free(path); return TRUE; }
WSLUA_FUNCTION wslua_datafile_path(lua_State* L) { #define WSLUA_OPTARG_datafile_path_FILENAME 1 /* A filename */ const char *fname = luaL_optstring(L, WSLUA_OPTARG_datafile_path_FILENAME,""); char* filename = get_datafile_path(fname); lua_pushstring(L,filename); g_free(filename); WSLUA_RETURN(1); /* The full pathname for a file in wireshark's configuration directory */ }
static GtkWidget * about_authors_page_new(void) { GtkWidget *page; char *absolute_path; absolute_path = get_datafile_path("AUTHORS-SHORT"); page = text_page_new(absolute_path); return page; }
/* except when NULL is returned if file doesn't exist */ char* wslua_get_actual_filename(const char* fname) { char fname_clean[256]; char* f; char* filename; g_strlcpy(fname_clean,fname,255); fname_clean[255] = '\0'; for(f = fname_clean; *f; f++) { switch(*f) { case '/': case '\\': *f = *(G_DIR_SEPARATOR_S); break; default: break; } } if ( file_exists(fname_clean) ) { return g_strdup(fname_clean); } filename = get_persconffile_path(fname_clean,FALSE); if ( file_exists(filename) ) { return filename; } g_free(filename); filename = get_datafile_path(fname_clean); if ( file_exists(filename) ) { return filename; } g_free(filename); if (running_in_build_directory()) { /* Running in build directory, try the source directory (Autotools) */ filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "epan" G_DIR_SEPARATOR_S "wslua" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), fname_clean); if (( ! file_exists(filename))) { /* Try the CMake output directory */ g_free(filename); filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_progfile_dir(), fname_clean); } if ( file_exists(filename) ) { return filename; } g_free(filename); } return NULL; }
WSLUA_CONSTRUCTOR Dir_global_config_path(lua_State* L) { /* Gets the global configuration directory path, with filename if supplied. @since 1.11.3 */ #define WSLUA_OPTARG_global_config_path_FILENAME 1 /* A filename */ const char *fname = luaL_optstring(L, WSLUA_OPTARG_global_config_path_FILENAME,""); char* filename; if (running_in_build_directory()) { /* Running in build directory, set datafile_path to wslua source directory */ filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "epan" G_DIR_SEPARATOR_S "wslua" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), fname); } else { filename = get_datafile_path(fname); } lua_pushstring(L,filename); g_free(filename); WSLUA_RETURN(1); /* The full pathname for a file in wireshark's configuration directory. */ }
/* The returned filename was g_malloc()'d so the caller must free it */ gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing) { gchar *pers_fname = NULL; if (! uat->from_global) { pers_fname = get_persconffile_path(uat->filename, uat->from_profile); } if ((! for_writing ) && (! file_exists(pers_fname) )) { gchar* data_fname = get_datafile_path(uat->filename); if (file_exists(data_fname)) { g_free(pers_fname); return data_fname; } g_free(data_fname); g_free(pers_fname); return NULL; } return pers_fname; }
/* except when NULL is returned if file doesn't exist */ static char* wslua_get_actual_filename(const char* fname) { char fname_clean[256]; char* f; char* filename; g_strlcpy(fname_clean,fname,255); fname_clean[255] = '\0'; for(f = fname_clean; *f; f++) { switch(*f) { case '/': case '\\': *f = *(G_DIR_SEPARATOR_S); break; default: break; } } if ( file_exists(fname_clean) ) { return g_strdup(fname_clean); } filename = get_persconffile_path(fname_clean,FALSE,FALSE); if ( file_exists(filename) ) { return filename; } g_free(filename); filename = get_datafile_path(fname_clean); if ( file_exists(filename) ) { return filename; } g_free(filename); return NULL; }
void read_filter_list(filter_list_type_t list_type, char **pref_path_return, int *errno_return) { const char *ff_name; char *ff_path; FILE *ff; GList **flpp; int c; char *filt_name, *filt_expr; int filt_name_len, filt_expr_len; int filt_name_index, filt_expr_index; int line = 1; *pref_path_return = NULL; /* assume no error */ switch (list_type) { case CFILTER_LIST: ff_name = CFILTER_FILE_NAME; flpp = &capture_filters; break; case DFILTER_LIST: ff_name = DFILTER_FILE_NAME; flpp = &display_filters; break; default: g_assert_not_reached(); return; } /* try to open personal "cfilters"/"dfilters" file */ ff_path = get_persconffile_path(ff_name, TRUE); if ((ff = ws_fopen(ff_path, "r")) == NULL) { /* * Did that fail because the file didn't exist? */ if (errno != ENOENT) { /* * No. Just give up. */ *pref_path_return = ff_path; *errno_return = errno; return; } /* * Yes. See if there's an "old style" personal "filters" file; if so, read it. * This means that a user will start out with their capture and * display filter lists being identical; each list may contain * filters that don't belong in that list. The user can edit * the filter lists, and delete the ones that don't belong in * a particular list. */ g_free(ff_path); ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE); if ((ff = ws_fopen(ff_path, "r")) == NULL) { /* * Did that fail because the file didn't exist? */ if (errno != ENOENT) { /* * No. Just give up. */ *pref_path_return = ff_path; *errno_return = errno; return; } /* * Try to open the global "cfilters/dfilters" file */ g_free(ff_path); ff_path = get_datafile_path(ff_name); if ((ff = ws_fopen(ff_path, "r")) == NULL) { /* * Well, that didn't work, either. Just give up. * Return an error if the file existed but we couldn't open it. */ if (errno != ENOENT) { *pref_path_return = ff_path; *errno_return = errno; } else { g_free(ff_path); } return; } } } /* If we already have a list of filters, discard it. */ /* this should never happen - this function is called only once for each list! */ while(*flpp) { *flpp = remove_filter_entry(*flpp, g_list_first(*flpp)); } /* Allocate the filter name buffer. */ filt_name_len = INIT_BUF_SIZE; filt_name = (char *)g_malloc(filt_name_len + 1); filt_expr_len = INIT_BUF_SIZE; filt_expr = (char *)g_malloc(filt_expr_len + 1); for (line = 1; ; line++) { /* Lines in a filter file are of the form "name" expression where "name" is a name, in quotes - backslashes in the name escape the next character, so quotes and backslashes can appear in the name - and "expression" is a filter expression, not in quotes, running to the end of the line. */ /* Skip over leading white space, if any. */ c = skip_whitespace(ff); if (c == EOF) break; /* Nothing more to read */ if (c == '\n') continue; /* Blank line. */ /* "c" is the first non-white-space character. If it's not a quote, it's an error. */ if (c != '"') { g_warning("'%s' line %d doesn't have a quoted filter name.", ff_path, line); while (c != '\n') c = getc(ff); /* skip to the end of the line */ continue; } /* Get the name of the filter. */ filt_name_index = 0; for (;;) { c = getc_crlf(ff); if (c == EOF || c == '\n') break; /* End of line - or end of file */ if (c == '"') { /* Closing quote. */ if (filt_name_index >= filt_name_len) { /* Filter name buffer isn't long enough; double its length. */ filt_name_len *= 2; filt_name = (char *)g_realloc(filt_name, filt_name_len + 1); } filt_name[filt_name_index] = '\0'; break; } if (c == '\\') { /* Next character is escaped */ c = getc_crlf(ff); if (c == EOF || c == '\n') break; /* End of line - or end of file */ } /* Add this character to the filter name string. */ if (filt_name_index >= filt_name_len) { /* Filter name buffer isn't long enough; double its length. */ filt_name_len *= 2; filt_name = (char *)g_realloc(filt_name, filt_name_len + 1); } filt_name[filt_name_index] = c; filt_name_index++; } if (c == EOF) { if (!ferror(ff)) { /* EOF, not error; no newline seen before EOF */ g_warning("'%s' line %d doesn't have a newline.", ff_path, line); } break; /* nothing more to read */ } if (c != '"') { /* No newline seen before end-of-line */ g_warning("'%s' line %d doesn't have a closing quote.", ff_path, line); continue; } /* Skip over separating white space, if any. */ c = skip_whitespace(ff); if (c == EOF) { if (!ferror(ff)) { /* EOF, not error; no newline seen before EOF */ g_warning("'%s' line %d doesn't have a newline.", ff_path, line); } break; /* nothing more to read */ } if (c == '\n') { /* No filter expression */ g_warning("'%s' line %d doesn't have a filter expression.", ff_path, line); continue; } /* "c" is the first non-white-space character; it's the first character of the filter expression. */ filt_expr_index = 0; for (;;) { /* Add this character to the filter expression string. */ if (filt_expr_index >= filt_expr_len) { /* Filter expressioin buffer isn't long enough; double its length. */ filt_expr_len *= 2; filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1); } filt_expr[filt_expr_index] = c; filt_expr_index++; /* Get the next character. */ c = getc_crlf(ff); if (c == EOF || c == '\n') break; } if (c == EOF) { if (!ferror(ff)) { /* EOF, not error; no newline seen before EOF */ g_warning("'%s' line %d doesn't have a newline.", ff_path, line); } break; /* nothing more to read */ } /* We saw the ending newline; terminate the filter expression string */ if (filt_expr_index >= filt_expr_len) { /* Filter expressioin buffer isn't long enough; double its length. */ filt_expr_len *= 2; filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1); } filt_expr[filt_expr_index] = '\0'; /* Add the new filter to the list of filters */ *flpp = add_filter_entry(*flpp, filt_name, filt_expr); } if (ferror(ff)) { *pref_path_return = ff_path; *errno_return = errno; } else g_free(ff_path); fclose(ff); g_free(filt_name); g_free(filt_expr); /* init the corresponding edited list */ switch (list_type) { case CFILTER_LIST: copy_filter_list(CFILTER_EDITED_LIST, CFILTER_LIST); break; case DFILTER_LIST: copy_filter_list(DFILTER_EDITED_LIST, DFILTER_LIST); break; default: g_assert_not_reached(); return; } }
void read_disabled_protos_list(char **gpath_return, int *gopen_errno_return, int *gread_errno_return, char **path_return, int *open_errno_return, int *read_errno_return) { int err; char *gff_path, *ff_path; FILE *ff; /* Construct the pathname of the global disabled protocols file. */ gff_path = get_datafile_path(GLOBAL_PROTOCOLS_FILE_NAME); /* If we already have a list of protocols, discard it. */ discard_existing_list (&global_disabled_protos); /* Read the global disabled protocols file, if it exists. */ *gpath_return = NULL; if ((ff = ws_fopen(gff_path, "r")) != NULL) { /* We succeeded in opening it; read it. */ err = read_disabled_protos_list_file(gff_path, ff, &global_disabled_protos); if (err != 0) { /* We had an error reading the file; return the errno and the pathname, so our caller can report the error. */ *gopen_errno_return = 0; *gread_errno_return = err; *gpath_return = gff_path; } else g_free(gff_path); fclose(ff); } else { /* We failed to open it. If we failed for some reason other than "it doesn't exist", return the errno and the pathname, so our caller can report the error. */ if (errno != ENOENT) { *gopen_errno_return = errno; *gread_errno_return = 0; *gpath_return = gff_path; } else g_free(gff_path); } /* Construct the pathname of the user's disabled protocols file. */ ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, TRUE, FALSE); /* If we already have a list of protocols, discard it. */ discard_existing_list (&disabled_protos); /* Read the user's disabled protocols file, if it exists. */ *path_return = NULL; if ((ff = ws_fopen(ff_path, "r")) != NULL) { /* We succeeded in opening it; read it. */ err = read_disabled_protos_list_file(ff_path, ff, &disabled_protos); if (err != 0) { /* We had an error reading the file; return the errno and the pathname, so our caller can report the error. */ *open_errno_return = 0; *read_errno_return = err; *path_return = ff_path; } else g_free(ff_path); fclose(ff); } else { /* We failed to open it. If we failed for some reason other than "it doesn't exist", return the errno and the pathname, so our caller can report the error. */ if (errno != ENOENT) { *open_errno_return = errno; *read_errno_return = 0; *path_return = ff_path; } else g_free(ff_path); } }
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) { ui->setupUi(this); QFile f_authors; QFile f_license; char *path = NULL; const char *constpath; gchar *message; #if defined (HAVE_LIBSMI) || defined (HAVE_GEOIP) gint i; gchar **resultArray; #endif /* Wireshark tab */ /* Construct the message string */ message = g_strdup_printf( "Version " VERSION "%s\n" "\n" "%s" "\n" "%s" "\n" "%s" "\n" "Wireshark is Open Source Software released under the GNU General Public License.\n" "\n" "Check the man page and http://www.wireshark.org for more information.", wireshark_gitversion, get_copyright_info(), comp_info_str->str, runtime_info_str->str); ui->label_wireshark->setTextInteractionFlags(Qt::TextSelectableByMouse); ui->label_wireshark->setText(message); /* Check if it is a dev release... (VERSION_MINOR is odd in dev release) */ #if VERSION_MINOR & 1 ui->label_logo->setPixmap( QPixmap( ":/about/wssplash_dev.png" ) ); #endif /* Authors */ f_authors.setFileName(get_datafile_path("AUTHORS-SHORT")); f_authors.open(QFile::ReadOnly | QFile::Text); QTextStream ReadFile_authors(&f_authors); ReadFile_authors.setCodec("UTF-8"); ui->pte_Authors->setFont(wsApp->monospaceFont()); ui->pte_Authors->insertPlainText(ReadFile_authors.readAll()); ui->pte_Authors->moveCursor(QTextCursor::Start); /* Folders */ /* set column widths */ #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) ui->tbFolders->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); #else ui->tbFolders->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); #endif ui->tbFolders->setRowCount(0); /* "file open" */ about_folders_row("\"File\" dialogs", get_last_open_dir(), "capture files"); /* temp */ about_folders_row("Temp", g_get_tmp_dir(), "untitled capture files"); /* pers conf */ path = get_persconffile_path("", FALSE); about_folders_row("Personal configuration", path, "\"dfilters\", \"preferences\", \"ethers\", ..."); g_free(path); /* global conf */ constpath = get_datafile_dir(); if (constpath != NULL) { about_folders_row("Global configuration", constpath, "\"dfilters\", \"preferences\", \"manuf\", ..."); } /* system */ constpath = get_systemfile_dir(); about_folders_row("System", constpath, "\"ethers\", \"ipxnets\""); /* program */ constpath = get_progfile_dir(); about_folders_row("Program", constpath, "program files"); #if defined(HAVE_PLUGINS) || defined(HAVE_LUA) /* pers plugins */ path = get_plugins_pers_dir(); about_folders_row("Personal Plugins", path, "dissector plugins"); g_free(path); /* global plugins */ about_folders_row("Global Plugins", get_plugin_dir(), "dissector plugins"); #endif #ifdef HAVE_PYTHON /* global python bindings */ about_folders_row("Python Bindings", get_wspython_dir(), "python bindings"); #endif #ifdef HAVE_GEOIP /* GeoIP */ path = geoip_db_get_paths(); resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10); for(i = 0; resultArray[i]; i++) about_folders_row("GeoIP path", g_strstrip(resultArray[i]), "GeoIP database search path"); g_strfreev(resultArray); g_free(path); #endif #ifdef HAVE_LIBSMI /* SMI MIBs/PIBs */ path = oid_get_default_mib_path(); resultArray = g_strsplit(path, G_SEARCHPATH_SEPARATOR_S, 10); for(i = 0; resultArray[i]; i++) about_folders_row("MIB/PIB path", g_strstrip(resultArray[i]), "SMI MIB/PIB search path"); g_strfreev(resultArray); g_free(path); #endif /* Plugins */ #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) ui->tbPlugins->horizontalHeader()->setResizeMode(3, QHeaderView::Stretch); #else ui->tbPlugins->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); #endif plugins_scan(); /* License */ #if defined(_WIN32) f_license.setFileName(get_datafile_path("COPYING.txt")); #else f_license.setFileName(get_datafile_path("COPYING")); #endif f_license.open(QFile::ReadOnly | QFile::Text); QTextStream ReadFile_license(&f_license); ui->pte_License->setFont(wsApp->monospaceFont()); ui->pte_License->insertPlainText(ReadFile_license.readAll()); ui->pte_License->moveCursor(QTextCursor::Start); }