void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) { char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; gchar *err_msg = NULL; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { if (profile_exists(profile_name, TRUE)) { char *pf_dir_path, *pf_dir_path2, *pf_filename; /* Copy from global profile */ if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } else { /* No personal and no global profile exists */ return; } } /* Then check if changing to another profile */ if (profile_name && strcmp (profile_name, get_profile_name()) == 0) { return; } /* Get the current geometry, before writing it to disk */ emit profileChanging(); if (profile_exists(get_profile_name(), FALSE)) { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } /* Set profile name and update the status bar */ set_profile_name (profile_name); emit profileNameChanged(profile_name); /* Apply new preferences */ readConfigurationFiles (&gdp_path, &dp_path, true); if (!recent_read_profile_static(&rf_path, &rf_open_errno)) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open common recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); g_free(rf_path); } if (recent.gui_fileopen_remembered_dir && test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { set_last_open_dir(recent.gui_fileopen_remembered_dir); } timestamp_set_type (recent.gui_time_format); timestamp_set_precision(recent.gui_time_precision); timestamp_set_seconds_type (recent.gui_seconds_format); packet_list_enable_color(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); prefs_apply_all(); #ifdef HAVE_LIBPCAP update_local_interfaces(); #endif setMonospaceFont(prefs.gui_qt_font_name); emit columnsChanged(); emit preferencesChanged(); emit recentFilesRead(); emit filterExpressionsChanged(); emit checkDisplayFilter(); /* Enable all protocols and disable from the disabled list */ proto_enable_all(); if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } /* Reload color filters */ if (!color_filters_reload(&err_msg, color_filter_add_cb)) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); g_free(err_msg); } emit localInterfaceListChanged(); emit packetDissectionChanged(); }
void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) { char *gdp_path, *dp_path; char *rf_path; int rf_open_errno; /* First check if profile exists */ if (!profile_exists(profile_name, FALSE)) { if (profile_exists(profile_name, TRUE)) { char *pf_dir_path, *pf_dir_path2, *pf_filename; /* Copy from global profile */ if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't create directory\n\"%s\":\n%s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); } if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.", pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno)); g_free(pf_filename); g_free(pf_dir_path); g_free(pf_dir_path2); } } else { /* No personal and no global profile exists */ return; } } /* Then check if changing to another profile */ if (profile_name && strcmp (profile_name, get_profile_name()) == 0) { return; } /* Get the current geometry, before writing it to disk */ emit profileChanging(); if (profile_exists(get_profile_name(), FALSE)) { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } /* Set profile name and update the status bar */ set_profile_name (profile_name); emit profileNameChanged(profile_name); /* Reset current preferences and apply the new */ prefs_reset(); // menu_prefs_reset(); (void) readConfigurationFiles (&gdp_path, &dp_path); recent_read_profile_static(&rf_path, &rf_open_errno); if (rf_path != NULL && rf_open_errno != 0) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open common recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); } if (recent.gui_fileopen_remembered_dir && test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { set_last_open_dir(recent.gui_fileopen_remembered_dir); } timestamp_set_type (recent.gui_time_format); timestamp_set_seconds_type (recent.gui_seconds_format); color_filters_enable(recent.packet_list_colorize); tap_update_timer_.setInterval(prefs.tap_update_interval); prefs_to_capture_opts(); prefs_apply_all(); emit preferencesChanged(); emit columnsChanged(); emit recentFilesRead(); emit filterExpressionsChanged(); // macros_post_update(); /* Enable all protocols and disable from the disabled list */ proto_enable_all(); if (gdp_path == NULL && dp_path == NULL) { set_disabled_protos_list(); set_disabled_heur_dissector_list(); } /* Reload color filters */ color_filters_reload(); // user_font_apply(); /* Update menus with new recent values */ // menu_recent_read_finished(); }
/* * load options from config file * args: * filename - config file * * asserts: * none * * returns: error code */ int config_load(const char *filename) { FILE *fp; char bufr[MAXLINE]; int line = 0; /*open file for read*/ if((fp = fopen(filename,"r")) == NULL) { fprintf(stderr, "GUVCVIEW: couldn't open %s for read: %s\n", filename, strerror(errno)); return -1; } while(fgets(bufr, MAXLINE, fp) != NULL) { line++; char *bufp = bufr; /*parse config line*/ /*trim leading and trailing spaces and newline*/ trim_leading_wspaces(bufp); trim_trailing_wspaces(bufp); /*skip empty or commented lines */ int size = strlen(bufp); if(size < 1 || *bufp == '#') { if(debug_level > 1) printf("GUVCVIEW: (config) empty or commented line (%i)\n", line); continue; } char *token = NULL; char *value = NULL; char *sp = strrchr(bufp, '='); if(sp) { int size = sp - bufp; token = strndup(bufp, size); trim_leading_wspaces(token); trim_trailing_wspaces(token); value = strdup(sp + 1); trim_leading_wspaces(value); trim_trailing_wspaces(value); } /*skip invalid lines */ if(!token || !value || strlen(token) < 1 || strlen(value) < 1) { fprintf(stderr, "GUVCVIEW: (config) skiping invalid config entry at line %i\n", line); if(token) free(token); if(value) free(value); continue; } /*check tokens*/ if(strcmp(token, "width") == 0) my_config.width = (int) strtoul(value, NULL, 10); else if(strcmp(token, "height") == 0) my_config.height = (int) strtoul(value, NULL, 10); else if(strcmp(token, "v4l2_format") == 0) my_config.format = (uint32_t) strtoul(value, NULL, 10); else if(strcmp(token, "capture") == 0) strncpy(my_config.capture, value, 4); else if(strcmp(token, "audio") == 0) strncpy(my_config.audio, value, 5); else if(strcmp(token, "gui") == 0) strncpy(my_config.gui, value, 4); else if(strcmp(token, "render") == 0) strncpy(my_config.render, value, 4); else if(strcmp(token, "video_codec") == 0) strncpy(my_config.video_codec, value, 4); else if(strcmp(token, "audio_codec") == 0) strncpy(my_config.audio_codec, value, 4); else if(strcmp(token, "profile_name") == 0 && strlen(value) > 2) { if(my_config.profile_name) free(my_config.profile_name); my_config.profile_name = strdup(value); set_profile_name(value); } else if(strcmp(token, "profile_path") == 0) { if(my_config.profile_path) free(my_config.profile_path); my_config.profile_path = strdup(value); set_profile_path(value); } else if(strcmp(token, "video_name") == 0 && strlen(value) > 2) { if(my_config.video_name) free(my_config.video_name); my_config.video_name = strdup(value); } else if(strcmp(token, "video_path") == 0) { if(my_config.video_path) free(my_config.video_path); my_config.video_path = strdup(value); } else if(strcmp(token, "photo_name") == 0 && strlen(value) > 2) { if(my_config.photo_name) free(my_config.photo_name); my_config.photo_name = strdup(value); } else if(strcmp(token, "photo_path") == 0) { if(my_config.photo_path) free(my_config.photo_path); my_config.photo_path = strdup(value); } else if(strcmp(token, "video_sufix") == 0) { my_config.video_sufix = (int) strtoul(value, NULL, 10); set_video_sufix_flag(my_config.video_sufix); } else if(strcmp(token, "photo_sufix") == 0) { my_config.photo_sufix = (int) strtoul(value, NULL, 10); set_photo_sufix_flag(my_config.photo_sufix); } else if(strcmp(token, "fps_num") == 0) my_config.fps_num = (int) strtoul(value, NULL, 10); else if(strcmp(token, "fps_denom") == 0) my_config.fps_denom = (int) strtoul(value, NULL, 10); else if(strcmp(token, "audio_device") == 0) my_config.audio_device = (int) strtoul(value, NULL, 10); else if(strcmp(token, "video_fx") == 0) my_config.video_fx = (uint32_t) strtoul(value, NULL, 16); else if(strcmp(token, "audio_fx") == 0) my_config.audio_fx = (uint32_t) strtoul(value, NULL, 16); else if(strcmp(token, "osd_mask") == 0) my_config.osd_mask = (uint32_t) strtoul(value, NULL, 16); else if(strcmp(token, "crosshair_color") == 0) my_config.crosshair_color = (uint32_t) strtoul(value, NULL, 16); else fprintf(stderr, "GUVCVIEW: (config) skiping invalid entry at line %i ('%s', '%s')\n", line, token, value); if(token) free(token); if(value) free(value); } //if(errno) //{ // fprintf(stderr, "GUVCVIEW: couldn't read line %i of config file: %s\n", line, strerror(errno)); // fclose(fp); // return -1; //} fclose(fp); return 0; }
/* And now our feature presentation... [ fade to music ] */ int main(int argc, char *argv[]) { WiresharkApplication a(argc, argv); MainWindow *w; char *init_progfile_dir_error; char *s; int opt; gboolean arg_error = FALSE; extern int info_update_freq; /* Found in about_dlg.c. */ const gchar *filter; #ifdef _WIN32 WSADATA wsaData; #endif /* _WIN32 */ char *rf_path; int rf_open_errno; char *gdp_path, *dp_path; int err; #ifdef HAVE_LIBPCAP gboolean start_capture = FALSE; gboolean list_link_layer_types = FALSE; GList *if_list; gchar *err_str; #else gboolean capture_option_specified = FALSE; #ifdef _WIN32 #ifdef HAVE_AIRPCAP gchar *err_str; #endif #endif #endif gint pl_size = 280, tv_size = 95, bv_size = 75; gchar *rc_file, *cf_name = NULL, *rfilter = NULL, *jfilter = NULL; dfilter_t *rfcode = NULL; gboolean rfilter_parse_failed = FALSE; e_prefs *prefs_p; char badopt; //GtkWidget *splash_win = NULL; GLogLevelFlags log_flags; guint go_to_packet = 0; gboolean jump_backwards = FALSE; dfilter_t *jump_to_filter = NULL; int optind_initial; int status; //initialize language ! QString locale = QLocale::system().name(); g_log(NULL, G_LOG_LEVEL_DEBUG, "Translator %s", locale.toStdString().c_str()); QTranslator translator; translator.load(QString(":/i18n/qtshark_") + locale); a.installTranslator(&translator); // Hopefully we won't have to use QString::fromUtf8() in as many places. QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForCStrings(utf8codec); QTextCodec::setCodecForTr(utf8codec); #ifdef HAVE_LIBPCAP #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) #define OPTSTRING_B "B:" #else #define OPTSTRING_B "" #endif /* _WIN32 or HAVE_PCAP_CREATE */ #else /* HAVE_LIBPCAP */ #define OPTSTRING_B "" #endif /* HAVE_LIBPCAP */ #ifdef HAVE_PCAP_CREATE #define OPTSTRING_I "I" #else #define OPTSTRING_I "" #endif #define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:" static const char optstring[] = OPTSTRING; /* * Get credential information for later use, and drop privileges * before doing anything else. * Let the user know if anything happened. */ init_process_policies(); relinquish_special_privs_perm(); /* * Attempt to get the pathname of the executable file. */ init_progfile_dir_error = init_progfile_dir(argv[0], main); g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); /* initialize the funnel mini-api */ // xxx qtshark //initialize_funnel_ops(); AirPDcapInitContext(&airpdcap_ctx); // xxx qtshark #ifdef _WIN32 /* Load wpcap if possible. Do this before collecting the run-time version information */ load_wpcap(); /* ... and also load the packet.dll from wpcap */ wpcap_packet_load(); #ifdef HAVE_AIRPCAP /* Load the airpcap.dll. This must also be done before collecting * run-time version information. */ airpcap_dll_ret_val = load_airpcap(); switch (airpcap_dll_ret_val) { case AIRPCAP_DLL_OK: /* load the airpcap interfaces */ airpcap_if_list = get_airpcap_interface_list(&err, &err_str); if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){ if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!"); g_free(err_str); } airpcap_if_active = NULL; } else { /* select the first ad default (THIS SHOULD BE CHANGED) */ airpcap_if_active = airpcap_get_default_if(airpcap_if_list); } break; #if 0 /* * XXX - Maybe we need to warn the user if one of the following happens??? */ case AIRPCAP_DLL_OLD: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n"); break; case AIRPCAP_DLL_ERROR: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n"); break; case AIRPCAP_DLL_NOT_FOUND: simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n"); break; #endif } #endif /* HAVE_AIRPCAP */ /* Start windows sockets */ WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); #endif /* _WIN32 */ profile_store_persconffiles (TRUE); /* Assemble the compile-time version information string */ comp_info_str = g_string_new("Compiled "); // xxx qtshark get_compiled_version_info(comp_info_str, get_qt_compiled_info, get_gui_compiled_info); /* Assemble the run-time version information string */ runtime_info_str = g_string_new("Running "); // xxx qtshark get_runtime_version_info(runtime_info_str, get_gui_runtime_info); /* Read the profile independent recent file. We have to do this here so we can */ /* set the profile before it can be set from the command line parameterts */ // xxx qtshark //recent_read_static(&rf_path, &rf_open_errno); //if (rf_path != NULL && rf_open_errno != 0) { // simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, // "Could not open common recent file\n\"%s\": %s.", // rf_path, strerror(rf_open_errno)); //} /* "pre-scan" the command line parameters, if we have "console only" parameters. We do this so we don't start GTK+ if we're only showing command-line help or version information. XXX - this pre-scan is done before we start GTK+, so we haven't run gtk_init() on the arguments. That means that GTK+ arguments have not been removed from the argument list; those arguments begin with "--", and will be treated as an error by getopt(). We thus ignore errors - *and* set "opterr" to 0 to suppress the error messages. */ opterr = 0; optind_initial = optind; while ((opt = getopt(argc, argv, optstring)) != -1) { switch (opt) { case 'C': /* Configuration Profile */ if (profile_exists (optarg, FALSE)) { set_profile_name (optarg); } else { cmdarg_err("Configuration Profile \"%s\" does not exist", optarg); exit(1); } break; case 'D': /* Print a list of capture devices and exit */ #ifdef HAVE_LIBPCAP if_list = capture_interface_list(&err, &err_str); if (if_list == NULL) { switch (err) { case CANT_GET_INTERFACE_LIST: cmdarg_err("%s", err_str); g_free(err_str); break; case NO_INTERFACES_FOUND: cmdarg_err("There are no interfaces on which a capture can be done"); break; } exit(2); } capture_opts_print_interfaces(if_list); free_interface_list(if_list); exit(0); #else capture_option_specified = TRUE; arg_error = TRUE; #endif break; case 'h': /* Print help and exit */ print_usage(TRUE); exit(0); break; #ifdef _WIN32 case 'i': if (strcmp(optarg, "-") == 0) stdin_capture = TRUE; break; #endif case 'P': /* Path settings - change these before the Preferences and alike are processed */ status = filesystem_opt(opt, optarg); if(status != 0) { cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg); exit(status); } break; case 'v': /* Show version and exit */ show_version(); exit(0); break; case 'X': /* * Extension command line options have to be processed before * we call epan_init() as they are supposed to be used by dissectors * or taps very early in the registration process. */ ex_opt_add(optarg); break; case '?': /* Ignore errors - the "real" scan will catch them. */ break; } } cf_callback_add(main_cf_callback, NULL); /* Arrange that if we have no console window, and a GLib message logging routine is called to log a message, we pop up a console window. We do that by inserting our own handler for all messages logged to the default domain; that handler pops up a console if necessary, and then calls the default handler. */ /* We might want to have component specific log levels later ... */ log_flags = (GLogLevelFlags) ( G_LOG_LEVEL_ERROR| G_LOG_LEVEL_CRITICAL| G_LOG_LEVEL_WARNING| G_LOG_LEVEL_MESSAGE| G_LOG_LEVEL_INFO| G_LOG_LEVEL_DEBUG| G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION ); g_log_set_handler(NULL, log_flags, console_log_handler, NULL /* user_data */); g_log_set_handler(LOG_DOMAIN_MAIN, log_flags, console_log_handler, NULL /* user_data */); #ifdef HAVE_LIBPCAP g_log_set_handler(LOG_DOMAIN_CAPTURE, log_flags, console_log_handler, NULL /* user_data */); g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD, log_flags, console_log_handler, NULL /* user_data */); /* Set the initial values in the capture options. This might be overwritten by preference settings and then again by the command line parameters. */ capture_opts_init(&global_capture_opts, &cfile); #endif /* Register all dissectors; we must do this before checking for the "-G" flag, as the "-G" flag dumps information registered by the dissectors, and we must do it before we read the preferences, in case any dissectors register preferences. */ epan_init(register_all_protocols,register_all_protocol_handoffs, NULL, NULL, // splash_update, (gpointer) splash_win, failure_alert_box,open_failure_alert_box,read_failure_alert_box, write_failure_alert_box ); // splash_update(RA_LISTENERS, NULL, (gpointer)splash_win); /* Register all tap listeners; we do this before we parse the arguments, as the "-z" argument can specify a registered tap. */ /* we register the plugin taps before the other taps because stats_tree taps plugins will be registered as tap listeners by stats_tree_stat.c and need to registered before that */ g_log(NULL, G_LOG_LEVEL_DEBUG, "plugin_dir: %s", get_plugin_dir()); #ifdef HAVE_PLUGINS register_all_plugin_tap_listeners(); #endif // register_all_tap_listeners(); // splash_update(RA_PREFERENCES, NULL, (gpointer)splash_win); prefs_p = read_configuration_files (&gdp_path, &dp_path); /* Removed thread code: * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027 */ g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: timestamp types should be set elsewhere"); timestamp_set_type(TS_RELATIVE); timestamp_set_precision(TS_PREC_AUTO_USEC); timestamp_set_seconds_type(TS_SECONDS_DEFAULT); ///////// build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE); font_init(); //////// /* Read the dynamic part of the recent file, as we have the gui now ready for it. */ recent_read_dynamic(&rf_path, &rf_open_errno); if (rf_path != NULL && rf_open_errno != 0) { simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "Could not open recent file\n\"%s\": %s.", rf_path, g_strerror(rf_open_errno)); } color_filters_enable(recent.packet_list_colorize); g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings"); color_filters_enable(TRUE); //////// switch (user_font_apply()) { case FA_SUCCESS: break; case FA_FONT_NOT_RESIZEABLE: /* "user_font_apply()" popped up an alert box. */ /* turn off zooming - font can't be resized */ case FA_FONT_NOT_AVAILABLE: /* XXX - did we successfully load the un-zoomed version earlier? If so, this *probably* means the font is available, but not at this particular zoom level, but perhaps some other failure occurred; I'm not sure you can determine which is the case, however. */ /* turn off zooming - zoom level is unavailable */ default: /* in any other case than FA_SUCCESS, turn off zooming */ // recent.gui_zoom_level = 0; /* XXX: would it be a good idea to disable zooming (insensitive GUI)? */ break; } //////// color_filters_init(); //////// w = new(MainWindow); w->show(); return a.exec(); }