5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "search_frame.h"
25 #include "ui_search_frame.h"
27 #include <epan/proto.h>
28 #include <epan/strutil.h>
30 #include "wireshark_application.h"
34 const int in_packet_list
= 0;
35 const int in_proto_tree
= 1;
36 const int in_bytes
= 2;
38 const int df_search
= 0;
39 const int hex_search
= 1;
40 const int string_search
= 2;
42 const int narrow_and_wide_chars
= 0;
43 const int narrow_chars
= 1;
44 const int wide_chars
= 2;
46 SearchFrame::SearchFrame(QWidget
*parent
) :
47 AccordionFrame(parent
),
48 sf_ui_(new Ui::SearchFrame
),
51 sf_ui_
->setupUi(this);
54 foreach (QWidget
*w
, findChildren
<QWidget
*>()) {
55 w
->setAttribute(Qt::WA_MacSmallSize
, true);
58 sf_ui_
->searchTypeComboBox
->setCurrentIndex(0);
62 SearchFrame::~SearchFrame()
67 void SearchFrame::animatedShow()
69 sf_ui_
->searchLineEdit
->setFocus();
71 AccordionFrame::animatedShow();
74 void SearchFrame::findNext()
76 if (!cap_file_
) return;
78 cap_file_
->dir
= SD_FORWARD
;
83 on_findButton_clicked();
86 void SearchFrame::findPrevious()
88 if (!cap_file_
) return;
90 cap_file_
->dir
= SD_BACKWARD
;
95 on_findButton_clicked();
98 void SearchFrame::setCaptureFile(capture_file
*cf
)
101 if (!cf
&& isVisible()) {
107 void SearchFrame::findFrameWithFilter(QString
&filter
)
110 sf_ui_
->searchLineEdit
->setText(filter
);
111 sf_ui_
->searchTypeComboBox
->setCurrentIndex(0);
115 void SearchFrame::keyPressEvent(QKeyEvent
*event
)
117 if (wsApp
->focusWidget() == sf_ui_
->searchLineEdit
) {
118 if (event
->modifiers() == Qt::NoModifier
) {
119 if (event
->key() == Qt::Key_Escape
) {
120 on_cancelButton_clicked();
121 } else if (event
->key() == Qt::Key_Enter
|| event
->key() == Qt::Key_Return
) {
122 on_findButton_clicked();
125 return; // searchLineEdit didn't want it and we don't either.
129 void SearchFrame::enableWidgets()
138 dfilter_t
*dfp
= NULL
;
139 bool enable
= sf_ui_
->searchTypeComboBox
->currentIndex() == string_search
;
140 sf_ui_
->searchInComboBox
->setEnabled(enable
);
141 sf_ui_
->caseCheckBox
->setEnabled(enable
);
142 sf_ui_
->charEncodingComboBox
->setEnabled(enable
);
144 switch (sf_ui_
->searchTypeComboBox
->currentIndex()) {
146 // XXX - Merge this with DisplayFitlerEdit::checkFilter
147 if (dfilter_compile(sf_ui_
->searchLineEdit
->text().toUtf8().constData(), &dfp
)) {
148 GPtrArray
*depr
= NULL
;
150 depr
= dfilter_deprecated_tokens(dfp
);
152 if (sf_ui_
->searchLineEdit
->text().isEmpty()) {
153 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Empty
);
155 /* You keep using that word. I do not think it means what you think it means. */
156 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Deprecated
);
158 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Valid
);
162 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Invalid
);
166 if (sf_ui_
->searchLineEdit
->text().isEmpty()) {
167 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Invalid
);
171 bytes
= convert_string_to_hex(sf_ui_
->searchLineEdit
->text().toUtf8().constData(), &nbytes
);
173 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Invalid
);
176 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Valid
);
181 if (sf_ui_
->searchLineEdit
->text().isEmpty()) {
182 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Invalid
);
184 sf_ui_
->searchLineEdit
->setSyntaxState(SyntaxLineEdit::Valid
);
188 QString err_string
= tr("No valid search type selected. Please report this to the development team.");
189 emit
pushFilterSyntaxStatus(err_string
);
193 if (sf_ui_
->searchLineEdit
->text().isEmpty() || sf_ui_
->searchLineEdit
->syntaxState() == SyntaxLineEdit::Invalid
) {
194 sf_ui_
->findButton
->setEnabled(false);
196 sf_ui_
->findButton
->setEnabled(true);
200 void SearchFrame::on_searchTypeComboBox_currentIndexChanged(int index
)
206 void SearchFrame::on_searchLineEdit_textChanged(const QString
&search_string
)
208 Q_UNUSED(search_string
);
212 void SearchFrame::on_findButton_clicked()
214 guint8
*bytes
= NULL
;
218 gboolean found_packet
= FALSE
;
225 cap_file_
->hex
= FALSE
;
226 cap_file_
->string
= FALSE
;
227 cap_file_
->case_type
= FALSE
;
228 cap_file_
->packet_data
= FALSE
;
229 cap_file_
->decode_data
= FALSE
;
230 cap_file_
->summary_data
= FALSE
;
231 cap_file_
->scs_type
= SCS_NARROW_AND_WIDE
;
233 switch (sf_ui_
->searchTypeComboBox
->currentIndex()) {
235 if (!dfilter_compile(sf_ui_
->searchLineEdit
->text().toUtf8().constData(), &dfp
)) {
236 err_string
= tr("Invalid filter.");
237 emit
pushFilterSyntaxStatus(err_string
);
242 err_string
= tr("That filter doesn't test anything.");
243 emit
pushFilterSyntaxStatus(err_string
);
248 bytes
= convert_string_to_hex(sf_ui_
->searchLineEdit
->text().toUtf8().constData(), &nbytes
);
250 err_string
= tr("That's not a valid hex string.");
251 emit
pushFilterSyntaxStatus(err_string
);
254 cap_file_
->hex
= TRUE
;
257 if (sf_ui_
->searchLineEdit
->text().isEmpty()) {
258 err_string
= tr("You didn't specify any text for which to search.");
259 emit
pushFilterSyntaxStatus(err_string
);
262 cap_file_
->string
= TRUE
;
263 cap_file_
->case_type
= sf_ui_
->caseCheckBox
->isChecked() ? FALSE
: TRUE
;
264 switch (sf_ui_
->charEncodingComboBox
->currentIndex()) {
265 case narrow_and_wide_chars
:
266 cap_file_
->scs_type
= SCS_NARROW_AND_WIDE
;
269 cap_file_
->scs_type
= SCS_NARROW
;
272 cap_file_
->scs_type
= SCS_WIDE
;
275 err_string
= tr("No valid character set selected. Please report this to the development team.");
276 emit
pushFilterSyntaxStatus(err_string
);
279 string
= convert_string_case(sf_ui_
->searchLineEdit
->text().toUtf8().constData(), cap_file_
->case_type
);
282 err_string
= tr("No valid search type selected. Please report this to the development team.");
283 emit
pushFilterSyntaxStatus(err_string
);
287 switch (sf_ui_
->searchInComboBox
->currentIndex()) {
289 cap_file_
->summary_data
= TRUE
;
292 cap_file_
->decode_data
= TRUE
;
295 cap_file_
->packet_data
= TRUE
;
298 err_string
= tr("No valid search area selected. Please report this to the development team.");
299 emit
pushFilterSyntaxStatus(err_string
);
303 g_free(cap_file_
->sfilter
);
304 cap_file_
->sfilter
= g_strdup(sf_ui_
->searchLineEdit
->text().toUtf8().constData());
306 if (cap_file_
->hex
) {
307 /* Hex value in packet data */
308 found_packet
= cf_find_packet_data(cap_file_
, bytes
, nbytes
, cap_file_
->dir
);
311 /* We didn't find a packet */
312 err_string
= tr("No packet contained those bytes.");
313 emit
pushFilterSyntaxStatus(err_string
);
316 } else if (cap_file_
->string
) {
317 if (cap_file_
->summary_data
) {
318 /* String in the Info column of the summary line */
319 found_packet
= cf_find_packet_summary_line(cap_file_
, string
, cap_file_
->dir
);
322 err_string
= tr("No packet contained that string in its Info column.");
323 emit
pushFilterSyntaxStatus(err_string
);
326 } else if (cap_file_
->decode_data
) {
327 /* String in the protocol tree headings */
328 found_packet
= cf_find_packet_protocol_tree(cap_file_
, string
, cap_file_
->dir
);
331 err_string
= tr("No packet contained that string in its dissected display.");
332 emit
pushFilterSyntaxStatus(err_string
);
335 } else if (cap_file_
->packet_data
&& string
) {
336 /* String in the ASCII-converted packet data */
337 found_packet
= cf_find_packet_data(cap_file_
, (guint8
*) string
, strlen(string
), cap_file_
->dir
);
340 err_string
= tr("No packet contained that string in its converted data.");
341 emit
pushFilterSyntaxStatus(err_string
);
346 /* Search via display filter */
347 found_packet
= cf_find_packet_dfilter(cap_file_
, dfp
, cap_file_
->dir
);
350 err_string
= tr("No packet matched that filter.");
351 emit
pushFilterSyntaxStatus(err_string
);
358 void SearchFrame::on_cancelButton_clicked()
369 * indent-tabs-mode: nil
372 * ex: set shiftwidth=4 tabstop=8 expandtab:
373 * :indentSize=4:tabSize=8:noTabs=true: