As suggested by Anders: back out 37112.
[obnox/wireshark/wip.git] / epan / epan.c
index e6c8b5d41474b1051d42a5e50d82a84b3fa7c57a..236ea20b925356e9e376de3440409e120a2a0277 100644 (file)
 #include "config.h"
 #endif
 
-#if (defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBGNUTLS)) && defined(_WIN32)
-#include <winposixtype.h>
-#endif
-
 #ifdef HAVE_LIBGCRYPT
 #include <gcrypt.h>
 #endif /* HAVE_LIBGCRYPT */
 #include "circuit.h"
 #include "except.h"
 #include "packet.h"
+#include "prefs.h"
 #include "column-utils.h"
 #include "tap.h"
 #include "addr_resolv.h"
-#include "oid_resolv.h"
+#include "oids.h"
 #include "emem.h"
 #include "expert.h"
 
 #ifdef HAVE_LUA_5_1
-       int wslua_init(void*);
+#include <lua.h>
+#include <wslua/wslua.h>
+#endif
+
+#ifdef HAVE_LIBSMI
+#include <smi.h>
+#endif
+
+#ifdef HAVE_C_ARES
+#include <ares_version.h>
+#endif
+
+#ifdef HAVE_GEOIP
+#include "geoip_db.h"
 #endif
 
 gchar*
@@ -64,19 +74,20 @@ epan_get_version(void) {
 }
 
 void
-epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
-         void (*register_all_handoffs)(register_cb cb, gpointer client_data),
+epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
+         void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
          register_cb cb,
          gpointer client_data,
-         void (*report_failure)(const char *, va_list),
-         void (*report_open_failure)(const char *, int, gboolean),
-         void (*report_read_failure)(const char *, int))
+         void (*report_failure_fcn_p)(const char *, va_list),
+         void (*report_open_failure_fcn_p)(const char *, int, gboolean),
+         void (*report_read_failure_fcn_p)(const char *, int),
+         void (*report_write_failure_fcn_p)(const char *, int))
 {
-       init_report_err(report_failure, report_open_failure, report_read_failure);
+       init_report_err(report_failure_fcn_p, report_open_failure_fcn_p,
+           report_read_failure_fcn_p, report_write_failure_fcn_p);
 
        /* initialize memory allocation subsystem */
-       ep_init_chunk();
-       se_init_chunk();
+       emem_init();
 
        /* initialize the GUID to name mapping table */
        guids_init();
@@ -88,9 +99,10 @@ epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
        gcry_check_version(NULL);
 #endif
        tvbuff_init();
-       oid_resolv_init();
        tap_init();
-       proto_init(register_all_protocols, register_all_handoffs, cb, client_data);
+       prefs_init();
+       proto_init(register_all_protocols_func, register_all_handoffs_func,
+           cb, client_data);
        packet_init();
        dfilter_init();
        final_registration_all_protocols();
@@ -99,15 +111,19 @@ epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
 #ifdef HAVE_LUA_5_1
        wslua_init(NULL);
 #endif
+#ifdef HAVE_GEOIP
+       geoip_db_init();
+#endif
 
 }
 
 void
 epan_cleanup(void)
 {
-       expert_cleanup();
+       cleanup_dissection();
        dfilter_cleanup();
        proto_cleanup();
+       prefs_cleanup();
        packet_cleanup();
        oid_resolv_cleanup();
        tvbuff_cleanup();
@@ -124,18 +140,28 @@ epan_conversation_init(void)
        conversation_init();
 }
 
+void
+epan_conversation_cleanup(void)
+{
+       conversation_cleanup();
+}
+
 void
 epan_circuit_init(void)
 {
        circuit_init();
 }
 
-epan_dissect_t*
-epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
+void
+epan_circuit_cleanup(void)
 {
-       epan_dissect_t  *edt;
+       circuit_cleanup();
+}
 
-       edt = g_new(epan_dissect_t, 1);
+epan_dissect_t*
+epan_dissect_init(epan_dissect_t       *edt, const gboolean create_proto_tree, const gboolean proto_tree_visible)
+{
+       g_assert(edt);
 
        if (create_proto_tree) {
                edt->tree = proto_tree_create_root();
@@ -148,6 +174,23 @@ epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
        return edt;
 }
 
+epan_dissect_t*
+epan_dissect_new(const gboolean create_proto_tree, const gboolean proto_tree_visible)
+{
+       epan_dissect_t  *edt;
+
+       edt = g_new0(epan_dissect_t, 1);
+
+       return epan_dissect_init(edt, create_proto_tree, proto_tree_visible);
+}
+
+void
+epan_dissect_fake_protocols(epan_dissect_t *edt, const gboolean fake_protocols)
+{
+       if (edt)
+               proto_tree_set_fake_protocols(edt->tree, fake_protocols);
+}
+
 void
 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
         const guint8* data, frame_data *fd, column_info *cinfo)
@@ -158,10 +201,11 @@ epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
        dissect_packet(edt, pseudo_header, data, fd, cinfo);
 }
 
-
 void
-epan_dissect_free(epan_dissect_t* edt)
+epan_dissect_cleanup(epan_dissect_t* edt)
 {
+       g_assert(edt);
+
        /* Free the data sources list. */
        free_data_sources(&edt->pi);
 
@@ -173,18 +217,161 @@ epan_dissect_free(epan_dissect_t* edt)
        if (edt->tree) {
                proto_tree_free(edt->tree);
        }
+}
 
