/* read filters from the user's filter file */
static gboolean
read_users_filters(GSList **cfl)
{
    gchar    *path;
    FILE     *f;
    gboolean  ret;

    /* decide what file to open (from dfilter code) */
    path = get_persconffile_path("colorfilters", TRUE);
    if ((f = ws_fopen(path, "r")) == NULL) {
        if (errno != ENOENT) {
            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                          "Could not open filter file\n\"%s\": %s.", path,
                          g_strerror(errno));
        }
        g_free(path);
        return FALSE;
    }
    g_free(path);
    path = NULL;

    ret = read_filters_file(f, cfl);
    fclose(f);
    return ret;
}
/* save filters in users filter file */
gboolean
color_filters_write(GSList *cfl)
{
    gchar *pf_dir_path;
    gchar *path;
    FILE  *f;

    /* Create the directory that holds personal configuration files,
       if necessary.  */
    if (create_persconffile_dir(&pf_dir_path) == -1) {
        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                      "Can't create directory\n\"%s\"\nfor color files: %s.",
                      pf_dir_path, g_strerror(errno));
        g_free(pf_dir_path);
        return FALSE;
    }

    path = get_persconffile_path("colorfilters", TRUE);
    if ((f = ws_fopen(path, "w+")) == NULL) {
        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                      "Could not open\n%s\nfor writing: %s.",
                      path, g_strerror(errno));
        g_free(path);
        return FALSE;
    }
    g_free(path);
    write_filters_file(cfl, f, FALSE);
    fclose(f);
    return TRUE;
}
Exemple #3
0
/* read filters from the user's filter file */
static gboolean
read_users_filters(GSList **cfl, 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_persconffile_path("colorfilters", TRUE);
    if ((f = ws_fopen(path, "r")) == NULL) {
        if (errno != ENOENT) {
            *err_msg = g_strdup_printf("Could not open filter file\n\"%s\": %s.", path,
                          g_strerror(errno));
        }
        g_free(path);
        return FALSE;
    }

    ret = read_filters_file(path, f, cfl, add_cb);
    if (ret != 0) {
        *err_msg = g_strdup_printf("Error reading filter file\n\"%s\": %s.",
                                   path, g_strerror(errno));
        fclose(f);
        g_free(path);
        return FALSE;
    }

    fclose(f);
    g_free(path);
    return TRUE;
}
Exemple #4
0
WSLUA_FUNCTION wslua_persconffile_path(lua_State* L) {
#define WSLUA_OPTARG_persconffile_path_FILENAME 1 /* A filename */
	const char *fname = luaL_optstring(L, WSLUA_OPTARG_persconffile_path_FILENAME,"");
	char* filename = get_persconffile_path(fname,FALSE,FALSE);

	lua_pushstring(L,filename);
	g_free(filename);
	WSLUA_RETURN(1); /* The full pathname for a file in the personal configuration directory */
}
Exemple #5
0
/* 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;
}
Exemple #6
0
WSLUA_CONSTRUCTOR Dir_personal_config_path(lua_State* L) {
    /* Gets the personal configuration directory path, with filename if supplied.

       @since 1.11.3
    */
