From 345532845160245f1b1fd322e3a6b5e38b9a0fe2 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 9 Feb 2006 17:22:30 +0000 Subject: [PATCH] serialize in the new pattern format, and get rid of md5 and use the Digest class (no idea that it existed) --- zypp/target/store/Makefile.am | 4 ++-- zypp/target/store/PersistentStorage.cc | 3 +-- zypp/target/store/XMLFilesBackend.cc | 29 ++++++----------------------- zypp/target/store/serialize.cc | 25 ++++++++++++++++++------- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/zypp/target/store/Makefile.am b/zypp/target/store/Makefile.am index 47436e3..a0f7ced 100644 --- a/zypp/target/store/Makefile.am +++ b/zypp/target/store/Makefile.am @@ -7,13 +7,13 @@ SUBDIRS = xml targetstoreincludedir = $(pkgincludedir)/target/store -targetstoreinclude_HEADERS = PersistentStorage.h Backend.h XMLFilesBackend.h serialize.h xml_escape_parser.hpp parser_utils.hpp md5.h +targetstoreinclude_HEADERS = PersistentStorage.h Backend.h XMLFilesBackend.h serialize.h xml_escape_parser.hpp parser_utils.hpp noinst_LTLIBRARIES = lib@PACKAGE@_target_store.la ## ################################################## -lib@PACKAGE@_target_store_la_SOURCES = PersistentStorage.cc Backend.cc XMLFilesBackend.cc serialize.cc xml_escape_parser.cpp md5.cc +lib@PACKAGE@_target_store_la_SOURCES = PersistentStorage.cc Backend.cc XMLFilesBackend.cc serialize.cc xml_escape_parser.cpp lib@PACKAGE@_target_store_la_LIBADD = -lboost_regex -lboost_filesystem \ xml/lib@PACKAGE@_target_xml.la diff --git a/zypp/target/store/PersistentStorage.cc b/zypp/target/store/PersistentStorage.cc index 8bc267a..9d9a1f3 100644 --- a/zypp/target/store/PersistentStorage.cc +++ b/zypp/target/store/PersistentStorage.cc @@ -6,7 +6,7 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ -/** \file devel/devel.dmacvicar/PersistentStorage.cc +/** \file zypp/target/store/PersistentStorage.cc * */ #include @@ -15,7 +15,6 @@ #include "PersistentStorage.h" #include "Backend.h" #include "XMLFilesBackend.h" -//#include "devel/devel.dmacvicar/BDBBackend.h" using std::endl; diff --git a/zypp/target/store/XMLFilesBackend.cc b/zypp/target/store/XMLFilesBackend.cc index fee5ed2..1fc9a0c 100644 --- a/zypp/target/store/XMLFilesBackend.cc +++ b/zypp/target/store/XMLFilesBackend.cc @@ -19,6 +19,8 @@ #include "zypp/base/Exception.h" #include "zypp/CapFactory.h" +#include "zypp/Digest.h" + #include "zypp/target/store/xml/XMLPatchImpl.h" #include "zypp/target/store/xml/XMLMessageImpl.h" @@ -42,8 +44,6 @@ #include "XMLFilesBackend.h" #include "serialize.h" -#include "md5.h" - #define ZYPP_DB_DIR "/var/lib/zypp_db" using std::endl; @@ -751,25 +751,6 @@ XMLFilesBackend::storedSources() const } -static std::string hexDigest(const std::string &message) -{ - md5_state_t state; - md5_byte_t digest[16]; - - md5_init(&state); - /* Append a string to the message. */ - md5_append(&state, (md5_byte_t*) message.c_str(), message.size()); /* Finish the message and return the digest. */ - md5_finish(&state, digest); - - char s[33]; - int i; - for (i=0; i<16; i++) - sprintf(s+i*2, "%02x", digest[i]); - - s[32]='\0'; - return std::string(s); -} - void XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) { @@ -788,7 +769,8 @@ XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) //DBG << filename << std::endl; try { - std::string full_path = (source_p / hexDigest(data.alias)).string(); + std::stringstream message_stream(data.alias); + std::string full_path = (source_p / Digest::digest("MD5", message_stream)).string(); file.open(full_path.c_str()); file << xml; @@ -808,7 +790,8 @@ XMLFilesBackend::deleteSource(const std::string &alias) path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("source-cache"); try { - std::string full_path = (source_p / hexDigest(alias)).string(); + std::stringstream message_stream(alias); + std::string full_path = (source_p / Digest::digest("MD5", message_stream)).string(); remove(full_path); } catch ( std::exception &e ) diff --git a/zypp/target/store/serialize.cc b/zypp/target/store/serialize.cc index d0317a0..0ca1d8d 100644 --- a/zypp/target/store/serialize.cc +++ b/zypp/target/store/serialize.cc @@ -244,13 +244,24 @@ template<> // or constPtr? std::string toXML( const Pattern::constPtr &obj ) { stringstream out; - /* - out << "type() << "\">" << std::endl; - // reuse Resolvable information serialize function - out << toXML(static_cast(obj)); - out << " " << obj->text() << "" << std::endl; - out << "" << std::endl; - */ + out << "" << std::endl; + out << "" << std::endl; + out << " " << obj->patternId() << "" << std::endl; + out << " " << obj->name() << "" << std::endl; + //out << " foobar" << std::endl; + out << " " << (obj->isDefault() ? "true" : "false" ) << "" << std::endl; + out << " " << (obj->userVisible() ? "true" : "false" ) << "" << std::endl; + out << " " << obj->category() << "" << std::endl; + out << " " << obj->icon() << "" << std::endl; + out << " " << std::endl; + //out << " This is my pattern, it is soooooooo coool!" << std::endl; + //out << " Duh" << std::endl; + out << toXML(obj->deps()) << std::endl; + out << "" << std::endl; return out.str(); } -- 2.7.4