+void
+epan_dissect_free(epan_dissect_t* edt)
+{
+       epan_dissect_cleanup(edt);
        g_free(edt);
 }
 
 void
 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
 {
-       dfilter_prime_proto_tree(dfcode, edt->tree);
+    dfilter_prime_proto_tree(dfcode, edt->tree);
+}
+
+/* ----------------------- */
+const gchar *
+epan_custom_set(epan_dissect_t *edt, int field_id,
+                             gint occurrence,
+                             gchar *result,
+                             gchar *expr, const int size )
+{
+    return proto_custom_set(edt->tree, field_id, occurrence, result, expr, size);
+}
+
+void
+epan_dissect_fill_in_columns(epan_dissect_t *edt, const gboolean fill_col_exprs, const gboolean fill_fd_colums)
+{
+    col_custom_set_edt(edt, edt->pi.cinfo);
+    col_fill_in(&edt->pi, fill_col_exprs, fill_fd_colums);
+}
+
+/*
+ * Get compile-time information for libraries used by libwireshark.
+ */
+void
+epan_get_compiled_version_info(GString *str)
+{
+        /* PCRE */
+       g_string_append(str, ", ");
+#ifdef HAVE_LIBPCRE
+       g_string_append(str, "with libpcre ");
+#ifdef PCRE_MAJOR
+#ifdef PCRE_MINOR
+       g_string_append_printf(str, "%u.%u", PCRE_MAJOR, PCRE_MINOR);
+#else                  /* PCRE_MINOR */
+       g_string_append_printf(str, "%u", PCRE_MAJOR);
+#endif                 /* PCRE_MINOR */
+#else          /* PCRE_MAJOR */
+       g_string_append(str, "(version unknown)");
+#endif         /* PCRE_MAJOR */
+#else  /* HAVE_LIBPCRE */
+       g_string_append(str, "without libpcre");
+#endif /* HAVE_LIBPCRE */
+
+        /* SNMP */
+       g_string_append(str, ", ");
+#ifdef HAVE_LIBSMI
+       g_string_append(str, "with SMI " SMI_VERSION_STRING);
+#else /* no SNMP library */
+       g_string_append(str, "without SMI");
+#endif /* _SMI_H */
+
+       /* c-ares */
+       g_string_append(str, ", ");
+#ifdef HAVE_C_ARES
+       g_string_append(str, "with c-ares " ARES_VERSION_STR);
+#else
+       g_string_append(str, "without c-ares");
+
+       /* ADNS - only add if no c-ares */
+       g_string_append(str, ", ");
+#ifdef HAVE_GNU_ADNS
+       g_string_append(str, "with ADNS");
+#else
+       g_string_append(str, "without ADNS");
+#endif /* HAVE_GNU_ADNS */
+#endif /* HAVE_C_ARES */
+
+        /* LUA */
+       g_string_append(str, ", ");
+#ifdef HAVE_LUA_5_1
+       g_string_append(str, "with ");
+       g_string_append(str, LUA_VERSION);
+#else
+       g_string_append(str, "without Lua");
+#endif /* HAVE_LUA_5_1 */
+
+       g_string_append(str, ", ");
+#ifdef HAVE_PYTHON
+       g_string_append(str, "with Python");
+#ifdef PY_VERSION
+       g_string_append(str, " " PY_VERSION);
+#endif /* PY_VERSION */
+#else
+       g_string_append(str, "without Python");
+#endif /* HAVE_PYTHON */
+
+        /* GnuTLS */
+       g_string_append(str, ", ");
+#ifdef HAVE_LIBGNUTLS
+       g_string_append(str, "with GnuTLS " LIBGNUTLS_VERSION);
+#else
+       g_string_append(str, "without GnuTLS");
+#endif /* HAVE_LIBGNUTLS */
+
+        /* Gcrypt */
+       g_string_append(str, ", ");
+#ifdef HAVE_LIBGCRYPT
+       g_string_append(str, "with Gcrypt " GCRYPT_VERSION);
+#else
+       g_string_append(str, "without Gcrypt");
+#endif /* HAVE_LIBGCRYPT */
+
+        /* Kerberos */
+        /* XXX - I don't see how to get the version number, at least for KfW */
+       g_string_append(str, ", ");
+#ifdef HAVE_KERBEROS
+#ifdef HAVE_MIT_KERBEROS
+       g_string_append(str, "with MIT Kerberos");
+#else
+        /* HAVE_HEIMDAL_KERBEROS */
+       g_string_append(str, "with Heimdal Kerberos");
+#endif
+#else
+       g_string_append(str, "without Kerberos");
+#endif /* HAVE_KERBEROS */
+
+       /* GeoIP */
+       g_string_append(str, ", ");
+#ifdef HAVE_GEOIP
+       g_string_append(str, "with GeoIP");
+#else
+       g_string_append(str, "without GeoIP");
+#endif /* HAVE_GEOIP */
+
 }
 
+/*
+ * Get runtime information for libraries used by libwireshark.
+ */
 void
-epan_dissect_fill_in_columns(epan_dissect_t *edt)
+epan_get_runtime_version_info(GString *str
+#if !defined(HAVE_LIBGNUTLS) && !defined(HAVE_LIBGCRYPT)
+_U_
+#endif
+)
 {
-    col_fill_in(&edt->pi);
+        /* GnuTLS */
+#ifdef HAVE_LIBGNUTLS
+       g_string_append_printf(str, ", GnuTLS %s", gnutls_check_version(NULL));
+#endif /* HAVE_LIBGNUTLS */
+
+        /* Gcrypt */
+#ifdef HAVE_LIBGCRYPT
+       g_string_append_printf(str, ", Gcrypt %s", gcry_check_version(NULL));
+#endif /* HAVE_LIBGCRYPT */
 }