From c9c13dc10f736361cec1efaa061b1ec37b72fa96 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 11 Oct 2005 21:16:14 +0000 Subject: [PATCH] add minor functions --- panda/src/express/hashVal.cxx | 27 +++++++++++++++++++++++++++ panda/src/express/hashVal.h | 3 +++ panda/src/putil/load_prc_file.cxx | 20 ++++++++++++++++++++ panda/src/putil/load_prc_file.h | 16 ++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/panda/src/express/hashVal.cxx b/panda/src/express/hashVal.cxx index 3674c21397..8d5bbcf869 100644 --- a/panda/src/express/hashVal.cxx +++ b/panda/src/express/hashVal.cxx @@ -164,6 +164,33 @@ set_from_hex(const string &text) { return !strm.fail(); } +//////////////////////////////////////////////////////////////////// +// Function: HashVal::as_bin +// Access: Published +// Description: Returns the HashVal as a 16-byte binary string. +//////////////////////////////////////////////////////////////////// +string HashVal:: +as_bin() const { + Datagram dg; + write_datagram(dg); + return dg.get_message(); +} + +//////////////////////////////////////////////////////////////////// +// Function: HashVal::set_from_bin +// Access: Published +// Description: Sets the HashVal from a 16-byte binary string. +// Returns true if successful, false otherwise. +//////////////////////////////////////////////////////////////////// +bool HashVal:: +set_from_bin(const string &text) { + nassertr(text.size() == 16, false); + Datagram dg(text); + DatagramIterator dgi(dg); + read_datagram(dgi); + return true; +} + #ifdef HAVE_OPENSSL //////////////////////////////////////////////////////////////////// // Function: HashVal::hash_file diff --git a/panda/src/express/hashVal.h b/panda/src/express/hashVal.h index d60324f9ac..67210be9ad 100644 --- a/panda/src/express/hashVal.h +++ b/panda/src/express/hashVal.h @@ -61,6 +61,9 @@ PUBLISHED: string as_hex() const; bool set_from_hex(const string &text); + string as_bin() const; + bool set_from_bin(const string &text); + INLINE void write_datagram(Datagram &destination) const; INLINE void read_datagram(DatagramIterator &source); INLINE void write_stream(StreamWriter &destination) const; diff --git a/panda/src/putil/load_prc_file.cxx b/panda/src/putil/load_prc_file.cxx index 0fc6580ba3..86d528485e 100644 --- a/panda/src/putil/load_prc_file.cxx +++ b/panda/src/putil/load_prc_file.cxx @@ -18,9 +18,11 @@ #include "load_prc_file.h" #include "configPageManager.h" +#include "configVariableManager.h" #include "virtualFileSystem.h" #include "config_express.h" #include "config_util.h" +#include "hashVal.h" //////////////////////////////////////////////////////////////////// // Function: load_prc_file @@ -121,3 +123,21 @@ unload_prc_file(ConfigPage *page) { return cp_mgr->delete_explicit_page(page); } + +#ifdef HAVE_OPENSSL + +//////////////////////////////////////////////////////////////////// +// Function: hash_prc_variables +// Description: Fills HashVal with the hash from the current prc file +// state as reported by +// ConfigVariableManager::write_prc_variables(). +//////////////////////////////////////////////////////////////////// +void +hash_prc_variables(HashVal &hash) { + ostringstream strm; + ConfigVariableManager *cv_mgr = ConfigVariableManager::get_global_ptr(); + cv_mgr->write_prc_variables(strm); + hash.hash_string(strm.str()); +} + +#endif // HAVE_OPENSSL diff --git a/panda/src/putil/load_prc_file.h b/panda/src/putil/load_prc_file.h index a492c0bbb1..2ed7c7a378 100644 --- a/panda/src/putil/load_prc_file.h +++ b/panda/src/putil/load_prc_file.h @@ -22,6 +22,7 @@ #include "pandabase.h" class ConfigPage; +class HashVal; BEGIN_PUBLISH //////////////////////////////////////////////////////////////////// @@ -69,6 +70,21 @@ load_prc_file_data(const string &name, const string &data); //////////////////////////////////////////////////////////////////// EXPCL_PANDA bool unload_prc_file(ConfigPage *page); + +#ifdef HAVE_OPENSSL + +//////////////////////////////////////////////////////////////////// +// Function: hash_prc_variables +// Description: Fills HashVal with the hash from the current prc file +// state as reported by +// ConfigVariableManager::write_prc_variables(). +//////////////////////////////////////////////////////////////////// +EXPCL_PANDA void +hash_prc_variables(HashVal &hash); + +#endif // HAVE_OPENSSL + + END_PUBLISH #endif