2 * Definitions for routines for merging files.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "wiretap/wtap.h"
18 #endif /* __cplusplus */
28 * Structures to manage our input files.
30 typedef struct merge_in_file_s {
33 in_file_state_e state;
34 guint32 packet_num; /* current packet number */
35 gint64 size; /* file size */
36 GArray *idb_index_map; /* used for mapping the old phdr interface_id values to new during merge */
37 guint dsbs_seen; /* number of elements processed so far from wth->dsbs */
40 /** Return values from merge_files(). */
44 /* below here are true errors */
45 MERGE_ERR_CANT_OPEN_INFILE,
46 MERGE_ERR_CANT_OPEN_OUTFILE,
47 MERGE_ERR_CANT_READ_INFILE,
48 MERGE_ERR_BAD_PHDR_INTERFACE_ID,
49 MERGE_ERR_CANT_WRITE_OUTFILE,
50 MERGE_ERR_CANT_CLOSE_OUTFILE,
51 MERGE_ERR_INVALID_OPTION
55 /** Merge events, used as an arg in the callback function - indicates when the callback was invoked. */
57 MERGE_EVENT_INPUT_FILES_OPENED,
58 MERGE_EVENT_FRAME_TYPE_SELECTED,
59 MERGE_EVENT_READY_TO_MERGE,
60 MERGE_EVENT_RECORD_WAS_READ,
65 /** Merge mode for IDB info. */
67 IDB_MERGE_MODE_NONE = 0, /**< no merging of IDBs is done, all IDBs are copied into merged file */
68 IDB_MERGE_MODE_ALL_SAME,/**< duplicate IDBs merged only if all the files have the same set of IDBs */
69 IDB_MERGE_MODE_ANY_SAME, /**< any and all duplicate IDBs are merged into one IDB, even within a file */
74 /** Returns the idb_merge_mode for the given string name.
76 * @param name The name of the mode.
77 * @return The idb_merge_mode, or IDB_MERGE_MODE_MAX on failure.
79 WS_DLL_PUBLIC idb_merge_mode
80 merge_string_to_idb_merge_mode(const char *name);
83 /** Returns the string name for the given number.
85 * @param mode The number of the mode, representing the idb_merge_mode enum value.
86 * @return The string name, or "UNKNOWN" on failure.
88 WS_DLL_PUBLIC const char*
89 merge_idb_merge_mode_to_string(const int mode);
92 /** @struct merge_progress_callback_t
94 * @brief Callback information for merging.
96 * @details The merge_files() routine can invoke a callback during its execution,
97 * to enable verbose printing or progress bar updating, for example. This struct
98 * provides merge_files() with the callback routine to invoke, and optionally
99 * private data to pass through to the callback each time it is invoked.
100 * For the callback_func routine's arguments: the event is when the callback
101 * was invoked, the num is an int specific to the event, in_files is an array
102 * of the created merge info, in_file_count is the size of the array, data is
103 * whatever was passed in the data member of this struct. The callback_func
104 * routine's return value should be TRUE if merging should be aborted.
107 gboolean (*callback_func)(merge_event event, int num,
108 const merge_in_file_t in_files[], const guint in_file_count,
110 void *data; /**< private data to use for passing through to the callback function */
111 } merge_progress_callback_t;
114 /** Merge the given input files to a file with the given filename
116 * @param out_filename The output filename
117 * @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
118 * @param in_filenames An array of input filenames to merge from
119 * @param in_file_count The number of entries in in_filenames
120 * @param do_append Whether to append by file order instead of chronological order
121 * @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
122 * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
123 * @param app_name The application name performing the merge, used in SHB info
124 * @param cb The callback information to use during execution
125 * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
126 * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
127 * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
128 * MERGE_ERR_CANT_CLOSE_OUTFILE
129 * @param[out] err_info Additional information for some WTAP_ERR_XXX codes
130 * @param[out] err_fileno Set to the input file number which failed, if it
132 * @param[out] err_framenum Set to the input frame number if it failed
133 * @return the frame type
135 WS_DLL_PUBLIC merge_result
136 merge_files(const gchar* out_filename, const int file_type,
137 const char *const *in_filenames, const guint in_file_count,
138 const gboolean do_append, const idb_merge_mode mode,
139 guint snaplen, const gchar *app_name, merge_progress_callback_t* cb,
140 int *err, gchar **err_info, guint *err_fileno,
141 guint32 *err_framenum);
143 /** Merge the given input files to a temporary file
145 * @param out_filenamep Points to a pointer that's set to point to the
146 * pathname of the temporary file; it's allocated with g_malloc()
147 * @param pfx A string to be used as the prefix for the temporary file name
148 * @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
149 * @param in_filenames An array of input filenames to merge from
150 * @param in_file_count The number of entries in in_filenames
151 * @param do_append Whether to append by file order instead of chronological order
152 * @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
153 * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
154 * @param app_name The application name performing the merge, used in SHB info
155 * @param cb The callback information to use during execution
156 * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
157 * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
158 * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
159 * MERGE_ERR_CANT_CLOSE_OUTFILE
160 * @param[out] err_info Additional information for some WTAP_ERR_XXX codes
161 * @param[out] err_fileno Set to the input file number which failed, if it
163 * @param[out] err_framenum Set to the input frame number if it failed
164 * @return the frame type
166 WS_DLL_PUBLIC merge_result
167 merge_files_to_tempfile(gchar **out_filenamep, const char *pfx,
168 const int file_type, const char *const *in_filenames,
169 const guint in_file_count, const gboolean do_append,
170 const idb_merge_mode mode, guint snaplen,
171 const gchar *app_name, merge_progress_callback_t* cb,
172 int *err, gchar **err_info, guint *err_fileno,
173 guint32 *err_framenum);
175 /** Merge the given input files to the standard output
177 * @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
178 * @param in_filenames An array of input filenames to merge from
179 * @param in_file_count The number of entries in in_filenames
180 * @param do_append Whether to append by file order instead of chronological order
181 * @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
182 * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
183 * @param app_name The application name performing the merge, used in SHB info
184 * @param cb The callback information to use during execution
185 * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
186 * with MERGE_ERR_CANT_OPEN_INFILE, MERGE_ERR_CANT_OPEN_OUTFILE,
187 * MERGE_ERR_CANT_READ_INFILE, MERGE_ERR_CANT_WRITE_OUTFILE, or
188 * MERGE_ERR_CANT_CLOSE_OUTFILE
189 * @param[out] err_info Additional information for some WTAP_ERR_XXX codes
190 * @param[out] err_fileno Set to the input file number which failed, if it
192 * @param[out] err_framenum Set to the input frame number if it failed
193 * @return the frame type
195 WS_DLL_PUBLIC merge_result
196 merge_files_to_stdout(const int file_type, const char *const *in_filenames,
197 const guint in_file_count, const gboolean do_append,
198 const idb_merge_mode mode, guint snaplen,
199 const gchar *app_name, merge_progress_callback_t* cb,
200 int *err, gchar **err_info, guint *err_fileno,
201 guint32 *err_framenum);
205 #endif /* __cplusplus */
207 #endif /* __MERGE_H__ */