Wireshark  4.3.0
The Wireshark network protocol analyzer
wireshark_main_window.h
Go to the documentation of this file.
1 
10 #ifndef WIRESHARK_MAIN_WINDOW_H
11 #define WIRESHARK_MAIN_WINDOW_H
12 
39 #include <stdio.h>
40 
41 #include <config.h>
42 
43 #include <glib.h>
44 
45 #include "file.h"
46 
47 #include "ui/ws_ui_util.h"
48 #include "ui/iface_toolbar.h"
49 
50 #include <epan/plugin_if.h>
51 #include <epan/timestamp.h>
52 
53 #ifdef HAVE_LIBPCAP
54 #include "capture_opts.h"
55 #endif
57 
58 #include <QMainWindow>
59 #include <QPointer>
60 #include <QTextCodec>
61 
62 #ifdef _WIN32
63 # include <QTimer>
64 #else
65 # include <QSocketNotifier>
66 #endif
67 
68 #include "capture_file.h"
69 #include "capture_file_dialog.h"
73 #include "main_window.h"
74 #include "rtp_stream_dialog.h"
75 #include "rtp_analysis_dialog.h"
77 
78 class AccordionFrame;
79 class ByteViewTab;
80 class CaptureOptionsDialog;
81 class PrintDialog;
82 class FileSetDialog;
83 class FilterDialog;
84 class FunnelStatistics;
85 class WelcomePage;
87 class PacketDiagram;
88 class PacketList;
89 class ProtoTree;
90 #if defined(HAVE_LIBNL) && defined(HAVE_NL80211)
91 class WirelessFrame;
92 #endif
95 
96 class QAction;
97 class QActionGroup;
98 
99 namespace Ui {
100  class WiresharkMainWindow;
101 }
102 
103 Q_DECLARE_METATYPE(ts_type)
104 Q_DECLARE_METATYPE(ts_precision)
105 
107 {
108  Q_OBJECT
109 
110 public:
111  explicit WiresharkMainWindow(QWidget *parent = nullptr);
113 
114 #ifdef HAVE_LIBPCAP
115  capture_session *captureSession() { return &cap_session_; }
116  info_data_t *captureInfoData() { return &info_data_; }
117 #endif
118 
119  virtual QMenu *createPopupMenu();
120 
121  CaptureFile *captureFile() { return &capture_file_; }
122 
123  void removeAdditionalToolbar(QString toolbarName);
124 
125  void addInterfaceToolbar(const iface_toolbar *toolbar_entry);
126  void removeInterfaceToolbar(const gchar *menu_title);
127 
128  QString getMwFileName();
129  void setMwFileName(QString fileName);
130 
131 protected:
132  virtual bool eventFilter(QObject *obj, QEvent *event);
133  virtual bool event(QEvent *event);
134  virtual void keyPressEvent(QKeyEvent *event);
135  virtual void closeEvent(QCloseEvent *event);
136  virtual void dragEnterEvent(QDragEnterEvent *event);
137  virtual void dropEvent(QDropEvent *event);
138  virtual void changeEvent(QEvent* event);
139 
140 private:
141  // XXX Move to FilterUtils
142  enum MatchSelected {
143  MatchSelectedReplace,
144  MatchSelectedAnd,
145  MatchSelectedOr,
146  MatchSelectedNot,
147  MatchSelectedAndNot,
148  MatchSelectedOrNot
149  };
150 
151  enum FileCloseContext {
152  Default,
153  Quit,
154  Restart,
155  Reload,
156  Update
157  };
158 
159  Ui::WiresharkMainWindow *main_ui_;
160  CaptureFile capture_file_;
161  QFont mono_font_;
162  QMap<QString, QTextCodec *> text_codec_map_;
163 #if defined(HAVE_LIBNL) && defined(HAVE_NL80211)
164  WirelessFrame *wireless_frame_;
165 #endif
166  QWidget *previous_focus_;
167  FileSetDialog *file_set_dialog_;
168  QActionGroup *show_hide_actions_;
169  QActionGroup *time_display_actions_;
170  QActionGroup *time_precision_actions_;
171  FunnelStatistics *funnel_statistics_;
172  QList<QPair<QAction *, bool> > freeze_actions_;
173  QPointer<QWidget> freeze_focus_;
174  QMap<QAction *, ts_type> td_actions;
175  QMap<QAction *, ts_precision> tp_actions;
176  bool was_maximized_;
177 
178  /* the following values are maintained so that the capture file name and status
179  is available when there is no cf structure available */
180  QString mwFileName_;
181 
182  bool capture_stopping_;
183  bool capture_filter_valid_;
184  bool use_capturing_title_;
185 #ifdef HAVE_LIBPCAP
186  capture_session cap_session_;
187  CaptureOptionsDialog *capture_options_dialog_;
188  info_data_t info_data_;
189 #endif
190 
191 #if defined(Q_OS_MAC)
192  QMenu *dock_menu_;
193 #endif
194 
195 #ifdef HAVE_SOFTWARE_UPDATE
196  QAction *update_action_;
197 #endif
198 
199  QPoint dragStartPosition;
200 
201  QPointer<SSLKeylogDialog> sslkeylog_dialog_;
202 
203  void freeze();
204  void thaw();
205 
206  void mergeCaptureFile();
207  void importCaptureFile();
208  bool saveCaptureFile(capture_file *cf, bool dont_reopen);
209  bool saveAsCaptureFile(capture_file *cf, bool must_support_comments = false, bool dont_reopen = false);
210  void exportSelectedPackets();
211  void exportDissections(export_type_e export_type);
212 
213 #ifdef Q_OS_WIN
214  void fileAddExtension(QString &file_name, int file_type, wtap_compression_type compression_type);
215 #endif // Q_OS_WIN
216  bool testCaptureFileClose(QString before_what, FileCloseContext context = Default);
217  void captureStop();
218 
219  void findTextCodecs();
220 
221  void initMainToolbarIcons();
222  void initShowHideMainWidgets();
223  void initTimeDisplayFormatMenu();
224  void initTimePrecisionFormatMenu();
225  void initFreezeActions();
226 
227  void setTitlebarForCaptureInProgress();
228  void setMenusForCaptureFile(bool force_disable = false);
229  void setMenusForCaptureInProgress(bool capture_in_progress = false);
230  void setMenusForCaptureStopping();
231  void setForCapturedPackets(bool have_captured_packets);
232  void setMenusForFileSet(bool enable_list_files);
233  void setWindowIcon(const QIcon &icon);
234  QString replaceWindowTitleVariables(QString title);
235 
236  void externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, gint depth);
237 
238  void setForCaptureInProgress(bool capture_in_progress = false, bool handle_toolbars = false, GArray *ifaces = NULL);
239  QMenu* findOrAddMenu(QMenu *parent_menu, QString& menu_text);
240 
241  void captureFileReadStarted(const QString &action);
242 
243  void addMenuActions(QList<QAction *> &actions, int menu_group);
244  void removeMenuActions(QList<QAction *> &actions, int menu_group);
245  void goToConversationFrame(bool go_next);
246  void colorizeWithFilter(QByteArray filter, int color_number = -1);
247 
248 signals:
249  void setDissectedCaptureFile(capture_file *cf);
250  void closePacketDialogs();
251  void reloadFields();
252  void packetInfoChanged(struct _packet_info *pinfo);
253  void fieldFilterChanged(const QByteArray field_filter);
254 
255  void fieldHighlight(FieldInformation *);
256 
257  void captureActive(int);
258  void selectRtpStream(rtpstream_id_t *id);
259  void deselectRtpStream(rtpstream_id_t *id);
260 
261 #ifdef HAVE_LIBPCAP
262  void showExtcapOptions(QString &device_name, bool startCaptureOnClose);
263 #endif
264 
265 public slots:
266  // in main_window_slots.cpp
275  // XXX We might want to return a cf_read_status_t or a CaptureFile.
276  bool openCaptureFile(QString cf_path, QString display_filter, unsigned int type, gboolean is_tempfile = FALSE);
277  bool openCaptureFile(QString cf_path = QString(), QString display_filter = QString()) { return openCaptureFile(cf_path, display_filter, WTAP_TYPE_AUTO); }
278  void filterPackets(QString new_filter = QString(), bool force = false);
279  void updateForUnsavedChanges();
280  void layoutToolbars();
281  void updatePreferenceActions();
282  void updateRecentActions();
283 
284  void setTitlebarForCaptureFile();
285  void setWSWindowTitle(QString title = QString());
286 
287  void showCaptureOptionsDialog();
288 
289 #ifdef HAVE_LIBPCAP
290  void captureCapturePrepared(capture_session *);
291  void captureCaptureUpdateStarted(capture_session *);
292  void captureCaptureUpdateFinished(capture_session *);
293  void captureCaptureFixedFinished(capture_session *cap_session);
294  void captureCaptureFailed(capture_session *);
295 #endif
296 
297  void captureFileOpened();
298  void captureFileReadFinished();
299  void captureFileClosing();
300  void captureFileClosed();
301 
302  void launchRLCGraph(bool channelKnown, guint16 ueid, guint8 rlcMode,
303  guint16 channelType, guint16 channelId, guint8 direction);
304 
305  void rtpPlayerDialogReplaceRtpStreams(QVector<rtpstream_id_t *> stream_ids);
306  void rtpPlayerDialogAddRtpStreams(QVector<rtpstream_id_t *> stream_ids);
307  void rtpPlayerDialogRemoveRtpStreams(QVector<rtpstream_id_t *> stream_ids);
308  void rtpAnalysisDialogReplaceRtpStreams(QVector<rtpstream_id_t *> stream_ids);
309  void rtpAnalysisDialogAddRtpStreams(QVector<rtpstream_id_t *> stream_ids);
310  void rtpAnalysisDialogRemoveRtpStreams(QVector<rtpstream_id_t *> stream_ids);
311  void rtpStreamsDialogSelectRtpStreams(QVector<rtpstream_id_t *> stream_ids);
312  void rtpStreamsDialogDeselectRtpStreams(QVector<rtpstream_id_t *> stream_ids);
313 
314 private slots:
315 
316  void captureEventHandler(CaptureEvent ev);
317 
318  // Manually connected slots (no "on_<object>_<signal>").
319 
320  void initViewColorizeMenu();
321  void initConversationMenus();
322  static bool addExportObjectsMenuItem(const void *key, void *value, void *userdata);
323  void initExportObjectsMenus();
324  static bool addFollowStreamMenuItem(const void *key, void *value, void *userdata);
325  void initFollowStreamMenus();
326 
327  // in main_window_slots.cpp
333  void startCapture(QStringList);
334  void startCapture();
335  void popLiveCaptureInProgress();
336  void stopCapture();
337 
338  void loadWindowGeometry();
339  void saveWindowGeometry();
340  void mainStackChanged(int);
341  void updateRecentCaptures();
342  void recentActionTriggered();
343  void addPacketComment();
344  void editPacketComment();
345  void deletePacketComment();
346  void deleteCommentsFromPackets();
347  QString commentToMenuText(QString text, int max_len = 40);
348  void setEditCommentsMenu();
349  void setMenusForSelectedPacket();
350  void setMenusForSelectedTreeRow(FieldInformation *fi = NULL);
351  void interfaceSelectionChanged();
352  void captureFilterSyntaxChanged(bool valid);
353  void redissectPackets();
354  void checkDisplayFilter();
355  void fieldsChanged();
356  void reloadLuaPlugins();
357  void showAccordionFrame(AccordionFrame *show_frame, bool toggle = false);
358  void showColumnEditor(int column);
359  void showPreferenceEditor(); // module_t *, pref *
360  void addStatsPluginsToMenu();
361  void addDynamicMenus();
362  void reloadDynamicMenus();
363  void addPluginIFStructures();
364  QMenu * searchSubMenu(QString objectName);
365  void activatePluginIFToolbar(bool);
366  void updateTitlebar();
367 
368  void startInterfaceCapture(bool valid, const QString capture_filter);
369 
370  void applyGlobalCommandLineOptions();
371  void setFeaturesEnabled(bool enabled = true);
372 
373  void on_actionNewDisplayFilterExpression_triggered();
374  void onFilterSelected(QString, bool);
375  void onFilterPreferences();
376  void onFilterEdit(int uatIndex);
377 
378  // Handle FilterAction signals
379  void queuedFilterAction(QString filter, FilterAction::Action action, FilterAction::ActionType type);
380 
386  void openStatCommandDialog(const QString &menu_path, const char *arg, void *userdata);
387 
393  void openTapParameterDialog(const QString cfg_str, const QString arg, void *userdata);
394  void openTapParameterDialog();
395 
396 #if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
397  void softwareUpdateRequested();
398 #endif
399 
400  // Automatically connected slots ("on_<object>_<signal>").
401  //
402  // The slots below follow the naming conventaion described in
403  // https://doc.qt.io/archives/qt-4.8/qmetaobject.html#connectSlotsByName
404  // and are automatically connected at initialization time via
405  // main_ui_->setupUi, which in turn calls connectSlotsByName.
406  //
407  // If you're manually connecting a signal to a slot, don't prefix its name
408  // with "on_". Otherwise you'll get runtime warnings.
409 
410  // We might want move these to main_window_actions.cpp similar to
411  // gtk/main_menubar.c
412 
413  void connectFileMenuActions();
414  void exportPacketBytes();
415  void exportPDU();
416  void stripPacketHeaders();
417  void exportTLSSessionKeys();
418  void printFile();
419 
420  void connectEditMenuActions();
421  void copySelectedItems(WiresharkMainWindow::CopySelected selection_type);
422  void findPacket();
423  void editTimeShift();
424  void editConfigurationProfiles();
425  void editTimeShiftFinished(int);
426  void addPacketCommentFinished(PacketCommentDialog* pc_dialog, int result);
427  void editPacketCommentFinished(PacketCommentDialog* pc_dialog, int result, guint nComment);
428  void deleteAllPacketComments();
429  void deleteAllPacketCommentsFinished(int result);
430  void injectSecrets();
431  void discardAllSecrets();
432  void discardAllSecretsFinished(int result);
433  void showPreferencesDialog(QString module_name);
434 
435  void connectViewMenuActions();
436  void showHideMainWidgets(QAction *action);
437  void setTimestampFormat(QAction *action);
438  void setTimestampPrecision(QAction *action);
439  void setTimeDisplaySecondsWithHoursAndMinutes(bool checked);
440  void editResolvedName();
441  void setNameResolution();
442  void zoomText();
443  void showColoringRulesDialog();
444  void colorizeConversation(bool create_rule = false);
445  void colorizeActionTriggered();
446  void openPacketDialog(bool from_reference = false);
447  void reloadCaptureFileAsFormatOrCapture();
448  void reloadCaptureFile();
449 
450  void connectGoMenuActions();
451 
452  void resetPreviousFocus();
453 
454  void connectCaptureMenuActions();
455  void startCaptureTriggered();
456 
457  void connectAnalyzeMenuActions();
458 
459  void matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type);
460  void applyFieldAsColumn();
461 
462  void filterMenuAboutToShow();
463 
464  void applyConversationFilter();
465  void applyExportObject();
466 
467  void openFollowStreamDialog(int proto_id, guint stream_num, guint sub_stream_num, bool use_stream_index = true);
468  void openFollowStreamDialog(int proto_id);
469 
470  void statCommandExpertInfo(const char *, void *);
471 
472  void connectHelpMenuActions();
473 
474 #ifdef HAVE_SOFTWARE_UPDATE
475  void checkForUpdates();
476 #endif
477 
478  void goToCancelClicked();
479  void goToGoClicked();
480  void goToLineEditReturnPressed();
481 
482  void connectStatisticsMenuActions();
483 
484  void showResolvedAddressesDialog();
485  void showConversationsDialog();
486  void showEndpointsDialog();
487 
488  void openTcpStreamDialog(int graph_type);
489  void openSCTPAllAssocsDialog();
490  void on_actionSCTPShowAllAssociations_triggered();
491  void on_actionSCTPAnalyseThisAssociation_triggered();
492  void on_actionSCTPFilterThisAssociation_triggered();
493  void statCommandMulticastStatistics(const char *arg, void *);
494 
495  void statCommandWlanStatistics(const char *arg, void *);
496 
497  void openStatisticsTreeDialog(const gchar *abbr);
498  void statCommandIOGraph(const char *, void *);
499 
500  void connectTelephonyMenuActions();
501 
502  RtpStreamDialog *openTelephonyRtpStreamsDialog();
503  RtpPlayerDialog *openTelephonyRtpPlayerDialog();
504  RtpAnalysisDialog *openTelephonyRtpAnalysisDialog();
505  void statCommandLteMacStatistics(const char *arg, void *);
506  void statCommandLteRlcStatistics(const char *arg, void *);
507  void openRtpStreamAnalysisDialog();
508  void openRtpPlayerDialog();
509 
510  void connectWirelessMenuActions();
511 
512  void connectToolsMenuActions();
513 
514  void externalMenuItemTriggered();
515 
516  void on_actionContextWikiProtocolPage_triggered();
517  void on_actionContextFilterFieldReference_triggered();
518 
519  void extcap_options_finished(int result);
520  void showExtcapOptionsDialog(QString & device_name, bool startCaptureOnClose);
521 
522  QString findRtpStreams(QVector<rtpstream_id_t *> *stream_ids, bool reverse);
523 
524  void openBrowserKeylogDialog();
525 
526  friend class MainApplication;
527 };
528 
529 #endif // WIRESHARK_MAIN_WINDOW_H
Definition: accordion_frame.h:18
Definition: byte_view_tab.h:29
Definition: capture_event.h:20
Definition: capture_file.h:23
Definition: field_information.h:23
Definition: file_set_dialog.h:31
Definition: filter_dialog.h:28
Definition: filter_expression_toolbar.h:20
Definition: funnel_statistics.h:32
Definition: main_application.h:51
Definition: main_window.h:40
Definition: packet_comment_dialog.h:22
Definition: packet_diagram.h:26
Definition: packet_list.h:39
Definition: print_dialog.h:29
Definition: proto_tree.h:29
Definition: rtp_analysis_dialog.h:63
Definition: rtp_player_dialog.h:68
Definition: rtp_stream_dialog.h:29
Definition: welcome_page.h:27
Definition: wireless_frame.h:22
Definition: wireshark_application.h:16
Definition: wireshark_main_window.h:107
bool openCaptureFile(QString cf_path, QString display_filter, unsigned int type, gboolean is_tempfile=FALSE)
Definition: wireshark_main_window_slots.cpp:191
Definition: cfile.h:67
Definition: capture_session.h:137
Definition: plugin_if.h:55
Definition: iface_toolbar.h:57
Definition: capture_info.h:40
Definition: packet_info.h:44
Definition: rtp_stream_id.h:33