From c8831ab0e730b59037cbf210c3505922447ef9cc Mon Sep 17 00:00:00 2001
From: Balint Reczey <balint@balintreczey.hu>
Date: Fri, 2 Sep 2016 16:07:31 +0200
Subject: [PATCH] Use system's nghttp2

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -647,7 +647,7 @@
 # - set HAVE_XXX
 
 #The minimum package list
-set(PACKAGELIST Gettext M Git GLIB2 GMODULE2 GTHREAD2 LEX YACC Perl SED SH PythonInterp)
+set(PACKAGELIST Gettext M Git GLIB2 GMODULE2 GTHREAD2 LEX YACC Perl SED SH PythonInterp NGHTTP2)
 set(LEX_REQUIRED TRUE)
 set(GLIB2_REQUIRED TRUE)
 set(GLIB2_FIND_REQUIRED TRUE)
@@ -878,6 +878,9 @@
 if(LIBSSH_FOUND)
 	set(HAVE_LIBSSH 1)
 endif()
+if(NGHTTP2_FOUND)
+	set(HAVE_NGHTTP2 1)
+endif()
 if(HAVE_LIBCARES)
 	set(HAVE_C_ARES 1)
 endif()
@@ -1483,6 +1486,13 @@
 				"${_dll_output_dir}"
 		)
 	endif(LUA_FOUND)
+	if (NGHTTP2_FOUND)
+		add_custom_command(TARGET copy_cli_dlls PRE_BUILD
+			COMMAND ${CMAKE_COMMAND} -E copy_if_different
+				"${NGHTTP2_DLL_DIR}/${NGHTTP2_DLL}"
+				"${_dll_output_dir}"
+		)
+	endif(NGHTTP2_FOUND)
 	if (SMI_FOUND)
 		# Wireshark.nsi wants SMI_DIR which is the base SMI directory
 		get_filename_component(SMI_DIR ${SMI_DLL_DIR} DIRECTORY)
--- /dev/null
+++ b/cmake/modules/FindNGHTTP2.cmake
@@ -0,0 +1,55 @@
+# Find the system's Nghttp2 includes and library
+#
+#  NGHTTP2_INCLUDE_DIRS - where to find nghttp2.h
+#  NGHTTP2_LIBRARIES    - List of libraries when using nghttp2
+#  NGHTTP2_FOUND        - True if nghttp2 found
+#  NGHTTP2_DLL_DIR      - (Windows) Path to the Nghttp2 DLL
+#  NGHTTP2_DLL          - (Windows) Name of the Nghttp2 DLL
+
+include( FindWSWinLibs )
+FindWSWinLibs( "nghttp2-.*" "NGHTTP2_HINTS" )
+
+find_package(PkgConfig)
+pkg_search_module(NGHTTP2 libnghttp2)
+
+find_path( NGHTTP2_INCLUDE_DIR
+  NAMES nghttp2/nghttp2.h
+  HINTS
+    "${NGHTTP2_INCLUDEDIR}"
+    "${NGHTTP2_HINTS}/include"
+  PATHS /usr/local/include /usr/include
+)
+
+find_library( NGHTTP2_LIBRARY
+  NAMES nghttp2
+  HINTS
+    "${NGHTTP2_LIBDIR}"
+    "${NGHTTP2_HINTS}/lib"
+  PATHS /usr/local/lib /usr/lib
+)
+
+include( FindPackageHandleStandardArgs )
+find_package_handle_standard_args( Nghttp2 DEFAULT_MSG NGHTTP2_INCLUDE_DIR NGHTTP2_LIBRARY )
+
+if( NGHTTP2_FOUND )
+  set( NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR} )
+  set( NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY} )
+  if (WIN32)
+    set ( NGHTTP2_DLL_DIR "${NGHTTP2_HINTS}/bin"
+      CACHE PATH "Path to nghttp2 DLL"
+    )
+    file( GLOB _nghttp2_dll RELATIVE "${NGHTTP2_DLL_DIR}"
+      "${NGHTTP2_DLL_DIR}/libnghttp2-*.dll"
+    )
+    set ( NGHTTP2_DLL ${_nghttp2_dll}
+      # We're storing filenames only. Should we use STRING instead?
+      CACHE FILEPATH "nghttp2 DLL file name"
+    )
+    mark_as_advanced( NGHTTP2_DLL_DIR NGHTTP2_DLL )
+  endif()
+else()
+  set( NGHTTP2_INCLUDE_DIRS )
+  set( NGHTTP2_LIBRARIES )
+endif()
+
+mark_as_advanced( NGHTTP2_LIBRARIES NGHTTP2_INCLUDE_DIRS )
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -124,6 +124,9 @@
 /* Define to use kerberos */
 #cmakedefine HAVE_KERBEROS 1
 
+/* Define to use nghttp2 */
+#cmakedefine HAVE_NGHTTP2 1
+
 /* Define to use the libcap library */
 #cmakedefine HAVE_LIBCAP 1
 
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -31,7 +31,6 @@
 add_subdirectory(dfilter)
 add_subdirectory(dissectors)
 add_subdirectory(ftypes)
-add_subdirectory(nghttp2)
 add_subdirectory(wmem)
 if (HAVE_LIBLUA)
 	add_subdirectory(wslua)
