/* 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; }
void proto_help_init(void) { gchar *search_dir[PH_CONF_DIRS]; const gchar *ini_name; gchar *ini_path; GDir *conf_dir; int i; search_dir[0] = g_strdup_printf("%s" G_DIR_SEPARATOR_S PH_CONFFILE_SUBDIR, get_datafile_dir()); /* XXX - Use profiles? */ search_dir[1] = get_persconffile_path(PH_CONFFILE_SUBDIR, FALSE, FALSE); #ifdef PH_DEBUG_LOG g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, ph_logging_handler, NULL); #endif if (g_ph_key_files) return; g_ph_key_files = g_ptr_array_new(); /* Start loop */ #ifdef PH_DEBUG_LOG ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), PH_FILE_LOG); #endif for (i = 0; i < PH_CONF_DIRS; i++) { g_log(NULL, G_LOG_LEVEL_INFO, "Looking for protocol help files in '%s'", search_dir[i]); conf_dir = g_dir_open(search_dir[i], 0, NULL); if (!conf_dir) { continue; } while ((ini_name = g_dir_read_name(conf_dir)) != NULL) { if (! g_str_has_suffix(ini_name, PH_INI_SUFFIX)) { continue; } g_log(NULL, G_LOG_LEVEL_INFO, "-- Found '%s'", ini_name); ini_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", search_dir[i], ini_name); ph_ini_load_file(ini_path); g_free(ini_path); } g_dir_close(conf_dir); } }
/* * Open the help dialog and show a specific HTML help page. */ void help_topic_html(const gchar *topic) { GString *url; /* try to open local .chm file */ #ifdef HHC_DIR HWND hw; url = g_string_new(""); g_string_append_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help", get_datafile_dir(), topic); hw = HtmlHelpW(NULL, utf_8to16(url->str), HH_DISPLAY_TOPIC, 0); g_string_free(url, TRUE /* free_segment */); /* if the .chm file could be opened, stop here */ if(hw != NULL) { return; } #endif /* HHC_DIR */ url = g_string_new(""); #ifdef DOC_DIR if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) { /* try to open the HTML page from wireshark.org instead */ g_string_append_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", topic); } else { #endif /* ifdef DOC_DIR */ /* try to open the HTML page from wireshark.org instead */ g_string_append_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", topic); #ifdef DOC_DIR } #endif /* ifdef DOC_DIR */ browser_open_url(url->str); g_string_free(url, TRUE /* free_segment */); }
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. */ }
/* * Given a filename return a filesystem URL. Relative paths are prefixed with * the datafile directory path. */ gchar * data_file_url(const gchar *filename) { gchar *file_path; gchar *uri; /* Absolute path? */ #ifdef G_OS_WIN32 if((strlen(filename) > 2) && (filename[1] == ':')) { file_path = g_strdup(filename); #else if((strlen(filename) > 1) && (filename[0] == '/')) { file_path = g_strdup(filename); #endif } else if(running_in_build_directory()) { file_path = g_strdup_printf("%s/doc/%s", get_datafile_dir(), filename); } else { file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename); } /* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */ /* convert filename to uri */ uri = g_filename_to_uri(file_path, NULL, NULL); g_free(file_path); return uri; } const char * topic_online_url(topic_action_e action) { switch(action) { case(ONLINEPAGE_HOME): return "http://www.wireshark.org"; break; case(ONLINEPAGE_WIKI): return "http://wiki.wireshark.org"; break; case(ONLINEPAGE_DOWNLOAD): return "http://www.wireshark.org/download.html"; break; case(ONLINEPAGE_USERGUIDE): return "http://www.wireshark.org/docs/wsug_html_chunked/"; break; case(ONLINEPAGE_FAQ): return "http://www.wireshark.org/faq.html"; break; case(ONLINEPAGE_ASK): return "http://ask.wireshark.org"; break; case(ONLINEPAGE_SAMPLE_FILES): return "http://wiki.wireshark.org/SampleCaptures"; break; case(ONLINEPAGE_CAPTURE_SETUP): return "http://wiki.wireshark.org/CaptureSetup"; break; case(ONLINEPAGE_NETWORK_MEDIA): return "http://wiki.wireshark.org/CaptureSetup/NetworkMedia"; break; case(ONLINEPAGE_SAMPLE_CAPTURES): return "http://wiki.wireshark.org/SampleCaptures"; break; case(ONLINEPAGE_SECURITY): return "http://wiki.wireshark.org/Security"; break; case(ONLINEPAGE_CHIMNEY): return "http://wiki.wireshark.org/CaptureSetup/Offloading#chimney"; break; default: return NULL; } } /* * Open the help dialog and show a specific HTML help page. */ gchar * user_guide_url(const gchar *page) { GString *url = g_string_new(""); gchar *ug_url = NULL; /* * Try to open local .chm file. This is not the most intuitive way to * go about this but it fits in with the rest of the _url functions. */ #ifdef HHC_DIR HWND hw; g_string_printf(url, "%s\\user-guide.chm::/wsug_chm/%s>Wireshark Help", get_datafile_dir(), page); hw = HtmlHelpW(NULL, utf_8to16(url->str), HH_DISPLAY_TOPIC, 0); /* if the .chm file could be opened, stop here */ if(hw != NULL) { g_string_free(url, TRUE /* free_segment */); return NULL; } #endif /* HHC_DIR */ #ifdef DOC_DIR if (g_file_test(DOC_DIR "/guides/wsug_html_chunked", G_FILE_TEST_IS_DIR)) { /* try to open the HTML page from wireshark.org instead */ g_string_printf(url, "file://" DOC_DIR "/guides/wsug_html_chunked/%s", page); } else { #endif /* ifdef DOC_DIR */ /* try to open the HTML page from wireshark.org instead */ g_string_printf(url, "http://www.wireshark.org/docs/wsug_html_chunked/%s", page); #ifdef DOC_DIR } #endif /* ifdef DOC_DIR */ ug_url = url->str; g_string_free(url, FALSE); return ug_url; }
MainWindowPreferencesFrame::MainWindowPreferencesFrame(QWidget *parent) : QFrame(parent), ui(new Ui::MainWindowPreferencesFrame) { ui->setupUi(this); pref_geometry_save_position_ = prefFromPrefPtr(&prefs.gui_geometry_save_position); pref_geometry_save_size_ = prefFromPrefPtr(&prefs.gui_geometry_save_size); pref_geometry_save_maximized_ = prefFromPrefPtr(&prefs.gui_geometry_save_maximized); pref_fileopen_style_ = prefFromPrefPtr(&prefs.gui_fileopen_style); pref_fileopen_dir_ = prefFromPrefPtr(&prefs.gui_fileopen_dir); pref_recent_df_entries_max_ = prefFromPrefPtr(&prefs.gui_recent_df_entries_max); pref_recent_files_count_max_ = prefFromPrefPtr(&prefs.gui_recent_files_count_max); pref_ask_unsaved_ = prefFromPrefPtr(&prefs.gui_ask_unsaved); pref_toolbar_main_style_ = prefFromPrefPtr(&prefs.gui_toolbar_main_style); pref_toolbar_filter_style_ = prefFromPrefPtr(&prefs.gui_toolbar_filter_style); QStyleOption style_opt; QString indent_ss = QString( "QRadioButton, QLineEdit, QLabel {" " margin-left: %1px;" "}" ).arg(ui->geometryCheckBox->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()); ui->foStyleLastOpenedRadioButton->setStyleSheet(indent_ss); ui->foStyleSpecifiedRadioButton->setStyleSheet(indent_ss); ui->maxFilterLineEdit->setStyleSheet(indent_ss); ui->maxRecentLineEdit->setStyleSheet(indent_ss); int num_entry_width = ui->maxFilterLineEdit->fontMetrics().height() * 3; ui->maxFilterLineEdit->setMaximumWidth(num_entry_width); ui->maxRecentLineEdit->setMaximumWidth(num_entry_width); QString globalLanguagesPath(QString(get_datafile_dir()) + "/languages/"); QString userLanguagesPath(gchar_free_to_qstring(get_persconffile_path("languages/", FALSE))); QStringList filenames = QDir(":/i18n/").entryList(QStringList("wireshark_*.qm")); filenames += QDir(globalLanguagesPath).entryList(QStringList("wireshark_*.qm")); filenames += QDir(userLanguagesPath).entryList(QStringList("wireshark_*.qm")); for (int i = 0; i < filenames.size(); i += 1) { QString locale; locale = filenames[i]; locale.truncate(locale.lastIndexOf('.')); locale.remove(0, locale.indexOf('_') + 1); QString lang = QLocale::languageToString(QLocale(locale).language()); QIcon ico = QIcon(); if (QFile::exists(QString(":/languages/%1.svg").arg(locale))) ico.addFile(QString(":/languages/%1.svg").arg(locale)); if (QFile::exists(globalLanguagesPath + locale + ".svg")) ico.addFile(globalLanguagesPath + locale + ".svg"); if (QFile::exists(userLanguagesPath + locale + ".svg")) ico.addFile(userLanguagesPath + locale + ".svg"); ui->languageComboBox->addItem(ico, lang, locale); } ui->languageComboBox->setItemData(0, USE_SYSTEM_LANGUAGE); ui->languageComboBox->model()->sort(0); for (int i = 0; i < ui->languageComboBox->count(); i += 1) { if (QString(language) == ui->languageComboBox->itemData(i).toString()) { ui->languageComboBox->setCurrentIndex(i); break; } } }
extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) { gint* ett; avp_init(); matecfg = g_malloc(sizeof(mate_config)); matecfg->hfid_mate = mate_hfid; matecfg->fields_filter = g_string_new(""); matecfg->protos_filter = g_string_new(""); matecfg->dbg_facility = NULL; matecfg->mate_lib_path = g_strdup_printf("%s%c%s%c",get_datafile_dir(),DIR_SEP,DEFAULT_MATE_LIB_PATH,DIR_SEP); matecfg->pducfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gopcfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gogcfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->transfs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->pducfglist = g_ptr_array_new(); matecfg->gops_by_pduname = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gogs_by_gopname = g_hash_table_new(g_str_hash,g_str_equal); matecfg->ett_root = -1; matecfg->hfrs = g_array_new(FALSE,FALSE,sizeof(hf_register_info)); matecfg->ett = g_array_new(FALSE,FALSE,sizeof(gint*)); matecfg->defaults.pdu.drop_unassigned = FALSE; matecfg->defaults.pdu.discard = FALSE; matecfg->defaults.pdu.last_extracted = FALSE; matecfg->defaults.pdu.match_mode = AVPL_STRICT; matecfg->defaults.pdu.replace_mode = AVPL_INSERT; /* gop prefs */ matecfg->defaults.gop.expiration = -1.0; matecfg->defaults.gop.idle_timeout = -1.0; matecfg->defaults.gop.lifetime = -1.0; matecfg->defaults.gop.pdu_tree_mode = GOP_FRAME_TREE; matecfg->defaults.gop.show_times = TRUE; matecfg->defaults.gop.drop_unassigned = FALSE; /* gog prefs */ matecfg->defaults.gog.expiration = 5.0; matecfg->defaults.gog.show_times = TRUE; matecfg->defaults.gog.gop_tree_mode = GOP_BASIC_TREE; /* what to dbgprint */ matecfg->dbg_lvl = 0; matecfg->dbg_pdu_lvl = 0; matecfg->dbg_gop_lvl = 0; matecfg->dbg_gog_lvl = 0; matecfg->config_error = g_string_new(""); ett = &matecfg->ett_root; g_array_append_val(matecfg->ett,ett); if ( mate_load_config(filename,matecfg) ) { analyze_config(); } else { report_failure("MATE failed to configure!\n" "It is recommended that you fix your config and restart Wireshark.\n" "The reported error is:\n%s\n",matecfg->config_error->str); /* if (matecfg) destroy_mate_config(matecfg,FALSE); */ matecfg = NULL; return NULL; } if (matecfg->fields_filter->len > 1) { g_string_erase(matecfg->fields_filter,0,2); g_string_erase(matecfg->protos_filter,0,2); } else { /*destroy_mate_config(matecfg,FALSE);*/ matecfg = NULL; return NULL; } matecfg->tap_filter = g_strdup_printf("(%s) && (%s)",matecfg->protos_filter->str,matecfg->fields_filter->str); return matecfg; }
static GtkWidget * about_folders_page_new(void) { GtkWidget *table; const char *constpath; char *path; const gchar *titles[] = { "Name", "Folder", "Typical Files"}; GtkWidget *scrolledwindow; #if defined (HAVE_LIBSMI) || defined (HAVE_GEOIP) gint i; gchar **resultArray; #endif scrolledwindow = scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_SHADOW_IN); /* Container for our data */ table = simple_list_new(3, titles); /* connect a callback so we can spot a double-click */ g_signal_connect(table, "button_press_event", G_CALLBACK(about_folders_callback), NULL); simple_list_url_col(table, 1); /* "file open" */ about_folders_row(table, "\"File\" dialogs", get_last_open_dir(), "capture files"); /* temp */ path = get_tempfile_path(""); about_folders_row(table, "Temp", path, "untitled capture files"); g_free(path); /* pers conf */ path = get_persconffile_path("", FALSE, FALSE); about_folders_row(table, "Personal configuration", path, "\"dfilters\", \"preferences\", \"ethers\", ..."); g_free(path); /* global conf */ constpath = get_datafile_dir(); if (constpath != NULL) { about_folders_row(table, "Global configuration", constpath, "\"dfilters\", \"preferences\", \"manuf\", ..."); } /* system */ constpath = get_systemfile_dir(); about_folders_row(table, "System", constpath, "\"ethers\", \"ipxnets\""); /* program */ constpath = get_progfile_dir(); about_folders_row(table, "Program", constpath, "program files"); #if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1) /* pers plugins */ path = get_plugins_pers_dir(); about_folders_row(table, "Personal Plugins", path, "dissector plugins"); g_free(path); /* global plugins */ about_folders_row(table, "Global Plugins", get_plugin_dir(), "dissector plugins"); #endif #ifdef HAVE_PYTHON /* global python bindings */ about_folders_row(table, "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(table, "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(table, "MIB/PIB path", g_strstrip(resultArray[i]), "SMI MIB/PIB search path"); g_strfreev(resultArray); g_free(path); #endif gtk_container_add(GTK_CONTAINER(scrolledwindow), table); return scrolledwindow; }
void write_pdml_preamble(FILE *fh, const gchar* filename) { time_t t=time(NULL); char *ts=asctime(localtime(&t)); ts[strlen(ts)-1]=0; /* overwrite \n */ fputs("<?xml version=\"1.0\"?>\n", fh); fputs("<?xml-stylesheet type=\"text/xsl\" href=\"" PDML2HTML_XSL "\"?>\n", fh); fprintf(fh, "<!-- You can find " PDML2HTML_XSL " in %s or at http://anonsvn.wireshark.org/trunk/wireshark/" PDML2HTML_XSL ". -->\n", get_datafile_dir()); fputs("<pdml version=\"" PDML_VERSION "\" ", fh); fprintf(fh, "creator=\"%s/%s\" time=\"%s\" capture_file=\"%s\">\n", PACKAGE, VERSION, ts, filename ? filename : ""); }
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); }