コード例 #1
0
static gboolean
proto_hier_tree_iter_next(GtkTreeModel *tree_model, GtkTreeIter *iter)
{
	ProtoHierTreeModel *model;

	g_return_val_if_fail(PROTOHIER_IS_TREE(tree_model), FALSE);
	model = (ProtoHierTreeModel *) tree_model;

	g_return_val_if_fail(iter->stamp == model->stamp, FALSE);

	/* protocol */
	if (iter->user_data2 == NULL) {
		void *cookie = iter->user_data;
		int proto_id;

		proto_id = proto_get_next_protocol(&cookie);
		/* get next enabled protocol */
		while (proto_id != -1) {
			protocol_t *p = find_protocol_by_id(proto_id);

			if (proto_is_protocol_enabled(p))
				break;
			proto_id = proto_get_next_protocol(&cookie);
		}

		if (proto_id == -1)
			return FALSE;

		iter->user_data = cookie;
		iter->user_data3 = proto_registrar_get_nth(proto_id);
		return TRUE;
	}

	/* field */
	{
		void *cookie2 = iter->user_data2;
		header_field_info *hfinfo;

		hfinfo = proto_get_next_protocol_field(&cookie2);
		/* get next field */
		while (hfinfo) {
			if (hfinfo->same_name_prev_id == -1)
				break;
			hfinfo = proto_get_next_protocol_field(&cookie2);
		}

		/* not found? */
		if (!hfinfo)
			return FALSE;

		iter->user_data2 = cookie2;
		iter->user_data3 = hfinfo;
		return TRUE;
	}
}
コード例 #2
0
static GtkTreePath *
proto_hier_tree_get_path(GtkTreeModel *tree_model, GtkTreeIter *iter)
{
	ProtoHierTreeModel *model;
	GtkTreePath *path;
	int pos;

	int p_id;
	void *cookie;

	g_return_val_if_fail(PROTOHIER_IS_TREE(tree_model), NULL);
	model = (ProtoHierTreeModel *) tree_model;

	g_return_val_if_fail(iter != NULL, NULL);
	g_return_val_if_fail(iter->stamp == model->stamp, FALSE);

	p_id = proto_get_data_protocol(iter->user_data);

	path = gtk_tree_path_new();

	/* protocol */
	{
		int id;

		/* XXX, assuming that protocols can't be disabled! */
		pos = 0;
		for (id = proto_get_first_protocol(&cookie); id != p_id && id != -1; id = proto_get_next_protocol(&cookie)) {
			protocol_t *p = find_protocol_by_id(id);

			if (!proto_is_protocol_enabled(p))
				continue;
			pos++;
		}
		gtk_tree_path_append_index(path, pos);
	}

	/* field */
	if (iter->user_data2 != NULL) {
		header_field_info *hfinfo;

		pos = 0;
		for (hfinfo = proto_get_first_protocol_field(p_id, &cookie); hfinfo && hfinfo != iter->user_data3; hfinfo = proto_get_next_protocol_field(&cookie)) {
			if (hfinfo->same_name_prev_id != -1)
				continue;
			pos++;
		}
		gtk_tree_path_append_index(path, pos);
	}

	return path;
}
コード例 #3
0
// Nearly identical to SupportedProtocolsDialog::fillTree.
void DisplayFilterExpressionDialog::fillTree()
{
    void *proto_cookie;
    QList <QTreeWidgetItem *> proto_list;

    for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1;
         proto_id = proto_get_next_protocol(&proto_cookie)) {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        if (!proto_is_protocol_enabled(protocol)) continue;

        QTreeWidgetItem *proto_ti = new QTreeWidgetItem(proto_type_);
        QString label = QString("%1 " UTF8_MIDDLE_DOT " %3")
                .arg(proto_get_protocol_short_name(protocol))
                .arg(proto_get_protocol_long_name(protocol));
        proto_ti->setText(0, label);
        proto_ti->setData(0, Qt::UserRole, QVariant::fromValue(proto_id));
        proto_list << proto_ti;
    }

    wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1);

    ui->fieldTreeWidget->invisibleRootItem()->addChildren(proto_list);
    ui->fieldTreeWidget->sortByColumn(0, Qt::AscendingOrder);

    int field_count = 0;
    foreach (QTreeWidgetItem *proto_ti, proto_list) {
        void *field_cookie;
        int proto_id = proto_ti->data(0, Qt::UserRole).toInt();

        QList <QTreeWidgetItem *> field_list;
        for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo != NULL;
             hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) {
            if (hfinfo->same_name_prev_id != -1) continue; // Ignore duplicate names.

            QTreeWidgetItem *field_ti = new QTreeWidgetItem(field_type_);
            QString label = QString("%1 " UTF8_MIDDLE_DOT " %3").arg(hfinfo->abbrev).arg(hfinfo->name);
            field_ti->setText(0, label);
            field_ti->setData(0, Qt::UserRole, VariantPointer<header_field_info>::asQVariant(hfinfo));
            field_list << field_ti;

            field_count++;
            if (field_count % 10000 == 0) {
                wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1);
            }
        }
        std::sort(field_list.begin(), field_list.end());
        proto_ti->addChildren(field_list);
    }
