decode the stored source
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 6 Feb 2006 17:10:30 +0000 (17:10 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 6 Feb 2006 17:10:30 +0000 (17:10 +0000)
zypp/target/store/PersistentStorage.h
zypp/target/store/XMLFilesBackend.cc
zypp/target/store/xml/Makefile.am
zypp/target/store/xml/XMLSourceCacheParser.cc [new file with mode: 0644]
zypp/target/store/xml/XMLSourceCacheParser.h [new file with mode: 0644]

index 1fdbe989a0d4831c69afd116fa14d2105a51febd..033c6df506b232822345ceadddb8639c319d2648 100644 (file)
@@ -50,7 +50,7 @@ namespace zypp
           enabled = false;
           autorefresh = false;
         };
-
+       
         bool enabled;
         bool autorefresh;
         std::string product_dir;
index 045fdaf9cf35f1b8bfbde425fc9d87ed07456145..975a5296ffe9082857cf8d64dff9e785a343a20e 100644 (file)
@@ -33,6 +33,8 @@
 
 #include <list>
 
+#include <zypp/target/store/xml/XMLSourceCacheParser.h>
+
 #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
 #include "boost/filesystem/fstream.hpp"    // ditto
 
@@ -619,8 +621,13 @@ XMLFilesBackend::storedSources() const
   {
     DBG << "[source-cache] - " << dir_itr->leaf() << std::endl;
     //sources.insert( sourceDataFromCacheFile( source_p + "/" + dir_itr->leaf() ) );
-    PersistentStorage::SourceData data;
-    sources.push_back(data);
+    std::string full_path = (source_p / dir_itr->leaf()).string();
+    std::ifstream anIstream(full_path.c_str());
+    XMLSourceCacheParser iter(anIstream, "");
+    for (; ! iter.atEnd(); ++iter) {
+      PersistentStorage::SourceData data = **iter;
+      sources.push_back(data);
+    }
   }
   MIL << "done reading source cache" << std::endl;
   return sources;
index 04fdbd6e28390a1177784f01b614162ae2e1277c..b6091716fd3edbc846463aadc9c6efd026fd5bc8 100644 (file)
@@ -3,6 +3,8 @@
 
 SUBDIRS =
 
+INCLUDES = -I$(oldincludedir)/libxml2 -I..
+
 ## ##################################################
 
 targetxmlincludedir = $(pkgincludedir)/target/store/xml
@@ -13,7 +15,8 @@ targetxmlinclude_HEADERS =            \
        XMLScriptImpl.h \
        XMLSelectionImpl.h \
        XMLPatternImpl.h \
-       XMLProductImpl.h
+       XMLProductImpl.h \
+       XMLSourceCacheParser.h
 
 
 noinst_LTLIBRARIES =   lib@PACKAGE@_target_xml.la
@@ -26,6 +29,7 @@ lib@PACKAGE@_target_xml_la_SOURCES = \
        XMLScriptImpl.cc \
        XMLSelectionImpl.cc \
        XMLPatternImpl.cc \
-       XMLProductImpl.cc
+       XMLProductImpl.cc \
+       XMLSourceCacheParser.cc
 
 ## ##################################################
