aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2016-02-16 22:34:12 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-02-18 08:06:46 +0000
commit30d83e089c2f0b5d5d67892c6fc581ba9ce0a0a5 (patch)
treed746f24099cf6bdf108e9f64fc1aaf8df5bdd8fc /ui/qt
parentb77ffb9d36a9405943dadce3d4849c1106b2e361 (diff)
Qt: Add regex support in Find Packet
Add support for using regular expressions in the Search Frame when searching in packet list, packet details and packet bytes. This search is in many cases faster than plain string search. Change-Id: I2d8a709046f90d7b278fb39547fc4e2e420623bc Reviewed-on: https://code.wireshark.org/review/13981 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/search_frame.cpp68
-rw-r--r--ui/qt/search_frame.h4
-rw-r--r--ui/qt/search_frame.ui7
3 files changed, 70 insertions, 9 deletions
diff --git a/ui/qt/search_frame.cpp b/ui/qt/search_frame.cpp
index 6fe3f2de03..c0c7f13c64 100644
--- a/ui/qt/search_frame.cpp
+++ b/ui/qt/search_frame.cpp
@@ -40,7 +40,8 @@ enum {
enum {
df_search_,
hex_search_,
- string_search_
+ string_search_,
+ regex_search_
};
enum {
@@ -52,7 +53,8 @@ enum {
SearchFrame::SearchFrame(QWidget *parent) :
AccordionFrame(parent),
sf_ui_(new Ui::SearchFrame),
- cap_file_(NULL)
+ cap_file_(NULL),
+ regex_(NULL)
{
sf_ui_->setupUi(this);
@@ -67,6 +69,9 @@ SearchFrame::SearchFrame(QWidget *parent) :
SearchFrame::~SearchFrame()
{
+ if (regex_) {
+ g_regex_unref(regex_);
+ }
delete sf_ui_;
}
@@ -138,6 +143,33 @@ void SearchFrame::keyPressEvent(QKeyEvent *event)
}
}
+bool SearchFrame::regexCompile()
+{
+ int flags = (G_REGEX_OPTIMIZE);
+ if (!sf_ui_->caseCheckBox->isChecked()) {
+ flags |= G_REGEX_CASELESS;
+ }
+
+ if (regex_) {
+ g_regex_unref(regex_);
+ }
+
+ if (sf_ui_->searchLineEdit->text().isEmpty()) {
+ regex_ = NULL;
+ return false;
+ }
+
+ GError *g_error = NULL;
+ regex_ = g_regex_new(sf_ui_->searchLineEdit->text().toUtf8().constData(),
+ (GRegexCompileFlags)flags, (GRegexMatchFlags) 0, &g_error);
+ if (g_error) {
+ regex_error_ = g_error->message;
+ g_error_free(g_error);
+ }
+
+ return regex_ ? true : false;
+}
+
void SearchFrame::updateWidgets()
{
if (cap_file_) {
@@ -147,12 +179,12 @@ void SearchFrame::updateWidgets()
return;
}
- bool enable = sf_ui_->searchTypeComboBox->currentIndex() == string_search_;
- sf_ui_->searchInComboBox->setEnabled(enable);
- sf_ui_->caseCheckBox->setEnabled(enable);
- sf_ui_->charEncodingComboBox->setEnabled(enable);
+ int search_type = sf_ui_->searchTypeComboBox->currentIndex();
+ sf_ui_->searchInComboBox->setEnabled(search_type == string_search_ || search_type == regex_search_);
+ sf_ui_->caseCheckBox->setEnabled(search_type == string_search_ || search_type == regex_search_);
+ sf_ui_->charEncodingComboBox->setEnabled(search_type == string_search_);
- switch (sf_ui_->searchTypeComboBox->currentIndex()) {
+ switch (search_type) {
case df_search_:
sf_ui_->searchLineEdit->checkDisplayFilter(sf_ui_->searchLineEdit->text());
break;
@@ -178,6 +210,13 @@ void SearchFrame::updateWidgets()
sf_ui_->searchLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
}
break;
+ case regex_search_:
+ if (regexCompile()) {
+ sf_ui_->searchLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
+ } else {
+ sf_ui_->searchLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
+ }
+ break;
default:
// currentIndex is probably -1. Nothing is selected or list is empty.
return;
@@ -190,6 +229,11 @@ void SearchFrame::updateWidgets()
}
}
+void SearchFrame::on_caseCheckBox_toggled(bool)
+{
+ regexCompile();
+}
+
void SearchFrame::on_searchTypeComboBox_currentIndexChanged(int)
{
updateWidgets();
@@ -216,12 +260,14 @@ void SearchFrame::on_findButton_clicked()
cap_file_->hex = FALSE;
cap_file_->string = FALSE;
cap_file_->case_type = FALSE;
+ cap_file_->regex = NULL;
cap_file_->packet_data = FALSE;
cap_file_->decode_data = FALSE;
cap_file_->summary_data = FALSE;
cap_file_->scs_type = SCS_NARROW_AND_WIDE;
- switch (sf_ui_->searchTypeComboBox->currentIndex()) {
+ int search_type = sf_ui_->searchTypeComboBox->currentIndex();
+ switch (search_type) {
case df_search_:
if (!dfilter_compile(sf_ui_->searchLineEdit->text().toUtf8().constData(), &dfp, NULL)) {
err_string = tr("Invalid filter.");
@@ -245,6 +291,7 @@ void SearchFrame::on_findButton_clicked()
cap_file_->hex = TRUE;
break;
case string_search_:
+ case regex_search_:
if (sf_ui_->searchLineEdit->text().isEmpty()) {
err_string = tr("You didn't specify any text for which to search.");
emit pushFilterSyntaxStatus(err_string);
@@ -252,6 +299,7 @@ void SearchFrame::on_findButton_clicked()
}
cap_file_->string = TRUE;
cap_file_->case_type = sf_ui_->caseCheckBox->isChecked() ? FALSE : TRUE;
+ cap_file_->regex = (search_type == regex_search_ ? regex_ : NULL);
switch (sf_ui_->charEncodingComboBox->currentIndex()) {
case narrow_and_wide_chars_:
cap_file_->scs_type = SCS_NARROW_AND_WIDE;
@@ -305,6 +353,10 @@ void SearchFrame::on_findButton_clicked()
return;
}
} else if (cap_file_->string) {
+ if (search_type == regex_search_ && !cap_file_->regex) {
+ emit pushFilterSyntaxStatus(regex_error_);
+ return;
+ }
if (cap_file_->summary_data) {
/* String in the Info column of the summary line */
found_packet = cf_find_packet_summary_line(cap_file_, string, cap_file_->dir);
diff --git a/ui/qt/search_frame.h b/ui/qt/search_frame.h
index 9ba8c62c1c..ee895e0366 100644
--- a/ui/qt/search_frame.h
+++ b/ui/qt/search_frame.h
@@ -55,12 +55,16 @@ protected:
virtual void keyPressEvent(QKeyEvent *event);
private:
+ bool regexCompile();
void updateWidgets();
Ui::SearchFrame *sf_ui_;
capture_file *cap_file_;
+ GRegex *regex_;
+ QString regex_error_;
private slots:
+ void on_caseCheckBox_toggled(bool);
void on_searchTypeComboBox_currentIndexChanged(int);
void on_searchLineEdit_textChanged(const QString &);
void on_findButton_clicked();
diff --git a/ui/qt/search_frame.ui b/ui/qt/search_frame.ui
index e05a4ff06b..d2b9056118 100644
--- a/ui/qt/search_frame.ui
+++ b/ui/qt/search_frame.ui
@@ -106,7 +106,7 @@
<item>
<widget class="QComboBox" name="searchTypeComboBox">
<property name="toolTip">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search for data using display filter syntax (e.g. ip.addr==10.1.1.1), a hexadecimal string (e.g. fffffda5) or a plain string (e.g. My String).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search for data using display filter syntax (e.g. ip.addr==10.1.1.1), a hexadecimal string (e.g. fffffda5), a plain string (e.g. My String) or a regular expression (e.g. colou?r).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
@@ -123,6 +123,11 @@
<string>String</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>Regular Expression</string>
+ </property>
+ </item>
</widget>
</item>
<item>