#define WSLUA_OPTARG_personal_config_path_FILENAME 1 /* A filename. */
    const char *fname = luaL_optstring(L, WSLUA_OPTARG_personal_config_path_FILENAME,"");
    char* filename = get_persconffile_path(fname,FALSE);

    lua_pushstring(L,filename);
    g_free(filename);
    WSLUA_RETURN(1); /* The full pathname for a file in the personal configuration directory. */
}
Exemple #7
0
/* check for all updates */
void
update_check(gboolean interactive)
{
    char *local_file;
    const char *url_file = "http://127.0.0.1/wsupdate";	/* XXX - build the URL depending on platform, versions, ... */
    update_info_t *update_info_wireshark;
    update_info_t *update_info_winpcap;


    /* build update file name */
    /* XXX - using the personal path, use temp dir instead? */
    local_file = get_persconffile_path("wsupdate", FALSE, TRUE /*for_writing*/);
    if(local_file == NULL) {
        g_warning("Couldn't create output path!");
        return;
    }

    /* download update file */
    if(download_file(url_file, local_file) == -1) {
        g_warning("Couldn't download update file: %s", local_file);
        g_free(local_file);
        return;
    }

    /* check wireshark */
    update_info_wireshark = update_check_wireshark(local_file);

    /* check winpcap */
    update_info_winpcap = update_check_winpcap(local_file);

    /* display results */
    if(update_info_wireshark->needs_update || update_info_winpcap->needs_update) {
        if(update_info_wireshark->needs_update)
            update_info_display(update_info_wireshark);
        if(update_info_winpcap->needs_update)
            update_info_display(update_info_winpcap);
    } else {
        if(interactive) {
            simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No updates available");
        }
    }

    /* cleanup */
    update_info_delete(update_info_wireshark);
    update_info_delete(update_info_winpcap);

    g_free(local_file);
}
Exemple #8
0
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);
	}
}
Exemple #9
0
/* 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;
}
Exemple #10
0
/* 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;
}
Exemple #11
0
/* Return value is malloced so the caller should g_free() it. */
char *get_plugins_pers_dir(void)
{
    return get_persconffile_path(PLUGINS_DIR_NAME, FALSE, FALSE);
}
Exemple #12
0
/*
 * Write out a list of filters.
 *
 * On success, "*pref_path_return" is set to NULL.
 * On error, "*pref_path_return" is set to point to the pathname of
 * the file we tried to read - it should be freed by our caller -
 * and "*errno_return" is set to the error.
 */
void
save_filter_list(filter_list_type_t list_type, char **pref_path_return,
    int *errno_return)
{
  const gchar *ff_name;
  gchar      *ff_path, *ff_path_new;
  GList      *fl;
  GList      *flpp;
  filter_def *filt;
  FILE       *ff;
  guchar     *p, c;

  *pref_path_return = NULL;	/* assume no error */

  switch (list_type) {

  case CFILTER_LIST:
    ff_name = CFILTER_FILE_NAME;
    fl = capture_filters;
    break;

  case DFILTER_LIST:
    ff_name = DFILTER_FILE_NAME;
    fl = display_filters;
    break;

  default:
    g_assert_not_reached();
    return;
  }

  ff_path = get_persconffile_path(ff_name, TRUE);

  /* Write to "XXX.new", and rename if that succeeds.
     That means we don't trash the file if we fail to write it out
     completely. */
  ff_path_new = g_strdup_printf("%s.new", ff_path);

  if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    g_free(ff_path_new);
    return;
  }
  flpp = g_list_first(fl);
  while (flpp) {
    filt = (filter_def *) flpp->data;

    /* Write out the filter name as a quoted string; escape any quotes
       or backslashes. */
    putc('"', ff);
    for (p = (guchar *)filt->name; (c = *p) != '\0'; p++) {
      if (c == '"' || c == '\\')
        putc('\\', ff);
      putc(c, ff);
    }
    putc('"', ff);

    /* Separate the filter name and value with a space. */
    putc(' ', ff);

    /* Write out the filter expression and a newline. */
    fprintf(ff, "%s\n", filt->strval);
    if (ferror(ff)) {
      *pref_path_return = ff_path;
      *errno_return = errno;
      fclose(ff);
      ws_unlink(ff_path_new);
      g_free(ff_path_new);
      return;
    }
    flpp = flpp->next;
  }
  if (fclose(ff) == EOF) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }

#ifdef _WIN32
  /* ANSI C doesn't say whether "rename()" removes the target if it
     exists; the Win32 call to rename files doesn't do so, which I
     infer is the reason why the MSVC++ "rename()" doesn't do so.
     We must therefore remove the target file first, on Windows.

     XXX - ws_rename() should be ws_stdio_rename() on Windows,
     and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
     so it should remove the target if it exists, so this stuff
     shouldn't be necessary.  Perhaps it dates back to when we were
     calling rename(), with that being a wrapper around Microsoft's
     _rename(), which didn't remove the target. */
  if (ws_remove(ff_path) < 0 && errno != ENOENT) {
    /* It failed for some reason other than "it's not there"; if
       it's not there, we don't need to remove it, so we just
       drive on. */
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }
#endif

  if (ws_rename(ff_path_new, ff_path) < 0) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }
  g_free(ff_path_new);
  g_free(ff_path);
}
Exemple #13
0
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;
  }
}
Exemple #14
0
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);
}
/*
 * Write out a list of disabled protocols.
 *
 * On success, "*pref_path_return" is set to NULL.
 * On error, "*pref_path_return" is set to point to the pathname of
 * the file we tried to read - it should be freed by our caller -
 * and "*errno_return" is set to the error.
 */
void
save_disabled_protos_list(char **pref_path_return, int *errno_return)
{
  gchar       *ff_path, *ff_path_new;
  FILE        *ff;
  gint         i;
  protocol_t  *protocol;
  void        *cookie;

  *pref_path_return = NULL;	/* assume no error */

  ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, TRUE, TRUE);

  /* Write to "XXX.new", and rename if that succeeds.
     That means we don't trash the file if we fail to write it out
     completely. */
  ff_path_new = g_strdup_printf("%s.new", ff_path);

  if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    g_free(ff_path_new);
    return;
  }

  /* Iterate over all the protocols */

  for (i = proto_get_first_protocol(&cookie); i != -1;
       i = proto_get_next_protocol(&cookie)) {

    if (!proto_can_toggle_protocol(i)) {
      continue;
    }

    protocol = find_protocol_by_id(i);
    if (proto_is_protocol_enabled(protocol)) {
      continue;
    }

    /* Write out the protocol name. */
    fprintf(ff, "%s\n", proto_get_protocol_filter_name(i));
  }

  if (fclose(ff) == EOF) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }

#ifdef _WIN32
  /* ANSI C doesn't say whether "rename()" removes the target if it
     exists; the Win32 call to rename files doesn't do so, which I
     infer is the reason why the MSVC++ "rename()" doesn't do so.
     We must therefore remove the target file first, on Windows.

     XXX - ws_rename() should be ws_stdio_rename() on Windows,
     and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
     so it should remove the target if it exists, so this stuff
     shouldn't be necessary.  Perhaps it dates back to when we were
     calling rename(), with that being a wrapper around Microsoft's
     _rename(), which didn't remove the target. */
  if (ws_remove(ff_path) < 0 && errno != ENOENT) {
    /* It failed for some reason other than "it's not there"; if
       it's not there, we don't need to remove it, so we just
       drive on. */
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }
#endif

  if (ws_rename(ff_path_new, ff_path) < 0) {
    *pref_path_return = ff_path;
    *errno_return = errno;
    ws_unlink(ff_path_new);
    g_free(ff_path_new);
    return;
  }
  g_free(ff_path_new);
  g_free(ff_path);
}
Exemple #16
0
/* Attempt to Write out profile "recent" to the user's profile recent file.
   If we got an error report it with a dialog box and return FALSE,
   otherwise return TRUE. */
gboolean
write_profile_recent(void)
{
  char        *pf_dir_path;
  char        *rf_path;
  FILE        *rf;

  /* To do:
   * - Split output lines longer than MAX_VAL_LEN
   * - Create a function for the preference directory check/creation
   *   so that duplication can be avoided with filter.c
   */

  /* Create the directory that holds personal configuration files, if
     necessary.  */
  if (create_persconffile_dir(&pf_dir_path) == -1) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
      g_strerror(errno));
     g_free(pf_dir_path);
     return FALSE;
  }

  rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);
  if ((rf = ws_fopen(rf_path, "w")) == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't open recent file\n\"%s\": %s.", rf_path,
      g_strerror(errno));
    g_free(rf_path);
    return FALSE;
  }
  g_free(rf_path);

  fputs("# Recent settings file for Wireshark " VERSION ".\n"
    "#\n"
    "# This file is regenerated each time Wireshark is quit\n"
    "# and when changing configuration profile.\n"
    "# So be careful, if you want to make manual changes here.\n"
    "\n", rf);

  fprintf(rf, "\n# Main Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_MAIN_TOOLBAR_SHOW ": %s\n",
		  recent.main_toolbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Filter Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_FILTER_TOOLBAR_SHOW ": %s\n",
		  recent.filter_toolbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Wireless Settings Toolbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_WIRELESS_TOOLBAR_SHOW ": %s\n",
		  recent.wireless_toolbar_show == TRUE ? "TRUE" : "FALSE");

