various capture code cleanup and fixes:
[obnox/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __FILE_H__
26 #define __FILE_H__
27
28 #include "packet-range.h"
29 #include "wiretap/wtap.h"
30 #include <epan/dfilter/dfilter.h>
31 #include "print.h"
32 #include <errno.h>
33 #include <epan/epan.h>
34
35 #include "cfile.h"
36
37
38 /** Return values from functions that only can succeed or fail. */
39 typedef enum {
40         CF_OK,                      /**< operation succeeded */
41         CF_ERROR        /**< operation got an error (function may provide err with details) */
42 } cf_status_t;
43
44 /** Return values from functions that read capture files. */
45 typedef enum {
46         CF_READ_OK,             /**< operation succeeded */
47         CF_READ_ERROR,          /**< operation got an error (function may provide err with details) */
48         CF_READ_ABORTED         /**< operation aborted by user */
49 } cf_read_status_t;
50
51 /** Return values from functions that print sets of packets. */
52 typedef enum {
53         CF_PRINT_OK,                /**< print operation succeeded */
54         CF_PRINT_OPEN_ERROR,    /**< print operation failed while opening printer */
55         CF_PRINT_WRITE_ERROR    /**< print operation failed while writing to the printer */
56 } cf_print_status_t;
57
58 typedef enum {
59     cf_cb_file_closed,
60     cf_cb_file_read_start,
61     cf_cb_file_read_finished,
62 #ifdef HAVE_LIBPCAP
63     cf_cb_live_capture_update_started,
64     cf_cb_live_capture_fixed_started,
65     cf_cb_live_capture_update_finished,
66     cf_cb_live_capture_fixed_finished,
67 #endif
68     cf_cb_packet_selected,
69     cf_cb_packet_unselected,
70     cf_cb_field_unselected,
71     cf_cb_file_safe_started,
72     cf_cb_file_safe_finished,
73     cf_cb_file_safe_reload_finished,
74     cf_cb_file_safe_failed
75 } cf_cbs;
76
77 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
78
79 extern void
80 cf_callback_invoke(int event, gpointer data);
81
82 extern void
83 cf_callback_add(cf_callback_t func, gpointer user_data);
84
85 extern void
86 cf_callback_remove(cf_callback_t func);
87
88 /**
89  * Open a capture file.
90  *
91  * @param cf the capture file to be opened
92  * @param fname the filename to be opened
93  * @param is_tempfile is this a temporary file?
94  * @return one of cf_status_t
95  */
96 cf_status_t cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
97
98 /**
99  * Close a capture file.
100  *
101  * @param cf the capture file to be closed
102  */
103 void cf_close(capture_file *cf);
104
105 /**
106  * Reload a capture file.
107  *
108  * @param cf the capture file to be reloaded
109  */
110 void cf_reload(capture_file *cf);
111
112 /**
113  * Read all packets of a capture file into the internal structures.
114  * 
115  * @param cf the capture file to be read
116  * @return one of cf_read_status_t
117  */
118 cf_read_status_t cf_read(capture_file *cf);
119
120 /**
121  * Start reading from the end of a capture file.
122  * This is used in "Update list of packets in Real-Time".
123  * 
124  * @param cf the capture file to be read from
125  * @param fname the filename to be read from
126  * @param is_tempfile is this a temporary file?
127  * @param err the error code, if an error had occured
128  * @return one of cf_status_t
129  */
130 cf_status_t cf_start_tail(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
131
132 /**
133  * Read packets from the "end" of a capture file.
134  * 
135  * @param cf the capture file to be read from
136  * @param to_read the number of packets to read
137  * @param err the error code, if an error had occured
138  * @return one of cf_read_status_t
139  */
140 cf_read_status_t cf_continue_tail(capture_file *cf, int to_read, int *err);
141
142 /**
143  * Finish reading from "end" of a capture file.
144  * 
145  * @param cf the capture file to be read from
146  * @param err the error code, if an error had occured
147  * @return one of cf_read_status_t
148  */
149 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
150
151 /**
152  * Save a capture file (or a range of it).
153  * 
154  * @param cf the capture file to save to
155  * @param fname the filename to save to
156  * @param range the range of packets to save
157  * @param save_format the format of the file to save (libpcap, ...)
158  * @return one of cf_status_t
159  */
160 cf_status_t cf_save(capture_file * cf, const char *fname, packet_range_t *range, guint save_format);
161
162 /**
163  * Get a displayable name of the capture file.
164  * 
165  * @param cf the capture file
166  * @return the displayable name (don't have to be g_free'd)
167  */
168 const gchar *cf_get_display_name(capture_file *cf);
169
170 /**
171  * Get the number of packets in the capture file.
172  * 
173  * @param cf the capture file
174  * @return the number of packets in the capture file
175  */
176 int cf_packet_count(capture_file *cf);
177
178 /**
179  * Is this capture file a temporary file?
180  * 
181  * @param cf the capture file
182  * @return TRUE if it's a temporary file, FALSE otherwise
183  */
184 gboolean cf_is_tempfile(capture_file *cf);
185
186 /**
187  * Set flag, that this file is a tempfile.
188  */
189 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
190
191 /**
192  * Set flag, if the number of packet drops while capturing are known or not.
193  * 
194  * @param cf the capture file
195  * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
196  */
197 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
198
199 /**
200  * Set the number of packet drops while capturing.
201  * 
202  * @param cf the capture file
203  * @param drops the number of packet drops occured while capturing
204  */
205 void cf_set_drops(capture_file *cf, guint32 drops);
206
207 /**
208  * Get flag state, if the number of packet drops while capturing are known or not.
209  * 
210  * @param cf the capture file
211  * @return TRUE if the number of packet drops are known, FALSE otherwise
212  */
213 gboolean cf_get_drops_known(capture_file *cf);
214
215 /**
216  * Get the number of packet drops while capturing.
217  * 
218  * @param cf the capture file
219  * @return the number of packet drops occured while capturing
220  */
221 guint32 cf_get_drops(capture_file *cf);
222
223 /**
224  * Set the read filter.
225  * @todo this shouldn't be required, remove it somehow
226  * 
227  * @param cf the capture file
228  * @param rfcode the readfilter
229  */
230 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
231
232 /**
233  * "Display Filter" packets in the capture file.
234  * 
235  * @param cf the capture file
236  * @param dfilter the display filter
237  * @param force TRUE if do in any case, FALSE only if dfilter changed
238  * @return one of cf_status_t
239  */
240 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
241
242 /**
243  * At least one "Refence Time" flag has changed, rescan all packets.
244  * 
245  * @param cf the capture file
246  */
247 void cf_reftime_packets(capture_file *cf);
248
249 /**
250  * At least one "Refence Time" flag has changed, rescan all packets.
251  * 
252  * @param cf the capture file
253  */
254 void cf_colorize_packets(capture_file *cf);
255
256 /**
257  * "Something" has changed, rescan all packets.
258  * 
259  * @param cf the capture file
260  */
261 void cf_redissect_packets(capture_file *cf);
262
263 /**
264  * Rescan all packets and just run taps - don't reconstruct the display.
265  * 
266  * @param cf the capture file
267  * @return one of cf_read_status_t
268  */
269 cf_read_status_t cf_retap_packets(capture_file *cf);
270
271 /**
272  * The time format has changed, rescan all packets.
273  * 
274  * @param cf the capture file
275  */
276 void cf_change_time_formats(capture_file *cf);
277
278 /**
279  * Print the capture file.
280  * 
281  * @param cf the capture file
282  * @param print_args the arguments what and how to print
283  * @return one of cf_print_status_t
284  */
285 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
286
287 /**
288  * Print (export) the capture file into PDML format.
289  * 
290  * @param cf the capture file
291  * @param print_args the arguments what and how to export
292  * @return one of cf_print_status_t
293  */
294 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
295
296 /**
297  * Print (export) the capture file into PSML format.
298  * 
299  * @param cf the capture file
300  * @param print_args the arguments what and how to export
301  * @return one of cf_print_status_t
302  */
303 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
304
305 /**
306  * Print (export) the capture file into CSV format.
307  *
308  * @param cf the capture file
309  * @param print_args the arguments what and how to export
310  * @return one of cf_print_status_t
311  */
312 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
313
314 /**
315  * Find Packet in protocol tree.
316  * 
317  * @param cf the capture file
318  * @param string the string to find
319  * @return TRUE if a packet was found, FALSE otherwise
320  */
321 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string);
322
323 /**
324  * Find Packet in summary line.
325  * 
326  * @param cf the capture file
327  * @param string the string to find
328  * @return TRUE if a packet was found, FALSE otherwise
329  */
330 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string);
331
332 /**
333  * Find Packet in packet data.
334  * 
335  * @param cf the capture file
336  * @param string the string to find
337  * @param string_size the size of the string to find
338  * @return TRUE if a packet was found, FALSE otherwise
339  */
340 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
341                           size_t string_size);
342
343 /**
344  * Find Packet by display filter.
345  * 
346  * @param cf the capture file
347  * @param sfcode the display filter to find a packet for
348  * @return TRUE if a packet was found, FALSE otherwise
349  */
350 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode);
351
352 /**
353  * GoTo Packet in first row.
354  * 
355  * @param cf the capture file
356  * @return TRUE if the first row exists, FALSE otherwise
357  */
358 gboolean cf_goto_top_frame(capture_file *cf);
359
360 /**
361  * GoTo Packet in last row.
362  * 
363  * @param cf the capture file
364  * @return TRUE if last row exists, FALSE otherwise
365  */
366 gboolean cf_goto_bottom_frame(capture_file *cf);
367
368 /**
369  * GoTo Packet with the given row.
370  * 
371  * @param cf the capture file
372  * @param row the row to go to
373  * @return TRUE if this row exists, FALSE otherwise
374  */
375 gboolean cf_goto_frame(capture_file *cf, guint row);
376
377 /**
378  * Go to frame specified by currently selected protocol tree field.
379  * (Go To Corresponding Packet)
380  * @todo this is ugly and should be improved!
381  *
382  * @param cf the capture file
383  * @return TRUE if this packet exists, FALSE otherwise
384  */
385 gboolean cf_goto_framenum(capture_file *cf);
386
387 /**
388  * Select the packet in the given row.
389  *
390  * @param cf the capture file
391  * @param row the row to select
392  */
393 void cf_select_packet(capture_file *cf, int row);
394
395 /**
396  * Unselect all packets, if any.
397  *
398  * @param cf the capture file
399  * @param row the row to select
400  */
401 void cf_unselect_packet(capture_file *cf);
402
403 /**
404  * Unselect all protocol tree fields, if any.
405  *
406  * @param cf the capture file
407  * @param row the row to select
408  */
409 void cf_unselect_field(capture_file *cf);
410
411 /**
412  * Mark a particular frame in a particular capture.
413  *
414  * @param cf the capture file
415  * @param frame the frame to be marked
416  */
417 void cf_mark_frame(capture_file *cf, frame_data *frame);
418
419 /**
420  * Unmark a particular frame in a particular capture.
421  *
422  * @param cf the capture file
423  * @param frame the frame to be unmarked
424  */
425 void cf_unmark_frame(capture_file *cf, frame_data *frame);
426
427 /**
428  * Convert error number and info to a complete message.
429  *
430  * @param err the error number
431  * @param err_info the additional info about this error (e.g. filename)
432  * @return statically allocated error message
433  */
434 char *cf_read_error_message(int err, const gchar *err_info);
435
436 /**
437  * Merge two (or more) capture files into one.
438  * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
439  *
440  * @param out_filename pointer to output filename; if output filename is
441  * NULL, a temporary file name is generated and *out_filename is set
442  * to point to the generated file name
443  * @param in_file_count the number of input files to merge
444  * @param in_filnames array of input filenames
445  * @param file_type the output filetype
446  * @param do_append FALSE to merge chronologically, TRUE simply append
447  * @return one of cf_status_t
448  */
449 cf_status_t
450 cf_merge_files(char **out_filename, int in_file_count,
451                char *const *in_filenames, int file_type, gboolean do_append);
452
453 #endif /* file.h */