Harald Welte <laforge@gnumonks.org>
[obnox/wireshark/wip.git] / merge.h
diff --git a/merge.h b/merge.h
index 933333c1468bb360f19b9f6030e3f03406c5fb64..afa28bdedf000512beec9e09a5ea83587b5818a3 100644 (file)
--- a/merge.h
+++ b/merge.h
@@ -1,11 +1,10 @@
 /* merge.h
- * Definitions for menu routines with toolkit-independent APIs but
- * toolkit-dependent implementations.
+ * Definitions for routines for merging files.
  *
- * $Id: merge.h,v 1.4 2004/06/29 20:59:23 ulfl Exp $
+ * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 extern "C" {
 #endif /* __cplusplus */
 
+typedef enum {
+  PACKET_PRESENT,
+  PACKET_NOT_PRESENT,
+  AT_EOF,
+  GOT_ERROR
+} in_file_state_e;
+
 /**
  * Structures to manage our input files.
  */
 typedef struct merge_in_file_s {
-  const char *filename;
-  wtap       *wth;
-  int         err;
-  gchar      *err_info;
-  long        data_offset;
-  gboolean    ok;
+  const char     *filename;
+  wtap           *wth;
+  gint64          data_offset;
+  in_file_state_e state;
+  guint32         packet_num;  /* current packet number */
+  gint64          size;                /* file size */
 } merge_in_file_t;
 
-/**
- * Structures to manage our output file.
- */
-typedef struct merge_out_file_s {
-  int          fd;
-  wtap_dumper *pdh;
-  int          file_type;
-  int          frame_type;
-  unsigned int snaplen;
-  int          count;
-} merge_out_file_t;
-
-/** Verbosity levels. */
-typedef enum {
-    VERBOSE_NONE,
-    VERBOSE_ERRORS,
-    VERBOSE_ALL
-} verbose_e;
-
-/** Current verbosity level, default is VERBOSE_NONE. */
-extern int merge_verbose;
-
 /** Open a number of input files to merge.
  * 
  * @param in_file_count number of entries in in_file_names and in_files
  * @param in_file_names filenames of the input files
  * @param in_files input file array to be filled (>= sizeof(merge_in_file_t) * in_file_count)
  * @param err wiretap error, if failed
- * @return number of opened input files
+ * @param err_info wiretap error string, if failed
+ * @param err_fileno file on which open failed, if failed
+ * @return TRUE if all files could be opened, FALSE otherwise
  */
-extern int
-merge_open_in_files(int in_file_count, char *in_file_names[], merge_in_file_t *in_files[], int *err);
+extern gboolean
+merge_open_in_files(int in_file_count, char *const *in_file_names,
+                    merge_in_file_t **in_files, int *err, gchar **err_info,
+                    int *err_fileno);
 
 /** Close the input files again.
  * 
@@ -83,23 +71,6 @@ merge_open_in_files(int in_file_count, char *in_file_names[], merge_in_file_t *i
 extern void
 merge_close_in_files(int in_file_count, merge_in_file_t in_files[]);
 
-/** Open the output file.
- * 
- * @param out_file the prefilled output file array
- * @param snapshot_len the snapshot length of the output file
- * @param err wiretap error, if failed
- * @return TRUE, if the output file could be opened
- */
-extern gboolean
-merge_open_outfile(merge_out_file_t *out_file, int snapshot_len, int *err);
-
-/** Close the output file again.
- * 
- * @param out_file the output file array
- */
-extern void
-merge_close_outfile(merge_out_file_t *out_file);
-
 /** Try to get the frame type from the input files.
  * 
  * @param in_file_count number of entries in in_files
@@ -118,42 +89,34 @@ merge_select_frame_type(int in_file_count, merge_in_file_t in_files[]);
 extern int
 merge_max_snapshot_length(int in_file_count, merge_in_file_t in_files[]);
 
-/** Merge the packets from the input files into the output file sorted chronologically.
+/** Read the next packet, in chronological order, from the set of files to
+ * be merged.
  * 
  * @param in_file_count number of entries in in_files
  * @param in_files input file array
- * @param out_file the output file array
  * @param err wiretap error, if failed
- * @return TRUE if function succeeded
+ * @param err_info wiretap error string, if failed
+ * @return pointer to merge_in_file_t for file from which that packet
+ * came, or NULL on error or EOF
  */
-extern gboolean
-merge_files(int in_file_count, merge_in_file_t in_files[], merge_out_file_t *out_file, int *err);
+extern merge_in_file_t *
+merge_read_packet(int in_file_count, merge_in_file_t in_files[], int *err,
+                  gchar **err_info);
+
 
-/** Append the packets from the input files into the output file.
+/** Read the next packet, in file sequence order, from the set of files
+ * to be merged.
  * 
  * @param in_file_count number of entries in in_files
  * @param in_files input file array
- * @param out_file the output file array
- * @param err wiretap error, if failed
- * @return TRUE if function succeeded
- */
-extern gboolean
-merge_append_files(int in_file_count, merge_in_file_t in_files[], merge_out_file_t *out_file, int *err);
-
-
-/*
- * Convenience function: merge any number of input files into one.
- *
- * @param out_filename the output filename
- * @param in_file_count number of input files
- * @param in_filenames array of input filenames
- * @param do_append TRUE to append, FALSE to merge chronologically
  * @param err wiretap error, if failed
- * @return TRUE if function succeeded
+ * @param err_info wiretap error string, if failed
+ * @return pointer to merge_in_file_t for file from which that packet
+ * came, or NULL on error or EOF
  */
-extern gboolean
-merge_n_files(int out_fd, int in_file_count, char **in_filenames, gboolean do_append, int *err);
-
+extern merge_in_file_t *
+merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
+                         int *err, gchar **err_info);
 
 #ifdef __cplusplus
 }