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 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "wiretap/wtap.h"
30 #endif /* __cplusplus */
40 * Structures to manage our input files.
42 typedef struct merge_in_file_s {
46 in_file_state_e state;
47 guint32 packet_num; /* current packet number */
48 gint64 size; /* file size */
49 GArray *idb_index_map; /* used for mapping the old phdr interface_id values to new during merge */
52 /** Return values from merge_files(). */
56 /* below here are true errors */
57 MERGE_ERR_CANT_OPEN_INFILE,
58 MERGE_ERR_CANT_OPEN_OUTFILE,
59 MERGE_ERR_CANT_READ_INFILE,
60 MERGE_ERR_BAD_PHDR_INTERFACE_ID,
61 MERGE_ERR_CANT_WRITE_OUTFILE,
62 MERGE_ERR_CANT_CLOSE_OUTFILE
66 /** Merge events, used as an arg in the callback function - indicates when the callback was invoked. */
68 MERGE_EVENT_INPUT_FILES_OPENED,
69 MERGE_EVENT_FRAME_TYPE_SELECTED,
70 MERGE_EVENT_READY_TO_MERGE,
71 MERGE_EVENT_PACKET_WAS_READ,
76 /** Merge mode for IDB info. */
78 IDB_MERGE_MODE_NONE = 0, /**< no merging of IDBs is done, all IDBs are copied into merged file */
79 IDB_MERGE_MODE_ALL_SAME,/**< duplicate IDBs merged only if all the files have the same set of IDBs */
80 IDB_MERGE_MODE_ANY_SAME, /**< any and all duplicate IDBs are merged into one IDB, even within a file */
85 /** Returns the idb_merge_mode for the given string name.
87 * @param name The name of the mode.
88 * @return The idb_merge_mode, or IDB_MERGE_MODE_MAX on failure.
90 WS_DLL_PUBLIC idb_merge_mode
91 merge_string_to_idb_merge_mode(const char *name);
94 /** Returns the string name for the given number.
96 * @param mode The number of the mode, representing the idb_merge_mode enum value.
97 * @return The string name, or "UNKNOWN" on failure.
99 WS_DLL_PUBLIC const char*
100 merge_idb_merge_mode_to_string(const int mode);
103 /** @struct merge_progress_callback_t
105 * @brief Callback information for merging.
107 * @details The merge_files() routine can invoke a callback during its execution,
108 * to enable verbose printing or progress bar updating, for example. This struct
109 * provides merge_files() with the callback routine to invoke, and optionally
110 * private data to pass through to the callback each time it is invoked.
111 * For the callback_func routine's arguments: the event is when the callback
112 * was invoked, the num is an int specific to the event, in_files is an array
113 * of the created merge info, in_file_count is the size of the array, data is
114 * whatever was passed in the data member of this struct. The callback_func
115 * routine's return value should be TRUE if merging should be aborted.
118 gboolean (*callback_func)(merge_event event, int num,
119 const merge_in_file_t in_files[], const guint in_file_count,
121 void *data; /**< private data to use for passing through to the callback function */
122 } merge_progress_callback_t;
125 /** Merge the given input files to the output file descriptor.
127 * @param out_fd The already opened output file decriptor
128 * @param out_filename The output filename, used in error messages
129 * @param file_type The WTAP_FILE_TYPE_SUBTYPE_XXX output file type
130 * @param in_filenames An array of input filenames to merge from
131 * @param in_file_count The number of entries in in_filenames
132 * @param do_append Whether to append by file order instead of chronological order
133 * @param mode The IDB_MERGE_MODE_XXX merge mode for interface data
134 * @param snaplen The snaplen to limit it to, or 0 to leave as it is in the files
135 * @param app_name The application name performing the merge, used in SHB info
136 * @param cb The callback information to use during execution
137 * @param[out] err Set to the internal WTAP_ERR_XXX error code if it failed
138 * @param[out] err_info Set to a descriptive error string, which must be g_free'd
139 * @param[out] err_fileno Set to the input file number which failed, if it failed
140 * @return the frame type
142 WS_DLL_PUBLIC merge_result
143 merge_files(int out_fd, const gchar* out_filename, const int file_type,
144 const char *const *in_filenames, const guint in_file_count,
145 const gboolean do_append, const idb_merge_mode mode,
146 guint snaplen, const gchar *app_name, merge_progress_callback_t* cb,
147 int *err, gchar **err_info, guint *err_fileno);
151 #endif /* __cplusplus */
153 #endif /* __MERGE_H__ */