serialize in the new pattern format, and get rid of md5 and use the Digest class...
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 9 Feb 2006 17:22:30 +0000 (17:22 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 9 Feb 2006 17:22:30 +0000 (17:22 +0000)
zypp/target/store/Makefile.am
zypp/target/store/PersistentStorage.cc
zypp/target/store/XMLFilesBackend.cc
zypp/target/store/serialize.cc

index 47436e3..a0f7ced 100644 (file)
@@ -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
index 8bc267a..9d9a1f3 100644 (file)
@@ -6,7 +6,7 @@
 |                         /_____||_| |_| |_|                           |
 |                                                                      |
 \---------------------------------------------------------------------*/
-/** \file      devel/devel.dmacvicar/PersistentStorage.cc
+/** \file      zypp/target/store/PersistentStorage.cc
 *
 */
 #include <iostream>
@@ -15,7 +15,6 @@
 #include "PersistentStorage.h"
 #include "Backend.h"
 #include "XMLFilesBackend.h"
-//#include "devel/devel.dmacvicar/BDBBackend.h"
 
 using std::endl;
 
index fee5ed2..1fc9a0c 100644 (file)
@@ -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 )
index d0317a0..0ca1d8d 100644 (file)
@@ -244,13 +244,24 @@ template<> // or constPtr?
 std::string toXML( const Pattern::constPtr &obj )
 {
   stringstream out;
-  /*
-  out << "<message type=\"" << obj->type() << "\">" << std::endl;
-  // reuse Resolvable information serialize function
-  out << toXML(static_cast<Resolvable::constPtr>(obj));
-  out << "  <text>" << obj->text() << "</text>" << std::endl;
-  out << "</message>" << std::endl;
-  */
+  out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
+  out << "<pattern" << std::endl;
+  out << "  xmlns=\"http://novell.com/package/metadata/suse/pattern\"" << std::endl;
+  out << "  xmlns:yum=\"http://linux.duke.edu/metadata/common\"" << std::endl;
+  out << "  xmlns:rpm=\"http://linux.duke.edu/metadata/rpm\"" << std::endl;
+  out << "  xmlns:suse=\"http://novell.com/package/metadata/suse/common\">" << std::endl;
+  out << "  <patternid>" << obj->patternId() << "</patternid>" << std::endl;
+  out << "  <name>" << obj->name() << "</name>" << std::endl;
+  //out << "  <name lang='en.US'>foobar</name>" << std::endl;
+  out << "  <default>" << (obj->isDefault() ? "true" : "false" ) << "</default>" << std::endl;
+  out << "  <uservisible>" << (obj->userVisible() ? "true" : "false" ) << "</uservisible>" << std::endl;
+  out << "  <category>" << obj->category() << "</category>" << std::endl;
+  out << "  <icon>" << obj->icon() << "</icon>" << std::endl;
+  out << "  <script>" << obj->script() << "</script>" << std::endl;
+  //out << "  <description lang='cs.CZ'>This is my pattern, it is soooooooo coool!</description>" << std::endl;
+  //out << "  <description lang='en.US'>Duh</description>" << std::endl;
+  out << toXML(obj->deps()) << std::endl;
+  out << "</pattern>" << std::endl;
   return out.str();
 }