Hand the packet provider functions to epan_new().
authorGuy Harris <guy@alum.mit.edu>
Fri, 8 Dec 2017 04:33:22 +0000 (20:33 -0800)
committerGuy Harris <guy@alum.mit.edu>
Fri, 8 Dec 2017 04:33:55 +0000 (04:33 +0000)
Have separate packet_provider_data structures and packet_provider_funcs
structures; the latter holds a table of functions that libwireshark can
call for information about packets, the latter holds the data that those
functions use.

This means we no longer need to expose the structure of an epan_t
outside epan/epan.c; get rid of epan/epan-int.h.

Change-Id: I381b88993aa19e55720ce02c42ad33738e3f51f4
Reviewed-on: https://code.wireshark.org/review/24732
Reviewed-by: Guy Harris <guy@alum.mit.edu>
12 files changed:
cfile.h
epan/Makefile.am
epan/epan-int.h [deleted file]
epan/epan.c
epan/epan.h
file.c
file_packet_provider.c
rawshark.c
sharkd.c
tfshark.c
tools/oss-fuzzshark/fuzzshark.c
tshark.c

diff --git a/cfile.h b/cfile.h
index 05a09794c8fedcac2ccaa16f732bb2ce40068bea..d1c4e379a75b79d9d68d1dc495636fe4087a532b 100644 (file)
--- a/cfile.h
+++ b/cfile.h
@@ -46,7 +46,7 @@ typedef enum {
 /*
  * Packet provider for programs using a capture file.
  */
-struct packet_provider {
+struct packet_provider_data {
   wtap        *wth;                  /* Wiretap session */
   const frame_data *ref;
   frame_data  *prev_dis;
@@ -102,7 +102,7 @@ typedef struct _capture_file {
   struct wtap_pkthdr phdr;           /* Packet header */
   Buffer       buf;                  /* Packet data */
   /* packet provider */
-  struct packet_provider provider;
+  struct packet_provider_data provider;
   /* frames */
   guint32      first_displayed;      /* Frame number of first frame displayed */
   guint32      last_displayed;       /* Frame number of last frame displayed */
@@ -120,10 +120,10 @@ typedef struct _capture_file {
 
 extern void cap_file_init(capture_file *cf);
 
-const char *cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 interface_id);
-const char *cap_file_provider_get_interface_description(struct packet_provider *prov, guint32 interface_id);
-const char *cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_data *fd);
-void cap_file_provider_set_user_comment(struct packet_provider *prov, frame_data *fd, const char *new_comment);
+const char *cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id);
+const char *cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id);
+const char *cap_file_provider_get_user_comment(struct packet_provider_data *prov, const frame_data *fd);
+void cap_file_provider_set_user_comment(struct packet_provider_data *prov, frame_data *fd, const char *new_comment);
 
 #ifdef __cplusplus
 }
index db5832774fee806f409171e23e0211df4b1e6aaf..31c01b52aea8e42c6ca641e76d80fccc2ae05de6 100644 (file)
@@ -282,7 +282,6 @@ LIBWIRESHARK_INCLUDES_PUBLIC = \
        xdlc.h
 
 LIBWIRESHARK_INCLUDES_PRIVATE = \
-       epan-int.h              \
        to_str-int.h
 
 subpkgincludedir = $(pkgincludedir)/epan
diff --git a/epan/epan-int.h b/epan/epan-int.h
deleted file mode 100644 (file)
index 54f1fb5..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/* epan-int.h
- *
- * Wireshark Protocol Analyzer Library
- *
- * Copyright (c) 2001 by Gerald Combs <gerald@wireshark.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __EPAN_INT_H__
-#define __EPAN_INT_H__
-
-#include <epan/frame_data.h>
-#include <wsutil/nstime.h>
-
-struct epan_session {
-       struct packet_provider *prov;   /* packet provider for this session */
-
-       const nstime_t *(*get_frame_ts)(struct packet_provider *prov, guint32 frame_num);
-       const char *(*get_interface_name)(struct packet_provider *prov, guint32 interface_id);
-       const char *(*get_interface_description)(struct packet_provider *prov, guint32 interface_id);
-       const char *(*get_user_comment)(struct packet_provider *prov, const frame_data *fd);
-};
-
-#endif
index 8d9d8dbc94ce85073cd44a8e3add1f995446e3f5..1940f21fbfa1a29441b7e6b4e50bc9229924709d 100644 (file)
 #include <epan/exceptions.h>
 
 #include "epan.h"