#ifdef HAVE_AIRPCAP
  fprintf(rf, "\n# Show (hide) old AirPcap driver warning dialog box.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_DRIVER_CHECK_SHOW ": %s\n",
		  recent.airpcap_driver_check_show == TRUE ? "TRUE" : "FALSE");
#endif

  fprintf(rf, "\n# Packet list show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PACKET_LIST_SHOW ": %s\n",
		  recent.packet_list_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Tree view show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_TREE_VIEW_SHOW ": %s\n",
		  recent.tree_view_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Byte view show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_BYTE_VIEW_SHOW ": %s\n",
		  recent.byte_view_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Statusbar show (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_STATUSBAR_SHOW ": %s\n",
		  recent.statusbar_show == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Packet list colorize (hide).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PACKET_LIST_COLORIZE ": %s\n",
		  recent.packet_list_colorize == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Timestamp display format.\n");
  fprintf(rf, "# One of: RELATIVE, ABSOLUTE, ABSOLUTE_WITH_DATE, DELTA, DELTA_DIS, EPOCH, UTC, UTC_WITH_DATE\n");
  fprintf(rf, RECENT_GUI_TIME_FORMAT ": %s\n",
          ts_type_text[recent.gui_time_format]);

  fprintf(rf, "\n# Timestamp display precision.\n");
  fprintf(rf, "# One of: AUTO, SEC, DSEC, CSEC, MSEC, USEC, NSEC\n");
  fprintf(rf, RECENT_GUI_TIME_PRECISION ": %s\n",
          ts_precision_text[recent.gui_time_precision]);

  fprintf(rf, "\n# Seconds display format.\n");
  fprintf(rf, "# One of: SECONDS, HOUR_MIN_SEC\n");
  fprintf(rf, RECENT_GUI_SECONDS_FORMAT ": %s\n",
          ts_seconds_text[recent.gui_seconds_format]);

  fprintf(rf, "\n# Zoom level.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_ZOOM_LEVEL ": %d\n",
		  recent.gui_zoom_level);

  fprintf(rf, "\n# Bytes view.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_BYTES_VIEW ": %d\n",
		  recent.gui_bytes_view);

  fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_upper_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE ": %d\n",
		  recent.gui_geometry_main_upper_pane);
  }
  fprintf(rf, "\n# Main window middle pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_lower_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE ": %d\n",
		  recent.gui_geometry_main_lower_pane);
  }

  fprintf(rf, "\n# Packet list column pixel widths.\n");
  fprintf(rf, "# Each pair of strings consists of a column format and its pixel width.\n");
  packet_list_recent_write_all(rf);

  if (get_last_open_dir() != NULL) {
    fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n");

    if(u3_active())
      fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", u3_contract_device_path(get_last_open_dir()));
    else
      fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", get_last_open_dir());
  }

  fclose(rf);

  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
     an error indication, or maybe write to a new recent file and
     rename that file on top of the old one only if there are not I/O
     errors. */
  return TRUE;
}
Exemple #17
0
/* Attempt to Write out "recent common" to the user's recent common file.
   If we got an error report it with a dialog box and return FALSE,
   otherwise return TRUE. */
