Put "cf_status_t" back.
[jlayton/wireshark.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 /** Return values from functions that read capture files. */
38 typedef enum {
39         CF_OK,          /**< operation succeeded */
40         CF_ERROR        /**< operation got an error (function may provide err with details) */
41 } cf_status_t;
42
43 typedef enum {
44         CF_READ_OK,             /**< operation succeeded */
45         CF_READ_ERROR,          /**< operation got an error (function may provide err with details) */
46         CF_READ_ABORTED         /**< operation aborted by user */
47 } cf_read_status_t;
48
49 /** Return values from functions that print sets of packets. */
50 typedef enum {
51         CF_PRINT_OK,            /**< operation succeeded */
52         CF_PRINT_OPEN_ERROR,    /**< print operation failed while opening printer */
53         CF_PRINT_WRITE_ERROR    /**< print operation failed while writing to the printer */
54 } cf_print_status_t;
55
56 /**
57  * Open a capture file.
58  *
59  * @param cf the capture file to be opened
60  * @param fname the filename to be opened
61  * @param is_tempfile is this a temporary file?
62  * @return one of cf_status_t
63  */
64 cf_status_t cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
65
66 /**
67  * Close a capture file.
68  *
69  * @param cf the capture file to be closed
70  */
71 void cf_close(capture_file *cf);
72
73 /**
74  * Reload a capture file.
75  *
76  * @param cf the capture file to be reloaded
77  */
78 void cf_reload(capture_file *cf);
79
80 /**
81  * Read all packets of a capture file into the internal structures.
82  * 
83  * @param cf the capture file to be read
84  * @return one of cf_read_status_t
85  */
86 cf_read_status_t cf_read(capture_file *cf);
87
88 /**
89  * Start reading from the end of a capture file.
90  * This is used in "Update list of packets in Real-Time".
91  * 
92  * @param cf the capture file to be read from
93  * @param fname the filename to be read from
94  * @param is_tempfile is this a temporary file?
95  * @param err the error code, if an error had occured
96  * @return one of cf_status_t
97  */
98 cf_status_t cf_start_tail(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
99
100 /**
101  * Read packets from the "end" of a capture file.
102  * 
103  * @param cf the capture file to be read from
104  * @param to_read the number of packets to read
105  * @param err the error code, if an error had occured
106  * @return one of cf_read_status_t
107  */
108 cf_read_status_t cf_continue_tail(capture_file *cf, int to_read, int *err);
109
110 /**
111  * Finish reading from "end" of a capture file.
112  * 
113  * @param cf the capture file to be read from
114  * @param err the error code, if an error had occured
115  * @return one of cf_read_status_t
116  */
117 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
118
119 /**
120  * Save a capture file (or a range of it).
121  * 
122  * @param cf the capture file to save to
123  * @param fname the filename to save to
124  * @param range the range of packets to save
125  * @param save_format the format of the file to save (libpcap, ...)
126  * @return one of cf_status_t
127  */
128 cf_status_t cf_save(capture_file * cf, const char *fname, packet_range_t *range, guint save_format);
129
130 /**
131  * Get a displayable name of the capture file.
132  * 
133  * @param cf the capture file
134  * @return the displayable name (don't have to be g_free'd)
135  */
136 const gchar *cf_get_display_name(capture_file *cf);
137
138 /**
139  * Get the number of packets in the capture file.
140  * 
141  * @param cf the capture file
142  * @return the number of packets in the capture file
143  */
144 int cf_packet_count(capture_file *cf);
145
146 /**
147  * Is this capture file a temporary file?
148  * 
149  * @param cf the capture file
150  * @return TRUE if it's a temporary file, FALSE otherwise
151  */
152 gboolean cf_is_tempfile(capture_file *cf);
153
154 /**
155  * Get the interface name to capture from.
156  * 
157  * @param cf the capture file
158  * @return the interface name (don't have to be g_free'd)
159  */
160 gchar *cf_get_iface(capture_file *cf);
161
162 /**
163  * Get the capture filter of this capture file.
164  * 
165  * @param cf the capture file
166  * @return the capture filter (don't have to be g_free'd)
167  */
168 gchar *cf_get_cfilter(capture_file *cf);
169
170 /**
171  * Set flag, if the number of packet drops while capturing are known or not.
172  * 
173  * @param cf the capture file
174  * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
175  */
176 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
177
178 /**
179  * Set the number of packet drops while capturing.
180  * 
181  * @param cf the capture file
182  * @param drops the number of packet drops occured while capturing
183  */
184 void cf_set_drops(capture_file *cf, guint32 drops);
185
186 /**
187  * Set the read filter.
188  * @todo this shouldn't be required, remove it somehow
189  * 
190  * @param cf the capture file
191  * @param rfcode the readfilter
192  */
193 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
194
195 /**
196  * "Display Filter" packets in the capture file.
197  * 
198  * @param cf the capture file
199  * @param dfilter the display filter
200  * @param force TRUE if do in any case, FALSE only if dfilter changed
201  * @return one of cf_status_t
202  */
203 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
204
205 /**
206  * At least one "Refence Time" flag has changed, rescan all packets.
207  * 
208  * @param cf the capture file
209  */
210 void cf_reftime_packets(capture_file *cf);
211
212 /**
213  * At least one "Refence Time" flag has changed, rescan all packets.
214  * 
215  * @param cf the capture file
216  */
217 void cf_colorize_packets(capture_file *cf);
218
219 /**
220  * "Something" has changed, rescan all packets.
221  * 
222  * @param cf the capture file
223  */
224 void cf_redissect_packets(capture_file *cf);
225
226 /**
227  * Rescan all packets and just run taps - don't reconstruct the display.
228  * 
229  * @param cf the capture file
230  * @return one of cf_read_status_t
231  */
232 cf_read_status_t cf_retap_packets(capture_file *cf);
233
234 /**
235  * The time format has changed, rescan all packets.
236  * 
237  * @param cf the capture file
238  */
239 void cf_change_time_formats(capture_file *cf);
240
241 /**
242  * Print the capture file.
243  * 
244  * @param cf the capture file
245  * @param print_args the arguments what and how to print
246  * @return one of cf_print_status_t
247  */
248 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
249
250 /**
251  * Print (export) the capture file into PDML format.
252  * 
253  * @param cf the capture file
254  * @param print_args the arguments what and how to export
255  * @return one of cf_print_status_t
256  */
257 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
258
259 /**
260  * Print (export) the capture file into PSML format.
261  * 
262  * @param cf the capture file
263  * @param print_args the arguments what and how to export
264  * @return one of cf_print_status_t
265  */
266 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
267
268 /**
269  * Find Packet in protocol tree.
270  * 
271  * @param cf the capture file
272  * @param string the string to find
273  * @return TRUE if a packet was found, FALSE otherwise
274  */
275 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string);
276
277 /**
278  * Find Packet in summary line.
279  * 
280  * @param cf the capture file
281  * @param string the string to find
282  * @return TRUE if a packet was found, FALSE otherwise
283  */
284 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string);
285
286 /**
287  * Find Packet in packet data.
288  * 
289  * @param cf the capture file
290  * @param string the string to find
291  * @param string_size the size of the string to find
292  * @return TRUE if a packet was found, FALSE otherwise
293  */
294 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
295                           size_t string_size);
296
297 /**
298  * Find Packet by display filter.
299  * 
300  * @param cf the capture file
301  * @param sfcode the display filter to find a packet for
302  * @return TRUE if a packet was found, FALSE otherwise
303  */
304 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode);
305
306 /**
307  * GoTo Packet in first row.
308  * 
309  * @param cf the capture file
310  * @return TRUE if the first row exists, FALSE otherwise
311  */
312 gboolean cf_goto_top_frame(capture_file *cf);
313
314 /**
315  * GoTo Packet in last row.
316  * 
317  * @param cf the capture file
318  * @return TRUE if last row exists, FALSE otherwise
319  */
320 gboolean cf_goto_bottom_frame(capture_file *cf);
321
322 /**
323  * GoTo Packet with the given row.
324  * 
325  * @param cf the capture file
326  * @param row the row to go to
327  * @return TRUE if this row exists, FALSE otherwise
328  */
329 gboolean cf_goto_frame(capture_file *cf, guint row);
330
331 /**
332  * Go to frame specified by currently selected protocol tree field.
333  * (Go To Corresponding Packet)
334  * @todo this is ugly and should be improved!
335  *
336  * @param cf the capture file
337  * @return TRUE if this packet exists, FALSE otherwise
338  */
339 gboolean cf_goto_framenum(capture_file *cf);
340
341 /**
342  * Select the packet in the given row.
343  *
344  * @param cf the capture file
345  * @param row the row to select
346  */
347 void cf_select_packet(capture_file *cf, int row);
348
349 /**
350  * Unselect all packets, if any.
351  *
352  * @param cf the capture file
353  * @param row the row to select
354  */
355 void cf_unselect_packet(capture_file *cf);
356
357 /**
358  * Unselect all protocol tree fields, if any.
359  *
360  * @param cf the capture file
361  * @param row the row to select
362  */
363 void cf_unselect_field(capture_file *cf);
364
365 /**
366  * Mark a particular frame in a particular capture.
367  *
368  * @param cf the capture file
369  * @param frame the frame to be marked
370  */
371 void cf_mark_frame(capture_file *cf, frame_data *frame);
372
373 /**
374  * Unmark a particular frame in a particular capture.
375  *
376  * @param cf the capture file
377  * @param frame the frame to be unmarked
378  */
379 void cf_unmark_frame(capture_file *cf, frame_data *frame);
380
381 /**
382  * Convert error number and info to a complete message.
383  *
384  * @param err the error number
385  * @param err_info the additional info about this error (e.g. filename)
386  * @return statically allocated error message
387  */
388 char *cf_read_error_message(int err, const gchar *err_info);
389
390 /**
391  * Merge two (or more) capture files into one.
392  * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
393  *
394  * @param out_filename output filename
395  * @param out_fd output file descriptor
396  * @param in_file_count the number of input files to merge
397  * @param in_filnames array of input filenames
398  * @param file_type the output filetype
399  * @param do_append FALSE to merge chronologically, TRUE simply append
400  * @return TRUE if merging suceeded, FALSE otherwise
401  */
402 gboolean
403 cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
404                char *const *in_filenames, int file_type, gboolean do_append);
405
406
407 #endif /* file.h */