Docs: Remove a bunch of GTK+ references.
[metze/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifndef __FILE_H__
12 #define __FILE_H__
13
14 #include <errno.h>
15
16 #include <wiretap/wtap.h>
17 #include <epan/epan.h>
18 #include <epan/print.h>
19 #include <ui/packet_range.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24
25 /** Return values from functions that only can succeed or fail. */
26 typedef enum {
27     CF_OK,      /**< operation succeeded */
28     CF_ERROR    /**< operation got an error (function may provide err with details) */
29 } cf_status_t;
30
31 /** Return values from functions that read capture files. */
32 typedef enum {
33     CF_READ_OK,      /**< operation succeeded */
34     CF_READ_ERROR,   /**< operation got an error (function may provide err with details) */
35     CF_READ_ABORTED  /**< operation aborted by user */
36 } cf_read_status_t;
37
38 /** Return values from functions that write out packets. */
39 typedef enum {
40     CF_WRITE_OK,      /**< operation succeeded */
41     CF_WRITE_ERROR,   /**< operation got an error (function may provide err with details) */
42     CF_WRITE_ABORTED  /**< operation aborted by user */
43 } cf_write_status_t;
44
45 /** Return values from functions that print sets of packets. */
46 typedef enum {
47     CF_PRINT_OK,            /**< print operation succeeded */
48     CF_PRINT_OPEN_ERROR,    /**< print operation failed while opening printer */
49     CF_PRINT_WRITE_ERROR    /**< print operation failed while writing to the printer */
50 } cf_print_status_t;
51
52 typedef enum {
53     cf_cb_file_opened,
54     cf_cb_file_closing,
55     cf_cb_file_closed,
56     cf_cb_file_read_started,
57     cf_cb_file_read_finished,
58     cf_cb_file_reload_started,
59     cf_cb_file_reload_finished,
60     cf_cb_file_rescan_started,
61     cf_cb_file_rescan_finished,
62     cf_cb_file_retap_started,
63     cf_cb_file_retap_finished,
64     cf_cb_file_merge_started, /* Qt only */
65     cf_cb_file_merge_finished, /* Qt only */
66     cf_cb_file_fast_save_finished, /* GTK+ only? */
67     cf_cb_packet_selected, /* GTK+ only. */
68     cf_cb_packet_unselected, /* GTK+ only. */
69     cf_cb_field_unselected, /* GTK+ only. */
70     cf_cb_file_save_started,
71     cf_cb_file_save_finished,
72     cf_cb_file_save_failed,
73     cf_cb_file_save_stopped,
74     cf_cb_file_export_specified_packets_started, /* GTK+ only. */
75     cf_cb_file_export_specified_packets_finished, /* GTK+ only. */
76     cf_cb_file_export_specified_packets_failed, /* GTK+ only. */
77     cf_cb_file_export_specified_packets_stopped /* GTK+ only. */
78 } cf_cbs;
79
80 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
81
82 typedef struct {
83     const char    *string;
84     size_t         string_len;
85     capture_file  *cf;
86     gboolean       frame_matched;
87     field_info    *finfo;
88 } match_data;
89
90 /**
91  * Add a capture file event callback.
92  *
93  * @param func The function to be called for each event.
94  *             The function will be passed three parameters: The event type (event),
95  *             event-dependent data (data), and user-supplied data (user_data).
96  *             Event-dependent data may be a capture_file pointer, character pointer,
97  *             or NULL.
98  * @param user_data User-supplied data to pass to the callback. May be NULL.
99  */
100
101 extern void
102 cf_callback_add(cf_callback_t func, gpointer user_data);
103
104 /**
105  * Remove a capture file event callback.
106  *
107  * @param func The function to be removed.
108  * @param user_data User-supplied data. Must be the same value supplied to cf_callback_add.
109  */
110
111 extern void
112 cf_callback_remove(cf_callback_t func, gpointer user_data);
113
114 /**
115  * Open a capture file.
116  *
117  * @param cf the capture file to be opened
118  * @param fname the filename to be opened
119  * @param type WTAP_TYPE_AUTO for automatic or index to direct open routine
120  * @param is_tempfile is this a temporary file?
121  * @param err error code
122  * @return one of cf_status_t
123  */
124 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
125
126 /**
127  * Close a capture file.
128  *
129  * @param cf the capture file to be closed
130  */
131 void cf_close(capture_file *cf);
132
133 /**
134  * Reload a capture file.
135  *
136  * @param cf the capture file to be reloaded
137  */
138 void cf_reload(capture_file *cf);
139
140 /**
141  * Read all packets of a capture file into the internal structures.
142  *
143  * @param cf the capture file to be read
144  * @param from_save reread asked from cf_save_records
145  * @return one of cf_read_status_t
146  */
147 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
148
149 /**
150  * Read the metadata and raw data for a record.  It will pop
151  * up an alert box if there's an error.
152  *
153  * @param cf the capture file from which to read the record
154  * @param fdata the frame_data structure for the record in question
155  * @param rec pointer to a wtap_rec structure to contain the
156  * record's metadata
157  * @param buf a Buffer into which to read the record's raw data
158  * @return TRUE if the read succeeded, FALSE if there was an error
159  */
160 gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata,
161                           wtap_rec *rec, Buffer *buf);
162
163 /**
164  * Read the metadata and raw data for a record into a
165  * capture_file structure's phdr and buf members.
166  * It will pop up an alert box if there's an error.
167  *
168  * @param cf the capture file from which to read the record
169  * @param fdata the frame_data structure for the record in question
170  * @return TRUE if the read succeeded, FALSE if there was an error
171  */
172 gboolean cf_read_record(capture_file *cf, frame_data *fdata);
173
174 /**
175  * Read packets from the "end" of a capture file.
176  *
177  * @param cf the capture file to be read from
178  * @param to_read the number of packets to read
179  * @param err the error code, if an error had occurred
180  * @return one of cf_read_status_t
181  */
182 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
183
184 /**
185  * Fake reading packets from the "end" of a capture file.
186  *
187  * @param cf the capture file to be read from
188  */
189 void cf_fake_continue_tail(capture_file *cf);
190
191 /**
192  * Finish reading from "end" of a capture file.
193  *
194  * @param cf the capture file to be read from
195  * @param err the error code, if an error had occurred
196  * @return one of cf_read_status_t
197  */
198 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
199
200 /**
201  * Determine whether this capture file (or a range of it) can be written
202  * in any format using Wiretap rather than by copying the raw data.
203  *
204  * @param cf the capture file to check
205  * @return TRUE if it can be written, FALSE if it can't
206  */
207 gboolean cf_can_write_with_wiretap(capture_file *cf);
208
209 /**
210  * Determine whether this capture file can be saved with a "save" operation;
211  * if there's nothing unsaved, it can't.
212  *
213  * @param cf the capture file to check
214  * @return TRUE if it can be saved, FALSE if it can't
215  */
216 gboolean cf_can_save(capture_file *cf);
217
218 /**
219  * Determine whether this capture file can be saved with a "save as" operation.
220  *
221  * @param cf the capture file to check
222  * @return TRUE if it can be saved, FALSE if it can't
223  */
224 gboolean cf_can_save_as(capture_file *cf);
225
226 /**
227  * Determine whether this capture file has unsaved data.
228  *
229  * @param cf the capture file to check
230  * @return TRUE if it has unsaved data, FALSE if it doesn't
231  */
232 gboolean cf_has_unsaved_data(capture_file *cf);
233
234 /**
235  * Save all packets in a capture file to a new file, and, if that succeeds,
236  * make that file the current capture file.  If there's already a file with
237  * that name, do a "safe save", writing to a temporary file in the same
238  * directory and, if the write succeeds, renaming the new file on top of the
239  * old file, so that if the write fails, the old file is still intact.
240  *
241  * @param cf the capture file to save to
242  * @param fname the filename to save to
243  * @param save_format the format of the file to save (libpcap, ...)
244  * @param compressed whether to gzip compress the file
245  * @param discard_comments TRUE if we should discard comments if the save
246  * succeeds (because we saved in a format that doesn't support
247  * comments)
248  * @param dont_reopen TRUE if it shouldn't reopen and make that file the
249  * current capture file
250  * @return one of cf_write_status_t
251  */
252 cf_write_status_t cf_save_records(capture_file * cf, const char *fname,
253                                   guint save_format, gboolean compressed,
254                                   gboolean discard_comments,
255                                   gboolean dont_reopen);
256
257 /**
258  * Export some or all packets from a capture file to a new file.  If there's
259  * already a file with that name, do a "safe save", writing to a temporary
260  * file in the same directory and, if the write succeeds, renaming the new
261  * file on top of the old file, so that if the write fails, the old file is
262  * still intact.
263  *
264  * @param cf the capture file to write to
265  * @param fname the filename to write to
266  * @param range the range of packets to write
267  * @param save_format the format of the file to write (libpcap, ...)
268  * @param compressed whether to gzip compress the file
269  * @return one of cf_write_status_t
270  */
271 cf_write_status_t cf_export_specified_packets(capture_file *cf,
272                                               const char *fname,
273                                               packet_range_t *range,
274                                               guint save_format,
275                                               gboolean compressed);
276
277 /**
278  * Get a displayable name of the capture file.
279  *
280  * @param cf the capture file
281  * @return the displayable name (must be g_free'd)
282  */
283 gchar *cf_get_display_name(capture_file *cf);
284
285 /**
286  * Set the source of the capture data for temporary files, e.g.
287  * "Interface eth0" or "Pipe from Pong"
288  *
289  * @param cf the capture file
290  * @param source the source description. this will be copied internally.
291  */
292 void cf_set_tempfile_source(capture_file *cf, gchar *source);
293
294 /**
295  * Get the source of the capture data for temporary files. Guaranteed to
296  * return a non-null value. The returned value should not be freed.
297  *
298  * @param cf the capture file
299  */
300 const gchar *cf_get_tempfile_source(capture_file *cf);
301
302 /**
303  * Get the number of packets in the capture file.
304  *
305  * @param cf the capture file
306  * @return the number of packets in the capture file
307  */
308 int cf_get_packet_count(capture_file *cf);
309
310 /**
311  * Is this capture file a temporary file?
312  *
313  * @param cf the capture file
314  * @return TRUE if it's a temporary file, FALSE otherwise
315  */
316 gboolean cf_is_tempfile(capture_file *cf);
317
318 /**
319  * Set flag, that this file is a tempfile.
320  */
321 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
322
323 /**
324  * Set flag, if the number of packet drops while capturing are known or not.
325  *
326  * @param cf the capture file
327  * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
328  */
329 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
330
331 /**
332  * Set the number of packet drops while capturing.
333  *
334  * @param cf the capture file
335  * @param drops the number of packet drops occurred while capturing
336  */
337 void cf_set_drops(capture_file *cf, guint32 drops);
338
339 /**
340  * Get flag state, if the number of packet drops while capturing are known or not.
341  *
342  * @param cf the capture file
343  * @return TRUE if the number of packet drops are known, FALSE otherwise
344  */
345 gboolean cf_get_drops_known(capture_file *cf);
346
347 /**
348  * Get the number of packet drops while capturing.
349  *
350  * @param cf the capture file
351  * @return the number of packet drops occurred while capturing
352  */
353 guint32 cf_get_drops(capture_file *cf);
354
355 /**
356  * Set the read filter.
357  * @todo this shouldn't be required, remove it somehow
358  *
359  * @param cf the capture file
360  * @param rfcode the readfilter
361  */
362 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
363
364 /**
365  * "Display Filter" packets in the capture file.
366  *
367  * @param cf the capture file
368  * @param dfilter the display filter
369  * @param force TRUE if do in any case, FALSE only if dfilter changed
370  * @return one of cf_status_t
371  */
372 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
373
374 /**
375  * At least one "Refence Time" flag has changed, rescan all packets.
376  *
377  * @param cf the capture file
378  */
379 void cf_reftime_packets(capture_file *cf);
380
381 /**
382  * Return the time it took to load the file (in msec).
383  */
384 gulong cf_get_computed_elapsed(capture_file *cf);
385
386 /**
387  * "Something" has changed, rescan all packets.
388  *
389  * @param cf the capture file
390  */
391 void cf_redissect_packets(capture_file *cf);
392
393 /**
394  * Rescan all packets and just run taps - don't reconstruct the display.
395  *
396  * @param cf the capture file
397  * @return one of cf_read_status_t
398  */
399 cf_read_status_t cf_retap_packets(capture_file *cf);
400
401 /**
402  * Adjust timestamp precision if auto is selected.
403  *
404  * @param cf the capture file
405  */
406 void cf_timestamp_auto_precision(capture_file *cf);
407
408 /* print_range, enum which frames should be printed */
409 typedef enum {
410     print_range_selected_only,    /* selected frame(s) only (currently only one) */
411     print_range_marked_only,      /* marked frames only */
412     print_range_all_displayed,    /* all frames currently displayed */
413     print_range_all_captured      /* all frames in capture */
414 } print_range_e;
415
416 typedef struct {
417     print_stream_t *stream;       /* the stream to which we're printing */
418     print_format_e format;        /* plain text or PostScript */
419     gboolean to_file;             /* TRUE if we're printing to a file */
420     char *file;                   /* file output pathname */
421     char *cmd;                    /* print command string (not win32) */
422     packet_range_t range;
423
424     gboolean print_summary;       /* TRUE if we should print summary line. */
425     gboolean print_col_headings;  /* TRUE if we should print column headings */
426     print_dissections_e print_dissections;
427     gboolean print_hex;           /* TRUE if we should print hex data;
428                                    * FALSE if we should print only if not dissected. */
429     gboolean print_formfeed;      /* TRUE if a formfeed should be printed before
430                                    * each new packet */
431 } print_args_t;
432
433 /**
434  * Print the capture file.
435  *
436  * @param cf the capture file
437  * @param print_args the arguments what and how to print
438  * @param show_progress_bar TRUE if a progress bar is to be shown
439  * @return one of cf_print_status_t
440  */
441 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args,
442                                    gboolean show_progress_bar);
443
444 /**
445  * Print (export) the capture file into PDML format.
446  *
447  * @param cf the capture file
448  * @param print_args the arguments what and how to export
449  * @return one of cf_print_status_t
450  */
451 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
452
453 /**
454  * Print (export) the capture file into PSML format.
455  *
456  * @param cf the capture file
457  * @param print_args the arguments what and how to export
458  * @return one of cf_print_status_t
459  */
460 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
461
462 /**
463  * Print (export) the capture file into CSV format.
464  *
465  * @param cf the capture file
466  * @param print_args the arguments what and how to export
467  * @return one of cf_print_status_t
468  */
469 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
470
471 /**
472  * Print (export) the capture file into C Arrays format.
473  *
474  * @param cf the capture file
475  * @param print_args the arguments what and how to export
476  * @return one of cf_print_status_t
477  */
478 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
479
480 /**
481  * Print (export) the capture file into JSON format.
482  *
483  * @param cf the capture file
484  * @param print_args the arguments what and how to export
485  * @return one of cf_print_status_t
486  */
487 cf_print_status_t cf_write_json_packets(capture_file *cf, print_args_t *print_args);
488
489 /**
490  * Find packet with a protocol tree item that contains a specified text string.
491  *
492  * @param cf the capture file
493  * @param string the string to find
494  * @param dir direction in which to search
495  * @return TRUE if a packet was found, FALSE otherwise
496  */
497 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
498                                       search_direction dir);
499
500 /**
501  * Find field with a label that contains text string cfile->sfilter.
502  *
503  * @param cf the capture file
504  * @param tree the protocol tree
505  * @param mdata the first field (mdata->finfo) that matched the string
506  * @return TRUE if a packet was found, FALSE otherwise
507  */
508 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
509                                              match_data *mdata);
510
511 /**
512  * Find packet whose summary line contains a specified text string.
513  *
514  * @param cf the capture file
515  * @param string the string to find
516  * @param dir direction in which to search
517  * @return TRUE if a packet was found, FALSE otherwise
518  */
519 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
520                                      search_direction dir);
521
522 /**
523  * Find packet whose data contains a specified byte string.
524  *
525  * @param cf the capture file
526  * @param string the string to find
527  * @param string_size the size of the string to find
528  * @param dir direction in which to search
529  * @return TRUE if a packet was found, FALSE otherwise
530  */
531 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
532                              size_t string_size, search_direction dir);
533
534 /**
535  * Find packet that matches a compiled display filter.
536  *
537  * @param cf the capture file
538  * @param sfcode the display filter to match
539  * @param dir direction in which to search
540  * @return TRUE if a packet was found, FALSE otherwise
541  */
542 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
543                                 search_direction dir);
544
545 /**
546  * Find packet that matches a display filter given as a text string.
547  *
548  * @param cf the capture file
549  * @param filter the display filter to match
550  * @param dir direction in which to search
551  * @return TRUE if a packet was found, FALSE otherwise
552  */
553 gboolean
554 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
555                               search_direction dir);
556
557 /**
558  * Find marked packet.
559  *
560  * @param cf the capture file
561  * @param dir direction in which to search
562  * @return TRUE if a packet was found, FALSE otherwise
563  */
564 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
565
566 /**
567  * Find time-reference packet.
568  *
569  * @param cf the capture file
570  * @param dir direction in which to search
571  * @return TRUE if a packet was found, FALSE otherwise
572  */
573 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
574
575 /**
576  * GoTo Packet with the given row.
577  *
578  * @param cf the capture file
579  * @param row the row to go to
580  * @return TRUE if this row exists, FALSE otherwise
581  */
582 gboolean cf_goto_frame(capture_file *cf, guint row);
583
584 /**
585  * Go to frame specified by currently selected protocol tree field.
586  * (Go To Corresponding Packet)
587  * @todo this is ugly and should be improved!
588  *
589  * @param cf the capture file
590  * @return TRUE if this packet exists, FALSE otherwise
591  */
592 gboolean cf_goto_framenum(capture_file *cf);
593
594 /**
595  * Select the packet in the given row.
596  *
597  * @param cf the capture file
598  * @param row the row to select
599  */
600 void cf_select_packet(capture_file *cf, int row);
601
602 /**
603  * Unselect all packets, if any.
604  *
605  * @param cf the capture file
606  */
607 void cf_unselect_packet(capture_file *cf);
608
609 /**
610  * Unselect all protocol tree fields, if any.
611  *
612  * @param cf the capture file
613  */
614 void cf_unselect_field(capture_file *cf);
615
616 /**
617  * Mark a particular frame in a particular capture.
618  *
619  * @param cf the capture file
620  * @param frame the frame to be marked
621  */
622 void cf_mark_frame(capture_file *cf, frame_data *frame);
623
624 /**
625  * Unmark a particular frame in a particular capture.
626  *
627  * @param cf the capture file
628  * @param frame the frame to be unmarked
629  */
630 void cf_unmark_frame(capture_file *cf, frame_data *frame);
631
632 /**
633  * Ignore a particular frame in a particular capture.
634  *
635  * @param cf the capture file
636  * @param frame the frame to be ignored
637  */
638 void cf_ignore_frame(capture_file *cf, frame_data *frame);
639
640 /**
641  * Unignore a particular frame in a particular capture.
642  *
643  * @param cf the capture file
644  * @param frame the frame to be unignored
645  */
646 void cf_unignore_frame(capture_file *cf, frame_data *frame);
647
648 /**
649  * Merge two or more capture files into a temporary file.
650  * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
651  *
652  * @param pd_window Window pointer suitable for use by delayed_create_progress_dlg.
653  * @param out_filenamep Points to a pointer that's set to point to the
654  *        pathname of the temporary file; it's allocated with g_malloc()
655  * @param in_file_count the number of input files to merge
656  * @param in_filenames array of input filenames
657  * @param file_type the output filetype
658  * @param do_append FALSE to merge chronologically, TRUE simply append
659  * @return one of cf_status_t
660  */
661 cf_status_t
662 cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep,
663                            int in_file_count, char *const *in_filenames,
664                            int file_type, gboolean do_append);
665
666
667 /**
668  * Get the comment on a capture from the SHB data block
669  * XXX - should support multiple sections.
670  *
671  * @param cf the capture file
672  */
673 const gchar* cf_read_section_comment(capture_file *cf);
674
675 /**
676  * Update(replace) the comment on a capture from the SHB data block
677  * XXX - should support multiple sections.
678  *
679  * @param cf the capture file
680  * @param comment the string replacing the old comment
681  */
682 void cf_update_section_comment(capture_file *cf, gchar *comment);
683
684 /*
685  * Get the comment on a packet (record).
686  * If the comment has been edited, it returns the result of the edit,
687  * otherwise it returns the comment from the file.
688  *
689  * @param cf the capture file
690  * @param fd the frame_data structure for the frame
691  */
692 char *cf_get_packet_comment(capture_file *cf, const frame_data *fd);
693
694 /**
695  * Update(replace) the comment on a capture from a frame
696  *
697  * @param cf the capture file
698  * @param fd the frame_data structure for the frame
699  * @param new_comment the string replacing the old comment
700  */
701 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
702
703 /**
704  * What types of comments does this file have?
705  *
706  * @param cf the capture file
707  * @return bitset of WTAP_COMMENT_ values
708  */
709 guint32 cf_comment_types(capture_file *cf);
710
711 /**
712  * Add a resolved address to this file's list of resolved addresses.
713  *
714  * @param cf the capture file
715  * @param addr a string representing an IPv4 or IPv6 address
716  * @param name a string containing a name corresponding to that address
717  * @return TRUE if it succeeds, FALSE if not
718  */
719 gboolean cf_add_ip_name_from_string(capture_file *cf, const char *addr, const char *name);
720
721 #ifdef __cplusplus
722 }
723 #endif /* __cplusplus */
724
725 #endif /* file.h */
726
727 /*
728  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
729  *
730  * Local variables:
731  * c-basic-offset: 4
732  * tab-width: 8
733  * indent-tabs-mode: nil
734  * End:
735  *
736  * vi: set shiftwidth=4 tabstop=8 expandtab:
737  * :indentSize=4:tabSize=8:noTabs=true:
738  */