gboolean
write_recent(void)
{
  char        *pf_dir_path;
  char        *rf_path;
  FILE        *rf;

  /* To do:
   * - Split output lines longer than MAX_VAL_LEN
   * - Create a function for the preference directory check/creation
   *   so that duplication can be avoided with filter.c
   */

  /* Create the directory that holds personal configuration files, if
     necessary.  */
  if (create_persconffile_dir(&pf_dir_path) == -1) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
      g_strerror(errno));
     g_free(pf_dir_path);
     return FALSE;
  }

  rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE);
  if ((rf = ws_fopen(rf_path, "w")) == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't open recent file\n\"%s\": %s.", rf_path,
      g_strerror(errno));
    g_free(rf_path);
    return FALSE;
  }
  g_free(rf_path);

  fputs("# Recent settings file for Wireshark " VERSION ".\n"
    "#\n"
    "# This file is regenerated each time Wireshark is quit.\n"
    "# So be careful, if you want to make manual changes here.\n"
    "\n"
    "######## Recent capture files (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  menu_recent_file_write_all(rf);

  fputs("\n"
    "######## Recent capture filters (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  cfilter_recent_write_all(rf);

  fputs("\n"
    "######## Recent display filters (latest last), cannot be altered through command line ########\n"
    "\n", rf);

  dfilter_recent_combo_write_all(rf);

#ifdef HAVE_PCAP_REMOTE
  fputs("\n"
    "######## Recent remote hosts, cannot be altered through command line ########\n"
    "\n", rf);

  capture_remote_combo_recent_write_all(rf);
#endif

  fprintf(rf, "\n# Main window geometry.\n");
  fprintf(rf, "# Decimal numbers.\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_X ": %d\n", recent.gui_geometry_main_x);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_Y ": %d\n", recent.gui_geometry_main_y);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_WIDTH ": %d\n",
  		  recent.gui_geometry_main_width);
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_HEIGHT ": %d\n",
  		  recent.gui_geometry_main_height);

  fprintf(rf, "\n# Main window maximized.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED ": %s\n",
		  recent.gui_geometry_main_maximized == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Statusbar left pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_status_pane_left != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_STATUS_PANE_LEFT ": %d\n",
		  recent.gui_geometry_status_pane_left);
  }
  fprintf(rf, "\n# Statusbar middle pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_status_pane_right != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_STATUS_PANE_RIGHT ": %d\n",
		  recent.gui_geometry_status_pane_right);
  }

  fprintf(rf, "\n# Last used Configuration Profile.\n");
  fprintf(rf, RECENT_LAST_USED_PROFILE ": %s\n", get_profile_name());

  fprintf(rf, "\n# WLAN statistics upper pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  fprintf(rf, RECENT_GUI_GEOMETRY_WLAN_STATS_PANE ": %d\n",
	  recent.gui_geometry_wlan_stats_pane);

  fprintf(rf, "\n# Warn if running with elevated permissions (e.g. as root).\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PRIVS_WARN_IF_ELEVATED ": %s\n",
		  recent.privs_warn_if_elevated == TRUE ? "TRUE" : "FALSE");

  fprintf(rf, "\n# Warn if npf.sys isn't loaded on Windows >= 6.0.\n");
  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
  fprintf(rf, RECENT_KEY_PRIVS_WARN_IF_NO_NPF ": %s\n",
		  recent.privs_warn_if_no_npf == TRUE ? "TRUE" : "FALSE");

  window_geom_recent_write_all(rf);

  fclose(rf);

  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
     an error indication, or maybe write to a new recent file and
     rename that file on top of the old one only if there are not I/O
     errors. */
  return TRUE;
}
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);
  }
}
void ProfileDialog::updateWidgets()
{
    QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem();
    bool enable_new = false;
    bool enable_del = false;
    bool enable_copy = false;
    bool enable_ok = true;
    profile_def *current_profile = NULL;

    if (item) {
        current_profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
        enable_new = true;
        enable_copy = true;
        if (!current_profile->is_global && !(item->font(0).strikeOut())) {
            enable_del = true;
        }
    }

    if (current_profile) {
        QString profile_path;
        QString profile_info;
        switch (current_profile->status) {
        case PROF_STAT_DEFAULT:
            if (item->font(0).strikeOut()) {
                profile_info = tr("Will be reset to default values");
            } else {
                profile_path = get_persconffile_path("", FALSE);
            }
            break;
        case PROF_STAT_EXISTS:
            {
            char* profile_dir = current_profile->is_global ? get_global_profiles_dir() : get_profiles_dir();
            profile_path = profile_dir;
            g_free(profile_dir);

            profile_path.append(QDir::separator()).append(current_profile->name);
            }
            break;
        case PROF_STAT_COPY:
            if (current_profile->reference) {
                profile_info = tr("Created from %1").arg(current_profile->reference);
                if (current_profile->from_global) {
                    profile_info.append(QString(" %1").arg(tr("(system provided)")));
                }
                break;
            }
            /* Fall Through */
        case PROF_STAT_NEW:
            profile_info = tr("Created from default settings");
            break;
        case PROF_STAT_CHANGED:
            profile_info = tr("Renamed from %1").arg(current_profile->reference);
            break;
        }
        if (!profile_path.isEmpty()) {
            pd_ui_->infoLabel->setUrl(QUrl::fromLocalFile(profile_path).toString());
            pd_ui_->infoLabel->setText(profile_path);
            pd_ui_->infoLabel->setToolTip(tr("Go to %1").arg(profile_path));
        } else {
            pd_ui_->infoLabel->clear();
            pd_ui_->infoLabel->setText(profile_info);
        }
    } else {
        pd_ui_->infoLabel->clear();
    }

    if (pd_ui_->profileTreeWidget->topLevelItemCount() > 0) {
        profile_def *profile;
        for (int i = 0; i < pd_ui_->profileTreeWidget->topLevelItemCount(); i++) {
            item = pd_ui_->profileTreeWidget->topLevelItem(i);
            profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
            if (gchar *err_msg = profile_name_is_valid(profile->name)) {
                item->setToolTip(0, err_msg);
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
                if (profile == current_profile) {
                    pd_ui_->infoLabel->setText(err_msg);
                }
                g_free(err_msg);
                enable_ok = false;
                continue;
            }
            if (profile->is_global) {
                item->setToolTip(0, tr("This is a system provided profile."));
                continue;
            }
            if (current_profile && !current_profile->is_global && profile != current_profile && strcmp(profile->name, current_profile->name) == 0) {
                item->setToolTip(0, tr("A profile already exists with this name."));
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
                if (current_profile->status != PROF_STAT_DEFAULT &&
                    current_profile->status != PROF_STAT_EXISTS)
                {
                    pd_ui_->infoLabel->setText(tr("A profile already exists with this name"));
                }
                enable_ok = false;
            } else if (item->font(0).strikeOut()) {
                item->setToolTip(0, tr("The profile will be reset to default values."));
                item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_deprecated));
            } else {
                item->setBackground(0, QBrush());
            }
        }
    }

    pd_ui_->profileTreeWidget->resizeColumnToContents(0);
    pd_ui_->newToolButton->setEnabled(enable_new);
    pd_ui_->deleteToolButton->setEnabled(enable_del);
    pd_ui_->copyToolButton->setEnabled(enable_copy);
    ok_button_->setEnabled(enable_ok);
}
ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
    GeometryStateDialog(parent),
    ui(new Ui::ColoringRulesDialog),
    colorRuleModel_(palette().color(QPalette::Text), palette().color(QPalette::Base), this),
    colorRuleDelegate_(this)
{
    ui->setupUi(this);
    if (parent) loadGeometry(parent->width() * 2 / 3, parent->height() * 4 / 5);

    setWindowTitle(wsApp->windowTitleString(tr("Coloring Rules %1").arg(get_profile_name())));

    ui->coloringRulesTreeView->setModel(&colorRuleModel_);
    ui->coloringRulesTreeView->setItemDelegate(&colorRuleDelegate_);

    ui->coloringRulesTreeView->viewport()->setAcceptDrops(true);

    for (int i = 0; i < colorRuleModel_.columnCount(); i++) {
        ui->coloringRulesTreeView->resizeColumnToContents(i);
    }

#ifdef Q_OS_MAC
    ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true);
    ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true);
    ui->copyToolButton->setAttribute(Qt::WA_MacSmallSize, true);
    ui->clearToolButton->setAttribute(Qt::WA_MacSmallSize, true);
    ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true);
