Grr forgot debug flag - again.
[obnox/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40
41 /** Return values from functions that only can succeed or fail. */
42 typedef enum {
43         CF_OK,                      /**< operation succeeded */
44         CF_ERROR        /**< operation got an error (function may provide err with details) */
45 } cf_status_t;
46
47 /** Return values from functions that read capture files. */
48 typedef enum {
49         CF_READ_OK,             /**< operation succeeded */
50         CF_READ_ERROR,          /**< operation got an error (function may provide err with details) */
51         CF_READ_ABORTED         /**< operation aborted by user */
52 } cf_read_status_t;
53
54 /** Return values from functions that print sets of packets. */
55 typedef enum {
56         CF_PRINT_OK,                /**< print operation succeeded */
57         CF_PRINT_OPEN_ERROR,    /**< print operation failed while opening printer */
58         CF_PRINT_WRITE_ERROR    /**< print operation failed while writing to the printer */
59 } cf_print_status_t;
60
61 typedef enum {
62     cf_cb_file_closing,
63     cf_cb_file_closed,
64     cf_cb_file_read_started,
65     cf_cb_file_read_finished,
66     cf_cb_packet_selected,
67     cf_cb_packet_unselected,
68     cf_cb_field_unselected,
69     cf_cb_file_save_started,
70     cf_cb_file_save_finished,
71     cf_cb_file_save_reload_finished,
72     cf_cb_file_save_failed
73 } cf_cbs;
74
75 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
76
77 typedef struct {
78     const char    *string;
79     size_t         string_len;
80     capture_file  *cf;
81     gboolean       frame_matched;
82     field_info    *finfo;
83 } match_data;
84
85 extern void
86 cf_callback_add(cf_callback_t func, gpointer user_data);
87
88 extern void
89 cf_callback_remove(cf_callback_t func);
90
91 /**
92  * Open a capture file.
93  *
94  * @param cf the capture file to be opened
95  * @param fname the filename to be opened
96  * @param is_tempfile is this a temporary file?
97  * @param err error code
98  * @return one of cf_status_t
99  */
100 cf_status_t cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
101
102 /**
103  * Close a capture file.
104  *
105  * @param cf the capture file to be closed
106  */
107 void cf_close(capture_file *cf);
108
109 /**
110  * Reload a capture file.
111  *
112  * @param cf the capture file to be reloaded
113  */
114 void cf_reload(capture_file *cf);
115
116 /**
117  * Read all packets of a capture file into the internal structures.
118  *
119  * @param cf the capture file to be read
120  * @param from_save reread asked from cf_save
121  * @return one of cf_read_status_t
122  */
123 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
124
125 /**
126  * Read the pseudo-header and raw data for a packet.  It will pop
127  * up an alert box if there's an error.
128  *
129  * @param cf the capture file from which to read the packet
130  * @param fdata the frame_data structure for the packet in question
131  * @param pseudo_header pointer to a wtap_pseudo_header union into
132  * which to read the packet's pseudo-header
133  * @param pd a guin8 array into which to read the packet's raw data
134  * @return TRUE if the read succeeded, FALSE if there was an error
135  */
136 gboolean cf_read_frame_r(capture_file *cf, frame_data *fdata,
137                          union wtap_pseudo_header *pseudo_header, guint8 *pd);
138
139 /**
140  * Read the pseudo-header and raw data for a packet into a
141  * capture_file structure's pseudo_header and pd members.
142  * It will pop up an alert box if there's an error.
143  *
144  * @param cf the capture file from which to read the packet
145  * @param fdata the frame_data structure for the packet in question
146  * @return TRUE if the read succeeded, FALSE if there was an error
147  */
148 gboolean cf_read_frame(capture_file *cf, frame_data *fdata);
149
150 /**
151  * Start reading from the end of a capture file.
152  * This is used in "Update list of packets in Real-Time".
153  *
154  * @param cf the capture file to be read from
155  * @param fname the filename to be read from
156  * @param is_tempfile is this a temporary file?
157  * @param err the error code, if an error had occured
158  * @return one of cf_status_t
159  */
160 cf_status_t cf_start_tail(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
161
162 /**
163  * Read packets from the "end" of a capture file.
164  *
165  * @param cf the capture file to be read from
166  * @param to_read the number of packets to read
167  * @param err the error code, if an error had occured
168  * @return one of cf_read_status_t
169  */
170 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
171
172 /**
173  * Fake reading packets from the "end" of a capture file.
174  *
175  * @param cf the capture file to be read from
176  */
177 void cf_fake_continue_tail(capture_file *cf);
178
179 /**
180  * Finish reading from "end" of a capture file.
181  *
182  * @param cf the capture file to be read from
183  * @param err the error code, if an error had occured
184  * @return one of cf_read_status_t
185  */
186 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
187
188 /**
189  * Determine whether this capture file (or a range of it) can be saved
190  * (except by copying the raw file data).
191  *
192  * @param cf the capture file to check
193  * @return TRUE if it can be saved, FALSE if it can't
194  */
195 gboolean cf_can_save_as(capture_file *cf);
196
197 /**
198  * Save a capture file (or a range of it).
199  *
200  * @param cf the capture file to save to
201  * @param fname the filename to save to
202  * @param range the range of packets to save
203  * @param save_format the format of the file to save (libpcap, ...)
204  * @param compressed whether to gzip compress the file
205  * @return one of cf_status_t
206  */
207 cf_status_t cf_save(capture_file * cf, const char *fname, packet_range_t *range, guint save_format, gboolean compressed);
208
209 /**
210  * Get a displayable name of the capture file.
211  *
212  * @param cf the capture file
213  * @return the displayable name (don't have to be g_free'd)
214  */
215 const gchar *cf_get_display_name(capture_file *cf);
216
217 /**
218  * Set the source of the capture data for temporary files, e.g.
219  * "Interface eth0" or "Pipe from Pong"
220  *
221  * @param cf the capture file
222  * @param source the source description. this will be copied internally.
223  */
224 void cf_set_tempfile_source(capture_file *cf, gchar *source);
225
226 /**
227  * Get the source of the capture data for temporary files. Guaranteed to
228  * return a non-null value. The returned value should not be freed.
229  *
230  * @param cf the capture file
231  */
232 const gchar *cf_get_tempfile_source(capture_file *cf);
233
234 /**
235  * Get the number of packets in the capture file.
236  *
237  * @param cf the capture file
238  * @return the number of packets in the capture file
239  */
240 int cf_get_packet_count(capture_file *cf);
241
242 /**
243  * Set the number of packets in the capture file.
244  *
245  * @param cf the capture file
246  * @param packet_count the number of packets in the capture file
247  */
248 void cf_set_packet_count(capture_file *cf, int packet_count);
249
250 /**
251  * Is this capture file a temporary file?
252  *
253  * @param cf the capture file
254  * @return TRUE if it's a temporary file, FALSE otherwise
255  */
256 gboolean cf_is_tempfile(capture_file *cf);
257
258 /**
259  * Set flag, that this file is a tempfile.
260  */
261 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
262
263 /**
264  * Set flag, if the number of packet drops while capturing are known or not.
265  *
266  * @param cf the capture file
267  * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
268  */
269 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
270
271 /**
272  * Set the number of packet drops while capturing.
273  *
274  * @param cf the capture file
275  * @param drops the number of packet drops occured while capturing
276  */
277 void cf_set_drops(capture_file *cf, guint32 drops);
278
279 /**
280  * Get flag state, if the number of packet drops while capturing are known or not.
281  *
282  * @param cf the capture file
283  * @return TRUE if the number of packet drops are known, FALSE otherwise
284  */
285 gboolean cf_get_drops_known(capture_file *cf);
286
287 /**
288  * Get the number of packet drops while capturing.
289  *
290  * @param cf the capture file
291  * @return the number of packet drops occured while capturing
292  */
293 guint32 cf_get_drops(capture_file *cf);
294
295 /**
296  * Set the read filter.
297  * @todo this shouldn't be required, remove it somehow
298  *
299  * @param cf the capture file
300  * @param rfcode the readfilter
301  */
302 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
303
304 /**
305  * "Display Filter" packets in the capture file.
306  *
307  * @param cf the capture file
308  * @param dfilter the display filter
309  * @param force TRUE if do in any case, FALSE only if dfilter changed
310  * @return one of cf_status_t
311  */
312 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
313
314 /**
315  * At least one "Refence Time" flag has changed, rescan all packets.
316  *
317  * @param cf the capture file
318  */
319 void cf_reftime_packets(capture_file *cf);
320
321 /**
322  * Return the time it took to load the file
323  */
324 gulong cf_get_computed_elapsed(void);
325
326 /**
327  * "Something" has changed, rescan all packets.
328  *
329  * @param cf the capture file
330  */
331 void cf_redissect_packets(capture_file *cf);
332
333 /**
334  * Rescan all packets and just run taps - don't reconstruct the display.
335  *
336  * @param cf the capture file
337  * @return one of cf_read_status_t
338  */
339 cf_read_status_t cf_retap_packets(capture_file *cf);
340
341 /**
342  * Adjust timestamp precision if auto is selected.
343  *
344  * @param cf the capture file
345  */
346 void cf_timestamp_auto_precision(capture_file *cf);
347
348 /**
349  * Print the capture file.
350  *
351  * @param cf the capture file
352  * @param print_args the arguments what and how to print
353  * @return one of cf_print_status_t
354  */
355 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
356
357 /**
358  * Print (export) the capture file into PDML format.
359  *
360  * @param cf the capture file
361  * @param print_args the arguments what and how to export
362  * @return one of cf_print_status_t
363  */
364 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
365
366 /**
367  * Print (export) the capture file into PSML format.
368  *
369  * @param cf the capture file
370  * @param print_args the arguments what and how to export
371  * @return one of cf_print_status_t
372  */
373 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
374
375 /**
376  * Print (export) the capture file into CSV format.
377  *
378  * @param cf the capture file
379  * @param print_args the arguments what and how to export
380  * @return one of cf_print_status_t
381  */
382 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
383
384 /**
385  * Print (export) the capture file into C Arrays format.
386  *
387  * @param cf the capture file
388  * @param print_args the arguments what and how to export
389  * @return one of cf_print_status_t
390  */
391 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
392
393 /**
394  * Find packet with a protocol tree item that contains a specified text string.
395  *
396  * @param cf the capture file
397  * @param string the string to find
398  * @param dir direction in which to search
399  * @return TRUE if a packet was found, FALSE otherwise
400  */
401 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
402                                       search_direction dir);
403
404 /**
405  * Find field with a label that contains text string cfile->sfilter.
406  *
407  * @param cf the capture file
408  * @param tree the protocol tree
409  * @param mdata the first field (mdata->finfo) that matched the string
410  * @return TRUE if a packet was found, FALSE otherwise
411  */
412 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
413                                              match_data *mdata);
414
415 /**
416  * Find packet whose summary line contains a specified text string.
417  *
418  * @param cf the capture file
419  * @param string the string to find
420  * @param dir direction in which to search
421  * @return TRUE if a packet was found, FALSE otherwise
422  */
423 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
424                                      search_direction dir);
425
426 /**
427  * Find packet whose data contains a specified byte string.
428  *
429  * @param cf the capture file
430  * @param string the string to find
431  * @param string_size the size of the string to find
432  * @param dir direction in which to search
433  * @return TRUE if a packet was found, FALSE otherwise
434  */
435 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
436                              size_t string_size, search_direction dir);
437
438 /**
439  * Find packet that matches a compiled display filter.
440  *
441  * @param cf the capture file
442  * @param sfcode the display filter to match
443  * @param dir direction in which to search
444  * @return TRUE if a packet was found, FALSE otherwise
445  */
446 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
447                                 search_direction dir);
448
449 /**
450  * Find packet that matches a display filter given as a text string.
451  *
452  * @param cf the capture file
453  * @param filter the display filter to match
454  * @param dir direction in which to search
455  * @return TRUE if a packet was found, FALSE otherwise
456  */
457 gboolean
458 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
459                               search_direction dir);
460
461 /**
462  * Find marked packet.
463  *
464  * @param cf the capture file
465  * @param dir direction in which to search
466  * @return TRUE if a packet was found, FALSE otherwise
467  */
468 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
469
470 /**
471  * Find time-reference packet.
472  *
473  * @param cf the capture file
474  * @param dir direction in which to search
475  * @return TRUE if a packet was found, FALSE otherwise
476  */
477 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
478
479 /**
480  * GoTo Packet in first row.
481  *
482  * @return TRUE if the first row exists, FALSE otherwise
483  */
484 gboolean cf_goto_top_frame(void);
485
486 /**
487  * GoTo Packet in last row.
488  *
489  * @return TRUE if last row exists, FALSE otherwise
490  */
491 gboolean cf_goto_bottom_frame(void);
492
493 /**
494  * GoTo Packet with the given row.
495  *
496  * @param cf the capture file
497  * @param row the row to go to
498  * @return TRUE if this row exists, FALSE otherwise
499  */
500 gboolean cf_goto_frame(capture_file *cf, guint row);
501
502 /**
503  * Go to frame specified by currently selected protocol tree field.
504  * (Go To Corresponding Packet)
505  * @todo this is ugly and should be improved!
506  *
507  * @param cf the capture file
508  * @return TRUE if this packet exists, FALSE otherwise
509  */
510 gboolean cf_goto_framenum(capture_file *cf);
511
512 /**
513  * Select the packet in the given row.
514  *
515  * @param cf the capture file
516  * @param row the row to select
517  */
518 void cf_select_packet(capture_file *cf, int row);
519
520 /**
521  * Unselect all packets, if any.
522  *
523  * @param cf the capture file
524  */
525 void cf_unselect_packet(capture_file *cf);
526
527 /**
528  * Unselect all protocol tree fields, if any.
529  *
530  * @param cf the capture file
531  */
532 void cf_unselect_field(capture_file *cf);
533
534 /**
535  * Mark a particular frame in a particular capture.
536  *
537  * @param cf the capture file
538  * @param frame the frame to be marked
539  */
540 void cf_mark_frame(capture_file *cf, frame_data *frame);
541
542 /**
543  * Unmark a particular frame in a particular capture.
544  *
545  * @param cf the capture file
546  * @param frame the frame to be unmarked
547  */
548 void cf_unmark_frame(capture_file *cf, frame_data *frame);
549
550 /**
551  * Ignore a particular frame in a particular capture.
552  *
553  * @param cf the capture file
554  * @param frame the frame to be ignored
555  */
556 void cf_ignore_frame(capture_file *cf, frame_data *frame);
557
558 /**
559  * Unignore a particular frame in a particular capture.
560  *
561  * @param cf the capture file
562  * @param frame the frame to be unignored
563  */
564 void cf_unignore_frame(capture_file *cf, frame_data *frame);
565
566 /**
567  * Merge two (or more) capture files into one.
568  * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
569  *
570  * @param out_filename pointer to output filename; if output filename is
571  * NULL, a temporary file name is generated and *out_filename is set
572  * to point to the generated file name
573  * @param in_file_count the number of input files to merge
574  * @param in_filenames array of input filenames
575  * @param file_type the output filetype
576  * @param do_append FALSE to merge chronologically, TRUE simply append
577  * @return one of cf_status_t
578  */
579 cf_status_t
580 cf_merge_files(char **out_filename, int in_file_count,
581                char *const *in_filenames, int file_type, gboolean do_append);
582
583 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
584 void read_keytab_file(const char *);
585 #endif
586
587 #ifdef __cplusplus
588 }
589 #endif /* __cplusplus */
590
591 #endif /* file.h */