From 887741751c072dfa45b8d8161afa308d770738bb Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 7 Nov 2000 18:49:29 +0000 Subject: [PATCH] *** empty log message *** --- dtool/Config.pp | 6 +++ dtool/LocalSetup.pp | 3 ++ dtool/pptempl/Global.pp | 21 ++++++++ dtool/src/cppparser/cppPreprocessor.cxx | 10 ++-- dtool/src/parser-inc/Sources.pp | 2 +- dtool/src/parser-inc/files.h | 19 ++++++++ dtool/src/parser-inc/md5.h | 19 ++++++++ panda/src/downloader/Sources.pp | 4 ++ panda/src/downloader/crypto_utils.cxx | 64 +++++++++++++++++++++++++ panda/src/downloader/crypto_utils.h | 19 ++++++++ panda/src/downloader/download_utils.cxx | 58 ---------------------- panda/src/downloader/download_utils.h | 6 +-- 12 files changed, 162 insertions(+), 69 deletions(-) create mode 100644 dtool/src/parser-inc/files.h create mode 100644 dtool/src/parser-inc/md5.h create mode 100644 panda/src/downloader/crypto_utils.cxx create mode 100644 panda/src/downloader/crypto_utils.h diff --git a/dtool/Config.pp b/dtool/Config.pp index 901bf78e82..40d6dcf3f1 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -156,6 +156,12 @@ #define NSPR_LIBS nspr4 #defer HAVE_NSPR $[libtest $[NSPR_LPATH],$[NSPR_LIBS]] +// Is Crypto++ installed, and where? +#define CRYPTO_IPATH /usr/include/crypto++ +#define CRYPTO_LPATH /usr/lib +#define CRYPTO_LIBS cryptlib +#defer HAVE_CRYPTO $[libtest $[CRYPTO_LPATH],$[CRYPTO_LIBS]] + // Is VRPN installed, and where? #define VRPN_IPATH #define VRPN_LPATH diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index 721563b4eb..ebb0ecd530 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -31,6 +31,9 @@ $[cdefine HAVE_PYTHON] /* Define if we have NSPR installed. */ $[cdefine HAVE_NSPR] +/* Define if we have crypto++ installed. */ +$[cdefine HAVE_CRYPTO] + /* Define if we have VRPN installed. */ $[cdefine HAVE_VRPN] diff --git a/dtool/pptempl/Global.pp b/dtool/pptempl/Global.pp index 85e152703a..426c9ceda3 100644 --- a/dtool/pptempl/Global.pp +++ b/dtool/pptempl/Global.pp @@ -81,6 +81,12 @@ #define nspr_libs $[NSPR_LIBS] #endif +#if $[HAVE_CRYPTO] + #define crypto_ipath $[wildcard $[CRYPTO_IPATH]] + #define crypto_lpath $[wildcard $[CRYPTO_LPATH]] + #define crypto_libs $[CRYPTO_LIBS] +#endif + #if $[HAVE_ZLIB] #define zlib_ipath $[wildcard $[ZLIB_IPATH]] #define zlib_lpath $[wildcard $[ZLIB_LPATH]] @@ -170,6 +176,7 @@ $[and \ $[or $[not $[DIRECTORY_IF_PYTHON]],$[HAVE_PYTHON]], \ $[or $[not $[DIRECTORY_IF_NSPR]],$[HAVE_NSPR]], \ + $[or $[not $[DIRECTORY_IF_CRYPTO]],$[HAVE_CRYPTO]], \ $[or $[not $[DIRECTORY_IF_ZLIB]],$[HAVE_ZLIB]], \ $[or $[not $[DIRECTORY_IF_SOXST]],$[HAVE_SOXST]], \ $[or $[not $[DIRECTORY_IF_GL]],$[HAVE_GL]], \ @@ -195,6 +202,7 @@ $[and \ $[or $[not $[TARGET_IF_PYTHON]],$[HAVE_PYTHON]], \ $[or $[not $[TARGET_IF_NSPR]],$[HAVE_NSPR]], \ + $[or $[not $[TARGET_IF_CRYPTO]],$[HAVE_CRYPTO]], \ $[or $[not $[TARGET_IF_ZLIB]],$[HAVE_ZLIB]], \ $[or $[not $[TARGET_IF_SOXST]],$[HAVE_SOXST]], \ $[or $[not $[TARGET_IF_GL]],$[HAVE_GL]], \ @@ -237,6 +245,7 @@ // target. #defer get_sources \ $[SOURCES] \ + $[if $[HAVE_CRYPTO],$[IF_CRYPTO_SOURCES]] \ $[if $[HAVE_ZLIB],$[IF_ZLIB_SOURCES]] \ $[if $[HAVE_IPC],$[IF_IPC_SOURCES]] \ $[if $[HAVE_NET],$[IF_NET_SOURCES]] \ @@ -279,6 +288,9 @@ #defun get_cflags #define alt_cflags $[nspr_cflags] $[python_cflags] + #if $[ne $[USE_CRYPTO] $[components $[USE_CRYPTO],$[active_component_libs]],] + #set alt_cflags $[alt_cflags] $[crypto_cflags] + #endif #if $[ne $[USE_ZLIB] $[components $[USE_ZLIB],$[active_component_libs]],] #set alt_cflags $[alt_cflags] $[zlib_cflags] #endif @@ -326,6 +338,9 @@ #defun get_ipath #define alt_ipath $[nspr_ipath] $[python_ipath] + #if $[ne $[USE_CRYPTO] $[components $[USE_CRYPTO],$[active_component_libs]],] + #set alt_ipath $[alt_ipath] $[crypto_ipath] + #endif #if $[ne $[USE_ZLIB] $[components $[USE_ZLIB],$[active_component_libs]],] #set alt_ipath $[alt_ipath] $[zlib_ipath] #endif @@ -373,6 +388,9 @@ #defun get_lpath #define alt_lpath $[nspr_lpath] $[python_lpath] + #if $[ne $[USE_CRYPTO] $[components $[USE_CRYPTO],$[active_component_libs]],] + #set alt_lpath $[alt_lpath] $[crypto_lpath] + #endif #if $[ne $[USE_ZLIB] $[components $[USE_ZLIB],$[active_component_libs]],] #set alt_lpath $[alt_lpath] $[zlib_lpath] #endif @@ -421,6 +439,9 @@ #defun get_libs #define alt_libs $[nspr_libs] $[python_libs] + #if $[ne $[USE_CRYPTO] $[components $[USE_CRYPTO],$[active_component_libs]],] + #set alt_libs $[alt_libs] $[crypto_libs] + #endif #if $[ne $[USE_ZLIB] $[components $[USE_ZLIB],$[active_component_libs]],] #set alt_libs $[alt_libs] $[zlib_libs] #endif diff --git a/dtool/src/cppparser/cppPreprocessor.cxx b/dtool/src/cppparser/cppPreprocessor.cxx index f9ae384c30..7f53a852af 100644 --- a/dtool/src/cppparser/cppPreprocessor.cxx +++ b/dtool/src/cppparser/cppPreprocessor.cxx @@ -1322,15 +1322,15 @@ handle_include_directive(const string &args, int first_line, } // Now look for it on the include path. - if (!found_file && filename.resolve_filename(_include_path)) { - found_file = true; - source = CPPFile::S_alternate; - } - if (!found_file && filename.resolve_filename(_system_include_path)) { found_file = true; source = CPPFile::S_system; } + + if (!found_file && filename.resolve_filename(_include_path)) { + found_file = true; + source = CPPFile::S_alternate; + } if (!found_file) { warning("Cannot find " + filename.get_fullpath(), diff --git a/dtool/src/parser-inc/Sources.pp b/dtool/src/parser-inc/Sources.pp index dbbc4e4afd..08f2822805 100644 --- a/dtool/src/parser-inc/Sources.pp +++ b/dtool/src/parser-inc/Sources.pp @@ -1,3 +1,3 @@ #define INSTALL_PARSER_INC \ deque iostream list map pair queue set stack stdtypedefs.h \ - string vector windows.h zlib.h + string vector windows.h zlib.h md5.h files.h diff --git a/dtool/src/parser-inc/files.h b/dtool/src/parser-inc/files.h new file mode 100644 index 0000000000..1344e10ebe --- /dev/null +++ b/dtool/src/parser-inc/files.h @@ -0,0 +1,19 @@ +// Filename: files.h +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef FILES_H +#define FILES_H + +namespace CryptoPP { + class FileSource; + class FileSink; +}; + +#endif diff --git a/dtool/src/parser-inc/md5.h b/dtool/src/parser-inc/md5.h new file mode 100644 index 0000000000..990bf90981 --- /dev/null +++ b/dtool/src/parser-inc/md5.h @@ -0,0 +1,19 @@ +// Filename: md5.h +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. + +#ifndef MD5_H +#define MD5_H + +namespace CryptoPP { + class MD5; +}; + +#endif + diff --git a/panda/src/downloader/Sources.pp b/panda/src/downloader/Sources.pp index 89fcf9bbf3..b321895fea 100644 --- a/panda/src/downloader/Sources.pp +++ b/panda/src/downloader/Sources.pp @@ -1,6 +1,7 @@ #define LOCAL_LIBS event ipc express pandabase #define OTHER_LIBS interrogatedb:c dconfig:c dtoolutil:c dtoolbase:c dtool:m #define USE_ZLIB yes +#define USE_CRYPTO yes #define USE_IPC yes #begin lib_target @@ -19,6 +20,9 @@ decompressor.cxx decompressor.h zcompressor.I zcompressor.cxx \ zcompressor.h download_utils.cxx download_utils.h + #define IF_CRYPTO_SOURCES \ + crypto_utils.cxx crypto_utils.h + #define INSTALL_HEADERS \ downloader.h downloader.I \ config_downloader.h zcompressor.I zcompressor.h \ diff --git a/panda/src/downloader/crypto_utils.cxx b/panda/src/downloader/crypto_utils.cxx new file mode 100644 index 0000000000..62aff1a572 --- /dev/null +++ b/panda/src/downloader/crypto_utils.cxx @@ -0,0 +1,64 @@ +// Filename: crypto_utils.cxx +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +// This file is compiled only if we have crypto++ installed. + +#include "crypto_utils.h" + +#include +#include + +#include + +USING_NAMESPACE(CryptoPP); +USING_NAMESPACE(std); + +uint +read32(istream& is) { + unsigned int ret = 0x0; + unsigned char b1, b2, b3, b4; + is >> b1; + is >> b2; + is >> b3; + is >> b4; + ret = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + return ret; +} + +void +md5_a_file(const Filename &name, HashVal &ret) { + ostringstream os; + MD5 md5; + + string fs = name.get_fullpath(); + FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os))); + + istringstream is(os.str()); + + ret[0] = read32(is); + ret[1] = read32(is); + ret[2] = read32(is); + ret[3] = read32(is); +} + +void +md5_a_buffer(unsigned char* buf, unsigned long len, HashVal& ret) { + MD5 md5; + + HashFilter hash(md5); + hash.Put((byte*)buf, len); + hash.Close(); + + unsigned char* outb; + unsigned long outl = hash.MaxRetrieveable(); + outb = new uchar[outl]; + hash.Get((byte*)outb, outl); + ret[0] = (outb[0] << 24) | (outb[1] << 16) | (outb[2] << 8) | outb[3]; + ret[1] = (outb[4] << 24) | (outb[5] << 16) | (outb[6] << 8) | outb[7]; + ret[2] = (outb[8] << 24) | (outb[9] << 16) | (outb[10] << 8) | outb[11]; + ret[3] = (outb[12] << 24) | (outb[13] << 16) | (outb[14] << 8) | outb[15]; + delete outb; +} + diff --git a/panda/src/downloader/crypto_utils.h b/panda/src/downloader/crypto_utils.h new file mode 100644 index 0000000000..49eafd74e4 --- /dev/null +++ b/panda/src/downloader/crypto_utils.h @@ -0,0 +1,19 @@ +// Filename: crypto_utils.h +// Created by: drose (07Nov00) +// +//////////////////////////////////////////////////////////////////// + +#ifndef CRYPTO_UTILS_H +#define CRYPTO_UTILS_H + +#include +#include +#include + +typedef uint HashVal[4]; + +EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret); +EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret); + +#endif + diff --git a/panda/src/downloader/download_utils.cxx b/panda/src/downloader/download_utils.cxx index 5bc363219b..9454e84f64 100644 --- a/panda/src/downloader/download_utils.cxx +++ b/panda/src/downloader/download_utils.cxx @@ -60,61 +60,3 @@ check_adler(Filename name) { return adler; } - -#include -#include - -#include -#include -#include - -USING_NAMESPACE(CryptoPP); -USING_NAMESPACE(std); - -uint -read32(istream& is) { - unsigned int ret = 0x0; - unsigned char b1, b2, b3, b4; - is >> b1; - is >> b2; - is >> b3; - is >> b4; - ret = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; - return ret; -} - -void -md5_a_file(const Filename &name, HashVal &ret) { - ostrstream os; - MD5 md5; - - string fs = name.get_fullpath(); - FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os))); - - istrstream is(os.str()); - - ret[0] = read32(is); - ret[1] = read32(is); - ret[2] = read32(is); - ret[3] = read32(is); -} - -void -md5_a_buffer(unsigned char* buf, unsigned long len, HashVal& ret) { - MD5 md5; - - HashFilter hash(md5); - hash.Put((byte*)buf, len); - hash.Close(); - - unsigned char* outb; - unsigned long outl = hash.MaxRetrieveable(); - outb = new uchar[outl]; - hash.Get((byte*)outb, outl); - ret[0] = (outb[0] << 24) | (outb[1] << 16) | (outb[2] << 8) | outb[3]; - ret[1] = (outb[4] << 24) | (outb[5] << 16) | (outb[6] << 8) | outb[7]; - ret[2] = (outb[8] << 24) | (outb[9] << 16) | (outb[10] << 8) | outb[11]; - ret[3] = (outb[12] << 24) | (outb[13] << 16) | (outb[14] << 8) | outb[15]; - delete outb; -} - diff --git a/panda/src/downloader/download_utils.h b/panda/src/downloader/download_utils.h index 9e141b3fba..5bced97c75 100644 --- a/panda/src/downloader/download_utils.h +++ b/panda/src/downloader/download_utils.h @@ -7,15 +7,11 @@ #define DOWNLOAD_UTILS_H #include -#include #include - -typedef uint HashVal[4]; +#include EXPCL_PANDAEXPRESS ulong check_crc(Filename name); EXPCL_PANDAEXPRESS ulong check_adler(Filename name); -EXPCL_PANDAEXPRESS void md5_a_file(const Filename &fname, HashVal &ret); -EXPCL_PANDAEXPRESS void md5_a_buffer(uchar *buf, ulong len, HashVal &ret); #endif