-#include "epan-int.h"
+#include "epan/frame_data.h"
+
 #include "dfilter/dfilter.h"
 #include "epan_dissect.h"
 
+#include <wsutil/nstime.h>
+
 #include "conversation.h"
 #include "except.h"
 #include "packet.h"
@@ -283,12 +286,19 @@ epan_cleanup(void)
        wmem_cleanup();
 }
 
+struct epan_session {
+       struct packet_provider_data *prov;      /* packet provider data for this session */
+       struct packet_provider_funcs funcs;     /* functions using that data */
+};
+
 epan_t *
-epan_new(struct packet_provider *prov)
+epan_new(struct packet_provider_data *prov,
+    const struct packet_provider_funcs *funcs)
 {
        epan_t *session = g_slice_new0(epan_t);
 
        session->prov = prov;
+       session->funcs = *funcs;
 
        /* XXX, it should take session as param */
        init_dissection();
@@ -299,8 +309,8 @@ epan_new(struct packet_provider *prov)
 const char *
 epan_get_user_comment(const epan_t *session, const frame_data *fd)
 {
-       if (session->get_user_comment)
-               return session->get_user_comment(session->prov, fd);
+       if (session->funcs.get_user_comment)
+               return session->funcs.get_user_comment(session->prov, fd);
 
        return NULL;
 }
@@ -308,8 +318,8 @@ epan_get_user_comment(const epan_t *session, const frame_data *fd)
 const char *
 epan_get_interface_name(const epan_t *session, guint32 interface_id)
 {
-       if (session->get_interface_name)
-               return session->get_interface_name(session->prov, interface_id);
+       if (session->funcs.get_interface_name)
+               return session->funcs.get_interface_name(session->prov, interface_id);
 
        return NULL;
 }
@@ -317,8 +327,8 @@ epan_get_interface_name(const epan_t *session, guint32 interface_id)
 const char *
 epan_get_interface_description(const epan_t *session, guint32 interface_id)
 {
-       if (session->get_interface_description)
-               return session->get_interface_description(session->prov, interface_id);
+       if (session->funcs.get_interface_description)
+               return session->funcs.get_interface_description(session->prov, interface_id);
 
        return NULL;
 }
@@ -328,8 +338,8 @@ epan_get_frame_ts(const epan_t *session, guint32 frame_num)
 {
        const nstime_t *abs_ts = NULL;
 
-       if (session->get_frame_ts)
-               abs_ts = session->get_frame_ts(session->prov, frame_num);
+       if (session->funcs.get_frame_ts)
+               abs_ts = session->funcs.get_frame_ts(session->prov, frame_num);
 
        if (!abs_ts)
                ws_g_warning("!!! couldn't get frame ts for %u !!!\n", frame_num);
index 306c583f8f2fb7aa255166a5f44e6fdcdb8ab96a..5cafb780dc406454d5ddf507875c48c6640e9585 100644 (file)
@@ -44,7 +44,18 @@ struct epan_column_info;
  * time stamps, comments, and other information outside the packet
  * data itself.
  */
-struct packet_provider;
+struct packet_provider_data;
+
+/*
+ * Structure containing pointers to functions supplied by the user
+ * of libwireshark.
+ */
+struct packet_provider_funcs {
+       const nstime_t *(*get_frame_ts)(struct packet_provider_data *prov, guint32 frame_num);
+       const char *(*get_interface_name)(struct packet_provider_data *prov, guint32 interface_id);
+       const char *(*get_interface_description)(struct packet_provider_data *prov, guint32 interface_id);
+       const char *(*get_user_comment)(struct packet_provider_data *prov, const frame_data *fd);
+};
 
 /**
        @mainpage Wireshark EPAN the packet analyzing engine. Source code can be found in the epan directory
@@ -138,7 +149,8 @@ void epan_conversation_init(void);
  */
 typedef struct epan_session epan_t;
 
-WS_DLL_PUBLIC epan_t *epan_new(struct packet_provider *prov);
+WS_DLL_PUBLIC epan_t *epan_new(struct packet_provider_data *prov,
+    const struct packet_provider_funcs *funcs);
 
 WS_DLL_PUBLIC const char *epan_get_user_comment(const epan_t *session, const frame_data *fd);
 
diff --git a/file.c b/file.c
index 7fda336642cc370e91a2da798f95012a87ab7488..d0080c4802abac24e3784a07479358ef918348b1 100644 (file)
--- a/file.c
+++ b/file.c
@@ -26,7 +26,6 @@
 #include <wiretap/merge.h>
 
 #include <epan/exceptions.h>
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 #include <epan/column.h>
 #include <epan/packet.h>
@@ -223,7 +222,7 @@ static void compute_elapsed(capture_file *cf, GTimeVal *start_time)
 }
 
 static const nstime_t *
-ws_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+ws_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
 {
   if (prov->prev_dis && prov->prev_dis->num == frame_num)
     return &prov->prev_dis->abs_ts;
@@ -243,14 +242,14 @@ ws_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
 static epan_t *
 ws_epan_new(capture_file *cf)
 {
-  epan_t *epan = epan_new(&cf->provider);
-
-  epan->get_frame_ts = ws_get_frame_ts;
-  epan->get_interface_name = cap_file_provider_get_interface_name;
-  epan->get_interface_description = cap_file_provider_get_interface_description;
-  epan->get_user_comment = cap_file_provider_get_user_comment;
-
-  return epan;
+  static const struct packet_provider_funcs funcs = {
+    ws_get_frame_ts,
+    cap_file_provider_get_interface_name,
+    cap_file_provider_get_interface_description,
+    cap_file_provider_get_user_comment
+  };
+
+  return epan_new(&cf->provider, &funcs);
 }
 
 cf_status_t
index e536298a8ebd7b46d65c4236aaf1d1b7ad2d47f9..c08d2168193e8b31f016b9638de7724b11c61afd 100644 (file)
@@ -1,5 +1,5 @@
-/* file_packet_provider.c
- * Routines for a packet_provider for packets from a file.
+/* file_packet_provider_data.c
+ * Routines for a packet_provider_data for packets from a file.
  *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
@@ -24,7 +24,7 @@ frame_cmp(gconstpointer a, gconstpointer b, gpointer user_data _U_)
 }
 
 const char *
-cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 interface_id)
+cap_file_provider_get_interface_name(struct packet_provider_data *prov, guint32 interface_id)
 {
   wtapng_iface_descriptions_t *idb_info;
   wtap_block_t wtapng_if_descr = NULL;
@@ -47,7 +47,7 @@ cap_file_provider_get_interface_name(struct packet_provider *prov, guint32 inter
 }
 
 const char *
-cap_file_provider_get_interface_description(struct packet_provider *prov, guint32 interface_id)
+cap_file_provider_get_interface_description(struct packet_provider_data *prov, guint32 interface_id)
 {
   wtapng_iface_descriptions_t *idb_info;
   wtap_block_t wtapng_if_descr = NULL;
@@ -68,7 +68,7 @@ cap_file_provider_get_interface_description(struct packet_provider *prov, guint3
 }
 
 const char *
-cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_data *fd)
+cap_file_provider_get_user_comment(struct packet_provider_data *prov, const frame_data *fd)
 {
   if (prov->frames_user_comments)
      return (const char *)g_tree_lookup(prov->frames_user_comments, fd);
@@ -78,7 +78,7 @@ cap_file_provider_get_user_comment(struct packet_provider *prov, const frame_dat
 }
 
 void
-cap_file_provider_set_user_comment(struct packet_provider *prov, frame_data *fd, const char *new_comment)
+cap_file_provider_set_user_comment(struct packet_provider_data *prov, frame_data *fd, const char *new_comment)
 {
   if (!prov->frames_user_comments)
     prov->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free);
index e97ab249ba155335f837cf690b89be8dc11f46ac..eb382fd5ba35e819090a79621161ef8701928cb6 100644 (file)
@@ -44,7 +44,6 @@
 #endif
 
 #include <glib.h>
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 
 #include <wsutil/cmdarg_err.h>
@@ -1464,7 +1463,7 @@ open_failure_message(const char *filename, int err, gboolean for_writing)
 }
 
 static const nstime_t *
-raw_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+raw_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
 {
     if (prov->ref && prov->ref->num == frame_num)
         return &prov->ref->abs_ts;
@@ -1481,14 +1480,14 @@ raw_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
 static epan_t *
 raw_epan_new(capture_file *cf)
 {
-    epan_t *epan = epan_new(&cf->provider);
-
-    epan->get_frame_ts = raw_get_frame_ts;
-    epan->get_interface_name = cap_file_provider_get_interface_name;
-    epan->get_interface_description = cap_file_provider_get_interface_description;
-    epan->get_user_comment = NULL;
+    static const struct packet_provider_funcs funcs = {
+        raw_get_frame_ts,
+        cap_file_provider_get_interface_name,
+        cap_file_provider_get_interface_description,
+        NULL,
+    };
 
-    return epan;
+    return epan_new(&cf->provider, &funcs);
 }
 
 cf_status_t
index 5ceb7bf2febfd2444c86b5b5bb3056f4a34a4feb..d2be886e307073683ccf8b52fa1a8b3a211c9c99 100644 (file)
--- a/sharkd.c
+++ b/sharkd.c
@@ -21,7 +21,6 @@
 #include <glib.h>
 
 #include <epan/exceptions.h>
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 
 #include <wsutil/clopts_common.h>
@@ -221,7 +220,7 @@ clean_exit:
 }
 
 static const nstime_t *
-sharkd_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+sharkd_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
 {
   if (prov->ref && prov->ref->num == frame_num)
     return &prov->ref->abs_ts;
@@ -244,14 +243,14 @@ sharkd_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
 static epan_t *
 sharkd_epan_new(capture_file *cf)
 {
-  epan_t *epan = epan_new(&cf->provider);
-
-  epan->get_frame_ts = sharkd_get_frame_ts;
-  epan->get_interface_name = cap_file_provider_get_interface_name;
-  epan->get_interface_description = cap_file_provider_get_interface_description;
-  epan->get_user_comment = cap_file_provider_get_user_comment;
-
-  return epan;
+  static const struct packet_provider_funcs funcs = {
+    sharkd_get_frame_ts,
+    cap_file_provider_get_interface_name,
+    cap_file_provider_get_interface_description,
+    cap_file_provider_get_user_comment
+  };
+
+  return epan_new(&cf->provider, &funcs);
 }
 
 static gboolean
index d6e696f26866090836e548281de7ebc00b4ef438..d8cdfcbc042bb9f776485e6bde36dc82966452fc 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -30,7 +30,6 @@
 #include <glib.h>
 
 #include <epan/exceptions.h>
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 
 #include <wsutil/clopts_common.h>
@@ -1023,7 +1022,7 @@ clean_exit:
 }
 
 static const nstime_t *
-tfshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+tfshark_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
 {
   if (prov->ref && prov->ref->num == frame_num)
     return &prov->ref->abs_ts;
@@ -1044,7 +1043,7 @@ tfshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
 }
 
 static const char *
-no_interface_name(struct packet_provider *prov _U_, guint32 interface_id _U_)
+no_interface_name(struct packet_provider_data *prov _U_, guint32 interface_id _U_)
 {
     return "";
 }
@@ -1052,13 +1051,14 @@ no_interface_name(struct packet_provider *prov _U_, guint32 interface_id _U_)
 static epan_t *
 tfshark_epan_new(capture_file *cf)
 {
-  epan_t *epan = epan_new(&cf->provider);
-
-  epan->get_frame_ts = tfshark_get_frame_ts;
-  epan->get_interface_name = no_interface_name;
-  epan->get_user_comment = NULL;
+  static const struct packet_provider_funcs funcs = {
+    tfshark_get_frame_ts,
+    no_interface_name,
+    NULL,
+    NULL,
+  };
 
-  return epan;
+  return epan_new(&cf->provider, &funcs);
 }
 
 static gboolean
index 56e816b12bf119e281d3293acd4e70143453779b..9c623efbf20daa1cc402f02cc6cdc7e39821e38b 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <glib.h>
 
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 
 #include <wsutil/cmdarg_err.h>
@@ -111,7 +110,7 @@ failure_message_cont(const char *msg_format, va_list ap)
 }
 
 static const nstime_t *
-fuzzshark_get_frame_ts(struct packet_provider *prov _U_, guint32 frame_num _U_)
+fuzzshark_get_frame_ts(struct packet_provider_data *prov _U_, guint32 frame_num _U_)
 {
        static nstime_t empty;
 
@@ -121,14 +120,14 @@ fuzzshark_get_frame_ts(struct packet_provider *prov _U_, guint32 frame_num _U_)
 static epan_t *
 fuzzshark_epan_new(void)
 {
-       epan_t *epan = epan_new(NULL);
-
-       epan->get_frame_ts = fuzzshark_get_frame_ts;
-       epan->get_interface_name = NULL;
-       epan->get_interface_description = NULL;
-       epan->get_user_comment = NULL;
-
-       return epan;
+       static const struct packet_provider_funcs funcs = {
+               fuzzshark_get_frame_ts,
+               NULL,
+               NULL,
+               NULL
+       };
+
+       return epan_new(NULL, &funcs);
 }
 
 static dissector_handle_t
index 07a828983e4eca7173a9bf746dfddef9d16a87fe..099f49ff974cde7e3a42c062c615ee6d0c81e3e3 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -43,7 +43,6 @@
 #include <glib.h>
 
 #include <epan/exceptions.h>
-#include <epan/epan-int.h>
 #include <epan/epan.h>
 
 #include <wsutil/clopts_common.h>
@@ -2343,7 +2342,7 @@ pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_pro
 }
 
 static const nstime_t *
-tshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
+tshark_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
 {
   if (prov->ref && prov->ref->num == frame_num)
     return &prov->ref->abs_ts;
@@ -2366,14 +2365,14 @@ tshark_get_frame_ts(struct packet_provider *prov, guint32 frame_num)
 static epan_t *
 tshark_epan_new(capture_file *cf)
 {
-  epan_t *epan = epan_new(&cf->provider);
-
-  epan->get_frame_ts = tshark_get_frame_ts;
-  epan->get_interface_name = cap_file_provider_get_interface_name;
-  epan->get_interface_description = cap_file_provider_get_interface_description;
-  epan->get_user_comment = NULL;
+  static const struct packet_provider_funcs funcs = {
+    tshark_get_frame_ts,
+    cap_file_provider_get_interface_name,
+    cap_file_provider_get_interface_description,
+    NULL,
+  };
 
-  return epan;
+  return epan_new(&cf->provider, &funcs);
 }
 
 #ifdef HAVE_LIBPCAP