@@ -200,6 +199,7 @@
 	${GNUTLS_LIBRARIES}
 	${SMI_LIBRARIES}
 	${M_LIBRARIES}
+	${NGHTTP2_LIBRARIES}
 	${LUA_LIBRARIES}
 	${WIN_PSAPI_LIBRARY}
 )
@@ -235,7 +235,6 @@
 	$<TARGET_OBJECTS:dissectors>
 	$<TARGET_OBJECTS:dissectors-corba>
 	$<TARGET_OBJECTS:ftypes>
-	$<TARGET_OBJECTS:nghttp2>
 	$<TARGET_OBJECTS:wmem>
 	${wslua_sources}
 	${CMAKE_BINARY_DIR}/image/libwireshark.rc
@@ -264,7 +263,6 @@
 file(GLOB D_HEADERS dissectors/*.h)
 file(GLOB FTYPES_HEADERS ftypes/*.h)
 file(GLOB WMEM_HEADERS wmem/*.h)
-file(GLOB NGHTTP2_HEADERS nghttp2/*.h)
 
 add_custom_command(OUTPUT libwireshark.abi.tar.gz
 	COMMAND ${CMAKE_COMMAND} -E remove_directory ${ABICHECK_TMPDIR}
@@ -276,7 +274,6 @@
 	COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}/dissectors
 	COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}/ftypes
 	COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}/wmem
-	COMMAND ${CMAKE_COMMAND} -E make_directory ${ABICHECK_TMPDIR}/nghttp2
 	COMMAND ${ABI_COPY_COMMAND} ${TOP_LEVEL_HEADERS} ${ABICHECK_TMPDIR} ${ABI_COPY_FLAGS}
 	COMMAND ${ABI_COPY_COMMAND} ${ABICHECK_HEADERS} ${ABICHECK_TMPDIR}/epan ${ABI_COPY_FLAGS}
 	COMMAND ${ABI_COPY_COMMAND} ${CRYPT_HEADERS} ${ABICHECK_TMPDIR}/crypt ${ABI_COPY_FLAGS}
@@ -285,7 +282,6 @@
 	COMMAND ${ABI_COPY_COMMAND} ${D_HEADERS} ${ABICHECK_TMPDIR}/dissectors ${ABI_COPY_FLAGS}
 	COMMAND ${ABI_COPY_COMMAND} ${FTYPES_HEADERS} ${ABICHECK_TMPDIR}/ftypes ${ABI_COPY_FLAGS}
 	COMMAND ${ABI_COPY_COMMAND} ${WMEM_HEADERS} ${ABICHECK_TMPDIR}/wmem ${ABI_COPY_FLAGS}
-	COMMAND ${ABI_COPY_COMMAND} ${NGHTTP2_HEADERS} ${ABICHECK_TMPDIR}/nghttp2 ${ABI_COPY_FLAGS}
 	COMMAND rm -f ${ABICHECK_TMPDIR}/dissectors/x11-extension-implementation.h
 		${ABICHECK_TMPDIR}/dissectors/packet-rtps.h
 		${ABICHECK_TMPDIR}/dissectors/x11-glx-render-enum.h
@@ -299,10 +295,9 @@
 #		${ABICHECK_TMPDIR}/epan/* ${ABICHECK_TMPDIR}/compress/*
 #		${ABICHECK_TMPDIR}/dfilter/* ${ABICHECK_TMPDIR}/dissectors/*
 #		${ABICHECK_TMPDIR}/ftypes/* ${ABICHECK_TMPDIR}/wmem/*
-#		${ABICHECK_TMPDIR}/nghttp2/*
 	DEPENDS ${HEADERS}
 		${CRYPT_HEADERS} ${COMPRESS_HEADERS} ${DFILTER_HEADERS} ${D_HEADERS}
-		${FTYPES_HEADERS} ${WMEM_HEADERS} ${NGHTTP2_HEADERS} epan)
+		${FTYPES_HEADERS} ${WMEM_HEADERS} epan)
 
 # By default the name for a library with target name epan will be libepan,
 # but Ethereal is now named Wireshark
--- a/epan/dissectors/packet-http2.c
+++ b/epan/dissectors/packet-http2.c
@@ -43,7 +43,9 @@
 #include <epan/prefs.h>
 #include <epan/proto_data.h>
 
-#include <epan/nghttp2/nghttp2.h>
+#ifdef HAVE_NGHTTP2
+#include <nghttp2/nghttp2.h>
+#endif
 
 #include "packet-tcp.h"
 #include <epan/tap.h>
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -68,6 +68,10 @@
 #include <ares_version.h>
 #endif
 
+#ifdef HAVE_NGHTTP2
+#include <nghttp2/nghttp2ver.h>
+#endif
+
 static wmem_allocator_t *pinfo_pool_cache = NULL;
 
 const gchar*
@@ -562,6 +566,13 @@
 	g_string_append(str, "without GeoIP");
 #endif /* HAVE_GEOIP */
 
+	/* nghttp2 */
+	g_string_append(str, ", ");
+#ifdef HAVE_NGHTTP2
+	g_string_append(str, "with nghttp2 " NGHTTP2_VERSION);
+#else
+	g_string_append(str, "without nghttp2");
+#endif /* HAVE_NGHTTP2 */
 }
 
 /*