#endif

    connect(ui->coloringRulesTreeView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
            this, SLOT(colorRuleSelectionChanged(const QItemSelection &, const QItemSelection &)));
    connect(&colorRuleDelegate_, SIGNAL(invalidField(const QModelIndex&, const QString&)),
            this, SLOT(invalidField(const QModelIndex&, const QString&)));
    connect(&colorRuleDelegate_, SIGNAL(validField(const QModelIndex&)),
            this, SLOT(validField(const QModelIndex&)));
    connect(&colorRuleModel_, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowCountChanged()));
    connect(&colorRuleModel_, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(rowCountChanged()));

    rowCountChanged();

    import_button_ = ui->buttonBox->addButton(tr("Import" UTF8_HORIZONTAL_ELLIPSIS), QDialogButtonBox::ApplyRole);
    import_button_->setToolTip(tr("Select a file and add its filters to the end of the list."));
    export_button_ = ui->buttonBox->addButton(tr("Export" UTF8_HORIZONTAL_ELLIPSIS), QDialogButtonBox::ApplyRole);
    export_button_->setToolTip(tr("Save filters in a file."));

    QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
    CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(COLORFILTERS_FILE_NAME, copy_button);
    copy_button->setMenu(copy_from_menu);
    copy_button->setToolTip(tr("Copy coloring rules from another profile."));
    copy_button->setEnabled(copy_from_menu->haveProfiles());
    connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));

    QString abs_path = gchar_free_to_qstring(get_persconffile_path(COLORFILTERS_FILE_NAME, TRUE));
    if (file_exists(abs_path.toUtf8().constData())) {
        ui->pathLabel->setText(abs_path);
        ui->pathLabel->setUrl(QUrl::fromLocalFile(abs_path).toString());
        ui->pathLabel->setToolTip(tr("Open ") + COLORFILTERS_FILE_NAME);
        ui->pathLabel->setEnabled(true);
    }

    if (!add_filter.isEmpty()) {
        colorRuleModel_.addColor(false, add_filter, palette().color(QPalette::Text), palette().color(QPalette::Base));

        //setup the buttons appropriately
        ui->coloringRulesTreeView->setCurrentIndex(colorRuleModel_.index(0, 0));

        //set edit on display filter
        ui->coloringRulesTreeView->edit(colorRuleModel_.index(0, 1));
    }else {
        ui->coloringRulesTreeView->setCurrentIndex(QModelIndex());
    }

    checkUnknownColorfilters();

    updateHint();
}
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;
}
Exemple #22
0
/* Attempt to Write out profile "recent" to the user's profile recent file.
   If we got an error report it with a dialog box and return FALSE,
   otherwise return TRUE. */
gboolean
write_profile_recent(void)
{
  char        *pf_dir_path;
  char        *rf_path;
  char        *string_list;
  FILE        *rf;

  /* To do:
   * - Split output lines longer than MAX_VAL_LEN
   * - Create a function for the preference directory check/creation
   *   so that duplication can be avoided with filter.c
   */

  /* Create the directory that holds personal configuration files, if
     necessary.  */
  if (create_persconffile_dir(&pf_dir_path) == -1) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
      g_strerror(errno));
     g_free(pf_dir_path);
     return FALSE;
  }

  rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE);
  if ((rf = ws_fopen(rf_path, "w")) == NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
      "Can't open recent file\n\"%s\": %s.", rf_path,
      g_strerror(errno));
    g_free(rf_path);
    return FALSE;
  }
  g_free(rf_path);

  fputs("# Recent settings file for Wireshark " VERSION ".\n"
    "#\n"
    "# This file is regenerated each time Wireshark is quit\n"
    "# and when changing configuration profile.\n"
    "# So be careful, if you want to make manual changes here.\n"
    "\n", rf);

  write_recent_boolean(rf, "Main Toolbar show (hide)",
                       RECENT_KEY_MAIN_TOOLBAR_SHOW,
                       recent.main_toolbar_show);

  write_recent_boolean(rf, "Filter Toolbar show (hide)",
                       RECENT_KEY_FILTER_TOOLBAR_SHOW,
                       recent.filter_toolbar_show);

  write_recent_boolean(rf, "Wireless Settings Toolbar show (hide)",
                       RECENT_KEY_WIRELESS_TOOLBAR_SHOW,
                       recent.wireless_toolbar_show);

