From Kovarththanan Rajaratnam via bug 3500:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 1 Jun 2010 22:20:15 +0000 (22:20 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 1 Jun 2010 22:20:15 +0000 (22:20 +0000)
S├ębastien's initial commit [1] didn't contain support for embedding Python on
Windows.

[1] http://anonsvn.wireshark.org/viewvc?view=rev&revision=28529

From me:

Comment out PYTHON_EMBED for now.

Start a list of known Python+CRT versions.

Add get_wspython_dir to libwireshark.def.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@33036 f5534014-38df-0310-8fa8-9805f1628bb7

Makefile.nmake
config.h.win32
config.nmake
epan/Makefile.nmake
epan/libwireshark.def
epan/wspython/wspy_register.c

index 75298aa5d73ac25f1ed05573340aeaae57b7821b..b8335c8c365ebd2f6999a197fdc394607c3b9787 100644 (file)
@@ -43,7 +43,7 @@ GENERATED_CFLAGS=-DHAVE_CONFIG_H $(LOCAL_CFLAGS) $(GLIB_CFLAGS) /I. /Iwiretap \
        $(ZLIB_CFLAGS) /I$(PCAP_DIR)\include \
        $(AIRPCAP_CFLAGS) \
        $(C_ARES_CFLAGS) $(ADNS_CFLAGS) $(PCRE_CFLAGS) $(GNUTLS_CFLAGS) \
-       $(LUA_CFLAGS) $(SMI_CFLAGS) $(GEOIP_CFLAGS) \
+       $(LUA_CFLAGS) $(PYTHON_CFLAGS) $(SMI_CFLAGS) $(GEOIP_CFLAGS) \
        -D_U_="" -D_NEED_VAR_IMPORT_
 CFLAGS=-WX $(GENERATED_CFLAGS)
 
@@ -77,6 +77,7 @@ wireshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        $(HHC_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
+       $(PYTHON_LIBS) \
 !IFDEF ENABLE_LIBWIRESHARK
        epan\libwireshark.lib \
 !ELSE
@@ -96,6 +97,7 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
+       $(PYTHON_LIBS) \
 !IFDEF ENABLE_LIBWIRESHARK
        epan\libwireshark.lib \
 !ELSE
@@ -115,6 +117,7 @@ rawshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
+       $(PYTHON_LIBS) \
 !IFDEF ENABLE_LIBWIRESHARK
        epan\libwireshark.lib \
 !ELSE
@@ -155,7 +158,8 @@ dumpcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS) \
         $(GTHREAD_LIBS) \
-       $(GNUTLS_LIBS)
+       $(GNUTLS_LIBS) \
+       $(PYTHON_LIBS)
 
 dftest_LIBS=  wiretap\wiretap-$(WTAP_VERSION).lib \
        wsock32.lib user32.lib \
@@ -369,6 +373,7 @@ config.h    : config.h.win32 config.nmake
            -e "s/@HAVE_LIBGCRYPT@/$(LIBGCRYPT_CONFIG)/" \
            -e "s/@HAVE_LUA@/$(LUA_CONFIG)/" \
            -e "s/@HAVE_LUA_5_1@/$(LUA_VERSION)/" \
+           -e "s/@HAVE_PYTHON@/$(PYTHON_CONFIG)/" \
            -e "s/@HAVE_AIRPCAP@/$(AIRPCAP_CONFIG)/" \
            -e "s/@HAVE_AIRPDCAP@/$(AIRPDCAP_CONFIG)/" \
            -e "s/@HAVE_LIBPORTAUDIO@/$(PORTAUDIO_CONFIG)/" \
@@ -943,6 +948,12 @@ install-generated-files:
 !IFDEF LUA_DIR
        xcopy ".\epan\wslua\init.lua" $(INSTALL_DIR) /d
        xcopy ".\epan\wslua\console.lua" $(INSTALL_DIR) /d
+!ENDIF
+!IFDEF PYTHON_DIR
+       if not exist $(INSTALL_DIR)\python mkdir $(INSTALL_DIR)\python
+       xcopy ".\epan\wspython\register-dissector.py" $(INSTALL_DIR)\python /d
+       xcopy ".\epan\wspython\wspy_dissector.py" $(INSTALL_DIR)\python /d
+       xcopy ".\epan\wspython\wspy_libws.py" $(INSTALL_DIR)\python /d
 !ENDIF
        xcopy ipmap.html $(INSTALL_DIR) /d
        xcopy doc\*.html $(INSTALL_DIR) /d
index a463161c5a0824f562cfa6a6ab908a73c228bf8f..aed2d95469eec28b042fa67febdc82f8212592ff 100644 (file)
 @HAVE_LUA@
 @HAVE_LUA_5_1@
 
+/* Define to use Python */
+@HAVE_PYTHON@
+
 /* Define to use Portaudio library */
 @HAVE_LIBPORTAUDIO@
 /* Define  version of of the Portaudio library API */
index 5bba362a6d6e1a80d8b7f9b6a2bd9efc631a64a3..8e7cea3b9e9ea8e4570fac485690706db8a4b3a0 100644 (file)
@@ -138,6 +138,40 @@ MSVC_VARIANT=MSVC2008
 #
 NASM=$(WIRESHARK_LIBS)\nasm-2.02\nasm.exe
 
+#
+# Optional: the Python library enables scripting support.
+#
+# If you don't have the Python library, comment this line out, so that
+# PYTHON_EMBED isn't defined.
+#
+# NOTE: The Python library must have been compiled with the same
+# compiler (MSVC_VARIANT) as Wireshark. Kown python.org Python
+# CRT versions:
+#
+# Python version    CRT (32-bit)    CRT (64-bit)
+# 2.4.4             7.1             ?
+# 2.6.1             9.0             ?
+# 2.6.2                             9.0
+#
+# If you versions of Python and Visual C++ use different CRTs
+# comment this out.
+#
+#PYTHON_EMBED=1
+
+#
+# Optional: the Python interpreter is used as part of the buildsystem
+#
+# If you have the Python interpreter, set this to the directory in which
+# the Python package is stored
+#
+# If you don't have the Python interpreter, comment this line out, so that
+# PYTHON_DIR isn't defined.
+#
+# V2.4 to V2.6 should work
+#
+#PYTHON_VER=26
+#PYTHON_DIR=C:\Python$(PYTHON_VER)
+
 
 !if "$(WIRESHARK_TARGET_PLATFORM)" == "win32"
 ##### Win32 Libraries #####
@@ -582,30 +616,12 @@ PERL=perl
 POD2MAN=$(SH) pod2man
 POD2HTML=$(SH) pod2html
 
-# Command for native Windows Python (recommended)
-# V2.4 to V2.6 should work
-
-# If you want to specify your Python settings, uncomment the lines below.
-#PYTHON="C:\Python26\python.exe"
-#PATH=c:\Python26;$(PATH)
-
-# Command for Cygwin's Python (not recommended)
+#
+# If you don't have the native Python package installed, you can use
+# the Cygwin version (not recommended)
+#
 #PYTHON=env python
 
-# Otherwise, find Python automatically.
-!IF !DEFINED(PYTHON)
-!IF EXIST(c:\Python26\python.exe)
-PYTHON="C:\Python26\python.exe"
-PATH=c:\Python26;$(PATH)
-!ELSE IF EXIST(c:\Python25\python.exe)
-PYTHON="C:\Python25\python.exe"
-PATH=c:\Python25;$(PATH)
-!ELSE IF EXIST(c:\Python24\python.exe)
-PYTHON="C:\Python24\python.exe"
-PATH=c:\Python24;$(PATH)
-!ENDIF
-!ENDIF
-
 # command for lex/flexx (cygwin's flex recommended)
 LEX=flex
 
@@ -674,6 +690,36 @@ UPX=$(WIRESHARK_LIBS)\upx303w\upx.exe
 
 ##### Flags, PATHs and Miscellaneous #####
 
+# Santity check: native vs Cygwin Python options
+!IF DEFINED(PYTHON) && DEFINED(PYTHON_DIR)
+!ERROR PYTHON and PYTHON_DIR cannot be specified at the same time
+!ENDIF
+
+# Find native Python automatically if PYTHON(_DIR) wasn't defined
+!IF !DEFINED(PYTHON) && !DEFINED(PYTHON_DIR)
+!IF EXIST(c:\Python26\python.exe)
+PYTHON_VER=26
+!ELSE IF EXIST(c:\Python25\python.exe)
+PYTHON_VER=25
+!ELSE IF EXIST(c:\Python24\python.exe)
+PYTHON_VER=24
+!ENDIF
+
+!IF DEFINED(PYTHON_VER)
+PYTHON_DIR=C:\Python$(PYTHON_VER)
+!ENDIF
+!ENDIF
+
+!IF DEFINED(PYTHON_DIR)
+PYTHON="$(PYTHON_DIR)\python.exe"
+PATH=$(PYTHON_DIR);$(PATH)
+!ENDIF
+
+# Santity check: Python embedding requires a valid PYTHON_DIR
+!IF DEFINED(PYTHON_EMBED) && !DEFINED(PYTHON_DIR)
+!ERROR PYTHON_EMBED requires that PYTHON_DIR is defined
+!ENDIF
+
 # "convert" the MSVC variant into the required MSC compiler version
 !IF "$(MSVC_VARIANT)" == "MSVC6"
 MSC_VER_REQUIRED=1200
@@ -1116,6 +1162,17 @@ LUA_LIBS=
 LUA_CONFIG=
 !ENDIF
 
+!IF DEFINED(PYTHON_EMBED)
+PYTHON_CFLAGS=/I$(PYTHON_DIR)\include
+PYTHON_LIBS=$(PYTHON_DIR)\libs\python$(PYTHON_VER).lib
+# Nmake uses carets to escape special characters
+PYTHON_CONFIG=^#define HAVE_PYTHON 1
+!else
+PYTHON_CFLAGS=
+PYTHON_LIBS=
+PYTHON_CONFIG=
+!ENDIF
+
 !IFDEF PORTAUDIO_DIR
 # Nmake uses carets to escape special characters
 PORTAUDIO_CONFIG=^#define HAVE_LIBPORTAUDIO 1
index b0e2d43ed70f7795d794d2097f751d15a1d2939b..77f5fa026e2630a2fdbbbc1b67dc022ac5e55531 100644 (file)
@@ -28,6 +28,14 @@ WSLUA_LIB=
 WSLUA_DIR=
 !ENDIf
 
+!IFDEF PYTHON_DIR
+WSPYTHON_LIB=wspython\wspython.lib
+WSPYTHON_DIR=wspython
+!ELSE
+WSPYTHON_LIB=
+WSPYTHON_DIR=
+!ENDIf
+
 # For use when making libwireshark.dll
 libwireshark_LIBS = \
        $(GLIB_LIBS)    \
@@ -39,6 +47,7 @@ libwireshark_LIBS = \
        $(ZLIB_LIBS) \
        $(GNUTLS_LIBS) \
        $(LUA_LIBS) \
+       $(PYTHON_LIBS) \
        $(SMI_LIBS) \
        $(GEOIP_LIBS) \
        ..\wsutil\libwsutil.lib \
@@ -48,6 +57,7 @@ libwireshark_LIBS = \
        ftypes\ftypes.lib \
        dfilter\dfilter.lib \
        $(WSLUA_LIB) \
+       $(WSPYTHON_LIB) \
        dissectors\dissectors.lib
 
 .c.obj::
@@ -67,17 +77,17 @@ DOXYGEN_DEP=doxygen
 !ENDIF
 
 !IFDEF ENABLE_LIBWIRESHARK
-all: crc crypt ftypes dfilter $(WSLUA_DIR) dissectors libwireshark.dll
+all: crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.dll
 !ELSE
-all: crc crypt ftypes dfilter $(WSLUA_DIR) dissectors libwireshark.lib
+all: crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.lib
 !ENDIF
 
 # For use when making libwireshark.dll
 libwireshark.lib: libwireshark.dll
 libwireshark.exp: libwireshark.dll
 
-libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crc crypt ftypes dfilter $(WSLUA_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
-                 crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib dissectors\dissectors.lib $(WSLUA_LIB) ..\image\libwireshark.res
+libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
+                 crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res
        @echo Linking libwireshark.dll
        $(link) $(dlllflags) $(conlibsdll) shell32.lib \
                $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \
@@ -87,8 +97,8 @@ libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crc crypt
                dissectors\register.obj \
                $(EXTRA_OBJECTS)
 
-libwireshark.lib       : ..\config.h $(LIBWIRESHARK_OBJECTS) crc crypt ftypes dfilter $(WSLUA_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
-                  crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib $(WSLUA_LIB) dissectors\dissectors.lib
+libwireshark.lib       : ..\config.h $(LIBWIRESHARK_OBJECTS) crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
+                  crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib $(WSLUA_LIB) $(WSPYTHON_LIB) dissectors\dissectors.lib
        link /lib /out:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \
                $(EXTRA_OBJECTS)
 
@@ -117,6 +127,8 @@ clean:  clean-local
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
        cd ../wslua
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
+       cd ../wspython
+       $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
        cd ..
 
 #
@@ -149,6 +161,8 @@ distclean: distclean-local
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
        cd ../wslua
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
+       cd ../wspython
+       $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
        cd ..
 
 maintainer-clean-local: distclean-local
@@ -166,6 +180,8 @@ maintainer-clean: maintainer-clean-local
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
        cd ../wslua
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
+       cd ../wspython
+       $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
        cd ..
 
 crc:: ..\config.h
@@ -198,6 +214,11 @@ wslua:: ..\config.h
        $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
        cd ..
 
+wspython:: ..\config.h
+       cd wspython
+       $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
+       cd ..
+
 doxygen.cfg: ..\config.nmake doxygen.cfg.in
        sed -e s/@VERSION@/$(VERSION)/ \
            < doxygen.cfg.in > $@
index bddcb9152be711efbe1d2d92a968bfbcda059650..fe9684fe4c6a7163ba353dfa929ed60051ea5bc5 100644 (file)
@@ -542,6 +542,7 @@ get_systemfile_dir
 get_tcp_port
 get_tempfile_path
 get_udp_port
+get_wspython_dir
 getenv_utf8
 golay_decode
 golay_encode
index dd3e4fb1bc3c8160f2a9bee8254e43be7c798669..76f4efd8f33897ea1c0f5ccb9055b18b5e738a20 100644 (file)
@@ -229,7 +229,7 @@ void py_dissect(tvbuff_t * tvb, packet_info * pinfo,
  */
 dissector_t py_generic_dissector(void)
 {
-  return py_dissect;
+  return &py_dissect;
 }
 
 struct SRegisterHandoffsForeach {