diff --git a/zypp/target/store/xml/XMLSourceCacheParser.cc b/zypp/target/store/xml/XMLSourceCacheParser.cc
new file mode 100644 (file)
index 0000000..973ecb6
--- /dev/null
@@ -0,0 +1,104 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/store/xml/XMLSourceCacheParser.cc
+ *
+*/
+
+#include <zypp/parser/LibXMLHelper.h>
+#include <istream>
+#include <string>
+#include <cassert>
+#include <libxml/xmlreader.h>
+#include <libxml/tree.h>
+#include <zypp/base/Logger.h>
+//#include <zypp/parser/yum/schemanames.h>
+
+#include <zypp/target/store/xml/XMLSourceCacheParser.h>
+
+using namespace std;
+
+namespace zypp {
+    namespace storage {
+
+      XMLSourceCacheParser::XMLSourceCacheParser()
+      { }
+      
+      XMLSourceCacheParser::XMLSourceCacheParser(SourceData_Ptr& entry)
+      : zypp::parser::XMLNodeIterator<SourceData_Ptr>(entry)
+      { }
+      
+      
+      XMLSourceCacheParser::~XMLSourceCacheParser()
+      { }
+      
+      
+      // select for which elements process() will be called
+      bool 
+      XMLSourceCacheParser::isInterested(const xmlNodePtr nodePtr)
+      {
+        return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "source-cache";
+      }
+      
+      // do the actual processing
+      SourceData_Ptr
+      XMLSourceCacheParser::process(const xmlTextReaderPtr reader)
+      {
+        assert(reader);
+        SourceData_Ptr dataPtr = new PersistentStorage::SourceData;
+        xmlNodePtr dataNode = xmlTextReaderExpand(reader);
+        assert(dataNode);
+        
+        for (xmlNodePtr child = dataNode->children; child && child != dataNode; child = child->next)
+        {
+          if (_helper.isElement(child))
+          {
+            string name = _helper.name(child);
+            if (name == "enabled")
+            {
+              dataPtr->enabled = (_helper.content(child) == "true") ? true : false;
+            }
+            else if (name == "auto-refresh")
+            {
+              dataPtr->autorefresh = (_helper.content(child) == "true") ? true : false;
+            }
+            else if (name == "type")
+            {
+              dataPtr->type = _helper.content(child);
+            }
+            else if (name == "product-dir")
+            {
+              dataPtr->product_dir = _helper.content(child);
+            }
+            else if (name == "alias")
+            {
+              dataPtr->alias = _helper.content(child);
+            }
+            else if (name == "url")
+            {
+              dataPtr->url = _helper.content(child);
+            }
+            else
+            {
+              WAR << "SourceCache entry contains the unknown element <" << name << "> "
+                << _helper.positionInfo(child) << ", skipping" << endl;
+            }
+          }
+        }
+        return dataPtr;
+      } /* end process */
+      
+      
+      XMLSourceCacheParser::XMLSourceCacheParser(istream &is, const string &baseUrl)
+      : zypp::parser::XMLNodeIterator<SourceData_Ptr>(is, baseUrl, "")
+      { 
+        fetchNext();
+      }
+      
+  } // namespace storage
+} // namespace zypp
diff --git a/zypp/target/store/xml/XMLSourceCacheParser.h b/zypp/target/store/xml/XMLSourceCacheParser.h
new file mode 100644 (file)
index 0000000..2ab77b3
--- /dev/null
@@ -0,0 +1,64 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/target/store/xml/XMLSourceCacheParser.h
+ *
+*/
+
+#ifndef XMLSourceCacheParser_h
+#define XMLSourceCacheParser_h
+
+#include <zypp/target/store/PersistentStorage.h>
+#include <zypp/parser/XMLNodeIterator.h>
+#include <zypp/parser/LibXMLHelper.h>
+#include <list>
+
+typedef zypp::storage::PersistentStorage::SourceData* SourceData_Ptr;
+
+namespace zypp
+{
+namespace storage
+{
+     /*
+      * Use this class as an iterator that produces, one after one,
+      * XMLSourceCacheData_Ptr(s) for the XML group elements.
+      * Here's an example:
+      *
+      * for (XMLSourceCacheParser iter(anIstream, baseUrl),
+      *      iter != XMLSourceCacheParser.end(),     // or: iter() != 0, or ! iter.atEnd()
+      *      ++iter) {
+      *    doSomething(*iter)
+      * }
+      *
+      * The iterator owns the pointer (i.e., caller must not delete it)
+      * until the next ++ operator is called. At this time, it will be
+      * destroyed (and a new ENTRYTYPE is created.)
+      *
+      * If the input is fundamentally flawed so that it makes no sense to
+      * continue parsing, XMLNodeIterator will log it and consider the input as finished.
+      * You can query the exit status with errorStatus().
+      */
+
+      class XMLSourceCacheParser : public zypp::parser::XMLNodeIterator<SourceData_Ptr>
+      { 
+      public:
+        XMLSourceCacheParser(std::istream &is, const std::string &baseUrl);
+        XMLSourceCacheParser();
+        XMLSourceCacheParser(SourceData_Ptr & entry);
+        virtual ~XMLSourceCacheParser();
+        
+      private:
+        virtual bool isInterested(const xmlNodePtr nodePtr);
+        virtual SourceData_Ptr process(const xmlTextReaderPtr reader);
+        void parseSourceList(SourceData_Ptr dataPtr, xmlNodePtr node);
+        zypp::parser::LibXMLHelper _helper;
+      };
+  } // namespace storage
+} // namespace zypp
+
+#endif