#ifdef HAVE_AIRPCAP
  write_recent_boolean(rf, "Show (hide) old AirPcap driver warning dialog box",
                       RECENT_KEY_DRIVER_CHECK_SHOW,
                       recent.airpcap_driver_check_show);
#endif

  write_recent_boolean(rf, "Packet list show (hide)",
                       RECENT_KEY_PACKET_LIST_SHOW,
                       recent.packet_list_show);

  write_recent_boolean(rf, "Tree view show (hide)",
                       RECENT_KEY_TREE_VIEW_SHOW,
                       recent.tree_view_show);

  write_recent_boolean(rf, "Byte view show (hide)",
                       RECENT_KEY_BYTE_VIEW_SHOW,
                       recent.byte_view_show);

  write_recent_boolean(rf, "Statusbar show (hide)",
                       RECENT_KEY_STATUSBAR_SHOW,
                       recent.statusbar_show);

  write_recent_boolean(rf, "Packet list colorize (hide)",
                       RECENT_KEY_PACKET_LIST_COLORIZE,
                       recent.packet_list_colorize);

  write_recent_enum(rf, "Timestamp display format",
                    RECENT_GUI_TIME_FORMAT, ts_type_values,
                    recent.gui_time_format);

  write_recent_enum(rf, "Timestamp display precision",
                    RECENT_GUI_TIME_PRECISION, ts_precision_values,
                    recent.gui_time_precision);

  write_recent_enum(rf, "Seconds display format",
                    RECENT_GUI_SECONDS_FORMAT, ts_seconds_values,
                    recent.gui_seconds_format);

  fprintf(rf, "\n# Zoom level.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_ZOOM_LEVEL ": %d\n",
          recent.gui_zoom_level);

  fprintf(rf, "\n# Bytes view.\n");
  fprintf(rf, "# A decimal number.\n");
  fprintf(rf, RECENT_GUI_BYTES_VIEW ": %d\n",
          recent.gui_bytes_view);

  fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_upper_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE ": %d\n",
            recent.gui_geometry_main_upper_pane);
  }
  fprintf(rf, "\n# Main window middle pane size.\n");
  fprintf(rf, "# Decimal number.\n");
  if (recent.gui_geometry_main_lower_pane != 0) {
    fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE ": %d\n",
            recent.gui_geometry_main_lower_pane);
  }

  fprintf(rf, "\n# Packet list column pixel widths.\n");
  fprintf(rf, "# Each pair of strings consists of a column format and its pixel width.\n");
  packet_list_recent_write_all(rf);

  fprintf(rf, "\n# Open conversation dialog tabs.\n");
  fprintf(rf, "# List of conversation names, e.g. \"TCP\", \"IPv6\".\n");
  string_list = join_string_list(recent.conversation_tabs);
  fprintf(rf, RECENT_GUI_CONVERSATION_TABS ": %s\n", string_list);
  g_free(string_list);

  fprintf(rf, "\n# Open endpoint dialog tabs.\n");
  fprintf(rf, "# List of endpoint names, e.g. \"TCP\", \"IPv6\".\n");
  string_list = join_string_list(recent.endpoint_tabs);
  fprintf(rf, RECENT_GUI_ENDPOINT_TABS ": %s\n", string_list);
  g_free(string_list);

  write_recent_boolean(rf, "For RLC stats, whether to use RLC PDUs found inside MAC frames",
                       RECENT_GUI_RLC_PDUS_FROM_MAC_FRAMES,
                       recent.gui_rlc_use_pdus_from_mac);

  if (get_last_open_dir() != NULL) {
    fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n");
    fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n", get_last_open_dir());
  }

  fclose(rf);

  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
     an error indication, or maybe write to a new recent file and
     rename that file on top of the old one only if there are not I/O
     errors. */
  return TRUE;
}
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;
        }
    }

}