コード例 #4
0
static gint
proto_hier_tree_iter_n_children(GtkTreeModel *tree_model, GtkTreeIter *iter)
{
	ProtoHierTreeModel *model;
	gint count = 0;

	int p_id;
	void *cookie;

	g_return_val_if_fail(PROTOHIER_IS_TREE(tree_model), 0);
	model = (ProtoHierTreeModel *) tree_model;

	g_return_val_if_fail(iter == NULL || iter->user_data != NULL, 0);

	if (iter) {
		header_field_info *hfinfo;

		g_return_val_if_fail(iter->stamp == model->stamp, 0);

		/* field has no child */
		if (iter->user_data2 != NULL)
			return 0;

		p_id = proto_get_data_protocol(iter->user_data);

		/* count not-duplicated fields */
		for (hfinfo = proto_get_first_protocol_field(p_id, &cookie); hfinfo; hfinfo = proto_get_next_protocol_field(&cookie)) {
			if (hfinfo->same_name_prev_id != -1)
				continue;
			count++;
		}

	} else {
		/* count enabled protocols */
		for (p_id = proto_get_first_protocol(&cookie); p_id != -1; p_id = proto_get_next_protocol(&cookie)) {
			protocol_t *p = find_protocol_by_id(p_id);

			if (!proto_is_protocol_enabled(p))
				continue;
			count++;
		}
	}

	return count;
}
コード例 #5
0
EnabledProtocolsDialog::EnabledProtocolsDialog(QWidget *parent) :
    GeometryStateDialog(parent),
    ui(new Ui::EnabledProtocolsDialog)
{
    ui->setupUi(this);
    loadGeometry();
    setWindowTitle(wsApp->windowTitleString(tr("Enabled Protocols")));

    void *cookie;
    protocol_t *protocol;

    //Remove "original" item
    ui->protocol_tree_->takeTopLevelItem(0);

    // Iterate over all the protocols
    for (gint i = proto_get_first_protocol(&cookie);
         i != -1;
         i = proto_get_next_protocol(&cookie))
    {
        if (proto_can_toggle_protocol(i))
        {
            protocol = find_protocol_by_id(i);
            ProtocolTreeWidgetItem* protocol_row = new ProtocolTreeWidgetItem(ui->protocol_tree_->invisibleRootItem(), protocol);

            proto_heuristic_dissector_foreach(protocol, addHeuristicItem, protocol_row);
        }
    }

    ui->protocol_tree_->expandAll();

    //make sortable
    ui->protocol_tree_->setSortingEnabled(true);
    ui->protocol_tree_->sortByColumn(PROTOCOL_COLUMN, Qt::AscendingOrder);

    // Some protocols have excessively long names. Instead of calling
    // resizeColumnToContents, pick a reasonable-ish em width and apply it.
    int one_em = ui->protocol_tree_->fontMetrics().height();
    ui->protocol_tree_->setColumnWidth(PROTOCOL_COLUMN, one_em * 18);

    //"Remove" Save button
    if (!prefs.gui_use_pref_save)
        ui->buttonBox->button(QDialogButtonBox::Save)->setHidden(true);
}
コード例 #6
0
void SupportedProtocolsDialog::fillTree()
{
    void *proto_cookie;
    QList <QTreeWidgetItem *> proto_list;

    for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1;
         proto_id = proto_get_next_protocol(&proto_cookie)) {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        QTreeWidgetItem *proto_ti = new QTreeWidgetItem();
        proto_ti->setText(name_col_, proto_get_protocol_short_name(protocol));
        proto_ti->setText(filter_col_, proto_get_protocol_filter_name(proto_id));
        // type_col_ empty
        proto_ti->setText(descr_col_, proto_get_protocol_long_name(protocol));
        proto_ti->setData(name_col_, Qt::UserRole, proto_id);
        proto_list << proto_ti;
    }

    updateStatistics();
    ui->protoTreeWidget->invisibleRootItem()->addChildren(proto_list);
    ui->protoTreeWidget->sortByColumn(name_col_, Qt::AscendingOrder);

    foreach (QTreeWidgetItem *proto_ti, proto_list) {
        void *field_cookie;
        int proto_id = proto_ti->data(name_col_, Qt::UserRole).toInt();
        QList <QTreeWidgetItem *> field_list;
        for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo != NULL;
             hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) {
            if (hfinfo->same_name_prev_id != -1) continue;

            QTreeWidgetItem *field_ti = new QTreeWidgetItem();
            field_ti->setText(name_col_, hfinfo->name);
            field_ti->setText(filter_col_, hfinfo->abbrev);
            field_ti->setText(type_col_, ftype_pretty_name(hfinfo->type));
            field_ti->setText(descr_col_, hfinfo->blurb);
            field_list << field_ti;

            field_count_++;
            if (field_count_ % 1000 == 0) updateStatistics();
        }
        std::sort(field_list.begin(), field_list.end());
        proto_ti->addChildren(field_list);
    }
