Change some of the merge.c APIs to return more information on failure,
[jlayton/wireshark.git] / merge.h
1 /* merge.h
2  * Definitions for routines for merging files.
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 __MERGE_H__
26 #define __MERGE_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 /**
33  * Structures to manage our input files.
34  */
35 typedef struct merge_in_file_s {
36   const char *filename;
37   wtap       *wth;
38   int         err;
39   gchar      *err_info;
40   long        data_offset;
41   gboolean    ok;
42 } merge_in_file_t;
43
44 /**
45  * Structures to manage our output file.
46  */
47 typedef struct merge_out_file_s {
48   wtap_dumper *pdh;
49   unsigned int snaplen;
50   int          count;
51 } merge_out_file_t;
52
53 /** Verbosity levels. */
54 typedef enum {
55     VERBOSE_NONE,
56     VERBOSE_ERRORS,
57     VERBOSE_ALL
58 } verbose_e;
59
60 /** Current verbosity level, default is VERBOSE_NONE. */
61 extern int merge_verbose;
62
63 /** Open a number of input files to merge.
64  * 
65  * @param in_file_count number of entries in in_file_names and in_files
66  * @param in_file_names filenames of the input files
67  * @param in_files input file array to be filled (>= sizeof(merge_in_file_t) * in_file_count)
68  * @param err wiretap error, if failed and VERBOSE_NONE
69  * @param err_info wiretap error string, if failed and VERBOSE_NONE
70  * @param err_fileno file on which open failed, if VERBOSE_NONE
71  * @return number of opened input files
72  */
73 extern int
74 merge_open_in_files(int in_file_count, char *const *in_file_names,
75                     merge_in_file_t **in_files, int *err, gchar **err_info,
76                     int *err_fileno);
77
78 /** Close the input files again.
79  * 
80  * @param in_file_count number of entries in in_files
81  * @param in_files input file array to be closed
82  */
83 extern void
84 merge_close_in_files(int in_file_count, merge_in_file_t in_files[]);
85
86 /** Open the output file.
87  * 
88  * @param out_file the output file array, which we fill in
89  * @param fd the file descriptor to use for the output file
90  * @param file_type the file type to write
91  * @param frame_type the frame type to write
92  * @param snapshot_len the snapshot length of the output file
93  * @param err wiretap error, if failed
94  * @return TRUE, if the output file could be opened
95  */
96 extern gboolean
97 merge_open_outfile(merge_out_file_t *out_file, int fd, int file_type,
98                    int frame_type, int snapshot_len, int *err);
99
100 /** Close the output file again.
101  * 
102  * @param out_file the output file array
103  * @param err wiretap error, if failed
104  * @return TRUE if the close succeeded, FALSE otherwise
105  */
106 extern gboolean
107 merge_close_outfile(merge_out_file_t *out_file, int *err);
108
109 /** Try to get the frame type from the input files.
110  * 
111  * @param in_file_count number of entries in in_files
112  * @param in_files input file array
113  * @return the frame type
114  */
115 extern int
116 merge_select_frame_type(int in_file_count, merge_in_file_t in_files[]);
117
118 /** Try to get the snapshot length from the input files.
119  * 
120  * @param in_file_count number of entries in in_files
121  * @param in_files input file array
122  * @return the snapshot length
123  */
124 extern int
125 merge_max_snapshot_length(int in_file_count, merge_in_file_t in_files[]);
126
127 /** Merge the packets from the input files into the output file sorted chronologically.
128  * 
129  * @param in_file_count number of entries in in_files
130  * @param in_files input file array
131  * @param out_file the output file array
132  * @param err wiretap error, if failed
133  * @return TRUE on success or read failure, FALSE on write failure
134  */
135 extern gboolean
136 merge_files(int in_file_count, merge_in_file_t in_files[], merge_out_file_t *out_file, int *err);
137
138 /** Append the packets from the input files into the output file.
139  * 
140  * @param in_file_count number of entries in in_files
141  * @param in_files input file array
142  * @param out_file the output file array
143  * @param err wiretap error, if failed
144  * @return TRUE on success or read failure, FALSE on write failure
145  */
146 extern gboolean
147 merge_append_files(int in_file_count, merge_in_file_t in_files[], merge_out_file_t *out_file, int *err);
148
149 /** Return status from merge_n_files */
150 typedef enum {
151     MERGE_SUCCESS,
152     MERGE_OPEN_INPUT_FAILED,
153     MERGE_OPEN_OUTPUT_FAILED,
154     MERGE_WRITE_FAILED
155 } merge_status_e;
156
157 /*
158  * Convenience function: merge any number of input files into one.
159  *
160  * @param out_filename the output filename
161  * @param in_file_count number of input files
162  * @param in_filenames array of input filenames
163  * @param do_append TRUE to append, FALSE to merge chronologically
164  * @param err wiretap error, if failed and VERBOSE_NONE
165  * @param err_info wiretap error string, if failed and VERBOSE_NONE
166  * @param err_fileno file on which open failed, if VERBOSE_NONE
167  * @return merge_status_e
168  */
169 extern merge_status_e
170 merge_n_files(int out_fd, int in_file_count, char *const *in_filenames,
171               int filetype, gboolean do_append, int *err, gchar **err_info,
172               int *err_fileno);
173
174
175 #ifdef __cplusplus
176 }
177 #endif /* __cplusplus */
178
179 #endif /* __MERGE_H__ */
180