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