コード例 #7
0
static gboolean
proto_hier_tree_iter_nth_child(GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, gint n)
{
	ProtoHierTreeModel *model;

	gint proto_id;
	void *cookie;

	g_return_val_if_fail(PROTOHIER_IS_TREE(tree_model), FALSE);
	model = (ProtoHierTreeModel *) tree_model;

	if (parent) {
		header_field_info *hfinfo;

		g_return_val_if_fail(parent->stamp == model->stamp, FALSE);

		/* no child of field */
		if (parent->user_data2 != NULL)
			return FALSE;

		proto_id = proto_get_data_protocol(parent->user_data);

		/* get n-th field of protocol */
		hfinfo = proto_get_first_protocol_field(proto_id, &cookie);
		while (hfinfo) {
			if (hfinfo->same_name_prev_id == -1) {
				if (!n)
					break;
				n--;
			}
			hfinfo = proto_get_next_protocol_field(&cookie);
		}

		/* not found? */
		if (!hfinfo)
			return FALSE;

		iter->stamp = model->stamp;
		iter->user_data = parent->user_data;
		iter->user_data2 = cookie;
		iter->user_data3 = hfinfo;
		return TRUE;
	}

	/* get n-th enabled protocol */
	proto_id = proto_get_first_protocol(&cookie);
	while (proto_id != -1) {
		protocol_t *p = find_protocol_by_id(proto_id);

		if (proto_is_protocol_enabled(p)) {
			if (!n)
				break;
			n--;
		}
		proto_id = proto_get_next_protocol(&cookie);
	}

	/* not found? */
	if (proto_id == -1)
		return FALSE;

	iter->stamp = model->stamp;
	iter->user_data = cookie;
	iter->user_data2 = NULL;
	iter->user_data3 = proto_registrar_get_nth(proto_id);
	return TRUE;
}
コード例 #8
0
/*
 * 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);
}
コード例 #9
0
// ui/gtk/filter_autocomplete.c:build_autocompletion_list
void FieldFilterEdit::buildCompletionList(const QString &field_word)
{
    // Push a hint about the current field.
    if (syntaxState() == Valid) {
        emit popFilterSyntaxStatus();

        header_field_info *hfinfo = proto_registrar_get_byname(field_word.toUtf8().constData());
        if (hfinfo) {
            QString cursor_field_msg = QString("%1: %2")
                    .arg(hfinfo->name)
                    .arg(ftype_pretty_name(hfinfo->type));
            emit pushFilterSyntaxStatus(cursor_field_msg);
        }
    }

    if (field_word.length() < 1) {
        completion_model_->setStringList(QStringList());
        return;
    }

    void *proto_cookie;
    QStringList field_list;
    int field_dots = field_word.count('.'); // Some protocol names (_ws.expert) contain periods.
    for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1; proto_id = proto_get_next_protocol(&proto_cookie)) {
        protocol_t *protocol = find_protocol_by_id(proto_id);
        if (!proto_is_protocol_enabled(protocol)) continue;

        const QString pfname = proto_get_protocol_filter_name(proto_id);
        field_list << pfname;

        // Add fields only if we're past the protocol name and only for the
        // current protocol.
        if (field_dots > pfname.count('.')) {
            void *field_cookie;
            const QByteArray fw_ba = field_word.toUtf8(); // or toLatin1 or toStdString?
            const char *fw_utf8 = fw_ba.constData();
            gsize fw_len = (gsize) strlen(fw_utf8);
            for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo; hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) {
                if (hfinfo->same_name_prev_id != -1) continue; // Ignore duplicate names.

                if (!g_ascii_strncasecmp(fw_utf8, hfinfo->abbrev, fw_len)) {
                    if ((gsize) strlen(hfinfo->abbrev) != fw_len) field_list << hfinfo->abbrev;
                }
            }
        }
    }
    field_list.sort();

    completion_model_->setStringList(field_list);
    completer()->setCompletionPrefix(field_word);
}